[Python-Dev] Accessing globals without dict lookup (original) (raw)

Guido van Rossum guido@python.org
Mon, 11 Feb 2002 09:42:54 -0500


On Mon, 11 Feb 2002, Ka-Ping Yee wrote: > This simplifies things further: > > PyObject* cellget(PyGlobalCell* c) > { > return c->cellcellptr->cellobjptr; > }

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/)