8000 Move _pysqlite_converters to global state · python/cpython@33d9dc0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 33d9dc0

Browse files
author
Erlend E. Aasland
committed
Move _pysqlite_converters to global state
1 parent 81b8c0a commit 33d9dc0

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

Modules/_sqlite/cursor.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ _pysqlite_get_converter(const char *keystr, Py_ssize_t keylen)
147147
return NULL;
148148
}
149149

150-
retval = PyDict_GetItemWithError(_pysqlite_converters, upcase_key);
150+
pysqlite_state *state = pysqlite_get_state(NULL);
151+
retval = PyDict_GetItemWithError(state->converters, upcase_key);
151152
Py_DECREF(upcase_key);
152153

153154
return retval;

Modules/_sqlite/module.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module _sqlite3
4242
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
4343

4444
/* static objects at module-level */
45-
PyObject* _pysqlite_converters = NULL;
4645
int _pysqlite_enable_callback_tracebacks = 0;
4746
int pysqlite_BaseTypeAdapted = 0;
4847

@@ -197,7 +196,8 @@ pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
197196
goto error;
198197
}
199198

200-
if (PyDict_SetItem(_pysqlite_converters, name, callable) != 0) {
199+
pysqlite_state *state = pysqlite_get_state(module);
200+
if (PyDict_SetItem(state->converters, name, callable) != 0) {
201201
goto error;
202202
}
203203

@@ -246,15 +246,13 @@ pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
246246

247247
static int converters_init(PyObject* module)
248248
{
249-
_pysqlite_converters = PyDict_New();
250-
if (!_pysqlite_converters) {
249+
pysqlite_state *state = pysqlite_get_state(module);
250+
state->converters = PyDict_New();
251+
if (state->converters == NULL) {
251252
return -1;
252253
}
253254

254-
int res = PyModule_AddObjectRef(module, "converters", _pysqlite_converters);
255-
Py_DECREF(_pysqlite_converters);
256-
257-
return res;
255+
return PyModule_AddObjectRef(module, "converters", state->converters);
258256
}
259257

260258
static int

Modules/_sqlite/module.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ typedef struct {
4141
PyObject *ProgrammingError;
4242
PyObject *Warning;
4343

44+
/* A dictionary, mapping column types (INTEGER, VARCHAR, etc.) to converter
45+
* functions, that convert the SQL value to the appropriate Python value.
46+
* The key is uppercase.
47+
*/
48+
PyObject *converters;
49+
4450
PyObject *lru_cache;
4551

4652
PyTypeObject *ConnectionType;
@@ -58,12 +64,6 @@ pysqlite_get_state(PyObject *Py_UNUSED(module))
5864
return &pysqlite_global_state;
5965
}
6066

61-
/* A dictionary, mapping column types (INTEGER, VARCHAR, etc.) to converter
62-
* functions, that convert the SQL value to the appropriate Python value.
63-
* The key is uppercase.
64-
*/
65-
extern PyObject* _pysqlite_converters;
66-
6767
extern int _pysqlite_enable_callback_tracebacks;
6868
extern int pysqlite_BaseTypeAdapted;
6969

0 commit comments

Comments
 (0)
0