8000 bpo-42064: Finalise establishing sqlite3 global state by erlend-aasland · Pull Request #27155 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-42064: Finalise establishing sqlite3 global state #27155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 20, 2021
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
Next Next commit
Move _pysqlite_converters to global state
  • Loading branch information
Erlend E. Aasland committed Jul 14, 2021
commit 33d9dc06fe6c86940bb4ffafdd4ad43bc81e3bb1
3 changes: 2 additions & 1 deletion Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ _pysqlite_get_converter(const char *keystr, Py_ssize_t keylen)
return NULL;
}

retval = PyDict_GetItemWithError(_pysqlite_converters, upcase_key);
pysqlite_state *state = pysqlite_get_state(NULL);
retval = PyDict_GetItemWithError(state->converters, upcase_key);
Py_DECREF(upcase_key);

return retval;
Expand Down
14 changes: 6 additions & 8 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module _sqlite3
/*[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;

Expand Down Expand Up @@ -197,7 +196,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;
}

Expand Down Expand Up @@ -246,15 +246,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
Expand Down
12 changes: 6 additions & 6 deletions Modules/_sqlite/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ typedef struct {
PyObject *ProgrammingError;
PyObject *Warning;

/* A dictionary, mapping column types (INTEGER, VARCHAR, etc.) to converter
* functions, that convert the SQL value to the appropriate Python value.
* The key is uppercase.
*/
PyObject *converters;

PyObject *lru_cache;

PyTypeObject *ConnectionType;
Expand All @@ -58,12 +64,6 @@ pysqlite_get_state(PyObject *Py_UNUSED(module))
return &pysqlite_global_state;
}

/* A dictionary, mapping column types (INTEGER, VARCHAR, etc.) to converter
* functions, that convert the SQL value to the appropriate Python value.
* The key is uppercase.
*/
extern PyObject* _pysqlite_converters;

extern int _pysqlite_enable_callback_tracebacks;
extern int pysqlite_BaseTypeAdapted;

Expand Down
0