diff options
author | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-07-14 16:07:27 -0700 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-07-14 19:14:35 -0700 |
commit | a5639ad034ddc5521ff4d399d74fc069f3cbf592 (patch) | |
tree | ee27441e27bec76afcd74fe3c3eadff3d424dbab /src | |
parent | 5c0ec3238a2b8f69be75040c706959e5c852f5ad (diff) | |
download | pycrypto-a5639ad034ddc5521ff4d399d74fc069f3cbf592.tar.gz |
Py3k cleanup: Define PyLong_SHIFT and PyLong_MASK in Python 2.5 and below
Diffstat (limited to 'src')
-rw-r--r-- | src/_fastmath.c | 13 | ||||
-rw-r--r-- | src/pycrypto_compat.h | 4 |
2 files changed, 3 insertions, 14 deletions
diff --git a/src/_fastmath.c b/src/_fastmath.c index 4f2932d..3be1432 100644 --- a/src/_fastmath.c +++ b/src/_fastmath.c @@ -83,11 +83,7 @@ longObjToMPZ (mpz_t m, PyLongObject * p) for (i = 0; i < size; i++) { mpz_set_ui (temp, p->ob_digit[i]); -#ifdef IS_PY3K mpz_mul_2exp (temp2, temp, PyLong_SHIFT * i); -#else - mpz_mul_2exp (temp2, temp, SHIFT * i); -#endif mpz_add (m, m, temp2); } mpz_mul_si(m, m, negative); @@ -99,11 +95,7 @@ static PyObject * mpzToLongObj (mpz_t m) { /* borrowed from gmpy */ -#ifdef IS_PY3K int size = (mpz_sizeinbase (m, 2) + PyLong_SHIFT - 1) / PyLong_SHIFT; -#else - int size = (mpz_sizeinbase (m, 2) + SHIFT - 1) / SHIFT; -#endif int sgn; int i; mpz_t temp; @@ -115,13 +107,8 @@ mpzToLongObj (mpz_t m) mpz_mul_si(temp, m, sgn); for (i = 0; i < size; i++) { -#ifdef IS_PY3K l->ob_digit[i] = (digit) (mpz_get_ui (temp) & PyLong_MASK); mpz_fdiv_q_2exp (temp, temp, PyLong_SHIFT); -#else - l->ob_digit[i] = (digit) (mpz_get_ui (temp) & MASK); - mpz_fdiv_q_2exp (temp, temp, SHIFT); -#endif } i = size; while ((i > 0) && (l->ob_digit[i - 1] == 0)) diff --git a/src/pycrypto_compat.h b/src/pycrypto_compat.h index 274bfb4..6234839 100644 --- a/src/pycrypto_compat.h +++ b/src/pycrypto_compat.h @@ -40,7 +40,9 @@ # define PyBytes_Size PyString_Size # define PyBytes_AsString PyString_AsString # define PyBytesObject PyStringObject -# if PY_MINOR_VERSION <= 5 /* PyUnicode_FromString exists from Python 2.6 on up */ +# if PY_MINOR_VERSION <= 5 /* Python 2.5 and earlier */ +# define PyLong_MASK MASK +# define PyLong_SHIFT SHIFT # define PyUnicode_FromString PyString_FromString # endif #endif |