diff options
Diffstat (limited to 'Modules/_sqlite/module.c')
-rw-r--r-- | Modules/_sqlite/module.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index c60007e..9587cbd 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -32,7 +32,10 @@ #error "SQLite 3.7.15 or higher required" #endif +#define clinic_state() (pysqlite_get_state(NULL)) #include "clinic/module.c.h" +#undef clinic_state + /*[clinic input] module _sqlite3 [clinic start generated code]*/ @@ -57,12 +60,6 @@ int pysqlite_BaseTypeAdapted = 0; pysqlite_state pysqlite_global_state; -pysqlite_state * -pysqlite_get_state(PyObject *Py_UNUSED(module)) -{ - return &pysqlite_global_state; -} - static PyObject* module_connect(PyObject* self, PyObject* args, PyObject* kwargs) { @@ -93,7 +90,8 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject* } if (factory == NULL) { - factory = (PyObject*)pysqlite_ConnectionType; + pysqlite_state *state = pysqlite_get_state(self); + factory = (PyObject *)state->ConnectionType; } return PyObject_Call(factory, args, kwargs); @@ -176,9 +174,12 @@ pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type, pysqlite_BaseTypeAdapted = 1; } - rc = pysqlite_microprotocols_add(type, (PyObject*)pysqlite_PrepareProtocolType, caster); - if (rc == -1) + pysqlite_state *state = pysqlite_get_state(NULL); + PyObject *protocol = (PyObject *)state->PrepareProtocolType; + rc = pysqlite_microprotocols_add(type, protocol, caster); + if (rc == -1) { return NULL; + } Py_RETURN_NONE; } @@ -240,7 +241,7 @@ pysqlite_enable_callback_trace_impl(PyObject *module, int enable) _sqlite3.adapt as pysqlite_adapt obj: object - proto: object(c_default='(PyObject*)pysqlite_PrepareProtocolType') = PrepareProtocolType + proto: object(c_default='(PyObject *)clinic_state()->PrepareProtocolType') = PrepareProtocolType alt: object = NULL / @@ -250,7 +251,7 @@ Adapt given object to given protocol. Non-standard. static PyObject * pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto, PyObject *alt) -/*[clinic end generated code: output=0c3927c5fcd23dd9 input=a58ab77fb5ae22dd]*/ +/*[clinic end generated code: output=0c3927c5fcd23dd9 input=c8995aeb25d0e542]*/ { return pysqlite_microprotocols_adapt(obj, proto, alt); } @@ -358,7 +359,7 @@ static struct PyModuleDef _sqlite3module = { #define ADD_TYPE(module, type) \ do { \ - if (PyModule_AddType(module, &type) < 0) { \ + if (PyModule_AddType(module, type) < 0) { \ goto error; \ } \ } while (0) @@ -392,6 +393,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void) } module = PyModule_Create(&_sqlite3module); + pysqlite_state *state = pysqlite_get_state(module); if (!module || (pysqlite_row_setup_types(module) < 0) || @@ -403,10 +405,10 @@ PyMODINIT_FUNC PyInit__sqlite3(void) goto error; } - ADD_TYPE(module, *pysqlite_ConnectionType); - ADD_TYPE(module, *pysqlite_CursorType); - ADD_TYPE(module, *pysqlite_PrepareProtocolType); - ADD_TYPE(module, *pysqlite_RowType); + ADD_TYPE(module, state->ConnectionType); + ADD_TYPE(module, state->CursorType); + ADD_TYPE(module, state->PrepareProtocolType); + ADD_TYPE(module, state->RowType); /*** Create DB-API Exception hierarchy */ ADD_EXCEPTION(module, "Error", pysqlite_Error, PyExc_Exception); |