@@ -346,6 +346,14 @@ static struct PyModuleDef _sqlite3module = {
346
346
NULL
347
347
};
348
348
349
+ #define ADD_TYPE (module , type ) \
350
+ do { \
351
+ if (PyModule_AddType(module, &type) < 0) { \
352
+ Py_DECREF(module); \
353
+ return NULL; \
354
+ } \
355
+ } while (0)
356
+
349
357
PyMODINIT_FUNC PyInit__sqlite3 (void )
350
358
{
351
359
PyObject * module , * dict ;
@@ -366,14 +374,10 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
366
374
return NULL ;
367
375
}
368
376
369
- Py_INCREF (& pysqlite_ConnectionType );
370
- PyModule_AddObject (module , "Connection" , (PyObject * ) & pysqlite_ConnectionType );
371
- Py_INCREF (& pysqlite_CursorType );
372
- PyModule_AddObject (module , "Cursor" , (PyObject * ) & pysqlite_CursorType );
373
- Py_INCREF (& pysqlite_PrepareProtocolType );
374
- PyModule_AddObject (module , "PrepareProtocol" , (PyObject * ) & pysqlite_PrepareProtocolType );
375
- Py_INCREF (& pysqlite_RowType );
376
- PyModule_AddObject (module , "Row" , (PyObject * ) & pysqlite_RowType );
377
+ ADD_TYPE (module , pysqlite_ConnectionType );
378
+ ADD_TYPE (module , pysqlite_CursorType );
379
+ ADD_TYPE (module , pysqlite_PrepareProtocolType );
380
+ ADD_TYPE (module , pysqlite_RowType );
377
381
378
382
if (!(dict = PyModule_GetDict (module ))) {
379
383
goto error ;
0 commit comments