* 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>
* 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;
}
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;
}
@ -499,7 +499,7 @@ each_with_index_i(val, memo)
VALUE val;
NODE *memo;
{
rb_yield(rb_assoc_new(val, INT2FIX(memo->u3.cnt)));
rb_yield_values(val, INT2FIX(memo->u3.cnt));
memo->u3.cnt++;
return Qnil;
}

18
eval.c
View File

@ -4230,7 +4230,7 @@ VALUE
#ifdef HAVE_STDARG_PROTOTYPES
rb_yield_values(int n, ...)
#else
rb_yield_values(int n, va_alist)
rb_yield_values(n, va_alist)
int n;
va_dcl
#endif
@ -4250,6 +4250,16 @@ rb_yield_values(int n, va_alist)
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
rb_f_loop()
{
@ -9375,7 +9385,7 @@ rb_thread_start_0(fn, arg, th_arg)
{
volatile rb_thread_t th = th_arg;
volatile VALUE thread = th->thread;
struct BLOCK* saved_block = 0;
volatile struct BLOCK* saved_block = 0;
enum thread_status status;
int state;
@ -9434,12 +9444,12 @@ rb_thread_start_0(fn, arg, th_arg)
rb_thread_remove(th);
while (saved_block) {
struct BLOCK *tmp = saved_block;
volatile struct BLOCK *tmp = saved_block;
if (tmp->frame.argc > 0)
free(tmp->frame.argv);
saved_block = tmp->prev;
free(tmp);
free((void*)tmp);
}
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 */
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);
}
if (RBASIC(ptr)->klass == 0) {
if (BUILTIN_TYPE(ptr) == 0 || RBASIC(ptr)->klass == 0) {
rb_raise(rb_eRangeError, "0x%lx is recycled object", p0);
}
return (VALUE)ptr;

View File

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

View File

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

1
ruby.h
View File

@ -537,6 +537,7 @@ void rb_warn __((const char*, ...)); /* reports always */
VALUE rb_each _((VALUE));
VALUE rb_yield _((VALUE));
VALUE rb_yield_values __((int n, ...));
VALUE rb_yield_splat _((VALUE));
int rb_block_given_p _((void));
VALUE rb_iterate _((VALUE(*)(VALUE),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))) {
match = rb_backref_get();
rb_match_busy(match);
rb_yield(result);
rb_yield_splat(result);
rb_backref_set(match); /* restore $~ value */
}
rb_backref_set(match);