Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e647b47

Browse files
committed
Fix buildbot issues due to _ctypes failing to compile in 3.1.
Recorded rollback of revisions 83837,83841 via svnmerge from svn+ssh://[email protected]/python/branches/py3k
1 parent bd25d59 commit e647b47

9 files changed

Lines changed: 20 additions & 43 deletions

File tree

Misc/NEWS

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ Core and Builtins
1515
- Issue #5319: Print an error if flushing stdout fails at interpreter
1616
shutdown.
1717

18-
- Issue #6869: Fix a refcount problem in the _ctypes extension.
19-
20-
- Issue #5504: ctypes should now work with systems where mmap can't
21-
be PROT_WRITE and PROT_EXEC.
22-
2318
- Issue #8814: function annotations (the ``__annotations__`` attribute)
2419
are now included in the set of attributes copied by default by
2520
functools.wraps and functools.update_wrapper. Patch by Terrence Cole.

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3367,7 +3367,7 @@ PyCFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
33673367
self->callable = callable;
33683368

33693369
self->thunk = thunk;
3370-
*(void **)self->b_ptr = (void *)thunk->pcl_exec;
3370+
*(void **)self->b_ptr = (void *)thunk->pcl;
33713371

33723372
Py_INCREF((PyObject *)thunk); /* for KeepRef */
33733373
if (-1 == KeepRef((CDataObject *)self, 0, (PyObject *)thunk)) {
@@ -5326,42 +5326,36 @@ PyInit__ctypes(void)
53265326
Struct_Type.tp_base = &PyCData_Type;
53275327
if (PyType_Ready(&Struct_Type) < 0)
53285328
return NULL;
5329-
Py_INCREF(&Struct_Type);
53305329
PyModule_AddObject(m, "Structure", (PyObject *)&Struct_Type);
53315330

53325331
Py_TYPE(&Union_Type) = &UnionType_Type;
53335332
Union_Type.tp_base = &PyCData_Type;
53345333
if (PyType_Ready(&Union_Type) < 0)
53355334
return NULL;
5336-
Py_INCREF(&Union_Type);
53375335
PyModule_AddObject(m, "Union", (PyObject *)&Union_Type);
53385336

53395337
Py_TYPE(&PyCPointer_Type) = &PyCPointerType_Type;
53405338
PyCPointer_Type.tp_base = &PyCData_Type;
53415339
if (PyType_Ready(&PyCPointer_Type) < 0)
53425340
return NULL;
5343-
Py_INCREF(&PyCPointer_Type);
53445341
PyModule_AddObject(m, "_Pointer", (PyObject *)&PyCPointer_Type);
53455342

53465343
Py_TYPE(&PyCArray_Type) = &PyCArrayType_Type;
53475344
PyCArray_Type.tp_base = &PyCData_Type;
53485345
if (PyType_Ready(&PyCArray_Type) < 0)
53495346
return NULL;
5350-
Py_INCREF(&PyCArray_Type);
53515347
PyModule_AddObject(m, "Array", (PyObject *)&PyCArray_Type);
53525348

53535349
Py_TYPE(&Simple_Type) = &PyCSimpleType_Type;
53545350
Simple_Type.tp_base = &PyCData_Type;
53555351
if (PyType_Ready(&Simple_Type) < 0)
53565352
return NULL;
5357-
Py_INCREF(&Simple_Type);
53585353
PyModule_AddObject(m, "_SimpleCData", (PyObject *)&Simple_Type);
53595354

53605355
Py_TYPE(&PyCFuncPtr_Type) = &PyCFuncPtrType_Type;
53615356
PyCFuncPtr_Type.tp_base = &PyCData_Type;
53625357
if (PyType_Ready(&PyCFuncPtr_Type) < 0)
53635358
return NULL;
5364-
Py_INCREF(&PyCFuncPtr_Type);
53655359
PyModule_AddObject(m, "CFuncPtr", (PyObject *)&PyCFuncPtr_Type);
53665360

53675361
/*************************************************

Modules/_ctypes/callbacks.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ CThunkObject_dealloc(PyObject *_self)
1616
Py_XDECREF(self->converters);
1717
Py_XDECREF(self->callable);
1818
Py_XDECREF(self->restype);
19-
if (self->pcl_write)
20-
ffi_closure_free(self->pcl_write);
19+
if (self->pcl)
20+
_ctypes_free_closure(self->pcl);
2121
PyObject_GC_Del(self);
2222
}
2323

@@ -370,8 +370,7 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
370370
return NULL;
371371
}
372372

373-
p->pcl_exec = NULL;
374-
p->pcl_write = NULL;
373+
p->pcl = NULL;
375374
memset(&p->cif, 0, sizeof(p->cif));
376375
p->converters = NULL;
377376
p->callable = NULL;
@@ -401,9 +400,8 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
401400

402401
assert(CThunk_CheckExact((PyObject *)p));
403402

404-
p->pcl_write = ffi_closure_alloc(sizeof(ffi_closure),
405-
&p->pcl_exec);
406-
if (p->pcl_write == NULL) {
403+
p->pcl = _ctypes_alloc_closure();
404+
if (p->pcl == NULL) {
407405
PyErr_NoMemory();
408406
goto error;
409407
}
@@ -448,9 +446,7 @@ CThunkObject *_ctypes_alloc_callback(PyObject *callable,
448446
"ffi_prep_cif failed with %d", result);
449447
goto error;
450448
}
451-
result = ffi_prep_closure_loc(p->pcl_write, &p->cif, closure_fcn,
452-
p,
453-
p->pcl_exec);
449+
result = ffi_prep_closure(p->pcl, &p->cif, closure_fcn, p);
454450
if (result != FFI_OK) {
455451
PyErr_Format(PyExc_RuntimeError,
456452
"ffi_prep_closure failed with %d", result);

Modules/_ctypes/ctypes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ struct tagCDataObject {
5858

5959
typedef struct {
6060
PyObject_VAR_HEAD
61-
ffi_closure *pcl_write; /* the C callable, writeable */
62-
void *pcl_exec; /* the C callable, executable */
61+
ffi_closure *pcl; /* the C callable */
6362
ffi_cif cif;
6463
int flags;
6564
PyObject *converters;

Modules/_ctypes/libffi/fficonfig.py.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
ffi_sources = """
22
src/prep_cif.c
3-
src/closures.c
4-
src/dlmalloc.c
53
""".split()
64

75
ffi_platforms = {

Modules/_ctypes/libffi_msvc/ffi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,10 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue,
371371
extern void ffi_closure_OUTER();
372372

373373
ffi_status
374-
ffi_prep_closure_loc (ffi_closure* closure,
375-
ffi_cif* cif,
376-
void (*fun)(ffi_cif*,void*,void**,void*),
377-
void *user_data,
378-
void *codeloc)
374+
ffi_prep_closure (ffi_closure* closure,
375+
ffi_cif* cif,
376+
void (*fun)(ffi_cif*,void*,void**,void*),
377+
void *user_data)
379378
{
380379
short bytes;
381380
char *tramp;
@@ -453,5 +452,6 @@ ffi_prep_closure_loc (ffi_closure* closure,
453452
closure->cif = cif;
454453
closure->user_data = user_data;
455454
closure->fun = fun;
455+
456456
return FFI_OK;
457457
}

Modules/_ctypes/libffi_msvc/ffi.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,11 @@ typedef struct {
221221
void *user_data;
222222
} ffi_closure;
223223

224-
void ffi_closure_free(void *);
225-
void *ffi_closure_alloc (size_t size, void **code);
226-
227224
ffi_status
228-
ffi_prep_closure_loc (ffi_closure*,
225+
ffi_prep_closure (ffi_closure*,
229226
ffi_cif *,
230227
void (*fun)(ffi_cif*,void*,void**,void*),
231-
void *user_data,
232-
void *codeloc);
228+
void *user_data);
233229

234230
typedef struct {
235231
char tramp[FFI_TRAMPOLINE_SIZE];

Modules/_ctypes/malloc_closure.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ static void more_core(void)
8989
/******************************************************************/
9090

9191
/* put the item back into the free list */
92-
void ffi_closure_free(void *p)
92+
void _ctypes_free_closure(void *p)
9393
{
9494
ITEM *item = (ITEM *)p;
9595
item->next = free_list;
9696
free_list = item;
9797
}
9898

9999
/* return one item from the free list, allocating more if needed */
100-
void *ffi_closure_alloc(size_t ignored, void** codeloc)
100+
void *_ctypes_alloc_closure(void)
101101
{
102102
ITEM *item;
103103
if (!free_list)
@@ -106,7 +106,5 @@ void *ffi_closure_alloc(size_t ignored, void** codeloc)
106106
return NULL;
107107
item = free_list;
108108
free_list = item->next;
109-
*codeloc = (void *)item;
110-
return (void *)item;
109+
return item;
111110
}
112-

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,8 @@ def detect_ctypes(self, inc_dirs, lib_dirs):
16361636
'_ctypes/callbacks.c',
16371637
'_ctypes/callproc.c',
16381638
'_ctypes/stgdict.c',
1639-
'_ctypes/cfield.c']
1639+
'_ctypes/cfield.c',
1640+
'_ctypes/malloc_closure.c']
16401641
depends = ['_ctypes/ctypes.h']
16411642

16421643
if sys.platform == 'darwin':

0 commit comments

Comments
 (0)