Ronald Oussoren avatar Ronald Oussoren committed 1b07d36

* Improve py3k port
* Don't use Carbon.CF compatibility code, Carbon.CF is not very
useful anyway and keeping this code working is too much of
a hassle.
* Improve test coverage for objc.object_property

Comments (0)

Files changed (13)

pyobjc-core/Lib/PyObjCTools/TestSupport.py

             offset = 0
         info = method.__metadata__()
         type = info['arguments'][argno+offset]['type']
-        if type != '^?':
+        if type != b'^?':
             self.fail(message or "arg %d of %s is not of type function_pointer"%(
                 argno, method))
 

pyobjc-core/Lib/objc/_convenience.py

 
 CLASS_METHODS['NSNull'] = (
     ('__nonzero__',  lambda self: False ),
+    ('__bool__',  lambda self: False ),
 )
 
 NSDecimalNumber = lookUpClass('NSDecimalNumber')
             result.symmetric_difference_update(other)
             return result
 
-        def __len__(self):
-            return len(self.__value)
 
     class nsdict_keys(nsdict_view):
         __slots__=('__value')
         def __init__(self, value):
             self.__value =  value
 
+        def __len__(self):
+            return len(self.__value)
+
         def __iter__(self):
             return iter(self.__value)
 
         def __init__(self, value):
             self.__value =  value
 
+        def __len__(self):
+            return len(self.__value)
+
         def __iter__(self):
-            return iter(self.objectEnumerator())
+            return iter(self.__value.objectEnumerator())
 
         def __contains__(self, value):
             for v in iter(self):
         def __init__(self, value):
             self.__value =  value
 
+        def __len__(self):
+            return len(self.__value)
+
         def __iter__(self):
             for k in self.__value:
                 yield (k, self.__value[k])

pyobjc-core/Lib/objc/_properties.py

         self._getter = None
         self._setter = None
         self._validate = None
-        self._depends_on = list(depends_on)
+        if depends_on is None:
+            self._depends_on = ()
+        else:
+            self._depends_on = list(depends_on)
 
         self.__getprop = None
         self.__setprop = None

