[macruby-changes] [3060] MacRuby/trunk

source_changes at macosforge.org source_changes at macosforge.org
Sun Nov 29 19:18:49 PST 2009


Revision: 3060
          http://trac.macosforge.org/projects/ruby/changeset/3060
Author:   lsansonetti at apple.com
Date:     2009-11-29 19:18:46 -0800 (Sun, 29 Nov 2009)
Log Message:
-----------
start tagging non-RObject classes to not use ivar slots + added Module#__properties__ to return the list of Objective-C properties 

Modified Paths:
--------------
    MacRuby/trunk/class.c
    MacRuby/trunk/include/ruby/ruby.h
    MacRuby/trunk/object.c
    MacRuby/trunk/parse.y
    MacRuby/trunk/vm.cpp

Modified: MacRuby/trunk/class.c
===================================================================
--- MacRuby/trunk/class.c	2009-11-28 02:18:14 UTC (rev 3059)
+++ MacRuby/trunk/class.c	2009-11-30 03:18:46 UTC (rev 3060)
@@ -153,9 +153,7 @@
 static VALUE
 rb_objc_alloc_class(const char *name, VALUE super, VALUE flags, VALUE klass)
 {
-    Class ocklass;
     char ocname[128];
-    int version_flag;
 
     if (name == NULL) {
 	static long anon_count = 1;
@@ -165,29 +163,35 @@
 	if (objc_getClass(name) != NULL) {
 	    long count = 1;
 	    snprintf(ocname, sizeof ocname, "RB%s", name);
-	    while (objc_getClass(ocname) != NULL)
+	    while (objc_getClass(ocname) != NULL) {
 		snprintf(ocname, sizeof ocname, "RB%s%ld", name, ++count);
-//	    rb_warning("can't create `%s' as an Objective-C class, because " 
-//		       "it already exists, instead using `%s'", name, ocname);
+	    }
 	}
 	else {
 	    strncpy(ocname, name, sizeof ocname);
 	}
     }
 
-    if (super == 0)
+    if (super == 0) {
 	super = rb_cObject;
+    }
 
-    ocklass = objc_allocateClassPair((Class)super, ocname, sizeof(id));
+    Class ocklass = objc_allocateClassPair((Class)super, ocname, sizeof(id));
     assert(ocklass != NULL);
 
-    version_flag = RCLASS_IS_RUBY_CLASS;
+    long version_flag = RCLASS_IS_RUBY_CLASS;
     if (flags == T_MODULE) {
 	version_flag |= RCLASS_IS_MODULE;
     }
-    if (super == rb_cObject || (RCLASS_VERSION(super) & RCLASS_IS_OBJECT_SUBCLASS) == RCLASS_IS_OBJECT_SUBCLASS) {
+    const long super_version = RCLASS_VERSION(super);
+    if (super == rb_cObject
+	|| (super_version & RCLASS_IS_OBJECT_SUBCLASS)
+	    == RCLASS_IS_OBJECT_SUBCLASS) {
 	version_flag |= RCLASS_IS_OBJECT_SUBCLASS;
     }
+    if ((super_version & RCLASS_NO_IV_SLOTS) == RCLASS_NO_IV_SLOTS) {
+	version_flag |= RCLASS_NO_IV_SLOTS;
+    }	
 
     RCLASS_SET_VERSION(ocklass, version_flag);
 

Modified: MacRuby/trunk/include/ruby/ruby.h
===================================================================
--- MacRuby/trunk/include/ruby/ruby.h	2009-11-28 02:18:14 UTC (rev 3059)
+++ MacRuby/trunk/include/ruby/ruby.h	2009-11-30 03:18:46 UTC (rev 3060)
@@ -558,6 +558,7 @@
 # define RCLASS_SCOPE_PROTECTED	      (1<<25)  /* class opened for protected methods */
 # define RCLASS_SCOPE_MOD_FUNC	      (1<<26)  /* class opened for module_function methods */
 # define RCLASS_KVO_CHECK_DONE	      (1<<27)  /* class created by KVO and flags merged */
+# define RCLASS_NO_IV_SLOTS	      (1<<28)  /* class cannot hold ivar slots (T_DATA & friends) */
 # if defined(__LP64__)
 #  define _PTR_TYPE uint64_t
 #  define RCLASS_VERSION(m) (class_getVersion((Class)m))

Modified: MacRuby/trunk/object.c
===================================================================
--- MacRuby/trunk/object.c	2009-11-28 02:18:14 UTC (rev 3059)
+++ MacRuby/trunk/object.c	2009-11-30 03:18:46 UTC (rev 3060)
@@ -1546,6 +1546,21 @@
     return rb_mod_ancestors_nocopy(self);
 }
 
+static VALUE
+rb_mod_properties_imp(VALUE self, SEL sel)
+{
+    VALUE ary = rb_ary_new();
+    unsigned int count = 0;
+    objc_property_t *list = class_copyPropertyList((Class)self, &count);
+    if (list != NULL) {
+	for (unsigned int i = 0; i < count; i++) {
+	    rb_ary_push(ary, ID2SYM(rb_intern(property_getName(list[i]))));
+	}
+	free(list);
+    }
+    return ary;
+}
+
 /*
  *  call-seq:
  *     mod.freeze
@@ -2882,8 +2897,10 @@
     rb_cBasicObject = (VALUE)objc_duplicateClass((Class)rb_cObject, "BasicObject", 0);
     rb_const_set(rb_cObject, rb_intern("BasicObject"), rb_cBasicObject);
     rb_cModule = boot_defclass("Module", rb_cNSObject);
+    RCLASS_SET_VERSION_FLAG(rb_cModule, RCLASS_NO_IV_SLOTS);
     rb_define_object_special_methods(rb_cModule);
     rb_cClass =  boot_defclass("Class",  rb_cModule);
+    RCLASS_SET_VERSION_FLAG(rb_cClass, RCLASS_NO_IV_SLOTS);
 
     allocCache = rb_vm_get_call_cache(selAlloc);
     initializeCache = rb_vm_get_call_cache(selInitialize);
@@ -3019,6 +3036,7 @@
     rb_objc_define_method(rb_cModule, "name", rb_mod_name, 0);  /* in variable.c */
     rb_objc_define_method(rb_cModule, "ancestors", rb_mod_ancestors_imp, 0);
     rb_objc_define_method(rb_cModule, "__ancestors__", rb_mod_ancestors_all_imp, 0);
+    rb_objc_define_method(rb_cModule, "__properties__", rb_mod_properties_imp, 0);
     VALUE rb_mod_objc_ib_outlet(VALUE, SEL, int, VALUE *);
     rb_objc_define_private_method(rb_cModule, "ib_outlet", rb_mod_objc_ib_outlet, -1); /* in objc.m */
     rb_objc_define_method(rb_cClass, "__meta__?", rb_class_is_meta, 0);

Modified: MacRuby/trunk/parse.y
===================================================================
--- MacRuby/trunk/parse.y	2009-11-28 02:18:14 UTC (rev 3059)
+++ MacRuby/trunk/parse.y	2009-11-30 03:18:46 UTC (rev 3060)
@@ -10607,9 +10607,8 @@
 void
 Init_ripper(void)
 {
-    VALUE Ripper;
-
-    Ripper = rb_define_class("Ripper", rb_cObject);
+    VALUE Ripper = rb_define_class("Ripper", rb_cObject);
+    RCLASS_SET_VERSION_FLAG(Ripper, RCLASS_NO_IV_SLOTS);
     rb_define_const(Ripper, "Version", rb_usascii_str_new2(RIPPER_VERSION));
     rb_objc_define_method(*(VALUE *)Ripper, "alloc", ripper_s_allocate, 0);
     rb_objc_define_method(Ripper, "initialize", ripper_initialize, -1);

Modified: MacRuby/trunk/vm.cpp
===================================================================
--- MacRuby/trunk/vm.cpp	2009-11-28 02:18:14 UTC (rev 3059)
+++ MacRuby/trunk/vm.cpp	2009-11-30 03:18:46 UTC (rev 3060)
@@ -1006,7 +1006,7 @@
     if ((klass_version & RCLASS_IS_RUBY_CLASS) != RCLASS_IS_RUBY_CLASS
 	|| (klass_version & RCLASS_IS_OBJECT_SUBCLASS)
 	    != RCLASS_IS_OBJECT_SUBCLASS
-	|| klass == rb_cClass || klass == rb_cModule) {
+	|| (klass_version & RCLASS_NO_IV_SLOTS) == RCLASS_NO_IV_SLOTS) {
 	return false;
     }
     return true;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20091129/f0774034/attachment.html>


More information about the macruby-changes mailing list