diff options
author | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-07-14 16:02:04 -0700 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-07-14 19:13:33 -0700 |
commit | 5c0ec3238a2b8f69be75040c706959e5c852f5ad (patch) | |
tree | 53d561098fb3d75af643333a0302e32fafd33d9c /src | |
parent | 1418e318180f651de1c4b08468b75ca719d703ba (diff) | |
download | pycrypto-5c0ec3238a2b8f69be75040c706959e5c852f5ad.tar.gz |
Py3k cleanup: Define PyInt_FromLong for Python 3.x and use it
This is the first of a series of changes that aims to reduce code
duplication between the Python 3 and Python 2 versions of the C
extensions.
Diffstat (limited to 'src')
-rw-r--r-- | src/_counter.c | 12 | ||||
-rw-r--r-- | src/block_template.c | 7 | ||||
-rw-r--r-- | src/hash_template.c | 3 | ||||
-rw-r--r-- | src/pycrypto_compat.h | 1 | ||||
-rw-r--r-- | src/stream_template.c | 5 | ||||
-rw-r--r-- | src/winrand.c | 3 |
6 files changed, 12 insertions, 19 deletions
diff --git a/src/_counter.c b/src/_counter.c index f82c378..2bd33ae 100644 --- a/src/_counter.c +++ b/src/_counter.c @@ -28,10 +28,6 @@ #include <string.h> #include "_counter.h" -#ifndef IS_PY3K -#define PyLong_FromLong PyInt_FromLong -#endif - /* Deal with old API in Python 2.1 */ #if PYTHON_API_VERSION < 1011 #define PyModule_AddIntConstant(m,n,v) {PyObject *o=PyInt_FromLong(v); \ @@ -166,7 +162,7 @@ _CounterObject_next_value(PCT_CounterObject *self, int little_endian) goto err_out; } - eight = PyLong_FromLong(8); + eight = PyInt_FromLong(8); if (!eight) goto err_out; @@ -191,7 +187,7 @@ _CounterObject_next_value(PCT_CounterObject *self, int little_endian) /* ch = ord(p) */ Py_CLEAR(ch); /* delete old ch */ - ch = PyLong_FromLong((long) *p); + ch = PyInt_FromLong((long) *p); if (!ch) goto err_out; @@ -326,7 +322,7 @@ CounterLEObject_getattr(PyObject *s, char *name) #else if (strcmp(name, "carry") == 0) { #endif - return PyLong_FromLong((long)self->carry); + return PyInt_FromLong((long)self->carry); } #ifdef IS_PY3K generic: @@ -352,7 +348,7 @@ CounterBEObject_getattr(PyObject *s, char *name) #else if (strcmp(name, "carry") == 0) { #endif - return PyLong_FromLong((long)self->carry); + return PyInt_FromLong((long)self->carry); } #ifdef IS_PY3K generic: diff --git a/src/block_template.c b/src/block_template.c index e1f3f2f..0e7442a 100644 --- a/src/block_template.c +++ b/src/block_template.c @@ -75,7 +75,6 @@ static PyTypeObject ALGtype; #else staticforward PyTypeObject ALGtype; #define is_ALGobject(v) ((v)->ob_type == &ALGtype) -#define PyLong_FromLong PyInt_FromLong /* For Python 2.x */ #endif static ALGobject * @@ -668,7 +667,7 @@ ALGgetattr(PyObject *s, char *name) if (strcmp(name, "mode") == 0) #endif { - return(PyLong_FromLong((long)(self->mode))); + return(PyInt_FromLong((long)(self->mode))); } #ifdef IS_PY3K if (PyUnicode_CompareWithASCIIString(attr, "block_size") == 0) @@ -676,7 +675,7 @@ ALGgetattr(PyObject *s, char *name) if (strcmp(name, "block_size") == 0) #endif { - return PyLong_FromLong(BLOCK_SIZE); + return PyInt_FromLong(BLOCK_SIZE); } #ifdef IS_PY3K if (PyUnicode_CompareWithASCIIString(attr, "key_size") == 0) @@ -684,7 +683,7 @@ ALGgetattr(PyObject *s, char *name) if (strcmp(name, "key_size") == 0) #endif { - return PyLong_FromLong(KEY_SIZE); + return PyInt_FromLong(KEY_SIZE); } #ifdef IS_PY3K generic: diff --git a/src/hash_template.c b/src/hash_template.c index 1e0ed70..249040f 100644 --- a/src/hash_template.c +++ b/src/hash_template.c @@ -52,7 +52,6 @@ static PyTypeObject ALGtype; #else staticforward PyTypeObject ALGtype; #define is_ALGobject(v) ((v)->ob_type == &ALGtype) -#define PyLong_FromLong PyInt_FromLong /* For Python 2.x */ #endif static ALGobject * @@ -202,7 +201,7 @@ ALG_getattr(PyObject *self, char *name) goto generic; if (PyUnicode_CompareWithASCIIString(attr, "digest_size")==0) - return PyLong_FromLong(DIGEST_SIZE); + return PyInt_FromLong(DIGEST_SIZE); if (PyUnicode_CompareWithASCIIString(attr, "name")==0) return PyUnicode_FromString(_MODULE_STRING); /* we should try to be compatible with hashlib here */ #else diff --git a/src/pycrypto_compat.h b/src/pycrypto_compat.h index 6ae31dd..274bfb4 100644 --- a/src/pycrypto_compat.h +++ b/src/pycrypto_compat.h @@ -31,6 +31,7 @@ #if PY_MAJOR_VERSION >= 3 # define IS_PY3K +# define PyInt_FromLong PyLong_FromLong #else # define PyBytes_GET_SIZE PyString_GET_SIZE # define PyBytes_FromStringAndSize PyString_FromStringAndSize diff --git a/src/stream_template.c b/src/stream_template.c index da7baa6..5d13650 100644 --- a/src/stream_template.c +++ b/src/stream_template.c @@ -59,7 +59,6 @@ static PyTypeObject ALGtype; #else staticforward PyTypeObject ALGtype; #define is_ALGobject(v) ((v)->ob_type == &ALGtype) -#define PyLong_FromLong PyInt_FromLong /* For Python 2.x */ #endif static ALGobject * @@ -216,7 +215,7 @@ ALGgetattr(PyObject *self, char *name) if (strcmp(name, "block_size") == 0) #endif { - return PyLong_FromLong(BLOCK_SIZE); + return PyInt_FromLong(BLOCK_SIZE); } #ifdef IS_PY3K if (PyUnicode_CompareWithASCIIString(attr, "key_size") == 0) @@ -224,7 +223,7 @@ ALGgetattr(PyObject *self, char *name) if (strcmp(name, "key_size") == 0) #endif { - return PyLong_FromLong(KEY_SIZE); + return PyInt_FromLong(KEY_SIZE); } #ifdef IS_PY3K generic: diff --git a/src/winrand.c b/src/winrand.c index 56aa450..0528972 100644 --- a/src/winrand.c +++ b/src/winrand.c @@ -64,7 +64,6 @@ static PyTypeObject WRtype; #else staticforward PyTypeObject WRtype; #define is_WRobject(v) ((v)->ob_type == &WRtype) -#define PyLong_FromLong PyInt_FromLong /* for Python 2.x */ #endif static void @@ -216,7 +215,7 @@ WRgetattr(PyObject *s, char *name) #else if (strcmp(name, "hcp") == 0) #endif - return PyLong_FromLong((long) self->hcp); + return PyInt_FromLong((long) self->hcp); #ifdef IS_PY3K generic: return PyObject_GenericGetAttr(s, attr); |