[Python-Dev] recursion limit in marshal (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Fri May 18 07:52:40 CEST 2007


The point of this message is to see if anyone thinks 2000 is unreasonable. It could probably be raised, but I'm not going to try it since I don't have access to a Windows box. Testing this remotely sucks.

If this turns out ever to be a limitation, I would challenge the reporter to rewrite marshal in a non-recursive manner.

It shouldn't be that difficult: w_object should operate a queue of objects yet to be written, and Tuple, Dict, Set (why does marshal support writing sets, anyway?) would all just add things to the queue rather than recursively invoking w_object.

The only challenge would be code objects, which have a w_long interspersed with the w_object calls. I would fix this by changing the marshal format of code objects, to move the co_firstlineno to the beginning.

For reading, a heap-managed stack would be necessary, consisting of a (type, value, position, next) linked list. Again, code objects would need special casing, to allow construction with NULL pointers at first, followed by indexed setting of the code fields. For lists and tuples, position would define the next index to be filled; for dictionaries, it would not be needed, and for code objects, it would index the various elements of the code object.

Regards, Martin



More information about the Python-Dev mailing list