Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 329499 | Differences between
and this patch

Collapse All | Expand All

(-)setup.py (-2 / +1 lines)
Lines 1861-1868 Link Here
1861
                   '_ctypes/callbacks.c',
1861
                   '_ctypes/callbacks.c',
1862
                   '_ctypes/callproc.c',
1862
                   '_ctypes/callproc.c',
1863
                   '_ctypes/stgdict.c',
1863
                   '_ctypes/stgdict.c',
1864
                   '_ctypes/cfield.c',
1864
                   '_ctypes/cfield.c']
1865
                   '_ctypes/malloc_closure.c']
1866
        depends = ['_ctypes/ctypes.h']
1865
        depends = ['_ctypes/ctypes.h']
1867
1866
1868
        if sys.platform == 'darwin':
1867
        if sys.platform == 'darwin':
(-)Modules/_ctypes/callbacks.c (-6 / +10 lines)
Lines 21-28 Link Here
21
    Py_XDECREF(self->converters);
21
    Py_XDECREF(self->converters);
22
    Py_XDECREF(self->callable);
22
    Py_XDECREF(self->callable);
23
    Py_XDECREF(self->restype);
23
    Py_XDECREF(self->restype);
24
    if (self->pcl)
24
    if (self->pcl_write)
25
        FreeClosure(self->pcl);
25
        ffi_closure_free(self->pcl_write);
26
    PyObject_GC_Del(self);
26
    PyObject_GC_Del(self);
27
}
27
}
28
28
Lines 373-379 Link Here
373
        return NULL;
373
        return NULL;
374
    }
374
    }
375
375
376
    p->pcl = NULL;
376
    p->pcl_exec = NULL;
377
    p->pcl_write = NULL;
377
    memset(&p->cif, 0, sizeof(p->cif));
378
    memset(&p->cif, 0, sizeof(p->cif));
378
    p->converters = NULL;
379
    p->converters = NULL;
379
    p->callable = NULL;
380
    p->callable = NULL;
Lines 403-410 Link Here
403
404
404
    assert(CThunk_CheckExact(p));
405
    assert(CThunk_CheckExact(p));
405
406
406
    p->pcl = MallocClosure();
407
    p->pcl_write = ffi_closure_alloc(sizeof(ffi_closure),
407
    if (p->pcl == NULL) {
408
                                     &p->pcl_exec);
409
    if (p->pcl_write == NULL) {
408
        PyErr_NoMemory();
410
        PyErr_NoMemory();
409
        goto error;
411
        goto error;
410
    }
412
    }
Lines 449-455 Link Here
449
                     "ffi_prep_cif failed with %d", result);
451
                     "ffi_prep_cif failed with %d", result);
450
        goto error;
452
        goto error;
451
    }
453
    }
452
    result = ffi_prep_closure(p->pcl, &p->cif, closure_fcn, p);
454
    result = ffi_prep_closure_loc(p->pcl_write, &p->cif, closure_fcn,
455
                                  p,
456
                                  p->pcl_exec);
