diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2020-11-04 19:31:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 19:31:51 (GMT) |
commit | 789359f47c2a744caa9a405131706099fd7ad6bd (patch) | |
tree | 946fd05f4c0489f766e6b144e763559cda0e95c1 | |
parent | 7184218e186811e75be663be78e57d5302bf8af6 (diff) | |
download | cpython-789359f47c2a744caa9a405131706099fd7ad6bd.zip cpython-789359f47c2a744caa9a405131706099fd7ad6bd.tar.gz cpython-789359f47c2a744caa9a405131706099fd7ad6bd.tar.bz2 |
bpo-1635741: _sqlite3 uses PyModule_AddObjectRef() (GH-23148)
-rw-r--r-- | Modules/_sqlite/microprotocols.c | 8 | ||||
-rw-r--r-- | Modules/_sqlite/module.c | 25 |
2 files changed, 16 insertions, 17 deletions
diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c index cf1fefd..41f0867 100644 --- a/Modules/_sqlite/microprotocols.c +++ b/Modules/_sqlite/microprotocols.c @@ -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; } diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index 3332440..9fdf514 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -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[] = { @@ -361,8 +361,9 @@ do { \ if (!exc) { \ goto error; \ } \ - if (PyModule_AddObject(module, name, exc) < 0) { \ - Py_DECREF(exc); \ + int res = PyModule_AddObjectRef(module, name, exc); \ + Py_DECREF(exc); \ + if (res < 0) { \ goto error; \ } \ } while (0) @@ -416,9 +417,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) { goto error; } @@ -441,7 +440,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void) } /* initialize the default converters */ - converters_init(module); + if (converters_init(module) < 0) { + goto error; + } error: if (PyErr_Occurred()) |