pyobjc-core/Modules/objc/libffi_support.m

 
 		if (stubUserdata->argCount == Py_SIZE(methinfo) && !haveVarArgs && !haveVarKwds) {
 			/* OK */
-		} else if ((stubUserdata->argCount <= 1) && haveVarArgs && haveVarKwds) {
+		} else if ((stubUserdata->argCount <= 1) && (haveVarArgs || haveVarKwds)) {
 			/* OK: 
 			 *    def m(self, *args, **kwds), or 
 			 *    def m(*args, **kwds)  

pyobjc-core/Modules/objc/method-signature.m

 				if (descr->sel_type == NULL) {
 					return -1;
 				}
-			} 
-#if PY_MAJOR_VERSION == 2
-			else if (PyString_Check(d)) {
-				descr->sel_type = PyObjCUtil_Strdup(PyString_AsString(d));
+			} else if (PyBytes_Check(d)) {
+				descr->sel_type = PyObjCUtil_Strdup(PyBytes_AsString(d));
 				if (descr->sel_type == NULL) {
 					return -1;
 				}
 			}
-#endif
 		}
 	}
 

pyobjc-core/Modules/objc/module.m

 		
 		name = PyObject_GetAttrString(aMethod, "__name__");
 
-#if PY_MAJOR_VERSION == 2
+#if PY_MAJOR_VERSION == 3
 		if (PyBytes_Check(name)) {
 			PyObject* t = PyUnicode_Decode(
 					PyBytes_AsString(name),
 	global_release_pool = [[NSAutoreleasePool alloc] init];
 	[OC_NSAutoreleasePoolCollector newAutoreleasePool];
 
+#ifndef Py_ARG_BYTES
+#error "No Py_ARG_BYTES"
+#endif
+
+#ifndef Py_ARG_NSInteger
+#error "No Py_ARG_NSInteger"
+#endif
+
+#ifndef Py_ARG_NSUInteger
+#error "No Py_ARG_NSUInteger"
+#endif
+
 #if PY_MAJOR_VERSION == 3
 	return m;
 #endif

pyobjc-core/Modules/objc/objc-class.m

 nsmutabledata_getbuffer(PyObject* obj, Py_buffer* view, int flags)
 {
 	NSMutableData *self = (NSMutableData *)PyObjCObject_GetObject(obj);
-	if (flags & PyBUF_WRITABLE) {
+	if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE) {
 		return PyBuffer_FillInfo(view, obj, (void*)[self mutableBytes], [self length], 0, flags);
 	} else {
 		return PyBuffer_FillInfo(view, obj, (void*)[self bytes], [self length], 1, flags);

pyobjc-core/Modules/objc/objc-object.m

 		 * Don't call 'description' for uninitialized objects, that
 		 * is undefined behaviour and will crash the interpreter sometimes.
 		 */
-		//res = PyObject_CallMethod((PyObject*)self, "description", NULL);
-		res = NULL;
+		res = PyObject_CallMethod((PyObject*)self, "description", NULL);
+		//res = NULL;
 		if (res == NULL) {
 			PyErr_Clear();
 		} else {

pyobjc-core/Modules/objc/parsexml.m

 {
 	char* name = attribute_string(cur_node, "name", NULL);
 	char* value = attribute_string(cur_node, "value", "value64");
+	BOOL nsstring = attribute_bool(cur_node, "nsstring", NULL, NO);
 
 	if (name != NULL && value != NULL && *value != '\0') {
-		size_t i, len = strlen(value);
-
-		PyObject* v = NULL;
-		for (i = 0; i < len; i++) {
-			if (((unsigned char)value[i]) > 127) {
-				v = PyUnicode_DecodeUTF8(value, len, "strict");
-				if (v == NULL) {
-					if (name) xmlFree(name);
-					if (value) xmlFree(value);
-					return -1;
-				}
-				break;
-			}
-		}
-		if (v == NULL) {
+		size_t len = strlen(value);
+		PyObject* v;
+		if (nsstring) {
+			v = PyUnicode_DecodeUTF8(value, len, "strict");
+		} else {
 			v = PyBytes_InternFromStringAndSize(value, len);
 		}
 		if (v == NULL) {

pyobjc-core/Modules/objc/pyobjc-compat.h

 
 #endif
 
-#if PY_VERSION_HEX < 0x03000000
+#if PY_MAJOR_VERSION == 2
 
 #ifndef Py_ARG_BYTES
 #define Py_ARG_BYTES "s"
 
 #if __LP64__
 #define Py_ARG_NSInteger "l"
-#define Py_ARG_NSUInteger "L"
+#define Py_ARG_NSUInteger "k"
 #else
 #define Py_ARG_NSInteger "i"
-#define Py_ARG_NSUInteger "L"
+#define Py_ARG_NSUInteger "I"
 #endif
 
 #if PY_MAJOR_VERSION == 2

pyobjc-core/Modules/objc/pyobjc.h

 
 // Loading in AppKit on Mac OS X 10.3 results in
 // a bit less than 1500 classes.
-#define PYOBJC_EXPECTED_CLASS_COUNT 2048
+#define PYOBJC_EXPECTED_CLASS_COUNT 3000
 #define PY_SSIZE_T_CLEAN
 
 #include <Python.h>
 #include "structmember.h"
 #include "pyobjc-compat.h"
 
+/* PyObjC_DEBUG: If defined the bridge will perform more internal checks */
+#ifdef Py_DEBUG
+   /* Enable when Python is compiled with internal checks enabled */
+#  define PyObjC_DEBUG
+#endif
+
+/* PyObjC_ERROR_ABORT: If defined an internal error will result in an abort() */
+#define	PyObjC_ERROR_ABORT 1
+
 
 #include <objc/objc-runtime.h>
 #include <objc/objc.h>
 // how do we make this dependent on sizeof(unichar)??
 #if Py_UNICODE_SIZE == 2
 #define PyObjC_UNICODE_FAST_PATH
+#else
+#error "Py_UNICODE_SIZE != 2 is not supported"
 #endif
 
 #include "objc-runtime-compat.h"
 
 
 
-//#ifdef Py_DEBUG
-#if 1
+#ifdef PyObjC_DEBUG
+
+#ifdef PyObjCErr_InternalError
+#define _PyObjC_InternalError_Bailout()	abort()
+#else
+#define _PyObjC_InternalError_Bailout()	((void)0)
+#endif
 
 #define PyObjCErr_InternalError() \
+    do { \
 	PyErr_Format(PyObjCExc_InternalError, \
 	   "PyObjC: internal error in %s at %s:%d", \
-	   __FUNCTION__, __FILE__, __LINE__)
+	   __FUNCTION__, __FILE__, __LINE__); \
+	   _PyObjC_InternalError_Bailout(); \
+    } while (0)
+
+#define PyObjCErr_InternalErrorMesg(msg) \
+    do { \
+	PyErr_Format(PyObjCExc_InternalError, \
+	  "PyObjC: internal error in %s at %s:%d: %s", \
+	   __FUNCTION__, __FILE__, __LINE__, msg) \
+	   _PyObjC_InternalError_Bailout(); \
+    } while (0)
+
 #define PyObjC_Assert(expr, retval) \
-	if (!(expr)) { PyObjCErr_InternalError(); return (retval); }
+	if (!(expr)) { PyObjCErr_InternalErrorMesg(\
+			"assertion failed: " #expr); return (retval); }
 
 #else
 
+#define PyObjCErr_InternalError()	((void)0)
+#define PyObjCErr_InternalErrorMesg(mesg)	((void)0)
+
 #define PyObjC_Assert(expr, retval)	((void)0)
 
 #endif

pyobjc-core/Modules/objc/toll-free-bridging.m

 
 #import <Foundation/NSURL.h>
 
-#if !defined(__OBJC2__) && (PY_VERSION_HEX < 0x02050000)
+#if 0 && !defined(__OBJC2__) && (PY_MAJOR_VERSION == 2)
 #include "pymactoolbox.h"
 #endif
 
 PyObjC_IDToCFType(id argument __attribute__((__unused__)))
 {
 
-#if !defined(__OBJC2__) && (PY_MAJOR_VERSION == 2)
+#if 0 && !defined(__OBJC2__) && (PY_MAJOR_VERSION == 2)
 	CFTypeRef typeRef = (CFTypeRef)argument;
 	CFTypeID typeID = CFGetTypeID(argument);
 

pyobjc-core/PyObjCTest/test_metadata.py

         if sys.version_info[0] == 2:
             self.assertEquals(
                 [ ord(x)+1 for x in "hello\0world" ],
-                [ ord(x) for x in v ])
+                [ x for x in v ])
         else:
             self.assertEquals(
                 [ x+1 for x in b"hello\0world" ],
         if sys.version_info[0] == 2:
             self.assertEquals(
                 [ ord(x)+2 for x in b"hello\0world" ],
-                [ ord(x) for x in v ])
+                [ x for x in v ])
         else:
             self.assertEquals(
                 [ x+2 for x in b"hello\0world" ],
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.