[Rubycocoa-devel 277] Re: pass-by-reference arguments support + class hierarchy

Back to archive index

Laurent Sansonetti lsans****@apple*****
Wed Jun 7 23:23:55 JST 2006


On Jun 6, 2006, at 9:00 PM, Jonathan Paisley wrote:

> On 5 Jun 2006, at 17:17, Laurent Sansonetti wrote:
>
>> 2/ class hierarchy
>>
>> The current version of RubyCocoa does not respect the Objective-C
>> class hierarchy when creating the Ruby proxy classes. For example,
>> OSX::NSString does not inherit from OSX::NSObject.
>
> I haven't had a chance to figure out the exact cause yet, but the  
> class name doesn't show up properly when one of these is inspected.  
> For example:
>
>   p OSX::NSArray.array
>   #<:0x93048a class='NSCFArray' id=0x2a20e30>
>
> Note that there's nothing between the < and :.
>

I found that the following patch fixes this problem that was surely  
introduced with this new inheritance, as objects that directly  
inherits from OSX:ObjcID do not have this problem (in this case,  
NSArray.array returns a NSCFArray!).

Apparently rb_class2name() calls rb_class_real() on the class and  
this picks the right class, rb_mod_name() does not do that. Also,  
rb_class2name() returns us a C string that we don't have to convert,  
and according to the code it does more logic if classname() returns  
nil, so I believe the patch is good (I applied it in the branch).

--- ../framework/src/objc/cls_objcid.m  6 Jun 2006 15:39:40  
-0000       1.5.2.3
+++ ../framework/src/objc/cls_objcid.m  7 Jun 2006 14:19:40 -0000
@@ -101,9 +101,8 @@
    id ocid = OBJCID_ID(rcv);
    id pool = [[NSAutoreleasePool alloc] init];
    const char* class_desc = [[[ocid class] description] UTF8String];
-  VALUE rbclass_name = rb_mod_name(CLASS_OF(rcv));
    snprintf(s, sizeof(s), "#<%s:0x%lx class='%s' id=%p>",
-          STR2CSTR(rbclass_name),
+          rb_class2name(CLASS_OF(rcv)),
            NUM2ULONG(rb_obj_id(rcv)),
            class_desc, ocid);
    result = rb_str_new2(s);

Laurent



More information about the Rubycocoa-devel mailing list
Back to archive index