Ronald Oussoren avatar Ronald Oussoren committed 5dd153a

* Enable PYOBJC_NEW_INITIALIZER_PATTERN code, it's much better then
the alternative

* Remove some #if-def-ed code

* Reintroduce PyMem_Malloc and friends, except in places where that would
not be safe

* Fix some minor memory management bugs

* Remove a speed-hack in class-list.m

Comments (0)

Files changed (20)

Modules/objc/ObjCPointer.m

 PyObjCPointer_dealloc (PyObjCPointer *self)
 {
 	Py_DECREF (self->type);
-	/*
-	self->ob_type->tp_free((PyObject*)self);
-	*/
 	PyObject_Free((PyObject*)self);
 }
 

Modules/objc/class-builder.m

 		void** args,
 		void* userarg);
 
-#if 0
-static void object_method_copyWithZone_(
-		ffi_cif* cif,
-		void* retval,
-		void** args,
-		void* userarg);
-
-struct copyWithZoneData {
-	Class 	  class;
-	PyObject* callable;
-};
-#endif
-
-
 /*
  * When we create a 'Class' we actually create the struct below. This allows
  * us to add some extra information to the class defintion.
 		goto error_cleanup;
 	}
 
-
 	if (!PyObjCClass_HasPythonImplementation(py_superclass)) {
 		/* 
 		 * This class has a super_class that is pure objective-C
 		PyObjCRT_ClassAddMethodList(
 			&(new_class->class), 
 			method_list);
+		method_list = NULL;
 	}
 	if (meta_method_list) {
 		PyObjCRT_ClassAddMethodList(
 			&(new_class->meta_class), 
 			meta_method_list);
+		meta_method_list = NULL;
 	}
 
 	Py_XDECREF(py_superclass);
 	int             i;
 	int 		len;
 	PyObjCMethodSignature* signature;
-	char		   argbuf[1024];
+	/*char		   argbuf[1024]; */
 	const char* 		type;
-	void* arg = NULL;
+	void* argbuf = NULL;
 	int  err;
 	int   arglen;
 	PyObject* pymeth;
 			return;
 		}
 
-		arg = alloca(arglen);
+		argbuf = PyMem_Malloc(arglen);
 		
 		[invocation getArgument:argbuf atIndex:i];
 
 			if (type[1] == _C_PTR) {
 				have_output ++;
 			}
+			PyMem_Free(argbuf); argbuf = NULL;
 			continue;
 		default:
 			v = pythonify_c_value(type, argbuf);
 		}
