Skip to content

Commit 3213e91

Browse files
Erlend Egeberg Aaslandadorilson
authored andcommitted
bpo-1635741: _sqlite3 uses PyModule_AddObjectRef() (pythonGH-23148)
1 parent 1ba72a3 commit 3213e91

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

Modules/_sqlite/microprotocols.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ pysqlite_microprotocols_init(PyObject *module)
4343
return -1;
4444
}
4545

46-
if (PyModule_AddObject(module, "adapters", psyco_adapters) < 0) {
47-
Py_DECREF(psyco_adapters);
48-
return -1;
49-
}
46+
int res = PyModule_AddObjectRef(module, "adapters", psyco_adapters);
47+
Py_DECREF(psyco_adapters);
5048

51-
return 0;
49+
return res;
5250
}
5351

5452

Modules/_sqlite/module.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,17 @@ pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
263263
return pysqlite_microprotocols_adapt(obj, proto, alt);
264264
}
265265

266-
static void converters_init(PyObject* module)
266+
static int converters_init(PyObject* module)
267267
{
268268
_pysqlite_converters = PyDict_New();
269269
if (!_pysqlite_converters) {
270-
return;
270+
return -1;
271271
}
272272

273-
if (PyModule_AddObject(module, "converters", _pysqlite_converters) < 0) {
274-
Py_DECREF(_pysqlite_converters);
275-
}
276-
return;
273+
int res = PyModule_AddObjectRef(module, "converters", _pysqlite_converters);
274+
Py_DECREF(_pysqlite_converters);
275+
276+
return res;
277277
}
278278

279279
static PyMethodDef module_methods[] = {
@@ -361,8 +361,9 @@ do { \
361361
if (!exc) { \
362362
goto error; \
363363
} \
364-
if (PyModule_AddObject(module, name, exc) < 0) { \
365-
Py_DECREF(exc); \
364+
int res = PyModule_AddObjectRef(module, name, exc); \
365+
Py_DECREF(exc); \
366+
if (res < 0) { \
366367
goto error; \
367368
} \
368369
} while (0)
@@ -416,9 +417,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
416417
non-ASCII data and bytestrings to be returned for ASCII data.
417418
Now OptimizedUnicode is an alias for str, so it has no
418419
effect. */
419-
Py_INCREF((PyObject*)&PyUnicode_Type);
420-
if (PyModule_AddObject(module, "OptimizedUnicode", (PyObject*)&PyUnicode_Type) < 0) {
421-
Py_DECREF((PyObject*)&PyUnicode_Type);
420+
if (PyModule_AddObjectRef(module, "OptimizedUnicode", (PyObject*)&PyUnicode_Type) < 0) {
422421
goto error;
423422
}
424423

@@ -441,7 +440,9 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
441440
}
442441

443442
/* initialize the default converters */
444-
converters_init(module);
443+
if (converters_init(module) < 0) {
444+
goto error;
445+
}
445446

446447
error:
447448
if (PyErr_Occurred())

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy