[65318] users/toby/objcports

toby at macports.org toby at macports.org
Wed Mar 24 23:42:24 PDT 2010


Revision: 65318
          http://trac.macports.org/changeset/65318
Author:   toby at macports.org
Date:     2010-03-24 23:42:24 -0700 (Wed, 24 Mar 2010)
Log Message:
-----------
refactoring

Modified Paths:
--------------
    users/toby/objcports/MPIndex.h
    users/toby/objcports/MPIndex.m
    users/toby/objcports/objcports.xcodeproj/project.pbxproj
    users/toby/objcports/port.m

Added Paths:
-----------
    users/toby/objcports/Tcl_NSDataChannel.h
    users/toby/objcports/Tcl_NSDataChannel.m
    users/toby/objcports/nstcl.h
    users/toby/objcports/nstcl.m

Modified: users/toby/objcports/MPIndex.h
===================================================================
--- users/toby/objcports/MPIndex.h	2010-03-25 06:27:38 UTC (rev 65317)
+++ users/toby/objcports/MPIndex.h	2010-03-25 06:42:24 UTC (rev 65318)
@@ -4,5 +4,6 @@
 }
 
 - (id)initWithSourceURL:(NSURL *)source;
+- (NSDictionary *)index;
 
 @end

Modified: users/toby/objcports/MPIndex.m
===================================================================
--- users/toby/objcports/MPIndex.m	2010-03-25 06:27:38 UTC (rev 65317)
+++ users/toby/objcports/MPIndex.m	2010-03-25 06:42:24 UTC (rev 65318)
@@ -2,87 +2,9 @@
 #include <tcl.h>
 
 #include "MPIndex.h"
-#include "cftcl.h"
+#include "Tcl_NSDataChannel.h"
+#include "nstcl.h"
 
-struct NSData_channel_ctx {
-	NSData *data;
-	off_t offset;
-};
-
-static int
-dataclose(ClientData instanceData, Tcl_Interp *interp)
-{
-	struct NSData_channel_ctx *ctx = (struct NSData_channel_ctx *)instanceData;
-
-	[ctx->data release];
-	free(ctx);
-
-	return 0;
-}
-
-static int
-datainput(ClientData instanceData, char *buf, int bufSize, int *errorCodePtr __unused)
-{
-	struct NSData_channel_ctx *ctx = (struct NSData_channel_ctx *)instanceData;
-	size_t bytes;
-
-	bytes = [ctx->data length] - ctx->offset;
-	if ((size_t)bufSize < bytes) {
-		bytes = bufSize;
-	}
-
-	memcpy(buf, (char *)[ctx->data bytes] + ctx->offset, bytes);
-	ctx->offset += bytes;
-
-	return (int)bytes;
-}
-
-static void
-datawatch(ClientData instanceData, int mask)
-{
-	//printf("%s (%p %d)\n", __FUNCTION__, instanceData, mask);
-}
-
-static Tcl_ChannelType NSDataChannelType = {
-	"NSData",				// typeName
-	TCL_CHANNEL_VERSION_5,	// version
-	dataclose,				// closeProc
-	datainput,				// inputProc
-	NULL,					// outputProc (maybe)
-	NULL,					// seekProc
-	NULL,					// setOptionProc
-	NULL,					// getOptionProc
-	datawatch,				// watchProc
-	NULL,					// getHandleProc (maybe)
-	NULL,					// close2Proc
-	NULL,					// blockModeProc
-	NULL,					// flushProc (2)
-	NULL,					// handlerProc (2)
-	NULL,					// wideSeekProc (3)
-	NULL,					// threadActionProc (4)
-	NULL,					// truncateProc (5)
-};
-
-Tcl_Channel
-Tcl_CreateNSDataChannel(NSData *data)
-{
-	char *channel_name;
-	Tcl_Channel channel = NULL;
-	struct NSData_channel_ctx *ctx;
-
-	if (data) {
-		ctx = malloc(sizeof(*ctx));
-		ctx->data = [data retain];
-		ctx->offset = 0;
-
-		asprintf(&channel_name, "%p", data);
-		channel = Tcl_CreateChannel(&NSDataChannelType, channel_name, ctx, TCL_READABLE);
-		free(channel_name);
-	}
-
-	return channel;
-}
-
 static NSMutableDictionary *
 MPCopyPortIndex(NSData *data)
 {
@@ -116,19 +38,19 @@
 		}
 		Tcl_ListObjGetElements(interp, line, &objc, &objv);
 		assert(objc == 2);