+		PyMem_Free(argbuf); argbuf = NULL;
 
 		if (v == NULL) {
 			Py_DECREF(arglist);
 
 	if (!have_output) {
 		if (*type  != _C_VOID && *type != _C_ONEWAY) {
-			arg = alloca(arglen+1);
+			argbuf = PyMem_Malloc(arglen+1);
 
-			err = depythonify_c_value(type, result, arg);
+			err = depythonify_c_value(type, result, argbuf);
 			if (err == -1) {
+				PyMem_Free(argbuf);
 				PyObjCMethodSignature_Free(signature);
 				PyObjCErr_ToObjCWithGILState(&state);
 				return;
 			}
 			if (isAlloc && *type == _C_ID) {
-				[(*(id*)arg) retain];
+				[(*(id*)argbuf) retain];
 			}
-			[invocation setReturnValue:arg];
+			[invocation setReturnValue:argbuf];
+			PyMem_Free(argbuf);
 		}
 		Py_DECREF(result);
 
 			idx = 1;
 			real_res = PyTuple_GET_ITEM(result, 0);
 
-			arg = alloca(arglen+1);
+			argbuf = PyMem_Malloc(arglen+1);
 
-			err = depythonify_c_value(type, real_res, arg);
+			err = depythonify_c_value(type, real_res, argbuf);
 			if (err == -1) {
 				PyObjCMethodSignature_Free(signature);
 				PyObjCErr_ToObjCWithGILState(&state);
+				PyMem_Free(argbuf);
 				return;
 			}
 			if (isAlloc && *type == _C_ID) {
-				[(*(id*)arg) retain];
+				[(*(id*)argbuf) retain];
 			}
-			[invocation setReturnValue:arg];
+			[invocation setReturnValue:argbuf];
+			PyMem_Free(argbuf);
 
 		} else {
 			if (!PyTuple_Check(result) 

Modules/objc/class-list.m

 	int		bufferLen = 0;
 	int		neededLen = 0;
 	int             i;
-	Class		initialBuffer[1024];
 
 	/*
 	 * objc_getClassList returns the number of classes known in the runtime,
 	 * fairly large static buffer, this way we need only one call unless
 	 * there is a very large number of classes.
 	 */
-	neededLen = objc_getClassList(initialBuffer, 1024);
-	if (neededLen >= 1024) {
-		while (bufferLen < neededLen) {
-			Class*    newBuffer;
-			bufferLen = neededLen;
+	neededLen = objc_getClassList(NULL, 0);
+	bufferLen = 0;
+	buffer = NULL;
 
-			/* Realloc(NULL, ...) might not work, call Malloc when
-			 * the buffer is NULL.
-			 */
-			if (buffer == NULL) {
-				newBuffer = malloc(sizeof(Class) * bufferLen);
-			} else {
-				newBuffer = realloc(buffer, 
-						sizeof(Class) * bufferLen);
-			}
-			if (newBuffer == NULL) {
-				PyErr_NoMemory();
-				goto error;
-			}
-			buffer = newBuffer; newBuffer = NULL;
-			neededLen = objc_getClassList(buffer, bufferLen);
+	while (bufferLen < neededLen) {
+		Class*    newBuffer;
+		bufferLen = neededLen;
+
+		/* Realloc(NULL, ...) might not work, call Malloc when
+		 * the buffer is NULL.
+		 */
+		if (buffer == NULL) {
+			newBuffer = PyMem_Malloc(
+				sizeof(Class) * bufferLen);
+		} else {
+			newBuffer = PyMem_Realloc(buffer, 
+				sizeof(Class) * bufferLen);
 		}
-		bufferLen = neededLen;
-	} else {
-		bufferLen = neededLen;
-		buffer = initialBuffer;
+		if (newBuffer == NULL) {
+			PyErr_NoMemory();
+			goto error;
+		}
+		buffer = newBuffer; newBuffer = NULL;
+		neededLen = objc_getClassList(buffer, bufferLen);
 	}
+	bufferLen = neededLen;
 
 	result = PyTuple_New(bufferLen);
 	if (result == NULL) {
 		PyTuple_SET_ITEM(result, i, pyclass);
 	}
 
-	if (buffer != initialBuffer) {
-		free(buffer); buffer = NULL;
-	}
+	PyMem_Free(buffer); buffer = NULL;
+
 	return result;
 
 error:
-	if (buffer && buffer != initialBuffer) {
-		free(buffer);
+	if (buffer != NULL) {
+		PyMem_Free(buffer);
 		buffer = NULL;
 	}
 	Py_XDECREF(result);

Modules/objc/instance-var.m

 static void
 ivar_dealloc(PyObjCInstanceVariable* ivar)
 {
-	free(ivar->name);
+	PyMem_Free(ivar->name);
 	ivar->ob_type->tp_free((PyObject*)ivar);
 }
 

Modules/objc/libffi_support.m

 static void
 free_type(void *obj)
 {
-	free(((ffi_type*)obj)->elements);
-	free(obj);
+	PyMem_Free(((ffi_type*)obj)->elements);
+	PyMem_Free(obj);
 }
 
 static ffi_type* signature_to_ffi_type(const char* argtype);
 	 */
 	field_count = atoi(argtype+1);
 			
-	type = malloc(sizeof(*type));
+	type = PyMem_Malloc(sizeof(*type));
 	if (type == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 	 * fine on MacOS X.
 	 */
 	type->type = FFI_TYPE_STRUCT;
-	type->elements = malloc((1+field_count) * sizeof(ffi_type*));
+	type->elements = PyMem_Malloc((1+field_count) * sizeof(ffi_type*));
 	if (type->elements == NULL) {
-		free(type);
+		PyMem_Free(type);
 		PyErr_NoMemory();
 		return NULL;
 	}
 		return NULL;
 	}
 			
-	type = malloc(sizeof(*type));
+	type = PyMem_Malloc(sizeof(*type));
 	if (type == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 	type->size = PyObjCRT_SizeOfType(argtype);
 	type->alignment = PyObjCRT_AlignOfType(argtype);
 	type->type = FFI_TYPE_STRUCT;
-	type->elements = malloc((1+field_count) * sizeof(ffi_type*));
+	type->elements = PyMem_Malloc((1+field_count) * sizeof(ffi_type*));
 	if (type->elements == NULL) {
-		free(type);
+		PyMem_Free(type);
 		PyErr_NoMemory();
 		return NULL;
 	}
 			type->elements[field_count] = 
 				signature_to_ffi_type(curtype);
 			if (type->elements[field_count] == NULL) {
-				free(type->elements);
+				PyMem_Free(type->elements);
 				return NULL;
 			}
 			field_count++;
 			curtype = PyObjCRT_SkipTypeSpec(curtype);
 			if (curtype == NULL) {
-				free(type->elements);
+				PyMem_Free(type->elements);
 				return NULL;
 			}
 		}
 		return NULL;
 	}
 
-	stubUserdata = malloc(sizeof(*stubUserdata));
+	stubUserdata = PyMem_Malloc(sizeof(*stubUserdata));
 	if (stubUserdata == NULL) {
 		PyObjCMethodSignature_Free(methinfo);
 		return NULL;
 		if (stubUserdata->callable) {
 			Py_DECREF(stubUserdata->callable);
 		}
-		free(stubUserdata);
+		PyMem_Free(stubUserdata);
 		return NULL;
 	}
 
 	}
 
 
-	argbuf = malloc(argbuf_len);
+	argbuf = PyMem_Malloc(argbuf_len); 
 	if (argbuf == 0) {
 		PyErr_NoMemory();
 		goto error_cleanup;
 	}
-	byref = malloc(sizeof(void*) * methinfo->nargs);
+	byref = PyMem_Malloc(sizeof(void*) * methinfo->nargs);
 	if (byref == NULL) {
 		PyErr_NoMemory();
 		goto error_cleanup;
 		}
 	}
 
-	free(argbuf);
+	PyMem_Free(argbuf);
 	argbuf = NULL;
-	free(byref);
+	PyMem_Free(byref);
 	byref = NULL;
 	methinfo = NULL;
 
 		result = NULL;
 	}
 	if (argbuf) {
-		free(argbuf);
+		PyMem_Free(argbuf);
 		argbuf = NULL;
 	}
 	if (byref) {
-		free(byref);
+		PyMem_Free(byref);
 		byref = NULL;
 	}
 	return NULL;
 	}
 
 	/* Build FFI argumentlist description */
-	cl_arg_types = malloc(sizeof(ffi_type*) * (argOffset+methinfo->nargs));
+	cl_arg_types = PyMem_Malloc(sizeof(ffi_type*) * (argOffset+methinfo->nargs));
 	if (cl_arg_types == NULL) {
-		free(cl_ret_type);
+		PyMem_Free(cl_ret_type);
 		PyErr_NoMemory();
 		return NULL;
 	}
 		cl_arg_types[i+argOffset] = arg_signature_to_ffi_type(
 			methinfo->argtype[i]);
 		if (cl_arg_types[i+argOffset] == NULL) {
-			free(cl_arg_types);
+			PyMem_Free(cl_arg_types);
 			return NULL;
 		}
 	}
 
 	/* Create the invocation description */
