[Python-Dev] with_traceback

Guido van Rossum guido at python.org
Fri Mar 2 05:52:51 CET 2007


On 3/1/07, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
> > You start with a traceback object pointing to the current frame
> > object (traceback objects are distinct from frame objects,
>
> Just out of curiosity, is it really necessary to have
> a distinct traceback object? Couldn't the traceback
> just be made of dead frame objects linked the opposite
> way through their f_next pointers?

That would be rather fragile; there's tons of code that follows f_next
pointers, without regard for whether the frame is alive or dead. Using
a separate pointer would be a possibility, but it would probably still
mean setting the f_next pointers to NULL to avoid hard cycles. Maybe
this idea could be used for a new VM design though.

> Seems to me it would be advantageous if raising an
> exception (once it's created) could be done without
> having to allocate any memory. Otherwise you could
> get the situation where you're trying to raise a
> MemoryError, but there's no memory to allocate a
> traceback object, so you raise a MemoryError...
> etc...
>
> That might be a reason for pre-allocating the
> MemoryError exception, too.

I think it is preallocated.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list