Ronald Oussoren avatar Ronald Oussoren committed acdd105

GNUstep: AppKit and AddressBook now "work" on GNUstep (barely tested, the
regression-tests work fine but I haven't tried GUI programming on GNUstep yet)

Also some minor cleanup

Comments (0)

Files changed (48)

Lib/AppKit/_AppKitSignatures.py

 setSignatureForSelector("NSFont", "positionOfGlyph:struckOverRect:metricsExist:", "{_NSPoint=ff}@:I{_NSRect={_NSPoint=ff}{_NSSize=ff}}o^c")
 setSignatureForSelector("NSFont", "positionOfGlyph:withRelation:toBaseGlyph:totalAdvancement:metricsExist:", "{_NSPoint=ff}@:IiIo^{_NSSize=ff}o^c")
 setSignatureForSelector("NSWorkspace", "getFileSystemInfoForPath:isRemovable:isWritable:isUnmountable:description:type:", "c28@4:8@12o^c16o^c20o^c24o^@28o^@32")
-setSignatureForSelector("NSWorkspace", "getInfoForFile:application:type:", "c16@4:8@12o^@16o^@20")
+setSignatureForSelector("NSWorkspace", "getInfoForFile:application:type:", "c@:@o^@o^@")
 setSignatureForSelector("NSWorkspace", "performFileOperation:source:destination:files:tag:", "c@:@@@@o^i")
 setSignatureForSelector("NSDocument", "_changeAlertDidEnd:returnCode:contextInfo:", "v16@4:8@12i16i20")
 setSignatureForSelector("NSDocument", "_compatibility_canCloseDocumentWithDelegate:shouldCloseSelector:contextInfo:", "v16@4:8@12:16i20")

Lib/AppKit/test/test_nsfont.py

 
     def testConstants(self):
         self.assert_(hasattr(AppKit, 'NSFontIdentityMatrix'))
-        self.assertEquals(AppKit.NSFontIdentityMatrix, None)
+
+        if AppKit.NSFontIdentityMatrix is None:
+            # MacOSX
+            return
+
+        self.assertEquals(AppKit.NSFontIdentityMatrix, (1.0, 0.0, 0.0, 1.0, 0.0, 0.0))
 
     def testMatrixMethods(self):
         o = AppKit.NSFont.boldSystemFontOfSize_(10);

Lib/Foundation/test/test_nsset.py

 from Foundation import *
 
 class TestNSSetInteraction(unittest.TestCase):
-    def testRepeatedAllocInit( self ):
+    def __testRepeatedAllocInit( self ):
         for i in range(1,1000):
             a = NSSet.alloc().init()
 
-    def testContains( self ):
+    def __testContains( self ):
         x = NSSet.setWithArray_( ["foo", "bar", "baz"] )
 
         self.assert_( "foo" in x )
         self.assert_( "notfoo" not in x )
 
-    def testIteration( self ):
+    def __testIteration( self ):
         x = NSSet.setWithArray_( ["foo", "bar", "baz"] )
 
         for i in x:

Lib/objc/_convenience.py

 
     Matching entries from both mappings are added to the 'type_dict'.
     """
-    PYOBJC_NEW_INITIALIZER_PATTERN = not (hasattr(selector, 'returnsSelf') and hasattr(selector, 'isInitializer'))
     for k, sel in type_dict.items():
         if not isinstance(sel, selector):
             continue
 
-        if not PYOBJC_NEW_INITIALIZER_PATTERN and sel.selector.startswith('init') and not sel.isClassMethod:
-            # Instance methods that start with 'init*' are constructors. These
-            # return 'self'. If they don't they reallocated the previous 
-            # value, don't use that afterwards.
-            sel.returnsSelf = 1
-            sel.isInitializer = 1
-        elif sel.selector == "alloc" or sel.selector == "allocWithZone:":
+        if sel.selector == "alloc" or sel.selector == "allocWithZone:":
             sel.isAlloc = 1
 
         if sel.selector in ( 'copy', 'copyWithZone:', 
                     t = type_dict[name]
                     v = selector(value, selector=t.selector, 
                         signature=t.signature, isClassMethod=t.isClassMethod)
-                    if not PYOBJC_NEW_INITIALIZER_PATTERN:
-                        v.isInitializer = t.isInitializer
-                        v.returnsSelf = t.returnsSelf
                     v.isAlloc = t.isAlloc
 
-                    #if t.selector.startswith('init'):
-                    #    v.isInitializer = 1
-                    #    v.returnsSelf = 1
-                    #elif sel.selector == "alloc" \
-                    #        or sel.selector == "allocWithZone:":
-                    #    sel.isAlloc = 1
-
                     type_dict[name] = v
                 else:
                     type_dict[name] = value

Lib/objc/test/test_imp.py

 import objc
 import unittest
 
-PYOBJC_NEW_INITIALIZER_PATTERN = not (hasattr(objc.selector, 'returnsSelf') and hasattr(objc.selector, 'isInitializer'))
 
 class TestBasicIMP (unittest.TestCase):
     # Test the basic functionality of IMP's. Imp's are basically unbound
         self.assert_(m.isClassMethod)
         self.assertEquals(m.isAlloc, cls.alloc.isAlloc)
         self.assertEquals(m.doesDonateReference, cls.alloc.doesDonateReference)
-        if not PYOBJC_NEW_INITIALIZER_PATTERN:
-            self.assertEquals(m.returnsSelf, cls.alloc.returnsSelf)
         self.assertEquals(m.selector, 'alloc')
 
         o = m(cls).init()
         self.assert_(not m.isClassMethod)
         self.assertEquals(m.isAlloc, cls.init.isAlloc)
         self.assertEquals(m.doesDonateReference, cls.init.doesDonateReference)
-        if not PYOBJC_NEW_INITIALIZER_PATTERN:
-            self.assertEquals(m.returnsSelf, cls.init.returnsSelf)
         self.assertEquals(m.selector, 'init')
 
         o = m(cls.alloc())
         self.assert_(not m.isClassMethod)
         self.assertEquals(m.isAlloc, cls.init.isAlloc)
         self.assertEquals(m.doesDonateReference, cls.init.doesDonateReference)
-        if not PYOBJC_NEW_INITIALIZER_PATTERN:
-            self.assertEquals(m.returnsSelf, cls.init.returnsSelf)
         self.assertEquals(m.selector, 'init')
 
         o = m(cls.alloc())

Lib/objc/test/test_regr.py

         self.assertRaises(TypeError, fm.stringWithFileSystemRepresentation_length_, "/var")
         self.assertEquals(u"/var", fm.stringWithFileSystemRepresentation_length_("/var/boo", 4))
 
-    def testUninitWarning(self):
-        """
-        Check that calling methods on unitialized objects raises an error
-        """
-        import warnings
-        import Foundation
-
-        # Not applicable to PYOBJC_NEW_INITIALIZER_PATTERN
-        PYOBJC_NEW_INITIALIZER_PATTERN = not (hasattr(objc.selector, 'returnsSelf') and hasattr(objc.selector, 'isInitializer'))
-        if PYOBJC_NEW_INITIALIZER_PATTERN:
-            return
-
-        warnings.filterwarnings('ignore',
-            category=objc.UninitializedDeallocWarning)
-        o = Foundation.NSObject.alloc() # Not yet initialized
-        warnings.filterwarnings('error', category=RuntimeWarning)
-        try:
-            self.assertRaises(RuntimeWarning, o.description)
-            del o
-        finally:
-            del warnings.filters[0:2]
-
     def testMemoryInit(self):
         """
         Regression test for bug #814683, that didn't initialize the memory

Lib/objc/test/testbndl.m

 		return NULL;
 	}
 
