File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -343,8 +343,7 @@ static struct PyModuleDef _sqlite3module = {
343
343
#define ADD_TYPE (module , type ) \
344
344
do { \
345
345
if (PyModule_AddType(module, &type) < 0) { \
346
- Py_DECREF(module); \
347
- return NULL; \
346
+ goto error; \
348
347
} \
349
348
} while (0)
350
349
@@ -370,6 +369,12 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
370
369
return NULL ;
371
370
}
372
371
372
+ int rc = sqlite3_initialize ();
373
+ if (rc != SQLITE_OK ) {
374
+ PyErr_SetString (PyExc_ImportError , sqlite3_errstr (rc ));
375
+ return NULL ;
376
+ }
377
+
373
378
module = PyModule_Create (& _sqlite3module );
374
379
375
380
if (!module ||
@@ -380,8 +385,7 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
380
385
(pysqlite_statement_setup_types (module ) < 0 ) ||
381
386
(pysqlite_prepare_protocol_setup_types (module ) < 0 )
382
387
) {
383
- Py_XDECREF (module );
384
- return NULL ;
388
+ goto error ;
385
389
}
386
390
387
391
ADD_TYPE (module , * pysqlite_ConnectionType );
@@ -428,12 +432,11 @@ PyMODINIT_FUNC PyInit__sqlite3(void)
428
432
goto error ;
429
433
}
430
434
431
- error :
432
- if (PyErr_Occurred ())
433
- {
434
- PyErr_SetString (PyExc_ImportError , MODULE_NAME ": init failed" );
435
- Py_DECREF (module );
436
- module = NULL ;
437
- }
438
435
return module ;
436
+
437
+ error :
438
+ sqlite3_shutdown ();
439
+ PyErr_SetString (PyExc_ImportError , MODULE_NAME ": init failed" );
440
+ Py_XDECREF (module );
441
+ return NULL ;
439
442
}
You can’t perform that action at this time.
0 commit comments