Core and Builtins
-----------------
+ - Issue #16741: Fix an error reporting in int().
+
- Issue #17899: Fix rare file descriptor leak in os.listdir().
+- Issue #9035: ismount now recognises volumes mounted below a drive root
+ on Windows. Original patch by Atsuo Ishimoto.
+
+- Issue #18214: Improve finalization of Python modules to avoid setting
+ their globals to None, in most cases.
+
+- Issue #18112: PEP 442 implementation (safe object finalization).
+
- Issue #18552: Check return value of PyArena_AddPyObject() in
obj2ast_object().
if (strobj == NULL)
return NULL;
PyErr_Format(PyExc_ValueError,
-- "invalid literal for int() with base %d: %R",
++ "invalid literal for int() with base %d: %.200R",
base, strobj);
Py_DECREF(strobj);
return NULL;
}
- "invalid literal for int() with base %d: %R",
+ /* Since PyLong_FromString doesn't have a length parameter,
+ * check here for possible NULs in the string.
+ *
+ * Reports an invalid literal as a bytes object.
+ */
+ PyObject *
+ _PyLong_FromBytes(const char *s, Py_ssize_t len, int base)
+ {
+ PyObject *result, *strobj;
+ char *end = NULL;
+
+ result = PyLong_FromString((char*)s, &end, base);
+ if (end == NULL || (result != NULL && end == s + len))
+ return result;
+ Py_XDECREF(result);
+ strobj = PyBytes_FromStringAndSize(s, Py_MIN(len, 200));
+ if (strobj != NULL) {
+ PyErr_Format(PyExc_ValueError,
++ "invalid literal for int() with base %d: %.200R",
+ base, strobj);
+ Py_DECREF(strobj);
+ }
+ return NULL;
+ }
+
PyObject *
PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base)
{
PyObject *
PyLong_FromUnicodeObject(PyObject *u, int base)
{
- PyObject *result;
- PyObject *asciidig;
- char *buffer, *end;
- PyObject *result, *asciidig, *strobj;
++ PyObject *result, *asciidig;
+ char *buffer, *end = NULL;
Py_ssize_t buflen;
asciidig = _PyUnicode_TransformDecimalAndSpaceToASCII(u);
buffer = PyUnicode_AsUTF8AndSize(asciidig, &buflen);
if (buffer == NULL) {
Py_DECREF(asciidig);
- return NULL;
+ if (!PyErr_ExceptionMatches(PyExc_UnicodeEncodeError))
+ return NULL;
}
- result = PyLong_FromString(buffer, &end, base);
- if (result != NULL && end != buffer + buflen) {
- PyErr_SetString(PyExc_ValueError,
- "null byte in argument for int()");
- Py_DECREF(result);
- result = NULL;
+ else {
+ result = PyLong_FromString(buffer, &end, base);
+ if (end == NULL || (result != NULL && end == buffer + buflen)) {
+ Py_DECREF(asciidig);
+ return result;
+ }
+ Py_DECREF(asciidig);
+ Py_XDECREF(result);
}
- Py_DECREF(asciidig);
- return result;
- strobj = PySequence_GetSlice(u, 0, 200);
- if (strobj != NULL) {
- PyErr_Format(PyExc_ValueError,
- "invalid literal for int() with base %d: %R",
- base, strobj);
- Py_DECREF(strobj);
- }
++ PyErr_Format(PyExc_ValueError,
++ "invalid literal for int() with base %d: %.200R",
++ base, u);
+ return NULL;
}
/* forward */