summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 16:36:31 -0700
committerDwayne Litzenberger <dlitz@dlitz.net>2013-07-14 19:14:35 -0700
commit96579d92769c47adbaa00f8407b85f93eb856c66 (patch)
tree4f378688cdde607476e18a8f30b232cee228efc2 /src
parent52287434f824732c52ba21b771a9626c312ca4e9 (diff)
downloadpycrypto-96579d92769c47adbaa00f8407b85f93eb856c66.tar.gz
Py3k cleanup: PyType_Ready
Diffstat (limited to 'src')
-rw-r--r--src/_counter.c9
-rw-r--r--src/_fastmath.c7
-rw-r--r--src/block_template.c5
-rw-r--r--src/hash_template.c5
-rw-r--r--src/pycrypto_compat.h1
-rw-r--r--src/stream_template.c5
-rw-r--r--src/winrand.c4
7 files changed, 21 insertions, 15 deletions
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