Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method signature differences vs. Apple runtime #122

Open
d235j opened this issue Aug 7, 2019 · 3 comments
Open

Method signature differences vs. Apple runtime #122

d235j opened this issue Aug 7, 2019 · 3 comments

Comments

@d235j
Copy link

d235j commented Aug 7, 2019

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 #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
Copy link
Member

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

@hmelder
Copy link
Collaborator

hmelder commented Feb 14, 2024

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

@davidchisnall
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants