[macruby-changes] [3158] MacRuby/trunk/variable.c
source_changes at macosforge.org
source_changes at macosforge.org
Tue Dec 22 19:30:11 PST 2009
Revision: 3158
http://trac.macosforge.org/projects/ruby/changeset/3158
Author: lsansonetti at apple.com
Date: 2009-12-22 19:30:08 -0800 (Tue, 22 Dec 2009)
Log Message:
-----------
fixed some class variables bugs
Modified Paths:
--------------
MacRuby/trunk/variable.c
Modified: MacRuby/trunk/variable.c
===================================================================
--- MacRuby/trunk/variable.c 2009-12-23 02:09:33 UTC (rev 3157)
+++ MacRuby/trunk/variable.c 2009-12-23 03:30:08 UTC (rev 3158)
@@ -1914,31 +1914,53 @@
void
rb_cvar_set(VALUE klass, ID id, VALUE val)
{
- if (RCLASS_META(klass)) {
- klass = (VALUE)objc_getClass(class_getName((Class)klass));
+ klass = unmeta_class(klass);
+
+ // Locate the class where the cvar should be set by looking through the
+ // current class ancestry.
+ VALUE k = klass;
+ while (k != 0) {
+ if (ivar_get(k, id, false, true) != Qundef) {
+ klass = k;
+ break;
+ }
+ k = RCLASS_SUPER(k);
}
+
rb_ivar_set(klass, id, val);
}
-VALUE
-rb_cvar_get2(VALUE klass, ID id, bool check)
+static VALUE
+rb_cvar_get3(VALUE klass, ID id, bool check, bool defined)
{
VALUE orig = klass;
klass = unmeta_class(klass);
- VALUE value = ivar_get(klass, id, false, true);
- if (value == Qundef) {
- if (check) {
- rb_name_error(id,"uninitialized class variable %s in %s",
- rb_id2name(id), rb_class2name(orig));
+
+ // Locate the cvar by looking through the class ancestry.
+ while (klass != 0) {
+ VALUE value = ivar_get(klass, id, false, true);
+ if (value != Qundef) {
+ return defined ? Qtrue : value;
}
- else {
- return Qnil;
- }
+ klass = RCLASS_SUPER(klass);
}
- return value;
+
+ if (check) {
+ rb_name_error(id,"uninitialized class variable %s in %s",
+ rb_id2name(id), rb_class2name(orig));
+ }
+ else {
+ return defined ? Qfalse : Qnil;
+ }
}
VALUE
+rb_cvar_get2(VALUE klass, ID id, bool check)
+{
+ return rb_cvar_get3(klass, id, check, false);
+}
+
+VALUE
rb_cvar_get(VALUE klass, ID id)
{
return rb_cvar_get2(klass, id, true);
@@ -1947,8 +1969,7 @@
VALUE
rb_cvar_defined(VALUE klass, ID id)
{
- klass = unmeta_class(klass);
- return ivar_get(klass, id, false, true) == Qundef ? Qfalse : Qtrue;
+ return rb_cvar_get3(klass, id, false, true);
}
void
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091222/16d581ca/attachment-0001.html>
More information about the macruby-changes
mailing list