@@ -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
279279static 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
446447error :
447448 if (PyErr_Occurred ())
0 commit comments