-		key = CFStringCreateWithTclObject(NULL, objv[0]);
+		key = [[NSString alloc] initWithTclObject:objv[0]];
 		Tcl_GetIntFromObj(interp, objv[1], &len);
 		
 		/* Read dictionary. */
 		Tcl_ReadChars(chan, line, len, 0);
 		Tcl_ListObjGetElements(interp, line, &objc, &objv);
-		value = CFDictionaryCreateWithTclObjects(NULL, objv, objc);
+		value = [[NSDictionary alloc] initWithTclObjects:objv count:objc];
 		assert(value);
 		
 		/* Store data. */
 		[result setObject:value forKey:key];
-		CFRelease(key);
-		CFRelease(value);
+		[key release];
+		[value release];
 		
 		Tcl_DecrRefCount(line);
 	}
@@ -149,7 +71,7 @@
 	self = [super init];
 
 	_source = [source retain];
-
+	
 	data = [[NSData alloc] initWithContentsOfURL:[_source URLByAppendingPathComponent:@"PortIndex"] options:(NSDataReadingMapped | NSDataReadingUncached) error:&error];
 	if (data) {
 		_index = MPCopyPortIndex(data);
@@ -173,4 +95,9 @@
 	return [NSString stringWithFormat:@"<%@: %@>", [self class], _source];
 }
 
+- (NSDictionary *)index
+{
+	return _index;
+}
+
 @end

Added: users/toby/objcports/Tcl_NSDataChannel.h
===================================================================
--- users/toby/objcports/Tcl_NSDataChannel.h	                        (rev 0)
+++ users/toby/objcports/Tcl_NSDataChannel.h	2010-03-25 06:42:24 UTC (rev 65318)
@@ -0,0 +1 @@
+Tcl_Channel Tcl_CreateNSDataChannel(NSData *data);

Added: users/toby/objcports/Tcl_NSDataChannel.m
===================================================================
--- users/toby/objcports/Tcl_NSDataChannel.m	                        (rev 0)
+++ users/toby/objcports/Tcl_NSDataChannel.m	2010-03-25 06:42:24 UTC (rev 65318)
@@ -0,0 +1,83 @@
+#include <Foundation/Foundation.h>
+#include <tcl.h>
+
+#include "Tcl_NSDataChannel.h"
+
+struct NSDataChannel_ctx_s {
+	NSData *data;
+	off_t offset;
+};
+typedef struct NSDataChannel_ctx_s *NSDataChannel_ctx_t;
+
+static int
+NSDataChannel_close(ClientData instanceData, Tcl_Interp *interp __unused)
+{
+	NSDataChannel_ctx_t ctx = (NSDataChannel_ctx_t)instanceData;
+
+	[ctx->data release];
+	free(ctx);
+
+	return 0;
+}
+
+static int
+NSDataChannel_input(ClientData instanceData, char *buf, int bufSize, int *errorCodePtr __unused)
+{
+	NSDataChannel_ctx_t ctx = (NSDataChannel_ctx_t)instanceData;
+	size_t bytes;
+
+	bytes = [ctx->data length] - ctx->offset;
+	if (bytes > (size_t)bufSize) {
+		bytes = bufSize;
+	}
+
+	memcpy(buf, (char *)[ctx->data bytes] + ctx->offset, bytes);
+	ctx->offset += bytes;
+
+	return (int)bytes;
+}
+
+static void
+NSDataChannel_watch(ClientData instanceData __unused, int mask __unused)
+{
+}
+
+static Tcl_ChannelType NSDataChannelType = {
+	"NSData",				// typeName
+	TCL_CHANNEL_VERSION_5,	// version
+	NSDataChannel_close,	// closeProc
+	NSDataChannel_input,	// inputProc
+	NULL,					// outputProc
+	NULL,					// seekProc
+	NULL,					// setOptionProc
+	NULL,					// getOptionProc
+	NSDataChannel_watch,	// watchProc
+	NULL,					// getHandleProc
+	NULL,					// close2Proc
+	NULL,					// blockModeProc
+	NULL,					// flushProc (2)
+	NULL,					// handlerProc (2)
+	NULL,					// wideSeekProc (3)
+	NULL,					// threadActionProc (4)
+	NULL,					// truncateProc (5)
+};
+
+Tcl_Channel
+Tcl_CreateNSDataChannel(NSData *data)
+{
+	char *channel_name;
+	Tcl_Channel channel = NULL;
+	NSDataChannel_ctx_t ctx;
+
+	if (data) {
+		ctx = malloc(sizeof(*ctx));
+		ctx->data = [data retain];
+		ctx->offset = 0;
+		
+		asprintf(&channel_name, "%p", data);
+		channel = Tcl_CreateChannel(&NSDataChannelType, channel_name, ctx, TCL_READABLE);
+		free(channel_name);
+	}
+
+	return channel;
+}