453
    if (result != FFI_OK) {
457
    if (result != FFI_OK) {
454
        PyErr_Format(PyExc_RuntimeError,
458
        PyErr_Format(PyExc_RuntimeError,
455
                     "ffi_prep_closure failed with %d", result);
459
                     "ffi_prep_closure failed with %d", result);
(-)Modules/_ctypes/malloc_closure.c (-114 lines)
Lines 1-114 Link Here
1
/*****************************************************************
2
  This file should be kept compatible with Python 2.3, see PEP 291.
3
 *****************************************************************/
4
5
#include <Python.h>
6
#include <ffi.h>
7
#ifdef MS_WIN32
8
#include <windows.h>
9
#else
10
#include <sys/mman.h>
11
#include <unistd.h>
12
# if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
13
#  define MAP_ANONYMOUS MAP_ANON
14
# endif
15
#endif
16
#include "ctypes.h"
17
18
/* BLOCKSIZE can be adjusted.  Larger blocksize will take a larger memory
19
   overhead, but allocate less blocks from the system.  It may be that some
20
   systems have a limit of how many mmap'd blocks can be open.
21
*/
22
23
#define BLOCKSIZE _pagesize
24
25
/* #define MALLOC_CLOSURE_DEBUG */ /* enable for some debugging output */
26
27
/******************************************************************/
28
29
typedef union _tagITEM {
30
    ffi_closure closure;
31
    union _tagITEM *next;
32
} ITEM;
33
34
static ITEM *free_list;
35
static int _pagesize;
36
37
static void more_core(void)
38
{
39
    ITEM *item;
40
    int count, i;
41
42
/* determine the pagesize */
43
#ifdef MS_WIN32
44
    if (!_pagesize) {
45
        SYSTEM_INFO systeminfo;
46
        GetSystemInfo(&systeminfo);
47
        _pagesize = systeminfo.dwPageSize;
48
    }
49
#else
50
    if (!_pagesize) {
51
#ifdef _SC_PAGESIZE
52
        _pagesize = sysconf(_SC_PAGESIZE);
53
#else
54
        _pagesize = getpagesize();
55
#endif
56
    }
57
#endif
58
59
    /* calculate the number of nodes to allocate */
60
    count = BLOCKSIZE / sizeof(ITEM);
61
62
    /* allocate a memory block */
63
#ifdef MS_WIN32
64
    item = (ITEM *)VirtualAlloc(NULL,
65
                                           count * sizeof(ITEM),
66
                                           MEM_COMMIT,
67
                                           PAGE_EXECUTE_READWRITE);
68
    if (item == NULL)
69
        return;
70
#else
71
    item = (ITEM *)mmap(NULL,
72
                        count * sizeof(ITEM),
73
                        PROT_READ | PROT_WRITE | PROT_EXEC,
74
                        MAP_PRIVATE | MAP_ANONYMOUS,
75
                        -1,
76
                        0);
77
    if (item == (void *)MAP_FAILED)
78
        return;
79
#endif
80
81
#ifdef MALLOC_CLOSURE_DEBUG
82
    printf("block at %p allocated (%d bytes), %d ITEMs\n",
83
           item, count * sizeof(ITEM), count);
84
#endif
85
    /* put them into the free list */
86
    for (i = 0; i < count; ++i) {
87
        item->next = free_list;
88
        free_list = item;
89
        ++item;
90
    }
91
}
92
93
/******************************************************************/
94
95
/* put the item back into the free list */
96
void FreeClosure(void *p)
97
{
98
    ITEM *item = (ITEM *)p;
99
    item->next = free_list;
100
    free_list = item;
101
}
102
103
/* return one item from the free list, allocating more if needed */
104
void *MallocClosure(void)
105
{
106
    ITEM *item;
107
    if (!free_list)
108
        more_core();
109
    if (!free_list)
110
        return NULL;
111
    item = free_list;
112
    free_list = item->next;
113
    return item;
114
}
(-)Modules/_ctypes/_ctypes.c (-1 / +1 lines)
Lines 3443-3449 Link Here
3443
    self->callable = callable;
3443
    self->callable = callable;
3444
3444
3445
    self->thunk = thunk;
3445
    self->thunk = thunk;
3446
    *(void **)self->b_ptr = (void *)thunk->pcl;
3446
    *(void **)self->b_ptr = (void *)thunk->pcl_exec;
3447
3447
3448
    Py_INCREF((PyObject *)thunk); /* for KeepRef */
3448
    Py_INCREF((PyObject *)thunk); /* for KeepRef */
3449
    if (-1 == KeepRef((CDataObject *)self, 0, (PyObject *)thunk)) {
3449
    if (-1 == KeepRef((CDataObject *)self, 0, (PyObject *)thunk)) {
(-)Modules/_ctypes/ctypes.h (-1 / +2 lines)
Lines 95-101 Link Here
95
95
96
typedef struct {
96
typedef struct {
97
    PyObject_VAR_HEAD
97
    PyObject_VAR_HEAD
98
    ffi_closure *pcl; /* the C callable */
98
    ffi_closure *pcl_write; /* the C callable, writeable */
99
    void *pcl_exec;         /* the C callable, executable */
99
    ffi_cif cif;
100
    ffi_cif cif;
100
    int flags;
101
    int flags;
101
    PyObject *converters;
102
    PyObject *converters;

Return to bug 329499