summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>1999-12-23 15:41:28 (GMT)
committerFred Drake <fdrake@acm.org>1999-12-23 15:41:28 (GMT)
commit121ee2722e510834bda99f8a48ccadc55d832e2a (patch)
tree05311c404805c2ffc462142ff1246a10ccacd8e3 /Objects
parentdb1bd5c230e2ed71b95939e61a09271887b03b31 (diff)
downloadcpython-121ee2722e510834bda99f8a48ccadc55d832e2a.zip
cpython-121ee2722e510834bda99f8a48ccadc55d832e2a.tar.gz
cpython-121ee2722e510834bda99f8a48ccadc55d832e2a.tar.bz2
long_format(): Now takes a third parameter, addL; iff true, a
trailing 'L' is appended to the representation, otherwise not. All existing call sites are modified to pass true for addL. Remove incorrect statement about external use of this function from elsewhere; it's static! long_str(): Handler for the tp_str slot in the type object. Identical to long_repr(), but passes false as the addL parameter of long_format().
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 0aecf8f..bdf4774 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -47,7 +47,7 @@ static PyLongObject *long_normalize Py_PROTO((PyLongObject *));
static PyLongObject *mul1 Py_PROTO((PyLongObject *, wdigit));
static PyLongObject *muladd1 Py_PROTO((PyLongObject *, wdigit, wdigit));
static PyLongObject *divrem1 Py_PROTO((PyLongObject *, wdigit, digit *));
-static PyObject *long_format Py_PROTO((PyObject *aa, int base));
+static PyObject *long_format Py_PROTO((PyObject *aa, int base, int addL));
static int ticker; /* XXX Could be shared with ceval? */
@@ -570,13 +570,13 @@ divrem1(a, n, prem)
/* Convert a long int object to a string, using a given conversion base.
Return a string object.
- If base is 8 or 16, add the proper prefix '0' or '0x'.
- External linkage: used in bltinmodule.c by hex() and oct(). */
+ If base is 8 or 16, add the proper prefix '0' or '0x'. */
static PyObject *
-long_format(aa, base)
+long_format(aa, base, addL)
PyObject *aa;
int base;
+ int addL;
{
register PyLongObject *a = (PyLongObject *)aa;
PyStringObject *str;
@@ -599,13 +599,14 @@ long_format(aa, base)
++bits;
i >>= 1;
}
- i = 6 + (size_a*SHIFT + bits-1) / bits;
+ i = 5 + (addL ? 1 : 0) + (size_a*SHIFT + bits-1) / bits;
str = (PyStringObject *) PyString_FromStringAndSize((char *)0, i);
if (str == NULL)
return NULL;
p = PyString_AS_STRING(str) + i;
*p = '\0';
- *--p = 'L';
+ if (addL)
+ *--p = 'L';
if (a->ob_size < 0)
sign = '-';
@@ -974,7 +975,14 @@ static PyObject *
long_repr(v)
PyObject *v;
{
- return long_format(v, 10);
+ return long_format(v, 10, 1);
+}
+
+static PyObject *
+long_str(v)
+ PyObject *v;
+{
+ return long_format(v, 10, 0);
}
static int
@@ -1756,14 +1764,14 @@ static PyObject *
long_oct(v)
PyObject *v;
{
- return long_format(v, 8);
+ return long_format(v, 8, 1);
}
static PyObject *
long_hex(v)
PyObject *v;
{
- return long_format(v, 16);
+ return long_format(v, 16, 1);
}
@@ -1817,4 +1825,6 @@ PyTypeObject PyLong_Type = {
0, /*tp_as_mapping*/
(long (*) Py_FPROTO((PyObject *)))
(hashfunc)long_hash, /*tp_hash*/
+ 0, /*tp_call*/
+ (reprfunc)long_str, /*tp_str*/
};