From bbf2ad4ed8a142c5fba8b5e56293006b359f9b18 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 15 Sep 2000 06:00:30 +0000 Subject: [PATCH] matz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 30 +++++++++++++++++++++++------- bignum.c | 2 +- eval.c | 19 ++++++++----------- intern.h | 1 + object.c | 1 + parse.y | 10 +++++++++- ruby.h | 1 + sample/time.rb | 2 +- variable.c | 37 +++++++++++++++++++++++++++++++++++-- 9 files changed, 80 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index dca259b0d4..3942ac876b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,27 @@ +Wed Sep 13 17:11:19 2000 Yukihiro Matsumoto + + * stable version 1.6.0 released. + +Thu Sep 14 02:46:54 2000 Yukihiro Matsumoto + + * eval.c (rb_thread_yield): array strip should be done in this + function. + +Wed Sep 13 17:01:03 2000 Yukihiro Matsumoto + + * bignum.c (rb_big_eq): imcomplete value compare of bignums. + +Wed Sep 13 06:39:54 2000 Yukihiro Matsumoto + + * variable.c (rb_mod_class_variables): Module#class_variables added. + Wed Sep 13 06:09:26 2000 Wakou Aoyama * lib/cgi.rb: bug fix: CGI::header(): output status header. -Tue Sep 12 22:34:20 2000 Yukihiro Matsumoto +Wed Sep 13 01:09:12 2000 Yukihiro Matsumoto - * stable version 1.6.0 released. + * parse.y (yylex): allow global variables like '$__a'. Tue Sep 12 22:28:43 2000 WATANABE Hirofumi @@ -17,8 +34,8 @@ Tue Sep 12 16:01:58 2000 WATANABE Hirofumi Tue Sep 12 15:37:55 2000 Yukihiro Matsumoto - * eval.c (rb_yield_0): stripped array too much, should be just for - proc_call(). + * eval.c (rb_yield_0): stripped array too much, should remove just + for proc_call(). Tue Sep 12 07:05:24 2000 Wakou Aoyama @@ -98,7 +115,7 @@ Sun Sep 3 23:44:04 2000 Noriaki Harada Sun Sep 3 11:31:53 2000 Takaaki Tateishi - * parse.y (rescue): no assignment was done if rescue body as + * parse.y (rescue): no assignment was done if rescue body was empty. Sat Sep 2 10:52:21 2000 Yukihiro Matsumoto @@ -146,8 +163,7 @@ Wed Aug 30 23:21:20 2000 Yukihiro Matsumoto * numeric.c (rb_num2long): use rb_Integer() instead of independent convert routine. - * eval.c (rb_rescue2): now arbitrary number of exception types can - be specified. + * eval.c (rb_rescue2): now takes arbitrary number of exception types. * object.c (rb_convert_type): use rb_rescue2 now to handle NameError. diff --git a/bignum.c b/bignum.c index cf9128d0b3..3a5fed571c 100644 --- a/bignum.c +++ b/bignum.c @@ -562,7 +562,7 @@ rb_big_eq(x, y) } if (RBIGNUM(x)->sign != RBIGNUM(y)->sign) return Qfalse; if (RBIGNUM(x)->len != RBIGNUM(y)->len) return Qfalse; - if (memcmp(BDIGITS(x),BDIGITS(y),RBIGNUM(y)->len) != 0) return Qfalse; + if (MEMCMP(BDIGITS(x),BDIGITS(y),USHORT,RBIGNUM(y)->len) != 0) return Qfalse; return Qtrue; } diff --git a/eval.c b/eval.c index e7f87051a0..f396638013 100644 --- a/eval.c +++ b/eval.c @@ -815,8 +815,8 @@ static rb_thread_t curr_thread = 0; static VALUE rb_eval _((VALUE,NODE*)); static VALUE eval _((VALUE,VALUE,VALUE,char*,int)); static NODE *compile _((VALUE, char*, int)); -static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int)); +static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int)); static VALUE rb_call _((VALUE,VALUE,ID,int,VALUE*,int)); static VALUE module_setup _((VALUE,NODE*)); @@ -2226,7 +2226,7 @@ rb_eval(self, n) else { result = Qnil; } - result = rb_yield_0(result, 0, 0, Qfalse); + result = rb_yield_0(result, 0, 0, 0); break; case NODE_RESCUE: @@ -3503,14 +3503,14 @@ VALUE rb_yield(val) VALUE val; { - return rb_yield_0(val, 0, 0, Qfalse); + return rb_yield_0(val, 0, 0, 0); } static VALUE rb_f_loop() { for (;;) { - rb_yield_0(Qnil, 0, 0, Qfalse); + rb_yield_0(Qnil, 0, 0, 0); CHECK_INTS; } return Qnil; /* dummy */ @@ -4809,7 +4809,7 @@ yield_under_i(self) PUSH_TAG(PROT_NONE); if ((state = EXEC_TAG()) == 0) { - result = rb_yield_0(self, self, ruby_class, Qfalse); + result = rb_yield_0(self, self, ruby_class, 0); } POP_TAG(); ruby_block = old_block; @@ -4819,7 +4819,7 @@ yield_under_i(self) } /* static block, no need to restore */ ruby_block->frame.cbase = ruby_frame->cbase; - return rb_yield_0(self, self, ruby_class, Qfalse); + return rb_yield_0(self, self, ruby_class, 0); } /* block eval under the class/module context */ @@ -5452,9 +5452,6 @@ errat_setter(val, id, var) set_backtrace(ruby_errinfo, val); } -VALUE rb_f_global_variables(); -VALUE f_instance_variables(); - static VALUE rb_f_local_variables() { @@ -7781,7 +7778,7 @@ rb_thread_yield(arg, th) rb_thread_t th; { scope_dup(ruby_block->scope); - return rb_yield_0(callargs(arg), 0, 0, Qfalse); + return rb_yield_0(callargs(arg), 0, 0, Qtrue); } static VALUE @@ -8335,7 +8332,7 @@ rb_f_catch(dmy, tag) t = rb_to_id(tag); PUSH_TAG(t); if ((state = EXEC_TAG()) == 0) { - val = rb_yield_0(tag, 0, 0, Qfalse); + val = rb_yield_0(tag, 0, 0, 0); } else if (state == TAG_THROW && t == prot_tag->dst) { val = prot_tag->retval; diff --git a/intern.h b/intern.h index 5609c3f8d3..d651b408c4 100644 --- a/intern.h +++ b/intern.h @@ -372,6 +372,7 @@ VALUE rb_cvar_get _((VALUE, ID)); int rb_cvar_defined_singleton _((VALUE, ID)); void rb_cvar_set_singleton _((VALUE, ID, VALUE)); VALUE rb_cvar_get_singleton _((VALUE, ID)); +VALUE rb_mod_class_variables _((VALUE)); /* version.c */ void ruby_show_version _((void)); void ruby_show_copyright _((void)); diff --git a/object.c b/object.c index 3db26148e6..fe9f8adbb9 100644 --- a/object.c +++ b/object.c @@ -1176,6 +1176,7 @@ Init_Object() rb_define_method(rb_cModule, "const_defined?", rb_mod_const_defined, 1); rb_define_private_method(rb_cModule, "remove_const", rb_mod_remove_const, 1); rb_define_private_method(rb_cModule, "method_added", rb_obj_dummy, 1); + rb_define_method(rb_cModule, "class_variables", rb_mod_class_variables, 0); rb_define_method(rb_cClass, "new", rb_class_new_instance, -1); rb_define_method(rb_cClass, "superclass", rb_class_superclass, 0); diff --git a/parse.y b/parse.y index 0cf9194f36..3a273da94e 100644 --- a/parse.y +++ b/parse.y @@ -3397,7 +3397,15 @@ yylex() case '~': /* $~: match-data */ /* fall through */ case '_': /* $_: last read line string */ - local_cnt(c); + c = nextc(); + if (is_identchar(c)) { + tokadd('$'); + tokadd('_'); + break; + } + pushback(c); + c = '_'; + local_cnt('_'); /* fall through */ case '*': /* $*: argv */ case '$': /* $$: pid */ diff --git a/ruby.h b/ruby.h index 6b65d61632..09fb395ace 100644 --- a/ruby.h +++ b/ruby.h @@ -394,6 +394,7 @@ void xfree _((void*)); #define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(n)) #define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n)) #define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n)) +#define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(n)) void rb_glob _((char*,void(*)(),VALUE)); diff --git a/sample/time.rb b/sample/time.rb index f4f4ec4883..1624fdf992 100644 --- a/sample/time.rb +++ b/sample/time.rb @@ -3,6 +3,6 @@ cmd = ARGV.join(" ") b = Time.now system(cmd) e = Time.now -ut, st, cut, cst = Time.times +ut, st, cut, cst = Time.times.to_a total = (e - b).to_f printf STDERR, "%11.1f real %11.1f user %11.1f sys\n", total, cut, cst diff --git a/variable.c b/variable.c index b37c040681..cd9fe0d48e 100644 --- a/variable.c +++ b/variable.c @@ -1167,11 +1167,10 @@ rb_mod_const_of(mod, ary) VALUE mod; VALUE ary; { - rb_mod_const_at(mod, ary); for (;;) { + rb_mod_const_at(mod, ary); mod = RCLASS(mod)->super; if (!mod) break; - rb_mod_const_at(mod, ary); } return ary; } @@ -1488,6 +1487,40 @@ rb_define_class_variable(klass, name, val) rb_cvar_declare(klass, id, val); } +static int +cv_i(key, value, ary) + ID key; + VALUE value; + VALUE ary; +{ + if (rb_is_class_id(key)) { + VALUE kval = rb_str_new2(rb_id2name(key)); + if (!rb_ary_includes(ary, kval)) { + rb_ary_push(ary, kval); + } + } + return ST_CONTINUE; +} + +VALUE +rb_mod_class_variables(obj) + VALUE obj; +{ + VALUE ary = rb_ary_new(); + + if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4) + rb_raise(rb_eSecurityError, "Insecure: can't get metainfo"); + + for (;;) { + if (RCLASS(obj)->iv_tbl) { + st_foreach(RCLASS(obj)->iv_tbl, cv_i, ary); + } + obj = RCLASS(obj)->super; + if (!obj) break; + } + return ary; +} + VALUE rb_iv_get(obj, name) VALUE obj;