summaryrefslogtreecommitdiffstats
path: root/Modules/_sqlite/microprotocols.c
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2021-07-20 10:59:18 (GMT)
committerGitHub <noreply@github.com>2021-07-20 10:59:18 (GMT)
commit4c0deb25ac899fbe4da626ce3cb21f204cdd3aa9 (patch)
tree4f2aa2801e9981d143d1f9a5dd543f2ea8579859 /Modules/_sqlite/microprotocols.c
parent366fcbac18e3adc41e3901580dbedb6a91e41a10 (diff)
downloadcpython-4c0deb25ac899fbe4da626ce3cb21f204cdd3aa9.zip
cpython-4c0deb25ac899fbe4da626ce3cb21f204cdd3aa9.tar.gz
cpython-4c0deb25ac899fbe4da626ce3cb21f204cdd3aa9.tar.bz2
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
Diffstat (limited to 'Modules/_sqlite/microprotocols.c')
-rw-r--r--Modules/_sqlite/microprotocols.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c
index e72fc92..160d7b9 100644
--- a/Modules/_sqlite/microprotocols.c
+++ b/Modules/_sqlite/microprotocols.c
@@ -29,9 +29,6 @@
#include "microprotocols.h"
#include "prepare_protocol.h"
-/** the adapters registry **/
-
-static PyObject *psyco_adapters = NULL;
/* pysqlite_microprotocols_init - initialize the adapters dictionary */
@@ -39,14 +36,13 @@ int
pysqlite_microprotocols_init(PyObject *module)
{
/* create adapters dictionary and put it in module namespace */
- if ((psyco_adapters = PyDict_New()) == NULL) {
+ pysqlite_state *state = pysqlite_get_state(module);
+ state->psyco_adapters = PyDict_New();
+ if (state->psyco_adapters == NULL) {
return -1;
}
- int res = PyModule_AddObjectRef(module, "adapters", psyco_adapters);
- Py_DECREF(psyco_adapters);
-
- return res;
+ return PyModule_AddObjectRef(module, "adapters", state->psyco_adapters);
}
@@ -65,7 +61,8 @@ pysqlite_microprotocols_add(PyTypeObject *type, PyObject *proto, PyObject *cast)
return -1;
}
- rc = PyDict_SetItem(psyco_adapters, key, cast);
+ pysqlite_state *state = pysqlite_get_state(NULL);
+ rc = PyDict_SetItem(state->psyco_adapters, key, cast);
Py_DECREF(key);
return rc;
@@ -89,7 +86,8 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
if (!key) {
return NULL;
}
- adapter = PyDict_GetItemWithError(psyco_adapters, key);
+ pysqlite_state *state = pysqlite_get_state(NULL);
+ adapter = PyDict_GetItemWithError(state->psyco_adapters, key);
Py_DECREF(key);
if (adapter) {
Py_INCREF(adapter);
@@ -143,7 +141,6 @@ pysqlite_microprotocols_adapt(PyObject *obj, PyObject *proto, PyObject *alt)
return Py_NewRef(alt);
}
/* else set the right exception and return NULL */
- pysqlite_state *state = pysqlite_get_state(NULL);
PyErr_SetString(state->ProgrammingError, "can't adapt");
return NULL;
}