frameobject.c bug ? No call to PyFrame_LocalsToFast.

Boris Boutillier boris at cantal.lip6.fr
Fri Apr 12 04:18:03 EDT 2002


This is not completely true, as we can generate some code with
CO_NEWLOCALS removed, with new.code for example.

I'll give here an example of what can be done with this initialisation
(that by the way just need to be done if CO_NEWLOCALS = 0 so no overhead
for common case, see and of post for the diff).

I've written a GenFunction class that is used as follow :

def f(toto,tata,*args,**kwds):
	print 'args :',toto,tata,args,kwds
	print 'value :',value
	value = 5
	print 'gbl :',gbl

f = GenFunction(f)
g = {'gbl':3}
l = {'value':4}
gbl = 12

f('toto','tata','a1','a2','a3',k='k1',l='k2',globals=g,locals=l)

>>args : toto tata ('a1', 'a2', 'a3') {'k': 'k1', 'l': 'k2'}
>>value : 4
>>gbl : 3

In fact I've also written a GenDict class, inherited from dict to which
you give a creation function to use when searched key is not in dict,
with the previous GenFunction class this allow to use globals and locals
that create automatic variables.

So I don't understand why not a call to PyFrame_LocalsToFast when Locals
is not null or empty, the overhead is just for the special case (the test
is already done in the code.

I give here the diff between the python2.2.1c2 version of frameobject.c
and my version :

diff Objects/frameobject.c ../Python-2.2.1c2/Objects/frameobject.c 
277,282d276
<       
<       while (--extras >= 0)
<               f->f_localsplus[extras] = NULL;
<       
<       f->f_nlocals = code->co_nlocals;
<       
293d286
<               f->f_locals = locals;
299,300d291
<               f->f_locals = locals;
<               PyFrame_LocalsToFast(f,1);
302c293
<       
---
>       f->f_locals = locals;
307d297
< 
311a302
>       f->f_nlocals = code->co_nlocals;
315a307,308
>       while (--extras >= 0)
>               f->f_localsplus[extras] = NULL;



Boris



More information about the Python-list mailing list