While implementing Stackless Python, a new problem arose: Nested structures like frame chains and tracebacks can now easily grow somuch that they cause a stack overflow on deallocation.
To protect lists, tuples, frames, dicts and tracebacks against this, I wrote a stackless deallocator. At the moment, everything is done in trashcan.c . This gives a slight performance loss of 5% for pystone, most probably due to the double indirection and non-local code reference. It is yet a hack, since I'm grabbing the tp->dealloc pointers of these types and replace them by safe versions. This just in order to try out things quickly. Later I will change this and incorporate the stack checks into the affected modules, after I got some feedback on this.
This patch applies to Stackless and standard Python as well: Deallocation of deeply nested structures will never again cause a stack overflow.
Installation for the intermediate version: Insert a line
at the end of Py_Initialize in pythonrun.c
Please try it and check my code wether there is a better solution.
cheers - chris