| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include "Python.h" |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#define BLOCK_SIZE 1000 |
| 24 |
#define BHEAD_SIZE 8 |
| 25 |
#define N_INTOBJECTS ((BLOCK_SIZE - BHEAD_SIZE) / sizeof(PyIntObject)) |
| 26 |
|
| 27 |
struct _intblock { |
| 28 |
struct _intblock *next; |
| 29 |
PyIntObject objects[N_INTOBJECTS]; |
| 30 |
}; |
| 31 |
|
| 32 |
typedef struct _intblock PyIntBlock; |
| 33 |
|
| 34 |
static PyIntBlock *block_list = NULL; |
| 35 |
static PyIntObject *free_list = NULL; |
| 36 |
|
| 37 |
static PyIntObject * |
| 38 |
fill_free_list(void) |
| 39 |
{ |
| 40 |
PyIntObject *p, *q; |
| 41 |
|
| 42 |
p = (PyIntObject *) PyMem_MALLOC(sizeof(PyIntBlock)); |
| 43 |
if (p == NULL) |
| 44 |
return (PyIntObject *) PyErr_NoMemory(); |
| 45 |
((PyIntBlock *)p)->next = block_list; |
| 46 |
block_list = (PyIntBlock *)p; |
| 47 |
|
| 48 |
|
| 49 |
p = &((PyIntBlock *)p)->objects[0]; |
| 50 |
q = p + N_INTOBJECTS; |
| 51 |
while (--q > p) |
| 52 |
Py_TYPE(q) = (struct _typeobject *)(q-1); |
| 53 |
Py_TYPE(q) = NULL; |
| 54 |
return p + N_INTOBJECTS - 1; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
#ifdef CPYEXT_TESTS |
| 59 |
#define _Py_int_dealloc _cpyexttest_int_dealloc |
| 60 |
#ifdef __GNUC__ |
| 61 |
__attribute__((visibility("default"))) |
| 62 |
#else |
| 63 |
__declspec(dllexport) |
| 64 |
#endif |
| 65 |
#else |
| 66 |
#define _Py_int_dealloc _PyPy_int_dealloc |
| 67 |
#endif |
| 68 |
void |
| 69 |
_Py_int_dealloc(PyObject *obj) |
| 70 |
{ |
| 71 |
PyIntObject *v = (PyIntObject *)obj; |
| 72 |
if (PyInt_CheckExact(v)) { |
| 73 |
Py_TYPE(v) = (struct _typeobject *)free_list; |
| 74 |
free_list = v; |
| 75 |
} |
| 76 |
else |
| 77 |
Py_TYPE(v)->tp_free((PyObject *)v); |
| 78 |
} |