-	buf = alloca(PyObjCRT_SizeOfType(signature));
+	buf = PyMem_Malloc(PyObjCRT_SizeOfType(signature));
 	if (buf == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 
 	r = PyObjC_PythonToObjC(signature, o, buf);
 	if (r < 0) {
+		PyMem_Free(buf);
 		return NULL;
 	}
 
 	o = PyObjC_ObjCToPython(signature, buf);
+	PyMem_Free(buf);
 	return o;
 
 }

Modules/AddressBook/_AddressBook.m

 #include <Python.h>
 
 #import <AddressBook/AddressBook.h>
-#import <CoreFoundation/CoreFoundation.h>
 
 #include "pyobjc-api.h"
 #include "wrapper-const-table.h"
 
 
 PyDoc_STRVAR(addressbook_doc,
-"Cocoa._AddressBook defines constants, types and global functions used by "
-"Cocoa.AddressBook."
+  "_AddressBook defines constants, types and global functions used by "
+  "AddressBook."
 );
 
 
 		return;
 	}
 
+#ifdef MACOSX 
 	bundle = CFBundleCreate(NULL,
 		(CFURLRef)[NSURL fileURLWithPath:@"/System/Library/Frameworks/AddressBook.framework"]);
+#else
+	bundle = nil;
+#endif
 
 
 	if (register_ints(d, enum_table) < 0) return;

Modules/AppKit/_AppKit.m

 #import <AppKit/AppKit.h>
 #import <AppKit/NSGraphics.h>
 
+
 #ifdef MACOSX
+#import <CoreFoundation/CoreFoundation.h>
 
 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
 #import <AppKit/NSNib.h>
 			anArg++;
 		}
 
