diff --git a/ChangeLog b/ChangeLog index 9600780..4caa7c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,20 @@ -2003 Aug 13 +2003 Sep 24 Stefan Urbanek + + * STEnvironmentDescription: guard initialisation in Autorelease pool + +2003 Sep 23 Stefan Urbanek + + * STEngine: setValueForOption: added + +2003 Aug 13 Stefan Urbanek * Version 0.8.0 -2003 Aug 9 +2003 Aug 9 Stefan Urbanek * Removed compiler warnings in StepTalk.framework, Smalltalk and Tools -2003 Aug 6 +2003 Aug 6 Stefan Urbanek * Frameworks: new directory * Changed StepTalk from library to framework diff --git a/Frameworks/StepTalk/NSInvocation+additions.m b/Frameworks/StepTalk/NSInvocation+additions.m index 8f5fc30..35f2eec 100644 --- a/Frameworks/StepTalk/NSInvocation+additions.m +++ b/Frameworks/StepTalk/NSInvocation+additions.m @@ -51,6 +51,8 @@ static Class NSValue_class = nil; @" is number value '%@'", object);\ break +/** This method is a factory method, that means that you have to release the + object when you no longer need it. */ id STObjectFromValueOfType(void *value, const char *type) { id object; @@ -264,6 +266,8 @@ void STGetValueOfTypeFromObject(void *value, const char *type, id anObject) [self setArgument:(void *)value atIndex:anIndex]; NSZoneFree(STMallocZone,value); } + + - (id)getArgumentAsObjectAtIndex:(int)anIndex { const char *type; diff --git a/Frameworks/StepTalk/STEngine.h b/Frameworks/StepTalk/STEngine.h index 765adae..ceb3d6f 100644 --- a/Frameworks/StepTalk/STEngine.h +++ b/Frameworks/StepTalk/STEngine.h @@ -54,6 +54,9 @@ - (BOOL)understandsCode:(NSString *)code; +- (void)setValue:(id)anObject forOption:(NSString *)anOption; +- (id)valueForOption:(NSString *)anOption; + /* Methods */ - (STMethod *)methodFromSource:(NSString *)sourceString forReceiver:(id)receiver diff --git a/Frameworks/StepTalk/STEngine.m b/Frameworks/StepTalk/STEngine.m index 61a5f93..aea01b1 100644 --- a/Frameworks/StepTalk/STEngine.m +++ b/Frameworks/StepTalk/STEngine.m @@ -146,5 +146,17 @@ void _STInitMallocZone(void) [self subclassResponsibility:_cmd]; return nil; } +/** Set engine specific option. Refer to particuliar language engine + documentation for more information. */ +- (void)setValue:(id)anObject forOption:(NSString *)anOption +{ + /* do nothing */ +} +/** Returs a value for engine specific option */ +- (id)valueForOption:(NSString *)anOption +{ + /* do nothing */ + return nil; +} @end diff --git a/Frameworks/StepTalk/STEnvironmentDescription.m b/Frameworks/StepTalk/STEnvironmentDescription.m index 0e81c9e..c05dbe4 100644 --- a/Frameworks/StepTalk/STEnvironmentDescription.m +++ b/Frameworks/StepTalk/STEnvironmentDescription.m @@ -39,6 +39,7 @@ #import #import #import +#import static NSDictionary *dictForDescriptionWithName(NSString *defName) { @@ -149,6 +150,7 @@ static NSDictionary *dictForDescriptionWithName(NSString *defName) - (void)updateFromDictionary:(NSDictionary *)def { + NSAutoreleasePool *pool = [NSAutoreleasePool new]; NSString *str; BOOL saveFlag = restriction; @@ -190,6 +192,8 @@ static NSDictionary *dictForDescriptionWithName(NSString *defName) [self updateAliasesFromDictionary:[def objectForKey:@"Aliases"]]; restriction = saveFlag; + + [pool release]; } - (void)updateUseList:(NSArray *)array diff --git a/Languages/Smalltalk/ChangeLog b/Languages/Smalltalk/ChangeLog index f3a24f3..a00923e 100644 --- a/Languages/Smalltalk/ChangeLog +++ b/Languages/Smalltalk/ChangeLog @@ -1,3 +1,11 @@ +2003 Sep 24 Stefan Urbanek + + * Guard compilation with an autorelease pool + +2003 Sep 23 Stefan Urbanek + + * STBytecodeInterpreter: fixed memory leak (reported by Alexander Diemand) + 2003 Aug 5 Stefan Urbanek * STScriptObject renamed to STSmalltalkScriptObject, because of steptalk diff --git a/Languages/Smalltalk/NSArray+additions.m b/Languages/Smalltalk/NSArray+additions.m index 51f0e0a..bb9fd21 100644 --- a/Languages/Smalltalk/NSArray+additions.m +++ b/Languages/Smalltalk/NSArray+additions.m @@ -28,6 +28,7 @@ #import "NSNumber+additions.h" #import "STBlock.h" +#import #import @implementation NSArray (STCollecting) @@ -42,6 +43,7 @@ { retval = [block valueWith:object]; } + return retval; } - select:(STBlock *)block diff --git a/Languages/Smalltalk/NSNumber+additions.m b/Languages/Smalltalk/NSNumber+additions.m index 669d1d2..dbe3479 100644 --- a/Languages/Smalltalk/NSNumber+additions.m +++ b/Languages/Smalltalk/NSNumber+additions.m @@ -11,6 +11,7 @@ #import "NSNumber+additions.h" #import "STBlock.h" #include +#import @implementation NSNumber (STSmalltalkAdditions) - ifTrue:(STBlock *)block diff --git a/Languages/Smalltalk/STBytecodeInterpreter.m b/Languages/Smalltalk/STBytecodeInterpreter.m index 5eca123..1a41ae4 100644 --- a/Languages/Smalltalk/STBytecodeInterpreter.m +++ b/Languages/Smalltalk/STBytecodeInterpreter.m @@ -40,6 +40,7 @@ #import #import #import +#import #import #import @@ -107,6 +108,7 @@ static Class NSInvocation_class = nil; forReceiver:(id)anObject arguments:(NSArray*)args { + // NSAutoreleasePool *pool = [NSAutoreleasePool new]; STExecutionContext *oldContext; STMethodContext *newContext; id retval; @@ -135,8 +137,8 @@ static Class NSInvocation_class = nil; [method selector]]; } - newContext = [STMethodContext methodContextWithMethod:method - environment:environment]; + newContext = [[STMethodContext alloc] initWithMethod:method + environment:environment]; [newContext setArgumentsFromArray:args]; [newContext setReceiver:anObject]; @@ -148,6 +150,11 @@ static Class NSInvocation_class = nil; [self setContext:oldContext]; + RELEASE(newContext); + // RETAIN(retval); + // [pool release]; + // AUTORELEASE(retval) + return retval; } @@ -303,7 +310,7 @@ static Class NSInvocation_class = nil; argumentCount:argCount stackSize:stackSize]; - [stack push:block]; + [stack push:AUTORELEASE(block)]; } /* --------------------------------------------------------------------------- diff --git a/Languages/Smalltalk/STCompiler.m b/Languages/Smalltalk/STCompiler.m index 6d9adcf..232b75e 100644 --- a/Languages/Smalltalk/STCompiler.m +++ b/Languages/Smalltalk/STCompiler.m @@ -244,6 +244,7 @@ extern int STCparse(void *context); - (STCompiledScript *)compileString:(NSString *)aString { + NSAutoreleasePool *pool = [NSAutoreleasePool new]; STCompiledScript *result; NSString *exceptionFmt = @"Syntax error at line %i near '%@', " @"reason: %@."; @@ -301,6 +302,8 @@ extern int STCparse(void *context); RELEASE(receiverVars); RELEASE(reader); + [pool release]; + result = AUTORELEASE(resultScript); resultScript = nil; @@ -370,7 +373,7 @@ extern int STCparse(void *context); - (STCompiledCode *)compileStatements:(STCStatements *)statements { - STCompiledCode *compiledCode; + STCompiledCode *compiledCode; #ifdef DEBUG int count; int i; diff --git a/Languages/Smalltalk/STSmalltalkScriptObject.m b/Languages/Smalltalk/STSmalltalkScriptObject.m index 007a85c..e4bd164 100644 --- a/Languages/Smalltalk/STSmalltalkScriptObject.m +++ b/Languages/Smalltalk/STSmalltalkScriptObject.m @@ -31,6 +31,7 @@ #import #import #import +#import #import #import @@ -115,6 +116,7 @@ - (void) forwardInvocation:(NSInvocation *)invocation { + NSAutoreleasePool *pool = [NSAutoreleasePool new]; STCompiledMethod *method; NSString *methodName = NSStringFromSelector([invocation selector]); NSMutableArray *args; @@ -129,6 +131,7 @@ @"creating new interpreter for script '%@'", name); interpreter = [[STBytecodeInterpreter alloc] initWithEnvironment:environment]; + } @@ -146,7 +149,7 @@ @"script object perform: %@ with %i args", methodName,count-2); - args = [NSMutableArray array]; + args = [[NSMutableArray alloc] init]; for(index = 2; index < count; index++) { @@ -154,16 +157,18 @@ [args addObject:arg]; } - NSDebugLLog(@"STSending", - @">> forwarding to self ..."); + // NSDebugLLog(@"STSending", + // @">> forwarding to self ..."); retval = [interpreter interpretMethod:method forReceiver:self arguments:args]; + RELEASE(args); - NSDebugLLog(@"STSending", - @"<< returned from forwarding"); + // NSDebugLLog(@"STSending", + // @"<< returned from forwarding"); [invocation setReturnValue:&retval]; + [pool release]; } @end diff --git a/Languages/Smalltalk/SmalltalkEngine.m b/Languages/Smalltalk/SmalltalkEngine.m index 5a3dca5..6be57d5 100644 --- a/Languages/Smalltalk/SmalltalkEngine.m +++ b/Languages/Smalltalk/SmalltalkEngine.m @@ -73,11 +73,11 @@ [compiler setEnvironment:env]; - AUTORELEASE(compiler); - script = [compiler compileString:sourceCode]; retval = [script executeInEnvironment:env]; + AUTORELEASE(compiler); + return retval; } diff --git a/Testing/leaks/GNUmakefile b/Testing/leaks/GNUmakefile new file mode 100644 index 0000000..7fee3f9 --- /dev/null +++ b/Testing/leaks/GNUmakefile @@ -0,0 +1,39 @@ +# +# StepTalk tools +# +# Copyright (C) 2000,2001 Stefan Urbanek +# +# This file is part of the StepTalk. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public +# License along with this library; if not, write to the Free +# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02111, USA. +# + +include $(GNUSTEP_MAKEFILES)/common.make + +TOOL_NAME = leaktest + +leaktest_OBJC_FILES = leaktest.m + +ADDITIONAL_TOOL_LIBS = -lStepTalk + +ADDITIONAL_OBJCFLAGS = -Wall -Wno-import + +ifeq ($(check),yes) + ADDITIONAL_OBJCFLAGS += -Werror +endif + +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/tool.make +-include GNUMakefile.postamble diff --git a/Testing/leaks/leaktest.m b/Testing/leaks/leaktest.m new file mode 100644 index 0000000..f685ff9 --- /dev/null +++ b/Testing/leaks/leaktest.m @@ -0,0 +1,40 @@ +#import +#import +#import +#import + +#import + +int main(void) +{ + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + NSAutoreleasePool *innerPool; + NSString *theScript; + NSString *fname = @"script.st"; + STEnvironment *env; + STEngine *engine; + id result; + + theScript = [NSString stringWithContentsOfFile:fname]; + + GSDebugAllocationActive(YES); + + NSLog(@"allocated objects on starting script\n%s",GSDebugAllocationList(NO)); + + env = [STEnvironment defaultScriptingEnvironment]; + engine = [STEngine engineForLanguageWithName:@"Smalltalk"]; + + NS_DURING + //innerPool = [NSAutoreleasePool new]; + result = [engine executeCode:theScript inEnvironment:env]; + //[innerPool release]; + NS_HANDLER + /* handle the exception */ + NSLog(@"%@",localException); + NS_ENDHANDLER + + //NSLog(@"change of allocated objects\n%s",GSDebugAllocationList(YES)); + printf("%s",GSDebugAllocationList(NO)); + + [pool release]; +} diff --git a/Testing/leaks/script.st b/Testing/leaks/script.st new file mode 100644 index 0000000..e186642 --- /dev/null +++ b/Testing/leaks/script.st @@ -0,0 +1,18 @@ +[| + +main + | tval | + + tval := 1. + tval to: 20000 do: [ :counter | + self testme: counter. + ]. + + +! +testme: tval + | retval | + retval := tval + 1. + ^retval + +] diff --git a/Testing/leaks/test b/Testing/leaks/test new file mode 100755 index 0000000..40033c9 --- /dev/null +++ b/Testing/leaks/test @@ -0,0 +1 @@ +make debug=yes && obj/leaktest | sort -n