-	cif = malloc(sizeof(*cif));
+	cif = PyMem_Malloc(sizeof(*cif));
 	if (cif == NULL) {
-		free(cl_arg_types);
+		PyMem_Free(cl_arg_types);
 		PyErr_NoMemory();
 		return NULL;
 	}
 	rv = ffi_prep_cif(cif, FFI_DEFAULT_ABI, methinfo->nargs+argOffset, 
 		cl_ret_type, cl_arg_types);
 	if (rv != FFI_OK) {
-		free(cl_arg_types);
+		PyMem_Free(cl_arg_types);
 		PyErr_Format(PyExc_RuntimeError,
 			"Cannot create FFI CIF: %d", rv);
 		return NULL;
 void
 PyObjCFFI_FreeCIF(ffi_cif* cif)
 {
-	if (cif->arg_types) free(cif->arg_types);
-	free(cif);
+	if (cif->arg_types) PyMem_Free(cif->arg_types);
+	PyMem_Free(cif);
 }
 
 /*
 	}
 
 	/* And finally create the actual closure */
-	cl = malloc(sizeof(*cl));
+	cl = PyMem_Malloc(sizeof(*cl));
 	if (cl == NULL) {
 		PyObjCFFI_FreeCIF(cif);
 		PyErr_NoMemory();
 {
 	void* retval;
 	ffi_closure* cl;
-	
+
 	cl = (ffi_closure*)closure;
 	retval = cl->user_data;
 	PyObjCFFI_FreeCIF(cl->cif);
-	free(cl);
+	PyMem_Free(cl);
 
 	return retval;
 }

Modules/objc/method-signature.m

 		nargs++;
 	}
 
-	retval = malloc(sizeof(PyObjCMethodSignature) + sizeof(char*)*nargs);
+	retval = PyMem_Malloc(sizeof(PyObjCMethodSignature) + sizeof(char*)*nargs);
 	if (retval == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 	retval->retainCount = 1;
 	retval->signature = PyObjCUtil_Strdup(signature);
 	if (retval->signature == NULL) {
-		free(retval);
+		PyMem_Free(retval);
 		return NULL;
 	}
 
 {
 	if (--value->retainCount != 0) return;
 
-	free((char*)(value->signature));
-	free(value);
+	PyMem_Free((char*)(value->signature));
+	PyMem_Free(value);
 }
 
 

Modules/objc/module.m

 		/* install in methods to add */
 		objcMethod = &methodsToAdd->method_list[methodIndex];
 		objcMethod->method_name = PyObjCSelector_GetSelector(aMethod);
-		objcMethod->method_types = PyObjCUtil_Strdup(
+		objcMethod->method_types = strdup(
 				PyObjCSelector_Signature(aMethod));
 		if (objcMethod->method_types == NULL) {
 			goto cleanup_and_return_error;
 		return NULL;
 	}
 
+	module_key = PyString_FromString("__module__");
 	if (module_key == NULL) {
-		module_key = PyString_FromString("__module__");
-		if (module_key == NULL) {
-			Py_DECREF(class_list);
-			return NULL;
-		}
+		Py_DECREF(class_list);
+		return NULL;
 	}
 
 	len = PyTuple_GET_SIZE(class_list);
 					/* skip, posed-as type */
 				} else if (PyDict_SetItemString(module_globals, 
 						((PyTypeObject*)item)->tp_name, item) == -1) {
-					Py_DECREF(module_key);
-					Py_DECREF(class_list);
+					Py_DECREF(module_key);module_key = NULL;
+					Py_DECREF(class_list);class_list = NULL;
 					return NULL;
 				}
 				continue;
 
 		/* cls is located in bundle */
 		if (PyObject_SetAttr(item, module_key, module_name) == -1) {
-			Py_DECREF(module_key);
-			Py_DECREF(class_list);
+			Py_DECREF(module_key); module_key = NULL;
+			Py_DECREF(class_list); class_list = NULL;
 			return NULL;
 		}
 
 			/* skip, posed-as type */
 		} else if (PyDict_SetItemString(module_globals, 
 				((PyTypeObject*)item)->tp_name, item) == -1) {
-		//	Py_DECREF(module_key);
-			Py_DECREF(class_list);
+			Py_DECREF(module_key); module_key = NULL;
+			Py_DECREF(class_list); class_list = NULL;
 			return NULL;
 		}
 	}
