diff options
-rw-r--r-- | MLKCompiledClosure.h | 3 | ||||
-rw-r--r-- | MLKCompiledClosure.m | 14 |
2 files changed, 13 insertions, 4 deletions
diff --git a/MLKCompiledClosure.h b/MLKCompiledClosure.h index a4498d2..53267b2 100644 --- a/MLKCompiledClosure.h +++ b/MLKCompiledClosure.h @@ -27,8 +27,9 @@ @interface MLKCompiledClosure : NSObject <MLKFuncallable> { int _dataLength; - id (*_code)(); + id (**_code)(); id *_data; + BOOL _ownPointer; // do we own the _code pointer cell? } -(id) initWithCode:(void *)code diff --git a/MLKCompiledClosure.m b/MLKCompiledClosure.m index 35c8aca..b70fa03 100644 --- a/MLKCompiledClosure.m +++ b/MLKCompiledClosure.m @@ -38,7 +38,10 @@ _data = data; _dataLength = dataLength; - _code = code; + _ownPointer = YES; + + _code = malloc (sizeof (id (*)())); + *_code = code; for (i = 0; i < _dataLength; i++) { @@ -86,7 +89,7 @@ format:@"FFI type is invalid (this is probably a bug)."]; } - ffi_call (&cif, FFI_FN (_code), &return_value, (void**)argv); + ffi_call (&cif, FFI_FN (*_code), &return_value, (void**)argv); // FIXME return [NSArray arrayWithObject:nullify(return_value)]; @@ -108,11 +111,16 @@ [super dealloc]; - // FIXME: Decrease refcount of _code. + // FIXME: Decrease refcount of *_code. Note: When releasing *_code, + // also release _code regardless of whether we own it. + for (i = 0; i < _dataLength; i++) { LRELEASE (_data[i]); } free (_data); + + if (_ownPointer) + free (_code); } @end |