Added: users/toby/objcports/nstcl.h
===================================================================
--- users/toby/objcports/nstcl.h	                        (rev 0)
+++ users/toby/objcports/nstcl.h	2010-03-25 06:42:24 UTC (rev 65318)
@@ -0,0 +1,14 @@
+ at interface NSString (nstcl)
++ (id)stringWithTclObject:(Tcl_Obj *)object;
+- (id)initWithTclObject:(Tcl_Obj *)object;
+ at end
+
+ at interface NSArray (nstcl)
++ (id)arrayWithTclObjects:(Tcl_Obj **)objects count:(NSUInteger)count;
+- (id)initWithTclObjects:(Tcl_Obj **)objects count:(NSUInteger)count;
+ at end
+
+ at interface NSDictionary (nstcl)
++ (id)dictionaryWithTclObjects:(Tcl_Obj **)objects count:(NSUInteger)count;
+- (id)initWithTclObjects:(Tcl_Obj **)objects count:(NSUInteger)count;
+ at end

Added: users/toby/objcports/nstcl.m
===================================================================
--- users/toby/objcports/nstcl.m	                        (rev 0)
+++ users/toby/objcports/nstcl.m	2010-03-25 06:42:24 UTC (rev 65318)
@@ -0,0 +1,82 @@
+#include <Foundation/Foundation.h>
+#include <tcl.h>
+
+#include "nstcl.h"
+
+ at implementation NSString (nstcl)
+
++ (id)stringWithTclObject:(Tcl_Obj *)object
+{
+	return [[[self alloc] initWithTclObject:object] autorelease];
+}
+
+- (id)initWithTclObject:(Tcl_Obj *)object
+{
+	return [self initWithUTF8String:Tcl_GetString(object)];
+}
+
+ at end
+
+ at implementation NSArray (nstcl)
+
++ (id)arrayWithTclObjects:(Tcl_Obj **)objects count:(NSUInteger)count
+{
+	return [[[self alloc] initWithTclObjects:objects count:count] autorelease];
+}
+
+- (id)initWithTclObjects:(Tcl_Obj **)objects count:(NSUInteger)count
+{
+	NSUInteger i;
+	id *array;
+	id result;
+
+	array = alloca(count * sizeof(id));
+
+	for (i = 0; i < count; i++) {
+		array[i] = [[NSString alloc] initWithTclObject:objects[i]];
+	}
+	result = [self initWithObjects:array count:count];
+	for (i = 0; i < count; i++) {
+		[array[i] release];
+	}
+
+	return result;
+}
+
+ at end
+
+ at implementation NSDictionary (nstcl)
+
++ (id)dictionaryWithTclObjects:(Tcl_Obj **)objects count:(NSUInteger)count
+{
+	return [[[self alloc] initWithTclObjects:objects count:count] autorelease];
+}
+
+- (id)initWithTclObjects:(Tcl_Obj **)objects count:(NSUInteger)count
+{
+	NSUInteger count2, i;
+	id *keys, *objs;
+	id result;
+
+	if ((count % 2) != 0) {
+		return nil;
+	}
+
+	count2 = count / 2;
+	keys = alloca(count2 * sizeof(id));
+	objs = alloca(count2 * sizeof(id));
+
+	for (i = 0; i < count2; i++) {
+		keys[i] = [[NSString alloc] initWithTclObject:objects[i * 2]];
+		objs[i] = [[NSString alloc] initWithTclObject:objects[i * 2 + 1]];
+	}
+	result = [self initWithObjects:objs forKeys:keys count:count2];
+	for (i = 0; i < count2; i++) {
+		[keys[i] release];
+		[objs[i] release];
+	}
+
+	return result;
+}
+
+ at end

Modified: users/toby/objcports/objcports.xcodeproj/project.pbxproj
===================================================================
--- users/toby/objcports/objcports.xcodeproj/project.pbxproj	2010-03-25 06:27:38 UTC (rev 65317)
+++ users/toby/objcports/objcports.xcodeproj/project.pbxproj	2010-03-25 06:42:24 UTC (rev 65318)
@@ -12,6 +12,8 @@
 		DA382DE5105A284E00D9B600 /* cftcl.c in Sources */ = {isa = PBXBuildFile; fileRef = DA382DE4105A284E00D9B600 /* cftcl.c */; };
 		DA382EF0105A2B4900D9B600 /* Tcl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA382EEF105A2B4900D9B600 /* Tcl.framework */; };
 		DA7AF1BC1058D1E200CF2187 /* internal.c in Sources */ = {isa = PBXBuildFile; fileRef = DA7AF1BB1058D1E200CF2187 /* internal.c */; };
