diff options
author | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-07-14 19:06:58 -0700 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-07-14 19:20:43 -0700 |
commit | 6fbddf912294b96a66f0e18b32c9312c67455ad5 (patch) | |
tree | ff318d3c01a831344c7ba16f14d5d7f2632622f5 /src/hash_template.c | |
parent | 385830424043c81945a21ca14e051e3b4c282829 (diff) | |
download | pycrypto-6fbddf912294b96a66f0e18b32c9312c67455ad5.tar.gz |
Py3k cleanup: Module initialization
Diffstat (limited to 'src/hash_template.c')
-rw-r--r-- | src/hash_template.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/hash_template.c b/src/hash_template.c index f3f116d..106e70b 100644 --- a/src/hash_template.c +++ b/src/hash_template.c @@ -300,32 +300,42 @@ static struct PyModuleDef moduledef = { PyMODINIT_FUNC _MODULE_NAME (void) { - PyObject *m; + PyObject *m = NULL; -#ifdef IS_PY3K if (PyType_Ready(&ALGtype) < 0) - return NULL; + goto errout; /* Create the module and add the functions */ +#ifdef IS_PY3K m = PyModule_Create(&moduledef); - if (m == NULL) - return NULL; #else - if (PyType_Ready(&ALGtype) < 0) - return; - m = Py_InitModule3("Crypto.Hash." _MODULE_STRING, ALG_functions, MODULE__doc__); #endif + if (m == NULL) + goto errout; /* Add some symbolic constants to the module */ PyModule_AddIntConstant(m, "digest_size", DIGEST_SIZE); PyModule_AddIntConstant(m, "block_size", BLOCK_SIZE); - /* Check for errors */ - if (PyErr_Occurred()) - Py_FatalError("can't initialize module " - _MODULE_STRING); +out: + /* Final error check, then return */ + 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; +#else + return; #endif + +errout: + /* Free the module and other global objects here */ + Py_CLEAR(m); + goto out; } |