Commits

Ronald Oussoren committed 4c2e034

Python2.5 related cleanups

Comments (0)

Files changed (37)

Modules/Foundation/decimals.m

 	NULL,				/* nb_true_divide */
 	NULL,				/* nb_inplace_floor_divide */
 	NULL				/* nb_inplace_true_divide */
+#if (PY_VERSION_HEX >= 0x02050000)
+	,NULL				/* nb_index */
+#endif
 };
 
 static NSDecimalNumber *

Modules/objc/OC_PythonArray.m

+#include "pyobjc.h"
 #import "OC_PythonArray.h"
 
 @implementation OC_PythonArray 
 
 -(int)count
 {
-	int result;
+	Py_ssize_t result;
 
 	PyObjC_BEGIN_WITH_GIL
 		result = PySequence_Length(value);
 
 	PyObjC_END_WITH_GIL
 
+	if (result > INT_MAX) {
+		return INT_MAX;
+	}
+
 	return result;
 }
 
 
 -(void)insertObject:(id)anObject atIndex:(unsigned)idx
 {
+	Py_ssize_t theIndex;
 	PyObject* v;
 	PyObject* w;
 
+	if (idx > PY_SSIZE_T_MAX) {
+		PyObjC_BEGIN_WITH_GIL
+			PyErr_SetString(PyExc_IndexError, "No such index");
+			PyObjC_GIL_FORWARD_EXC();
+		PyObjC_END_WITH_GIL
+	}
+	theIndex = idx;
+
 	PyObjC_BEGIN_WITH_GIL
 		if (anObject == [NSNull null]) {
 			Py_INCREF(Py_None);
 -(void)removeLastObject
 {
 	int r;
-	int idx;
+	Py_ssize_t idx;
 
 	PyObjC_BEGIN_WITH_GIL
 		idx = PySequence_Length(value);
 	int r;
 
 	PyObjC_BEGIN_WITH_GIL
-		if (idx > INT_MAX) {
+		if (idx > PY_SSIZE_T_MAX) {
 			PyErr_SetString(PyExc_IndexError, "No such index");
 			PyObjC_GIL_FORWARD_EXC();
 		}
 
-		r = PySequence_DelItem(value, (int)idx);
+		r = PySequence_DelItem(value, (Py_ssize_t)idx);
 		if (r == -1) {
 			PyObjC_GIL_FORWARD_EXC();
 		}

Modules/objc/OC_PythonData.m

 	self = [super init];
 	if (!self) return nil;
 
-	if (PyObject_AsReadBuffer(v, &buffer, ((int *)&buffer_len))) {
+	if (PyObject_AsReadBuffer(v, &buffer, &buffer_len)) {
 		[super dealloc];
 		return nil;
 	}
-
 	Py_INCREF(v);
 	Py_XDECREF(value);
 	value = v;
 {
 	unsigned rval;
 	PyObjC_BEGIN_WITH_GIL
-		if (PyObject_AsReadBuffer(value, &buffer, ((int *)&buffer_len))) {
+		if (PyObject_AsReadBuffer(value, &buffer, &buffer_len)) {
 			PyErr_Clear();
 			rval = 0;
 		}
-		rval = buffer_len;
+		if ((unsigned)buffer_len > UINT_MAX) {
+			rval = UINT_MAX;
+		} else {
+			rval = buffer_len;
+		}
 	PyObjC_END_WITH_GIL
 	return rval;
 }
 {
 	const void *rval;
 	PyObjC_BEGIN_WITH_GIL
-		if (PyObject_AsReadBuffer(value, &buffer, ((int *)&buffer_len))) {
+		if (PyObject_AsReadBuffer(value, &buffer, &buffer_len)) {
 			PyErr_Clear();
 			rval = NULL;
 		}

Modules/objc/OC_PythonDictionary.m

 {
 	OC_PythonDictionary* value;
 	BOOL valid;
-	int pos;
+	Py_ssize_t pos;
 }
 + newWithWrappedDictionary:(OC_PythonDictionary*)value;
 - initWithWrappedDictionary:(OC_PythonDictionary*)value;
 
 -(int)count
 {
-	int result;
+	Py_ssize_t result;
 
 	PyObjC_BEGIN_WITH_GIL
 		result = PyDict_Size(value);
 
 	PyObjC_END_WITH_GIL
 
+	if (result > INT_MAX) {
+		return INT_MAX;
+	}
 	return result;
 }
 
 	PyObjC_END_WITH_GIL
 }
 
--(BOOL)wrappedKey:(id*)keyPtr value:(id*)valuePtr atPosition:(int*)positionPtr
+-(BOOL)wrappedKey:(id*)keyPtr value:(id*)valuePtr atPosition:(Py_ssize_t*)positionPtr
 {
 	PyObject *pykey = NULL;
 	PyObject *pyvalue = NULL;

Modules/objc/OC_PythonObject.m

 PyObject *OC_PythonObject_DepythonifyTable = NULL;
 PyObject *OC_PythonObject_PythonifyStructTable = NULL;
 
-#if 0
-static void
-nsmaptable_python_retain(NSMapTable *table __attribute__((__unused__)), const void *datum) {
-	Py_INCREF((PyObject *)datum);
-}
-
-static void
-nsmaptable_python_release(NSMapTable *table __attribute__((__unused__)), void *datum) {
-	Py_DECREF((PyObject *)datum);
-}
-
-static void
-nsmaptable_objc_retain(NSMapTable *table __attribute__((__unused__)), const void *datum) {
-	[(id)datum retain];
-}
-
-static void
-nsmaptable_objc_release(NSMapTable *table __attribute__((__unused__)), void *datum) {
-	[(id)datum release];
-}
-
-NSMapTableKeyCallBacks PyObjC_ObjectToIdTable_KeyCallBacks = {
-	NULL, // use pointer value for hash
-	NULL, // use pointer value for equality
-	&nsmaptable_python_retain,
-	&nsmaptable_python_release,
-	NULL, // generic description
-	NULL // not a key
-};
-
-NSMapTableValueCallBacks PyObjC_ObjectToIdTable_ValueCallBacks = {
-	&nsmaptable_objc_retain,
-	&nsmaptable_objc_release,
-	NULL  // generic description
-};
-
-NSMapTable *PyObjC_ObjectToIdTable = NULL;
-#endif
-
-/* FIXME: PyObjC_RegisterObjCProxy should be moved to a central location! */
 @implementation OC_PythonObject
 + (int)wrapPyObject:(PyObject *)argument toId:(id *)datum
 {
 	PyObjC_END_WITH_GIL
 }
 
-+ (PyObject *)__pythonifyStruct:(PyObject*)obj withType:(const char *)type length:(int)length
++ (PyObject *)__pythonifyStruct:(PyObject*)obj withType:(const char *)type length:(Py_ssize_t)length
 {
 	if (OC_PythonObject_PythonifyStructTable == NULL) {
 		Py_INCREF(obj);
   returning the method itself if it matches @var{argcount}, NULL
   otherwise. */
 static inline PyObject *
-check_argcount (PyObject *pymethod, int argcount)
+check_argcount (PyObject *pymethod, Py_ssize_t argcount)
 {
 	PyCodeObject *func_code;
 
 get_method_for_selector(PyObject *obj, SEL aSelector)
 {
 	const char*  meth_name;
-	int          len;
+	Py_ssize_t   len;
 	char         pymeth_name[256];
-	unsigned int argcount;
+	Py_ssize_t   argcount;
 	PyObject*    pymethod;
 	const char*  p;
 	PyObject*    result;
 	char*        	   encoding;
 	PyObject*          pymethod;
 	PyCodeObject*      func_code;
-	int                argcount;
+	Py_ssize_t         argcount;
 
 	encoding = (char*)get_selector_encoding (self, sel);
 	if (encoding) {
 		pymethod = get_method_for_selector(pyObject, sel);
 		if (!pymethod) {
 			PyErr_Clear();
-			PyGILState_Release(_GILState); // XXX: FIXME
+			PyGILState_Release(_GILState); 
 			[NSException raise:NSInvalidArgumentException 
 				format:@"Class %s: no such selector: %s", 
 				GETISA(self)->name, PyObjCRT_SELName(sel)];
 	PyObject*          args = NULL;
 	volatile unsigned int       i;
 	unsigned int       argcount;      
-	int		   retsize;
+	Py_ssize_t	   retsize;
 	char*              retbuffer;
 
 	if ([self _forwardNative:invocation]) {
 		pymethod = get_method_for_selector(pyObject, aSelector);
 
 		if (!pymethod) {
-			PyGILState_Release(_GILState); // FIXME
+			PyGILState_Release(_GILState);
 			[self doesNotRecognizeSelector:aSelector];
 			return;
 		}
 		for (i=2; i< argcount; i++) {
 			const char *argtype;
 			char *argbuffer;
-			int  argsize;
+			Py_ssize_t  argsize;
 			PyObject *pyarg;
 
 			argtype = [msign getArgumentTypeAtIndex:i];
 				[invocation getArgument:argbuffer atIndex:i];
 
 			PyObjC_HANDLER
-				PyGILState_Release(_GILState); // FIXME
+				PyGILState_Release(_GILState);
 				[localException raise];
 
 			PyObjC_ENDHANDLER
 				[invocation setReturnValue:retbuffer];
 
 			PyObjC_HANDLER
-				PyGILState_Release(_GILState); // FIXME
+				PyGILState_Release(_GILState);
 				[localException raise];
 			PyObjC_ENDHANDLER
 		}

Modules/objc/OC_PythonString.m

 		supportsNoCopy = (int)[NSString instancesRespondToSelector:@selector(initWithBytesNoCopy:length:encoding:freeWhenDone:)];
 	}
 	if (!realObject) {
+		/* This will fail in interesting ways on 64-bit systems with
+		 * python2.5.  Luckily we don't support 64-bit systems :-)
+		 */
 		if (supportsNoCopy) {
 			// Mac OS X 10.3+
 			realObject = [[NSString alloc]
 				initWithBytesNoCopy:PyString_AS_STRING(value)
-							 length:(unsigned)PyString_GET_SIZE(value)
-						   encoding:[NSString defaultCStringEncoding]
-					   freeWhenDone:NO];
+				length:(unsigned)PyString_GET_SIZE(value)
+				encoding:[NSString defaultCStringEncoding]
+				freeWhenDone:NO];
 		} else {
 			// Mac OS X 10.2
 			realObject = [[NSString alloc]
-			    initWithBytes:PyString_AS_STRING(value)
-		  	           length:(unsigned)PyString_GET_SIZE(value)
-			         encoding:[NSString defaultCStringEncoding]];
+				initWithBytes:PyString_AS_STRING(value)
+				length:(unsigned)PyString_GET_SIZE(value)
+				encoding:[NSString defaultCStringEncoding]];
 		}
 	}
 	return realObject;

Modules/objc/OC_PythonUnicode.m

 	if (aRange.location + aRange.length > (unsigned)PyUnicode_GET_SIZE(value)) {
 		[NSException raise:@"NSRangeException" format:@"Range or index out of bounds"];
 	}
-	memcpy(buffer, PyUnicode_AS_UNICODE(value) + aRange.location, sizeof(unichar) * aRange.length);
-	/*
-	unsigned i;
-	for (i = 0; i < aRange.length; i++) {
-		buffer[i] = PyUnicode_AS_UNICODE(value)[aRange.location + i];
-	}
-	*/
+	memcpy(buffer, 
+	       PyUnicode_AS_UNICODE(value) + aRange.location, 
+	       sizeof(unichar) * aRange.length);
 }
 
 #else /* !PyObjC_UNICODE_FAST_PATH */

Modules/objc/ObjCPointer.m

 #include "pyobjc.h"
 
 static void
-PyObjCPointer_dealloc (PyObjCPointer *self)
+PyObjCPointer_dealloc (PyObject* _self)
 {
+	PyObjCPointer* self = (PyObjCPointer*)_self;
 	Py_DECREF (self->type);
 	PyObject_Free((PyObject*)self);
 }
 	"Unpack the pointed value accordingly to its type.\n"
         "obj.unpack() -> value");
 static PyObject *
-PyObjCPointer_unpack (PyObjCPointer *self)
+PyObjCPointer_unpack (PyObject* _self)
 {
+	PyObjCPointer* self = (PyObjCPointer*)_self;
+
 	if (self->ptr) {
 		const char *type = PyString_AS_STRING (self->type);
 
 {
 	{
 		"unpack",   
-		(PyCFunction) PyObjCPointer_unpack,       
+		(PyCFunction)PyObjCPointer_unpack,       
 		METH_NOARGS,   
 		PyObjCPointer_unpack_doc 
 	},
 	sizeof (char),				/* tp_itemsize */
   
 	/* methods */
-	(destructor)PyObjCPointer_dealloc,	/* tp_dealloc */
+	PyObjCPointer_dealloc,			/* tp_dealloc */
 	0,					/* tp_print */
 	0,					/* tp_getattr */
 	0,					/* tp_setattr */
 PyObjCPointer *
 PyObjCPointer_New(void *p, const char *t)
 {
-	unsigned int size = PyObjCRT_SizeOfType (t);
+	Py_ssize_t size = PyObjCRT_SizeOfType (t);
 	const char *typeend = PyObjCRT_SkipTypeSpec (t);
 	PyObjCPointer *self;
 
 	NSLog(@"PyObjCPointer created: at %p of type %s", p, t);
 
-	if (size == (unsigned int)-1) {
+	if (size == -1) {
 		return NULL;
 	}
 	if (typeend == NULL) {

Modules/objc/alloc_hack.m

 
 		Py_DECREF(arglist); 
 
-		/* TODO: assert result is None */
+		if (result != Py_None) {
+			PyErr_Format(PyExc_TypeError,
+				"dealloc should return None, returned instance"
+				" of %s", result->ob_type->tp_name);
+			PyObjC_GIL_FORWARD_EXC();
+		}
+
 		Py_DECREF(result);
 
 	PyObjC_END_WITH_GIL
 		Py_DECREF(arglist); 
 		PyObjCObject_ReleaseTransient(pyself, cookie);
 
-		/* TODO: assert result is None */
+		if (result != Py_None) {
+			PyErr_Format(PyExc_TypeError,
+				"release should return None, returned instance"
+				" of %s", result->ob_type->tp_name);
+			PyObjC_GIL_FORWARD_EXC();
+		}
+
 		Py_DECREF(result);
 
 	PyObjC_END_WITH_GIL

Modules/objc/bundle-variables.m

 	NSBundle*	bundle;
 	PyObject*	module_globals;
 	PyObject*	variableInfo;
-	int		skip_undefined = 1;
+	Py_ssize_t	skip_undefined = 1;
 	CFBundleRef	cfBundle;
 	PyObject*       seq;
-	int		i, len;
+	Py_ssize_t	i, len;
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&OO|i",
 			keywords, PyObjCObject_Convert, &bundle,
 
 		if (!PyTuple_Check(item)) {
 			PyErr_Format(PyExc_TypeError,
-				"item %d has type %s not tuple",
+				"item %" PY_FORMAT_SIZE_T 
+				"d has type %s not tuple",
 				i, item->ob_type->tp_name);
 			Py_DECREF(seq);
 			return NULL;
 		if (value == NULL) {
 			if (!skip_undefined) {
 				PyErr_SetString(PyObjCExc_Error,
-					"cannot find a variable"); // XXX
+					"cannot find a variable");
 				Py_DECREF(seq);
 				return NULL;
 			}
 	int		skip_undefined = 1;
 	CFBundleRef	cfBundle;
 	PyObject*       seq;
-	int		i, len;
+	Py_ssize_t	i, len;
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&OO|i",
 			keywords, PyObjCObject_Convert, &bundle,
 
 		if (!PyTuple_Check(item)) {
 			PyErr_Format(PyExc_TypeError,
-				"item %d has type %s not tuple",
+				"item %" PY_FORMAT_SIZE_T 
+				"d has type %s not tuple",
 				i, item->ob_type->tp_name);
 			Py_DECREF(seq);
 			return NULL;
 		if (value == NULL) {
 			if (!skip_undefined) {
 				PyErr_SetString(PyObjCExc_Error,
-					"cannot find a function"); // XXX
+					"cannot find a function");
 				Py_DECREF(seq);
 				return NULL;
 			}

Modules/objc/class-builder.m

 		void* userdata);
 
 /*
- * When we create a 'Class' we actually create the struct below. This allows
- * us to add some extra information to the class definition.
+ * When we create a 'Class' we actually create the struct below. 
  *
  * XXX: The struct is not really necessary, it just makes error-recovery 
  * slightly easier. 
 {
 	PyObject* slot_value;
 	PyObject* slots;
-	int       len, i;
+	Py_ssize_t len, i;
 
 	slot_value = PyDict_GetItemString(clsdict, "__slots__");
 	if (slot_value == NULL) {
 
 		if (!PyString_Check(slot_value)) {
 			PyErr_Format(PyExc_TypeError, 
-				"__slots__ entry %d is not a string", i);
+				"__slots__ entry %" PY_FORMAT_SIZE_T 
+				"d is not a string", i);
 			Py_DECREF(slots);
 			return -1;
 		}
 	Class intermediate_class = nil;
 	Class meta_class = nil;
 	Class root_class;
-	int i;
+	int r;
 	struct objc_method_list* method_list = NULL;
 	PyObjCRT_Method_t meth;
 	IMP closure;
 		goto error_cleanup;
 	}
 
-	i = PyObjCRT_SetupClass(
+	r = PyObjCRT_SetupClass(
 		intermediate_class, 
 		meta_class, 
 		name,
 		base_class->instance_size, NULL,
 		NULL
 		);
-	if (i < 0) {
+	if (r < 0) {
 		goto error_cleanup;
 	}
 
 	PyObject*                key_list = NULL;
 	PyObject*                key = NULL;
 	PyObject*                value = NULL;
-	int                      i, key_count;
-	int                      ivar_count = 0;
-	int                      ivar_size  = 0;
-	int                      meta_method_count = 0;
-	int                      method_count = 0;
-	int                      protocol_count = 0;
+	int               	 r;
+	Py_ssize_t		 i;
+	Py_ssize_t		 key_count;
+	Py_ssize_t               ivar_count = 0;
+	Py_ssize_t               ivar_size  = 0;
+	Py_ssize_t               meta_method_count = 0;
+	Py_ssize_t               method_count = 0;
+	Py_ssize_t               protocol_count = 0;
 	int                      first_python_gen = 0;
 	struct objc_ivar_list*   ivar_list = NULL;
 	struct objc_method_list* method_list = NULL;
 	Class                    root_class;
 	Class                    cur_class;
 	PyObject*                py_superclass = NULL;
-	int                      item_size;
+	Py_ssize_t               item_size;
 	int			 have_intermediate = 0;
 	int			 need_intermediate = 0;
 
 		root_class = root_class->super_class;
 	}
 
-	i = PyObjCRT_SetupClass(
+	r = PyObjCRT_SetupClass(
 		&new_class->class, 
 		&new_class->meta_class, 
 		name,
 		ivar_size, ivar_list,
 		protocol_list
 		);
-	if (i < 0) {
+	if (r < 0) {
 		goto error_cleanup;
 	}
 
 	}
 
 	while (cls != NULL) {
-		Class     objcClass = PyObjCClass_GetClass(cls);
+		Class objcClass = PyObjCClass_GetClass(cls);
 		PyObject* clsDict; 
 		PyObject* clsValues;
 		PyObject* o;
-		volatile int       i;
-		int len;
+		volatile Py_ssize_t i;
+		Py_ssize_t len;
 
 		if (objcClass == nil) break;
 
 	PyObject* 	result;
 	PyObject*       v;
 	int		isAlloc;
-	int             i;
-	int 		len;
+	Py_ssize_t      i;
+	Py_ssize_t	len;
 	PyObjCMethodSignature* signature;
 	/*char		   argbuf[1024]; */
 	const char* 		type;
 	void* argbuf = NULL;
 	int  err;
-	int   arglen;
+	Py_ssize_t   arglen;
 	PyObject* pymeth;
 	PyObject* pyself;
 	volatile int have_output = 0;
 		Py_DECREF(result);
 
 	} else {
-		int idx;
+		Py_ssize_t idx;
 		PyObject* real_res;
 
 		if (*type == _C_VOID && have_output == 1) {

Modules/objc/formal-protocol.m

 	char* name;
 	PyObject* supers;
 	PyObject* selectors;
-	int i, len;
-	int numInstance = 0;
-	int numClass = 0;
+	Py_ssize_t i, len;
+	Py_ssize_t numInstance = 0;
+	Py_ssize_t numClass = 0;
 	struct Protocol_struct* theProtocol = NULL;
 	struct objc_method_description* c;
 

Modules/objc/function.m

 func_call(PyObject* s, PyObject* args, PyObject* kwds)
 {
 	func_object* self = (func_object*)s;
-	int byref_in_count;
-	int byref_out_count;
-	int plain_count;
-	int argbuf_len;
+	Py_ssize_t byref_in_count;
+	Py_ssize_t byref_out_count;
+	Py_ssize_t plain_count;
+	Py_ssize_t argbuf_len;
 	int r;
 
 	unsigned char* argbuf;
 
 	if (self->methinfo->nargs >= 63) {
 		PyErr_Format(PyObjCExc_Error,
-			"wrapping a function with %d arguments, at most 64 "
+			"wrapping a function with %"PY_FORMAT_SIZE_T"d arguments, at most 64 "
 			"are supported", self->methinfo->nargs);
 		return NULL;
 	}
 	}
 
 	if (PyTuple_Size(args) != (plain_count + byref_in_count)) {
-		PyErr_Format(PyExc_TypeError, "Need %d arguments, got %d",
+		PyErr_Format(PyExc_TypeError, "Need %"PY_FORMAT_SIZE_T"d arguments, got %"PY_FORMAT_SIZE_T"d",
 			plain_count + byref_in_count, PyTuple_Size(args));
 		return NULL;
 	}
 	0,					/* tp_itemsize */
   
 	/* methods */
-	(destructor)func_dealloc,		/* tp_dealloc */
+	func_dealloc,				/* tp_dealloc */
 	0,					/* tp_print */
 	0,					/* tp_getattr */
 	0,					/* tp_setattr */

Modules/objc/informal-protocol.m

 	 * For some reason this code causes a crash, while it should
 	 * be the reverse of the code in proto_new.
 	 */
-	int len = PyTuple_Size(self->selectors);
-	int i;
+	Py_ssize_t len = PyTuple_Size(self->selectors);
+	Py_ssize_t i;
 
 	for (i = 0; i < len; i++) {
 		PyObjCSelector* tmp =
 	PyObjCInformalProtocol* result;
 	PyObject* name;
 	PyObject* selectors;
-	int       i, len;
+	Py_ssize_t       i, len;
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO:informal_protocol",
 			keywords, &name, &selectors)) { 
 		if (!PyObjCSelector_Check(
 				PyTuple_GET_ITEM(selectors, i))) {
 			PyErr_Format(PyExc_TypeError, 
-				"Item %d is not a selector", i);
+				"Item %"PY_FORMAT_SIZE_T"d is not a selector", i);
 			Py_DECREF(result);
 			return NULL;
 		}
 PyObjCInformalProtocol_FindSelector(PyObject* obj, SEL selector, int isClassMethod)
 {
 	PyObjCInformalProtocol* self = (PyObjCInformalProtocol*)obj;	
-	int i, len;
+	Py_ssize_t i, len;
 	PyObject* cur;
 	PyObject* seq;
 
 {
 	PyObject* values;
 	PyObject* seq;
-	int       i, len;
+	Py_ssize_t       i, len;
 
 	values = PyDict_Values(clsdict);
 	if (values == NULL) {
 	PyObject* obj, char* name, PyObject* super_class, PyObject* clsdict)
 {
 	PyObjCInformalProtocol* self = (PyObjCInformalProtocol*)obj;	
-	int i, len;
+	Py_ssize_t i, len;
 	PyObject* cur;
 	PyObject* seq;
 

Modules/objc/instance-var.m

  */
 
 static void
-ivar_dealloc(PyObjCInstanceVariable* ivar)
+ivar_dealloc(PyObject* _ivar)
 {
+	PyObjCInstanceVariable* ivar = (PyObjCInstanceVariable*)_ivar;
 	PyMem_Free(ivar->name);
 	PyMem_Free(ivar->type);
 	ivar->ob_type->tp_free((PyObject*)ivar);
 }
 
 static PyObject*
-ivar_repr(PyObjCInstanceVariable* self)
+ivar_repr(PyObject* _self)
 {
+	PyObjCInstanceVariable* self = (PyObjCInstanceVariable*)_self;
 	if (self->isOutlet) {
 		return PyString_FromFormat("<IBOutlet %s>", self->name);
 	} else {
 }
 
 static PyObject*
-ivar_descr_get(PyObjCInstanceVariable* self, PyObject* obj, PyObject* type __attribute__((__unused__)))
+ivar_descr_get(PyObject* _self, PyObject* obj, PyObject* type __attribute__((__unused__)))
 {
+	PyObjCInstanceVariable* self = (PyObjCInstanceVariable*)_self;
 	PyObjCRT_Ivar_t var;
 	id   objc;
 	PyObject* res;
 }
 
 static int
-ivar_descr_set(PyObjCInstanceVariable* self, PyObject* obj, PyObject* value)
+ivar_descr_set(PyObject* _self, PyObject* obj, PyObject* value)
 {
+	PyObjCInstanceVariable* self = (PyObjCInstanceVariable*)_self;
 	volatile PyObjCRT_Ivar_t var;
 	id   objc;
-	int  size;
+	Py_ssize_t  size;
 	int res;
 
 	if (value == NULL && !self->isSlot) {
 }
 
 static int
-ivar_init(PyObjCInstanceVariable* self, PyObject* args, PyObject* kwds)
+ivar_init(PyObject* _self, PyObject* args, PyObject* kwds)
 {
 static  char* keywords[] = { "name", "type", "isOutlet", NULL };
+	PyObjCInstanceVariable* self = (PyObjCInstanceVariable*)_self;
 	char* name = NULL;
 	char* type = @encode(id);
 	PyObject* isOutletObj = NULL;
 		return -1;
 	}
 	self->type = PyObjCUtil_Strdup(type);
-    if(self->type == NULL) {
+	if(self->type == NULL) {
 		PyMem_Free(self->name);
-        return -1;
-    }
+		return -1;
+	}
 	if (isOutletObj) {
 		self->isOutlet = PyObject_IsTrue(isOutletObj);
 	} else {
 	"ivar",                             
 	sizeof(PyObjCInstanceVariable),                       
 	0,                                           
-	(destructor)ivar_dealloc,               /* tp_dealloc */
+	ivar_dealloc,               		/* tp_dealloc */
 	0,                                      /* tp_print */
 	0,                                      /* tp_getattr */
 	0,                                      /* tp_setattr */
 	0,                                      /* tp_compare */
-	(reprfunc)ivar_repr,                    /* tp_repr */
+	ivar_repr,                    		/* tp_repr */
 	0,                                      /* tp_as_number */
 	0,                                      /* tp_as_sequence */
 	0,                                      /* tp_as_mapping */
 	0,                                      /* tp_getset */
 	0,                                      /* tp_base */
 	0,                                      /* tp_dict */
-	(descrgetfunc)ivar_descr_get,           /* tp_descr_get */
-	(descrsetfunc)ivar_descr_set,           /* tp_descr_set */
+	ivar_descr_get,           		/* tp_descr_get */
+	ivar_descr_set,           		/* tp_descr_set */
 	0,                                      /* tp_dictoffset */
-	(initproc)ivar_init,                    /* tp_init */
+	ivar_init,                    		/* tp_init */
 	PyType_GenericAlloc,                    /* tp_alloc */
 	PyType_GenericNew,                      /* tp_new */
 	0,                                      /* tp_free */

Modules/objc/ivar-accessor.m

 	}
 
 	while (cur != nil) {
-		int i, len;
+		Py_ssize_t i, len;
 		Ivar ivar;
 		PyObject* v;
 		int r;

Modules/objc/libffi_support.m

 
 #endif
 
-static int align(int offset, int alignment)
+static Py_ssize_t align(Py_ssize_t offset, Py_ssize_t alignment)
 {
-	int rest = offset % alignment;
+	Py_ssize_t rest = offset % alignment;
 	if (rest == 0) return offset;
 	return offset + (alignment - rest);
 }
 
-static int
-count_struct(const char* argtype)
+static Py_ssize_t
+num_struct_fields(const char* argtype)
 {
-	int res = 0;
+	Py_ssize_t res = 0;
 
 	if (*argtype != _C_STRUCT_B) return -1;
 	while (*argtype != _C_STRUCT_E && *argtype != '=') argtype++;
 static  PyObject* array_types = NULL; /* XXX: Use NSMap  */
 	PyObject* v;
 	ffi_type* type;
-	int       field_count;
-	int        i;
+	Py_ssize_t field_count;
+	Py_ssize_t i;
 	const char* key = argtype;
 
 	if (array_types == NULL) {
 	static  PyObject* struct_types = NULL; /* XXX: Use NSMap  */
 	PyObject* v;
 	ffi_type* type;
-	int       field_count;
-	const char*     curtype;
+	Py_ssize_t field_count;
+	const char* curtype;
 
 	if (struct_types == NULL) {
 		struct_types = PyDict_New();
 	/* We don't have a type description yet, dynamicly 
 	 * create it.
 	 */
-	field_count = count_struct(argtype);
+	field_count = num_struct_fields(argtype);
 	if (field_count == -1) {
 		PyErr_Format(PyObjCExc_InternalError,
 			"Cannot determine layout of %s", argtype);
 }
 #endif
 
-#else
+#else /* GNUstep */
 
 static inline ffi_type*
 arg_signature_to_ffi_type(const char* argtype)
 	}
 }
 
-#endif
+#endif /* GNUstep */
 
 /* This function decodes its arguments into Python values, then
  * calls the python method and finally encodes the return value
 	PyObject* callable = userdata->callable;
 	PyObjCMethodSignature* methinfo = userdata->methinfo;
 	int isAlloc = 0;
-	int                argOffset;
-	int                i;
+	Py_ssize_t         argOffset;
+	Py_ssize_t         i;
 	PyObject*          arglist;
 	PyObject*          res;
 	PyObject*          v;
 		/* We have some output parameters, locate them and encode
 		 * their values
 		 */
-		int idx;
+		Py_ssize_t idx;
 		PyObject* real_res;
 
 		if (*rettype == _C_VOID && have_output == 1) {
  * bufferspace that will be allocated just before the argument array
  */
 int PyObjCFFI_CountArguments(
-		PyObjCMethodSignature* methinfo, int argOffset,
-		int* byref_in_count, 
-		int* byref_out_count,
-		int* plain_count,
-		int* argbuf_len)
+		PyObjCMethodSignature* methinfo, Py_ssize_t argOffset,
+		Py_ssize_t* byref_in_count, 
+		Py_ssize_t* byref_out_count,
+		Py_ssize_t* plain_count,
+		Py_ssize_t* argbuf_len)
 {
-	int i;
-	int itemAlign;
-	int itemSize;
+	Py_ssize_t i;
+	Py_ssize_t itemAlign;
+	Py_ssize_t itemSize;
 
 	*byref_in_count = *byref_out_count = *plain_count = 0;
 	
 }
 
 int PyObjCFFI_ParseArguments(
-		PyObjCMethodSignature* methinfo, int argOffset,
+		PyObjCMethodSignature* methinfo, Py_ssize_t argOffset,
 		PyObject* args,
-		int argbuf_cur, unsigned char* argbuf,
+		Py_ssize_t argbuf_cur, unsigned char* argbuf,
 		void** byref,
 		ffi_type** arglist, void** values)
 {
-	int py_arg = 0;
-	int i;
+	Py_ssize_t py_arg = 0;
+	Py_ssize_t i;
 	void* arg;
 
 	for (i = argOffset; i < methinfo->nargs; i++) {
 
 		if (argtype[0] == _C_OUT && argtype[1] == _C_PTR) {
 			/* Just allocate room in argbuf and set that*/
-			int sz;
+			Py_ssize_t sz;
 
 			argbuf_cur = align(argbuf_cur, 
 				PyObjCRT_AlignOfType(argtype+2));
 			switch (*argtype) {
 			case _C_STRUCT_B: case _C_ARY_B: case _C_UNION_B:
 				/* Allocate space and encode */
-				{
-					argbuf_cur = align(argbuf_cur, 
-						PyObjCRT_AlignOfType(argtype));
-					arg = argbuf + argbuf_cur;
-					argbuf_cur += PyObjCRT_SizeOfType(argtype);
-					byref[i] = arg;
-	  				error = depythonify_c_value (
-						argtype, 
-						argument, 
-						arg);
+				argbuf_cur = align(argbuf_cur, 
+					PyObjCRT_AlignOfType(argtype));
+				arg = argbuf + argbuf_cur;
+				argbuf_cur += PyObjCRT_SizeOfType(argtype);
+				byref[i] = arg;
+				error = depythonify_c_value (
+					argtype, 
+					argument, 
+					arg);
 
-
-					arglist[i] = 
-						signature_to_ffi_type(argtype);
-					values[i] = arg;
-				} 
+				arglist[i] = signature_to_ffi_type(argtype);
+				values[i] = arg;
 				break;
 			case _C_INOUT:
 			case _C_IN:
 				}
 				break;
 			default:
-				{
 				argbuf_cur = align(argbuf_cur, PyObjCRT_AlignOfType(argtype));
 				arg = argbuf + argbuf_cur;
 				argbuf_cur += PyObjCRT_SizeOfType(argtype);
 
 				arglist[i] = signature_to_ffi_type(argtype);
 				values[i] = arg;
-				}
 			}
 
 			if (error == -1) {
 
 PyObject* 
 PyObjCFFI_BuildResult(
-	PyObjCMethodSignature* methinfo, int argOffset,
-	void* pRetval, void** byref, int byref_out_count,
+	PyObjCMethodSignature* methinfo, Py_ssize_t argOffset,
+	void* pRetval, void** byref, Py_ssize_t byref_out_count,
 	PyObject* self, int flags)
 /* XXX: Need to refactor to deal with 'self' */
 {
 	PyObject* result = NULL;
 	int py_arg;
 	void* arg;
-	int i;
+	Py_ssize_t i;
 
 	if ( (*methinfo->rettype != _C_VOID) /* && ([methinfo isOneway] == NO) */ ) {
 		objc_result = pythonify_c_return_value (methinfo->rettype, pRetval);
 PyObject *
 PyObjCFFI_Caller(PyObject *aMeth, PyObject* self, PyObject *args)
 {
-	int            argbuf_len = 0;
-	int            argbuf_cur = 0;
+	Py_ssize_t argbuf_len = 0;
+	Py_ssize_t argbuf_cur = 0;
 	unsigned char* volatile argbuf = NULL;
-	int            byref_in_count = 0;
-	int            byref_out_count = 0;
-	int            plain_count = 0;
+	Py_ssize_t byref_in_count = 0;
+	Py_ssize_t byref_out_count = 0;
+	Py_ssize_t plain_count = 0;
 	void** volatile byref = NULL; /* offset for arguments in argbuf */
 	const char* 	  rettype;
 	PyObjCMethodSignature*  volatile methinfo;
 	void*             values[64];
 	int               r;
 	void*		  msgResult;
-	int               resultSize;
-	volatile int      arglistOffset;
+	Py_ssize_t        resultSize;
+	volatile Py_ssize_t arglistOffset;
 	volatile int      flags;
 	SEL		  theSel;
 
 
 	if (methinfo->nargs >= 63) {
 		 PyErr_Format(PyObjCExc_Error,
-			 "wrapping a function with %d arguments, at most 64 "
+			 "wrapping a function with %"PY_FORMAT_SIZE_T"d arguments, at most 64 "
 			 "are supported", methinfo->nargs);
 		 return NULL;
 	}
 	 * input argument that is passed by reference.
 	 */
 	if (PyTuple_Size(args) != (plain_count + byref_in_count)) {
-		PyErr_Format(PyExc_TypeError, "Need %d arguments, got %d",
+		PyErr_Format(PyExc_TypeError, "Need %"PY_FORMAT_SIZE_T"d arguments, got %"PY_FORMAT_SIZE_T"d",
 			plain_count + byref_in_count, PyTuple_Size(args));
 		goto error_cleanup;
 	}
  * as an initial argument), and is set to 0 otherwise.
  */
 ffi_cif*
-PyObjCFFI_CIFForSignature(PyObjCMethodSignature* methinfo, int* pArgOffset)
+PyObjCFFI_CIFForSignature(PyObjCMethodSignature* methinfo, Py_ssize_t* pArgOffset)
 {
 	ffi_cif* cif;
 	ffi_type** cl_arg_types;
 	ffi_type* cl_ret_type;
 	const char* rettype;
-	int argOffset;
+	Py_ssize_t argOffset;
 	ffi_status rv;
 	int i;
 
 	ffi_cif *cif;
 	ffi_closure *cl;
 	ffi_status rv;
-	int argOffset;
+	Py_ssize_t argOffset;
 
 	cif = PyObjCFFI_CIFForSignature(methinfo, &argOffset);
 	if (cif == NULL) {

Modules/objc/method-accessor.m

 	volatile int   unbound_instance_method = 0;
 	char* flattened;
 
-
 	if (name[0] == '_' && name[1] == '_') {
 		/*
 		 * FIXME: Some classes (NSFault, NSFinalProxy) crash hard
 } ObjCMethodAccessor;
 
 static void
-obj_dealloc(ObjCMethodAccessor* self)
+obj_dealloc(PyObject* _self)
 {
+	ObjCMethodAccessor* self = (ObjCMethodAccessor*)_self;
 	Py_XDECREF(self->base);
 	self->base = NULL;
 
 }
 
 static PyObject*
-obj_getattro(ObjCMethodAccessor* self, PyObject* name)
+obj_getattro(PyObject* _self, PyObject* name)
 {
+	ObjCMethodAccessor* self = (ObjCMethodAccessor*)_self;
 	PyObject* result;
 	int	  class_method;
 
 }
 
 static PyObject*
-obj_repr(ObjCMethodAccessor* self)
+obj_repr(PyObject* _self)
 {
+	ObjCMethodAccessor* self = (ObjCMethodAccessor*)_self;
 	PyObject* rval;
 	PyObject* repr;
 
 	sizeof(ObjCMethodAccessor),		/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */
-	(destructor)obj_dealloc,	 	/* tp_dealloc */
+	obj_dealloc,	 			/* tp_dealloc */
 	0,					/* tp_print */
 	0,					/* tp_getattr */
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
-	(reprfunc)obj_repr,			/* tp_repr */
+	obj_repr,				/* tp_repr */
 	0,					/* tp_as_number */
 	0,					/* tp_as_sequence */
 	0,		       			/* tp_as_mapping */
 	0,					/* tp_hash */
 	0,					/* tp_call */
 	0,					/* tp_str */
-	(getattrofunc)obj_getattro,		/* tp_getattro */
+	obj_getattro,				/* tp_getattro */
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT,			/* tp_flags */

Modules/objc/method-imp.m

 
 
 static PyObject*
-imp_call(PyObjCIMPObject* self, PyObject* args)
+imp_call(PyObject* _self, PyObject* args, PyObject* kwds)
 {
+	PyObjCIMPObject* self = (PyObjCIMPObject*)_self;
 	PyObject* pyself;
 	PyObjC_CallFunc execute = NULL;
 	PyObject* res;
 	PyObject* pyres;
-	int       argslen;
+	Py_ssize_t argslen;
 	PyObject* arglist;
-	int       i;
+	Py_ssize_t i;
+
+	if (kwds != NULL && PyObject_Size(kwds) != 0) {
+		PyErr_SetString(PyExc_TypeError,
+		    "Objective-C selectorrs don't support keyword arguments");
+		return NULL;
+	}
 
 	argslen = PyTuple_Size(args);
 	if (argslen < 1) {
 }
 
 static PyObject* 
-imp_repr(PyObjCIMPObject* self)
+imp_repr(PyObject* _self)
 {
+	PyObjCIMPObject* self = (PyObjCIMPObject*)_self;
 	return PyString_FromFormat("<IMP %s at %p for %p>",
 		PyObjCRT_SELName(self->selector),
 		self, self->imp);
 }
 
 static void
-imp_dealloc(PyObjCIMPObject* self)
+imp_dealloc(PyObject* _self)
 {
+	PyObjCIMPObject* self = (PyObjCIMPObject*)_self;
 	PyObjCMethodSignature_Free(self->signature);
 	PyObject_Free(self);
 }
 
 PyDoc_STRVAR(imp_signature_doc, "Objective-C signature for the IMP");
 static PyObject*
-imp_signature(PyObjCIMPObject* self, void* closure __attribute__((__unused__)))
+imp_signature(PyObject* _self, void* closure __attribute__((__unused__)))
 {
+	PyObjCIMPObject* self = (PyObjCIMPObject*)_self;
 	if (self->signature) {
 		return PyString_FromString(self->signature->signature);
 	} else {
 
 PyDoc_STRVAR(imp_selector_doc, "Objective-C name for the IMP");
 static PyObject*
-imp_selector(PyObjCIMPObject* self, void* closure __attribute__((__unused__)))
+imp_selector(PyObject* _self, void* closure __attribute__((__unused__)))
 {
+	PyObjCIMPObject* self = (PyObjCIMPObject*)_self;
 	return PyString_FromString(PyObjCRT_SELName(self->selector));
 }
 
 PyDoc_STRVAR(imp_class_method_doc, 
 	"True if this is a class method, False otherwise");
 static PyObject*
-imp_class_method(PyObjCIMPObject* self, void* closure __attribute__((__unused__)))
+imp_class_method(PyObject* _self, void* closure __attribute__((__unused__)))
 {
+	PyObjCIMPObject* self = (PyObjCIMPObject*)_self;
 	return PyBool_FromLong(0 != (self->flags & PyObjCSelector_kCLASS_METHOD));
 }
 
 "NOTE: This field is used by the implementation to adjust reference counts."
 );
 static PyObject*
-imp_donates_ref(PyObjCIMPObject* self, void* closure __attribute__((__unused__)))
+imp_donates_ref(PyObject* _self, void* closure __attribute__((__unused__)))
 {
+	PyObjCIMPObject* self = (PyObjCIMPObject*)_self;
 	return PyBool_FromLong(0 != (self->flags & PyObjCSelector_kDONATE_REF));
 }
 
 "NOTE: This field is used by the implementation."
 );
 static PyObject*
-imp_is_alloc(PyObjCIMPObject* self, void* closure __attribute__((__unused__)))
+imp_is_alloc(PyObject* _self, void* closure __attribute__((__unused__)))
 {
+	PyObjCIMPObject* self = (PyObjCIMPObject*)_self;
 	return PyBool_FromLong(0 != (self->flags & PyObjCSelector_kRETURNS_UNINITIALIZED));
 }
 
 static PyGetSetDef imp_getset[] = {
 	{
 		"isAlloc",
-		(getter)imp_is_alloc,
+		imp_is_alloc,
 		0,
 		imp_is_alloc_doc,
 		0
 	},
 	{
 		"doesDonateReference",
-		(getter)imp_donates_ref,
+		imp_donates_ref,
 		0,
 		imp_donates_ref_doc,
 		0
 	},
 	{
 		"isClassMethod",
-		(getter)imp_class_method,
+		imp_class_method,
 		0,
 		imp_class_method_doc,
 		0
 	},
 	{ 
 		"signature", 
-		(getter)imp_signature, 
+		imp_signature, 
 		0,
 		imp_signature_doc, 
 		0
 	},
 	{ 
 		"selector",  
-		(getter)imp_selector, 
+		imp_selector, 
 		0, 
 		imp_selector_doc,
 		0
 	},
 	{ 
 		"__name__",  
-		(getter)imp_selector, 
+		imp_selector, 
 		0, 
 		imp_selector_doc,
 		0
 	sizeof(PyObjCIMPObject),		/* tp_basicsize */
 	0,					/* tp_itemsize */
 	/* methods */
-	(destructor)imp_dealloc,		/* tp_dealloc */
+	imp_dealloc,				/* tp_dealloc */
 	0,					/* tp_print */
 	0,					/* tp_getattr */
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
-	(reprfunc)imp_repr,			/* tp_repr */
+	imp_repr,				/* tp_repr */
 	0,					/* tp_as_number */
 	0,					/* tp_as_sequence */
 	0,		       			/* tp_as_mapping */
 	0,					/* tp_hash */
-	(ternaryfunc)imp_call,			/* tp_call */
+	imp_call,				/* tp_call */
 	0,					/* tp_str */
 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,					/* tp_setattro */
 {
 	int r;
 
-
 	r = PyObjC_RegisterMethodMapping(
 			nil, 
 			@selector(instanceMethodForSelector:),

Modules/objc/method-signature.m

 PyObjCMethodSignature* PyObjCMethodSignature_FromSignature(
 		const char* signature)
 {
-	int nargs;
+	Py_ssize_t nargs;
 	const char* cur;
 	PyObjCMethodSignature* retval;
 
-
 	/* Skip return-type */
 	cur = PyObjCRT_SkipTypeSpec(signature);
 
 		retval->rettype = cur;
 	}
 
-	
 	cur = PyObjCRT_SkipTypeSpec(retval->signature);
 	nargs = 0;
 	for (;cur && *cur; cur = PyObjCRT_SkipTypeSpec(cur)) {

Modules/objc/module.m

 	const char *type = "@";
 	PyObject *rval;
 	void *datum;
-	int size;
+	Py_ssize_t size;
 	PyObject *o;
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|s:repythonify",
 		keywords, &o, &type)) {
 	PyObject* classObject = NULL;
 	PyObject* methodsArray = NULL;
 	Class targetClass;
-	int methodCount;
-	int methodIndex;
+	Py_ssize_t methodCount;
+	Py_ssize_t methodIndex;
 	int r;
 	struct objc_method_list *methodsToAdd;
 	struct objc_method_list *classMethodsToAdd;
 allocateBuffer(PyObject* self __attribute__((__unused__)), PyObject* args, PyObject* kwds)
 {
 	static	char* keywords[] = { "length", 0 };
-	int length;
+	Py_ssize_t length;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", keywords, &length)) {
+	if (!PyArg_ParseTupleAndKeywords(args, kwds, Py_ARG_SIZE_T, 
+				keywords, &length)) {
 		return NULL;
 	}
 
 	PyObject* module_name;
 	PyObject* module_globals;
 	PyObject* class_list;
-	int       len, i;
+	Py_ssize_t len, i;
 	PyObject* module_key = NULL;
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, 
 	char* docstr = NULL;
 	PyObject* retval;
 	char** fieldnames = NULL;
-	int i;
+	Py_ssize_t i;
 
 	if (!PyArg_ParseTupleAndKeywords(args, kwds, "ssO|s", keywords, 
 				&name, &typestr, &pyfieldnames, &docstr)) {

Modules/objc/objc-NULL.m

 	0,					/* tp_getattr */
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
-	(reprfunc)obj_repr,			/* tp_repr */
+	obj_repr,				/* tp_repr */
 	0,					/* tp_as_number */
 	0,					/* tp_as_sequence */
 	0,		       			/* tp_as_mapping */

Modules/objc/objc-class.m

  */
 
 static
-int nsdata_getreadbuffer(PyObject *pyself, int segment __attribute__((unused)), void **ptrptr) {
+Py_ssize_t nsdata_getreadbuffer(PyObject *pyself, Py_ssize_t segment __attribute__((unused)), void **ptrptr) {
 	NSData *self = (NSData *)PyObjCObject_GetObject(pyself);
 	assert(segment == 0);
 	if (ptrptr != NULL) {
 }
 
 static
-int nsmutabledata_getwritebuffer(PyObject *pyself, int segment __attribute__((unused)), void **ptrptr) {
+Py_ssize_t nsmutabledata_getwritebuffer(PyObject *pyself, Py_ssize_t segment __attribute__((unused)), void **ptrptr) {
 	NSMutableData *self = (NSMutableData *)PyObjCObject_GetObject(pyself);
 	assert(segment == 0);
 	if (ptrptr != NULL) {
 }
 
 static
-int nsdata_getsegcount(PyObject *pyself, int *lenp) {
+Py_ssize_t nsdata_getsegcount(PyObject *pyself, Py_ssize_t *lenp) {
 	NSData *self = (NSData *)PyObjCObject_GetObject(pyself);
 	if (lenp != NULL) {
-		*lenp = (int)[self length];
+		*lenp = (Py_ssize_t)[self length];
 	}
 	return 1;
 }
 
 static PyBufferProcs nsdata_as_buffer = {
-	(getreadbufferproc)&nsdata_getreadbuffer,
+	nsdata_getreadbuffer,
 	NULL,
-	(getsegcountproc)&nsdata_getsegcount,
+	nsdata_getsegcount,
 	NULL
 };
 
 static PyBufferProcs nsmutabledata_as_buffer = {
-	(getreadbufferproc)&nsdata_getreadbuffer,
-	(getwritebufferproc)&nsmutabledata_getwritebuffer,
-	(getsegcountproc)&nsdata_getsegcount,
+	nsdata_getreadbuffer,
+	nsmutabledata_getwritebuffer,
+	nsdata_getsegcount,
 	NULL
 };
 
 	PyObject* res;
 	PyObject* k;
 	PyObject* v;
-	int       i;
-	int       len;
+	Py_ssize_t i;
+	Py_ssize_t len;
 	Class      objc_class = NULL;
 	Class	   super_class = NULL;
 	PyObject*  py_super_class = NULL;
 		return NULL;
 	}
 
-	len  = PyTuple_Size(bases);
+	len = PyTuple_Size(bases);
 	if (len < 1) {
 		PyErr_SetString(PyExc_TypeError, "'bases' must not be empty");
 		return NULL;
 		if (protocols == NULL) return NULL;
 	} else {
 		PyObject* seq;
-		int protocols_len;
+		Py_ssize_t protocols_len;
 
 		seq = PySequence_Fast(protocols, 
 			"__pyobjc_protocols__ not a sequence?");
 		return NULL;
 	}
 
-
-
 	/* call super-class implementation */
 	args = Py_BuildValue("(sOO)", name, real_bases, dict);
 	res =  PyType_Type.tp_new(type, args, NULL);
 static PyGetSetDef class_getset[] = {
 	{
 		"pyobjc_classMethods",
-		(getter)cls_get_classMethods,
+		cls_get_classMethods,
 		NULL,
 		cls_get_classMethods_doc,
 		0
 	},
 	{
 		"pyobjc_instanceMethods",
-		(getter)cls_get_instanceMethods,
+		cls_get_instanceMethods,
 		NULL,
 		cls_get_instanceMethods_doc,
 		0
 		 * might change due to posing.
 		 */
 		"__name__",
-		(getter)cls_get__name__,
+		cls_get__name__,
 		NULL,
 		NULL,
 		0
 	iterator = 0;
 	mlist = PyObjCRT_NextMethodList(objc_class, &iterator);
 	while (mlist != NULL) {
-		int i;
+		Py_ssize_t i;
 		PyObjCRT_Method_t meth;
 
 		for (i = 0; i < mlist->method_count; i++) {
 	iterator = 0;
 	mlist = PyObjCRT_NextMethodList(cls, &iterator);
 	while (mlist != NULL) {
-		int i;
+		Py_ssize_t i;
 		PyObjCRT_Method_t meth;
 
 		for (i = 0; i < mlist->method_count; i++) {
 	 * semantics.
 	 */
 	if (objc_class->ivars) {
-		int i;
+		Py_ssize_t i;
 		struct objc_ivar *var;
 		for (i = 0; i < objc_class->ivars->ivar_count; i++) {
 			var = objc_class->ivars->ivar_list + i;
 	PyObject*          attributes;
 	PyObject*          key;
 	PyObject*          v;
-	int                i;
-	int                len;
-
+	Py_ssize_t         i;
+	Py_ssize_t         len;
 
 	if (!PyObjCClass_Check(cls)) {
 		PyErr_Format(PyObjCExc_InternalError,
 	return 0;
 }
 
-int
+Py_ssize_t
 PyObjCClass_DictOffset(PyObject* cls)
 {
 	return ((PyObjCClassObject*)cls)->dictoffset;
 	PyObject* dict;
 	PyObject* keys;
 	PyObject* v;
-	int       i, len;
+	Py_ssize_t i, len;
 
 	if (PyObjC_ClassExtender == NULL || cls == NULL) return 0;
 

Modules/objc/objc-object.m

 }
 
 static PyObject*
-object_repr(PyObjCObject* self)
+object_repr(PyObject* _self)
 {
+	PyObjCObject* self = (PyObjCObject*)_self;
 	PyObject* res;
 
 	if ((self->flags & PyObjCObject_kUNINITIALIZED) == 0 && !PyObjCObject_IsClassic(self)) {
 static inline PyObject*
 _type_lookup(PyTypeObject* tp, PyObject* name)
 {
-	int i, n;
+	Py_ssize_t i, n;
 	PyObject *mro, *base, *dict;
 	PyObject *descr = NULL;
 	PyObject* protDict;
 
 static PyObject** _get_dictptr(PyObject* obj)
 {
-	int dictoffset;
+	Py_ssize_t dictoffset;
 	id obj_object;
 	dictoffset = PyObjCClass_DictOffset((PyObject*)obj->ob_type);
 	if (dictoffset == 0) return NULL;
 	PyObject *descr = NULL;
 	PyObject *res = NULL;
 	descrgetfunc f;
-	PyObject **dictptr;
-	char*      namestr;
+	PyObject** dictptr;
+	char* namestr;
 	id obj_inst;
 
 	if (!PyString_Check(name)){
 {
 	id obj_object;
 	PyObject* ret;
+
 	obj_object = PyObjCObject_GetObject(self);
 	assert(obj_object != nil);
 	ret = PyObjCClass_New(GETISA(obj_object));
 "can be used to force access to an instance method."
 );
 static PyObject*
-obj_get_instanceMethods(PyObjCObject* self, void* closure __attribute__((__unused__)))
+obj_get_instanceMethods(PyObject* _self, void* closure __attribute__((__unused__)))
 {
+	PyObjCObject* self = (PyObjCObject*)_self;
 	return PyObjCMethodAccessor_New((PyObject*)self, 0);
 }
 
 static PyGetSetDef obj_getset[] = {
 	{
 		"pyobjc_ISA",
-		(getter)objc_get_real_class,
+		objc_get_real_class,
 		NULL,
 		objc_get_real_class_doc,
 		0
 	},
 	{
 		"pyobjc_instanceMethods",
-		(getter)obj_get_instanceMethods,
+		obj_get_instanceMethods,
 		NULL,
 		obj_get_instanceMethods_doc,
 		0
 	0,					/* tp_getattr */
 	0,					/* tp_setattr */
 	0,					/* tp_compare */
-	(reprfunc)object_repr,			/* tp_repr */
+	object_repr,				/* tp_repr */
 	0,					/* tp_as_number */
 	0,					/* tp_as_sequence */
 	0,		       			/* tp_as_mapping */
 	(destructor)object_del			/* tp_del */
      },
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, /* as_number */
+       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
+#if PY_VERSION_HEX >= 0x02050000
+       , 0
+#endif
+     }, /* as_number */
      { 0, 0, 0 },			/* as_mapping */
      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },	/* as_sequence */
      { 0, 0, 0, 0 },			/* as_buffer */

Modules/objc/objc-runtime-apple.m

 	const char*name, 
 	Class superCls,
 	Class rootCls,
-	int ivarSize,
+	Py_ssize_t ivarSize,
 	struct objc_ivar_list* ivarList,
 	struct objc_protocol_list* protocolList
 )
 	}
 }
 
-struct objc_method_list *PyObjCRT_AllocMethodList(int numMethods)
+struct objc_method_list *PyObjCRT_AllocMethodList(Py_ssize_t numMethods)
 {
 	struct objc_method_list *mlist;
 
 	return mlist;
 }
 
-struct objc_protocol_list* PyObjCRT_AllocProtocolList(int numProtocols)
+struct objc_protocol_list* PyObjCRT_AllocProtocolList(Py_ssize_t numProtocols)
 {
 	struct objc_protocol_list *plist;
 

Modules/objc/objc_support.m

 @end
 
 #ifndef MAX
-static inline int
-MAX(int x, int y)
+static inline Py_ssize_t
+MAX(Py_ssize_t x, Py_ssize_t y)
 {
 	return x > y ? x : y;
 }
 #endif
 
-#if 0
-static inline int
-ROUND(int v, int a)
-{
-	return a * ((v+a-1)/a);
-}
-#else
-static inline int 
-ROUND(int v, int a)
+static inline Py_ssize_t 
+ROUND(Py_ssize_t v, Py_ssize_t a)
 {
 	if (v % a == 0) {
 		return v;
 		return v + a - (v % a);
 	}
 }
-#endif
 
 
 const char*
 */
 #ifdef MACOSX
 
-static inline int
+static inline Py_ssize_t
 PyObjC_EmbeddedAlignOfType (const char*  type)
 {
-	int align = PyObjCRT_AlignOfType(type);
+	Py_ssize_t align = PyObjCRT_AlignOfType(type);
 
 #ifdef __i386__
 	return align;
 
 #else
-	if (align < 4) {
+	if (align < 4 || align == 16) {
 		return align;
 	} else {
 		return 4;
 static inline int
 PyObjC_EmbeddedAlignOfType (const char*  type)
 {
-	int align =  PyObjCRT_AlignOfType(type);
+	Py_ssize_t align =  PyObjCRT_AlignOfType(type);
 
 	/* GNUstep/ix86 seems to behave like this: */
 	if (align < 4) {
 
 #endif
 
-int
+Py_ssize_t
 PyObjCRT_AlignOfType (const char *type)
 {
 	switch (*type) {
 		while(*type != _C_STRUCT_E && *type++ != '=') /* do nothing */;
 		if (*type != _C_STRUCT_E) {
 			int have_align = 0;
-			int align = 0;
+			Py_ssize_t align = 0;
 
 			while (type != NULL && *type != _C_STRUCT_E) {
 				if (*type == '"') {
 The aligned size if the size rounded up to the nearest alignment.
 */
 
-static int
+static Py_ssize_t
 PyObjCRT_AlignedSize (const char *type)
 {
-	int size = PyObjCRT_SizeOfType (type);
-	int align = PyObjCRT_AlignOfType (type);
+	Py_ssize_t size = PyObjCRT_SizeOfType (type);
+	Py_ssize_t align = PyObjCRT_AlignOfType (type);
 
 	if (size == -1 || align == -1) return -1;
-	return ROUND (size, align);
+	return ROUND(size, align);
 }
 
 /*
 return the size of an object specified by type 
 */
 
-int
+Py_ssize_t
 PyObjCRT_SizeOfType (const char *type)
 {
-	int itemSize;
+	Py_ssize_t itemSize;
 	switch (*type) {
 	case _C_VOID:    return 0;
 	case _C_ID:      return sizeof(id);
   
 	case _C_ARY_B:
 	{
-		int len = atoi(type+1);
-		int item_align;
+		Py_ssize_t len = atoi(type+1);
+		Py_ssize_t item_align;
 		while (isdigit(*++type))
 			;
 		item_align = PyObjCRT_AlignedSize(type);
 
 	case _C_STRUCT_B:
 	{
-		int acc_size = 0;
+		Py_ssize_t acc_size = 0;
 		int have_align =  0;
-		int align;
-		int max_align = 0;
+		Py_ssize_t align;
+		Py_ssize_t max_align = 0;
 
 		while (*type != _C_STRUCT_E && *type++ != '=')
 			; /* skip "<name>=" */
 
 	case _C_UNION_B:
 	{
-		int max_size = 0;
+		Py_ssize_t max_size = 0;
 		type++;
 		while (*type != _C_UNION_E) {
 			itemSize = PyObjCRT_SizeOfType (type);
 pythonify_c_array (const char *type, void *datum)
 {
 	PyObject *ret;
-	int nitems, itemidx, sizeofitem;
+	Py_ssize_t nitems, itemidx, sizeofitem;
 	unsigned char* curdatum;
 
 	nitems = atoi (type+1);
 {
 	PyObject *ret;
 	PyObject *converted;
-	unsigned int offset, itemidx;
+	Py_ssize_t offset, itemidx;
 	const char *item;
-	int have_align = 0, align;
+	int have_align = 0;
+	Py_ssize_t align;
 	int haveTuple;
 	const char* type_start = type;
 	const char* type_end = PyObjCRT_SkipTypeSpec(type);
 
 	const char* type_real_start = type;
-	int type_real_length = type_end - type_start;
+	Py_ssize_t type_real_length = type_end - type_start;
 
 	/* The compiler adds useless digits at the end of the signature */
 	while (type_end != type_start+1 && type_end[-1] != _C_STRUCT_E) {
 static int
 depythonify_c_array (const char *type, PyObject *arg, void *datum)
 {
-	int nitems, itemidx, sizeofitem;
+	Py_ssize_t nitems, itemidx, sizeofitem;
 	unsigned char* curdatum;
 	PyObject* seq;
 
 	if (nitems != PySequence_Fast_GET_SIZE(seq)) {
 		Py_DECREF(seq);
 		PyErr_Format(PyExc_ValueError,
-			"depythonifying array of %d items, got one of %d",
+			"depythonifying array of %"PY_FORMAT_SIZE_T"d items, got one of %"PY_FORMAT_SIZE_T"d",
 			nitems, PyTuple_Size(arg));
 		return -1;
 	}
 static int
 depythonify_c_struct(const char *types, PyObject *arg, void *datum)
 {
-	int nitems, offset, itemidx;
-	int have_align = 0, align;
+	Py_ssize_t nitems, offset, itemidx;
+	int have_align = 0;
+	Py_ssize_t align;
 	const char *type;
 	PyObject* seq;
 
 	if (nitems != PySequence_Fast_GET_SIZE(seq)) {
 		Py_DECREF(seq);
 		PyErr_Format(PyExc_ValueError,
-			"depythonifying struct of %d members, got tuple of %d",
+			"depythonifying struct of %"PY_FORMAT_SIZE_T"d members, got tuple of %"PY_FORMAT_SIZE_T"d",
 			nitems, PyTuple_Size (arg));
 		return -1;
 	}
   
 	case _C_UNION_B:
 	{
-		int size = PyObjCRT_SizeOfType (type);
+		Py_ssize_t size = PyObjCRT_SizeOfType (type);
 		if (size == -1) return NULL;
 		retobject = PyString_FromStringAndSize ((void*)datum, size);
 		break;
 }
 
 
-int PyObjCRT_SizeOfReturnType(const char* type)
+Py_ssize_t 
+PyObjCRT_SizeOfReturnType(const char* type)