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
Prev Previous commit
Next Next commit
Move pysqlite_BaseTypeAdapted to global state
  • Loading branch information
Erlend E. Aasland committed Jul 14, 2021
commit 650160dbc58340426b231998d5944a9b2667c966
6 changes: 2 additions & 4 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ module _sqlite3
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/

/* static objects at module-level */
int pysqlite_BaseTypeAdapted = 0;

pysqlite_state pysqlite_global_state;

// NOTE: This must equal sqlite3.Connection.__init__ argument spec!
Expand Down Expand Up @@ -157,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);
Expand Down
6 changes: 3 additions & 3 deletions Modules/_sqlite/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ 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;

int enable_callback_tracebacks;
PyObject *lru_cache;
int BaseTypeAdapted;
int enable_callback_tracebacks;

PyTypeObject *ConnectionType;
PyTypeObject *CursorType;
Expand All @@ -65,8 +67,6 @@ pysqlite_get_state(PyObject *Py_UNUSED(module))
return &pysqlite_global_state;
}

extern int pysqlite_BaseTypeAdapted;

#define PARSE_DECLTYPES 1
#define PARSE_COLNAMES 2
#endif
3 changes: 2 additions & 1 deletion Modules/_sqlite/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObjec
/* returns 0 if the object is one of Python's internal ones that don't need to be adapted */
static int _need_adapt(PyObject* obj)
{
if (pysqlite_BaseTypeAdapted) {
pysqlite_state *state = pysqlite_get_state(NULL);
if (state->BaseTypeAdapted) {
return 1;
}

Expand Down
0