From 2fd4c9a9c613326eda6b0837e3bc73fc6210f258 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Wed, 4 Nov 2009 22:25:54 +0000 Subject: [PATCH] The release pooling mechanism is now becoming scary. --- Library.cpp | 6 +++++- ObjectiveC.mk | 2 +- ObjectiveC/Library.mm | 11 +++++++---- todo.txt | 1 + 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Library.cpp b/Library.cpp index bc16967..7a87368 100644 --- a/Library.cpp +++ b/Library.cpp @@ -588,6 +588,7 @@ const char *CYPoolCCYON(apr_pool_t *pool, JSContextRef context, JSObjectRef obje JSValueRef toCYON(CYGetProperty(context, object, toCYON_s)); if (CYIsCallable(context, toCYON)) { JSValueRef value(CYCallAsFunction(context, (JSObjectRef) toCYON, object, 0, NULL)); + _assert(value != NULL); return CYPoolCString(pool, context, value); } @@ -881,7 +882,10 @@ Closure_privateData *CYMakeFunctor_(JSContextRef context, JSObjectRef function, static JSObjectRef CYMakeFunctor(JSContextRef context, JSObjectRef function, const char *type) { Closure_privateData *internal(CYMakeFunctor_(context, function, type, &FunctionClosure_)); - return JSObjectMake(context, Functor_, internal); + JSObjectRef object(JSObjectMake(context, Functor_, internal)); + // XXX: see above notes about needing to leak + JSValueProtect(CYGetJSContext(context), object); + return object; } JSObjectRef CYGetCachedObject(JSContextRef context, JSStringRef name) { diff --git a/ObjectiveC.mk b/ObjectiveC.mk index c2837c5..6f3e14e 100644 --- a/ObjectiveC.mk +++ b/ObjectiveC.mk @@ -1,5 +1,5 @@ filters += ObjectiveC -header += Struct.hpp ObjectiveC/Internal.hpp ObjectiveC/Syntax.hpp +header += Struct.hpp #ObjectiveC/Internal.hpp ObjectiveC/Syntax.hpp code += ObjectiveC/Output.o ObjectiveC/Replace.o ObjectiveC/Library.o Struct.hpp: diff --git a/ObjectiveC/Library.mm b/ObjectiveC/Library.mm index de56719..a4b01f1 100644 --- a/ObjectiveC/Library.mm +++ b/ObjectiveC/Library.mm @@ -4,14 +4,14 @@ #include #endif -#include "ObjectiveC/Internal.hpp" - #ifdef __APPLE__ #include "Struct.hpp" #endif #include +#include "ObjectiveC/Internal.hpp" + #include #include "cycript.hpp" @@ -1297,7 +1297,7 @@ static void CYObjectiveC_CallFunction(JSContextRef context, ffi_cif *cif, void ( throw CYJSError(context, CYCastJSValue(context, error)); } } -static bool CYObjectiveC_PoolFFI(apr_pool_t *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value) { CYPoolTry { +static bool CYObjectiveC_PoolFFI(apr_pool_t *pool, JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, JSValueRef value) { @try { switch (type->primitive) { case sig::object_P: case sig::typename_P: @@ -1313,7 +1313,9 @@ static bool CYObjectiveC_PoolFFI(apr_pool_t *pool, JSContextRef context, sig::Ty } return true; -} CYPoolCatch(false) return /*XXX*/ NULL; } +} @catch (NSException *error ) { + throw CYJSError(context, CYCastJSValue(context, error)); +} } static JSValueRef CYObjectiveC_FromFFI(JSContextRef context, sig::Type *type, ffi_type *ffi, void *data, bool initialize, JSObjectRef owner) { CYPoolTry { switch (type->primitive) { @@ -1421,6 +1423,7 @@ static JSObjectRef CYMakeMessage(JSContextRef context, SEL sel, IMP imp, const c static IMP CYMakeMessage(JSContextRef context, JSValueRef value, const char *type) { JSObjectRef function(CYCastJSObject(context, value)); Closure_privateData *internal(CYMakeFunctor_(context, function, type, &MessageClosure_)); + // XXX: see notes in Library.cpp about needing to leak return reinterpret_cast(internal->GetValue()); } diff --git a/todo.txt b/todo.txt index 5895845..046c0d0 100644 --- a/todo.txt +++ b/todo.txt @@ -20,3 +20,4 @@ errors in another process aren't displayed; to fix this, parse errors should get CYPoolTry/Catch now carefully save the exception after it /no longer needs the exception/... uhh... wtf? throw CYJSError should probably be replaced with CYThrow() across the board figure out what to do about global context refs: I really really want to retain the bastards +the concept of NULL pooling is entirely incorrect and sad... bad... evil... need to work on this... really -- 2.47.2