Mercurial > cpython-lru_cache-weakref
diff Python/pythonrun.c @ 6246:4cf20fa883a9 legacy-trunk
Fixed some details of printing the str() of an exception. This fixes
a core dump when __str__() returns a non-string, and plugs a memory
leak as well: the result of PyObject_Str() was never DECREFed.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 05 Sep 1997 19:11:53 +0000 |
| parents | dc974b3a6cf4 |
| children | 05d943c4597c |
line wrap: on
line diff
--- a/Python/pythonrun.c Fri Sep 05 19:00:56 1997 +0000 +++ b/Python/pythonrun.c Fri Sep 05 19:11:53 1997 +0000 @@ -761,10 +761,14 @@ /* only print colon if the str() of the object is not the empty string */ - if (s && strcmp(PyString_AsString(s), "")) + if (s == NULL) + err = -1; + else if (!PyString_Check(s) || + PyString_GET_SIZE(s) != 0) err = PyFile_WriteString(": ", f); if (err == 0) - err = PyFile_WriteObject(v, f, Py_PRINT_RAW); + err = PyFile_WriteObject(s, f, Py_PRINT_RAW); + Py_XDECREF(s); } } if (err == 0)
