[28250] users/rhwood/Pallet/MPTool

source_changes at macosforge.org source_changes at macosforge.org
Sun Aug 26 02:36:05 PDT 2007


Revision: 28250
          http://trac.macosforge.org/projects/macports/changeset/28250
Author:   rhwood at macports.org
Date:     2007-08-26 02:36:05 -0700 (Sun, 26 Aug 2007)

Log Message:
-----------
MPObject now based on DPObject from PortsManager instead of DPCocoa

Modified Paths:
--------------
    users/rhwood/Pallet/MPTool/MPObject.h
    users/rhwood/Pallet/MPTool/MPObject.m

Modified: users/rhwood/Pallet/MPTool/MPObject.h
===================================================================
--- users/rhwood/Pallet/MPTool/MPObject.h	2007-08-26 09:21:17 UTC (rev 28249)
+++ users/rhwood/Pallet/MPTool/MPObject.h	2007-08-26 09:36:05 UTC (rev 28250)
@@ -1,34 +1,32 @@
-//
-//  MPObject.h
-//  DarwinPorts
-//
 /*
- Copyright (c) 2003 Apple Computer, Inc.
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
- may be used to endorse or promote products derived from this software
- without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
+ * MPObject.h
+ * DarwinPorts
+ *
+ * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #import <Foundation/Foundation.h>
@@ -37,6 +35,7 @@
 @interface MPObject : NSObject 
 {
 @private
+    char *_cString;
     NSString *_cocoaString;  
     NSDictionary *_cocoaDictionary;  
     Tcl_Obj *_tclObj;
@@ -51,6 +50,7 @@
 - (Tcl_Obj *) tclObj;
 - (char *) cString;
 - (NSString *) stringValue;
+- (NSDictionary *) dictionaryValue;
 
 /** comparisons **/
 - (BOOL) isEqual: (id)object;

Modified: users/rhwood/Pallet/MPTool/MPObject.m
===================================================================
--- users/rhwood/Pallet/MPTool/MPObject.m	2007-08-26 09:21:17 UTC (rev 28249)
+++ users/rhwood/Pallet/MPTool/MPObject.m	2007-08-26 09:36:05 UTC (rev 28250)
@@ -1,34 +1,32 @@
-//
-//  MPObject.m
-//  DarwinPorts
-//
 /*
- Copyright (c) 2003 Apple Computer, Inc.
- All rights reserved.
- 
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- 1. Redistributions of source code must retain the above copyright
-    notice, this list of conditions and the following disclaimer.
- 2. Redistributions in binary form must reproduce the above copyright
-    notice, this list of conditions and the following disclaimer in the
-    documentation and/or other materials provided with the distribution.
- 3. Neither the name of Apple Computer, Inc. nor the names of its contributors
-    may be used to endorse or promote products derived from this software
-    without specific prior written permission.
- 
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
+ * MPObject.m
+ * DarwinPorts
+ *
+ * Copyright (c) 2002-2003, Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *    its contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #import "MPObject.h"
@@ -45,20 +43,10 @@
 
 + (MPObject *) objectWithString: (NSString *)string
 {
-    static NSMutableDictionary *cachedObjects;
-    MPObject *object = nil;
-    if (!cachedObjects)
-    {
-        cachedObjects = [[NSMutableDictionary alloc] init];
-    }
-    object = [cachedObjects objectForKey: string];
-    if (!object)
-    {
-        const char *cString = [string cString];
-        Tcl_Obj *tclObj = Tcl_NewStringObj(cString, strlen(cString));
-        object = [[[self alloc] initWithTclObj: tclObj] autorelease];
-        [cachedObjects setObject: object forKey: string];
-    }
+    const char *cString = [string cString];
+    Tcl_Obj *tclObj = Tcl_NewStringObj(cString, strlen(cString));
+    MPObject *object = [[[self alloc] initWithTclObj: tclObj] autorelease];
+    
     return object;
 }
 
@@ -84,7 +72,8 @@
 {
     Tcl_DecrRefCount(_tclObj);
     [_cocoaString release];
-    [_cocoaDictionary release];
+    if (_cString != NULL)
+        free(_cString);
     [super dealloc];
 }
 
@@ -100,7 +89,14 @@
 
 - (char *) cString 
 {
-    return Tcl_GetString(_tclObj);
+    /*
+     * Tcl_Obj value pointers are only safe
+     * until the next Tcl_Get*FromObj call.
+     */
+    if (_cString == NULL) {
+        _cString = strdup(Tcl_GetStringFromObj(_tclObj, NULL));
+    }
+    return _cString;
 }
 
 
@@ -113,7 +109,34 @@
     return _cocoaString;
 }
 
+- (NSDictionary*) dictionaryValue 
+{
+    Tcl_Obj **elemPtrs;
+    int elemLen, i;
 
+    if (nil == _cocoaDictionary)
+    {
+    	if (Tcl_ListObjGetElements(NULL, _tclObj, &elemLen, &elemPtrs) != TCL_OK)
+	    return nil;
+
+	if (elemLen & 1 || elemLen == 0)
+	    return nil;
+
+	NSMutableArray *keys = [NSMutableArray array];
+	NSMutableArray *values = [NSMutableArray array];
+
+	for (i = 0; i < elemLen; i += 2) {
+	    [keys addObject: [NSString stringWithCString: Tcl_GetString(elemPtrs[i])]];
+	    [values addObject: [NSString stringWithCString: Tcl_GetString(elemPtrs[i + 1])]];
+	}
+
+	_cocoaDictionary = [NSDictionary dictionaryWithObjects: values forKeys: keys];
+    }
+
+    return _cocoaDictionary;
+}
+
+
 - (NSString*) description 
 {
     return [self stringValue];

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070826/4efa8e83/attachment.html


More information about the macports-changes mailing list