From 588cf8382f6194d3c3eb6f09e17a1be73f5d2cda Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 9 Nov 2015 09:41:39 +0000 Subject: [PATCH] GNUstep does not export object_getClass *sigh* :(. --- Execute.cpp | 4 ++++ JavaScript.hpp | 2 ++ ObjectiveC/Library.mm | 21 +++++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Execute.cpp b/Execute.cpp index 1c7b833..deaeeda 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -261,6 +261,10 @@ JSObjectRef CYMakeStruct(JSContextRef context, void *data, sig::Type *type, ffi_ } static void *CYCastSymbol(const char *name) { + for (CYHook *hook : GetHooks()) + if (hook->CastSymbol != NULL) + if (void *value = (*hook->CastSymbol)(name)) + return value; return dlsym(RTLD_DEFAULT, name); } diff --git a/JavaScript.hpp b/JavaScript.hpp index e4af17b..0a3c431 100644 --- a/JavaScript.hpp +++ b/JavaScript.hpp @@ -131,6 +131,8 @@ struct CYHook { bool (*PoolFFI)(CYPool *, JSContextRef, sig::Type *, ffi_type *, void *, JSValueRef); JSValueRef (*FromFFI)(JSContextRef, sig::Type *, ffi_type *, void *, bool, JSObjectRef); + + void *(*CastSymbol)(const char *); }; struct CYRegisterHook { diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index bd2946a..e012757 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -2336,11 +2336,14 @@ JSValueRef CYSendMessage(CYPool &pool, JSContextRef context, id self, Class _cla imp = NULL; CYPoolTry { - NSMethodSignature *method([self methodSignatureForSelector:_cmd]); - if (method == nil) - throw CYJSError(context, "unrecognized selector %s sent to object %p", sel_getName(_cmd), self); - type = CYPoolCString(pool, context, [method _typeString]); + if (NSMethodSignature *method = [self methodSignatureForSelector:_cmd]) + type = CYPoolCString(pool, context, [method _typeString]); + else + type = NULL; } CYPoolCatch(NULL) + + if (type == NULL) + throw CYJSError(context, "unrecognized selector %s sent to object %p", sel_getName(_cmd), self); } void *setup[2]; @@ -2961,6 +2964,15 @@ void CYObjectiveC_SetupContext(JSContextRef context) { CYPoolTry { CYSetPrototype(context, CYCastJSObject(context, CYGetProperty(context, Selector, prototype_s)), Function_prototype); } CYPoolCatch() } +static void *CYObjectiveC_CastSymbol(const char *name) { + if (false); +#ifdef __GNU_LIBOBJC__ + else if (strcmp(name, "object_getClass") == 0) + return reinterpret_cast(&object_getClass); +#endif + return NULL; +} + static CYHook CYObjectiveCHook = { &CYObjectiveC_ExecuteStart, &CYObjectiveC_ExecuteEnd, @@ -2969,6 +2981,7 @@ static CYHook CYObjectiveCHook = { &CYObjectiveC_SetupContext, &CYObjectiveC_PoolFFI, &CYObjectiveC_FromFFI, + &CYObjectiveC_CastSymbol, }; CYRegisterHook CYObjectiveC(&CYObjectiveCHook); -- 2.49.0