[PyObjC-svn] r2019 - in trunk/pyobjc/pyobjc-core: . Lib/objc Lib/objc/test Modules/objc

[email protected]
Newsgroups gmane.comp.python.pyobjc.cvs
Message-ID <[email protected]>
Author: ronaldoussoren
Date: Wed Oct  8 13:56:50 2008
New Revision: 2019

Log:
various bugfixes

Modified:
   trunk/pyobjc/pyobjc-core/Lib/objc/_bridgesupport.py
   trunk/pyobjc/pyobjc-core/Lib/objc/test/test_objc.py
   trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m
   trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m
   trunk/pyobjc/pyobjc-core/Modules/objc/module.m
   trunk/pyobjc/pyobjc-core/Modules/objc/objc_support.m
   trunk/pyobjc/pyobjc-core/Modules/objc/objc_util.m
   trunk/pyobjc/pyobjc-core/Modules/objc/struct-wrapper.m
   trunk/pyobjc/pyobjc-core/Modules/objc/varlist.m
   trunk/pyobjc/pyobjc-core/setup.py

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/_bridgesupport.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/_bridgesupport.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/_bridgesupport.py	Wed Oct  8 13:56:50 2008
@@ -38,8 +38,12 @@
 NSAutoreleasePool = objc.lookUpClass('NSAutoreleasePool')
 _gBridgeSupportDirectories = (
         '/System/Library/BridgeSupport',
-        '/Library/BridgeSupport',
-        os.path.expanduser('~/Library/BridgeSupport'),
+
+# Don't use the rest of the default search path to avoid relying on data that
+# might be on a single system. That would make it harder to create standalone
+# apps in some cases.
+#        '/Library/BridgeSupport',
+#        os.path.expanduser('~/Library/BridgeSupport'),
     )
 
 for method in ('alloc', 'copy', 'copyWithZone:', 'mutableCopy', 'mutableCopyWithZone:'):
@@ -118,7 +122,9 @@
     globals['super'] = objc.super
 
     if 1:
-        # Prefer PyObjC's metadata for now
+        # Look for metadata in the Python wrapper and prefer that over the
+        # data in the framework or in system locations. 
+        # Needed because the system bridgesupport files are buggy.
         try:
             exists = pkg_resources.resource_exists(
                     frameworkName, "PyObjC.bridgesupport")

Modified: trunk/pyobjc/pyobjc-core/Lib/objc/test/test_objc.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/Lib/objc/test/test_objc.py	(original)
+++ trunk/pyobjc/pyobjc-core/Lib/objc/test/test_objc.py	Wed Oct  8 13:56:50 2008
@@ -86,17 +86,17 @@
         import pickle
 
         o = NSObject.alloc().init()
-        self.assertRaises(TypeError, pickle.dumps, o, 0)
-        self.assertRaises(TypeError, pickle.dumps, o, 1)
-        self.assertRaises(TypeError, pickle.dumps, o, 2)
+        self.assertRaises((TypeError, ValueError), pickle.dumps, o, 0)
+        self.assertRaises((TypeError, ValueError), pickle.dumps, o, 1)
+        self.assertRaises((TypeError, ValueError), pickle.dumps, o, 2)
 
     def testCPicklePure(self):
         import cPickle as pickle
 
         o = NSObject.alloc().init()
-        self.assertRaises(TypeError, pickle.dumps, o, 0)
-        self.assertRaises(TypeError, pickle.dumps, o, 1)
-        self.assertRaises(TypeError, pickle.dumps, o, 2)
+        self.assertRaises((TypeError, ValueError), pickle.dumps, o, 0)
+        self.assertRaises((TypeError, ValueError), pickle.dumps, o, 1)
+        self.assertRaises((TypeError, ValueError), pickle.dumps, o, 2)
 
 
 class TestDescription (objc.test.TestCase):

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/class-builder.m	Wed Oct  8 13:56:50 2008
@@ -2078,20 +2078,20 @@
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
 	// Set up a KVO stack so you only get one notification from this
