[macruby-changes] [430] MacRuby/branches/lrz_unstable

source_changes at macosforge.org source_changes at macosforge.org
Tue Aug 12 21:50:29 PDT 2008


Revision: 430
          http://trac.macosforge.org/projects/ruby/changeset/430
Author:   lsansonetti at apple.com
Date:     2008-08-12 21:50:29 -0700 (Tue, 12 Aug 2008)
Log Message:
-----------
wip

Modified Paths:
--------------
    MacRuby/branches/lrz_unstable/class.c
    MacRuby/branches/lrz_unstable/object.c
    MacRuby/branches/lrz_unstable/vm_eval.c
    MacRuby/branches/lrz_unstable/vm_method.c

Modified: MacRuby/branches/lrz_unstable/class.c
===================================================================
--- MacRuby/branches/lrz_unstable/class.c	2008-08-13 03:43:15 UTC (rev 429)
+++ MacRuby/branches/lrz_unstable/class.c	2008-08-13 04:50:29 UTC (rev 430)
@@ -307,7 +307,50 @@
 {
     VALUE klass = RBASIC(obj)->klass;
 #if WITH_OBJC
-    return klass;
+    if (!RCLASS_SINGLETON(klass)) {
+	return klass;
+    }
+    else {
+	/* copy singleton(unnamed) class */
+	VALUE clone = rb_objc_create_class(NULL, RCLASS_SUPER(klass));
+
+	CFMutableDictionaryRef ivar_dict = rb_class_ivar_dict(klass);
+	if (ivar_dict != NULL) {
+	    CFMutableDictionaryRef cloned_ivar_dict;
+
+	    cloned_ivar_dict = CFDictionaryCreateMutableCopy(NULL, 0, (CFDictionaryRef)ivar_dict);
+	    rb_class_ivar_set_dict(clone, cloned_ivar_dict);
+	    CFMakeCollectable(cloned_ivar_dict);
+	}
+
+	Method *methods;
+	unsigned i, methods_count;
+	methods = class_copyMethodList((Class)klass, &methods_count);
+	if (methods != NULL) {
+	    for (i = 0; i < methods_count; i++) {
+		Method method = methods[i], method2;
+		method2 = class_getInstanceMethod((Class)clone, method_getName(method));
+		if (method2 != class_getInstanceMethod((Class)RCLASS_SUPER(clone), method_getName(method))) {
+		    method_setImplementation(method2, method_getImplementation(method));
+		}
+		else {
+		    assert(class_addMethod((Class)clone, 
+				method_getName(method), 
+				method_getImplementation(method), 
+				method_getTypeEncoding(method)));
+		}
+	    }
+	    free(methods);
+	}
+
+	rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);
+	if (RCLASS_SUPER(clone) == rb_cNSObject) {
+	    RCLASS_VERSION(clone) ^= RCLASS_IS_OBJECT_SUBCLASS;
+	}
+	RCLASS_SET_VERSION_FLAG(clone, RCLASS_IS_SINGLETON);
+
+	return clone;
+    }
 #else
     if (!FL_TEST(klass, FL_SINGLETON))
 	return klass;

Modified: MacRuby/branches/lrz_unstable/object.c
===================================================================
--- MacRuby/branches/lrz_unstable/object.c	2008-08-13 03:43:15 UTC (rev 429)
+++ MacRuby/branches/lrz_unstable/object.c	2008-08-13 04:50:29 UTC (rev 430)
@@ -309,6 +309,7 @@
     switch (TYPE(obj)) {
 	case T_NATIVE:
 	    clone = rb_obj_alloc(rb_obj_class(obj));
+	    RBASIC(clone)->klass = rb_singleton_class_clone(obj);
 	    break;
 	case T_CLASS:
 	case T_MODULE:

Modified: MacRuby/branches/lrz_unstable/vm_eval.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_eval.c	2008-08-13 03:43:15 UTC (rev 429)
+++ MacRuby/branches/lrz_unstable/vm_eval.c	2008-08-13 04:50:29 UTC (rev 430)
@@ -199,12 +199,12 @@
 
     if (argc > 0 && mid != ID_ALLOCATOR) {
 	const char *mid_str;
-	char buf[512];
+	char buf[100];
 	size_t len;
 
 	mid_str = rb_id2name(mid);
 	len = strlen(mid_str);
-	if (len > 1 && mid_str[len - 1] == '=' && isalpha(mid_str[len - 2])) {
+	if (argc == 1 && len > 1 && mid_str[len - 1] == '=' && isalpha(mid_str[len - 2])) {
 	    assert(len + 3 < sizeof(buf));
 	    buf[0] = 's'; 
 	    buf[1] = 'e'; 
@@ -213,11 +213,12 @@
 	    strlcpy(&buf[4], &mid_str[1], len - 1);
 	    buf[len + 2] = ':';
 	    buf[len + 3] = '\0';
+	    mid = rb_intern(buf);
 	}
 	else if (mid_str[len - 1] != ':') {
 	    snprintf(buf, sizeof buf, "%s:", mid_str);
+	    mid = rb_intern(buf);
 	}
-	mid = rb_intern(buf);
     }
 
     method = rb_objc_method_node(klass, mid, &imp, &sel);    

Modified: MacRuby/branches/lrz_unstable/vm_method.c
===================================================================
--- MacRuby/branches/lrz_unstable/vm_method.c	2008-08-13 03:43:15 UTC (rev 429)
+++ MacRuby/branches/lrz_unstable/vm_method.c	2008-08-13 04:50:29 UTC (rev 430)
@@ -316,7 +316,7 @@
 {
 #if WITH_OBJC
     NODE *node = rb_objc_method_node(klass, id, NULL, NULL);
-    if (node == NULL) {
+    if (node == NULL && id != ID_ALLOCATOR) {
 	const char *id_str = rb_id2name(id);
 	size_t slen = strlen(id_str);
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080812/110dedcf/attachment.html 


More information about the macruby-changes mailing list