summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2002-11-06 16:15:14 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2002-11-06 16:15:14 (GMT)
commit07e147667cf02cbcb05c84fe03fee31ef61a21c4 (patch)
treeb190c3881196b25e5588937b3f96a9b421c00c04 /Objects/longobject.c
parentaca49b065bbe7c27d47798bdb3cb059ef213fc16 (diff)
downloadcpython-07e147667cf02cbcb05c84fe03fee31ef61a21c4.zip
cpython-07e147667cf02cbcb05c84fe03fee31ef61a21c4.tar.gz
cpython-07e147667cf02cbcb05c84fe03fee31ef61a21c4.tar.bz2
Make int("...") return a long if an int would overflow.
Also remove the 512 character limitation for int(u"...") and long(u"..."). This closes SF bug #629989.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 35d1211..7374fce 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -1123,17 +1123,19 @@ PyLong_FromString(char *str, char **pend, int base)
PyObject *
PyLong_FromUnicode(Py_UNICODE *u, int length, int base)
{
- char buffer[256];
+ PyObject *result;
+ char *buffer = PyMem_MALLOC(length+1);
- if (length >= sizeof(buffer)) {
- PyErr_SetString(PyExc_ValueError,
- "long() literal too large to convert");
- return NULL;
- }
- if (PyUnicode_EncodeDecimal(u, length, buffer, NULL))
+ if (buffer == NULL)
return NULL;
- return PyLong_FromString(buffer, NULL, base);
+ if (PyUnicode_EncodeDecimal(u, length, buffer, NULL)) {
+ PyMem_FREE(buffer);
+ return NULL;
+ }
+ result = PyLong_FromString(buffer, NULL, base);
+ PyMem_FREE(buffer);
+ return result;
}
#endif