1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
#include "Python.h"
//#define ISSUE_2482
typedef struct {
PyObject_HEAD
// Some extra storage:
char blank[500];
} instance;
static PyObject * get_basicsize(PyObject *self, PyObject * arg)
{
return PyLong_FromLong(((PyTypeObject*)arg)->tp_basicsize);
}
const char *name = "issue2482_object";
static
PyObject *make_object_base_type(void) {
PyHeapTypeObject *heap_type = (PyHeapTypeObject *) PyType_Type.tp_alloc(&PyType_Type, 0);
PyTypeObject *type = &heap_type->ht_type;
if (!heap_type) return NULL;
type->tp_name = name;
#ifdef ISSUE_2482
type->tp_base = &PyBaseObject_Type; /*fails */
#else
type->tp_base = &PyType_Type;
#endif
type->tp_basicsize = sizeof(instance);
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;
if (PyType_Ready(type) < 0)
return NULL;
return (PyObject *) heap_type;
};
static PyMethodDef issue2482_functions[] = {
{"get_basicsize", (PyCFunction)get_basicsize, METH_O, NULL},
{NULL, NULL} /* Sentinel */
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"issue2482",
"Module Doc",
-1,
issue2482_functions,
NULL,
NULL,
NULL,
NULL,
};
#define INITERROR return NULL
/* Initialize this module. */
#ifdef __GNUC__
extern __attribute__((visibility("default")))
#else
extern __declspec(dllexport)
#endif
PyMODINIT_FUNC
PyInit_issue2482(void)
#else
#define INITERROR return
/* Initialize this module. */
#ifdef __GNUC__
extern __attribute__((visibility("default")))
#else
extern __declspec(dllexport)
#endif
PyMODINIT_FUNC
initissue2482(void)
#endif
{
#if PY_MAJOR_VERSION >= 3
PyObject *module = PyModule_Create(&moduledef);
#else
PyObject *module = Py_InitModule("issue2482", issue2482_functions);
#endif
PyHeapTypeObject *heap_type;
PyTypeObject *type;
PyObject * base;
if (module == NULL)
INITERROR;
heap_type = (PyHeapTypeObject *) PyType_Type.tp_alloc(&PyType_Type, 0);
if (!heap_type) INITERROR;
type = &heap_type->ht_type;
type->tp_name = name;
base = make_object_base_type();
if (! base) INITERROR;
Py_INCREF(base);
type->tp_base = (PyTypeObject *) base;
type->tp_basicsize = ((PyTypeObject *) base)->tp_basicsize;
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;
if (PyType_Ready(type) < 0) INITERROR;
PyModule_AddObject(module, name, (PyObject *) type);
#if PY_MAJOR_VERSION >= 3
return module;
#endif
};
|