Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 6245:15bcec3d3259 | 6246:4cf20fa883a9 |
|---|---|
| 759 if (v != NULL && v != Py_None) { | 759 if (v != NULL && v != Py_None) { |
| 760 PyObject *s = PyObject_Str(v); | 760 PyObject *s = PyObject_Str(v); |
| 761 /* only print colon if the str() of the | 761 /* only print colon if the str() of the |
| 762 object is not the empty string | 762 object is not the empty string |
| 763 */ | 763 */ |
| 764 if (s && strcmp(PyString_AsString(s), "")) | 764 if (s == NULL) |
| 765 err = -1; | |
| 766 else if (!PyString_Check(s) || | |
| 767 PyString_GET_SIZE(s) != 0) | |
| 765 err = PyFile_WriteString(": ", f); | 768 err = PyFile_WriteString(": ", f); |
| 766 if (err == 0) | 769 if (err == 0) |
| 767 err = PyFile_WriteObject(v, f, Py_PRINT_RAW); | 770 err = PyFile_WriteObject(s, f, Py_PRINT_RAW); |
| 771 Py_XDECREF(s); | |
| 768 } | 772 } |
| 769 } | 773 } |
| 770 if (err == 0) | 774 if (err == 0) |
| 771 err = PyFile_WriteString("\n", f); | 775 err = PyFile_WriteString("\n", f); |
| 772 } | 776 } |
