[Python-Dev] Preserving the blamelist

Phillip J. Eby pje at telecommunity.com
Wed Apr 12 18:49:35 CEST 2006


At 03:00 AM 4/12/2006 -0400, Tim Peters wrote:
>Phillip, when eyeballing gen_dealloc(), I didn't understand two things:
>
>1. Why doesn't
>
>         if (gen->gi_frame->f_stacktop!=NULL) {
>
>    check first to be sure that gen->gi_frame != Py_None?

Apparently, it's because I'm an idiot, and because nobody else realized 
this during the initial review of the patch.  :)


>Is that impossible here for some reason?

No, I goofed.  It's amazing that this doesn't dump core whenever a 
generator exits.  :(



>2. It _looks_ like "gi_frame != NULL" is an (undocumented) invariant.
>Right?  If so,
>
>         Py_XDECREF(gen->gi_frame);
>
>    sends a confusing message (because of the "X", implying that NULL is OK).
>    Regardless, it would be good to add comments to genobject.h explaining
>    the possible values gi_frame can hold.  For example, what does it mean
>    when gi_frame is Py_None?  Can it ever be NULL?

I think what happened is that at one point I thought I was going to set 
gi_frame=NULL when there's no active frame, in order to speed up 
reclamation of the frame.  However, I think I then thought that it would 
break the operation of the generator's 'gi_frame' attribute, which is 
defined as T_OBJECT.  Or else I thought that the tp_visit was screwed up in 
that case.

So, it looks to me like what this *should* do is simply allow gi_frame to 
be NULL instead of Py_None, which would get rid of all the silly casting, 
and retroactively make the XDECREF correct.  :)

Does gen_traverse() need to do anything special to visit a null 
pointer?  Should it only conditionally visit it?



More information about the Python-Dev mailing list