[29413] users/rhwood/MacPorts.Framework

source_changes at macosforge.org source_changes at macosforge.org
Sun Sep 23 02:34:25 PDT 2007


Revision: 29413
          http://trac.macosforge.org/projects/macports/changeset/29413
Author:   rhwood at macports.org
Date:     2007-09-23 02:34:25 -0700 (Sun, 23 Sep 2007)

Log Message:
-----------
Remove [MPInterpreter dumpConfiguration]
Change MPInterpreter to ensure that there is only a single instance per thread

Modified Paths:
--------------
    users/rhwood/MacPorts.Framework/MPInterpreter.h
    users/rhwood/MacPorts.Framework/MPInterpreter.m
    users/rhwood/MacPorts.Framework/MPInterpreterTest.h
    users/rhwood/MacPorts.Framework/MPInterpreterTest.m

Modified: users/rhwood/MacPorts.Framework/MPInterpreter.h
===================================================================
--- users/rhwood/MacPorts.Framework/MPInterpreter.h	2007-09-23 09:27:29 UTC (rev 29412)
+++ users/rhwood/MacPorts.Framework/MPInterpreter.h	2007-09-23 09:34:25 UTC (rev 29413)
@@ -23,10 +23,9 @@
 
 #pragma Utilities
 
-- (void)dumpConfiguration;
+- (NSString *)evaluateArrayAsString:(NSArray *)statement;
+- (NSString *)evaluateStringAsString:(NSString *)statement;
 
-- (NSString *)evaluateAsString:(NSObject *)statement;
-
 - (NSArray *)getVariableAsArray:(NSString *)variable;
 - (NSString *)getVariableAsString:(NSString *)variable;
 

Modified: users/rhwood/MacPorts.Framework/MPInterpreter.m
===================================================================
--- users/rhwood/MacPorts.Framework/MPInterpreter.m	2007-09-23 09:27:29 UTC (rev 29412)
+++ users/rhwood/MacPorts.Framework/MPInterpreter.m	2007-09-23 09:34:25 UTC (rev 29413)
@@ -9,8 +9,6 @@
 #import "MPConstants.h"
 #import "MPInterpreter.h"
 
-static MPInterpreter *sharedMPInterpreter = nil;
-
 @implementation MPInterpreter
 
 - (id) init {
@@ -18,15 +16,14 @@
 		_interpreter = Tcl_CreateInterp();
 		if(_interpreter == NULL) {
 			NSLog(@"Error in Tcl_CreateInterp, aborting.");
-			return Nil;
 		}
 		if(Tcl_Init(_interpreter) == TCL_ERROR) {
 			NSLog(@"Error in Tcl Init: %s", Tcl_GetStringResult(_interpreter));
-			return Nil;
+			Tcl_DeleteInterp(_interpreter);
 		}
 		if( Tcl_EvalFile(_interpreter, [[[NSBundle mainBundle] pathForResource:@"init" ofType:@"tcl"] UTF8String]) != TCL_OK) {
 			NSLog(@"Error in Tcl_EvalFile: %s", Tcl_GetStringResult(_interpreter));
-			return Nil;
+			Tcl_DeleteInterp(_interpreter);
 		}
 	}
 	return self;
@@ -34,18 +31,18 @@
 
 + (MPInterpreter*)sharedInterpreter {
 	@synchronized(self) {
-		if (sharedMPInterpreter == nil) {
+		if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"] == nil) {
 			[[self alloc] init]; // assignment not done here
 		}
 	}
-	return sharedMPInterpreter;
+	return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"];
 }
 
 + (id)allocWithZone:(NSZone*)zone {
 	@synchronized(self) {
-		if (sharedMPInterpreter == nil) {
-			sharedMPInterpreter = [super allocWithZone:zone];
-			return sharedMPInterpreter;	// assignment and return on first allocation
+		if ([[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"] == nil) {
+			[[[NSThread currentThread] threadDictionary] setObject:[super allocWithZone:zone] forKey:@"sharedMPInterpreter"];
+			return [[[NSThread currentThread] threadDictionary] objectForKey:@"sharedMPInterpreter"];	// assignment and return on first allocation
 		}
 	}
 	return nil;	// subsequent allocation attempts return nil
@@ -77,12 +74,6 @@
 
 #pragma Utilities
 
-- (void)dumpConfiguration {
-	// DOES NOT WORK?
-	Tcl_GetVar(_interpreter, [@"system_options" UTF8String], TCL_GLOBAL_ONLY);
-	NSLog([NSString stringWithUTF8String:Tcl_GetStringResult(_interpreter)]);
-}
-
 - (NSString *)evaluateArrayAsString:(NSArray *)statement {
 	return [self evaluateStringAsString:[statement componentsJoinedByString:@" "]];
 }

Modified: users/rhwood/MacPorts.Framework/MPInterpreterTest.h
===================================================================
--- users/rhwood/MacPorts.Framework/MPInterpreterTest.h	2007-09-23 09:27:29 UTC (rev 29412)
+++ users/rhwood/MacPorts.Framework/MPInterpreterTest.h	2007-09-23 09:34:25 UTC (rev 29413)
@@ -12,7 +12,6 @@
 
 }
 
-- (void)testDumpConfiguration;
 - (void)testGetVariableArray;
 
 @end

Modified: users/rhwood/MacPorts.Framework/MPInterpreterTest.m
===================================================================
--- users/rhwood/MacPorts.Framework/MPInterpreterTest.m	2007-09-23 09:27:29 UTC (rev 29412)
+++ users/rhwood/MacPorts.Framework/MPInterpreterTest.m	2007-09-23 09:34:25 UTC (rev 29413)
@@ -7,18 +7,13 @@
 //
 
 #import "MPInterpreterTest.h"
-#import <MacPorts/MacPorts.h>
+#import "MPInterpreter.h"
 
 @implementation MPInterpreterTest
 
-- (void)testDumpConfiguration {
-//	MPInterpreter *interpreter = [MPInterpreter sharedInterpreter];
-//	[interpreter dumpConfiguration];
-}
-
 - (void)testGetVariableArray {
 	MPInterpreter *interpreter = [MPInterpreter sharedInterpreter];
-	STAssertEquals([[interpreter getVariable:@"macports::sources"] count], 0, "Empty array returned when should have at least 1 element.");
+	STAssertEquals([[interpreter getVariableAsArray:@"macports::sources"] count], 0, "Empty array returned when should have at least 1 element.");
 }
 
 @end

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070923/59024bda/attachment.html


More information about the macports-changes mailing list