[26137] trunk/base
source_changes at macosforge.org
source_changes at macosforge.org
Wed Jun 13 17:10:40 PDT 2007
Revision: 26137
http://trac.macosforge.org/projects/macports/changeset/26137
Author: landonf at macports.org
Date: 2007-06-13 17:10:40 -0700 (Wed, 13 Jun 2007)
Log Message:
-----------
A prototype dynamic Tcl -> Objective-C bridge; Written in 2003 by Kevin Van Vechten and I, finally committed today
Modified Paths:
--------------
trunk/base/Mk/dports.autoconf.mk.in
trunk/base/Mk/dports.tea.mk
trunk/base/configure
trunk/base/configure.ac
trunk/base/src/Makefile.in
Added Paths:
-----------
trunk/base/src/tclobjc1.0/
trunk/base/src/tclobjc1.0/MPMethodSignatureExtensions.h
trunk/base/src/tclobjc1.0/MPMethodSignatureExtensions.m
trunk/base/src/tclobjc1.0/Makefile.in
trunk/base/src/tclobjc1.0/objc_encoding.h
trunk/base/src/tclobjc1.0/objc_encoding.m
trunk/base/src/tclobjc1.0/tclobjc.h
trunk/base/src/tclobjc1.0/tclobjc.m
trunk/base/src/tclobjc1.0/tclobjc_types.c
trunk/base/src/tclobjc1.0/tclobjc_types.h
Modified: trunk/base/Mk/dports.autoconf.mk.in
===================================================================
--- trunk/base/Mk/dports.autoconf.mk.in 2007-06-14 00:00:22 UTC (rev 26136)
+++ trunk/base/Mk/dports.autoconf.mk.in 2007-06-14 00:10:40 UTC (rev 26137)
@@ -6,7 +6,7 @@
CC = @CC@
CFLAGS = @CFLAGS@ $(CFLAGS_QUICHEEATERS) $(CFLAGS_WERROR) $(CFLAGS_DEBUG) $(CFLAGS_OPTIMIZE) $(CPPFLAGS) $(CFLAGS_LIBCURL)
-OBJCFLAGS = @OBJCFLAGS@ $(CFLAGS_QUICHEEATERS) $(CFLAGS_WERROR) ${CFLAGS_DEBUG} $(CFLAGS_OPTIMIZE) $(CPPFLAGS) $(CFLAGS_LIBCURL)
+OBJCFLAGS = @OBJCFLAGS@ $(CFLAGS_WERROR) ${CFLAGS_DEBUG} $(CFLAGS_OPTIMIZE) $(CPPFLAGS) $(CFLAGS_LIBCURL)
CPPFLAGS = @CPPFLAGS@ @DEFS@ @INCLUDES@ @TCL_INCLUDES@
TCL_DEFS = @TCL_DEFS@
SHLIB_CFLAGS = @SHLIB_CFLAGS@
Modified: trunk/base/Mk/dports.tea.mk
===================================================================
--- trunk/base/Mk/dports.tea.mk 2007-06-14 00:00:22 UTC (rev 26136)
+++ trunk/base/Mk/dports.tea.mk 2007-06-14 00:10:40 UTC (rev 26137)
@@ -1,3 +1,8 @@
+.SUFFIXES: .m
+
+.m.o:
+ ${CC} -c -DUSE_TCL_STUBS ${OBJCFLAGS} ${TCL_DEFS} ${SHLIB_CFLAGS} $< -o $@
+
.c.o:
${CC} -c -DUSE_TCL_STUBS ${CFLAGS} ${TCL_DEFS} ${SHLIB_CFLAGS} $< -o $@
Modified: trunk/base/configure
===================================================================
--- trunk/base/configure 2007-06-14 00:00:22 UTC (rev 26136)
+++ trunk/base/configure 2007-06-14 00:10:40 UTC (rev 26137)
@@ -10898,7 +10898,7 @@
# Output
- ac_config_files="$ac_config_files Makefile Mk/dports.autoconf.mk doc/prefix.mtree doc/macosx.mtree doc/ports.conf src/Makefile src/darwinports1.0/darwinports_autoconf.tcl src/port1.0/port_autoconf.tcl src/registry1.0/registry_autoconf.tcl src/programs/Makefile src/darwinports1.0/darwinports_fastload.tcl"
+ ac_config_files="$ac_config_files Makefile Mk/dports.autoconf.mk doc/prefix.mtree doc/macosx.mtree doc/ports.conf src/Makefile src/darwinports1.0/darwinports_autoconf.tcl src/tclobjc1.0/Makefile src/port1.0/port_autoconf.tcl src/registry1.0/registry_autoconf.tcl src/programs/Makefile src/darwinports1.0/darwinports_fastload.tcl"
cat >confcache <<\_ACEOF
@@ -11434,6 +11434,7 @@
"doc/ports.conf" ) CONFIG_FILES="$CONFIG_FILES doc/ports.conf" ;;
"src/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
"src/darwinports1.0/darwinports_autoconf.tcl" ) CONFIG_FILES="$CONFIG_FILES src/darwinports1.0/darwinports_autoconf.tcl" ;;
+ "src/tclobjc1.0/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/tclobjc1.0/Makefile" ;;
"src/port1.0/port_autoconf.tcl" ) CONFIG_FILES="$CONFIG_FILES src/port1.0/port_autoconf.tcl" ;;
"src/registry1.0/registry_autoconf.tcl" ) CONFIG_FILES="$CONFIG_FILES src/registry1.0/registry_autoconf.tcl" ;;
"src/programs/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/programs/Makefile" ;;
Modified: trunk/base/configure.ac
===================================================================
--- trunk/base/configure.ac 2007-06-14 00:00:22 UTC (rev 26136)
+++ trunk/base/configure.ac 2007-06-14 00:10:40 UTC (rev 26137)
@@ -276,6 +276,7 @@
doc/ports.conf
src/Makefile
src/darwinports1.0/darwinports_autoconf.tcl
+ src/tclobjc1.0/Makefile
src/port1.0/port_autoconf.tcl
src/registry1.0/registry_autoconf.tcl
src/programs/Makefile
Modified: trunk/base/src/Makefile.in
===================================================================
--- trunk/base/src/Makefile.in 2007-06-14 00:00:22 UTC (rev 26136)
+++ trunk/base/src/Makefile.in 2007-06-14 00:10:40 UTC (rev 26137)
@@ -1,5 +1,5 @@
TCLPKG= @OUR_INCLUDED_PACKAGES@ darwinports1.0 port1.0 package1.0 \
- pextlib1.0 registry1.0 darwintracelib1.0
+ pextlib1.0 registry1.0 darwintracelib1.0 tclobjc1.0
SUBDIR= ${TCLPKG} port programs
all::
Added: trunk/base/src/tclobjc1.0/MPMethodSignatureExtensions.h
===================================================================
--- trunk/base/src/tclobjc1.0/MPMethodSignatureExtensions.h (rev 0)
+++ trunk/base/src/tclobjc1.0/MPMethodSignatureExtensions.h 2007-06-14 00:10:40 UTC (rev 26137)
@@ -0,0 +1,44 @@
+/*
+ * MPMethodSignatureExtensions.h
+ *
+ * Copyright (c) 2004 Landon J. Fuller <landonf at opendarwin.org>
+ * 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 the copyright owner nor the names of 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Foundation/Foundation.h>
+
+ at interface NSMethodSignature (MPMethodSignatureExtensions)
+
+- (unsigned int) getArgumentTypeSpecifierAtIndex: (unsigned) index;
+- (const char *) getArgumentTypeStringAtIndex: (unsigned) index;
+- (const char*) methodReturnTypeString;
+
+ at end
Added: trunk/base/src/tclobjc1.0/MPMethodSignatureExtensions.m
===================================================================
--- trunk/base/src/tclobjc1.0/MPMethodSignatureExtensions.m (rev 0)
+++ trunk/base/src/tclobjc1.0/MPMethodSignatureExtensions.m 2007-06-14 00:10:40 UTC (rev 26137)
@@ -0,0 +1,140 @@
+/*
+ * MPMethodSignatureExtension.m
+ *
+ * Copyright (c) 2004 Landon J. Fuller <landonf at opendarwin.org>
+ * 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 the copyright owner nor the names of 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "MPMethodSignatureExtensions.h"
+
+#include <tcl.h>
+
+#include "objc_encoding.h"
+
+ at implementation NSMethodSignature (MPMethodSignatureExtensions)
+
+#ifdef GNU_RUNTIME
+- (unsigned int) getArgumentTypeSpecifierAtIndex: (unsigned int) index {
+ NSArgumentInfo info;
+ info = [self argumentInfoAtIndex: index];
+ return info.qual;
+}
+
+- (const char *) getArgumentTypeStringAtIndex: (unsigned int) index {
+ return [self getArgumentTypeAtIndex: index];
+}
+
+
+- (const char*) methodReturnTypeString {
+ return [self methodReturnType];
+}
+
+#endif
+
+#ifdef APPLE_RUNTIME
+
+static const char * stripSpecifiers (const char *type) {
+ const char *p;
+ for (p = type; p != '\0'; p++) {
+ switch (*p) {
+ case _C_BYCOPY:
+ case _C_IN:
+ case _C_OUT:
+ case _C_INOUT:
+ case _C_CONST:
+ case _C_ONEWAY:
+ break;
+ default:
+ return(p);
+ }
+ }
+ return (NULL);
+}
+
+- (unsigned int) getArgumentTypeSpecifierAtIndex: (unsigned int) index {
+ const char *type;
+ unsigned int qual = 0;
+ type = [self getArgumentTypeAtIndex: index];
+ for (; type != '\0'; type++) {
+ switch (type[0]) {
+ case _C_BYCOPY:
+ qual |= _F_BYCOPY;
+ break;
+ case _C_IN:
+ qual |= _F_IN;
+ break;
+ case _C_OUT:
+ qual |= _F_OUT;
+ break;
+ case _C_INOUT:
+ qual |= _F_INOUT;
+ break;
+ case _C_CONST:
+ qual |= _F_CONST;
+ break;
+ case _C_ONEWAY:
+ qual |= _F_ONEWAY;
+ break;
+ default:
+ goto finish;
+ }
+ }
+finish:
+ return (qual);
+}
+
+
+- (const char *) getArgumentTypeStringAtIndex: (unsigned int) index {
+ const char *type;
+ type = stripSpecifiers([self getArgumentTypeAtIndex: index]);
+ if (!type) {
+ /* This is a fatal condition */
+ NSLog(@"No type found in string at %s:%d", __FILE__, __LINE__);
+ exit(1);
+ }
+ return (type);
+}
+
+
+- (const char*) methodReturnTypeString {
+ const char *type;
+ type = stripSpecifiers([self methodReturnType]);
+ if (!type) {
+ /* This is a fatal condition */
+ NSLog(@"No type found in string at %s:%d", __FILE__, __LINE__);
+ exit(1);
+ }
+ return (type);
+}
+
+#endif
+
+ at end
Added: trunk/base/src/tclobjc1.0/Makefile.in
===================================================================
--- trunk/base/src/tclobjc1.0/Makefile.in (rev 0)
+++ trunk/base/src/tclobjc1.0/Makefile.in 2007-06-14 00:10:40 UTC (rev 26137)
@@ -0,0 +1,7 @@
+OBJS= tclobjc.o tclobjc_types.o MPMethodSignatureExtensions.o objc_encoding.o
+SHLIB_NAME= tclobjc${SHLIB_SUFFIX}
+INSTALLDIR= ${DESTDIR}${datadir}/darwinports/Tcl/tclobjc1.0
+export MACOSX_DEPLOYMENT_TARGET=10.3
+
+include ../../Mk/dports.autoconf.mk
+include ../../Mk/dports.tea.mk
Added: trunk/base/src/tclobjc1.0/objc_encoding.h
===================================================================
--- trunk/base/src/tclobjc1.0/objc_encoding.h (rev 0)
+++ trunk/base/src/tclobjc1.0/objc_encoding.h 2007-06-14 00:10:40 UTC (rev 26137)
@@ -0,0 +1,62 @@
+/*
+ * objc_encoding.h
+ *
+ * Copyright (c) 2004 Landon J. Fuller <landonf at opendarwin.org>
+ * 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 the copyright owner nor the names of 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+int objc_to_tclobj(Tcl_Interp *interp, Tcl_Obj **objPtr, const char *type, void *val);
+int tclobj_to_objc(Tcl_Interp *interp, void **val, const char *type, Tcl_Obj *objPtr);
+
+#ifdef GNU_RUNTIME
+#include <objc/encoding.h>
+#endif
+
+#ifdef APPLE_RUNTIME
+#include <objc/objc-class.h>
+#define _C_BYCOPY 'O'
+#define _C_IN 'n'
+#define _C_OUT 'o'
+#define _C_INOUT 'N'
+#define _C_CONST 'r'
+#define _C_ONEWAY 'V'
+#define _C_BYREF 'R' /* XXX unsupported */
+#define _C_GCINVISIBLE '!' /* XXX unsupported */
+
+#define _F_BYCOPY 0x04
+#define _F_IN 0x01
+#define _F_OUT 0x02
+#define _F_INOUT 0x03
+#define _F_CONST 0x01
+#define _F_ONEWAY 0x10
+#define _F_BYREF 0x08
+#define _F_GCINVISIBLE 0x20 /* XXX unsupported */
+#endif
Added: trunk/base/src/tclobjc1.0/objc_encoding.m
===================================================================
--- trunk/base/src/tclobjc1.0/objc_encoding.m (rev 0)
+++ trunk/base/src/tclobjc1.0/objc_encoding.m 2007-06-14 00:10:40 UTC (rev 26137)
@@ -0,0 +1,119 @@
+/*
+ * objc_encoding.m
+ *
+ * Copyright (c) 2004 Landon J. Fuller <landonf at opendarwin.org>
+ * 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 the copyright owner nor the names of 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* Required by glibc for asprintf() */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <tcl.h>
+
+#include "tclobjc.h"
+#include "objc_encoding.h"
+#include "tclobjc_types.h"
+
+int objc_to_tclobj(Tcl_Interp *interp, Tcl_Obj **objPtr, const char *type, void *val) {
+ Tcl_Obj *tcl_result;
+ char *name;
+
+ switch(*type) {
+ case _C_CHARPTR:
+ *objPtr = Tcl_NewStringObj((char *) val, -1);
+ return (TCL_OK);
+ case _C_INT:
+ *objPtr = Tcl_NewIntObj((int) val);
+ return (TCL_OK);
+ case _C_ID:
+ *objPtr = TclObjC_NewIdObj(val);
+ name = Tcl_GetString(*objPtr);
+ Tcl_CreateObjCommand(interp, (char *) name, tclobjc_dispatch, (id) val, NULL);
+ return (TCL_OK);
+ default:
+ /* Unhandled objc type encoding */
+ if (interp) {
+ tcl_result = Tcl_NewStringObj("Invalid objc type encoding: ", -1);
+ Tcl_AppendToObj(tcl_result, type, -1);
+ Tcl_SetObjResult(interp, tcl_result);
+ }
+ return (TCL_ERROR);
+ }
+}
+
+int tclobj_to_objc(Tcl_Interp *interp, void **val, const char *type, Tcl_Obj *objPtr) {
+ Tcl_Obj *tcl_result;
+
+ switch(*type) {
+ char *ptr;
+ int length;
+ case _C_CHARPTR:
+ ptr = Tcl_GetStringFromObj(objPtr, &length);
+ *val = malloc(length);
+ if (*val == NULL)
+ return (TCL_ERROR);
+
+ memcpy(*val, ptr, length);
+ return (TCL_OK);
+ case _C_INT:
+ *val = malloc(sizeof(int));
+ if (*val == NULL)
+ return (TCL_ERROR);
+
+ if (Tcl_GetIntFromObj(interp, objPtr, *val) != TCL_OK) {
+ free(*val);
+ return (TCL_ERROR);
+ } else {
+ return (TCL_OK);
+ }
+
+ case _C_ID:
+ *val = malloc(sizeof(id));
+ if (TclObjC_GetIdFromObj(interp, objPtr, *val) != TCL_OK) {
+ free(*val);
+ return (TCL_ERROR);
+ } else {
+ return (TCL_OK);
+ }
+ default:
+ /* Unhandled objc type encoding */
+ if (interp) {
+ tcl_result = Tcl_NewStringObj("Invalid objc type encoding: ", -1);
+ Tcl_AppendToObj(tcl_result, type, -1);
+ Tcl_SetObjResult(interp, tcl_result);
+ }
+ return (TCL_ERROR);
+ }
+}
Added: trunk/base/src/tclobjc1.0/tclobjc.h
===================================================================
--- trunk/base/src/tclobjc1.0/tclobjc.h (rev 0)
+++ trunk/base/src/tclobjc1.0/tclobjc.h 2007-06-14 00:10:40 UTC (rev 26137)
@@ -0,0 +1,38 @@
+/*
+ * TclObjC.m
+ *
+ * Authors:
+ * Keven Van Vechten <kevin at opendarwin.org>
+ * Landon J. Fuller <landonf at opendarwin.org>
+ *
+ * Copyright (c) 2003 Kevin Van Vechten <kevin at opendarwin.org>
+ * Copyright (c) 2004 Landon J. Fuller <landonf at opendarwin.org>
+ * 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 the copyright owner nor the names of 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.
+ */
+
+int tclobjc_dispatch(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
Added: trunk/base/src/tclobjc1.0/tclobjc.m
===================================================================
--- trunk/base/src/tclobjc1.0/tclobjc.m (rev 0)
+++ trunk/base/src/tclobjc1.0/tclobjc.m 2007-06-14 00:10:40 UTC (rev 26137)
@@ -0,0 +1,215 @@
+/*
+ * tclobjc.m
+ *
+ * Copyright (c) 2003 Kevin Van Vechten <kevin at opendarwin.org>
+ * Copyright (c) 2004 Landon J. Fuller <landonf at opendarwin.org>
+ * 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 the copyright owner nor the names of 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <Foundation/Foundation.h>
+#include <tcl.h>
+
+#include "MPMethodSignatureExtensions.h"
+#include "objc_encoding.h"
+
+#include "tclobjc_types.h"
+
+/*
+ * Type Encodings
+ */
+int tclobjc_dispatch(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+ int result = TCL_OK;
+ id target = (id)clientData;
+ SEL selector;
+ Tcl_Obj *selname;
+ int i = 1;
+ fprintf(stderr, "objc = %d\n", objc);
+
+ if (objc < 2) {
+ Tcl_WrongNumArgs(interp, 1, objv, "arguments");
+ return (TCL_ERROR);
+ }
+
+ selname = Tcl_NewObj();
+ for (i = 1; i < objc; i += 2) {
+ Tcl_AppendObjToObj(selname, objv[i]);
+ }
+
+ fprintf(stderr, "selector = %s\n", Tcl_GetString(selname));
+
+#if defined(GNU_RUNTIME)
+ selector = sel_get_uid(Tcl_GetString(selname));
+#elif defined(APPLE_RUNTIME)
+ selector = sel_getUid(Tcl_GetString(selname));
+#endif
+
+ if (!selector) {
+ Tcl_Obj* tcl_result = Tcl_NewStringObj("Invalid selector specified", -1);
+ Tcl_SetObjResult(interp, tcl_result);
+ result = TCL_ERROR;
+ } else {
+// fprintf(stderr, "target = %08x\n", target);
+ NSMethodSignature* signature = [target methodSignatureForSelector:selector];
+ NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
+ [invocation setTarget:target];
+ [invocation setSelector:selector];
+
+ for (i = 2; i < objc; i += 2) {
+ int arg_num = i / 2 + 1;
+
+ const char* arg_type = [signature getArgumentTypeStringAtIndex:arg_num];
+ fprintf(stderr, "argument type %s\n", arg_type);
+ if (arg_type[0] == _C_ID) {
+ id obj;
+ if (TclObjC_GetIdFromObj(interp, objv[i], &obj) == TCL_OK) {
+ [invocation setArgument:&obj atIndex:arg_num];
+ }
+ } else if (arg_type[0] == _C_INT) {
+ int word = 0;
+ if (Tcl_GetIntFromObj(interp, objv[i], &word) == TCL_OK) {
+ [invocation setArgument:&word atIndex:arg_num];
+ }
+ } else if (arg_type[0] == _C_CHARPTR) {
+ int length;
+ char* buf = Tcl_GetStringFromObj(objv[i], &length);
+ if (buf)
+ [invocation setArgument:&buf atIndex:arg_num];
+ } else {
+ NSString* str = [NSString stringWithFormat:@"unexpected argument type %s at %s:%d", arg_type, __FILE__, __LINE__];
+ Tcl_Obj* tcl_result = Tcl_NewStringObj([str cString], -1);
+ Tcl_SetObjResult(interp, tcl_result);
+ result = TCL_ERROR;
+ break;
+ }
+ }
+
+ if (result == TCL_OK) {
+ Tcl_Obj *tcl_result;
+ [invocation invoke];
+ fprintf(stderr, "result size = %d\n", [signature methodReturnLength]);
+ void* result_ptr;
+ [invocation getReturnValue:&result_ptr];
+ const char* result_type = [signature methodReturnTypeString];
+ result = objc_to_tclobj(interp, &tcl_result, result_type, result_ptr);
+ Tcl_SetObjResult(interp, tcl_result);
+ }
+ }
+
+ [pool release];
+ return result;
+}
+
+
+/*
+ * Invoke the standard 'unknown' procedure
+ */
+static int StandardUnknownObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
+ Tcl_CmdInfo info;
+ int result;
+ if (!Tcl_GetCommandInfo(interp, "tclobjc::standard_unknown", &info) || !info.isNativeObjectProc)
+ return (TCL_ERROR);
+
+ result = (*info.objProc) (info.objClientData, interp, objc, objv);
+
+ /*
+ * Make sure the string value of the result is valid.
+ */
+ (void) Tcl_GetStringResult(interp);
+
+ return (result);
+}
+
+
+/*
+ * Replacement 'unknown' procedure.
+ * Dispatches messages to Objective C classes, if one exists, or calls
+ * standard 'unknown' procedure
+ */
+static int UnknownObjCmd(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
+ const char *className;
+ id classId;
+ Tcl_Obj **sobjv;
+ int sobjc, result;
+
+ if (objc < 2) {
+ return (StandardUnknownObjCmd(NULL, interp, objc, objv));
+ }
+
+ className = Tcl_GetStringFromObj(objv[1], NULL);
+
+ /*
+ * In the GNU Objective-C runtime, objc_getClass calls
+ * abort() if the class is not found.
+ *
+ * On Mac OS X (10.0+), if the class is not found, objc_getClass
+ * calls the class handler call back, and checks again.
+ * If the class is again not found, objc_getClass returns nil
+ */
+#if defined(APPLE_RUNTIME)
+ if ((classId = objc_getClass(className)) == nil)
+#elif defined(GNU_RUNTIME)
+ if ((classId = objc_lookUpClass(className)) == nil)
+#endif
+ return (StandardUnknownObjCmd(NULL, interp, objc, objv));
+
+ if (objc < 3) {
+ Tcl_WrongNumArgs(interp, 1, objv, "arguments");
+ return TCL_ERROR;
+ }
+
+ /* dispatch, minus first argument */
+ sobjc = objc - 1;
+ sobjv = malloc(sobjc * sizeof(Tcl_Obj));
+ memcpy(sobjv, &objv[1], sobjc * sizeof(Tcl_Obj));
+ result = tclobjc_dispatch((ClientData *) classId, interp, sobjc, sobjv);
+ free(sobjv);
+ return (result);
+}
+
+int tclobjc_init(Tcl_Interp *interp)
+{
+ if(Tcl_InitStubs(interp, "8.3", 0) == NULL)
+ return (TCL_ERROR);
+
+ /* Register custom Tcl_Obj types */
+ TclObjC_RegisterTclObjTypes();
+
+ if(Tcl_Eval(interp, "rename ::unknown tclobjc::standard_unknown") != TCL_OK)
+ return (TCL_ERROR);
+ Tcl_CreateObjCommand(interp, "unknown", UnknownObjCmd, NULL, NULL);
+
+ if(Tcl_PkgProvide(interp, "TclObjC", "1.0") != TCL_OK)
+ return TCL_ERROR;
+ return TCL_OK;
+}
Added: trunk/base/src/tclobjc1.0/tclobjc_types.c
===================================================================
--- trunk/base/src/tclobjc1.0/tclobjc_types.c (rev 0)
+++ trunk/base/src/tclobjc1.0/tclobjc_types.c 2007-06-14 00:10:40 UTC (rev 26137)
@@ -0,0 +1,198 @@
+/*
+ * TclObjTypes.c
+ *
+ * Copyright (c) 2004 Landon J. Fuller <landonf at opendarwin.org>
+ * 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 the copyright owner nor the names of 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+/* Required by glibc for asprintf() */
+#define _GNU_SOURCE
+#include <stdio.h>
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <objc/objc.h>
+
+#include <tcl.h>
+
+/*
+ * Tcl Objc Id Object
+ */
+
+/** All (evil) Objective-C string pointer representations start with a common prefix. */
+static const char tclobjc_name_prefix[] = "objc.id-";
+
+/** Invalid Objective-C pointer string representation. */
+static const char tclobjc_invalid_string_error[] = "Invalid Objective-C object: ";
+
+/* Standard prototypes */
+static void dup_objc_internalrep(Tcl_Obj *srcPtr, Tcl_Obj *dupPtr);
+static void update_objc_string(Tcl_Obj *objPtr);
+static int set_objc_fromstring(Tcl_Interp *interp, Tcl_Obj *objPtr);
+
+static Tcl_ObjType tclObjcIdType = {
+ /* Name */
+ "tclObjcId",
+ /* Tcl_FreeInternalRepProc */
+ NULL,
+ /* Tcl_DupInternalRepProc */
+ &dup_objc_internalrep,
+ /* Tcl_UpdateStringProc */
+ &update_objc_string,
+ /* Tcp_SetFromAnyProc */
+ &set_objc_fromstring
+};
+
+/*
+ * Private Functions
+ */
+
+/**
+ * Duplicate the internal objective-c pointer.
+ */
+static void dup_objc_internalrep(Tcl_Obj *srcPtr, Tcl_Obj *dupPtr) {
+ dupPtr->internalRep.otherValuePtr = srcPtr->internalRep.otherValuePtr;
+}
+
+
+/**
+ * Update the string value based on the internal pointer address.
+ */
+static void update_objc_string (Tcl_Obj *objPtr) {
+ char *string;
+ int length;
+
+ if ((length = asprintf(&string, "objc.id-%p", objPtr->internalRep.otherValuePtr)) <= 0) {
+ /* ack! malloc failed! */
+ abort();
+ }
+
+ /* Terminating NULL */
+ length++;
+
+ /* objPtr->bytes must be allocated with Tcl_Alloc */
+ objPtr->bytes = Tcl_Alloc(length);
+ strcpy(objPtr->bytes, string);
+ free(string);
+}
+
+/**
+ * Evil piece of code that set's the internal ObjC pointer value by
+ * converting the provided string value.
+ */
+static int set_objc_fromstring (Tcl_Interp *interp, Tcl_Obj *objPtr) {
+ Tcl_ObjType *oldTypePtr = objPtr->typePtr;
+ Tcl_Obj *tcl_result;
+ char *string, *p;
+ id objcId;
+ int length;
+
+ string = Tcl_GetStringFromObj(objPtr, &length);
+
+ /* Verify that this is a valid string */
+ if ((length < sizeof(tclobjc_name_prefix)) ||
+ (strncmp(string, tclobjc_name_prefix,
+ sizeof(tclobjc_name_prefix)) != 0)) {
+ goto invalid_obj;
+ }
+
+ p = string + sizeof(tclobjc_name_prefix);
+
+ if (sscanf(p, "%p", &objcId) != 1)
+ goto invalid_obj;
+
+ /* Free the old internal representation before setting new one */
+ if (oldTypePtr != NULL && oldTypePtr->freeIntRepProc != NULL) {
+ oldTypePtr->freeIntRepProc(objPtr);
+ }
+
+ objPtr->internalRep.otherValuePtr = objcId;
+ objPtr->typePtr = &tclObjcIdType;
+
+ return (TCL_OK);
+
+
+ /* Cleanup Handler */
+invalid_obj:
+ if (interp) {
+ tcl_result = Tcl_NewStringObj(tclobjc_invalid_string_error, sizeof(tclobjc_invalid_string_error));
+ Tcl_AppendObjToObj(tcl_result, objPtr);
+ Tcl_SetObjResult(interp, tcl_result);
+ }
+ return (TCL_ERROR);
+}
+
+/*
+ * Public Functions
+ */
+
+/**
+ * Create a new Tcl Object wrapper for a given Objective-C object.
+ */
+Tcl_Obj *TclObjC_NewIdObj(id objcId) {
+ Tcl_Obj *objPtr;
+
+ objPtr = Tcl_NewObj();
+
+ objPtr->bytes = NULL;
+
+ objPtr->internalRep.otherValuePtr = objcId;
+ objPtr->typePtr = &tclObjcIdType;
+ return (objPtr);
+}
+
+/**
+ * Returns a pointer to the wrapped Objective-C object.
+ */
+int TclObjC_GetIdFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, id *objcId)
+{
+ int result;
+
+ if (objPtr->typePtr == &tclObjcIdType) {
+ *objcId = objPtr->internalRep.otherValuePtr;
+ return (TCL_OK);
+ }
+
+ result = set_objc_fromstring(interp, objPtr);
+
+ if (result == TCL_OK)
+ *objcId = objPtr->internalRep.otherValuePtr;
+
+ return (result);
+}
+
+/**
+ * Register the Tcl Objective-C Object type(s).
+ */
+void TclObjC_RegisterTclObjTypes(void) {
+ Tcl_RegisterObjType(&tclObjcIdType);
+}
Added: trunk/base/src/tclobjc1.0/tclobjc_types.h
===================================================================
--- trunk/base/src/tclobjc1.0/tclobjc_types.h (rev 0)
+++ trunk/base/src/tclobjc1.0/tclobjc_types.h 2007-06-14 00:10:40 UTC (rev 26137)
@@ -0,0 +1,34 @@
+/*
+ * TclObjTypes.h
+ *
+ * Copyright (c) 2004 Landon J. Fuller <landonf at opendarwin.org>
+ * 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 the copyright owner nor the names of 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.
+ */
+
+Tcl_Obj *TclObjC_NewIdObj(id objcId);
+int TclObjC_GetIdFromObj(Tcl_Interp *interp, Tcl_Obj *objPtr, id *objcId);
+void TclObjC_RegisterTclObjTypes(void);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20070613/1de47c86/attachment.html
More information about the macports-changes
mailing list