[issue25455] Some repr implementations don't check for self-referential structures

Serhiy Storchaka report at bugs.python.org
Sun Nov 1 15:05:17 EST 2015


Serhiy Storchaka added the comment:

The general solution is to make PyObject_Repr to detect recursive calls (as reprlib.recursive_repr does).

The straightforward way is to use thread local identity set. It can be implemented as a dict that maps id(obj) -> obj (creates an int object for key for every call, requires about 40-80 bytes for recurse level), or as specialized hash table (see Modules/hashtable.c) (faster, requires about 12-24 bytes for recurse level).

The fastest solution would be to set special flag inside proceeded object. For now general object has no place for such flag, but we can add it to GC head. On 64-bit this would increase the size of GC head from 24 to 32 bytes, on 32-bit there is a free place in 16-bytes GC head.

However the performance can be not critical here, because in any case repr() creates new object (resulting string). Using thread local hash table can be enough. In any case the patch will be enough complex to target it 3.6 only.

----------
nosy: +serhiy.storchaka

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


More information about the Python-bugs-list mailing list