Le 7 janv. 2010 à 15:44, David Chisnall a écrit :

> On 7 Jan 2010, at 14:35, Quentin Mathé wrote:
>
>> Hi David,
>> class_getSuperclass() seems to be correctly implemented in
>> ObjectiveC2.framework but not in libobjc2.
>> In libobjc2, it calls class_get_super_class() which doesn't work with
>> a metaclass as argument.
>
> Please read the commit log or the code.  class_get_super_class() in
> libobjc2 does work correctly with metaclasses and unresolved classes.

Oops, sorry, I messed up with svn update and read an outdated version.

> I made this change because I noticed that the runtime was using
> class_get_super_class() in a few places and expecting it to actually
> work, where it was in fact only working in the common case and failing
> in unusual ones.  Exception handling is one example of this; throwing
> an instance of an unresolved class (easy to do if you throw a constant
> string) will fail with the GCC runtime.  The new runtime does not have
> this problem.

ok.

>> I think several similar new libobjc2 functions are currently broken
>> when you pass a metaclass because they call the old libobjc1 API  
>> which
>> doesn't accept metaclasses as classes.
>> Unless libobjc2 has changed the semantic of CLS_ISCLASS, CLS_ISCLASS
>> (aMetaclass) counterintuitively returns false. Since the old libobjc1
>> API checks the argument with CLS_ISCLASS in functions such as
>> class_get_super_class() or class_get_instance_size(), new APIs such  
>> as
>> class_getSuperclass() and class_getInstanceSize() are not equivalent.
>
> I've fixed class_getInstanceSize to just return the instance_size
> field.  Please report any other failures.

Here are few other ones: class_getName(), class_getVersion() and  
class_setVersion() which probably suffer from the same issue. I  
checked this libobjc2 code:
http://svn.gna.org/viewcvs/gnustep/libs/libobjc2/trunk/objc/objc-api.h?rev=29224&view=markup
http://svn.gna.org/viewcvs/gnustep/libs/libobjc2/trunk/objc/objc-api.h?rev=29224&view=auto

And I ran this code on Mac OS X:

        ETLog(@"Version %i", class_getVersion(objc_getMetaClass 
("NSCountedSet")));
        class_setVersion(objc_getMetaClass("NSCountedSet"), 300);
        ETLog(@"Version %i", class_getVersion(objc_getClass("NSCountedSet")));
        ETLog(@"Version %i", class_getVersion(objc_getMetaClass 
("NSCountedSet")));
        ETLog(@"Name %s", class_getName(objc_getMetaClass("NSCountedSet")));

the output is:

Version 7
Version 1
Version 300
Name NSCountedSet

Quentin.
_______________________________________________
Etoile-discuss mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-discuss

Répondre à