From 7ff7bcbf9dbb0f22a9802a7b3474c59c9bbd0b70 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 22 Aug 2003 08:09:58 +0000 Subject: [PATCH] * 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 --- ChangeLog | 10 ++++++++++ enum.c | 4 ++-- eval.c | 18 ++++++++++++++---- gc.c | 4 ++-- lib/cgi.rb | 6 +++--- lib/singleton.rb | 10 ++++++++-- ruby.h | 1 + string.c | 2 +- 8 files changed, 41 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 30b84fd6f4..24669e3aa0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Fri Aug 22 17:07:05 2003 Yukihiro Matsumoto + + * 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 * ext/syck/rubyext.c: refactoring of the transfer method diff --git a/enum.c b/enum.c index 71b2e7e763..ac27757bd4 100644 --- a/enum.c +++ b/enum.c @@ -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; } diff --git a/eval.c b/eval.c index 6612bacb93..a82d2941c9 100644 --- a/eval.c +++ b/eval.c @@ -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)) { diff --git a/gc.c b/gc.c index 1024c1a50e..613ad6db1e 100644 --- a/gc.c +++ b/gc.c @@ -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; diff --git a/lib/cgi.rb b/lib/cgi.rb index ee315cc48d..27dd83da01 100644 --- a/lib/cgi.rb +++ b/lib/cgi.rb @@ -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 diff --git a/lib/singleton.rb b/lib/singleton.rb index 30990b79bd..2954bfa153 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -95,7 +95,10 @@ class << Singleton @__instance__ = new ensure if @__instance__ - def self.instance; @__instance__ end + class <