Visitar URL original
bpo-42064: Finalise establishing sqlite3 global state by erlend-aasland · Pull Request #27155 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move psyco_adapters to global state
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed Jul 14, 2021
commit 300ba6c142f41ccece916ec27d85cd419e25ed53
19 changes: 8 additions & 11 deletions Modules/_sqlite/microprotocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,20 @@
#include "microprotocols.h"
#include "prepare_protocol.h"

/** the adapters registry **/

static PyObject *psyco_adapters = NULL;

/* pysqlite_microprotocols_init - initialize the adapters dictionary */

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);
}


Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions Modules/_sqlite/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef struct {
PyObject *converters;

PyObject *lru_cache;
PyObject *psyco_adapters; // The adapters registry
int BaseTypeAdapted;
int enable_callback_tracebacks;

Expand Down