+		DA8700EA115B33CB006E3FB5 /* nstcl.m in Sources */ = {isa = PBXBuildFile; fileRef = DA8700E9115B33CB006E3FB5 /* nstcl.m */; };
+		DA870137115B3AB6006E3FB5 /* Tcl_NSDataChannel.m in Sources */ = {isa = PBXBuildFile; fileRef = DA870136115B3AB6006E3FB5 /* Tcl_NSDataChannel.m */; };
 		DA96BED00F7C9C2500362779 /* MPIndex.m in Sources */ = {isa = PBXBuildFile; fileRef = DA96BECF0F7C9C2500362779 /* MPIndex.m */; };
 		DAB2118E107B33AB002E931E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DAB2118D107B33AB002E931E /* Foundation.framework */; };
 		DAD371710F0280EF0064AFF4 /* port.m in Sources */ = {isa = PBXBuildFile; fileRef = DAD371680F0280EF0064AFF4 /* port.m */; };
@@ -41,6 +43,10 @@
 		DA382EEF105A2B4900D9B600 /* Tcl.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Tcl.framework; path = /System/Library/Frameworks/Tcl.framework; sourceTree = "<absolute>"; };
 		DA7AF1BA1058D1E200CF2187 /* internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = internal.h; sourceTree = "<group>"; };
 		DA7AF1BB1058D1E200CF2187 /* internal.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = internal.c; sourceTree = "<group>"; };
+		DA8700E8115B33CB006E3FB5 /* nstcl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nstcl.h; sourceTree = "<group>"; };
+		DA8700E9115B33CB006E3FB5 /* nstcl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = nstcl.m; sourceTree = "<group>"; };
+		DA870135115B3AB6006E3FB5 /* Tcl_NSDataChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Tcl_NSDataChannel.h; sourceTree = "<group>"; };
+		DA870136115B3AB6006E3FB5 /* Tcl_NSDataChannel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Tcl_NSDataChannel.m; sourceTree = "<group>"; };
 		DA96BECE0F7C9C2500362779 /* MPIndex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MPIndex.h; sourceTree = "<group>"; };
 		DA96BECF0F7C9C2500362779 /* MPIndex.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPIndex.m; sourceTree = "<group>"; };
 		DAB2118D107B33AB002E931E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
@@ -91,6 +97,10 @@
 				DA382DE3105A284E00D9B600 /* cftcl.h */,
 				DA382DE4105A284E00D9B600 /* cftcl.c */,
 				FD1CD53B1018F5AD0071534F /* variables.plist */,
+				DA8700E8115B33CB006E3FB5 /* nstcl.h */,
+				DA8700E9115B33CB006E3FB5 /* nstcl.m */,
+				DA870135115B3AB6006E3FB5 /* Tcl_NSDataChannel.h */,
+				DA870136115B3AB6006E3FB5 /* Tcl_NSDataChannel.m */,
 			);
 			name = Source;
 			sourceTree = "<group>";
@@ -169,6 +179,8 @@
 				DA13887B101AED7000F73A82 /* MPConfig.m in Sources */,
 				DA7AF1BC1058D1E200CF2187 /* internal.c in Sources */,
 				DA382DE5105A284E00D9B600 /* cftcl.c in Sources */,
+				DA8700EA115B33CB006E3FB5 /* nstcl.m in Sources */,
+				DA870137115B3AB6006E3FB5 /* Tcl_NSDataChannel.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: users/toby/objcports/port.m
===================================================================
--- users/toby/objcports/port.m	2010-03-25 06:27:38 UTC (rev 65317)
+++ users/toby/objcports/port.m	2010-03-25 06:42:24 UTC (rev 65318)
@@ -26,7 +26,7 @@
 	if (url) {
 		portindex = [[MPIndex alloc] initWithSourceURL:url];
 		if (portindex) {
-			NSLog(@"%@", portindex);
+			NSLog(@"%@", [portindex index]);
 			[portindex release];
 		}
 	}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20100324/e99bc3fa/attachment-0001.html>


More information about the macports-changes mailing list