diff options
author | Walter Dörwald <walter@livinglogic.de> | 2002-11-06 16:15:14 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2002-11-06 16:15:14 (GMT) |
commit | 07e147667cf02cbcb05c84fe03fee31ef61a21c4 (patch) | |
tree | b190c3881196b25e5588937b3f96a9b421c00c04 /Objects/intobject.c | |
parent | aca49b065bbe7c27d47798bdb3cb059ef213fc16 (diff) | |
download | cpython-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/intobject.c')
-rw-r--r-- | Objects/intobject.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index 7404e98..e339085 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -208,10 +208,9 @@ PyInt_FromString(char *s, char **pend, int base) return NULL; } else if (errno != 0) { - PyOS_snprintf(buffer, sizeof(buffer), - "int() literal too large: %.200s", s); - PyErr_SetString(PyExc_ValueError, buffer); - return NULL; + if (err_ovf("string/unicode conversion")) + return NULL; + return PyLong_FromString(s, pend, base); } if (pend) *pend = end; @@ -222,16 +221,19 @@ PyInt_FromString(char *s, char **pend, int base) PyObject * PyInt_FromUnicode(Py_UNICODE *s, int length, int base) { - char buffer[256]; + PyObject *result; + char *buffer = PyMem_MALLOC(length+1); - if (length >= sizeof(buffer)) { - PyErr_SetString(PyExc_ValueError, - "int() literal too large to convert"); + if (buffer == NULL) return NULL; - } - if (PyUnicode_EncodeDecimal(s, length, buffer, NULL)) + + if (PyUnicode_EncodeDecimal(s, length, buffer, NULL)) { + PyMem_FREE(buffer); return NULL; - return PyInt_FromString(buffer, NULL, base); + } + result = PyInt_FromString(buffer, NULL, base); + PyMem_FREE(buffer); + return result; } #endif |