-		// Don't release the orignal arguments, unknown whether this 
-		// list is owned by the object.
-		//[((NSProcessInfoStruct *)processInfo)->arguments release]; 
+		/* 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 /* MACOSX */
 
 error_cleanup:
 	if (argv != NULL) {
-		for (i = 0; i < argc; i++) {\
+		for (i = 0; i < argc; i++) {
 			if (argv[i] != NULL) {
 				free(argv[i]);
 				argv[i] = NULL;
 		return NULL;
 	}
 
-	list = malloc(sizeof(int)*size);
+	list = PyMem_Malloc(sizeof(int)*size);
 	if (list == NULL) {
 		PyErr_NoMemory();
 		return 0;
 	PyObjC_ENDHANDLER
 
 	if (PyErr_Occurred()) {
-		free(list);
+		PyMem_Free(list);
 		return NULL;
 	}
 
 	result = PyObjC_CArrayToPython(@encode(int), list, size);
-	free(list);
+	PyMem_Free(list);
 	return result;
 }
 
 		return NULL;
 	}
 
-	list = malloc(sizeof(int)*size);
+	list = PyMem_Malloc(sizeof(int)*size);
 	if (list == NULL) {
 		PyErr_NoMemory();
 		return 0;
 	PyObjC_ENDHANDLER
 
 	if (PyErr_Occurred()) {
-		free(list);
+		PyMem_Free(list);
 		return NULL;
 	}
 
 	result = PyObjC_CArrayToPython(@encode(int), list, size);
-	free(list);
+	PyMem_Free(list);
 	return result;
 }
 
 	int bps;
 	int bpp;
 	PyObject* pyPlanar;
-	BOOL planarVal; // planar is a global symbol??
+	BOOL planarVal; 
 	BOOL exactMatch;
 	NSWindowDepth bestDepth;
 	PyObject* result;
 	{
 	        "NSRectFillList",
 		(PyCFunction)objc_NSRectFillList,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"void NSRectFillList(const NSRect *rects, int count);"
 	},
 	{
 	        "NSBestDepth",
 		(PyCFunction)objc_NSBestDepth,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"NSWindowDepth NSBestDepth(NSString *colorSpace, int bps, int bpp, BOOL planar, BOOL *exactMatch);"
 	},
 	{
 	        "NSAvailableWindowDepths",
 		(PyCFunction)objc_NSAvailableWindowDepths,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"int* NSAvailableWindowDepths(void);"
 	},
 	{
 	        "NSRectClipList",
 		(PyCFunction)objc_NSRectClipList,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"void NSRectClipList(const NSRect *rects, int count);"
 	},
 	{
 	        "NSDrawTiledRects",
 		(PyCFunction)objc_NSDrawTiledRects,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"void NSDrawTiledRects(NSRect boundsRect, NSRect clipRect, const NSRectEdge* sides, const float* grays, int count);"
 	},
 	{
 	        "NSDrawColorTiledRects",
 		(PyCFunction)objc_NSDrawColorTiledRects,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"void NSDrawColorTiledRects(NSRect boundsRect, NSRect clipRect, const NSRectEdge* sides, const NSColor** colors, int count);"
 	},
 	{
 	        "NSRectFillListWithColors",
 		(PyCFunction)objc_NSRectFillListWithColors,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"void NSRectFillListWithColors(const NSRect *rects, NSColor **colors, int count);"
 	},
 	{
 	        "NSRectFillListWithColorsUsingOperation",
 		(PyCFunction)objc_NSRectFillListWithColorsUsingOperation,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"void NSRectFillListWithColorsUsingOperation(const NSRect *rects, NSColor **colors, int count, NSCompositingOperation op)"
 	},
 	{
 	        "NSRectFillListWithGrays",
 		(PyCFunction)objc_NSRectFillListWithGrays,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"void NSRectFillListWithGrays(const NSRect *rects, const float *grays, int count);"
 	},
 	{
 	        "NSRectFillListUsingOperation",
 		(PyCFunction)objc_NSRectFillListUsingOperation,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"void NSRectFillListUsingOperation(const NSRect *rects, int count, NSCompositingOperation op);"
 	},
 	{
 		"NSGetWindowServerMemory",
 		(PyCFunction)objc_NSGetWindowServerMemory,
-		METH_VARARGS,
+		METH_VARARGS|METH_KEYWORDS,
 		"int NSGetWindowServerMemory(int context, int *virtualMemory, int *windowBackingMemory, NSString **windowDumpString);"
 	},
 
 			Py_DECREF(v);
 			return -1;
 		}
+		PyTuple_SET_ITEM(v, i, t);
 	}
 	
 	if (PyDict_SetItemString(d, (char*)name, v) == -1) {
 	 * seems to have the value of the first entry in the matrix,
 	 * instead of being the address of the array...
 	 */
-	fontMatrix(d, "NSFontIdentityMatrix", &NSFontIdentityMatrix);
+	fontMatrix(d, "NSFontIdentityMatrix", (float*)&NSFontIdentityMatrix);
 
 #else
 
 	PyDict_SetItemString(d, "NSAffineTransformStruct", v);
 	Py_DECREF(v);
 
-	/* TODO: NSTypesetterGlyphInfo */
-
 	/* register other method mappings */
 	if (_pyobjc_install_NSApplication() < 0) return;
 	if (_pyobjc_install_NSATSTypesetter() < 0) return;

Modules/AppKit/_AppKitMapping_NSBezierPath.m

 	PyObject* self, PyObject* arguments)
 {
 	PyObject* result;
+	PyObject* v;
 	struct objc_super super;
 	int    idx;
 	int    pointCount;
 	NSPoint points[3];
 	NSBezierPathElement res;
-	int i;
 	
 	if  (!PyArg_ParseTuple(arguments, "i", &idx)) {
 		return NULL;
 	result = PyTuple_New(2);
 	if (result == NULL) return NULL;
 
-	PyTuple_SET_ITEM(result, 0,
-		PyObjC_ObjCToPython(@encode(NSBezierPathElement), &res));
-	if (PyTuple_GET_ITEM(result, 0) == NULL) {
+	v = PyObjC_ObjCToPython(@encode(NSBezierPathElement), &res);
+	if (v == NULL) {
 		Py_DECREF(result);
 		return NULL;
 	}
 
-	PyTuple_SET_ITEM(result, 1, PyTuple_New(pointCount));
-	if (PyTuple_GET_ITEM(result, 1) == NULL) {
+	PyTuple_SET_ITEM(result, 0, v);
+
+	v = PyObjC_CArrayToPython(@encode(NSPoint), points, pointCount);
+	if (v == NULL) {
 		Py_DECREF(result);
 		return NULL;
 	}
-
-	for (i = 0; i < pointCount; i++) {
-		PyTuple_SET_ITEM(PyTuple_GET_ITEM(result, 1), i,
-			PyObjC_ObjCToPython(@encode(NSPoint), &points[i]));
-		if (PyErr_Occurred()) {
-			Py_DECREF(result);
-			return NULL;
-		}
-	}
+	PyTuple_SET_ITEM(result, 1, v);
 
 	return result;
 }
 		return NULL;
 	}
 
-	pattern = malloc(count * sizeof(float));
+	pattern = PyMem_Malloc(count * sizeof(float));
 	if (pattern == NULL) {
 		Py_DECREF(seq);
 		PyErr_NoMemory();
 		result = NULL;
 	PyObjC_ENDHANDLER
 
+	PyMem_Free(pattern);
+
 	if (PyErr_Occurred()) return NULL;
 
 	result = Py_None;
 	struct objc_super super;
 	PyObject* v;
 	float* volatile pattern;
-	int countIn, countOut, i;
+	int countIn, countOut;
 	float phase;
 
 	
 	}
 
 	if (countIn) {
-		pattern = malloc(countIn * sizeof(float));
+		pattern = PyMem_Malloc(countIn * sizeof(float));
 		if (pattern == NULL) {
 			PyErr_NoMemory();
 			return NULL;
 	PyObjC_ENDHANDLER
 
 	if (PyErr_Occurred()) {
+		if (pattern) {
+			PyMem_Free(pattern);
+		}
 		return NULL;
 	}
 
 		PyTuple_SET_ITEM(result, 0, Py_None);
 		Py_INCREF(Py_None);
 	} else {
-		v = PyTuple_New(countOut);
+		v = PyObjC_CArrayToPython(@encode(float), pattern, countOut);
 		if (v == NULL) {
 			Py_DECREF(result);
 			return NULL;
 		}
 
 		PyTuple_SET_ITEM(result, 0, v);
-
-		for (i = 0; i < countOut; i++) {
-			PyObject* p = PyFloat_FromDouble(pattern[i]);
-			if (p == NULL) {
-				Py_DECREF(result);
-				return NULL;
-			}
-			PyTuple_SET_ITEM(v, i, p);
-		}
 	}
 
 	v = PyInt_FromLong(countOut);
 	PyObject* result;
 	PyObject* arglist = NULL;
 	PyObject* v;
-	int i;
 
 	PyGILState_STATE state = PyObjCGILState_Ensure();
 
 	if (v == NULL) goto error;
 	PyTuple_SET_ITEM(arglist, 0, v);
 
-	v = PyTuple_New(count);
+	v = PyObjC_CArrayToPython(@encode(float), pattern, count);
 	if (v == NULL) goto error;
 	PyTuple_SET_ITEM(arglist, 1, v);
 
-	for (i = 0; i < count; i++) {
-		PyTuple_SET_ITEM(v, i, 
-			PyObjC_ObjCToPython(@encode(float), pattern+i));
-		if (PyTuple_GET_ITEM(v, i) == NULL) goto error;
-	}
-
 	v = PyInt_FromLong(count);
 	if (v == NULL) goto error;
 	PyTuple_SET_ITEM(arglist, 2, v);

Modules/AppKit/_AppKitMapping_NSBitmap.m

 		return NULL;
 	}
 
+	memset(dataPlanes, 0, sizeof(dataPlanes));
+
 	PyObjC_DURING
 
 		PyObjC_InitSuper(&super,
     
 		bitmapData = (unsigned char *) objc_msgSendSuper(&super, 
 				PyObjCSelector_GetSelector(method));
-
 			
 		bytesPerPlane = [
 			(NSBitmapImageRep*)PyObjCObject_GetObject(self) 

Modules/AppKit/_AppKitMapping_NSBitmapImageRep.m

 		PyTuple_SET_ITEM(result, 0, Py_None);
 		Py_INCREF(Py_None);
 	} else {
-		int i;
-		PyObject* v = PyTuple_New(numTypes);
-
+		PyObject* v = PyObjC_CArrayToPython(
+				@encode(NSTIFFCompression),
+				list, numTypes);
 		if (v == NULL) {
 			Py_DECREF(result);
 			return NULL;
 		}
-
 		PyTuple_SET_ITEM(result, 0, v);
-
-		for (i = 0; i < numTypes; i++) {
-			PyObject* o = PyObjC_ObjCToPython(
-				@encode(NSTIFFCompression), 
-				list + i);
-			if (o == NULL) {
-				Py_DECREF(result);
-				return NULL;
-			}
-			PyTuple_SET_ITEM(v, i, o);
-		}
 	}
 
 	return result;

Modules/AppKit/_AppKitMapping_NSFont.m

 		return NULL;
 	}
 
-	glyphs = malloc(sizeof(NSGlyph));
+	glyphs = PyMem_Malloc(sizeof(NSGlyph));
 	if (glyphs == NULL) {
 		Py_DECREF(seq);
 		return NULL;
 	}
 
-	points = malloc(sizeof(NSPoint));
+	points = PyMem_Malloc(sizeof(NSPoint));
 	if (glyphs == NULL) {
-		free(glyphs);
+		PyMem_Free(glyphs);
 		Py_DECREF(seq);
 		return NULL;
 	}
 			PySequence_Fast_GET_ITEM(seq, i),
 			glyphs + i);
 		if (r == -1) {
-			free(glyphs);
+			PyMem_Free(glyphs);
+			PyMem_Free(points);
 			Py_DECREF(seq);
 			return NULL;
 		}
 	PyObjC_ENDHANDLER
 
 	if (len == -1 && PyErr_Occurred()) {
-		free(points);
-		free(glyphs);
+		PyMem_Free(points);
+		PyMem_Free(glyphs);
 		return NULL;
 	}
 
-	free(glyphs);
+	PyMem_Free(glyphs);
+	
+	if (len > 0) {
+		seq = PyObjC_CArrayToPython(@encode(NSPoint), points, len);
+	} else {
+		seq = PyTuple_New(0);
+	}
+	PyMem_Free(points);
 
-	seq = PyTuple_New(len > 0? len: 0);
 	if (seq == NULL) {
-		free(points);
 		return NULL;
 	}
 
-	for (i = 0; i < len; i++) {
-		PyObject* v;
-
-		v = PyObjC_ObjCToPython(@encode(NSPoint), points + i);
-		if (v == NULL) {
-			free(points);
-			return NULL;
-		}
-
-		PyTuple_SET_ITEM(seq, i, v);
-	}
-	free(points);
-
 	result = Py_BuildValue("(iO)", len, seq);
 	Py_DECREF(seq);
 
 	if (v == NULL) goto error;
 	PyTuple_SET_ITEM(arglist, 0, v);
 
-	v = PyTuple_New(numGlyphs);
+	v = PyObjC_CArrayToPython(@encode(NSGlyph), glyphs, numGlyphs);
 	if (v == NULL) goto error;
 	PyTuple_SET_ITEM(arglist, 1, v);
 
-	for (i = 0; i < numGlyphs; i++) {
-		PyObject* t;
-
-		t = PyObjC_ObjCToPython(@encode(NSGlyph), glyphs + i);
-		if (t == NULL) goto error;
-		PyTuple_SET_ITEM(v, i, t);
-	}
-
 	v = PyInt_FromLong(numGlyphs);
 	if (v == NULL) goto error;
 	PyTuple_SET_ITEM(arglist, 2, v);
 	struct objc_super super;
 	PyObject* pyFontMatrix;
 	float* matrix;
-	int i;
 
 	if (!PyArg_ParseTuple(arguments, "")) {
 		return 0;
 		return NULL;
 	}
 
-	pyFontMatrix = PyTuple_New(6);
+	pyFontMatrix = PyObjC_CArrayToPython(@encode(float), matrix, 6);
 	if (pyFontMatrix == NULL) {
 		return NULL;
 	}
-	for (i = 0; i < 6; i++) {
-		PyObject* t = PyFloat_FromDouble(matrix[i]);
-		if (t == NULL) {
-			Py_DECREF(pyFontMatrix);
-		}
-		PyTuple_SET_ITEM(pyFontMatrix, i, t);
-	}
 
 	return pyFontMatrix;
 }

