diff options
Diffstat (limited to 'src/strxor.c')
-rw-r--r-- | src/strxor.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/strxor.c b/src/strxor.c index 575d3f8..55d8067 100644 --- a/src/strxor.c +++ b/src/strxor.c @@ -232,25 +232,40 @@ PyInit_strxor(void) initstrxor(void) #endif { - PyObject *m; + PyObject *m = NULL; /* Initialize the module */ #ifdef IS_PY3K m = PyModule_Create(&moduledef); - if (m == NULL) - return NULL; #else m = Py_InitModule("strxor", strxor_methods); - if (m == NULL) - return; #endif - + if (m == NULL) + goto errout; + /* Perform runtime tests */ runtime_test(); +out: + /* Final error check */ + if (m == NULL && !PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "can't initialize module"); + goto errout; + } + + /* Free local objects here */ + + /* Return */ #ifdef IS_PY3K - return m; + return m; +#else + return; #endif + +errout: + /* Free the module and other global objects here */ + Py_CLEAR(m); + goto out; } /* vim:set ts=4 sw=4 sts=4 expandtab: */ |