gnustep / libobjc2

Objective-C runtime library intended for use with Clang.
http://www.gnustep.org/
MIT License
439 stars 118 forks source link

Method signature differences vs. Apple runtime #122

Open d235j opened 5 years ago

d235j commented 5 years ago

The GNUstep libobjc2 API does not match Apple documentation. Some of these mismatches cause problems building code that links against the Apple runtime, e.g. Swift. The lack of objc_constructInstance and objc_destructInstance is discussed in https://github.com/gnustep/libobjc2/issues/121. Other than this, the signature differences in objc_lookUpClass and objc_getRequiredClass are the most problematic (Class vs. id).

Apple signature libobjc2 signature
const uint8_t * class_getIvarLayout(Class cls); const char *class_getIvarLayout(Class cls);
void class_setIvarLayout(Class cls, const uint8_t *layout); void class_setIvarLayout(Class cls, const char *layout);
const uint8_t * class_getWeakIvarLayout(Class cls); const char *class_getWeakIvarLayout(Class cls);
void class_setWeakIvarLayout(Class cls, const uint8_t *layout); void class_setWeakIvarLayout(Class cls, const char *layout);
Protocol _Nonnull class_copyProtocolList(Class cls, unsigned int *outCount); Protocol *__unsafe_unretained* class_copyProtocolList(Class cls, unsigned int *outCount);
id objc_constructInstance(Class cls, void *bytes); Unimplemented and necessary
void * objc_destructInstance(id obj); Unimplemented and necessary
id object_copy(id obj, size_t size); Commented out because of legacy GNU runtime lacking size parameter
Class objc_lookUpClass(const char *name); id objc_lookUpClass(const char *name);
Class objc_getRequiredClass(const char *name); id objc_getRequiredClass(const char *name);
Protocol _Nonnull objc_copyProtocolList(unsigned int *outCount); Protocol *__unsafe_unretained*objc_copyProtocolList(unsigned int *outCount);

The following methods are defined in a header not included from <objc/runtime.h>, but are part of the Runtime API:

OBJC_PUBLIC id objc_loadWeak(id object); OBJC_PUBLIC id objc_storeWeak(id addr, id obj);

The following methods have new annotations:

objc_property_t _Nonnull class_copyPropertyList(Class cls, unsigned int outCount); Method _Nonnull class_copyMethodList(Class cls, unsigned int outCount); Ivar object_getInstanceVariable(id obj, const char name, void _Nullable outValue); int objc_getClassList(Class _Nonnull buffer, int bufferCount); Class _Nonnull objc_copyClassList(unsigned int outCount); objc_property_t _Nonnull protocol_copyPropertyList(Protocol proto, unsigned int outCount); id objc_loadWeak(id _Nullable location); id objc_storeWeak(id _Nullable *location, id obj);

The following methods are unimplemented and probably should be implemented at some point: struct objc_method_description * method_getDescription(Method m);

The following methods are unimplemented but should not be necessary: Class objc_getFutureClass(const char name); void objc_setFutureClass (Class cls, const char name); Class objc_duplicateClass(Class original, const char name, size_t extraBytes); void objc_enumerationMutation(id obj); void objc_setEnumerationMutationHandler(void (handler)(id));

davidchisnall commented 5 years ago

I'm happy to take a pull request that updates these for Apple compatibility.

hmelder commented 8 months ago

It would very interesting to implement the required APIs. @davidchisnall what are your plans regarding GCC API deprecation?

davidchisnall commented 8 months ago

Most of the GCC APIs are guarded by an off by default flag, we can remove them at some point. The construct and destruct instance are probably not possible to support because it relies on a runtime that doesn’t add an object header.