summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2010-08-08 17:56:41 (GMT)
committerThomas Heller <theller@ctypes.org>2010-08-08 17:56:41 (GMT)
commit001d3a1d8ac9b5a057a585950182880f5733c608 (patch)
treefc83b45c8370714c94522d12b1f1a319fe23408d /Modules
parent6fe8c41e8ff4d87fd6bb1bc9ae67d0f49b5073f4 (diff)
downloadcpython-001d3a1d8ac9b5a057a585950182880f5733c608.zip
cpython-001d3a1d8ac9b5a057a585950182880f5733c608.tar.gz
cpython-001d3a1d8ac9b5a057a585950182880f5733c608.tar.bz2
Fis issue5504: ctypes does now work with systems where mmap can't be
PROT_WRITE and PROT_EXEC.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/_ctypes.c2
-rw-r--r--Modules/_ctypes/callbacks.c16
-rw-r--r--Modules/_ctypes/ctypes.h6
-rw-r--r--Modules/_ctypes/libffi/fficonfig.py.in2
-rw-r--r--Modules/_ctypes/libffi_msvc/ffi.c10
-rw-r--r--Modules/_ctypes/libffi_msvc/ffi.h8
-rw-r--r--Modules/_ctypes/malloc_closure.c8
7 files changed, 31 insertions, 21 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c
index af3bb5b..7d7d58c 100644
--- a/Modules/_ctypes/_ctypes.c
+++ b/Modules/_ctypes/_ctypes.c
@@ -3463,7 +3463,7 @@ PyCFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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)) {
diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c
index 8fbe6de..deedaa3 100644
--- a/Modules/_ctypes/callbacks.c
+++ b/Modules/_ctypes/callbacks.c
@@ -21,8 +21,8 @@ CThunkObject_dealloc(PyObject *_self)
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 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
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 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
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 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
"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);
diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h
index 7d7ba1f..59640cc 100644
--- a/Modules/_ctypes/ctypes.h
+++ b/Modules/_ctypes/ctypes.h
@@ -95,7 +95,8 @@ struct tagCDataObject {
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;
@@ -428,9 +429,6 @@ extern Py_ssize_t PyUnicode_AsWideChar_fixed(PyUnicodeObject *, wchar_t *, Py_ss
#endif
#endif
-extern void _ctypes_free_closure(void *);
-extern void *_ctypes_alloc_closure(void);
-
extern void _ctypes_add_traceback(char *, char *, int);
extern PyObject *PyCData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr);
diff --git a/Modules/_ctypes/libffi/fficonfig.py.in b/Modules/_ctypes/libffi/fficonfig.py.in
index b7bae9c..27c971f 100644
--- a/Modules/_ctypes/libffi/fficonfig.py.in
+++ b/Modules/_ctypes/libffi/fficonfig.py.in
@@ -1,5 +1,7 @@
ffi_sources = """
src/prep_cif.c
+src/closures.c
+src/dlmalloc.c
""".split()
ffi_platforms = {
diff --git a/Modules/_ctypes/libffi_msvc/ffi.c b/Modules/_ctypes/libffi_msvc/ffi.c
index 763d179..65581a7 100644
--- a/Modules/_ctypes/libffi_msvc/ffi.c
+++ b/Modules/_ctypes/libffi_msvc/ffi.c
@@ -371,10 +371,11 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
extern void ffi_closure_OUTER();
ffi_status
-ffi_prep_closure (ffi_closure* closure,
- ffi_cif* cif,
- void (*fun)(ffi_cif*,void*,void**,void*),
- void *user_data)
+ffi_prep_closure_loc (ffi_closure* closure,
+ ffi_cif* cif,
+ void (*fun)(ffi_cif*,void*,void**,void*),
+ void *user_data,
+ void *codeloc)
{
short bytes;
char *tramp;
@@ -452,6 +453,5 @@ ffi_prep_closure (ffi_closure* closure,
closure->cif = cif;
closure->user_data = user_data;
closure->fun = fun;
-
return FFI_OK;
}
diff --git a/Modules/_ctypes/libffi_msvc/ffi.h b/Modules/_ctypes/libffi_msvc/ffi.h
index a88d874..efb14c5 100644
--- a/Modules/_ctypes/libffi_msvc/ffi.h
+++ b/Modules/_ctypes/libffi_msvc/ffi.h
@@ -221,11 +221,15 @@ typedef struct {
void *user_data;
} ffi_closure;
+void ffi_closure_free(void *);
+void *ffi_closure_alloc (size_t size, void **code);
+
ffi_status
-ffi_prep_closure (ffi_closure*,
+ffi_prep_closure_loc (ffi_closure*,
ffi_cif *,
void (*fun)(ffi_cif*,void*,void**,void*),
- void *user_data);
+ void *user_data,
+ void *codeloc);
typedef struct {
char tramp[FFI_TRAMPOLINE_SIZE];
diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c
index a691ab4..d0a20b5 100644
--- a/Modules/_ctypes/malloc_closure.c
+++ b/Modules/_ctypes/malloc_closure.c
@@ -93,7 +93,7 @@ static void more_core(void)
/******************************************************************/
/* put the item back into the free list */
-void _ctypes_free_closure(void *p)
+void ffi_closure_free(void *p)
{
ITEM *item = (ITEM *)p;
item->next = free_list;
@@ -101,7 +101,7 @@ void _ctypes_free_closure(void *p)
}
/* return one item from the free list, allocating more if needed */
-void *_ctypes_alloc_closure(void)
+void *ffi_closure_alloc(size_t ignored, void** codeloc)
{
ITEM *item;
if (!free_list)
@@ -110,5 +110,7 @@ void *_ctypes_alloc_closure(void)
return NULL;
item = free_list;
free_list = item->next;
- return item;
+ *codeloc = (void *)item;
+ return (void *)item;
}
+