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().
This commit is contained in:
Fred Drake 1999-12-23 15:41:28 +00:00
parent db1bd5c230
commit 121ee2722e

View file

@ -47,7 +47,7 @@ static PyLongObject *long_normalize Py_PROTO((PyLongObject *));
static PyLongObject *mul1 Py_PROTO((PyLongObject *, wdigit)); static PyLongObject *mul1 Py_PROTO((PyLongObject *, wdigit));
static PyLongObject *muladd1 Py_PROTO((PyLongObject *, wdigit, wdigit)); static PyLongObject *muladd1 Py_PROTO((PyLongObject *, wdigit, wdigit));
static PyLongObject *divrem1 Py_PROTO((PyLongObject *, wdigit, digit *)); 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? */ 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. /* 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'. If base is 8 or 16, add the proper prefix '0' or '0x'. */
External linkage: used in bltinmodule.c by hex() and oct(). */
static PyObject * static PyObject *
long_format(aa, base) long_format(aa, base, addL)
PyObject *aa; PyObject *aa;
int base; int base;
int addL;
{ {
register PyLongObject *a = (PyLongObject *)aa; register PyLongObject *a = (PyLongObject *)aa;
PyStringObject *str; PyStringObject *str;
@ -599,13 +599,14 @@ long_format(aa, base)
++bits; ++bits;
i >>= 1; 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); str = (PyStringObject *) PyString_FromStringAndSize((char *)0, i);
if (str == NULL) if (str == NULL)
return NULL; return NULL;
p = PyString_AS_STRING(str) + i; p = PyString_AS_STRING(str) + i;
*p = '\0'; *p = '\0';
*--p = 'L'; if (addL)
*--p = 'L';
if (a->ob_size < 0) if (a->ob_size < 0)
sign = '-'; sign = '-';
@ -974,7 +975,14 @@ static PyObject *
long_repr(v) long_repr(v)
PyObject *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 static int
@ -1756,14 +1764,14 @@ static PyObject *
long_oct(v) long_oct(v)
PyObject *v; PyObject *v;
{ {
return long_format(v, 8); return long_format(v, 8, 1);
} }
static PyObject * static PyObject *
long_hex(v) long_hex(v)
PyObject *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*/ 0, /*tp_as_mapping*/
(long (*) Py_FPROTO((PyObject *))) (long (*) Py_FPROTO((PyObject *)))
(hashfunc)long_hash, /*tp_hash*/ (hashfunc)long_hash, /*tp_hash*/
0, /*tp_call*/
(reprfunc)long_str, /*tp_str*/
}; };