[issue22453] PyObject_REPR macro causes refcount leak

Serhiy Storchaka report at bugs.python.org
Tue Nov 18 11:40:50 CET 2014


Serhiy Storchaka added the comment:

Thank you for your report Chris.

PyObject_REPR() is used only in Python/compile.c just before calling Py_FatalError(). So refcount leaks doesn't matter in these cases.

PyObject_REPR() is expanded to deprecated _PyUnicode_AsString which is not defined if Py_LIMITED_API is defined. So it is unlikely that third-party code uses it. We can just remove this macro in 3.5.

There are other bugs in formatting fatal error messages where PyObject_REPR() is used. PyBytes_AS_STRING() is called for unicode objects. Definitely this branch of the code is rarely executed.

Here is a patch which expands PyObject_REPR() in Python/compile.c and replaces PyBytes_AS_STRING() with PyUnicode_AsUTF8(). In 3.5 we also should remove the PyObject_REPR macro definition.

----------
assignee:  -> serhiy.storchaka
keywords: +patch
nosy: +serhiy.storchaka
stage:  -> patch review
type: behavior -> resource usage
versions:  -Python 3.1, Python 3.2, Python 3.3
Added file: http://bugs.python.org/file37220/PyObject_REPR.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22453>
_______________________________________


More information about the Python-bugs-list mailing list