-	PyObjC_DURING
+	NS_DURING
 		if (_KVOHackLevel() == BROKEN_KVO) {
 			[self willChangeValueForKey:key];
 		}
-	PyObjC_HANDLER
-	PyObjC_ENDHANDLER
+	NS_HANDLER
+	NS_ENDHANDLER
 #endif
 
-	PyObjC_DURING
+	NS_DURING
 		// First check super
 		objc_superSetClass(spr, (Class)userdata);
 		objc_superSetReceiver(spr, self);
 		(void)objc_msgSendSuper(&spr, _meth, value, key);
-	PyObjC_HANDLER
+	NS_HANDLER
 		/* Parent doesn't know the key, try to create in the 
 		 * python side, just like for plain python objects.
 		 */
@@ -2153,7 +2153,7 @@
 #endif
 			[localException raise];
 		}
-	PyObjC_ENDHANDLER
+	NS_ENDHANDLER
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
 	// Pop the KVO stack

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/libffi_support.m	Wed Oct  8 13:56:50 2008
@@ -131,6 +131,12 @@
 	
 	argtype++;
 	while (*argtype != _C_STRUCT_E) {
+		if (*argtype == '"') {
+			/* Skip field name */
+			argtype++;
+			while (*argtype++ != '"') {}
+		}
+
 		argtype = PyObjCRT_SkipTypeSpec(argtype);
 		if (argtype == NULL) return -1;
 		res ++;
@@ -182,7 +188,7 @@
 	type->alignment = PyObjCRT_AlignOfType(argtype);
 
 	/* Libffi doesn't really know about arrays as part of larger 
-	 * data-structres (e.g. struct foo { int field[3]; };). We fake it
+	 * data-structures (e.g. struct foo { int field[3]; };). We fake it
 	 * by treating the nested array as a struct. These seems to work 
 	 * fine on MacOS X.
 	 */
@@ -266,6 +272,11 @@
 	if (*curtype == '=') {
 		curtype ++;
 		while (*curtype != _C_STRUCT_E) {
+			if (*curtype == '"') {
+				/* Skip field name */
+				curtype++;
+				while (*curtype++ != '"') {}
+			}
 			type->elements[field_count] = 
 				signature_to_ffi_type(curtype);
 			if (type->elements[field_count] == NULL) {
@@ -1978,7 +1989,11 @@
 
 		switch (*argtype) {
 		case _C_INOUT:
-			if (argtype[1] == _C_PTR) {
+			if (argtype[1] == _C_PTR && PyObjCPointerWrapper_HaveWrapper(argtype+1)) {
+				itemAlign = PyObjCRT_AlignOfType(argtype+1);
+				itemSize = PyObjCRT_SizeOfType(argtype+1);
+
+			} else if (argtype[1] == _C_PTR) {
 				(*byref_out_count) ++;
 				(*byref_in_count) ++;
 				itemAlign = PyObjCRT_AlignOfType(argtype+2);
@@ -3242,6 +3257,7 @@
 			}
 		}
 	}
+
 	return result;
 
 error_cleanup:

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/module.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/module.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/module.m	Wed Oct  8 13:56:50 2008
@@ -314,7 +314,7 @@
 		objcMethod->type = strdup(
 				PyObjCSelector_Signature(aMethod));
 
-		PyObjC_RemoveInternalTypeCodes(objcMethod->type);
+		PyObjC_RemoveInternalTypeCodes((char*)(objcMethod->type));
 		if (objcMethod->type == NULL) {
 			goto cleanup_and_return_error;
 		}

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc_support.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc_support.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc_support.m	Wed Oct  8 13:56:50 2008
@@ -732,6 +732,8 @@
 		return __alignof__(void*);
 
 	default:
+		printf("alignoftype\n");
+		abort();
 		PyErr_Format(PyObjCExc_InternalError, 
 			"PyObjCRT_AlignOfType: Unhandled type '%#x' %s", *type, type);
 		return -1;
@@ -2015,7 +2017,7 @@
 				PyString_AsString (argument)[0];
 			return 0;
 		}
-		r = depythonify_unsigned_int_value(argument, "unsigned short",
+		r = depythonify_unsigned_int_value(argument, "unsigned char",
 			&utemp, UCHAR_MAX);
 		if (r == 0) {
 			*(unsigned int*)datum = utemp;
@@ -2171,7 +2173,7 @@
 				PyString_AsString (argument)[0];
 			return 0;
 		}
-		r = depythonify_unsigned_int_value(argument, "unsigned short",
+		r = depythonify_unsigned_int_value(argument, "unsigned char",
 			&utemp, UCHAR_MAX);
 		if (r == 0) {
 			*(unsigned char*)datum = utemp;

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/objc_util.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/objc_util.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/objc_util.m	Wed Oct  8 13:56:50 2008
@@ -623,12 +623,24 @@
 	}
 
 	if ((eltsize == 1 || eltsize == 0) && 
-		!(*elementType == _C_NSBOOL || *elementType == _C_BOOL || *elementType == _C_CHAR_AS_INT) ) {
+		!(*elementType == _C_NSBOOL || *elementType == _C_BOOL || *elementType == _C_CHAR_AS_INT)) {
 		/* A simple byte-array */
+		/* Note: PyUnicode is explicitly excluded because it
+		 * implemenents the character buffer interface giving access
+		 * to the raw implementation. That's almost always not want
+		 * you want.
+		 */
 		char* buf;
 		Py_ssize_t bufsize;
 		int have_buffer;
 
+		if (PyUnicode_Check(pythonList)) {
+			PyErr_Format(PyExc_TypeError,
+				"Expecting byte-buffer, got %s",
+				pythonList->ob_type->tp_name);
+			return -1;
+		}
+
 
 		have_buffer = buffer_get(writable, pythonList, (void**)&buf, &bufsize);
 		if (have_buffer == -1) {

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/struct-wrapper.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/struct-wrapper.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/struct-wrapper.m	Wed Oct  8 13:56:50 2008
@@ -1118,7 +1118,7 @@
 	}
 
 	/* Register again using the typecode used in the ObjC runtime */
-	PyObjC_RemoveInternalTypeCodes(signature);
+	PyObjC_RemoveInternalTypeCodes((char*)signature);
 	r = PyDict_SetItemString(structRegistry, signature, structType);
 	if (r == -1) {
 		return NULL;

Modified: trunk/pyobjc/pyobjc-core/Modules/objc/varlist.m
==============================================================================
--- trunk/pyobjc/pyobjc-core/Modules/objc/varlist.m	(original)
+++ trunk/pyobjc/pyobjc-core/Modules/objc/varlist.m	Wed Oct  8 13:56:50 2008
@@ -254,6 +254,9 @@
 	if (tp == NULL) {
 		return NULL;
 	}
+	if (*tp == _C_VOID) {
+		*(char*)tp = _C_CHAR_AS_TEXT;
+	}
 	result = PyObject_New(PyObjC_VarList, &PyObjC_VarList_Type);
 	if (result == NULL) {
 		return NULL;

Modified: trunk/pyobjc/pyobjc-core/setup.py
==============================================================================
--- trunk/pyobjc/pyobjc-core/setup.py	(original)
+++ trunk/pyobjc/pyobjc-core/setup.py	Wed Oct  8 13:56:50 2008
@@ -295,7 +295,7 @@
 Topic :: Software Development :: User Interfaces
 """.splitlines())
 
-install_requires = setup_requires = ['py2app>=0.4.0', 'bdist_mpkg>=0.4.2']
+install_requires = setup_requires = [] # ['py2app>=0.4.0', 'bdist_mpkg>=0.4.2']
 
 dist = setup(
     name = "pyobjc-core", 

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.