Skip to content

Commit

Permalink
* eval.c (rb_eval): replace rb_cvar_declare() by rb_cvar_set().
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
matz committed Feb 15, 2002
1 parent 289430e commit 1e5d404
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 39 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Fri Feb 15 14:40:38 2002 Yukihiro Matsumoto <[email protected]>

* 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 <[email protected]>

* bignum.c (rb_big_rshift): should properly convert the nagative
Expand Down
8 changes: 4 additions & 4 deletions eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions intern.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 *));
Expand Down
36 changes: 5 additions & 31 deletions variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions version.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1e5d404

Please sign in to comment.