Riskless deletion of nested structures

Christian Tismer tismer at tismer.com
Mon Jan 31 10:59:15 EST 2000


Howdy,

Please review!

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

	_Py_trashcan_install();

at the end of Py_Initialize in pythonrun.c

Please try it and check my code wether there is a better solution.

cheers - chris

-- 
Christian Tismer             :^)   <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Düppelstr. 31                :    *Starship* http://starship.python.net
12163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trashcan.c
Type: application/x-unknown-content-type-cfile
Size: 2210 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20000131/4c063f63/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trashcan.h
Type: application/x-unknown-content-type-hfile
Size: 246 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20000131/4c063f63/attachment-0001.bin>


More information about the Python-list mailing list