* enum.c (inject_i): use rb_yield_values.

* enum.c (each_with_index_i): ditto.

* eval.c (rb_yield_splat): new function to call "yield *values".

* string.c (rb_str_scan): use rb_yield_splat().


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4424 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-08-22 08:09:58 +00:00
parent 7cca6c25f0
commit 7ff7bcbf9d
8 changed files with 41 additions and 14 deletions

View File

@ -1,3 +1,13 @@
Fri Aug 22 17:07:05 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* enum.c (inject_i): use rb_yield_values.
* enum.c (each_with_index_i): ditto.
* eval.c (rb_yield_splat): new function to call "yield *values".
* string.c (rb_str_scan): use rb_yield_splat().
Fri Aug 22 06:13:22 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net> Fri Aug 22 06:13:22 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
* ext/syck/rubyext.c: refactoring of the transfer method * ext/syck/rubyext.c: refactoring of the transfer method

4
enum.c
View File

@ -187,7 +187,7 @@ inject_i(i, memo)
memo->u1.value = i; memo->u1.value = i;
} }
else { else {
memo->u1.value = rb_yield(rb_assoc_new(memo->u1.value, i)); memo->u1.value = rb_yield_values(2, memo->u1.value, i);
} }
return Qnil; return Qnil;
} }
@ -499,7 +499,7 @@ each_with_index_i(val, memo)
VALUE val; VALUE val;
NODE *memo; NODE *memo;
{ {
rb_yield(rb_assoc_new(val, INT2FIX(memo->u3.cnt))); rb_yield_values(val, INT2FIX(memo->u3.cnt));
memo->u3.cnt++; memo->u3.cnt++;
return Qnil; return Qnil;
} }

18
eval.c
View File

