proper module init
This commit is contained in:
@ -292,10 +292,12 @@ static PyTypeObject pyField_type = {
|
|||||||
sizeof(pyField),
|
sizeof(pyField),
|
||||||
};
|
};
|
||||||
|
|
||||||
int pyField_prepare(void)
|
int pyField_prepare(PyObject *module)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
import_array1(-1);
|
||||||
|
|
||||||
pyField_type.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
|
pyField_type.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
|
||||||
#if PY_MAJOR_VERSION < 3
|
#if PY_MAJOR_VERSION < 3
|
||||||
pyField_type.tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER|Py_TPFLAGS_HAVE_NEWBUFFER;
|
pyField_type.tp_flags |= Py_TPFLAGS_HAVE_GETCHARBUFFER|Py_TPFLAGS_HAVE_NEWBUFFER;
|
||||||
@ -308,7 +310,12 @@ int pyField_prepare(void)
|
|||||||
if(PyType_Ready(&pyField_type)<0)
|
if(PyType_Ready(&pyField_type)<0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
import_array1(-1);
|
PyObject *typeobj=(PyObject*)&pyField_type;
|
||||||
|
Py_INCREF(typeobj);
|
||||||
|
if(PyModule_AddObject(module, "_Field", typeobj)) {
|
||||||
|
Py_DECREF(typeobj);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_NUMPY
|
#ifdef HAVE_NUMPY
|
||||||
for(i=0; i<=DBF_MENU; i++) {
|
for(i=0; i<=DBF_MENU; i++) {
|
||||||
@ -320,13 +327,6 @@ int pyField_prepare(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pyField_setup(PyObject *module)
|
|
||||||
{
|
|
||||||
PyObject *typeobj=(PyObject*)&pyField_type;
|
|
||||||
Py_INCREF(typeobj);
|
|
||||||
PyModule_AddObject(module, "_Field", (PyObject*)&pyField_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
void pyField_cleanup(void)
|
void pyField_cleanup(void)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -324,8 +324,10 @@ static PyTypeObject pyRecord_type = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int pyRecord_prepare(void)
|
int pyRecord_prepare(PyObject *module)
|
||||||
{
|
{
|
||||||
|
PyObject *typeobj=(PyObject*)&pyRecord_type;
|
||||||
|
|
||||||
pyRecord_type.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
|
pyRecord_type.tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE;
|
||||||
pyRecord_type.tp_methods = pyRecord_methods;
|
pyRecord_type.tp_methods = pyRecord_methods;
|
||||||
|
|
||||||
@ -338,12 +340,12 @@ int pyRecord_prepare(void)
|
|||||||
|
|
||||||
if(PyType_Ready(&pyRecord_type)<0)
|
if(PyType_Ready(&pyRecord_type)<0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
Py_INCREF(typeobj);
|
||||||
|
if(PyModule_AddObject(module, "_Record", typeobj)) {
|
||||||
|
Py_DECREF(typeobj);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pyRecord_setup(PyObject *module)
|
|
||||||
{
|
|
||||||
PyObject *typeobj=(PyObject*)&pyRecord_type;
|
|
||||||
Py_INCREF(typeobj);
|
|
||||||
PyModule_AddObject(module, "_Record", (PyObject*)&pyRecord_type);
|
|
||||||
}
|
|
||||||
|
@ -13,12 +13,10 @@
|
|||||||
#endif
|
#endif
|
||||||
void pyDBD_cleanup(void);
|
void pyDBD_cleanup(void);
|
||||||
|
|
||||||
int pyField_prepare(void);
|
int pyField_prepare(PyObject *module);
|
||||||
void pyField_setup(PyObject *module);
|
|
||||||
void pyField_cleanup(void);
|
void pyField_cleanup(void);
|
||||||
|
|
||||||
int pyRecord_prepare(void);
|
int pyRecord_prepare(PyObject *module);
|
||||||
void pyRecord_setup(PyObject *module);
|
|
||||||
|
|
||||||
int isPyRecord(dbCommon *);
|
int isPyRecord(dbCommon *);
|
||||||
int canIOScanRecord(dbCommon *);
|
int canIOScanRecord(dbCommon *);
|
||||||
|
@ -150,40 +150,45 @@ static struct PyModuleDef dbapimodule = {
|
|||||||
/* initialize "magic" builtin module */
|
/* initialize "magic" builtin module */
|
||||||
PyMODINIT_FUNC init_dbapi(void)
|
PyMODINIT_FUNC init_dbapi(void)
|
||||||
{
|
{
|
||||||
PyObject *mod, *hookdict, *pysuptable;
|
PyObject *mod = NULL, *hookdict;
|
||||||
pystate *st;
|
pystate *st;
|
||||||
|
|
||||||
import_array();
|
import_array();
|
||||||
|
|
||||||
if(pyField_prepare())
|
|
||||||
MODINIT_RET(NULL);
|
|
||||||
if(pyRecord_prepare())
|
|
||||||
MODINIT_RET(NULL);
|
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3
|
||||||
mod = PyModule_Create(&dbapimodule);
|
mod = PyModule_Create(&dbapimodule);
|
||||||
#else
|
#else
|
||||||
mod = Py_InitModule("_dbapi", devsup_methods);
|
mod = Py_InitModule("_dbapi", devsup_methods);
|
||||||
#endif
|
#endif
|
||||||
|
if(!mod)
|
||||||
pysuptable = PySet_New(NULL);
|
goto fail;
|
||||||
if(!pysuptable)
|
|
||||||
MODINIT_RET(NULL);
|
|
||||||
PyModule_AddObject(mod, "_supports", pysuptable);
|
|
||||||
|
|
||||||
hookdict = PyDict_New();
|
hookdict = PyDict_New();
|
||||||
if(!hookdict)
|
if(!hookdict)
|
||||||
MODINIT_RET(NULL);
|
goto fail;
|
||||||
|
|
||||||
PyModule_AddObject(mod, "_hooks", hookdict);
|
PyModule_AddObject(mod, "_hooks", hookdict);
|
||||||
|
|
||||||
for(st = statenames; st->name; st++) {
|
for(st = statenames; st->name; st++) {
|
||||||
PyDict_SetItemString(hookdict, st->name, PyInt_FromLong((long)st->state));
|
PyObject *ent = PyInt_FromLong((long)st->state);
|
||||||
|
if(!ent) goto fail;
|
||||||
|
if(PyDict_SetItemString(hookdict, st->name, ent)) {
|
||||||
|
Py_DECREF(ent);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pyField_setup(mod);
|
if(pyField_prepare(mod))
|
||||||
pyRecord_setup(mod);
|
goto fail;
|
||||||
|
if(pyRecord_prepare(mod))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
MODINIT_RET(mod);
|
MODINIT_RET(mod);
|
||||||
|
|
||||||
|
fail:
|
||||||
|
fprintf(stderr, "Failed to initialize builtin _dbapi module!\n");
|
||||||
|
Py_XDECREF(mod);
|
||||||
|
MODINIT_RET(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanupPy(void *junk)
|
static void cleanupPy(void *junk)
|
||||||
|
Reference in New Issue
Block a user