mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
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.
This commit is contained in:
parent
aca49b065b
commit
07e147667c
3 changed files with 31 additions and 26 deletions
|
@ -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");
|
||||
if (buffer == NULL)
|
||||
return NULL;
|
||||
|
||||
if (PyUnicode_EncodeDecimal(u, length, buffer, NULL)) {
|
||||
PyMem_FREE(buffer);
|
||||
return NULL;
|
||||
}
|
||||
if (PyUnicode_EncodeDecimal(u, length, buffer, NULL))
|
||||
return NULL;
|
||||
|
||||
return PyLong_FromString(buffer, NULL, base);
|
||||
result = PyLong_FromString(buffer, NULL, base);
|
||||
PyMem_FREE(buffer);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue