Skip to content

bpo-43505: explicitly initialise and shutdown sqlite3 #25404

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 1 commit into from
Apr 14, 2021
Merged
Changes from all commits
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
25 changes: 14 additions & 11 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,7 @@ static struct PyModuleDef _sqlite3module = {
#define ADD_TYPE(module, type) \
do { \
if (PyModule_AddType(module, &type) < 0) { \
Py_DECREF(module); \
return NULL; \
goto error; \
} \
} while (0)

Expand All @@ -370,6 +369,12 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
return NULL;
}

int rc = sqlite3_initialize();
if (rc != SQLITE_OK) {
PyErr_SetString(PyExc_ImportError, sqlite3_errstr(rc));
return NULL;
}

module = PyModule_Create(&_sqlite3module);

if (!module ||
Expand All @@ -380,8 +385,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
(pysqlite_statement_setup_types(module) < 0) ||
(pysqlite_prepare_protocol_setup_types(module) < 0)
) {
Py_XDECREF(module);
return NULL;
goto error;
}

ADD_TYPE(module, *pysqlite_ConnectionType);
Expand Down Expand Up @@ -428,12 +432,11 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
goto error;
}

error:
if (PyErr_Occurred())
{
PyErr_SetString(PyExc_ImportError, MODULE_NAME ": init failed");
Py_DECREF(module);
module = NULL;
}
return module;

error:
sqlite3_shutdown();
PyErr_SetString(PyExc_ImportError, MODULE_NAME ": init failed");
Py_XDECREF(module);
return NULL;
}