46f141e
diff -ur Python-2.6~/Modules/_ctypes/callbacks.c Python-2.6/Modules/_ctypes/callbacks.c
46f141e
--- Python-2.6~/Modules/_ctypes/callbacks.c	2008-06-09 00:58:54.000000000 -0400
46f141e
+++ Python-2.6/Modules/_ctypes/callbacks.c	2009-03-17 00:08:38.424528546 -0400
46f141e
@@ -21,8 +21,8 @@
46f141e
 	Py_XDECREF(self->converters);
46f141e
 	Py_XDECREF(self->callable);
46f141e
 	Py_XDECREF(self->restype);
46f141e
-	if (self->pcl)
46f141e
-		FreeClosure(self->pcl);
46f141e
+	if (self->pcl_write)
46f141e
+		ffi_closure_free(self->pcl_write);
46f141e
 	PyObject_Del(self);
46f141e
 }
46f141e
 
46f141e
@@ -373,7 +373,8 @@
46f141e
 		return NULL;
46f141e
 	}
46f141e
 
46f141e
-	p->pcl = NULL;
46f141e
+	p->pcl_exec = NULL;
46f141e
+	p->pcl_write = NULL;
46f141e
 	memset(&p->cif, 0, sizeof(p->cif));
46f141e
 	p->converters = NULL;
46f141e
 	p->callable = NULL;
46f141e
@@ -402,8 +403,9 @@
46f141e
 
46f141e
 	assert(CThunk_CheckExact(p));
46f141e
 
46f141e
-	p->pcl = MallocClosure();
46f141e
-	if (p->pcl == NULL) {
46f141e
+	p->pcl_write = ffi_closure_alloc(sizeof(ffi_closure),
46f141e
+					 &p->pcl_exec);
46f141e
+	if (p->pcl_write == NULL) {
46f141e
 		PyErr_NoMemory();
46f141e
 		goto error;
46f141e
 	}
46f141e
@@ -448,7 +450,9 @@
46f141e
 			     "ffi_prep_cif failed with %d", result);
46f141e
 		goto error;
46f141e
 	}
46f141e
-	result = ffi_prep_closure(p->pcl, &p->cif, closure_fcn, p);
46f141e
+	result = ffi_prep_closure_loc(p->pcl_write, &p->cif, closure_fcn,
46f141e
+				      p,
46f141e
+				      p->pcl_exec);
46f141e
 	if (result != FFI_OK) {
46f141e
 		PyErr_Format(PyExc_RuntimeError,
46f141e
 			     "ffi_prep_closure failed with %d", result);
46f141e
diff -ur Python-2.6~/Modules/_ctypes/_ctypes.c Python-2.6/Modules/_ctypes/_ctypes.c
46f141e
--- Python-2.6~/Modules/_ctypes/_ctypes.c	2008-08-19 15:40:23.000000000 -0400
46f141e
+++ Python-2.6/Modules/_ctypes/_ctypes.c	2009-03-17 00:08:38.479530502 -0400
46f141e
@@ -3438,7 +3438,7 @@
46f141e
 	self->callable = callable;
46f141e
 
46f141e
 	self->thunk = thunk;
46f141e
-	*(void **)self->b_ptr = (void *)thunk->pcl;
46f141e
+	*(void **)self->b_ptr = (void *)thunk->pcl_exec;
46f141e
 	
46f141e
 	Py_INCREF((PyObject *)thunk); /* for KeepRef */
46f141e
 	if (-1 == KeepRef((CDataObject *)self, 0, (PyObject *)thunk)) {
46f141e
diff -ur Python-2.6~/Modules/_ctypes/ctypes.h Python-2.6/Modules/_ctypes/ctypes.h
46f141e
--- Python-2.6~/Modules/_ctypes/ctypes.h	2008-07-24 07:16:45.000000000 -0400
46f141e
+++ Python-2.6/Modules/_ctypes/ctypes.h	2009-03-17 00:08:38.480528344 -0400
46f141e
@@ -95,7 +95,8 @@
46f141e
 
46f141e
 typedef struct {
46f141e
 	PyObject_VAR_HEAD
46f141e
-	ffi_closure *pcl; /* the C callable */
46f141e
+	ffi_closure *pcl_write; /* the C callable, writeable */
46f141e
+	void *pcl_exec;         /* the C callable, executable */
46f141e
 	ffi_cif cif;
46f141e
 	int flags;
46f141e
 	PyObject *converters;
46f141e
diff -ur Python-2.6~/setup.py Python-2.6/setup.py
46f141e
--- Python-2.6~/setup.py	2009-03-17 00:07:54.771651851 -0400
46f141e
+++ Python-2.6/setup.py	2009-03-17 00:08:19.792558478 -0400
46f141e
@@ -1701,8 +1701,7 @@
46f141e
                    '_ctypes/callbacks.c',
46f141e
                    '_ctypes/callproc.c',
46f141e
                    '_ctypes/stgdict.c',
46f141e
-                   '_ctypes/cfield.c',
46f141e
-                   '_ctypes/malloc_closure.c']
46f141e
+                   '_ctypes/cfield.c']
46f141e
         depends = ['_ctypes/ctypes.h']
46f141e
 
46f141e
         if sys.platform == 'darwin':