summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-10-24 14:55:57 (GMT)
committerGuido van Rossum <guido@python.org>1991-10-24 14:55:57 (GMT)
commit3d3037d51a541ac1480e60dc469efc51607542f5 (patch)
tree8d250f8a9c1709c2891ab325a6b038b04777894a /Objects
parent27acb3379e7349b0ca33e007919bee17882a59a3 (diff)
downloadcpython-3d3037d51a541ac1480e60dc469efc51607542f5.zip
cpython-3d3037d51a541ac1480e60dc469efc51607542f5.tar.gz
cpython-3d3037d51a541ac1480e60dc469efc51607542f5.tar.bz2
Changed convert to add '0' or '0x' prefix for oct/hex.
Added NULL function pointers for shift and mask ops.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index ca4088c..c9c0dbf 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -253,7 +253,8 @@ divrem1(a, n, prem)
}
/* Convert a long int object to a string, using a given conversion base.
- Return a string object. */
+ Return a string object.
+ If base is 8 or 16, add the proper prefix '0' or '0x'. */
stringobject *
long_format(a, base)
@@ -276,7 +277,7 @@ long_format(a, base)
++bits;
i >>= 1;
}
- i = 1 + (size_a*SHIFT + bits-1) / bits;
+ i = 3 + (size_a*SHIFT + bits-1) / bits;
str = (stringobject *) newsizedstringobject((char *)0, i);
if (str == NULL)
return NULL;
@@ -310,6 +311,12 @@ long_format(a, base)
})
} while (a->ob_size != 0);
DECREF(a);
+ if (base == 8)
+ *--p = '0';
+ else if (base == 16) {
+ *--p = 'x';
+ *--p = '0';
+ }
if (sign)
*--p = sign;
if (p != GETSTRINGVALUE(str)) {
@@ -992,6 +999,12 @@ static number_methods long_as_number = {
long_pos, /*tp_positive*/
long_abs, /*tp_absolute*/
long_nonzero, /*tp_nonzero*/
+ 0, /*nb_invert*/
+ 0, /*nb_lshift*/
+ 0, /*nb_rshift*/
+ 0, /*nb_and*/
+ 0, /*nb_xor*/
+ 0, /*nb_or*/
};
typeobject Longtype = {