From 1e5d404935dfe5bdedff5c857b1ec77ac6587387 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 15 Feb 2002 06:14:26 +0000 Subject: * eval.c (rb_eval): replace rb_cvar_declare() by rb_cvar_set(). * eval.c (assign): ditto. * variable.c (rb_cvar_set): 4th argument (warn) added; define new class variable if it's not defined yet. * variable.c (rb_cvar_declare): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 +++++++++++ eval.c | 8 ++++---- intern.h | 3 +-- variable.c | 36 +++++------------------------------- version.h | 4 ++-- 5 files changed, 23 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 91fa21caff..1d3ba18640 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Fri Feb 15 14:40:38 2002 Yukihiro Matsumoto + + * eval.c (rb_eval): replace rb_cvar_declare() by rb_cvar_set(). + + * eval.c (assign): ditto. + + * variable.c (rb_cvar_set): 4th argument (warn) added; define new + class variable if it's not defined yet. + + * variable.c (rb_cvar_declare): removed. + Fri Feb 15 13:36:58 2002 Yukihiro Matsumoto * bignum.c (rb_big_rshift): should properly convert the nagative diff --git a/eval.c b/eval.c index c53889031e..1bc78c72d1 100644 --- a/eval.c +++ b/eval.c @@ -2864,12 +2864,12 @@ rb_eval(self, n) if (ruby_verbose && FL_TEST(ruby_cbase, FL_SINGLETON)) { rb_warn("declaring singleton class variable"); } - rb_cvar_declare(ruby_cbase, node->nd_vid, result); + rb_cvar_set(ruby_cbase, node->nd_vid, result, Qtrue); break; case NODE_CVASGN: result = rb_eval(self, node->nd_value); - rb_cvar_set(ruby_cbase, node->nd_vid, result); + rb_cvar_set(ruby_cbase, node->nd_vid, result, Qfalse); break; case NODE_LVAR: @@ -3915,11 +3915,11 @@ assign(self, lhs, val, pcall) if (ruby_verbose && FL_TEST(ruby_cbase, FL_SINGLETON)) { rb_warn("declaring singleton class variable"); } - rb_cvar_declare(ruby_cbase, lhs->nd_vid, val); + rb_cvar_set(ruby_cbase, lhs->nd_vid, val, Qtrue); break; case NODE_CVASGN: - rb_cvar_set(ruby_cbase, lhs->nd_vid, val); + rb_cvar_set(ruby_cbase, lhs->nd_vid, val, Qfalse); break; case NODE_MASGN: diff --git a/intern.h b/intern.h index b5d0814527..62549f84fd 100644 --- a/intern.h +++ b/intern.h @@ -422,9 +422,8 @@ void rb_const_set _((VALUE, ID, VALUE)); void rb_const_assign _((VALUE, ID, VALUE)); VALUE rb_mod_constants _((VALUE)); void rb_autoload_load _((ID)); -void rb_cvar_declare _((VALUE, ID, VALUE)); VALUE rb_cvar_defined _((VALUE, ID)); -void rb_cvar_set _((VALUE, ID, VALUE)); +void rb_cvar_set _((VALUE, ID, VALUE, int)); VALUE rb_cvar_get _((VALUE, ID)); void rb_cv_set _((VALUE, const char *, VALUE)); VALUE rb_cv_get _((VALUE, const char *)); diff --git a/variable.c b/variable.c index 656497e742..c63fd573f0 100644 --- a/variable.c +++ b/variable.c @@ -1440,10 +1440,11 @@ cvar_override_check(id, a) } void -rb_cvar_set(klass, id, val) +rb_cvar_set(klass, id, val, warn) VALUE klass; ID id; VALUE val; + int warn; { VALUE tmp; @@ -1453,34 +1454,7 @@ rb_cvar_set(klass, id, val) if (OBJ_FROZEN(tmp)) rb_error_frozen("class/module"); if (!OBJ_TAINTED(tmp) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't modify class variable"); - st_insert(RCLASS(tmp)->iv_tbl,id,val); - if (ruby_verbose) { - cvar_override_check(id, tmp); - } - return; - } - tmp = RCLASS(tmp)->super; - } - - rb_name_error(id,"uninitialized class variable %s in %s", - rb_id2name(id), rb_class2name(klass)); -} - -void -rb_cvar_declare(klass, id, val) - VALUE klass; - ID id; - VALUE val; -{ - VALUE tmp; - - tmp = klass; - while (tmp) { - if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) { - if (OBJ_FROZEN(tmp)) rb_error_frozen("class/module"); - if (!OBJ_TAINTED(tmp) && rb_safe_level() >= 4) - rb_raise(rb_eSecurityError, "Insecure: can't modify class variable"); - if (ruby_verbose && klass != tmp) { + if (warn && ruby_verbose && klass != tmp) { rb_warning("already initialized class variable %s", rb_id2name(id)); } st_insert(RCLASS(tmp)->iv_tbl,id,val); @@ -1549,7 +1523,7 @@ rb_cv_set(klass, name, val) if (!rb_is_class_id(id)) { rb_name_error(id, "wrong class variable name %s", name); } - rb_cvar_set(klass, id, val); + rb_cvar_set(klass, id, val, Qfalse); } VALUE @@ -1575,7 +1549,7 @@ rb_define_class_variable(klass, name, val) if (!rb_is_class_id(id)) { rb_name_error(id, "wrong class variable name %s", name); } - rb_cvar_declare(klass, id, val); + rb_cvar_set(klass, id, val, Qtrue); } static int diff --git a/version.h b/version.h index 4e3370832a..134471fe93 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.7.2" -#define RUBY_RELEASE_DATE "2002-02-14" +#define RUBY_RELEASE_DATE "2002-02-15" #define RUBY_VERSION_CODE 172 -#define RUBY_RELEASE_CODE 20020214 +#define RUBY_RELEASE_CODE 20020215 -- cgit v1.2.3