[Python-3000-checkins] r51388 - in python/branches/p3yk: Lib/test/test_long.py Objects/longobject.c

guido.van.rossum python-3000-checkins at python.org
Fri Aug 18 18:29:55 CEST 2006


Author: guido.van.rossum
Date: Fri Aug 18 18:29:54 2006
New Revision: 51388

Modified:
   python/branches/p3yk/Lib/test/test_long.py
   python/branches/p3yk/Objects/longobject.c
Log:
repr() of a long int no longer produces a trailing 'L'.
More unit tests probably need fixing; later...


Modified: python/branches/p3yk/Lib/test/test_long.py
==============================================================================
--- python/branches/p3yk/Lib/test/test_long.py	(original)
+++ python/branches/p3yk/Lib/test/test_long.py	Fri Aug 18 18:29:54 2006
@@ -196,7 +196,7 @@
     def slow_format(self, x, base):
         if (x, base) == (0, 8):
             # this is an oddball!
-            return "0L"
+            return "0"
         digits = []
         sign = 0
         if x < 0:
@@ -208,7 +208,7 @@
         digits = digits or [0]
         return '-'[:sign] + \
                {8: '0', 10: '', 16: '0x'}[base] + \
-               "".join(map(lambda i: "0123456789abcdef"[i], digits)) + "L"
+               "".join(map(lambda i: "0123456789abcdef"[i], digits))
 
     def check_format_1(self, x):
         for base, mapper in (8, oct), (10, repr), (16, hex):
@@ -221,7 +221,7 @@
         # str() has to be checked a little differently since there's no
         # trailing "L"
         got = str(x)
-        expected = self.slow_format(x, 10)[:-1]
+        expected = self.slow_format(x, 10)
         msg = Frm("%s returned %r but expected %r for %r",
             mapper.__name__, got, expected, x)
         self.assertEqual(got, expected, msg)

Modified: python/branches/p3yk/Objects/longobject.c
==============================================================================
--- python/branches/p3yk/Objects/longobject.c	(original)
+++ python/branches/p3yk/Objects/longobject.c	Fri Aug 18 18:29:54 2006
@@ -35,7 +35,7 @@
 static PyLongObject *mul1(PyLongObject *, wdigit);
 static PyLongObject *muladd1(PyLongObject *, wdigit, wdigit);
 static PyLongObject *divrem1(PyLongObject *, digit, digit *);
-static PyObject *long_format(PyObject *aa, int base, int addL);
+static PyObject *long_format(PyObject *aa, int base);
 
 #define SIGCHECK(PyTryBlock) \
 	if (--_Py_Ticker < 0) { \
@@ -1198,7 +1198,7 @@
    If base is 8 or 16, add the proper prefix '0' or '0x'. */
 
 static PyObject *
-long_format(PyObject *aa, int base, int addL)
+long_format(PyObject *aa, int base)
 {
 	register PyLongObject *a = (PyLongObject *)aa;
 	PyStringObject *str;
@@ -1222,14 +1222,12 @@
 		++bits;
 		i >>= 1;
 	}
-	i = 5 + (addL ? 1 : 0) + (size_a*SHIFT + bits-1) / bits;
+	i = 5 + (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';
-        if (addL)
-                *--p = 'L';
 	if (a->ob_size < 0)
 		sign = '-';
 
@@ -1890,13 +1888,7 @@
 static PyObject *
 long_repr(PyObject *v)
 {
-	return long_format(v, 10, 1);
-}
-
-static PyObject *
-long_str(PyObject *v)
-{
-	return long_format(v, 10, 0);
+	return long_format(v, 10);
 }
 
 static int
@@ -3255,13 +3247,13 @@
 static PyObject *
 long_oct(PyObject *v)
 {
-	return long_format(v, 8, 1);
+	return long_format(v, 8);
 }
 
 static PyObject *
 long_hex(PyObject *v)
 {
-	return long_format(v, 16, 1);
+	return long_format(v, 16);
 }
 
 static PyObject *
@@ -3407,7 +3399,7 @@
 	0,					/* tp_as_mapping */
 	(hashfunc)long_hash,			/* tp_hash */
         0,              			/* tp_call */
-        long_str,				/* tp_str */
+        0,					/* tp_str */
 	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */


More information about the Python-3000-checkins mailing list