Modules/AppKit/_AppKitMapping_NSGraphicsContext.m

 
 	PyObjC_DURING
 		PyObjC_InitSuper(&super,
-		    PyObjCSelector_GetClass(method),
-		    PyObjCObject_GetObject(self));
+			PyObjCSelector_GetClass(method),
+			PyObjCObject_GetObject(self));
 
-		res = (CGContextRef)objc_msgSendSuper(&super,
-		    @selector(graphicsPort));
+		res = (CGContextRef)objc_msgSendSuper(&super, 
+				@selector(graphicsPort));
 	PyObjC_HANDLER
 		PyObjCErr_FromObjC(localException);
 		res = NULL;
 
 	sprintf(ptrString, "%08x", (unsigned int)res);
 	sillySwigThing = PyString_FromFormat("_%s_CGContextRef", ptrString);
-	retVal = PyObject_CallFunctionObjArgs(pyCGContextPtr, sillySwigThing, NULL);
+	retVal = PyObject_CallFunctionObjArgs(
+			pyCGContextPtr, sillySwigThing, NULL);
 	Py_DECREF(sillySwigThing);
 	Py_DECREF(pyCGContextPtr);
 	return retVal;

Modules/AppKit/_AppKitMapping_NSMatrix.m

 	return result;
 }
 
-
-
 static int 
 _pyobjc_install_NSMatrix(void)
 {

Modules/AppKit/_AppKitMapping_NSMovie.m

 	PyObjCErr_ToObjCWithGILState(&state);
 }
 
+#endif
 
 static int 
 _pyobjc_install_NSMovie(void)
 {
+
+#ifdef MACOSX
 	if (PyObjC_RegisterMethodMapping(objc_lookUpClass("NSMovie"), 
 		@selector(QTMovie),
 		call_NSMovie_QTMovie,
 
 		return -1;
 	}
+#endif /* MACOSX */
 
 	return 0;
 }
-
-#else /* GNUSTEP */
-
-static int 
-_pyobjc_install_NSMovie(void)
-{
-	return 0;
-}
-
-#endif

Modules/AppKit/_AppKitMapping_NSOpenGLContext.m

 #include <AppKit/AppKit.h>
 #include "pyobjc-api.h"
 
-#ifdef MACOSX 
-
-/* 1. I can't manage to get a working OpenGL on my develbox
- * 2. Need to detect if OpenGL support is present
- */
-
-#include <OpenGL/gl.h>
-
-#endif
-
-
 static int 
 _pyobjc_install_NSOpenGLContext(void)
 {

Modules/AppKit/_AppKitMapping_NSOpenGLPixelFormat.m

 
 #ifdef MACOSX 
 
+/* 1. I can't manage to get a working OpenGL on my Linux develbox
+ * 2. Need to detect if OpenGL support is present
+ */
+
 #include <OpenGL/gl.h>
 
 static PyObject*

Modules/AppKit/_AppKitMapping_NSQuickDrawView.m

 	PyObjCErr_ToObjCWithGILState(&state);
 }
 
+#endif /* MACOSX */
 
 static int 
 _pyobjc_install_NSQuickDrawView(void)
 {
+
+#ifdef MACOSX 
 	Class classNSQuickDrawView = objc_lookUpClass("NSQuickDrawView");
 
 	if (PyObjC_RegisterMethodMapping(
 
 		return -1;
 	}
+#endif /* MACOSX */
 
 	return 0;
 }
-
-#else
-
-static int 
-_pyobjc_install_NSQuickDrawView(void)
-{
-	return 0;
-}
-
-#endif

Modules/AppKit/_AppKitMapping_NSView.m

 	return result;
 }
 
-
 static PyObject* 
 call_NSView_getRectsBeingDrawn_count_(
 	PyObject* method, PyObject* self, PyObject* arguments)

Modules/AppKit/_AppKitMapping_NSWindow.m

 	PyObjCErr_ToObjCWithGILState(&state);
 }
 
+#endif /* MACOSX */
+
 
 static int 
 _pyobjc_install_NSWindow(void)
 {
+
+#ifdef MACOSX 
 	Class classNSWindow = objc_lookUpClass("NSWindow");
 
 	if (PyObjC_RegisterMethodMapping(
 
 		return -1;
 	}
+#endif /* MACOSX */
 
 	return 0;
 }
-
-#else
-
-static int 
-_pyobjc_install_NSWindow(void)
-{
-	return 0;
-}
-
-#endif

Modules/CoreFoundation/machsignals.m

 		if (!callable) break;
 
 		tmp = PyObject_CallFunction(callable, "i", signum);
-		Py_DECREF(callable);
 		Py_XDECREF(tmp);
 	} while (0);
 	if (PyErr_Occurred())

Modules/Foundation/_Foundation.m

 	
 	result = PyObjC_IdToPython(res);
 
-#if defined(PYOBJC_NEW_INITIALIZER_PATTERN)
 	if (PyObjCObject_IsUninitialized(self)) {
-        if (result != self) {
-            PyObjCObject_ClearObject(self);
-        }
-	}
-#else
-	if (PyObjCSelector_IsInitializer(method)) {
 		if (result != self) {
 			PyObjCObject_ClearObject(self);
 		}
 	}
-#endif /* PYOBJC_NEW_INITIALIZER_PATTERN */
 
 	return result;
 }

Modules/Foundation/_FoundationMapping_NSCoder.m

 	if (size == -1) {
 		return NULL;
 	}
-	buf = alloca(size);
+	buf = PyMem_Malloc(size);
 	if (buf == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 
 	err = PyObjC_PythonToObjC(signature, value, buf);
 	if (err == -1) {
+		PyMem_Free(buf);
 		return NULL;
 	}
 
 		PyObjCErr_FromObjC(localException);
 	PyObjC_ENDHANDLER
 
+	PyMem_Free(buf);
+
 	if (PyErr_Occurred()) {
 		return NULL;
 	}
 	if (size == -1) {
 		return NULL;
 	}
-	buf = alloca(size * (count+1));
+	buf = PyMem_Malloc(size * (count+1));
 	if (buf == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 	}
 
 	if (!PySequence_Check(value)) {
+		PyMem_Free(buf);
 		PyErr_SetString(PyExc_TypeError, "Need sequence of objects");
 		return NULL;
 	}
 
 	value_len = PySequence_Size(value);
 	if (value_len > count) {
+		PyMem_Free(buf);
 		PyErr_SetString(PyExc_ValueError, "Inconsistent arguments");
 		return NULL;
 	}
 				PySequence_GetItem(value, i), 
 				((char*)buf) + (size * i));
 		if (err == -1) {
+			PyMem_Free(buf);
 			return NULL;
 		}
 	}
 		PyObjCErr_FromObjC(localException);
 	PyObjC_ENDHANDLER
 
+	PyMem_Free(buf);
 	if (PyErr_Occurred()) return NULL;
 