@ -4230,7 +4230,7 @@ VALUE
#ifdef HAVE_STDARG_PROTOTYPES #ifdef HAVE_STDARG_PROTOTYPES
rb_yield_values(int n, ...) rb_yield_values(int n, ...)
#else #else
rb_yield_values(int n, va_alist) rb_yield_values(n, va_alist)
int n; int n;
va_dcl va_dcl
#endif #endif
@ -4250,6 +4250,16 @@ rb_yield_values(int n, va_alist)
return rb_yield_0(ary, 0, 0, Qfalse, Qtrue); return rb_yield_0(ary, 0, 0, Qfalse, Qtrue);
} }
VALUE
rb_yield_splat(values)
VALUE values;
{
if (RARRAY(value)->len == 0) {
return rb_yield_0(Qundef, 0, 0, Qfalse, Qfalse);
}
return rb_yield_0(values, 0, 0, Qfalse, Qtrue);
}
static VALUE static VALUE
rb_f_loop() rb_f_loop()
{ {
@ -9375,7 +9385,7 @@ rb_thread_start_0(fn, arg, th_arg)
{ {
volatile rb_thread_t th = th_arg; volatile rb_thread_t th = th_arg;
volatile VALUE thread = th->thread; volatile VALUE thread = th->thread;
struct BLOCK* saved_block = 0; volatile struct BLOCK* saved_block = 0;
enum thread_status status; enum thread_status status;
int state; int state;
@ -9434,12 +9444,12 @@ rb_thread_start_0(fn, arg, th_arg)
rb_thread_remove(th); rb_thread_remove(th);
while (saved_block) { while (saved_block) {
struct BLOCK *tmp = saved_block; volatile struct BLOCK *tmp = saved_block;
if (tmp->frame.argc > 0) if (tmp->frame.argc > 0)
free(tmp->frame.argv); free(tmp->frame.argv);
saved_block = tmp->prev; saved_block = tmp->prev;
free(tmp); free((void*)tmp);
} }
if (state && status != THREAD_TO_KILL && !NIL_P(ruby_errinfo)) { if (state && status != THREAD_TO_KILL && !NIL_P(ruby_errinfo)) {

4
gc.c
View File

@ -1636,10 +1636,10 @@ id2ref(obj, id)
} }
ptr = id ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */ ptr = id ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */
if (!is_pointer_to_heap((void *)ptr)) { if (!is_pointer_to_heap((void *)ptr)|| BUILTIN_TYPE(ptr) >= T_BLKTAG) {
rb_raise(rb_eRangeError, "0x%lx is not id value", p0); rb_raise(rb_eRangeError, "0x%lx is not id value", p0);
} }
if (RBASIC(ptr)->klass == 0) { if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) {
rb_raise(rb_eRangeError, "0x%lx is recycled object", p0); rb_raise(rb_eRangeError, "0x%lx is recycled object", p0);
} }
return (VALUE)ptr; return (VALUE)ptr;

View File

@ -973,7 +973,7 @@ class CGI
bufsize = 10 * 1024 bufsize = 10 * 1024
# start multipart/form-data # start multipart/form-data
stdinput.binmode stdinput.binmode if defined? stdinput.binmode
boundary_size = boundary.size + EOL.size boundary_size = boundary.size + EOL.size
content_length -= boundary_size content_length -= boundary_size
status = stdinput.read(boundary_size) status = stdinput.read(boundary_size)
@ -997,7 +997,7 @@ class CGI
body = Tempfile.new("CGI") body = Tempfile.new("CGI")
end end
end end
body.binmode body.binmode if defined? body.binmode
until head and /#{boundary}(?:#{EOL}|--)/n.match(buf) until head and /#{boundary}(?:#{EOL}|--)/n.match(buf)
@ -1123,7 +1123,7 @@ class CGI
env_table['QUERY_STRING'] or "" env_table['QUERY_STRING'] or ""
end end
when "POST" when "POST"
stdinput.binmode stdinput.binmode if defined? stdinput.binmode
stdinput.read(Integer(env_table['CONTENT_LENGTH'])) or '' stdinput.read(Integer(env_table['CONTENT_LENGTH'])) or ''
else else
read_from_cmdline read_from_cmdline

View File

@ -95,7 +95,10 @@ class << Singleton
@__instance__ = new @__instance__ = new
ensure ensure
if @__instance__ if @__instance__
def self.instance; @__instance__ end class <<self
remove_method :instance
def instance; @__instance__ end
end
else else
@__instance__ = nil # failed instance creation @__instance__ = nil # failed instance creation
end end
@ -109,7 +112,10 @@ class << Singleton
@__instance__ = new @__instance__ = new
ensure ensure
if @__instance__ if @__instance__
def self.instance; @__instance__ end class <<self
remove_method :instance
def instance; @__instance__ end
end
else else
@__instance__ = nil @__instance__ = nil
end end

1
ruby.h
View File

@ -537,6 +537,7 @@ void rb_warn __((const char*, ...)); /* reports always */
VALUE rb_each _((VALUE)); VALUE rb_each _((VALUE));
VALUE rb_yield _((VALUE)); VALUE rb_yield _((VALUE));
VALUE rb_yield_values __((int n, ...)); VALUE rb_yield_values __((int n, ...));
VALUE rb_yield_splat _((VALUE));
int rb_block_given_p _((void)); int rb_block_given_p _((void));
VALUE rb_iterate _((VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE)); VALUE rb_iterate _((VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE));
VALUE rb_rescue _((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE)); VALUE rb_rescue _((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE));

View File

@ -3066,7 +3066,7 @@ rb_str_scan(str, pat)
while (!NIL_P(result = scan_once(str, pat, &start))) { while (!NIL_P(result = scan_once(str, pat, &start))) {
match = rb_backref_get(); match = rb_backref_get();
rb_match_busy(match); rb_match_busy(match);
rb_yield(result); rb_yield_splat(result);
rb_backref_set(match); /* restore $~ value */ rb_backref_set(match); /* restore $~ value */
} }
rb_backref_set(match); rb_backref_set(match);