From 90a3e20fcfe07c24533cce14e1d1dd8a5d611ed6 Mon Sep 17 00:00:00 2001 From: Matthias Benkard Date: Sun, 28 Sep 2008 21:28:56 +0200 Subject: Use GC-aware allocation instead of malloc(3) where appropriate. --- MLKBinaryStreamCharacterStream.m | 2 +- MLKCompiledClosure.m | 15 ++++++++++++++- MLKForeignProcedure.h | 1 - MLKForeignProcedure.m | 14 ++++++++------ MLKForm.m | 10 ++++++++++ 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/MLKBinaryStreamCharacterStream.m b/MLKBinaryStreamCharacterStream.m index 6fc7119..4efe6e7 100644 --- a/MLKBinaryStreamCharacterStream.m +++ b/MLKBinaryStreamCharacterStream.m @@ -66,7 +66,7 @@ { retval = [tmpstr characterAtIndex:0]; [tmpstr release]; - //free (buffer); + //FIXME: ? free (buffer); return retval; } else diff --git a/MLKCompiledClosure.m b/MLKCompiledClosure.m index 9227008..6f61b45 100644 --- a/MLKCompiledClosure.m +++ b/MLKCompiledClosure.m @@ -26,6 +26,10 @@ #import #import +#ifdef __OBJC_GC__ +#import +#endif + #import @@ -36,14 +40,23 @@ { int i; - _data = data; _dataLength = dataLength; _code = code; +#ifdef __OBJC_GC__ + _data = NSAllocateCollectable (dataLength * sizeof(id), NSScannedOption); + for (i = 0; i < _dataLength; i++) + { + _data[i] = data[i]; + } + free (data); +#else + _data = data; for (i = 0; i < _dataLength; i++) { LRETAIN (_data[i]); } +#endif return self; } diff --git a/MLKForeignProcedure.h b/MLKForeignProcedure.h index 160bb7c..cb63d32 100644 --- a/MLKForeignProcedure.h +++ b/MLKForeignProcedure.h @@ -43,5 +43,4 @@ -(NSString *) descriptionForLisp; -(void) dealloc; --(void) finalize; @end diff --git a/MLKForeignProcedure.m b/MLKForeignProcedure.m index ce4ac8a..f268005 100644 --- a/MLKForeignProcedure.m +++ b/MLKForeignProcedure.m @@ -23,6 +23,10 @@ #import #import +#ifdef __OBJC_GC__ +#import +#endif + #ifdef HAVE_FFI_H #include #elif HAVE_FFI_FFI_H @@ -47,7 +51,11 @@ _code = code; _returnType = returnType; +#ifdef __OBJC_GC__ + _argumentTypes = NSAllocateCollectable (sizeof (MLKForeignType) * [argTypes count], NSScannedOption); +#else _argumentTypes = malloc (sizeof (MLKForeignType) * [argTypes count]); +#endif e = [argTypes objectEnumerator]; i = 0; @@ -113,10 +121,4 @@ free (_argumentTypes); [super dealloc]; } - --(void) finalize -{ - free (_argumentTypes); - [super finalize]; -} @end diff --git a/MLKForm.m b/MLKForm.m index 674181b..c7ee3f5 100644 --- a/MLKForm.m +++ b/MLKForm.m @@ -26,6 +26,10 @@ #import #import +#ifdef __OBJC_GC__ +#import +#endif + #include #define MAKE_FORM(OBJECT) \ @@ -489,7 +493,13 @@ argtypes = [[[_tail cdr] cdr] car]; _argc = [argtypes length]; + +#ifdef __OBJC_GC__ + _argumentTypes = NSAllocateCollectable (_argc * sizeof (MLKForeignType), NSScannedOption); +#else _argumentTypes = malloc (_argc * sizeof (MLKForeignType)); +#endif + while (argtypes) { _argumentTypes[i] = MLKForeignTypeWithTypeDesignator ([argtypes car]); -- cgit v1.2.3