Skip to content

Commit fe6d45a

Browse files
committed
Use PyModule_AddObjectRef where possible
1 parent c3d4ac9 commit fe6d45a

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

src/apsw.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,9 +2079,8 @@ PyInit_apsw(void)
20792079
#define ADD(name, item) \
20802080
do \
20812081
{ \
2082-
if (PyModule_AddObject(m, #name, (PyObject *)&item)) \
2082+
if (PyModule_AddObjectRef(m, #name, (PyObject *)&item)) \
20832083
goto fail; \
2084-
Py_INCREF(&item); \
20852084
} while (0)
20862085

20872086
ADD(Connection, ConnectionType);
@@ -2155,10 +2154,10 @@ PyInit_apsw(void)
21552154
*/
21562155

21572156
#ifdef APSW_USE_SQLITE_AMALGAMATION
2158-
if (PyModule_AddObject(m, "using_amalgamation", Py_NewRef(Py_True)))
2157+
if (PyModule_AddObjectRef(m, "using_amalgamation", Py_True))
21592158
goto fail;
21602159
#else
2161-
if (PyModule_AddObject(m, "using_amalgamation", Py_NewRef(Py_False)))
2160+
if (PyModule_AddObjectRef(m, "using_amalgamation", Py_False))
21622161
goto fail;
21632162
#endif
21642163

@@ -2244,7 +2243,7 @@ PyInit_apsw(void)
22442243
goto fail;
22452244
}
22462245

2247-
if (PyModule_AddObject(m, "no_change", Py_NewRef(apsw_no_change_object)))
2246+
if (PyModule_AddObjectRef(m, "no_change", apsw_no_change_object))
22482247
goto fail;
22492248

22502249
/* undocumented sentinel to do no bindings */
@@ -2253,11 +2252,11 @@ PyInit_apsw(void)
22532252
if (!apsw_cursor_null_bindings)
22542253
goto fail;
22552254

2256-
if (PyModule_AddObject(m, "_null_bindings", Py_NewRef(apsw_cursor_null_bindings)))
2255+
if (PyModule_AddObjectRef(m, "_null_bindings", apsw_cursor_null_bindings))
22572256
goto fail;
22582257

22592258
#ifdef APSW_FAULT_INJECT
2260-
if (PyModule_AddObject(m, "apsw_fault_inject", Py_NewRef(Py_True)))
2259+
if (PyModule_AddObjectRef(m, "apsw_fault_inject", Py_True))
22612260
goto fail;
22622261
#endif
22632262

src/exceptions.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,12 @@ init_exceptions(PyObject *m)
114114
{ &ExcNoFTS5, "NoFTS5Error", NoFTS5Error_exc_DOC },
115115
{ &ExcInvalidContext, "InvalidContextError", InvalidContextError_exc_DOC } };
116116

117-
/* PyModule_AddObject uses borrowed reference so we incref whatever
118-
we give to it, so we still have a copy to use */
119-
120117
/* custom ones first */
121118

122119
APSWException = PyErr_NewExceptionWithDoc("apsw.Error", Error_exc_DOC, NULL, NULL);
123120
if (!APSWException)
124121
return -1;
125-
if (PyModule_AddObject(m, "Error", Py_NewRef((PyObject *)APSWException)))
122+
if (PyModule_AddObjectRef(m, "Error", (PyObject *)APSWException))
126123
return -1;
127124

128125
for (i = 0; i < sizeof(apswexceptions) / sizeof(apswexceptions[0]); i++)

0 commit comments

Comments
 (0)