From 2e862b3da8a84b110b849190e37f4a530c83941a Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 11 Nov 2015 01:08:17 -0800 Subject: [PATCH] Isolate ffi_call uses to only one common function. --- Execute.cpp | 16 +++++++++------- JavaScript.hpp | 3 ++- ObjectiveC/Library.mm | 4 ++-- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Execute.cpp b/Execute.cpp index a3c69f5..57a9ae9 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -994,6 +994,10 @@ static void Struct_getPropertyNames(JSContextRef context, JSObjectRef object, JS } } +void CYCallFunction(CYPool &pool, JSContextRef context, ffi_cif *cif, void (*function)(), void *value, void **values) { + ffi_call(cif, function, value, values); +} + JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, void *setup[], size_t count, const JSValueRef arguments[], bool initialize, sig::Signature *signature, ffi_cif *cif, void (*function)()) { if (setups + count != signature->count - 1) throw CYJSError(context, "incorrect number of arguments to ffi function"); @@ -1012,15 +1016,13 @@ JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, voi uint8_t value[cif->rtype->size]; + void (*call)(CYPool &, JSContextRef, ffi_cif *, void (*)(), void *, void **) = &CYCallFunction; + // XXX: this only supports one hook, but it is a bad idea anyway for (CYHook *hook : GetHooks()) - if (hook->CallFunction != NULL) { - // XXX: this only supports one hook, but it is a bad idea anyway - (*hook->CallFunction)(context, cif, function, value, values); - goto from; - } - ffi_call(cif, function, value, values); + if (hook->CallFunction != NULL) + call = hook->CallFunction; - from: + call(pool, context, cif, function, value, values); return CYFromFFI(context, signature->elements[0].type, cif->rtype, value, initialize); } diff --git a/JavaScript.hpp b/JavaScript.hpp index 6ee7d9d..b658a51 100644 --- a/JavaScript.hpp +++ b/JavaScript.hpp @@ -112,6 +112,7 @@ _finline Type_ CYCastPointer(JSContextRef context, JSValueRef value) { void CYPoolFFI(CYPool *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value); JSValueRef CYFromFFI(JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, bool initialize = false, JSObjectRef owner = NULL); +void CYCallFunction(CYPool &pool, JSContextRef context, ffi_cif *cif, void (*function)(), void *value, void **values); JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, void *setup[], size_t count, const JSValueRef arguments[], bool initialize, sig::Signature *signature, ffi_cif *cif, void (*function)()); bool CYIsCallable(JSContextRef context, JSValueRef value); @@ -124,7 +125,7 @@ struct CYHook { void *(*ExecuteStart)(JSContextRef); void (*ExecuteEnd)(JSContextRef, void *); - void (*CallFunction)(JSContextRef, ffi_cif *, void (*)(), uint8_t *, void **); + void (*CallFunction)(CYPool &, JSContextRef, ffi_cif *, void (*)(), void *, void **); void (*Initialize)(); void (*SetupContext)(JSContextRef); diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index e68fb1b..68cf70d 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -1454,8 +1454,8 @@ void CYObjectiveC_ExecuteEnd(JSContextRef context, void *handle) { CYSadTry { return [(NSAutoreleasePool *) handle release]; } CYSadCatch() } -static void CYObjectiveC_CallFunction(JSContextRef context, ffi_cif *cif, void (*function)(), uint8_t *value, void **values) { CYSadTry { - ffi_call(cif, function, value, values); +static void CYObjectiveC_CallFunction(CYPool &pool, JSContextRef context, ffi_cif *cif, void (*function)(), void *value, void **values) { CYSadTry { + CYCallFunction(pool, context, cif, function, value, values); } CYSadCatch() } #ifdef __APPLE__ -- 2.45.2