summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-02-18 06:59:36 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-02-18 06:59:36 +0000
commit3d6fde336547463461180b9be5b1730194764d9c (patch)
treec268af56267dcc487f65cec821380293b37f4749 /variable.c
parentf0886df4a4d017ed3655b1e1a4a4df2ebaa8c71e (diff)
2000-02-18
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c101
1 files changed, 97 insertions, 4 deletions
diff --git a/variable.c b/variable.c
index 4d1ec0644c..c8bcfb0393 100644
--- a/variable.c
+++ b/variable.c
@@ -1216,24 +1216,34 @@ rb_const_defined(klass, id)
return rb_autoload_defined(id);
}
-void
-rb_const_set(klass, id, val)
+static void
+rb_mod_av_set(klass, id, val, dest)
VALUE klass;
ID id;
VALUE val;
+ char *dest;
{
if (!OBJ_TAINTED(klass) && rb_safe_level() >= 4)
- rb_raise(rb_eSecurityError, "Insecure: can't set constant");
+ rb_raise(rb_eSecurityError, "Insecure: can't set %s", dest);
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
if (!RCLASS(klass)->iv_tbl) {
RCLASS(klass)->iv_tbl = st_init_numtable();
}
else if (st_lookup(RCLASS(klass)->iv_tbl, id, 0)) {
- rb_warn("already initialized constant %s", rb_id2name(id));
+ rb_warn("already initialized %s %s", dest, rb_id2name(id));
}
st_insert(RCLASS(klass)->iv_tbl, id, val);
}
+
+void
+rb_const_set(klass, id, val)
+ VALUE klass;
+ ID id;
+ VALUE val;
+{
+ rb_mod_av_set(klass, id, val, "constant");
+}
void
rb_const_assign(klass, id, val)
@@ -1302,6 +1312,89 @@ rb_define_global_const(name, val)
rb_define_const(rb_cObject, name, val);
}
+void
+rb_shared_variable_declare(klass, id, val)
+ VALUE klass;
+ ID id;
+ VALUE val;
+{
+ rb_mod_av_set(klass, id, val, "shared variable");
+}
+
+void
+rb_shared_variable_set(klass, id, val)
+ VALUE klass;
+ ID id;
+ VALUE val;
+{
+ VALUE value;
+ VALUE tmp;
+
+ tmp = klass;
+ while (tmp) {
+ if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) {
+ st_insert(RCLASS(tmp)->iv_tbl,id,val);
+ return;
+ }
+ tmp = RCLASS(tmp)->super;
+ }
+
+ rb_raise(rb_eNameError,"uninitialized shared variable %s",rb_id2name(id));
+}
+
+VALUE
+rb_shared_variable_get(klass, id)
+ VALUE klass;
+ ID id;
+{
+ VALUE value;
+ VALUE tmp;
+
+ tmp = klass;
+ while (tmp) {
+ if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) {
+ return value;
+ }
+ tmp = RCLASS(tmp)->super;
+ }
+
+ rb_raise(rb_eNameError,"uninitialized shared variable %s",rb_id2name(id));
+ return Qnil; /* not reached */
+}
+
+int
+rb_shared_variable_defined(klass, id)
+ VALUE klass;
+ ID id;
+{
+ VALUE value;
+ VALUE tmp;
+
+ tmp = klass;
+ while (tmp) {
+ if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) {
+ return Qtrue;
+ }
+ tmp = RCLASS(tmp)->super;
+ }
+
+ return Qfalse;
+}
+
+void
+rb_define_shared_variable(klass, name, val)
+ VALUE klass;
+ const char *name;
+ VALUE val;
+{
+ ID id = rb_intern(name);
+
+ if (!rb_is_shared_id(id)) {
+ rb_raise(rb_eNameError, "wrong shared variable name %s", name);
+ }
+ rb_shared_variable_declare(klass, id, val);
+}
+
VALUE
rb_iv_get(obj, name)
VALUE obj;