mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-43505: Explicitly initialize and shutdown sqlite3 (GH-25404)
This commit is contained in:
parent
d9ba9dee7f
commit
def919342f
1 changed files with 14 additions and 11 deletions
|
@ -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)
|
||||
|
||||
|
@ -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 ||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue