diff --git a/ChangeLog b/ChangeLog index e00bae68b..8f4afa354 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-12-24 Nicola Pero + + * Source/NSObject.m ([+conformsToProtocol:]): Use the new code + only if __GNU_LIBOBJC__ is defined. + * Source/Additions/GSObjCRuntime.m (GSTypesFromSelector): Updated + usage of Modern typed selector API with __GNU_LIBOBJC__. + * Source/GSFFIInvocation.m (gs_find_best_typed_sel): Same. + (gs_objc_msg_forward2): Same. + (GSFFIInvocationCallback): Same. + 2010-12-24 Nicola Pero * Source/NSObject.m ([+conformsToProtocol:]): Fixed to iterate diff --git a/Source/Additions/GSObjCRuntime.m b/Source/Additions/GSObjCRuntime.m index 059faa19b..8e3d94eb6 100644 --- a/Source/Additions/GSObjCRuntime.m +++ b/Source/Additions/GSObjCRuntime.m @@ -166,7 +166,7 @@ GSTypesFromSelector(SEL sel) if (sel == 0) return 0; #ifdef __GNU_LIBOBJC__ - return sel_getType(sel); + return sel_getTypeEncoding(sel); #else return sel_getType_np(sel); #endif diff --git a/Source/GSFFIInvocation.m b/Source/GSFFIInvocation.m index 4b3812b4b..a260d9eeb 100644 --- a/Source/GSFFIInvocation.m +++ b/Source/GSFFIInvocation.m @@ -101,7 +101,7 @@ static INLINE SEL gs_find_best_typed_sel (SEL sel) { #ifdef __GNU_LIBOBJC__ - if (!sel_getType(sel)) + if (!sel_getTypeEncoding(sel)) #else if (!sel_getType_np(sel)) #endif @@ -110,13 +110,15 @@ gs_find_best_typed_sel (SEL sel) if (name) { - SEL tmp_sel = sel_get_any_typed_uid(name); #ifdef __GNU_LIBOBJC__ - if (sel_getType(tmp_sel)) -#else - if (sel_getType_np(tmp_sel)) -#endif + SEL tmp_sel = sel_getTypedSelector(name); + if (tmp_sel) return tmp_sel; +#else + SEL tmp_sel = sel_get_any_typed_uid(name); + if (sel_getType_np(tmp_sel)) + return tmp_sel; +#endif } } return sel; @@ -163,7 +165,7 @@ static IMP gs_objc_msg_forward2 (id receiver, SEL sel) */ sel = gs_find_best_typed_sel(sel); #ifdef __GNU_LIBOBJC__ - sel_type = sel_getType(sel); + sel_type = sel_getTypeEncoding(sel); #else sel_type = sel_getType_np(sel); #endif @@ -556,9 +558,9 @@ GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user) sig = nil; #ifdef __GNU_LIBOBJC__ - if (gs_protocol_selector(sel_getType(selector)) == YES) + if (gs_protocol_selector(sel_getTypeEncoding(selector)) == YES) { - sig = [NSMethodSignature signatureWithObjCTypes: sel_getType(selector)]; + sig = [NSMethodSignature signatureWithObjCTypes: sel_getTypeEncoding(selector)]; } #else if (gs_protocol_selector(sel_getType_np(selector)) == YES) @@ -579,7 +581,7 @@ GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user) { const char *receiverTypes = [sig methodType]; #ifdef __GNU_LIBOBJC__ - const char *runtimeTypes = sel_getType(selector); + const char *runtimeTypes = sel_getTypeEncoding(selector); #else const char *runtimeTypes = sel_getType_np(selector); #endif @@ -615,10 +617,10 @@ GSFFIInvocationCallback(ffi_cif *cif, void *retp, void **args, void *user) selector = gs_find_best_typed_sel (selector); #ifdef __GNU_LIBOBJC__ - if (sel_getType(selector) != 0) + if (sel_getTypeEncoding(selector) != 0) { sig = [NSMethodSignature signatureWithObjCTypes: - sel_getType(selector)]; + sel_getTypeEncoding(selector)]; } #else if (sel_getType_np(selector) != 0) diff --git a/Source/NSObject.m b/Source/NSObject.m index fd2a03378..b8f85b278 100644 --- a/Source/NSObject.m +++ b/Source/NSObject.m @@ -1298,6 +1298,7 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); */ + (BOOL) conformsToProtocol: (Protocol*)aProtocol { +#ifdef __GNU_LIBOBJC__ Class c; /* Iterate over the current class and all the superclasses. */ @@ -1310,6 +1311,13 @@ objc_create_block_classes_as_subclasses_of(Class super) __attribute__((weak)); } return NO; +#else + /* libobjc2 and ObjectiveC2/ have an implementation of + class_conformsToProtocol() which automatically looks up the + protocol in superclasses (unlike the Apple and GNU Objective-C + runtime ones). */ + return class_conformsToProtocol(self, aProtocol); +#endif } /**