3232#error "SQLite 3.7.15 or higher required"
3333#endif
3434
35+ #define clinic_state () (pysqlite_get_state(NULL))
3536#include "clinic/module.c.h"
37+ #undef clinic_state
38+
3639/*[clinic input]
3740module _sqlite3
3841[clinic start generated code]*/
@@ -57,12 +60,6 @@ int pysqlite_BaseTypeAdapted = 0;
5760
5861pysqlite_state pysqlite_global_state ;
5962
60- pysqlite_state *
61- pysqlite_get_state (PyObject * Py_UNUSED (module ))
62- {
63- return & pysqlite_global_state ;
64- }
65-
6663static PyObject * module_connect (PyObject * self , PyObject * args , PyObject *
6764 kwargs )
6865{
@@ -93,7 +90,8 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
9390 }
9491
9592 if (factory == NULL ) {
96- factory = (PyObject * )pysqlite_ConnectionType ;
93+ pysqlite_state * state = pysqlite_get_state (self );
94+ factory = (PyObject * )state -> ConnectionType ;
9795 }
9896
9997 return PyObject_Call (factory , args , kwargs );
@@ -176,9 +174,12 @@ pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type,
176174 pysqlite_BaseTypeAdapted = 1 ;
177175 }
178176
179- rc = pysqlite_microprotocols_add (type , (PyObject * )pysqlite_PrepareProtocolType , caster );
180- if (rc == -1 )
177+ pysqlite_state * state = pysqlite_get_state (NULL );
178+ PyObject * protocol = (PyObject * )state -> PrepareProtocolType ;
179+ rc = pysqlite_microprotocols_add (type , protocol , caster );
180+ if (rc == -1 ) {
181181 return NULL ;
182+ }
182183
183184 Py_RETURN_NONE ;
184185}
@@ -240,7 +241,7 @@ pysqlite_enable_callback_trace_impl(PyObject *module, int enable)
240241_sqlite3.adapt as pysqlite_adapt
241242
242243 obj: object
243- proto: object(c_default='(PyObject*)pysqlite_PrepareProtocolType ') = PrepareProtocolType
244+ proto: object(c_default='(PyObject *)clinic_state()->PrepareProtocolType ') = PrepareProtocolType
244245 alt: object = NULL
245246 /
246247
@@ -250,7 +251,7 @@ Adapt given object to given protocol. Non-standard.
250251static PyObject *
251252pysqlite_adapt_impl (PyObject * module , PyObject * obj , PyObject * proto ,
252253 PyObject * alt )
253- /*[clinic end generated code: output=0c3927c5fcd23dd9 input=a58ab77fb5ae22dd ]*/
254+ /*[clinic end generated code: output=0c3927c5fcd23dd9 input=c8995aeb25d0e542 ]*/
254255{
255256 return pysqlite_microprotocols_adapt (obj , proto , alt );
256257}
@@ -358,7 +359,7 @@ static struct PyModuleDef _sqlite3module = {
358359
359360#define ADD_TYPE (module , type ) \
360361do { \
361- if (PyModule_AddType(module, & type) < 0) { \
362+ if (PyModule_AddType(module, type) < 0) { \
362363 goto error; \
363364 } \
364365} while (0)
@@ -392,6 +393,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
392393 }
393394
394395 module = PyModule_Create (& _sqlite3module );
396+ pysqlite_state * state = pysqlite_get_state (module );
395397
396398 if (!module ||
397399 (pysqlite_row_setup_types (module ) < 0 ) ||
@@ -403,10 +405,10 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
403405 goto error ;
404406 }
405407
406- ADD_TYPE (module , * pysqlite_ConnectionType );
407- ADD_TYPE (module , * pysqlite_CursorType );
408- ADD_TYPE (module , * pysqlite_PrepareProtocolType );
409- ADD_TYPE (module , * pysqlite_RowType );
408+ ADD_TYPE (module , state -> ConnectionType );
409+ ADD_TYPE (module , state -> CursorType );
410+ ADD_TYPE (module , state -> PrepareProtocolType );
411+ ADD_TYPE (module , state -> RowType );
410412
411413 /*** Create DB-API Exception hierarchy */
412414 ADD_EXCEPTION (module , "Error" , pysqlite_Error , PyExc_Exception );
0 commit comments