-	//Py_XDECREF(module_key);
-	Py_XDECREF(class_list);
+	Py_XDECREF(module_key); module_key = NULL;
+	Py_XDECREF(class_list); class_list = NULL;
 
-	//NSLog(@"loadBundle %@ DONE", strval);
+	/*NSLog(@"loadBundle %@ DONE", strval);*/
 
 	Py_INCREF(Py_None);
 	return Py_None;

Modules/objc/objc-class.m

 		methodsToAdd->method_count = 1;
 		objcMethod = methodsToAdd->method_list;
 		objcMethod->method_name = PyObjCSelector_GetSelector(newVal);
-		objcMethod->method_types = PyObjCUtil_Strdup(
+		objcMethod->method_types = strdup(
 				PyObjCSelector_Signature(newVal));
 
 		if (objcMethod->method_types == NULL) {

Modules/objc/objc-object.m

 	tp = (PyTypeObject*)PyObjCClass_New(obj_class);
 
 	descr = NULL;
-
 	if (tp != obj->ob_type) {
 		/* Workaround for KVO implementation feature */
 		PyObject* dict;

Modules/objc/objc-runtime-apple.h

 	int res = 0; 
 	int cnt = 0;
 
-
 	/* The documented way of walking over the method-list is by using
 	 * class_nextMethodList. Handcoding it is noticeable faster (probably
 	 * because this exposes more information to the optimizer).
 	for (p = cls->methodLists; 
 	     (*p != (struct objc_method_list*)-1) && (*p != NULL);
 	     p++) {
+
 		res += (*p)->method_count;
 		cnt++;
 	}

Modules/objc/objc-runtime-apple.m

 	cls->info = CLS_CLASS; // |CLS_METHOD_ARRAY;
 	metaCls->info = CLS_META; // |CLS_METHOD_ARRAY;
 
-	cls->name = PyObjCUtil_Strdup(name);
+	cls->name = strdup(name);
 	if (cls->name == NULL) {
 		return -1;
 	}
-	metaCls->name = PyObjCUtil_Strdup(name);
+	metaCls->name = strdup(name);
 	if (metaCls->name == NULL) {
 		free((char*)(cls->name));
+		cls->name = NULL;
 		return -1;
 	}
 
 	if (cls->methodLists == NULL) {
 		PyErr_NoMemory();
 		free((char*)(cls->name)); 
+		cls->name = NULL;
 		free((char*)(metaCls->name)); 
+		metaCls->name = NULL;
 		return -1;
 	}
 	memset(cls->methodLists, 0, sizeof(*(cls->methodLists)));
 	if (cls->methodLists == NULL) {
 		PyErr_NoMemory();
 		free((char*)(cls->name)); 
+		cls->name = NULL;
 		free((char*)(metaCls->name)); 
+		metaCls->name = NULL;
 		free(cls->methodLists);
+		cls->methodLists = NULL;
 		return -1;
 	}
 	memset(metaCls->methodLists, 0, sizeof(*(metaCls->methodLists)));
 
 void PyObjCRT_ClearClass(Class cls)
 {
+	return;
 	if (cls->methodLists) {
 		if (cls->methodLists) {
 			struct objc_method_list** cur;
 			while (*cur != (struct objc_method_list*)-1) {
 				if (*cur != NULL) {
 					free(*cur);
+					*cur = NULL;
 				}
 				cur++;
 			}

Modules/objc/objc-runtime-gnu.m

 	cls->info = CLS_CLASS;
 	metaCls->info = CLS_META;
 
-	cls->name = PyObjCUtil_Strdup(name);
+	cls->name = strdup(name);
 	if (cls->name == NULL) {
 		return -1;
 	}
-	metaCls->name = PyObjCUtil_Strdup(name);
+	metaCls->name = strdup(name);
 	if (metaCls->name == NULL) {
 		free((char*)(cls->name));
+		cls->name = NULL;
 		return -1;
 	}
 
 
 	if (cls->name) {
 		free((char*)(cls->name));
+		cls->name = NULL;
 	}
 }
 

Modules/objc/objc_util.m

 	char* result;
 
 	len = strlen(value);
-	result = malloc(len+1);
+	result = PyMem_Malloc(len+1);
 	if (result == NULL) return NULL;
 
 	memcpy(result, value, len);
 void    PyObjC_FreeCArray(int code, void* array)
 {
 	if (code == SHOULD_FREE) {
-		free(array);
+		PyMem_Free(array);
 	}
 }
 
 	if (!r) {
 		return -1;
 	}
+
 	return 0;
 
 #if 0
 					"least %d", seqlen, pycount);
 			return -1;
 		}
-		*array = malloc(eltsize * pycount);
+		*array = PyMem_Malloc(eltsize * pycount);
 		if (*array == NULL) {
 			Py_DECREF(seq);
 			PyErr_NoMemory();
 					((char*)*array)+(i*eltsize));
 			if (r == -1) {
 				Py_DECREF(seq);
-				free(*array); *array = NULL;
+				PyMem_Free(*array); *array = NULL;
 				return -1;
 			}
 		}

Modules/objc/pointer-support.m

 	struct wrapper* value;
 
 	if (items == NULL) {
-		items = malloc(sizeof(struct wrapper));
+		items = PyMem_Malloc(sizeof(struct wrapper));
 		if (items == NULL) {
 			PyErr_NoMemory();
 			return -1;
 	} else {
 		struct wrapper* tmp;
 
-		tmp = realloc(items, sizeof(struct wrapper) *  (item_count+1));
+		tmp = PyMem_Realloc(items, sizeof(struct wrapper) *  (item_count+1));
 		if (tmp == NULL) {
 			PyErr_NoMemory();
 			return -1;

Modules/objc/pyobjc.h

  * Central include file for PyObjC. 
  */
 
-#define OBJC_VERSION "1.1b2"
+#define OBJC_VERSION "1.1c1"
 
 #include <Python.h>
 #include "structmember.h"

Modules/objc/selector.m

 static void
 free_replacement_signature(void* value)
 {
-	free(((struct replacement_signature*)value)->class_name);
-	free(((struct replacement_signature*)value)->signature);
-	free(value);
+	PyMem_Free(((struct replacement_signature*)value)->class_name);
+	PyMem_Free(((struct replacement_signature*)value)->signature);
+	PyMem_Free(value);
 }
 
 int 
 	struct replacement_signature* value;
 	PyObject*                      sublist;
 
-	value = malloc(sizeof(*value));
+	value = PyMem_Malloc(sizeof(*value));
 	if (value == NULL) {
 		PyErr_NoMemory();
 		return -1;
 	}
 	value->class_name = PyObjCUtil_Strdup(class_name);
 	if (value->class_name == NULL) {
-		free(value);
+		PyMem_Free(value);
 		return -1;
 	}
 	
 	value->selector = selector;
 	value->signature = PyObjCUtil_Strdup(signature);
 	if (value->signature == NULL) {
-		free(value->class_name);
+		PyMem_Free(value->class_name);
 		PyErr_NoMemory();
 		return -1;
 	}
 		}
 	}
 
-	free(self->sel_signature);
+	PyMem_Free(self->sel_signature);
 	self->sel_signature = NULL;
 	if (self->sel_self) { 
 		Py_DECREF(self->sel_self); 
 	arg_count = func_code->co_argcount;
 
 	/* arguments + return-type + selector */
-	result = malloc(arg_count+3);
+	result = PyMem_Malloc(arg_count+3);
 	if (result == 0) {
 		PyErr_NoMemory();
 		return NULL;

Modules/objc/struct-wrapper.m

 	PyMemberDef* members;
 	int i;
 
-	members = malloc(sizeof(PyMemberDef) * (numFields+1));
+	members = PyMem_Malloc(sizeof(PyMemberDef) * (numFields+1));
 	if (members == NULL) {
 		PyErr_NoMemory();
 		return NULL;
 	}
 	members[numFields].name = NULL;
 
-	result = malloc(sizeof(PyTypeObject));
+	result = PyMem_Malloc(sizeof(PyTypeObject));
 	if (result == NULL) {
-		free(members);
+		PyMem_Free(members);
 		PyErr_NoMemory();
 		return NULL;
 	}
 
 	if (PyType_Ready(result) == -1) {
 		/* Is freeing save? */
-		free(result);
-		free(members);
+		PyMem_Free(result);
+		PyMem_Free(members);
 		return NULL;
 	}
 	return (PyObject*)result;

Modules/objc/super-call.m

 		if (pyclass == NULL) return -1;
 	}
 
-	v = malloc(sizeof(*v));
+	v = PyMem_Malloc(sizeof(*v));
 	if (v == NULL) {
 		PyErr_NoMemory();
 		return -1;
 
 	PyTuple_SET_ITEM(entry, 0, pyclass);
 	PyTuple_SET_ITEM(entry, 1, PyString_InternFromString(selname));
-	PyTuple_SET_ITEM(entry, 2, PyCObject_FromVoidPtr(v, (free)));
+	PyTuple_SET_ITEM(entry, 2, PyCObject_FromVoidPtr(v, (PyMem_Free)));
 
 	if (PyErr_Occurred()) {
 		Py_DECREF(entry);
 		return -1;
 	}
 
-	v = malloc(sizeof(*v));
+	v = PyMem_Malloc(sizeof(*v));
 	if (v == NULL) {
 		PyErr_NoMemory();
 		return -1;
 	v->call_to_objc  = call_to_objc;
 	v->call_to_python = call_to_python;
 
-	entry = PyCObject_FromVoidPtr(v, (free));
+	entry = PyCObject_FromVoidPtr(v, (PyMem_Free));
 	if (entry == NULL) {
-		free(v);
+		PyMem_Free(v);
 		return -1;
 	}
 

Modules/objc/unicode-object.m

 PyObject* 
 PyObjCUnicode_New(NSString* value)
 {
-#if 0 /* def PyObjC_CONVERT_TO_UTF8_FIRST */
-	const char* utf8 = [value UTF8String];
-	PyUnicodeObject* tmp = (PyUnicodeObject*)PyUnicode_DecodeUTF8(
-			utf8, strlen(utf8), "strict");
-	PyObjCUnicodeObject* result;
-	if (tmp == NULL) return NULL;
-
-	result = PyObject_New(PyObjCUnicodeObject, &PyObjCUnicode_Type);
-	PyUnicode_AS_UNICODE(result) = PyMem_NEW(Py_UNICODE,
-		PyUnicode_GET_SIZE(tmp));
-	if (PyUnicode_AS_UNICODE(result) == NULL) {
-		Py_DECREF((PyObject*)result);
-		PyErr_NoMemory();
-		return NULL;
-	}
-	PyUnicode_GET_SIZE(result) = PyUnicode_GET_SIZE(tmp);
-	memcpy((char*)PyUnicode_AS_DATA(result), PyUnicode_AS_DATA(tmp),
-		PyUnicode_GET_DATA_SIZE(tmp));
-
-	result->base.hash = -1;
-
-	result->base.defenc = tmp->defenc;
-	Py_XINCREF(tmp->defenc);
-	Py_DECREF(tmp);
-#else
 	/* Conversion to PyUnicode without creating an autoreleased object.
 	 *
 	 * NOTE: A final optimization is removing the copy of 'characters', but
 
 	NS_DURING
 		length = [value length];
-		characters = malloc(sizeof(unichar) * length);
+		characters = PyMem_Malloc(sizeof(unichar) * length);
 		if (characters == NULL) {
 			PyErr_NoMemory();
 			NS_VALUERETURN(NULL, PyObject*);
 
 	NS_HANDLER
 		if (characters) {
-			free(characters);
+			PyMem_Free(characters);
 			characters = NULL;
 		}
 		PyObjCErr_FromObjC(localException);
 	PyUnicode_AS_UNICODE(result) = PyMem_NEW(Py_UNICODE, length);
 	if (PyUnicode_AS_UNICODE(result) == NULL) {
 		Py_DECREF((PyObject*)result);
-		free(characters); 
+		PyMem_Free(characters); characters = NULL;
 		PyErr_NoMemory();
 		return NULL;
 	}
 	for (i = 0; i < length; i++) {
 		PyUnicode_AS_UNICODE(result)[i] = (Py_UNICODE)(characters[i]);
 	}
-	free(characters); 
+	PyMem_Free(characters); characters = NULL;
 
 	result->base.defenc = NULL;
-#endif
 
 	result->base.hash = -1;
 
         sys.exit(1)
 
     CFLAGS=[
-        #"-DPYOBJC_NEW_INITIALIZER_PATTERN",
+        "-DPYOBJC_NEW_INITIALIZER_PATTERN",
         "-DMACOSX",
         "-DAPPLE_RUNTIME",
         "-no-cpp-precomp",
         ]
 
     OBJC_LDFLAGS=[
-        '-framework', 'Foundation',
+        '-framework', 'Foundation', 
         ]
 
     CF_LDFLAGS=[
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.