summaryrefslogtreecommitdiff
path: root/src/strxor.c
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 19:06:58 -0700
committerDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 19:20:43 -0700
commit6fbddf912294b96a66f0e18b32c9312c67455ad5 (patch)
treeff318d3c01a831344c7ba16f14d5d7f2632622f5 /src/strxor.c
parent385830424043c81945a21ca14e051e3b4c282829 (diff)
downloadpycrypto-6fbddf912294b96a66f0e18b32c9312c67455ad5.tar.gz
Py3k cleanup: Module initialization
Diffstat (limited to 'src/strxor.c')
-rw-r--r--src/strxor.c29
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: */