[Python-checkins] python/dist/src/Objects intobject.c,2.93,2.94 longobject.c,1.143,1.144
doerwalter@users.sourceforge.net
doerwalter@users.sourceforge.net
Wed, 06 Nov 2002 08:15:18 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv9395/Objects
Modified Files:
intobject.c longobject.c
Log Message:
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.
Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.93
retrieving revision 2.94
diff -C2 -d -r2.93 -r2.94
*** intobject.c 11 Sep 2002 19:00:52 -0000 2.93
--- intobject.c 6 Nov 2002 16:15:12 -0000 2.94
***************
*** 209,216 ****
}
else if (errno != 0) {
! PyOS_snprintf(buffer, sizeof(buffer),
! "int() literal too large: %.200s", s);
! PyErr_SetString(PyExc_ValueError, buffer);
! return NULL;
}
if (pend)
--- 209,215 ----
}
else if (errno != 0) {
! if (err_ovf("string/unicode conversion"))
! return NULL;
! return PyLong_FromString(s, pend, base);
}
if (pend)
***************
*** 223,236 ****
PyInt_FromUnicode(Py_UNICODE *s, int length, int base)
{
! char buffer[256];
! if (length >= sizeof(buffer)) {
! PyErr_SetString(PyExc_ValueError,
! "int() literal too large to convert");
return NULL;
! }
! if (PyUnicode_EncodeDecimal(s, length, buffer, NULL))
return NULL;
! return PyInt_FromString(buffer, NULL, base);
}
#endif
--- 222,238 ----
PyInt_FromUnicode(Py_UNICODE *s, int length, int base)
{
! PyObject *result;
! char *buffer = PyMem_MALLOC(length+1);
! if (buffer == NULL)
return NULL;
!
! if (PyUnicode_EncodeDecimal(s, length, buffer, NULL)) {
! PyMem_FREE(buffer);
return NULL;
! }
! result = PyInt_FromString(buffer, NULL, base);
! PyMem_FREE(buffer);
! return result;
}
#endif
Index: longobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/longobject.c,v
retrieving revision 1.143
retrieving revision 1.144
diff -C2 -d -r1.143 -r1.144
*** longobject.c 3 Sep 2002 20:10:45 -0000 1.143
--- longobject.c 6 Nov 2002 16:15:14 -0000 1.144
***************
*** 1124,1138 ****
PyLong_FromUnicode(Py_UNICODE *u, int length, int base)
{
! char buffer[256];
! if (length >= sizeof(buffer)) {
! PyErr_SetString(PyExc_ValueError,
! "long() literal too large to convert");
! return NULL;
! }
! if (PyUnicode_EncodeDecimal(u, length, buffer, NULL))
return NULL;
! return PyLong_FromString(buffer, NULL, base);
}
#endif
--- 1124,1140 ----
PyLong_FromUnicode(Py_UNICODE *u, int length, int base)
{
! PyObject *result;
! char *buffer = PyMem_MALLOC(length+1);
! if (buffer == NULL)
return NULL;
! if (PyUnicode_EncodeDecimal(u, length, buffer, NULL)) {
! PyMem_FREE(buffer);
! return NULL;
! }
! result = PyLong_FromString(buffer, NULL, base);
! PyMem_FREE(buffer);
! return result;
}
#endif