Index: setup.py =================================================================== --- setup.py (Revision 83687) +++ setup.py (Arbeitskopie) @@ -1867,8 +1867,7 @@ '_ctypes/callbacks.c', '_ctypes/callproc.c', '_ctypes/stgdict.c', - '_ctypes/cfield.c', - '_ctypes/malloc_closure.c'] + '_ctypes/cfield.c'] depends = ['_ctypes/ctypes.h'] if sys.platform == 'darwin': Index: Modules/_ctypes/_ctypes.c =================================================================== --- Modules/_ctypes/_ctypes.c (Revision 83687) +++ Modules/_ctypes/_ctypes.c (Arbeitskopie) @@ -3463,7 +3463,7 @@ self->callable = callable; self->thunk = thunk; - *(void **)self->b_ptr = (void *)thunk->pcl; + *(void **)self->b_ptr = (void *)thunk->pcl_exec; Py_INCREF((PyObject *)thunk); /* for KeepRef */ if (-1 == KeepRef((CDataObject *)self, 0, (PyObject *)thunk)) { Index: Modules/_ctypes/libffi/fficonfig.py.in =================================================================== --- Modules/_ctypes/libffi/fficonfig.py.in (Revision 83687) +++ Modules/_ctypes/libffi/fficonfig.py.in (Arbeitskopie) @@ -1,5 +1,7 @@ ffi_sources = """ src/prep_cif.c +src/closures.c +src/dlmalloc.c """.split() ffi_platforms = { Index: Modules/_ctypes/ctypes.h =================================================================== --- Modules/_ctypes/ctypes.h (Revision 83687) +++ Modules/_ctypes/ctypes.h (Arbeitskopie) @@ -95,7 +95,8 @@ typedef struct { PyObject_VAR_HEAD - ffi_closure *pcl; /* the C callable */ + ffi_closure *pcl_write; /* the C callable, writeable */ + void *pcl_exec; /* the C callable, executable */ ffi_cif cif; int flags; PyObject *converters; Index: Modules/_ctypes/callbacks.c =================================================================== --- Modules/_ctypes/callbacks.c (Revision 83687) +++ Modules/_ctypes/callbacks.c (Arbeitskopie) @@ -21,8 +21,8 @@ Py_XDECREF(self->converters); Py_XDECREF(self->callable); Py_XDECREF(self->restype); - if (self->pcl) - _ctypes_free_closure(self->pcl); + if (self->pcl_write) + ffi_closure_free(self->pcl_write); PyObject_GC_Del(self); } @@ -391,7 +391,8 @@ return NULL; } - p->pcl = NULL; + p->pcl_exec = NULL; + p->pcl_write = NULL; memset(&p->cif, 0, sizeof(p->cif)); p->converters = NULL; p->callable = NULL; @@ -421,8 +422,9 @@ assert(CThunk_CheckExact(p)); - p->pcl = _ctypes_alloc_closure(); - if (p->pcl == NULL) { + p->pcl_write = ffi_closure_alloc(sizeof(ffi_closure), + &p->pcl_exec); + if (p->pcl_write == NULL) { PyErr_NoMemory(); goto error; } @@ -467,7 +469,9 @@ "ffi_prep_cif failed with %d", result); goto error; } - result = ffi_prep_closure(p->pcl, &p->cif, closure_fcn, p); + result = ffi_prep_closure_loc(p->pcl_write, &p->cif, closure_fcn, + p, + p->pcl_exec); if (result != FFI_OK) { PyErr_Format(PyExc_RuntimeError, "ffi_prep_closure failed with %d", result);