-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
bpo-1635741: _sqlite3 uses PyModule_AddObjectRef #23148
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
Changes from 1 commit
c062592
590d11d
23ba6fa
cdae05e
911ee5a
a4bb4bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,17 +263,19 @@ pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto, | |
return pysqlite_microprotocols_adapt(obj, proto, alt); | ||
} | ||
|
||
static void converters_init(PyObject* module) | ||
static int converters_init(PyObject* module) | ||
{ | ||
int res; | ||
|
||
_pysqlite_converters = PyDict_New(); | ||
if (!_pysqlite_converters) { | ||
return; | ||
return -1; | ||
} | ||
|
||
if (PyModule_AddObject(module, "converters", _pysqlite_converters) < 0) { | ||
Py_DECREF(_pysqlite_converters); | ||
} | ||
return; | ||
res = PyModule_AddObjectRef(module, "converters", _pysqlite_converters); | ||
Py_DECREF(_pysqlite_converters); | ||
|
||
return res; | ||
} | ||
|
||
static PyMethodDef module_methods[] = { | ||
|
@@ -357,19 +359,22 @@ do { \ | |
|
||
#define ADD_EXCEPTION(module, name, exc, base) \ | ||
do { \ | ||
int res; \ | ||
exc = PyErr_NewException(MODULE_NAME "." name, base, NULL); \ | ||
if (!exc) { \ | ||
goto error; \ | ||
} \ | ||
if (PyModule_AddObject(module, name, exc) < 0) { \ | ||
Py_DECREF(exc); \ | ||
res = PyModule_AddObjectRef(module, name, exc); \ | ||
Py_DECREF(exc); \ | ||
if (res == -1) { \ | ||
erlend-aasland marked this conversation as resolved.
Show resolved
Hide resolved
|
||
goto error; \ | ||
} \ | ||
} while (0) | ||
|
||
PyMODINIT_FUNC PyInit__sqlite3(void) | ||
{ | ||
PyObject *module; | ||
int res; | ||
|
||
if (sqlite3_libversion_number() < 3007003) { | ||
PyErr_SetString(PyExc_ImportError, MODULE_NAME ": SQLite 3.7.3 or higher required"); | ||
|
@@ -417,8 +422,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void) | |
Now OptimizedUnicode is an alias for str, so it has no | ||
effect. */ | ||
Py_INCREF((PyObject*)&PyUnicode_Type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call looks like a ref leak. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the (now) useless INCREF/DECREF dance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it; thanks! |
||
if (PyModule_AddObject(module, "OptimizedUnicode", (PyObject*)&PyUnicode_Type) < 0) { | ||
Py_DECREF((PyObject*)&PyUnicode_Type); | ||
res = PyModule_AddObjectRef(module, "OptimizedUnicode", (PyObject*)&PyUnicode_Type); | ||
Py_DECREF((PyObject*)&PyUnicode_Type); | ||
if (res == -1) { | ||
goto error; | ||
} | ||
|
||
|
@@ -441,7 +447,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void) | |
} | ||
|
||
/* initialize the default converters */ | ||
converters_init(module); | ||
if (converters_init(module) < 0) { | ||
goto error; | ||
} | ||
|
||
error: | ||
if (PyErr_Occurred()) | ||
|
Uh oh!
There was an error while loading. Please reload this page.