-
 	Py_INCREF(Py_None);
 	return Py_None;
 }
 	if (size == -1) {
 		return NULL;
 	}
-	buf = alloca(size);
+	buf = PyMem_Malloc(size);
 	if (buf == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 	}
 
-
 	PyObjC_DURING
 		if (PyObjCIMP_Check(method)) {
 			((void(*)(id,SEL, char*,void*))
 	PyObjC_ENDHANDLER
 
 	if (PyErr_Occurred()) {
+		PyMem_Free(buf);
 		return NULL;
 	}
 
 	value = PyObjC_ObjCToPython(signature, buf);
+	PyMem_Free(buf);
 	if (value == NULL) {
 		return NULL;
 	}
 	if (size == -1) {
 		return NULL;
 	}
-	buf = alloca(size * (count+1));
+	buf = PyMem_Malloc(size * (count+1));
 	if (buf == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 	PyObjC_ENDHANDLER
 
 	if (PyErr_Occurred()) {
+		PyMem_Free(buf);
 		return NULL;
 	}
 
 	result = PyTuple_New(count);
 	if (result == NULL) {
+		PyMem_Free(buf);
 		return NULL;
 	}
 
 				((char*)buf) + (size * i)));
 		if (PyTuple_GET_ITEM(result, i) == NULL) {
 			Py_DECREF(result);
+			PyMem_Free(buf);
 			return NULL;
 		}
 	}
 
+	PyMem_Free(buf);
 	return result;
 }
 

Modules/Foundation/_FoundationMapping_NSDictionary.m

 		return NULL;
 	}
 
-	keys = alloca(sizeof(id) * count);
+	keys = PyMem_Malloc(sizeof(id) * count);
 	if (keys == NULL) {
 		Py_DECREF(keySeq);
 		Py_DECREF(objectSeq);
 		return NULL;
 	}
 
