Title: Stack overflow in reprlib causes a core dump
Type: crash Stage:
Components: Library (Lib) Versions: Python 3.4
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ceridwen, rhettinger, xtreak
Priority: normal Keywords:

Created on 2015-09-26 16:47 by ceridwen, last changed 2018-09-21 12:37 by xtreak.

Messages (1)
msg251655 - (view) Author: Ceridwen (ceridwen) Date: 2015-09-26 16:47
I have a linked list implementation made of nested tuples with a custom repr:

    def __repr__(self):
        return 'LinkedList(' + ', '.join(repr(v) for v in self) + ')'

(Iterating over a LinkedList returns just its contents.)

When using Raymond Hettinger's recipe for finding the size in memory of an object, , when I set verbose=True and exceed the recursion limit with reprlib.repr, I get the following error:

Fatal Python error: Cannot recover from stack overflow.

Current thread 0x00007fa24200d700 (most recent call first):
  File "<name of LinkedList file>.py", line 327 in __repr__
  File "/usr/lib/python3.4/", line 135 in repr_instance
  File "/usr/lib/python3.4/", line 64 in repr1
  File "/usr/lib/python3.4/", line 54 in repr
  File "", line 46 in sizeof
  [many instances of the above line repeated]
Aborted (core dumped)

The line in the recipe it fails when recursing on is:

            print(s, type(o), repr(o), file=stderr)

On 2.7 it fails with a RuntimeError as I'd expect.
Date User Action Args
2018-09-21 12:37:44xtreaksetnosy: + xtreak
2015-09-26 16:57:29serhiy.storchakasetnosy: + rhettinger
2015-09-26 16:47:58ceridwencreate