From ab8fc54acaa511d224a9855f9cfc253e7d280547 Mon Sep 17 00:00:00 2001 From: Dwayne Litzenberger Date: Sun, 14 Jul 2013 16:21:16 -0700 Subject: Py3k cleanup: staticforward and Py_TYPE --- src/block_template.c | 6 ++---- src/hash_template.c | 4 ---- src/pycrypto_compat.h | 2 ++ src/stream_template.c | 4 ---- src/winrand.c | 5 ----- 5 files changed, 4 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/block_template.c b/src/block_template.c index b8a5a17..869df41 100644 --- a/src/block_template.c +++ b/src/block_template.c @@ -68,12 +68,10 @@ typedef struct * These changes also dictate using Py_TYPE to check type, and PyVarObject_HEAD_INIT(NULL, 0) to initialize */ #ifdef IS_PY3K -static PyTypeObject ALGtype; #define PyInt_CheckExact PyLong_CheckExact #define PyInt_AS_LONG PyLong_AS_LONG -#else -staticforward PyTypeObject ALGtype; #endif +staticforward PyTypeObject ALGtype; static ALGobject * newALGobject(void) @@ -186,7 +184,7 @@ ALGnew(PyObject *self, PyObject *args, PyObject *kwdict) PyErr_SetString(PyExc_TypeError, "'counter' keyword parameter is required with CTR mode"); return NULL; - } else if (counter->ob_type == PCT_CounterBEType || counter->ob_type == PCT_CounterLEType) { + } else if (Py_TYPE(counter) == PCT_CounterBEType || Py_TYPE(counter) == PCT_CounterLEType) { counter_shortcut = 1; } else if (!PyCallable_Check(counter)) { PyErr_SetString(PyExc_ValueError, diff --git a/src/hash_template.c b/src/hash_template.c index 1bc6847..eb98224 100644 --- a/src/hash_template.c +++ b/src/hash_template.c @@ -46,11 +46,7 @@ typedef struct { /* Please see PEP3123 for a discussion of PyObject_HEAD and changes made in 3.x to make it conform to Standard C. * These changes also dictate using Py_TYPE to check type, and PyVarObject_HEAD_INIT(NULL, 0) to initialize */ -#ifdef IS_PY3K -static PyTypeObject ALGtype; -#else staticforward PyTypeObject ALGtype; -#endif static ALGobject * newALGobject(void) diff --git a/src/pycrypto_compat.h b/src/pycrypto_compat.h index c9098d4..3e8f92d 100644 --- a/src/pycrypto_compat.h +++ b/src/pycrypto_compat.h @@ -32,6 +32,7 @@ #if PY_MAJOR_VERSION >= 3 # define IS_PY3K # define PyInt_FromLong PyLong_FromLong +# define staticforward static #else # define PyBytes_GET_SIZE PyString_GET_SIZE # define PyBytes_FromStringAndSize PyString_FromStringAndSize @@ -41,6 +42,7 @@ # define PyBytes_AsString PyString_AsString # define PyBytesObject PyStringObject # if PY_MINOR_VERSION <= 5 /* Python 2.5 and earlier */ +# define Py_TYPE(v) ((v)->ob_type) # define PyLong_MASK MASK # define PyLong_SHIFT SHIFT # define PyUnicode_FromString PyString_FromString diff --git a/src/stream_template.c b/src/stream_template.c index 1e03f34..8c14b28 100644 --- a/src/stream_template.c +++ b/src/stream_template.c @@ -53,11 +53,7 @@ typedef struct /* Please see PEP3123 for a discussion of PyObject_HEAD and changes made in 3.x to make it conform to Standard C. * These changes also dictate using Py_TYPE to check type, and PyVarObject_HEAD_INIT(NULL, 0) to initialize */ -#ifdef IS_PY3K -static PyTypeObject ALGtype; -#else staticforward PyTypeObject ALGtype; -#endif static ALGobject * newALGobject(void) diff --git a/src/winrand.c b/src/winrand.c index 0528972..149ae5c 100644 --- a/src/winrand.c +++ b/src/winrand.c @@ -58,13 +58,8 @@ typedef struct /* Please see PEP3123 for a discussion of PyObject_HEAD and changes made in 3.x to make it conform to Standard C. * These changes also dictate using Py_TYPE to check type, and PyVarObject_HEAD_INIT(NULL, 0) to initialize */ -#ifdef IS_PY3K -static PyTypeObject WRtype; #define is_WRobject(v) (Py_TYPE(v) == &WRtype) -#else staticforward PyTypeObject WRtype; -#define is_WRobject(v) ((v)->ob_type == &WRtype) -#endif static void WRdealloc(PyObject *ptr) -- cgit v1.2.1