Skip to content
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

bpo-1635741: _sqlite3 uses PyModule_AddObjectRef #23148

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 3 additions & 5 deletions Modules/_sqlite/microprotocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ pysqlite_microprotocols_init(PyObject *module)
return -1;
}

if (PyModule_AddObject(module, "adapters", psyco_adapters) < 0) {
Py_DECREF(psyco_adapters);
return -1;
}
int res = PyModule_AddObjectRef(module, "adapters", psyco_adapters);
Py_DECREF(psyco_adapters);

return 0;
return res;
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
}


Expand Down
26 changes: 14 additions & 12 deletions Modules/_sqlite/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,17 @@ 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)
{
_pysqlite_converters = PyDict_New();
if (!_pysqlite_converters) {
return;
return -1;
}

if (PyModule_AddObject(module, "converters", _pysqlite_converters) < 0) {
Py_DECREF(_pysqlite_converters);
}
return;
int res = PyModule_AddObjectRef(module, "converters", _pysqlite_converters);
Py_DECREF(_pysqlite_converters);

return res;
}

static PyMethodDef module_methods[] = {
Expand Down Expand Up @@ -357,12 +357,14 @@ 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 < 0) { \
goto error; \
} \
} while (0)
Expand Down Expand Up @@ -416,9 +418,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
non-ASCII data and bytestrings to be returned for ASCII data.
Now OptimizedUnicode is an alias for str, so it has no
effect. */
Py_INCREF((PyObject*)&PyUnicode_Type);
if (PyModule_AddObject(module, "OptimizedUnicode", (PyObject*)&PyUnicode_Type) < 0) {
Py_DECREF((PyObject*)&PyUnicode_Type);
if (PyModule_AddObjectRef(module, "OptimizedUnicode", (PyObject*)&PyUnicode_Type) < 0) {
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
goto error;
}

Expand All @@ -441,7 +441,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
}

/* initialize the default converters */
converters_init(module);
if (converters_init(module) < 0) {
goto error;
}

error:
if (PyErr_Occurred())
Expand Down