summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-08-12 14:28:22 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-08-12 14:28:22 +0200
commitdfe50b2e72ddbd0148870748975f00e7fc662314 (patch)
tree65698a358024d4f82b4235b3944f53cfe5bc0868
parentefa4eaca17fd6c1e19210f069fe9963c185fa200 (diff)
MLKCompiledClosure: Always indirect through a function pointer before doing a call.
-rw-r--r--MLKCompiledClosure.h3
-rw-r--r--MLKCompiledClosure.m14
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