From 96579d92769c47adbaa00f8407b85f93eb856c66 Mon Sep 17 00:00:00 2001 From: Dwayne Litzenberger Date: Sun, 14 Jul 2013 16:36:31 -0700 Subject: Py3k cleanup: PyType_Ready --- src/_counter.c | 9 +++++---- src/_fastmath.c | 7 ++++--- src/block_template.c | 5 +++-- src/hash_template.c | 5 +++-- src/pycrypto_compat.h | 1 + src/stream_template.c | 5 +++-- src/winrand.c | 4 ++-- 7 files changed, 21 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/_counter.c b/src/_counter.c index 7ab8b95..618ee89 100644 --- a/src/_counter.c +++ b/src/_counter.c @@ -537,7 +537,6 @@ init_counter(void) /* TODO - Is the error handling here correct? */ #ifdef IS_PY3K - /* PyType_Ready automatically fills in ob_type with &PyType_Type if it's not already set */ if (PyType_Ready(&PCT_CounterLEType) < 0) return NULL; if (PyType_Ready(&PCT_CounterBEType) < 0) @@ -549,12 +548,14 @@ init_counter(void) return NULL; #else + if (PyType_Ready(&PCT_CounterLEType) < 0) + return; + if (PyType_Ready(&PCT_CounterBEType) < 0) + return; + m = Py_InitModule("_counter", module_methods); if (m == NULL) return; - - PCT_CounterLEType.ob_type = &PyType_Type; - PCT_CounterBEType.ob_type = &PyType_Type; #endif /* Add the counter types to the module so that epydoc can see them, and so diff --git a/src/_fastmath.c b/src/_fastmath.c index 3be1432..afbe931 100644 --- a/src/_fastmath.c +++ b/src/_fastmath.c @@ -1682,7 +1682,6 @@ init_fastmath (void) PyObject *_fastmath_dict; #ifdef IS_PY3K - /* PyType_Ready automatically fills in ob_type with &PyType_Type if it's not already set */ if (PyType_Ready(&rsaKeyType) < 0) return NULL; if (PyType_Ready(&dsaKeyType) < 0) @@ -1692,8 +1691,10 @@ init_fastmath (void) if (_fastmath_module == NULL) return NULL; #else - rsaKeyType.ob_type = &PyType_Type; - dsaKeyType.ob_type = &PyType_Type; + if (PyType_Ready(&rsaKeyType) < 0) + return; + if (PyType_Ready(&dsaKeyType) < 0) + return; _fastmath_module = Py_InitModule ("_fastmath", _fastmath__methods__); #endif _fastmath_dict = PyModule_GetDict (_fastmath_module); diff --git a/src/block_template.c b/src/block_template.c index c2c711f..d5e68c1 100644 --- a/src/block_template.c +++ b/src/block_template.c @@ -757,7 +757,6 @@ _MODULE_NAME (void) PyObject *m; #ifdef IS_PY3K - /* PyType_Ready automatically fills in ob_type with &PyType_Type if it's not already set */ if (PyType_Ready(&ALGtype) < 0) return NULL; @@ -766,7 +765,9 @@ _MODULE_NAME (void) if (m == NULL) return NULL; #else - ALGtype.ob_type = &PyType_Type; + if (PyType_Ready(&ALGtype) < 0) + return; + /* Create the module and add the functions */ m = Py_InitModule("Crypto.Cipher." _MODULE_STRING, modulemethods); #endif diff --git a/src/hash_template.c b/src/hash_template.c index eb98224..1134942 100644 --- a/src/hash_template.c +++ b/src/hash_template.c @@ -323,7 +323,6 @@ _MODULE_NAME (void) PyObject *m; #ifdef IS_PY3K - /* PyType_Ready automatically fills in ob_type with &PyType_Type if it's not already set */ if (PyType_Ready(&ALGtype) < 0) return NULL; @@ -332,7 +331,9 @@ _MODULE_NAME (void) if (m == NULL) return NULL; #else - ALGtype.ob_type = &PyType_Type; + if (PyType_Ready(&ALGtype) < 0) + return; + m = Py_InitModule3("Crypto.Hash." _MODULE_STRING, ALG_functions, MODULE__doc__); #endif diff --git a/src/pycrypto_compat.h b/src/pycrypto_compat.h index 4f75273..804e54a 100644 --- a/src/pycrypto_compat.h +++ b/src/pycrypto_compat.h @@ -52,6 +52,7 @@ # if PY_MINOR_VERSION <= 1 /* Python 2.1 only */ # define METH_O METH_OLDARGS /* METH_O is a subset of what METH_OLDARGS provides */ # define PyInt_CheckExact PyInt_Check +# define PyType_Ready(t) (((t)->ob_type = &PyType_Type) ? 0 : 0) # endif #endif diff --git a/src/stream_template.c b/src/stream_template.c index 8c14b28..7832484 100644 --- a/src/stream_template.c +++ b/src/stream_template.c @@ -301,7 +301,6 @@ void PyObject *m; #ifdef IS_PY3K - /* PyType_Ready automatically fills in ob_type with &PyType_Type if it's not already set */ if (PyType_Ready(&ALGtype) < 0) return NULL; @@ -310,7 +309,9 @@ void if (m == NULL) return NULL; #else - ALGtype.ob_type = &PyType_Type; + if (PyType_Ready(&ALGtype) < 0) + return; + /* Create the module and add the functions */ m = Py_InitModule("Crypto.Cipher." _MODULE_STRING, modulemethods); #endif diff --git a/src/winrand.c b/src/winrand.c index 149ae5c..09dcf75 100644 --- a/src/winrand.c +++ b/src/winrand.c @@ -285,7 +285,6 @@ initwinrandom() { PyObject *m; #ifdef IS_PY3K - /* PyType_Ready automatically fills in ob_type with &PyType_Type if it's not already set */ if (PyType_Ready(&WRtype) < 0) return NULL; /* Initialize the module */ @@ -293,7 +292,8 @@ initwinrandom() if (m == NULL) return NULL; #else - WRtype.ob_type = &PyType_Type; + if (PyType_Ready(&WRtype) < 0) + return NULL; m = Py_InitModule("winrandom", WR_mod_methods); #endif -- cgit v1.2.1