Added ARP guards

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/steptalk/trunk@17711 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Stefan Urbanek 2003-09-24 16:52:29 +00:00
parent 55304567c7
commit a76195b3fd
16 changed files with 169 additions and 14 deletions

View file

@ -1,12 +1,20 @@
2003 Aug 13
2003 Sep 24 Stefan Urbanek <urbanek@host.sk>
* STEnvironmentDescription: guard initialisation in Autorelease pool
2003 Sep 23 Stefan Urbanek <urbanek@host.sk>
* STEngine: setValueForOption: added
2003 Aug 13 Stefan Urbanek <urbanek@host.sk>
* Version 0.8.0
2003 Aug 9
2003 Aug 9 Stefan Urbanek <urbanek@host.sk>
* Removed compiler warnings in StepTalk.framework, Smalltalk and Tools
2003 Aug 6
2003 Aug 6 Stefan Urbanek <urbanek@host.sk>
* Frameworks: new directory
* Changed StepTalk from library to framework

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -39,6 +39,7 @@
#import <Foundation/NSString.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSAutoreleasePool.h>
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

View file

@ -1,3 +1,11 @@
2003 Sep 24 Stefan Urbanek <urbanek@host.sk>
* Guard compilation with an autorelease pool
2003 Sep 23 Stefan Urbanek <urbanek@host.sk>
* STBytecodeInterpreter: fixed memory leak (reported by Alexander Diemand)
2003 Aug 5 Stefan Urbanek <urbanek@host.sk>
* STScriptObject renamed to STSmalltalkScriptObject, because of steptalk

View file

@ -28,6 +28,7 @@
#import "NSNumber+additions.h"
#import "STBlock.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSEnumerator.h>
@implementation NSArray (STCollecting)
@ -42,6 +43,7 @@
{
retval = [block valueWith:object];
}
return retval;
}
- select:(STBlock *)block

View file

@ -11,6 +11,7 @@
#import "NSNumber+additions.h"
#import "STBlock.h"
#include <math.h>
#import <Foundation/NSAutoreleasePool.h>
@implementation NSNumber (STSmalltalkAdditions)
- ifTrue:(STBlock *)block

View file

@ -40,6 +40,7 @@
#import <StepTalk/STFunctions.h>
#import <StepTalk/NSInvocation+additions.h>
#import <StepTalk/STScripting.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSData.h>
@ -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)];
}
/* ---------------------------------------------------------------------------

View file

@ -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;

View file

@ -31,6 +31,7 @@
#import <Foundation/NSDebug.h>
#import <Foundation/NSMethodSignature.h>
#import <Foundation/NSString.h>
#import <Foundation/NSAutoreleasePool.h>
#import <StepTalk/NSInvocation+additions.h>
#import <StepTalk/STEnvironment.h>
@ -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

View file

@ -73,11 +73,11 @@
[compiler setEnvironment:env];
AUTORELEASE(compiler);
script = [compiler compileString:sourceCode];
retval = [script executeInEnvironment:env];
AUTORELEASE(compiler);
return retval;
}

39
Testing/leaks/GNUmakefile Normal file
View file

@ -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

40
Testing/leaks/leaktest.m Normal file
View file

@ -0,0 +1,40 @@
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSString.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSException.h>
#import <StepTalk/StepTalk.h>
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];
}

18
Testing/leaks/script.st Normal file
View file

@ -0,0 +1,18 @@
[|
main
| tval |
tval := 1.
tval to: 20000 do: [ :counter |
self testme: counter.
].
!
testme: tval
| retval |
retval := tval + 1.
^retval
]

1
Testing/leaks/test Executable file
View file

@ -0,0 +1 @@
make debug=yes && obj/leaktest | sort -n