diff options
author | Guido van Rossum <guido@python.org> | 1993-10-26 15:21:51 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1993-10-26 15:21:51 (GMT) |
commit | 72481a34974d3eb8246cc65181ef7fed253db904 (patch) | |
tree | 349a78e2f901c7499a8338c8ee27032f7c1af63b /Objects/intobject.c | |
parent | 8054fad890bbb6668cb2eb2fb3118222bada5975 (diff) | |
download | cpython-72481a34974d3eb8246cc65181ef7fed253db904.zip cpython-72481a34974d3eb8246cc65181ef7fed253db904.tar.gz cpython-72481a34974d3eb8246cc65181ef7fed253db904.tar.bz2 |
Changes to make range checks portable to 64-bit machines.
Diffstat (limited to 'Objects/intobject.c')
-rw-r--r-- | Objects/intobject.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index 6fcbe69..2953ffa 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -27,6 +27,24 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "allobjects.h" #include "modsupport.h" +#ifdef __STDC__ +#include <limits.h> +#endif + +#ifndef LONG_MAX +#define LONG_MAX 0X7FFFFFFFL +#endif + +#ifndef LONG_MIN +#define LONG_MIN (-LONG_MAX-1) +#endif + +#ifndef CHAR_BIT +#define CHAR_BIT 8 +#endif + +#define LONG_BIT (CHAR_BIT * sizeof(long)) + /* Standard Booleans */ intobject FalseObject = { @@ -229,7 +247,7 @@ int_mul(v, w) a = v->ob_ival; b = w->ob_ival; x = (double)a * (double)b; - if (x > 0x7fffffff || x < (double) (long) 0x80000000) + if (x > LONG_MAX || x < (double) (long) (LONG_MIN)) return err_ovf("integer multiplication"); return newintobject(a * b); } @@ -387,7 +405,7 @@ int_lshift(v, w) INCREF(v); return (object *) v; } - if (b >= 32) { + if (b >= LONG_BIT) { return newintobject(0L); } a = (unsigned long)a << b; @@ -410,7 +428,7 @@ int_rshift(v, w) INCREF(v); return (object *) v; } - if (b >= 32) { + if (b >= LONG_BIT) { if (a < 0) a = -1; else |