mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-42064: Finalise establishing sqlite3 global state (GH-27155)
With this, all sqlite3 static globals have been moved to the global state. There are a couple of global static strings left, but there should be no need for adding them to the state. https://bugs.python.org/issue42064
This commit is contained in:
parent
366fcbac18
commit
4c0deb25ac
6 changed files with 69 additions and 53 deletions
|
|
@ -41,11 +41,6 @@ module _sqlite3
|
|||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
|
||||
|
||||
/* static objects at module-level */
|
||||
PyObject* _pysqlite_converters = NULL;
|
||||
int _pysqlite_enable_callback_tracebacks = 0;
|
||||
int pysqlite_BaseTypeAdapted = 0;
|
||||
|
||||
pysqlite_state pysqlite_global_state;
|
||||
|
||||
// NOTE: This must equal sqlite3.Connection.__init__ argument spec!
|
||||
|
|
@ -159,7 +154,8 @@ pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type,
|
|||
* (99 % of all usages) */
|
||||
if (type == &PyLong_Type || type == &PyFloat_Type
|
||||
|| type == &PyUnicode_Type || type == &PyByteArray_Type) {
|
||||
pysqlite_BaseTypeAdapted = 1;
|
||||
pysqlite_state *state = pysqlite_get_state(module);
|
||||
state->BaseTypeAdapted = 1;
|
||||
}
|
||||
|
||||
pysqlite_state *state = pysqlite_get_state(NULL);
|
||||
|
|
@ -197,7 +193,8 @@ pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (PyDict_SetItem(_pysqlite_converters, name, callable) != 0) {
|
||||
pysqlite_state *state = pysqlite_get_state(module);
|
||||
if (PyDict_SetItem(state->converters, name, callable) != 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +217,8 @@ static PyObject *
|
|||
pysqlite_enable_callback_trace_impl(PyObject *module, int enable)
|
||||
/*[clinic end generated code: output=4ff1d051c698f194 input=cb79d3581eb77c40]*/
|
||||
{
|
||||
_pysqlite_enable_callback_tracebacks = enable;
|
||||
pysqlite_state *state = pysqlite_get_state(module);
|
||||
state->enable_callback_tracebacks = enable;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
|
@ -246,15 +244,13 @@ pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
|
|||
|
||||
static int converters_init(PyObject* module)
|
||||
{
|
||||
_pysqlite_converters = PyDict_New();
|
||||
if (!_pysqlite_converters) {
|
||||
pysqlite_state *state = pysqlite_get_state(module);
|
||||
state->converters = PyDict_New();
|
||||
if (state->converters == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int res = PyModule_AddObjectRef(module, "converters", _pysqlite_converters);
|
||||
Py_DECREF(_pysqlite_converters);
|
||||
|
||||
return res;
|
||||
return PyModule_AddObjectRef(module, "converters", state->converters);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue