Commits

Ronald Oussoren committed 11de5e0

Port to py3k

Comments (0)

Files changed (154)

pyobjc-framework-Cocoa/Lib/AppKit/PyObjC.bridgesupport

   </informal_protocol>
   <informal_protocol name='NSEditor'>
     <method selector='commitEditing' type='B@:' />
-    <method selector='commitEditingWithDelegate:didCommitSelector:contextInfo:' type='v@:@:^v' />
+    <method selector='commitEditingWithDelegate:didCommitSelector:contextInfo:' type='v@:@:^v' type64='v@:@:^v' />
     <method selector='discardEditing' type='v@:' />
   </informal_protocol>
   <informal_protocol name='NSEditorRegistration'>
       <retval type='B' />
     </method>
     <method selector='commitEditingWithDelegate:didCommitSelector:contextInfo:'>
-      <arg index='1' sel_of_type='v@:@B^v' />
-      <arg index='2' type='^v' />
+      <arg index='1' type=':' type64=':' sel_of_type='v@:@B^v' />
+      <arg index='2' type='^v' type64='^v' />
     </method>
     <method selector='isEditing'>
       <retval type='B' />
       <retval type='B' />
     </method>
     <method selector='commitEditingWithDelegate:didCommitSelector:contextInfo:'>
-      <arg index='1' sel_of_type='v@:@B^v' />
+      <arg index='1' type=':' sel_of_type='v@:@B^v' />
     </method>
   </class>
   <class name='NSWindow'>

pyobjc-framework-Cocoa/Lib/AppKit/_nsapp.py

     """
     def __getrealapp(self):
         d = {}
-        objc.loadBundleVariables(__bundle__, d, [ ('NSApp', '@' ) ])
+        objc.loadBundleVariables(__bundle__, d, [ ('NSApp', b'@' ) ])
         return d.get('NSApp')
 
     __class__ = property(lambda self: self.__getrealapp().__class__)

pyobjc-framework-Cocoa/Lib/Foundation/_nsindexset.py

     return self.indexPathByAddingIndex_(value)
 
 
-objc.addConvenienceForSelector('length', [
+objc.addConvenienceForSelector(b'length', [
     ('__len__', __len__),
 ])
-objc.addConvenienceForSelector('indexAtPosition:', [
+objc.addConvenienceForSelector(b'indexAtPosition:', [
     ('__getitem__', __getitem__),
 ])
-objc.addConvenienceForSelector('indexPathByAddingIndex:', [
+objc.addConvenienceForSelector(b'indexPathByAddingIndex:', [
     ('__add__', __add__),
 ])

pyobjc-framework-Cocoa/Lib/Foundation/_nsobject.py

 
 class NSObject (objc.Category(NSObject)):
 
-    @objc.namedSelector("_pyobjc_performOnThread:")
+    @objc.namedSelector(b"_pyobjc_performOnThread:")
     def _pyobjc_performOnThread_(self, callinfo):
         try:
             sel, arg = callinfo
             import traceback
             traceback.print_exc(fp=sys.stderr)
 
-    @objc.namedSelector("_pyobjc_performOnThreadWithResult:")
+    @objc.namedSelector(b"_pyobjc_performOnThreadWithResult:")
     def _pyobjc_performOnThreadWithResult_(self, callinfo):
         try:
             sel, arg, result = callinfo
 
 
     if hasattr(NSObject, "performSelector_onThread_withObject_waitUntilDone_"):
-        @objc.namedSelector("pyobjc_performSelector:onThread:withObject:waitUntilDone:")
+        @objc.namedSelector(b"pyobjc_performSelector:onThread:withObject:waitUntilDone:")
         def pyobjc_performSelector_onThread_withObject_waitUntilDone_(
                 self, aSelector, thread, arg, wait):
             """
             self.performSelector_onThread_withObject_waitUntilDone_(
                     'pyobjc_performOnThread:', thread, (aSelector, arg), wait)
 
-        @objc.namedSelector("pyobjc_performSelector:onThread:withObject:waitUntilDone:modes:")
+        @objc.namedSelector(b"pyobjc_performSelector:onThread:withObject:waitUntilDone:modes:")
         def pyobjc_performSelector_onThread_withObject_waitUntilDone_modes_(
                 self, aSelector, thread, arg, wait, modes):
             """
             self.performSelector_onThread_withObject_waitUntilDone_modes_(
                 'pyobjc_performOnThread:', thread, (aSelector, arg), wait, modes)
 
-    @objc.namedSelector("pyobjc_performSelector:withObject:afterDelay:")
+    @objc.namedSelector(b"pyobjc_performSelector:withObject:afterDelay:")
     def pyobjc_performSelector_withObject_afterDelay_(
             self, aSelector, arg, delay):
         """
         self.performSelector_withObject_afterDelay_(
             'pyobjc_performOnThread:', (aSelector, arg), delay)
 
-    @objc.namedSelector("pyobjc_performSelector:withObject:afterDelay:inModes:")
+    @objc.namedSelector(b"pyobjc_performSelector:withObject:afterDelay:inModes:")
     def pyobjc_performSelector_withObject_afterDelay_inModes_(
             self, aSelector, arg, delay, modes):
         """
             'pyobjc_performOnThread:', (aSelector, arg), delay, modes)
 
     if hasattr(NSObject, "performSelectorInBackground_withObject_waitUntilDone_"):
-        @objc.namedSelector("pyobjc_performSelectorInBackground:withObject:")
+        @objc.namedSelector(b"pyobjc_performSelectorInBackground:withObject:")
         def pyobjc_performSelectorInBackground_withObject_(
                 self, aSelector, arg):
             """
                 'pyobjc_performOnThread:', (aSelector, arg))
 
 
-    @objc.namedSelector("pyobjc_performSelectorInBackground:withObject:waitUntilDone:")
+    @objc.namedSelector(b"pyobjc_performSelectorInBackground:withObject:waitUntilDone:")
     def pyobjc_performSelectorOnMainThread_withObject_waitUntilDone_(
             self, aSelector, arg, wait):
         """
         self.performSelectorOnMainThread_withObject_waitUntilDone_(
             'pyobjc_performOnThread:', (aSelector, arg), wait)
 
-    @objc.namedSelector("pyobjc_performSelectorOnMainThread:withObject:waitUntilDone:modes:")
+    @objc.namedSelector(b"pyobjc_performSelectorOnMainThread:withObject:waitUntilDone:modes:")
     def pyobjc_performSelectorOnMainThread_withObject_waitUntilDone_modes_(
             self, aSelector, arg, wait, modes):
         """
 
     # And some a some versions that return results
 
