From ea2cf0afd8ccbaa406b107285648e024bc900b64 Mon Sep 17 00:00:00 2001 From: Dwayne Litzenberger Date: Sun, 14 Jul 2013 16:17:01 -0700 Subject: Py3k cleanup: PyModule_AddIntConstant --- src/_counter.c | 7 ------- src/block_template.c | 3 --- src/hash_template.c | 7 ------- src/pycrypto_compat.h | 12 ++++++++++++ src/stream_template.c | 7 ------- 5 files changed, 12 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/_counter.c b/src/_counter.c index 2bd33ae..7ab8b95 100644 --- a/src/_counter.c +++ b/src/_counter.c @@ -28,13 +28,6 @@ #include #include "_counter.h" -/* Deal with old API in Python 2.1 */ -#if PYTHON_API_VERSION < 1011 -#define PyModule_AddIntConstant(m,n,v) {PyObject *o=PyInt_FromLong(v); \ - if (o!=NULL) \ - {PyDict_SetItemString(PyModule_GetDict(m),n,o); Py_DECREF(o);}} -#endif - /* NB: This can be called multiple times for a given object, via the __init__ method. Be careful. */ static int CounterObject_init(PCT_CounterObject *self, PyObject *args, PyObject *kwargs) diff --git a/src/block_template.c b/src/block_template.c index 6a1ec93..f12fbfb 100644 --- a/src/block_template.c +++ b/src/block_template.c @@ -761,9 +761,6 @@ static struct PyModuleDef moduledef = { /* Deal with old API in Python 2.1 */ #if PYTHON_API_VERSION < 1011 -#define PyModule_AddIntConstant(m,n,v) {PyObject *o=PyInt_FromLong(v); \ - if (o!=NULL) \ - {PyDict_SetItemString(PyModule_GetDict(m),n,o); Py_DECREF(o);}} #define PyInt_CheckExact PyInt_Check #endif diff --git a/src/hash_template.c b/src/hash_template.c index cc66544..1bc6847 100644 --- a/src/hash_template.c +++ b/src/hash_template.c @@ -317,13 +317,6 @@ static struct PyModuleDef moduledef = { /* Initialize this module. */ -/* Deal with old API in Python 2.1 */ -#if PYTHON_API_VERSION < 1011 -#define PyModule_AddIntConstant(m,n,v) {PyObject *o=PyInt_FromLong(v); \ - if (o!=NULL) \ - {PyDict_SetItemString(PyModule_GetDict(m),n,o); Py_DECREF(o);}} -#endif - #ifdef IS_PY3K PyMODINIT_FUNC #else diff --git a/src/pycrypto_compat.h b/src/pycrypto_compat.h index 6234839..ccaf21a 100644 --- a/src/pycrypto_compat.h +++ b/src/pycrypto_compat.h @@ -47,6 +47,18 @@ # endif #endif +/* Python 2.1 doesn't have PyModule_AddIntConstant */ +#if PYTHON_API_VERSION < 1011 +#define PyModule_AddIntConstant(m,n,v) \ + do { \ + PyObject *o=PyInt_FromLong(v); \ + if (o!=NULL) { \ + PyObject_SetAttrString((m),(n),o); \ + Py_DECREF(o); \ + } \ + } while(0) +#endif + /* * Py_CLEAR for Python < 2.4 * See http://docs.python.org/api/countingRefs.html diff --git a/src/stream_template.c b/src/stream_template.c index 5456664..9c5a99a 100644 --- a/src/stream_template.c +++ b/src/stream_template.c @@ -300,13 +300,6 @@ static PyTypeObject ALGtype = /* Initialization function for the module */ -/* Deal with old API in Python 2.1 */ -#if PYTHON_API_VERSION < 1011 -#define PyModule_AddIntConstant(m,n,v) {PyObject *o=PyInt_FromLong(v); \ - if (o!=NULL) \ - {PyDict_SetItemString(PyModule_GetDict(m),n,o); Py_DECREF(o);}} -#endif - #ifdef IS_PY3K PyMODINIT_FUNC #else -- cgit v1.2.1