[Python-Dev] Accessing globals without dict lookup
Guido van Rossum
guido@python.org
2002年2月11日 09:42:54 -0500
> On 2002年2月11日, Ka-Ping Yee wrote:
> > This simplifies things further:
> >
> > PyObject* cell_get(PyGlobalCell* c)
> > {
> > return c->cell_cellptr->cell_objptr;
> > }
>> I forgot to mention that this would also add loopback cellptrs for
> the two cells pointed to by __builtin__.abs and __builtin__.max.
>> But hey... in that case the cellptr is always two steps away from
> the object. So why not just use PyObject**s instead of cells?
>> dict -> ptr -> ptr -> object
>> (Or, if we want to maintain backward compatibility with existing
> dictionaries, let a cell be an object, so we can check its type,
> and have it contain just one pointer instead of two?)
>> Am i out to lunch?
I think so. Think of max in the example used for your diagram (thanks
for that BTW!). The first cell for it contains 3; the second cell for
it contains the built-in function 'max'. A double dereference would
get the wrong value.
Or did I misread your suggestion?
--Guido van Rossum (home page: http://www.python.org/~guido/)