-    @objc.namedSelector("pyobjc_performSelectorOnMainThread:withObject:modes:")
+    @objc.namedSelector(b"pyobjc_performSelectorOnMainThread:withObject:modes:")
     def pyobjc_performSelectorOnMainThread_withObject_modes_(
             self, aSelector, arg, modes):
         """
             exc_type, exc_value, exc_trace = result
             raise exc_type, exc_value, exc_trace
 
-    @objc.namedSelector("pyobjc_performSelectorOnMainThread:withObject:")
+    @objc.namedSelector(b"pyobjc_performSelectorOnMainThread:withObject:")
     def pyobjc_performSelectorOnMainThread_withObject_(
             self, aSelector, arg):
         result = []
         # These methods require Leopard, don't define them if the 
         # platform functionality isn't present.
 
-        @objc.namedSelector("pyobjc_performSelector:onThread:withObject:modes:")
+        @objc.namedSelector(b"pyobjc_performSelector:onThread:withObject:modes:")
         def pyobjc_performSelector_onThread_withObject_modes_(
                 self, aSelector, thread, arg, modes):
             result = []
                 exc_type, exc_value, exc_trace = result
                 raise exc_type, exc_value, exc_trace
 
-        @objc.namedSelector("pyobjc_performSelector:onThread:withObject:")
+        @objc.namedSelector(b"pyobjc_performSelector:onThread:withObject:")
         def pyobjc_performSelector_onThread_withObject_(
                 self, aSelector, thread, arg):
             result = []

pyobjc-framework-Cocoa/Modules/_AppKit.m

 
 
 /* Python glue */
-#if PY_VERSION_HEX >= 0x03000000
-
-static struct PyModuleDef mod_module = {
-        PyModuleDef_HEAD_INIT,
-	"_AppKit",
-	NULL,
-	0,
-	mod_methods,
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-#define INITERROR() return NULL
-#define INITDONE() return m
-
-PyObject* PyInit__AppKit(void);
-
-PyObject*
-PyInit__AppKit(void)
-
-#else
-
-#define INITERROR() return
-#define INITDONE() return
-
-void init_AppKit(void);
-
-void
-init_AppKit(void)
-#endif
+PyObjC_MODULE_INIT(_AppKit)
 {
 	PyObject* m;
-#if PY_VERSION_HEX >= 0x03000000
-	m = PyModule_Create(&mod_module);
-#else
-	m = Py_InitModule4("_AppKit", mod_methods,
-		NULL, NULL, PYTHON_API_VERSION);
-#endif
+	m = PyObjC_MODULE_CREATE(_AppKit)
 	if (!m) { 
-		INITERROR();
+		PyObjC_INITERROR();
 	}
 
-	if (PyObjC_ImportAPI(m) == -1) INITERROR();
+	if (PyObjC_ImportAPI(m) == -1) PyObjC_INITERROR();
 
-	if (setup_carbon(m) == -1) INITERROR();
-	if (setup_nsbezierpath(m) == -1) INITERROR();
-	if (setup_nsbitmap(m) == -1) INITERROR();
-	if (setup_nsquickdrawview(m) == -1) INITERROR();
-	if (setup_nsview(m) == -1) INITERROR();
-	if (setup_nswindows(m) == -1) INITERROR();
+	if (setup_carbon(m) == -1) PyObjC_INITERROR();
+	if (setup_nsbezierpath(m) == -1) PyObjC_INITERROR();
+	if (setup_nsbitmap(m) == -1) PyObjC_INITERROR();
+	if (setup_nsquickdrawview(m) == -1) PyObjC_INITERROR();
+	if (setup_nsview(m) == -1) PyObjC_INITERROR();
+	if (setup_nswindows(m) == -1) PyObjC_INITERROR();
 
-	INITDONE();
+	PyObjC_INITDONE();
 }

pyobjc-framework-Cocoa/Modules/_AppKit_appmain.m

 		if (v == NULL) {
 			goto error_cleanup;
 		}
-		if (!PyString_Check(v)) {
+		if (PyUnicode_Check(v)) {
+			PyObject* bytes = PyUnicode_AsEncodedString(v, 
+					NULL, NULL);
+			if (!bytes) {
+				goto error_cleanup;
+			}
+			argv[i] = strdup(PyBytes_AsString(bytes));
+#if PY_MAJOR_VERSION == 2
+		} else if (PyString_Check(v)) {
+			argv[i] = strdup(PyString_AsString(v));
+#endif
+		} else {
 			PyErr_SetString(PyExc_TypeError, 
 				"NSApplicationMain: need list of strings "
 				"as argument");
 			goto error_cleanup;
 		}
 
-		argv[i] = strdup(PyString_AsString(v));
 		if (argv[i] == NULL) {
 			PyErr_SetString(PyExc_MemoryError,
 				"Out of memory");
 
 	argv[argc] = NULL;
 
-#if 0
-	/*
-	 * NSApplicationMain on MacOS X completely ignores its arguments and 
-	 * reads the argv from the shared NSProcessInfo. We *HACK* around this 
-	 * by setting a (private) instance variable of the object.
-	 *
-	 * This code is evil. Look away if you're easily scared.
-	 *
-	 * This doesn't work in 64-bit mode however. Therefore this code
-	 * is now disabled. This shouldn't make a difference when using
-	 * py2app or Xcode's PyObjC templates.
-	 */
-	{
-		typedef struct {
-			@defs(NSProcessInfo)
-		} NSProcessInfoStruct;
-	  
-		NSMutableArray *newarglist = [[NSMutableArray alloc] init];
-		NSProcessInfo *processInfo = [NSProcessInfo processInfo];
-		char **anArg = argv;
-
-		while(*anArg) {
-			[newarglist addObject: 
-				[NSString stringWithUTF8String: *anArg]];
-			anArg++;
-		}
-
-		/* Don't release the orignal arguments, because we don't know
-		 * if the list is owned by the processInfo object.
-		 *
-		 *[((NSProcessInfoStruct *)processInfo)->arguments release]; 
-		 */
-		((NSProcessInfoStruct *)processInfo)->arguments = newarglist;
-	}
-#endif
-
 	PyObjC_DURING
 		res = NSApplicationMain(argc, (const char**)argv);
 	PyObjC_HANDLER

pyobjc-framework-Cocoa/Modules/_AppKit_carbon.m

  * used in AppKit and wrapped in the python core).
  */
 
+#if PY_MAJOR_VERSION == 2
+
 #ifndef __LP64__
 
 #include "pymactoolbox.h"
 	return WinObj_New((WindowPtr)value);
 }
 
+#endif /* PY_MAJOR_VERSION == 2 */
+
 static int setup_carbon(PyObject* m __attribute__((__unused__)))
 {
+#if PY_MAJOR_VERSION == 2
 	if (PyObjCPointerWrapper_Register(@encode(WindowRef),
 	                &window2py, &py2window) < 0)
 		return -1;
+#endif
 
 	return 0;
 }

pyobjc-framework-Cocoa/Modules/_AppKit_inlines.m

 #include "Python.h"
+#include "pyobjc-api.h"
 #import <AppKit/AppKit.h>
 
-typedef void (*FUNCTION)(void);
 
-struct function_map {
-    const char* name;
-    FUNCTION    function;
-} function_map[] = {
-	{"NSEventMaskFromType", (FUNCTION)&NSEventMaskFromType },
+static PyObjC_function_map function_map[] = {
+	{"NSEventMaskFromType", (PyObjC_Function_Pointer)&NSEventMaskFromType },
     { 0, 0 }
 };
 
 
 
 /* Python glue */
-#if PY_VERSION_HEX >= 0x03000000
+#if PY_MAJOR_VERSION == 3
 
 static struct PyModuleDef mod_module = {
         PyModuleDef_HEAD_INIT,
 #endif
 {
 	PyObject* m;
-#if PY_VERSION_HEX >= 0x03000000
+#if PY_MAJOR_VERSION == 3
 	m = PyModule_Create(&mod_module);
 #else
 	m = Py_InitModule4("_inlines", mod_methods,
 	}
 
 	if (PyModule_AddObject(m, "_inline_list_", 
-		PyCObject_FromVoidPtr(function_map, NULL)) < 0) {
+		PyObjC_CreateInlineTab(function_map)) < 0) {
 		INITERROR();
 	}
 

pyobjc-framework-Cocoa/Modules/_AppKit_nsbezierpath.m

 	PyObject* result;
 	PyObject* v;
 	struct objc_super super;
-	int    idx;
+	NSInteger    idx;
 	int    pointCount;
 	NSPoint points[3];
 	NSBezierPathElement res;
 	
-	if  (!PyArg_ParseTuple(arguments, "i", &idx)) {
+	if  (!PyArg_ParseTuple(arguments, Py_ARG_NSInteger, &idx)) {
 		return NULL;
 	}
 
 	PyObjC_DURING
 		if (PyObjCIMP_Check(method)) {
-			res = ((NSBezierPathElement(*)(id,SEL,int,NSPoint*))
+			res = ((NSBezierPathElement(*)(id,SEL,NSInteger,NSPoint*))
 			   PyObjCIMP_GetIMP(method))(
 			   	PyObjCObject_GetObject(self),
 				PyObjCIMP_GetSelector(method),
 				PyObjCObject_GetObject(self));
 
 
-			res = (NSBezierPathElement)objc_msgSendSuper(&super,
+			res = ((NSBezierPathElement(*)(struct objc_super*, SEL, NSInteger, NSPoint*))objc_msgSendSuper)(&super,
 				PyObjCSelector_GetSelector(method), 
 				idx,
 				points);
 {
 	PyObject* result;
 	struct objc_super super;
-	int    idx;
+	NSInteger    idx;
 	NSPoint points[3];
 	PyObject* pointList;
 	PyObject* seq;
 	int i, len;
 	
-	if  (!PyArg_ParseTuple(arguments, "Oi", &pointList, &idx)) {
+	if  (!PyArg_ParseTuple(arguments, "O" Py_ARG_NSInteger, 
+				&pointList, &idx)) {
 		return NULL;
 	}
 
 
 	PyObjC_DURING
 		if (PyObjCIMP_Check(method)) {
-			((void(*)(id,SEL,NSPoint*,int))
+			((void(*)(id,SEL,NSPoint*,NSInteger))
 			   PyObjCIMP_GetIMP(method))(
 			   	PyObjCObject_GetObject(self),
 				PyObjCIMP_GetSelector(method),
 				PyObjCObject_GetObject(self));
 
 
-			(void)objc_msgSendSuper(&super,
+			((void(*)(struct objc_super*, SEL, NSPoint*, NSInteger))objc_msgSendSuper)(&super,
 				PyObjCSelector_GetSelector(method),
 				points,
 				idx);
 {
 	id self = *(id*)args[0];
 	//SEL _meth = *(SEL*)args[1];
-	int idx = *(int*)args[2];
+	NSInteger idx = *(NSInteger*)args[2];
 	NSPoint* points = *(NSPoint**)args[3];
 
 	PyObject* result;

pyobjc-framework-Cocoa/Modules/_AppKit_nsbitmap.m

 	PyObject* result;
 	struct objc_super super;
 	NSTIFFCompression* list;
-	int numTypes;
+	NSInteger numTypes;
 
 	if  (!PyArg_ParseTuple(arguments, "OO", &a1, &a2)) {
 		return NULL;
 			PyObjCSelector_GetClass(method),
 			PyObjCClass_GetClass(self));
 
-		(void)objc_msgSendSuper(&super,
+		((void(*)(struct objc_super*, SEL, NSTIFFCompression**, NSInteger*))objc_msgSendSuper)(&super,
 				PyObjCSelector_GetSelector(method),
 				&list, &numTypes);
 	PyObjC_HANDLER
 	struct objc_super super;
 
 	// check for five well defined read buffers in data planes argument
-	if (!PyArg_ParseTuple(arguments, "(z#z#z#z#z#)iiiibbsii",
+	if (!PyArg_ParseTuple(arguments, "("Py_ARG_BYTES"#"Py_ARG_BYTES"#"Py_ARG_BYTES"#"Py_ARG_BYTES"#"Py_ARG_BYTES"#)iiiibbsii",
 		&dataPlanes[0], &garbage,
 		&dataPlanes[1], &garbage,
 		&dataPlanes[2], &garbage,
 			PyObjCSelector_GetClass(method),
 			PyObjCObject_GetObject(self));
     
-		(void)objc_msgSendSuper(&super, 
+		((void(*)(struct objc_super*, SEL, unsigned char***))objc_msgSendSuper)(&super, 
 			PyObjCSelector_GetSelector(method),
-			&dataPlanes);
+			(unsigned char***)&dataPlanes);
 
 		bytesPerPlane = [
 			(NSBitmapImageRep*)PyObjCObject_GetObject(self) 
 	if (result != NULL) {
 		for(i=0; i<5; i++) {
 			if (dataPlanes[i]) {
+#if PY_VERSION_HEX <= 0x02069900
 				PyObject* buffer = PyBuffer_FromReadWriteMemory(dataPlanes[i], bytesPerPlane);
+#else
+				Py_buffer info;
+				if (PyBuffer_FillInfo(&info, NULL, dataPlanes[i], bytesPerPlane, 1, PyBUF_FULL) < 0) {
+					return NULL;
+				}
+				PyObject* buffer = PyMemoryView_FromBuffer(&info);
+#endif
+
 				if ( (!buffer) || PyErr_Occurred()) {
 					Py_DECREF(result);
 					result = NULL;
 		return NULL;
 	}
 
+#if  PY_VERSION_HEX <= 0x02069900
 	result = PyBuffer_FromReadWriteMemory(bitmapData, bytesPerPlane);
-	if (PyErr_Occurred()) {
+#else
+	Py_buffer info;
+	if (PyBuffer_FillInfo(&info, self, bitmapData, bytesPerPlane, 0, PyBUF_FULL) < 0) {
+		return NULL;
+	}
+	result = PyMemoryView_FromBuffer(&info);
+
+#endif
+	if (result == NULL) {
 		if (result) {
 			Py_DECREF(result);
 		}

pyobjc-framework-Cocoa/Modules/_AppKit_nsquickdrawview.m

 
-#ifndef __LP64__
+#if !defined(__LP64__) && PY_MAJOR_VERSION == 2
 	/* Quickdraw only exists in 32-bit mode. We do define a dummy 
 	 * init function to avoid breaking the Python module.
 	 */
 			PyObjCObject_GetObject(self));
 
 
-		port = objc_msgSendSuper(&super,
+		port = ((void*(*)(struct objc_super*, SEL))objc_msgSendSuper)(&super,
 				PyObjCSelector_GetSelector(method));
 
 	PyObjC_HANDLER
 
 static int setup_nsquickdrawview(PyObject* m __attribute__((__unused__)))
 {
-#ifndef __LP64__
+#if !defined(__LP64__) && PY_MAJOR_VERSION == 2
 	Class classNSQuickDrawView = objc_lookUpClass("NSQuickDrawView");
 	if (classNSQuickDrawView == NULL) {
 		return 0;

pyobjc-framework-Cocoa/Modules/_AppKit_nswindow.m

-#ifndef __LP64__
+#if PY_MAJOR_VERSION == 2
+
+#ifdef __LP64__
 
 #include "pymactoolbox.h"
 
 			PyObjCObject_GetObject(self));
 
 
-		windowRef = objc_msgSendSuper(&super,
+		windowRef = ((void*(*)(struct objc_super*, SEL))objc_msgSendSuper)(&super,
 				PyObjCSelector_GetSelector(method));
 
 	PyObjC_HANDLER
 			PyObjCSelector_GetClass(method),
 			PyObjCObject_GetObject(self));
 
-		objc_result = objc_msgSendSuper(&super,
+		objc_result = ((id(*)(struct objc_super*, SEL, void*))objc_msgSendSuper)(&super,
 				PyObjCSelector_GetSelector(method), windowRef);
 
 	PyObjC_HANDLER
 	PyObjCErr_ToObjCWithGILState(&state);
 }
 
-
+#endif /* PY_MAJOR_VERSION == 2 */
 
 static int setup_nswindows(PyObject* m __attribute__((__unused__)))
 {
+
+#if PY_MAJOR_VERSION == 2
 	Class classNSWindow = objc_lookUpClass("NSWindow");
 	if (classNSWindow == NULL) {
 		return 0;
 
 		return -1;
 	}
+#endif
 
 	return 0;
 }

pyobjc-framework-Cocoa/Modules/_CoreFoundation.m

 
 
 /* Python glue */
-#if PY_VERSION_HEX >= 0x03000000
 
-static struct PyModuleDef mod_module = {
-        PyModuleDef_HEAD_INIT,
-	"_CoreFoundation",
-	NULL,
-	0,
-	mod_methods,
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-#define INITERROR() return NULL
-#define INITDONE() return m
-
-PyObject* PyInit__CoreFoundation(void);
-
-PyObject*
-PyInit__CoreFoundation(void)
-
-#else
-
-#define INITERROR() return
-#define INITDONE() return
-
-void init_CoreFoundation(void);
-
-void
-init_CoreFoundation(void)
-#endif
+PyObjC_MODULE_INIT(_CoreFoundation)
 {
 	PyObject* m;
-#if PY_VERSION_HEX >= 0x03000000
-	m = PyModule_Create(&mod_module);
-#else
-	m = Py_InitModule4("_CoreFoundation", mod_methods,
-		NULL, NULL, PYTHON_API_VERSION);
-#endif
+	m = PyObjC_MODULE_CREATE(_CoreFoundation)
 	if (!m) { 
-		INITERROR();
+		PyObjC_INITERROR();
 	}
 
-	if (PyObjC_ImportAPI(m) == -1) INITERROR();
+	if (PyObjC_ImportAPI(m) == -1) PyObjC_INITERROR();
 
-	INITDONE();
+	PyObjC_INITDONE();
 }

pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFBitVector.m

 	}
 	if (py_bytes != Py_None) {
 		PyErr_Format(PyExc_ValueError, "argument 3: expecting None, got instance of %s",
-			py_bytes->ob_type->tp_name);
+			Py_TYPE(py_bytes)->tp_name);
 		return NULL;
 	}
 
-	PyObject* buffer = PyString_FromStringAndSize(NULL, (range.length+7)/8);
+	PyObject* buffer = PyBytes_FromStringAndSize(NULL, (range.length+7)/8);
 	if (buffer == NULL) {
 		return NULL;
 	}
-	memset(PyString_AsString(buffer), 0, (range.length+7)/8);
+	memset(PyBytes_AsString(buffer), 0, (range.length+7)/8);
 
-	CFBitVectorGetBits(vector, range, (unsigned char*)PyString_AsString(buffer));
+	CFBitVectorGetBits(vector, range, (unsigned char*)PyBytes_AsString(buffer));
 	return buffer;
 }
 

pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFFileDescriptor.m

 	PyObject* args)
 {
 	PyObject* py_f;
-	PyObject* py_context = NULL;
+	PyObject* py_context;
 	CFFileDescriptorRef f;
 	CFFileDescriptorContext context;
 
-	if (!PyArg_ParseTuple(args, "O|O", &py_f, &py_context)) {
+	if (!PyArg_ParseTuple(args, "OO", &py_f, &py_context)) {
 		return NULL;
 	}
 
-	if (py_context != NULL &&  py_context != Py_None) {
+	if (py_context != Py_None) {
 		PyErr_SetString(PyExc_ValueError, "invalid context");
 		return NULL;
 	}

pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFMachPort.m

 	PyGILState_STATE state = PyGILState_Ensure();
 
 	PyObject* py_f = PyObjC_ObjCToPython(@encode(CFMachPortRef), &f);
-	PyObject* py_msg = PyString_FromStringAndSize(msg, size);
+	PyObject* py_msg = PyBytes_FromStringAndSize(msg, size);
 	PyObject* py_size = PyLong_FromLongLong(size);
 
 	PyObject* result = PyObject_CallFunction(
 	PyObject* py_allocator;
 	PyObject* callout;
 	PyObject* info;
-	PyObject* py_shouldFree = Py_None;
+	PyObject* py_shouldFree;
 	CFAllocatorRef allocator;
 	Boolean shouldFree;
 
-	if (!PyArg_ParseTuple(args, "OOO|O", &py_allocator, &callout, &info, &py_shouldFree)) {
+	if (!PyArg_ParseTuple(args, "OOOO", &py_allocator, &callout, &info, &py_shouldFree)) {
 		return NULL;
 	}
 
 		return NULL;
 	}
 
-	PyObject* result =  Py_BuildValue("OO",
+	PyObject* result =  Py_BuildValue("NN",
 			PyObjC_ObjCToPython(@encode(CFMachPortRef), &rv),
 			PyBool_FromLong(shouldFree));
 
 	PyObject* py_port;
 	PyObject* callout;
 	PyObject* info;
-	PyObject* py_shouldFree = Py_None;
+	PyObject* py_shouldFree;
 	CFAllocatorRef allocator;
 	mach_port_t port;
 	Boolean shouldFree;
 
-	if (!PyArg_ParseTuple(args, "OOOO|O", &py_allocator, &py_port, &callout, &info, &py_shouldFree)) {
+	if (!PyArg_ParseTuple(args, "OOOOO", &py_allocator, &py_port, &callout, &info, &py_shouldFree)) {
 		return NULL;
 	}
 
 		return NULL;
 	}
 
-	PyObject* result =  Py_BuildValue("OO",
+	PyObject* result =  Py_BuildValue("NN",
 			PyObjC_ObjCToPython(@encode(CFMachPortRef), &rv),
 			PyBool_FromLong(shouldFree));
 
 	PyObject* args)
 {
 	PyObject* py_f;
-	PyObject* py_context = NULL;
+	PyObject* py_context;
 	CFMachPortRef f;
 	CFMachPortContext context;
 
-	if (!PyArg_ParseTuple(args, "O|O", &py_f, &py_context)) {
+	if (!PyArg_ParseTuple(args, "OO", &py_f, &py_context)) {
 		return NULL;
 	}
 

pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFMessagePort.m

 	PyObject* py_name;
 	PyObject* callout;
 	PyObject* info;
-	PyObject* py_shouldFree = Py_None;
+	PyObject* py_shouldFree;
 	CFAllocatorRef allocator;
 	CFStringRef name;
 	Boolean shouldFree;
 
-	if (!PyArg_ParseTuple(args, "OOOO|O", &py_allocator, &py_name, &callout, &info, &py_shouldFree)) {
+	if (!PyArg_ParseTuple(args, "OOOOO", &py_allocator, &py_name, &callout, &info, &py_shouldFree)) {
 		return NULL;
 	}
 
 		return NULL;
 	}
 
-	PyObject* result =  Py_BuildValue("OO",
+	PyObject* result =  Py_BuildValue("NN",
 			PyObjC_ObjCToPython(@encode(CFMachPortRef), &rv),
 			PyBool_FromLong(shouldFree));
 
 	PyObject* args)
 {
 	PyObject* py_f;
-	PyObject* py_context = NULL;
+	PyObject* py_context;
 	CFMessagePortRef f;
 	CFMessagePortContext context;
 
-	if (!PyArg_ParseTuple(args, "O|O", &py_f, &py_context)) {
+	if (!PyArg_ParseTuple(args, "OO", &py_f, &py_context)) {
 		return NULL;
 	}
 

pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFRunLoopObserver.m

 	PyObject* args)
 {
 	PyObject* py_f;
-	PyObject* py_context = NULL;
+	PyObject* py_context;
 	CFRunLoopObserverRef f;
 	CFRunLoopObserverContext context;
 
-	if (!PyArg_ParseTuple(args, "O|O", &py_f, &py_context)) {
+	if (!PyArg_ParseTuple(args, "OO", &py_f, &py_context)) {
 		return NULL;
 	}
 

pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFRunLoopSource.m

 	}
 
 	PyObject* v = PyTuple_GetItem(py_context, 0);
-	if (!PyInt_Check(v) || PyInt_AsLong(v) != 0) {
+	NSInteger i;
+
+	if (PyObjC_PythonToObjC(@encode(NSInteger), v, &i) == -1) {
+		PyErr_SetString(PyExc_ValueError, "Version field must be 0");
+		return NULL;
+	} else if (i != 0) {
 		PyErr_SetString(PyExc_ValueError, "Version field must be 0");
 		return NULL;
 	}
 	PyObject* args)
 {
 	PyObject* py_f;
-	PyObject* py_context = NULL;
+	PyObject* py_context;
 	CFRunLoopSourceRef f;
 	CFRunLoopSourceContext context;
 
-	if (!PyArg_ParseTuple(args, "O|O", &py_f, &py_context)) {
+	if (!PyArg_ParseTuple(args, "OO", &py_f, &py_context)) {
 		return NULL;
 	}
 

pyobjc-framework-Cocoa/Modules/_CoreFoundation_CFTree.m

 	PyObject* args)
 {
 	PyObject* py_tree;
-	PyObject* py_context = NULL;
+	PyObject* py_context;
 	CFTreeRef tree;
 	CFTreeContext context;
 
-	if (!PyArg_ParseTuple(args, "O|O", &py_tree, &py_context)) {
+	if (!PyArg_ParseTuple(args, "OO", &py_tree, &py_context)) {
 		return NULL;
 	}
 
 	PyObject* args)
 {
 	PyObject* py_tree;
-	PyObject* py_context = NULL;
+	PyObject* py_context;
 	CFTreeRef tree;
 	CFTreeContext context;
 	NSObject* info;
 
-	if (!PyArg_ParseTuple(args, "O|O", &py_tree, &py_context)) {
+	if (!PyArg_ParseTuple(args, "OO", &py_tree, &py_context)) {
 		return NULL;
 	}
 
 	PyObject* args)
 {
 	PyObject* py_allocator;
-	PyObject* py_context = NULL;
+	PyObject* py_context;
 	CFTreeRef tree;
 	CFTreeContext context;
 	CFAllocatorRef allocator;
 	NSObject* info;
 
-	if (!PyArg_ParseTuple(args, "O|O", &py_allocator, &py_context)) {
+	if (!PyArg_ParseTuple(args, "OO", &py_allocator, &py_context)) {
 		return NULL;
 	}
 	
 		return NULL;
 	}
 
+	children = NULL;
 	PyObjC_DURING
 		count = CFTreeGetChildCount(tree);
 		children = malloc(count * sizeof(CFTreeRef));
 		}
 
 	PyObjC_HANDLER
-		count = -1; children = NULL;
+		count = -1; 
+		if (children != NULL) {
+			free(children);
+			children = NULL;
+		}
 		PyObjCErr_FromObjC(localException);
 
 	PyObjC_ENDHANDLER
 
 	if (children == NULL) {
-		PyErr_NoMemory();
+		if (!PyErr_Occurred()) {
+			PyErr_NoMemory();
+		}
 		return NULL;
 	}
 		

pyobjc-framework-Cocoa/Modules/_CoreFoundation_inlines.m

 #define CF_INLINE
 #include "Python.h"
+#include "pyobjc-api.h"
 #import <CoreFoundation/CoreFoundation.h>
 
 
-typedef void (*FUNCTION)(void);
-
-struct function_map {
-    const char* name;
-    FUNCTION    function;
-} function_map[] = {
-	{"CFByteOrderGetCurrent", (FUNCTION)&CFByteOrderGetCurrent },
-	{"CFConvertDoubleHostToSwapped", (FUNCTION)&CFConvertDoubleHostToSwapped },
-	{"CFConvertDoubleSwappedToHost", (FUNCTION)&CFConvertDoubleSwappedToHost },
-	{"CFConvertFloat32HostToSwapped", (FUNCTION)&CFConvertFloat32HostToSwapped },
-	{"CFConvertFloat32SwappedToHost", (FUNCTION)&CFConvertFloat32SwappedToHost },
-	{"CFConvertFloat64HostToSwapped", (FUNCTION)&CFConvertFloat64HostToSwapped },
-	{"CFConvertFloat64SwappedToHost", (FUNCTION)&CFConvertFloat64SwappedToHost },
-	{"CFConvertFloatHostToSwapped", (FUNCTION)&CFConvertFloatHostToSwapped },
-	{"CFConvertFloatSwappedToHost", (FUNCTION)&CFConvertFloatSwappedToHost },
-	{"CFRangeMake", (FUNCTION)&CFRangeMake },
-	{"CFStringGetCharacterFromInlineBuffer", (FUNCTION)&CFStringGetCharacterFromInlineBuffer },
-	{"CFStringInitInlineBuffer", (FUNCTION)&CFStringInitInlineBuffer },
-	{"CFSwapInt16", (FUNCTION)&CFSwapInt16 },
-	{"CFSwapInt16BigToHost", (FUNCTION)&CFSwapInt16BigToHost },
-	{"CFSwapInt16HostToBig", (FUNCTION)&CFSwapInt16HostToBig },
-	{"CFSwapInt16HostToLittle", (FUNCTION)&CFSwapInt16HostToLittle },
-	{"CFSwapInt16LittleToHost", (FUNCTION)&CFSwapInt16LittleToHost },
-	{"CFSwapInt32", (FUNCTION)&CFSwapInt32 },
-	{"CFSwapInt32BigToHost", (FUNCTION)&CFSwapInt32BigToHost },
-	{"CFSwapInt32HostToBig", (FUNCTION)&CFSwapInt32HostToBig },
-	{"CFSwapInt32HostToLittle", (FUNCTION)&CFSwapInt32HostToLittle },
-	{"CFSwapInt32LittleToHost", (FUNCTION)&CFSwapInt32LittleToHost },
-	{"CFSwapInt64", (FUNCTION)&CFSwapInt64 },
-	{"CFSwapInt64BigToHost", (FUNCTION)&CFSwapInt64BigToHost },
-	{"CFSwapInt64HostToBig", (FUNCTION)&CFSwapInt64HostToBig },
-	{"CFSwapInt64HostToLittle", (FUNCTION)&CFSwapInt64HostToLittle },
-	{"CFSwapInt64LittleToHost", (FUNCTION)&CFSwapInt64LittleToHost },
-	{"CFUserNotificationCheckBoxChecked", (FUNCTION)&CFUserNotificationCheckBoxChecked },
-	{"CFUserNotificationPopUpSelection", (FUNCTION)&CFUserNotificationPopUpSelection },
-	{"CFUserNotificationSecureTextField", (FUNCTION)&CFUserNotificationSecureTextField },
+static PyObjC_function_map function_map[] = {
+	{"CFByteOrderGetCurrent", (PyObjC_Function_Pointer)&CFByteOrderGetCurrent },
+	{"CFConvertDoubleHostToSwapped", (PyObjC_Function_Pointer)&CFConvertDoubleHostToSwapped },
+	{"CFConvertDoubleSwappedToHost", (PyObjC_Function_Pointer)&CFConvertDoubleSwappedToHost },
+	{"CFConvertFloat32HostToSwapped", (PyObjC_Function_Pointer)&CFConvertFloat32HostToSwapped },
+	{"CFConvertFloat32SwappedToHost", (PyObjC_Function_Pointer)&CFConvertFloat32SwappedToHost },
+	{"CFConvertFloat64HostToSwapped", (PyObjC_Function_Pointer)&CFConvertFloat64HostToSwapped },
+	{"CFConvertFloat64SwappedToHost", (PyObjC_Function_Pointer)&CFConvertFloat64SwappedToHost },
+	{"CFConvertFloatHostToSwapped", (PyObjC_Function_Pointer)&CFConvertFloatHostToSwapped },
+	{"CFConvertFloatSwappedToHost", (PyObjC_Function_Pointer)&CFConvertFloatSwappedToHost },
+	{"CFRangeMake", (PyObjC_Function_Pointer)&CFRangeMake },
+	{"CFStringGetCharacterFromInlineBuffer", (PyObjC_Function_Pointer)&CFStringGetCharacterFromInlineBuffer },
+	{"CFStringInitInlineBuffer", (PyObjC_Function_Pointer)&CFStringInitInlineBuffer },
+	{"CFSwapInt16", (PyObjC_Function_Pointer)&CFSwapInt16 },
+	{"CFSwapInt16BigToHost", (PyObjC_Function_Pointer)&CFSwapInt16BigToHost },
+	{"CFSwapInt16HostToBig", (PyObjC_Function_Pointer)&CFSwapInt16HostToBig },
+	{"CFSwapInt16HostToLittle", (PyObjC_Function_Pointer)&CFSwapInt16HostToLittle },
+	{"CFSwapInt16LittleToHost", (PyObjC_Function_Pointer)&CFSwapInt16LittleToHost },
+	{"CFSwapInt32", (PyObjC_Function_Pointer)&CFSwapInt32 },
+	{"CFSwapInt32BigToHost", (PyObjC_Function_Pointer)&CFSwapInt32BigToHost },
+	{"CFSwapInt32HostToBig", (PyObjC_Function_Pointer)&CFSwapInt32HostToBig },
+	{"CFSwapInt32HostToLittle", (PyObjC_Function_Pointer)&CFSwapInt32HostToLittle },
+	{"CFSwapInt32LittleToHost", (PyObjC_Function_Pointer)&CFSwapInt32LittleToHost },
+	{"CFSwapInt64", (PyObjC_Function_Pointer)&CFSwapInt64 },
+	{"CFSwapInt64BigToHost", (PyObjC_Function_Pointer)&CFSwapInt64BigToHost },
+	{"CFSwapInt64HostToBig", (PyObjC_Function_Pointer)&CFSwapInt64HostToBig },
+	{"CFSwapInt64HostToLittle", (PyObjC_Function_Pointer)&CFSwapInt64HostToLittle },
+	{"CFSwapInt64LittleToHost", (PyObjC_Function_Pointer)&CFSwapInt64LittleToHost },
+	{"CFUserNotificationCheckBoxChecked", (PyObjC_Function_Pointer)&CFUserNotificationCheckBoxChecked },
+	{"CFUserNotificationPopUpSelection", (PyObjC_Function_Pointer)&CFUserNotificationPopUpSelection },
+	{"CFUserNotificationSecureTextField", (PyObjC_Function_Pointer)&CFUserNotificationSecureTextField },
 #if  PyObjC_BUILD_RELEASE >= 1006
-	{"CFStringIsSurrogateHighCharacter", (FUNCTION)&CFStringIsSurrogateHighCharacter },
-	{"CFStringIsSurrogateLowCharacter", (FUNCTION)&CFStringIsSurrogateLowCharacter },
-	{"CFStringGetLongCharacterForSurrogatePair", (FUNCTION)&CFStringGetLongCharacterForSurrogatePair },
-	{"CFStringGetSurrogatePairForLongCharacter", (FUNCTION)&CFStringGetSurrogatePairForLongCharacter },
+	{"CFStringIsSurrogateHighCharacter", (PyObjC_Function_Pointer)&CFStringIsSurrogateHighCharacter },
+	{"CFStringIsSurrogateLowCharacter", (PyObjC_Function_Pointer)&CFStringIsSurrogateLowCharacter },
+	{"CFStringGetLongCharacterForSurrogatePair", (PyObjC_Function_Pointer)&CFStringGetLongCharacterForSurrogatePair },
+	{"CFStringGetSurrogatePairForLongCharacter", (PyObjC_Function_Pointer)&CFStringGetSurrogatePairForLongCharacter },
 #endif
     { 0, 0 }
 };
 
 
 /* Python glue */
-#if PY_VERSION_HEX >= 0x03000000
+#if PY_MAJOR_VERSION == 3
 
 static struct PyModuleDef mod_module = {
         PyModuleDef_HEAD_INIT,
 #endif
 {
 	PyObject* m;
-#if PY_VERSION_HEX >= 0x03000000
+#if PY_MAJOR_VERSION == 3
 	m = PyModule_Create(&mod_module);
 #else
 	m = Py_InitModule4("_inlines", mod_methods,
 
 
 	if (PyModule_AddObject(m, "_inline_list_", 
-		PyCObject_FromVoidPtr(function_map, NULL)) < 0) {
+		PyObjC_CreateInlineTab(function_map)) < 0) {
 		INITERROR();
 	}
 

pyobjc-framework-Cocoa/Modules/_Foundation.m

 
 
 /* Python glue */
-#if PY_VERSION_HEX >= 0x03000000
-
-static struct PyModuleDef mod_module = {
-        PyModuleDef_HEAD_INIT,
-	"_Foundation",
-	NULL,
-	0,
-	mod_methods,
-	NULL,
-	NULL,
-	NULL,
-	NULL
-};
-
-#define INITERROR() return NULL
-#define INITDONE() return m
-
-PyObject* PyInit__Foundation(void);
-
-PyObject*
-PyInit__Foundation(void)
-
-#else
-
-#define INITERROR() return
-#define INITDONE() return
-
-void init_Foundation(void);
-
-void
-init_Foundation(void)
-#endif
+PyObjC_MODULE_INIT(_Foundation)
 {
 	PyObject* m;
-#if PY_VERSION_HEX >= 0x03000000
-	m = PyModule_Create(&mod_module);
-#else
-	m = Py_InitModule4("_Foundation", mod_methods,
-		NULL, NULL, PYTHON_API_VERSION);
-#endif
+	m = PyObjC_MODULE_CREATE(_Foundation)
 	if (!m) { 
-		INITERROR();
+		PyObjC_INITERROR();
 	}
 
-	if (PyObjC_ImportAPI(m) == -1) INITERROR();
+	if (PyObjC_ImportAPI(m) == -1) PyObjC_INITERROR();
 
-	if (setup_nsdecimal(m) == -1) INITERROR();
-	if (setup_nsinvocation(m) == -1) INITERROR();
-	if (setup_nsdata(m) == -1) INITERROR();
-	if (setup_nsnetservice(m) == -1) INITERROR();
-	if (setup_nscoder(m) == -1) INITERROR();
-	if (setup_nssstring(m) == -1) INITERROR();
+	if (setup_nsdecimal(m) == -1) PyObjC_INITERROR();
+	if (setup_nsinvocation(m) == -1) PyObjC_INITERROR();
+	if (setup_nsdata(m) == -1) PyObjC_INITERROR();
+	if (setup_nsnetservice(m) == -1) PyObjC_INITERROR();
+	if (setup_nscoder(m) == -1) PyObjC_INITERROR();
+	if (setup_nssstring(m) == -1) PyObjC_INITERROR();
 
-	INITDONE();
+	PyObjC_INITDONE();
 }

pyobjc-framework-Cocoa/Modules/_Foundation_NSDecimal.m

 	decimal_add,			/* nb_add */
 	decimal_subtract,		/* nb_subtract */
 	decimal_multiply,		/* nb_multiply */
+#if PY_MAJOR_VERSION == 2
 	decimal_divide,			/* nb_divide */
+#endif
 	NULL,				/* nb_remainder */
 	NULL,				/* nb_divmod */
 	decimal_power,			/* nb_power */
 	NULL,				/* nb_and */
 	NULL,				/* nb_xor */
 	NULL,				/* nb_or */
+
+#if PY_MAJOR_VERSION == 2
 	decimal_coerce,			/* nb_coerce */
+#endif
 	NULL,				/* nb_int */
 	NULL,				/* nb_long */
 	NULL,				/* nb_float */
+#if PY_MAJOR_VERSION == 2
 	NULL,				/* nb_oct */
 	NULL,				/* nb_hex */
+#endif
 	decimal_inplace_add,		/* nb_inplace_add */
 	decimal_inplace_subtract,	/* nb_inplace_subtract */
 	decimal_inplace_multiply,	/* nb_inplace_multiply */
+#if PY_MAJOR_VERSION == 2
 	decimal_inplace_divide,		/* nb_inplace_divide */
+#endif
 	NULL,				/* nb_inplace_remainder */
 	NULL,				/* nb_inplace_power */
 	NULL,				/* nb_inplace_lshift */
 	NULL,				/* nb_inplace_xor */
 	NULL,				/* nb_inplace_or */
 	NULL,				/* nb_floor_divide */
-	NULL,				/* nb_true_divide */
+	decimal_divide,			/* nb_true_divide */
 	NULL,				/* nb_inplace_floor_divide */
-	NULL				/* nb_inplace_true_divide */
+	decimal_inplace_divide		/* nb_inplace_true_divide */
 #if (PY_VERSION_HEX >= 0x02050000)
 	,NULL				/* nb_index */
 #endif
 }
 
 static PyTypeObject Decimal_Type = {
-	PyObject_HEAD_INIT(NULL)
-	0,					/* ob_size */
+	PyVarObject_HEAD_INIT(&PyType_Type, 0)
 	"Foundation.NSDecimal",			/* tp_name */
 	sizeof (DecimalObject),			/* tp_basicsize */
 	0,					/* tp_itemsize */
 	decimal_getattro,			/* tp_getattro */
 	PyObject_GenericSetAttr,		/* tp_setattro */
 	0,					/* tp_as_buffer */
-	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_RICHCOMPARE | Py_TPFLAGS_HAVE_INPLACEOPS, /* tp_flags */
+	Py_TPFLAGS_DEFAULT 
+#if PY_MAJOR_VERSION == 2
+		| Py_TPFLAGS_HAVE_RICHCOMPARE | Py_TPFLAGS_HAVE_INPLACEOPS
+#endif
+		, /* tp_flags */
 	"NSDecimal wrapper",			/* tp_doc */
 	0,					/* tp_traverse */
 	0,					/* tp_clear */
 			    "NSDecimal(stringValue) or NSDecimal(mantissa, exponent, isNegative)");
 			return -1;
 		}
-		if (PyInt_Check(pyValue)) {
-			long lng = PyInt_AsLong(pyValue);
-			if (lng < 0) {
-				mantissa = -lng;
-				exponent = 0;
-				negative = YES;
-			} else{
-				mantissa = lng;
-				exponent = 0;
-				negative = NO;
-			}
-				
-			DecimalFromComponents(&Decimal_Value(self),
-				mantissa, exponent, negative);
-			return 0;
-		} else if (PyLong_Check(pyValue)) {
+		if (PyLong_Check(pyValue)) {
 			mantissa = PyLong_AsUnsignedLongLong(pyValue);
 			if (PyErr_Occurred()) {
 				long long lng;
 					mantissa, 0, NO);
 				return 0;
 			}
+#if PY_MAJOR_VERSION == 2
+		} else if (PyInt_Check(pyValue)) {
+			long lng = PyInt_AsLong(pyValue);
+			if (lng < 0) {
+				mantissa = -lng;
+				exponent = 0;
+				negative = YES;
+			} else{
+				mantissa = lng;
+				exponent = 0;
+				negative = NO;
+			}
+				
+			DecimalFromComponents(&Decimal_Value(self),
+				mantissa, exponent, negative);
+			return 0;
+#endif
 		} else if (PyFloat_Check(pyValue)) {
 			/* Explicit conversion from float to NSDecimal
 			 * first convert the float to a string using repr, that
 			}
 			PyErr_Format(PyExc_TypeError, "cannot convert object of %s to NSDecimal", pyValue->ob_type->tp_name);
 			return -1;
-		} else if (!PyString_Check(pyValue) && !PyUnicode_Check(pyValue)) {
+		} else if (
+#if PY_MAJOR_VERSION == 2
+				!PyString_Check(pyValue) && 
+#endif
+				!PyUnicode_Check(pyValue)) {
 			PyErr_Format(PyExc_TypeError, "cannot convert object of %s to NSDecimal", pyValue->ob_type->tp_name);
 			return -1;
 		}
 
 	if (!Decimal_Check(*l)) {
 		/* The test is needed to avoid silently converting strings */
-		if (PyString_Check(*l) || PyUnicode_Check(*l) || PyFloat_Check(*l)) goto error;
+		if (PyBytes_Check(*l) || PyUnicode_Check(*l) || PyFloat_Check(*l)) goto error;
 		
 		left = (PyObject*)PyObject_New(DecimalObject, &Decimal_Type);
 		if (left == NULL) goto error;
 
 	if (!Decimal_Check(*r)) {
 		/* The test is needed to avoid silently converting strings */
-		if (PyString_Check(*r) || PyUnicode_Check(*r) || PyFloat_Check(*r)) goto error;
+		if (PyBytes_Check(*r) || PyUnicode_Check(*r) || PyFloat_Check(*r)) goto error;
 		
 		right = (PyObject*)PyObject_New(DecimalObject, &Decimal_Type);
 		if (right == NULL) goto error;

pyobjc-framework-Cocoa/Modules/_Foundation_NSInvocation.m

 	NSMethodSignature* signature;
 	const char* tp;
 	PyObject* py_value;
-	Py_ssize_t index;
+	NSUInteger index;
 	void* buf;
 	Py_ssize_t sz;
 
-	if  (!PyArg_ParseTuple(arguments, "On", &py_value, &index)) {
+	if  (!PyArg_ParseTuple(arguments, "O" Py_ARG_NSUInteger, &py_value, &index)) {
 		return NULL;
 	}
 
 				PyObjCSelector_GetClass(method),
 				PyObjCObject_GetObject(self));
 
-			(void)objc_msgSendSuper(&super,
+			((void(*)(struct objc_super*, SEL, void*, NSUInteger))objc_msgSendSuper)(&super,
 					PyObjCSelector_GetSelector(method),
 					buf, index);
 		}
 				PyObjCSelector_GetClass(method),
 				PyObjCObject_GetObject(self));
 
-			(void)objc_msgSendSuper(&super,
+			((void(*)(struct objc_super*, SEL, void*))objc_msgSendSuper)(&super,
 					PyObjCSelector_GetSelector(method),
 					buf);
 		}
 	NSMethodSignature* signature;
 	const char* tp;
 	PyObject* py_value;
-	Py_ssize_t index;
+	NSUInteger index;
 	void* buf;
 	Py_ssize_t sz;
 
-	if  (!PyArg_ParseTuple(arguments, "On", &py_value, &index)) {
+	if  (!PyArg_ParseTuple(arguments, "O" Py_ARG_NSUInteger, &py_value, &index)) {
 		return NULL;
 	}
 
 				PyObjCSelector_GetClass(method),
 				PyObjCObject_GetObject(self));
 
-			(void)objc_msgSendSuper(&super,
+			((void(*)(struct objc_super*,SEL,void*,NSUInteger))objc_msgSendSuper)(&super,
 					PyObjCSelector_GetSelector(method),
 					buf, index);
 		}
 				PyObjCSelector_GetClass(method),
 				PyObjCObject_GetObject(self));
 
-			(void)objc_msgSendSuper(&super,
+			((void(*)(struct objc_super*, SEL, void*))objc_msgSendSuper)(&super,
 					PyObjCSelector_GetSelector(method),
 					buf);
 		}

pyobjc-framework-Cocoa/Modules/_Foundation_data.m

 			PyObjCSelector_GetClass(method),
 			PyObjCObject_GetObject(self));
 
-		bytes = objc_msgSendSuper(&super, 
+		bytes = ((void*(*)(struct objc_super*, SEL))objc_msgSendSuper)(&super, 
 				PyObjCSelector_GetSelector(method));
-		bytes_len = (NSUInteger) objc_msgSendSuper(&super, @selector(length));
+		bytes_len = ((NSUInteger(*)(struct objc_super*, SEL))objc_msgSendSuper)(&super, @selector(length));
 
 
 	PyObjC_HANDLER
 
 	if (bytes == NULL && PyErr_Occurred()) return NULL;
 
-	result = PyBuffer_FromMemory((void*)bytes, bytes_len);
+#if PY_VERSION_HEX <= 0x02069900
+	result = PyBuffer_FromMemory((char*)bytes, bytes_len);
+#else
+	/* 2.7 or later: use a memory view */
+	Py_buffer info;
+	if (PyBuffer_FillInfo(&info, self, (void*)bytes, bytes_len, 1, PyBUF_FULL_RO) < 0) {
+		return NULL;
+	}
+	result = PyMemoryView_FromBuffer(&info);
+#endif
 
 	return result;
 }
 		return;
 	}
 
+#if PY_MAJOR_VERSION == 2
 	if (PyBuffer_Check(result)) {
 		/* XXX: Is this correct?? */
 		const void *p;
 		*pretval =  (void *)p;
 		PyGILState_Release(state);
 		return;
-	} else if (PyString_Check(result)) {
+	} else 
+#endif
+	if (PyBytes_Check(result)) {
 		/* XXX: Is this correct */
 		void* p;
 
-		p = PyString_AsString(result);
+		p = PyBytes_AsString(result);
 		*pretval = (void*)p;
 		PyGILState_Release(state);
 		return;
 			PyObjCSelector_GetClass(method),
 			PyObjCObject_GetObject(self));
 
-		bytes = objc_msgSendSuper(&super, 
+		bytes = ((void*(*)(struct objc_super*, SEL))objc_msgSendSuper)(&super, 
 				PyObjCSelector_GetSelector(method));
-		bytes_len = (NSUInteger) objc_msgSendSuper(&super, @selector(length));
+		bytes_len = ((NSUInteger(*)(struct objc_super*,SEL))objc_msgSendSuper)(&super, @selector(length));
 
 	PyObjC_HANDLER
 		PyObjCErr_FromObjC(localException);
 
 	if (bytes == NULL && PyErr_Occurred()) return NULL;
 
+#if PY_VERSION_HEX <= 0x02069900
 	result = PyBuffer_FromReadWriteMemory((void*)bytes, bytes_len);
 
+#else
+	/* 2.7 or later: use a memory view */
+	Py_buffer info;
+	if (PyBuffer_FillInfo(&info, self, bytes, bytes_len, 0, PyBUF_FULL) < 0) {
+		return NULL;
+	}
+	result = PyMemoryView_FromBuffer(&info);
+#endif
+
 	return result;
 }
 
 		return;
 	}
 
-	if (PyBuffer_Check(result)) {
-		/* XXX: Is this correct? */
-		void *p;
-		Py_ssize_t len;
-		if (PyObject_AsWriteBuffer(result, &p, &len) == -1) goto error;
-		Py_DECREF(result);
-		*pretval = (void *)p;
-		PyGILState_Release(state);
-		return;
-	}
-
-	PyErr_SetString(PyExc_ValueError, "No idea what to do with result.");
-	PyObjCErr_ToObjCWithGILState(&state);
-	*pretval = NULL;
+	void *p;
+	Py_ssize_t len;
+	if (PyObject_AsWriteBuffer(result, &p, &len) == -1) goto error;
+	Py_DECREF(result);
+	*pretval = (void *)p;
+	PyGILState_Release(state);
 	return;
 
 error:

pyobjc-framework-Cocoa/Modules/_Foundation_inlines.m

 #define NS_INLINE
 #include "Python.h"
+#include "pyobjc-api.h"
 #import <Foundation/Foundation.h>
 
-typedef void (*FUNCTION)(void);
-
-struct function_map {
-    const char* name;
-    FUNCTION    function;
-} function_map[] = {
-	{"NSConvertHostDoubleToSwapped", (FUNCTION)&NSConvertHostDoubleToSwapped },
-	{"NSConvertHostFloatToSwapped", (FUNCTION)&NSConvertHostFloatToSwapped },
-	{"NSConvertSwappedDoubleToHost", (FUNCTION)&NSConvertSwappedDoubleToHost },
-	{"NSConvertSwappedFloatToHost", (FUNCTION)&NSConvertSwappedFloatToHost },
-	{"NSDecimalIsNotANumber", (FUNCTION)&NSDecimalIsNotANumber },
-	{"NSEqualRanges", (FUNCTION)&NSEqualRanges },
-	{"NSHeight", (FUNCTION)&NSHeight },
-	{"NSHostByteOrder", (FUNCTION)&NSHostByteOrder },
-	{"NSLocationInRange", (FUNCTION)&NSLocationInRange },
-	{"NSMakePoint", (FUNCTION)&NSMakePoint },
-	{"NSMakeRange", (FUNCTION)&NSMakeRange },
-	{"NSMakeRect", (FUNCTION)&NSMakeRect },
-	{"NSMakeSize", (FUNCTION)&NSMakeSize },
-	{"NSMaxRange", (FUNCTION)&NSMaxRange },
-	{"NSMaxX", (FUNCTION)&NSMaxX },
-	{"NSMaxY", (FUNCTION)&NSMaxY },
-	{"NSMidX", (FUNCTION)&NSMidX },
-	{"NSMidY", (FUNCTION)&NSMidY },
-	{"NSMinX", (FUNCTION)&NSMinX },
-	{"NSMinY", (FUNCTION)&NSMinY },
-	{"NSSwapBigDoubleToHost", (FUNCTION)&NSSwapBigDoubleToHost },
-	{"NSSwapBigDoubleToHost", (FUNCTION)&NSSwapBigDoubleToHost },
-	{"NSSwapBigFloatToHost", (FUNCTION)&NSSwapBigFloatToHost },
-	{"NSSwapBigFloatToHost", (FUNCTION)&NSSwapBigFloatToHost },
-	{"NSSwapBigIntToHost", (FUNCTION)&NSSwapBigIntToHost },
-	{"NSSwapBigLongLongToHost", (FUNCTION)&NSSwapBigLongLongToHost },
-	{"NSSwapBigLongToHost", (FUNCTION)&NSSwapBigLongToHost },
-	{"NSSwapBigShortToHost", (FUNCTION)&NSSwapBigShortToHost },
-	{"NSSwapDouble", (FUNCTION)&NSSwapDouble },
-	{"NSSwapFloat", (FUNCTION)&NSSwapFloat },
-	{"NSSwapHostDoubleToBig", (FUNCTION)&NSSwapHostDoubleToBig },
-	{"NSSwapHostDoubleToBig", (FUNCTION)&NSSwapHostDoubleToBig },
-	{"NSSwapHostDoubleToLittle", (FUNCTION)&NSSwapHostDoubleToLittle },
-	{"NSSwapHostDoubleToLittle", (FUNCTION)&NSSwapHostDoubleToLittle },
-	{"NSSwapHostFloatToBig", (FUNCTION)&NSSwapHostFloatToBig },
-	{"NSSwapHostFloatToBig", (FUNCTION)&NSSwapHostFloatToBig },
-	{"NSSwapHostFloatToLittle", (FUNCTION)&NSSwapHostFloatToLittle },
-	{"NSSwapHostFloatToLittle", (FUNCTION)&NSSwapHostFloatToLittle },
-	{"NSSwapHostIntToBig", (FUNCTION)&NSSwapHostIntToBig },
-	{"NSSwapHostIntToLittle", (FUNCTION)&NSSwapHostIntToLittle },
-	{"NSSwapHostLongLongToBig", (FUNCTION)&NSSwapHostLongLongToBig },
-	{"NSSwapHostLongLongToLittle", (FUNCTION)&NSSwapHostLongLongToLittle },
-	{"NSSwapHostLongToBig", (FUNCTION)&NSSwapHostLongToBig },
-	{"NSSwapHostLongToLittle", (FUNCTION)&NSSwapHostLongToLittle },
-	{"NSSwapHostShortToBig", (FUNCTION)&NSSwapHostShortToBig },
-	{"NSSwapHostShortToLittle", (FUNCTION)&NSSwapHostShortToLittle },
-	{"NSSwapInt", (FUNCTION)&NSSwapInt },
-	{"NSSwapLittleDoubleToHost", (FUNCTION)&NSSwapLittleDoubleToHost },
-	{"NSSwapLittleDoubleToHost", (FUNCTION)&NSSwapLittleDoubleToHost },
-	{"NSSwapLittleFloatToHost", (FUNCTION)&NSSwapLittleFloatToHost },
-	{"NSSwapLittleFloatToHost", (FUNCTION)&NSSwapLittleFloatToHost },
-	{"NSSwapLittleIntToHost", (FUNCTION)&NSSwapLittleIntToHost },
-	{"NSSwapLittleLongLongToHost", (FUNCTION)&NSSwapLittleLongLongToHost },
-	{"NSSwapLittleLongToHost", (FUNCTION)&NSSwapLittleLongToHost },
-	{"NSSwapLittleShortToHost", (FUNCTION)&NSSwapLittleShortToHost },
-	{"NSSwapLong", (FUNCTION)&NSSwapLong },
-	{"NSSwapLongLong", (FUNCTION)&NSSwapLongLong },
-	{"NSSwapShort", (FUNCTION)&NSSwapShort },
-	{"NSWidth", (FUNCTION)&NSWidth },
+static PyObjC_function_map function_map[] = {
+	{"NSConvertHostDoubleToSwapped", (PyObjC_Function_Pointer)&NSConvertHostDoubleToSwapped },
+	{"NSConvertHostFloatToSwapped", (PyObjC_Function_Pointer)&NSConvertHostFloatToSwapped },
+	{"NSConvertSwappedDoubleToHost", (PyObjC_Function_Pointer)&NSConvertSwappedDoubleToHost },
+	{"NSConvertSwappedFloatToHost", (PyObjC_Function_Pointer)&NSConvertSwappedFloatToHost },
+	{"NSDecimalIsNotANumber", (PyObjC_Function_Pointer)&NSDecimalIsNotANumber },
+	{"NSEqualRanges", (PyObjC_Function_Pointer)&NSEqualRanges },
+	{"NSHeight", (PyObjC_Function_Pointer)&NSHeight },
+	{"NSHostByteOrder", (PyObjC_Function_Pointer)&NSHostByteOrder },
+	{"NSLocationInRange", (PyObjC_Function_Pointer)&NSLocationInRange },
+	{"NSMakePoint", (PyObjC_Function_Pointer)&NSMakePoint },
+	{"NSMakeRange", (PyObjC_Function_Pointer)&NSMakeRange },
+	{"NSMakeRect", (PyObjC_Function_Pointer)&NSMakeRect },
+	{"NSMakeSize", (PyObjC_Function_Pointer)&NSMakeSize },
+	{"NSMaxRange", (PyObjC_Function_Pointer)&NSMaxRange },
+	{"NSMaxX", (PyObjC_Function_Pointer)&NSMaxX },
+	{"NSMaxY", (PyObjC_Function_Pointer)&NSMaxY },
+	{"NSMidX", (PyObjC_Function_Pointer)&NSMidX },
+	{"NSMidY", (PyObjC_Function_Pointer)&NSMidY },
+	{"NSMinX", (PyObjC_Function_Pointer)&NSMinX },
+	{"NSMinY", (PyObjC_Function_Pointer)&NSMinY },
+	{"NSSwapBigDoubleToHost", (PyObjC_Function_Pointer)&NSSwapBigDoubleToHost },
+	{"NSSwapBigDoubleToHost", (PyObjC_Function_Pointer)&NSSwapBigDoubleToHost },
+	{"NSSwapBigFloatToHost", (PyObjC_Function_Pointer)&NSSwapBigFloatToHost },
+	{"NSSwapBigFloatToHost", (PyObjC_Function_Pointer)&NSSwapBigFloatToHost },
+	{"NSSwapBigIntToHost", (PyObjC_Function_Pointer)&NSSwapBigIntToHost },
+	{"NSSwapBigLongLongToHost", (PyObjC_Function_Pointer)&NSSwapBigLongLongToHost },
+	{"NSSwapBigLongToHost", (PyObjC_Function_Pointer)&NSSwapBigLongToHost },
+	{"NSSwapBigShortToHost", (PyObjC_Function_Pointer)&NSSwapBigShortToHost },
+	{"NSSwapDouble", (PyObjC_Function_Pointer)&NSSwapDouble },
+	{"NSSwapFloat", (PyObjC_Function_Pointer)&NSSwapFloat },
+	{"NSSwapHostDoubleToBig", (PyObjC_Function_Pointer)&NSSwapHostDoubleToBig },
+	{"NSSwapHostDoubleToBig", (PyObjC_Function_Pointer)&NSSwapHostDoubleToBig },
+	{"NSSwapHostDoubleToLittle", (PyObjC_Function_Pointer)&NSSwapHostDoubleToLittle },
+	{"NSSwapHostDoubleToLittle", (PyObjC_Function_Pointer)&NSSwapHostDoubleToLittle },
+	{"NSSwapHostFloatToBig", (PyObjC_Function_Pointer)&NSSwapHostFloatToBig },
+	{"NSSwapHostFloatToBig", (PyObjC_Function_Pointer)&NSSwapHostFloatToBig },
+	{"NSSwapHostFloatToLittle", (PyObjC_Function_Pointer)&NSSwapHostFloatToLittle },
+	{"NSSwapHostFloatToLittle", (PyObjC_Function_Pointer)&NSSwapHostFloatToLittle },
+	{"NSSwapHostIntToBig", (PyObjC_Function_Pointer)&NSSwapHostIntToBig },
+	{"NSSwapHostIntToLittle", (PyObjC_Function_Pointer)&NSSwapHostIntToLittle },
+	{"NSSwapHostLongLongToBig", (PyObjC_Function_Pointer)&NSSwapHostLongLongToBig },
+	{"NSSwapHostLongLongToLittle", (PyObjC_Function_Pointer)&NSSwapHostLongLongToLittle },
+	{"NSSwapHostLongToBig", (PyObjC_Function_Pointer)&NSSwapHostLongToBig },
+	{"NSSwapHostLongToLittle", (PyObjC_Function_Pointer)&NSSwapHostLongToLittle },
+	{"NSSwapHostShortToBig", (PyObjC_Function_Pointer)&NSSwapHostShortToBig },
+	{"NSSwapHostShortToLittle", (PyObjC_Function_Pointer)&NSSwapHostShortToLittle },
+	{"NSSwapInt", (PyObjC_Function_Pointer)&NSSwapInt },
+	{"NSSwapLittleDoubleToHost", (PyObjC_Function_Pointer)&NSSwapLittleDoubleToHost },
+	{"NSSwapLittleDoubleToHost", (PyObjC_Function_Pointer)&NSSwapLittleDoubleToHost },
+	{"NSSwapLittleFloatToHost", (PyObjC_Function_Pointer)&NSSwapLittleFloatToHost },
+	{"NSSwapLittleFloatToHost", (PyObjC_Function_Pointer)&NSSwapLittleFloatToHost },
+	{"NSSwapLittleIntToHost", (PyObjC_Function_Pointer)&NSSwapLittleIntToHost },
+	{"NSSwapLittleLongLongToHost", (PyObjC_Function_Pointer)&NSSwapLittleLongLongToHost },
+	{"NSSwapLittleLongToHost", (PyObjC_Function_Pointer)&NSSwapLittleLongToHost },
+	{"NSSwapLittleShortToHost", (PyObjC_Function_Pointer)&NSSwapLittleShortToHost },
+	{"NSSwapLong", (PyObjC_Function_Pointer)&NSSwapLong },
+	{"NSSwapLongLong", (PyObjC_Function_Pointer)&NSSwapLongLong },
+	{"NSSwapShort", (PyObjC_Function_Pointer)&NSSwapShort },
+	{"NSWidth", (PyObjC_Function_Pointer)&NSWidth },
 
 #ifndef NO_OBJC2_RUNTIME
-	{"NSMakeCollectable", (FUNCTION)&NSMakeCollectable },
-	{"NSPointFromCGPoint", (FUNCTION)&NSPointFromCGPoint },
-	{"NSPointToCGPoint", (FUNCTION)&NSPointToCGPoint },
-	{"NSRectFromCGRect", (FUNCTION)&NSRectFromCGRect },
-	{"NSRectToCGRect", (FUNCTION)&NSRectToCGRect },
-	{"NSSizeFromCGSize", (FUNCTION)&NSSizeFromCGSize },
-	{"NSSizeToCGSize", (FUNCTION)&NSSizeToCGSize },
+	{"NSMakeCollectable", (PyObjC_Function_Pointer)&NSMakeCollectable },
+	{"NSPointFromCGPoint", (PyObjC_Function_Pointer)&NSPointFromCGPoint },
+	{"NSPointToCGPoint", (PyObjC_Function_Pointer)&NSPointToCGPoint },
+	{"NSRectFromCGRect", (PyObjC_Function_Pointer)&NSRectFromCGRect },
+	{"NSRectToCGRect", (PyObjC_Function_Pointer)&NSRectToCGRect },
+	{"NSSizeFromCGSize", (PyObjC_Function_Pointer)&NSSizeFromCGSize },
+	{"NSSizeToCGSize", (PyObjC_Function_Pointer)&NSSizeToCGSize },
 #endif
 	
     { 0, 0 }
 
 
 	if (PyModule_AddObject(m, "_inline_list_", 
-		PyCObject_FromVoidPtr(function_map, NULL)) < 0)
+		PyObjC_CreateInlineTab(function_map)) < 0)
 
 		INITERROR();
 

pyobjc-framework-Cocoa/Modules/_Foundation_netservice.m

 		Py_DECREF(v);
 		return NULL;
 	}
-	return PyString_FromString(buf);
+	return PyBytes_FromString(buf);
 }
 
 static PyObject *
 	case AF_UNIX:
 	{
 		struct sockaddr_un *a = (struct sockaddr_un *) addr;
-		return PyString_FromString(a->sun_path);
+		return PyBytes_FromString(a->sun_path);
 	}
 
 	case AF_INET6:
 			PyObjCObject_GetObject(self));
 
 			
-		res = objc_msgSendSuper(&super, @selector(addresses));
+		res = ((id(*)(struct objc_super*, SEL))objc_msgSendSuper)(&super, @selector(addresses));
 	PyObjC_HANDLER
 		PyObjCErr_FromObjC(localException);
 		res = nil;

pyobjc-framework-Cocoa/Modules/_Foundation_nscoder.m

 call_NSCoder_encodeValueOfObjCType_at_(
 	PyObject* method, PyObject* self, PyObject* arguments)
 {
-	char* signature;