Mercurial > cpython-lru_cache-weakref
diff Objects/longobject.c @ 42719:ae83efb73506
Change the error reporting when an invalid string is encountered to avoid
reporting s'x' as the input (which is a lie).
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 22 Aug 2007 23:28:23 +0000 |
| parents | 13dc836d4a99 |
| children | 077fe7860cc9 |
line wrap: on
line diff
--- a/Objects/longobject.c Wed Aug 22 23:21:33 2007 +0000 +++ b/Objects/longobject.c Wed Aug 22 23:28:23 2007 +0000 @@ -1689,7 +1689,7 @@ int sign = 1, error_if_nonzero = 0; char *start, *orig_str = str; PyLongObject *z = NULL; - PyObject *strobj, *strrepr; + PyObject *strobj; Py_ssize_t slen; if ((base != 0 && base < 2) || base > 36) { @@ -1956,17 +1956,13 @@ onError: Py_XDECREF(z); slen = strlen(orig_str) < 200 ? strlen(orig_str) : 200; - strobj = PyString_FromStringAndSize(orig_str, slen); + strobj = PyUnicode_FromStringAndSize(orig_str, slen); if (strobj == NULL) return NULL; - strrepr = PyObject_ReprStr8(strobj); + PyErr_Format(PyExc_ValueError, + "invalid literal for int() with base %d: %R", + base, strobj); Py_DECREF(strobj); - if (strrepr == NULL) - return NULL; - PyErr_Format(PyExc_ValueError, - "invalid literal for int() with base %d: %s", - base, PyString_AS_STRING(strrepr)); - Py_DECREF(strrepr); return NULL; } @@ -3533,16 +3529,11 @@ size = PyString_GET_SIZE(x); } if (strlen(string) != size) { - /* create a repr() of the input string, - * just like PyLong_FromString does. */ - PyObject *srepr; - srepr = PyObject_ReprStr8(x); - if (srepr == NULL) - return NULL; + /* We only see this if there's a null byte in x, + x is a str8 or a bytes, *and* a base is given. */ PyErr_Format(PyExc_ValueError, - "invalid literal for int() with base %d: %s", - base, PyString_AS_STRING(srepr)); - Py_DECREF(srepr); + "invalid literal for int() with base %d: %R", + base, x); return NULL; } return PyLong_FromString(string, NULL, base);
