summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-12-05 21:57:21 (GMT)
committerGuido van Rossum <guido@python.org>1996-12-05 21:57:21 (GMT)
commit472c04f18f54327433c13601b25c7ea2c7071e6b (patch)
treefc1ab999db009acf14b4d51f4554e0e8a145c3f0 /Objects/longobject.c
parenta0a69b8b429f3d4c91f1c432247cfda017505976 (diff)
downloadcpython-472c04f18f54327433c13601b25c7ea2c7071e6b.zip
cpython-472c04f18f54327433c13601b25c7ea2c7071e6b.tar.gz
cpython-472c04f18f54327433c13601b25c7ea2c7071e6b.tar.bz2
Fix newlongobject so it will work for 64-bit as well as 32-bit hardware
(although for 32-bit hardware it's a bit slower than it was). Make gcc -Wall happy.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 6db4ff9..f98e517 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -90,17 +90,20 @@ object *
newlongobject(ival)
long ival;
{
- /* Assume a C long fits in at most 3 'digits' */
- /* XXX On 64 bit machines this isn't true!!! */
- longobject *v = alloclongobject(3);
+ /* Assume a C long fits in at most 5 'digits' */
+ /* Works on both 32- and 64-bit machines */
+ longobject *v = alloclongobject(5);
if (v != NULL) {
+ unsigned long t = ival;
+ int i;
if (ival < 0) {
- ival = -ival;
+ t = -ival;
v->ob_size = -(v->ob_size);
+ }
+ for (i = 0; i < 5; i++) {
+ v->ob_digit[i] = t & MASK;
+ t >>= SHIFT;
}
- v->ob_digit[0] = ival & MASK;
- v->ob_digit[1] = (ival >> SHIFT) & MASK;
- v->ob_digit[2] = ((unsigned long)ival >> (2*SHIFT)) & MASK;
v = long_normalize(v);
}
return (object *)v;
@@ -384,7 +387,7 @@ long_escan(str, pend, base)
int sign = 1;
longobject *z;
- if (base != 0 && base < 2 || base > 36) {
+ if ((base != 0 && base < 2) || base > 36) {
err_setstr(ValueError, "invalid base for long literal");
return NULL;
}
@@ -453,8 +456,8 @@ long_divrem(a, b, pdiv, prem)
return -1;
}
if (size_a < size_b ||
- size_a == size_b &&
- a->ob_digit[size_a-1] < b->ob_digit[size_b-1]) {
+ (size_a == size_b &&
+ a->ob_digit[size_a-1] < b->ob_digit[size_b-1])) {
/* |a| < |b|. */
*pdiv = alloclongobject(0);
INCREF(a);
@@ -889,8 +892,8 @@ l_divmod(v, w, pdiv, pmod)
if (long_divrem(v, w, &div, &mod) < 0)
return -1;
- if (mod->ob_size < 0 && w->ob_size > 0 ||
- mod->ob_size > 0 && w->ob_size < 0) {
+ if ((mod->ob_size < 0 && w->ob_size > 0) ||
+ (mod->ob_size > 0 && w->ob_size < 0)) {
longobject *temp;
longobject *one;
temp = (longobject *) long_add(mod, w);