diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2009-03-20 23:23:15 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2009-03-20 23:23:15 (GMT) |
commit | 16f966ee2618f7a6604b94de2e478637676f550e (patch) | |
tree | d5485383f759cbf9952847c04a5f09f1b0cb2c1a | |
parent | be075b1c4ed96d3b7550833a9a558690c2e6c0f9 (diff) | |
download | cpython-16f966ee2618f7a6604b94de2e478637676f550e.zip cpython-16f966ee2618f7a6604b94de2e478637676f550e.tar.gz cpython-16f966ee2618f7a6604b94de2e478637676f550e.tar.bz2 |
Merged revisions 70489 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r70489 | mark.dickinson | 2009-03-20 23:16:14 +0000 (Fri, 20 Mar 2009) | 4 lines
Rewrite Py_ARITHMETIC_RIGHT_SHIFT so that it's valid for all signed
integer types T, not just those for which "unsigned T" is legal.
........
-rw-r--r-- | Include/pyport.h | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/Include/pyport.h b/Include/pyport.h index 9449b5f..bf75d89 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -361,19 +361,23 @@ extern "C" { * C doesn't define whether a right-shift of a signed integer sign-extends * or zero-fills. Here a macro to force sign extension: * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) - * Return I >> J, forcing sign extension. + * Return I >> J, forcing sign extension. Arithmetically, return the + * floor of I/2**J. * Requirements: - * I is of basic signed type TYPE (char, short, int, long, or long long). - * TYPE is one of char, short, int, long, or long long, although long long - * must not be used except on platforms that support it. - * J is an integer >= 0 and strictly less than the number of bits in TYPE - * (because C doesn't define what happens for J outside that range either). + * I should have signed integer type. In the terminology of C99, this can + * be either one of the five standard signed integer types (signed char, + * short, int, long, long long) or an extended signed integer type. + * J is an integer >= 0 and strictly less than the number of bits in the + * type of I (because C doesn't define what happens for J outside that + * range either). + * TYPE used to specify the type of I, but is now ignored. It's been left + * in for backwards compatibility with versions <= 2.6 or 3.0. * Caution: * I may be evaluated more than once. */ #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \ - ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J)) + ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J)) #else #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) #endif |