-	objects = alloca(sizeof(id) * count);
+	objects = PyMem_Malloc(sizeof(id) * count);
 	if (objects == NULL) {
+		PyMem_Free(keys);
 		Py_DECREF(keySeq);
 		Py_DECREF(objectSeq);
 		PyErr_NoMemory();
 		err = PyObjC_PythonToObjC(@encode(id), 
 			PySequence_Fast_GET_ITEM(objectSeq, i), objects + i);
 		if (err == -1) {
+			PyMem_Free(keys);
+			PyMem_Free(objects);
 			Py_DECREF(keySeq);
 			Py_DECREF(objectSeq);
 			PyErr_NoMemory();
 		err = PyObjC_PythonToObjC(@encode(id), 
 			PySequence_Fast_GET_ITEM(keySeq, i), keys + i);
 		if (err == -1) {
+			PyMem_Free(keys);
+			PyMem_Free(objects);
 			Py_DECREF(keySeq);
 			Py_DECREF(objectSeq);
 			PyErr_NoMemory();
 		res = nil;
 	PyObjC_ENDHANDLER
 
+	PyMem_Free(keys);
+	PyMem_Free(objects);
 	Py_DECREF(objectSeq);
 	Py_DECREF(keySeq);
 
 		return NULL;
 	}
 
-	keys = alloca(sizeof(id) * count);
+	keys = PyMem_Malloc(sizeof(id) * count);
 	if (keys == NULL) {
 		Py_DECREF(keySeq);
 		Py_DECREF(objectSeq);
 		return NULL;
 	}
 
-	objects = alloca(sizeof(id) * count);
+	objects = PyMem_Malloc(sizeof(id) * count);
 	if (objects == NULL) {
+		PyMem_Free(keys);
 		Py_DECREF(keySeq);
 		Py_DECREF(objectSeq);
 		PyErr_NoMemory();
 		err = PyObjC_PythonToObjC(@encode(id), 
 			PySequence_Fast_GET_ITEM(objectSeq, i), objects + i);
 		if (err == -1) {
+			PyMem_Free(keys);
+			PyMem_Free(objects);
 			Py_DECREF(keySeq);
 			Py_DECREF(objectSeq);
 			PyErr_NoMemory();
 		err = PyObjC_PythonToObjC(@encode(id), 
 			PySequence_Fast_GET_ITEM(keySeq, i), keys + i);
 		if (err == -1) {
+			PyMem_Free(keys);
+			PyMem_Free(objects);
 			Py_DECREF(keySeq);
 			Py_DECREF(objectSeq);
 			PyErr_NoMemory();
 		res = nil;
 	PyObjC_ENDHANDLER
 
+	PyMem_Free(keys);
+	PyMem_Free(objects);
 	Py_DECREF(objectSeq);
 	Py_DECREF(keySeq);
 

Modules/Foundation/_FoundationMapping_NSMutableArray.m

 		return NULL;
 	}
 
-	indices = alloca(sizeof(unsigned) * count);
+	indices = PyMem_Malloc(sizeof(unsigned) * count);
 	if (indices == NULL) {
 		Py_DECREF(indicesSeq);
 		PyErr_NoMemory();
 		err = PyObjC_PythonToObjC(@encode(unsigned), 
 			PySequence_Fast_GET_ITEM(indicesSeq, i), indices + i);
 		if (err == -1) {
+			PyMem_Free(indices);
 			Py_DECREF(indicesSeq);
 			PyErr_NoMemory();
 			return NULL;
 	PyObjC_ENDHANDLER
 
 	Py_DECREF(indicesSeq);
+	PyMem_Free(indices);
 
 	if (PyErr_Occurred()) {
 		return NULL;
 		return NULL;
 	}
 
-	objects = alloca(sizeof(id) * count);
+	objects = PyMem_Malloc(sizeof(id) * count);
 	if (objects == NULL) {
 		Py_DECREF(objectSeq);
 		PyErr_NoMemory();
 		err = PyObjC_PythonToObjC(@encode(id), 
 			PySequence_Fast_GET_ITEM(objectSeq, i), objects + i);
 		if (err == -1) {
+			PyMem_Free(objects);
 			Py_DECREF(objectSeq);
 			PyErr_NoMemory();
 			return NULL;
 	PyObjC_ENDHANDLER
 
 	Py_DECREF(objectSeq);
+	PyMem_Free(objects);
 
 	if (PyErr_Occurred()) {
 		return NULL;

Modules/objc/class-builder.m

 	PyObject*                py_superclass;
 	int                      item_size;
 
-
-	/* XXX: May as well directly pass this in... */
-	py_superclass = PyObjCClass_New(super_class);
-	if (py_superclass == NULL) return NULL;
-
-	if (do_slots(py_superclass, class_dict) < 0) {
-		goto error_cleanup;
-	}
-
 	if (!PyList_Check(protocols)) {
 		PyErr_Format(ObjCExc_internal_error,  
 			"protocol list not a python 'list' but '%s'",
 		goto error_cleanup;
 	}
 
+	py_superclass = PyObjCClass_New(super_class);
+	if (py_superclass == NULL) return NULL;
+
+	if (do_slots(py_superclass, class_dict) < 0) {
+		goto error_cleanup;
+	}
+
+
 	/* 
 	 * Check for methods/variables that must not be overridden in python.
 	 */
 	 * methods.
 	 */
 	for (i = 0; i < key_count; i++) {
-		key = PyList_GetItem(key_list, i);
+		key = PyList_GET_ITEM(key_list, i);
 		if (PyErr_Occurred()) {
 			PyErr_SetString(ObjCExc_internal_error,
 				"PyObjCClass_BuildClass: "
 		meta_method_list = NULL;
 	}
 
-	Py_XDECREF(py_superclass);
+	Py_XDECREF(py_superclass); py_superclass = NULL;
 
 	if (PyDict_DelItemString(class_dict, "__dict__") < 0) {
 		PyErr_Clear();
 		PyObjCSelector_Signature(pymeth));
 	len = signature->nargs;
 
-	Py_XDECREF(pyself);
-	Py_XDECREF(pymeth);
+	Py_XDECREF(pymeth); pymeth = NULL;
 
 	arglist = PyList_New(1);
 	if (arglist == NULL) {
 		return;
 	}
 
-	i = PyList_SetItem(arglist, 0, pythonify_c_value(
-					signature->argtype[0],
-					(void*)&self));
-	if (i < 0) {
-		Py_DECREF(arglist);
-		PyObjCMethodSignature_Free(signature);
-		PyObjCErr_ToObjCWithGILState(&state);
-		return;
-	}
+	PyList_SET_ITEM(arglist, 0, pyself);
+	pyself = NULL;
 
 	for (i = 2; i < len; i++) {
 		type = signature->argtype[i];
 		return;
 	}
 	Py_DECREF(arglist);
-	arglist = v;
+	arglist = v; v = NULL;
 
 	result = PyObjC_CallPython(self, theSelector, arglist, &isAlloc);
 	Py_DECREF(arglist);
 					PyObjCErr_ToObjCWithGILState(&state);
 					return;
 				}
-				if (v->ob_refcnt == 1 && type[0] == _C_ID) {
+				if (result->ob_refcnt == 1 && type[0] == _C_ID) {
 					/* make sure return value doesn't die before
 					 * the caller can get its hands on it.
 					 */
 				(char*)[key cString],
 				val);
 			Py_DECREF(val);
+			Py_DECREF(selfObj);
 			if (r == -1) {
 				PyErr_Clear();
 				PyGILState_Release(state);
 				(char*)[key cString],
 				val);
 			Py_DECREF(val);
+			Py_DECREF(selfObj);
 			if (r == -1) {
 				PyErr_Clear();
 				PyGILState_Release(state);

Modules/objc/class-list.m

 		PyObject* pyclass = PyObjCClass_New(classid);
 		if (pyclass == NULL) goto error;
 
-		if (PyTuple_SET_ITEM(result, i, pyclass) < 0) {
-			Py_DECREF(pyclass);
-			goto error;
-		}
-
+		PyTuple_SET_ITEM(result, i, pyclass);
 		i++;
 	}
 

Modules/objc/informal-protocol.m

 }
 
 static PyObject*
-FindSelInDict(PyObject* clsdict, SEL selector)
+findSelInDict(PyObject* clsdict, SEL selector)
 {
 	PyObject* values;
 	PyObject* seq;
 		if (PyObjCSelector_GetSelector(v) == selector) {
 			Py_DECREF(seq);
 			Py_DECREF(values);
+			Py_INCREF(v);
 			return v;
 		}
 	}
 	return NULL;
 }
 
-static int signaturesEqual(char* sig1, char* sig2)
+static int 
+signaturesEqual(char* sig1, char* sig2)
 {
 	char buf1[1024];
 	char buf2[1024];
 
 		sel = PyObjCSelector_GetSelector(cur);
 
-		m = FindSelInDict(clsdict, sel);
+		m = findSelInDict(clsdict, sel);
 		if (m == NULL) {
 			m = PyObjCClass_FindSelector(super_class, sel);
 		}
 
 		if (m == NULL || !PyObjCSelector_Check(m)) {
+			Py_XDECREF(m);
 			if (PyObjCSelector_Required(cur)) {
 				PyErr_Format(PyExc_TypeError,
 					"class %s does not fully implement "
 					PyObjCSelector_Signature(cur)
 				);
 				Py_DECREF(seq);
+				Py_DECREF(m);
 				return 0;
 			}
+			Py_DECREF(m);
 		}
 	}
 	Py_DECREF(seq);

Modules/objc/libffi_support.m

 				if (err == -1) {
 					goto error;
 				}
-				if (v->ob_refcnt == 1 && argtype[0] == _C_ID) {
+				if (res->ob_refcnt == 1 && argtype[0] == _C_ID) {
 					/* make sure return value doesn't die before
 					 * the caller can get its hands on it.
 					 */
 					   "a value",
 					   PyObjCRT_SELName(*(SEL*)args[1]));
 				}
-				Py_DECREF(res); /* XXX */
+				Py_DECREF(res); 
 				goto error;
 			}
 		}
 		Py_INCREF(Py_None);
 		objc_result =  Py_None;
 	}
-#if defined(PYOBJC_NEW_INITIALIZER_PATTERN)
+
 	if (objc_result != self
 		&& PyObjCObject_Check(self) && PyObjCObject_Check(objc_result)
 		&& !(flags & PyObjCSelector_kRETURNS_UNINITIALIZED)
 		[PyObjCObject_GetObject(objc_result) release];
 		PyObjCObject_ClearObject(self);
 	}
-#else
-	if ( (flags & PyObjCSelector_kRETURNS_SELF)
-		&& (objc_result != self)) {
-
-		/* meth is a method that returns a possibly reallocated
-		 * version of self and self != return-value, the current
-		 * value of self is assumed to be no longer valid
-		 */
-		if (PyObjCObject_Check(self) && PyObjCObject_Check(objc_result)
-			&& (flags & PyObjCSelector_kINITIALIZER) &&
-			(((PyObjCObject*)self)->flags & PyObjCObject_kUNINITIALIZED)) {
-			[PyObjCObject_GetObject(objc_result) release];
-		}
-		PyObjCObject_ClearObject(self);
-	}
-#endif /* PYOBJC_NEW_INITIALIZER_PATTERN */
 
 	if (byref_out_count == 0) {
 		result = objc_result;

Modules/objc/method-accessor.m

 		} else {
 			bound_self = NULL;
 		}
+
 	} else {
 		PyErr_BadInternalCall();
 		return NULL;

Modules/objc/method-imp.m

 
 	execute = self->callfunc;
 
-#if !defined(PYOBJC_NEW_INITIALIZER_PATTERN)
-	if (PyObjCObject_Check(pyself) 
-		&& (PyObjCObject_GetFlags(pyself) & PyObjCObject_kUNINITIALIZED) 
-		&& !(self->flags & PyObjCSelector_kINITIALIZER)) {
-
-		char buf[1024];
-
-		snprintf(buf, sizeof(buf), 
-			"Calling IMP %s on uninitialized object %p of class %s\n",
-			PyObjCRT_SELName(self->selector),
-			(void*)PyObjCObject_GetObject(pyself),
-			GETISA(PyObjCObject_GetObject(pyself))->name);
-
-		if (PyErr_Warn(PyExc_RuntimeWarning, buf) < 0) {
-			return NULL;
-		}
-	}
-#endif /* ! PYOBJC_NEW_INITIALIZER_PATTERN */
-
-
 	arglist = PyTuple_New(argslen - 1);
 	for (i = 1; i < argslen; i++) {
 		PyObject* v = PyTuple_GET_ITEM(args, i);
 	if (res && PyObjCObject_Check(res)) {
 		if (self->flags & PyObjCSelector_kRETURNS_UNINITIALIZED) {
 			((PyObjCObject*)res)->flags |= PyObjCObject_kUNINITIALIZED;
-		}
-#if defined(PYOBJC_NEW_INITIALIZER_PATTERN)
-		else if (((PyObjCObject*)res)->flags & PyObjCObject_kUNINITIALIZED) {
+		} else if (((PyObjCObject*)res)->flags & PyObjCObject_kUNINITIALIZED) {
 			((PyObjCObject*)res)->flags &=
 				~PyObjCObject_kUNINITIALIZED;
 			if (pyself && pyself != res && PyObjCObject_Check(pyself) && !PyErr_Occurred()) {
 				PyObjCObject_ClearObject(pyself);
 			}
 		}
-#else
-		if (self->flags & PyObjCSelector_kINITIALIZER) {
-			if (((PyObjCObject*)res)->flags & PyObjCObject_kUNINITIALIZED)
-			{
-				((PyObjCObject*)res)->flags &= 
-					~PyObjCObject_kUNINITIALIZED;
-			}
-		}
-#endif /* PYOBJC_NEW_INITIALIZER_PATTERN */
 
 		if (self->flags & PyObjCSelector_kDONATE_REF) {
 			/* Ownership transfered to us, but 'execute' method has
 	return PyObjCBool_FromLong(0 != (self->flags & PyObjCSelector_kRETURNS_UNINITIALIZED));
 }
 
-#if !defined(PYOBJC_NEW_INITIALIZER_PATTERN)
-PyDoc_STRVAR(imp_returns_self_doc, 
-"True if this is method returns a reallocated 'self', False otherwise\n"
-"\n"
-"NOTE: This field is used by the implementation."
-);
-static PyObject*
-imp_returns_self(PyObjCIMPObject* self, void* closure __attribute__((__unused__)))
-{
-	return PyObjCBool_FromLong(0 != (self->flags & PyObjCSelector_kRETURNS_SELF));
-}
-
-PyDoc_STRVAR(imp_is_initializer_doc, 
-"True if this is method is an object initializer\n"
-"\n"
-"NOTE: This field is used by the implementation."
-);
-static PyObject*
-imp_is_initializer(PyObjCIMPObject* self, void* closure __attribute__((__unused__)))
-{
-	return PyObjCBool_FromLong(0 != (self->flags & PyObjCSelector_kINITIALIZER));
-}
-#endif /* ! PYOBJC_NEW_INITIALIZER_PATTERN */
 
 static PyGetSetDef imp_getset[] = {
-#if !defined(PYOBJC_NEW_INITIALIZER_PATTERN)
-	{
-		"isInitializer",
-		(getter)imp_is_initializer,
-		0,
-		imp_is_initializer_doc,
-		0
-	},
-#endif /* ! PYOBJC_NEW_INITIALIZER_PATTERN */
 	{
 		"isAlloc",
 		(getter)imp_is_alloc,
 		imp_selector_doc,
 		0
 	},
-#if !defined(PYOBJC_NEW_INITIALIZER_PATTERN)
-	{
-		"returnsSelf",
-		(getter)imp_returns_self,
-		0,
-		imp_returns_self_doc,
-		0
-	},
-#endif /* PYOBJC_NEW_INITIALIZER_PATTERN */
 	{ 
 		"__name__",  
 		(getter)imp_selector, 

Modules/objc/module.m

 		PyObject* aMethod = PySequence_Fast_GET_ITEM(methodsArray, methodIndex);
 		struct objc_method *objcMethod;
 
-		/* check
-		 * FIXME: We should support functions here, just like with
-		 * class definitions.
-		 */
 		aMethod = PyObjCSelector_FromFunction(
 			NULL,
 			aMethod,
 		for (j = 0; j < cls->protocols->count; j++) {
 			Protocol* p = cls->protocols->list[j];
 			if (strcmp([p name], name) == 0) {
-#if 0
-				printf("Found it in %s\n", cls->name);
-#endif
 				return PyObjCObject_NewClassic(p);
 			}
 		}

Modules/objc/objc-class.m

 		return (PyObjC_class_info*)item;
 	}
 
-	info = malloc(sizeof(PyObjC_class_info));
+	info = PyMem_Malloc(sizeof(PyObjC_class_info));
 	if (info == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 static int 
 objc_class_unregister(Class objc_class)
 {
+	PyObject* val;
 	if (class_registry == NULL) return 0;
 
-	/* XXX: Aren't we leaking memory here, I'd expect that we'd have
-         *      to DECREF the py_class.
-	 */ 
+	val = NSMapGet(class_registry, objc_class);
+	Py_XDECREF(val);
 	NSMapRemove(class_registry, objc_class);
 	return 0;
 }
  * @param objc_class An Objective-C class
  * @result Returns the Python wrapper for the class, or NULL
  * @discussion
- *     This functioin does not raise an Python exception when the
+ *     This function does not raise an Python exception when the
  *     wrapper cannot be found.
  */
 static PyObject*
 	if (objc_class == NULL) return NULL;
 
 	result = NSMapGet(class_registry, objc_class);
+	Py_XINCREF(result);
 	return result;
 }
 
 		return NULL;
 	}
 
-	v = PyTuple_GET_ITEM(bases, 0);
-	if (v == NULL) {
+	py_super_class = PyTuple_GET_ITEM(bases, 0);
+	if (py_super_class == NULL) {
 		return NULL;
 	}
 
-	if (!PyObjCClass_Check(v)) {
+	if (!PyObjCClass_Check(py_super_class)) {
 		PyErr_SetString(PyExc_TypeError, 
 				"first base class must "
 				"be objective-C based");
 		return NULL;
 	}
-	py_super_class = v;
 	super_class = PyObjCClass_GetClass(py_super_class);
 	if (super_class) {
 		PyObjCClass_CheckMethodList(py_super_class, 1);
 		Py_DECREF(protocols);
 		return NULL;
 	}
-	PyList_Append(real_bases, v);
+	PyList_Append(real_bases, py_super_class);
 	if (PyErr_Occurred()) {
 		Py_DECREF(protocols);
 		Py_DECREF(real_bases);
 		if (!recursive) break;
 		if (info->class->super_class == NULL) break;
 		cls = PyObjCClass_New(info->class->super_class);
-
 		Py_DECREF(cls);
 		info = get_class_info(cls);
 	}
 						selbuf, 
 						sizeof(selbuf));
 
-			/* FIXME: because we scan again later on, we should
-			 * take care to avoid replacing Python methods with
-			 * a custom selector ('selector' argument to function
-			 * objc.selector)
-			 *
-			 * We're save for now because none of the example code 
-			 * uses this feature.
-			 */
 			curItem = PyDict_GetItemString(dict, name);
 			if (curItem == NULL) {
 				PyErr_Clear();
 
 	result = objc_class_locate(objc_class);
 	if (result != NULL) {
-		Py_INCREF(result);
 		return result;
 	}
 
+#ifdef GNU_RUNTIME
+	/*
+	 * FIXME: we do get unresolved classes when fetching the class list
+	 * (especially when loading multiple frameworks). I'm not sure why
+	 * this occurs, it might be the way we link/compile our code.
+	 *
+	 * The test below seems to fix the problems, but is obviously a hack.
+	 */
+	if (!CLS_ISRESOLV(objc_class)) {
+		extern void __objc_resolve_class_links(void);
+		__objc_resolve_class_links();
+	}
+#endif
+
 	dict = PyDict_New();
 	PyDict_SetItemString(dict, "__slots__", PyTuple_New(0));
 
 	}
 
 	info->class = objc_class;
-	info->sel_to_py = PyDict_New(); 
+	info->sel_to_py = NULL;
 	info->method_magic = 0;
 	info->dictoffset = 0;
 	info->delmethod = NULL;

Modules/objc/objc-object.m

 	return res;
 }
 
-#if 0 /* No longer used */
-PyDoc_STRVAR(obj_get_classMethods_doc,
-"The attributes of this field are the class methods of this object. This can\n"
-"be used to force access to a class method."
-);
-static PyObject*
-obj_get_classMethods(PyObjCObject* self, void* closure __attribute__((__unused__)))
-{
-	return ObjCMethodAccessor_New((PyObject*)self, 1);
-}
-#endif
-
 PyDoc_STRVAR(objc_get_real_class_doc, "Return the current ISA of the object");
 static PyObject* objc_get_real_class(PyObject* self, void* closure __attribute__((__unused__)))
 {
 }
 
 static PyGetSetDef obj_getset[] = {
-#if 0
-	{
-		"pyobjc_classMethods",
-		(getter)obj_get_classMethods,
-		NULL,
-		obj_get_classMethods_doc,
-		0
-	},
-#endif
 	{
 		"pyobjc_ISA",
 		(getter)objc_get_real_class,
 #ifdef FREELIST_SIZE
 	if (obj_freelist_top == 0) {
 		res = cls_type->tp_alloc(cls_type, 0);
+		Py_DECREF(cls_type);
 		if (res == NULL) {
 			return NULL;
 		}
 	}
 #else
 	res = cls_type->tp_alloc(cls_type, 0);
+	Py_DECREF(cls_type);
 	if (res == NULL) {
 		return NULL;
 	}
 #ifdef FREELIST_SIZE
 	if (obj_freelist_top == 0) {
 		res = cls_type->tp_alloc(cls_type, 0);
+		Py_DECREF(cls_type);
 		if (res == NULL) {
 			return NULL;
 		}
 	}
 #else
 	res = cls_type->tp_alloc(cls_type, 0);
+	Py_DECREF(cls_type);
 	if (res == NULL) {
 		return NULL;
 	}
 #ifdef FREELIST_SIZE
 	if (obj_freelist_top == 0) {
 		res = cls_type->tp_alloc(cls_type, 0);
+		Py_DECREF(cls_type);
 		if (res == NULL) {
 			return NULL;
 		}
 	}
 #else
 	res = cls_type->tp_alloc(cls_type, 0);
+	Py_DECREF(cls_type);
 	if (res == NULL) {
 		return NULL;
 	}
 	}
 
 	res = cls_type->tp_alloc(cls_type, 0);
+	Py_DECREF(cls_type);
 	if (res == NULL) {
 		return NULL;
 	}
 void        
 PyObjCObject_ClearObject(PyObject* object)
 {
-    if (object == NULL) abort();
+	if (object == NULL) abort();
 	if (!PyObjCObject_Check(object)) {
 		PyErr_Format(PyExc_TypeError,
 			"'objc.objc_object' expected, got '%s'",

Modules/objc/objc-runtime-apple.m

 
 void PyObjCRT_ClearClass(Class cls)
 {
-	return;
 	if (cls->methodLists) {
 		if (cls->methodLists) {
 			struct objc_method_list** cur;

Modules/objc/objc-runtime-gnu.m

 
 	cls->protocols = metaCls->protocols = NULL;
 
-        __objc_install_premature_dtable (metaCls);
-	__objc_install_premature_dtable (cls);
+	metaCls->dtable = objc_get_uninstalled_dtable();
+	cls->dtable = objc_get_uninstalled_dtable();
 
 	return 0;
 }

Modules/objc/objc_support.m

 		type++;
 		while (*type != _C_UNION_E)
 		{
-			int item_align = PyObjC_EmbeddedAlignOfType(type);
+			int item_align = PyObjCRT_AlignOfType(type);
 			if (item_align == -1) return -1;
 			maxalign = MAX (maxalign, item_align);
 			type = PyObjCRT_SkipTypeSpec (type);
 #ifdef MACOSX
 			*(id*) datum = PyObjC_CFTypeToID(argument);
 			if (*(id*)datum != NULL) {
-				/* BUG! for some reason the unittests fail
-				 * without this retain. This needs further
-				 * investigation, as this doesn't look
-				 * correct to me
-				 */
-				[*(id*)datum retain];
 				return 0;
 			}
 #endif /* MACOSX */

Modules/objc/objc_util.m

 
 PyGILState_STATE PyObjCGILState_Ensure(void)
 {
-	/* Now that PyObjCUnicode_New no longer uses autorelead objects it 
-	 * should no longer be necessary to create a transient release-pool
-	 * for calls from ObjC to python. 
-	 * The pool might also be unsafe because at least some python methods
-	 * return objects whose only reference is in the autorelease pool (
-	 * it is unverified if this really is a problem)
-	 */
-#if 1
 	return PyGILState_Ensure();
-#else
-	int shouldCreateThreadPool = (PyGILState_GetThisThreadState() == NULL) ? 1 : 0;
-	PyGILState_STATE state = PyGILState_Ensure();
-	if (shouldCreateThreadPool) {
-		int err;
-		NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-		PyObject *pypool = PyObjC_IdToPython(pool);
-		PyObject *tdict = PyThreadState_GetDict();
-		assert(tdict != NULL);
-		assert(pypool != NULL);
-		err = PyDict_SetItemString(tdict, THREADSTATE_AUTORELEASEPOOL, pypool);
-		assert(err == 0);
-		Py_DECREF(pypool);
-	}
-	return state;
-#endif
 }
 
 int ObjCUtil_Init(PyObject* module)
 	}
 
 	return 0;
-
-#if 0
-	PyBufferProcs* pb = obj->ob_type->tp_as_buffer;
-	if (!PyType_HasFeature(obj->ob_type,
-				Py_TPFLAGS_HAVE_GETCHARBUFFER) ||
-				pb == NULL || 
-				pb->bf_getcharbuffer == NULL ||
-				pb->bf_getsegcount == NULL) {
-		PyErr_SetString(PyExc_TypeError, "cannot access buffer");
-		return -1;
-	}
-
-	if (pb->bf_getsegcount(obj, NULL) != 1) {
-		PyErr_SetString(PyExc_TypeError, 
-				"cannot access multi-segment buffer");
-		return -1;
-	}
-	
-	*sizeptr = pb->bf_getcharbuffer(obj, 0, (const char**)bufptr);
-	if (*sizeptr < 0) {
-		PyErr_SetString(PyExc_TypeError,
-				"error accessing buffer object");
-		return -1;
-	}
-	return 0;
-#endif
 }
 
 static char struct_elem_code(const char* typestr);

Modules/objc/pyobjc-api.h

  * This is the *only* header file that should be used to access 
  * functionality in the core bridge.
  *
- * $Id: pyobjc-api.h,v 1.33 2004/05/07 00:23:26 etrepum Exp $
+ * $Id: pyobjc-api.h,v 1.34 2004/05/21 20:44:31 ronaldoussoren Exp $
  */
 
 #include <Python.h>
  * - Version 7 adds PyObjCErr_AsExc, PyObjCGILState_Ensure
  * - Version 8 adds PyObjCObject_IsUninitialized,
         removes PyObjCSelector_IsInitializer
+ * - Version 9 (???)
  */
-#define PYOBJC_API_VERSION 8
+#define PYOBJC_API_VERSION 9
 
 #define PYOBJC_API_NAME "__C_API__"
 
     /* PyObjCGILState_Ensure */
     PyGILState_STATE (*gilstate_ensure)(void);
 
-#if !defined(PYOBJC_NEW_INITIALIZER_PATTERN)
-    /* PyObjCSelector_IsInitializer */
-    int (*sel_is_init)(PyObject*);
-#endif /* ! PYOBJC_NEW_INITIALIZER_PATTERN */
     int (*obj_is_uninitialized)(PyObject*);
 };
 
 #define PyObjCIMP_GetIMP   (PyObjC_API->imp_get_imp)
 #define PyObjCIMP_GetSelector   (PyObjC_API->imp_get_sel)
 #define PyObjCGILState_Ensure (PyObjC_API->gilstate_ensure)
-#define PyObjCSelector_IsInitializer (PyObjC_API->sel_is_init)
 #define PyObjCObject_IsUninitialized (PyObjC_API->obj_is_uninitialized)
 
 
 
 
 #ifndef PYOBJC_METHOD_STUB_IMPL
+
 static int
 PyObjC_ImportAPI(PyObject* calling_module)
 {

Modules/objc/pyobjc-api.m

 #undef PyObjCObject_GetObject
 #endif
 
-#if !defined(PYOBJC_NEW_INITIALIZER_PATTERN)
-static int sel_is_init(PyObject* object)
-{
-	if (!PyObjCSelector_Check(object)) {
-		return -1;
-	}
-