[Python-Dev] Re: [Python-checkins] CVS: python/dist/src/Objects object.c,2.124.4.11,2.124.4.12

Guido van Rossum guido@digicool.com
Mon, 11 Jun 2001 08:57:18 -0400


> > Modified Files:
> >       Tag: descr-branch
> > 	object.c 
> > Log Message:
> > Add _PyObject_GetDictPtr() -- an internal API to get a pointer to
> > where __dict__ is stored in an object.  The simplest case is to add
> > tp_dictoffset to the start of the object, but there are comlications:
> > tp_flags may tell us that tp_dictoffset is not defined, or the offset
> > may be negative: indexing from the end of the object, where
> > tp_itemsize may have to be taken into account.
> 
> Why would you ever have a negative size in there? That seems like an
> unnecessary "feature". The offsets are easily set up by the compiler as
> positive values. (not even sure how you'd come up with a proper/valid
> negative value)

When extending a type like tuple or string, the __dict__ has to be
added to the end, after the last item, because we can't change the
starting offset of the first item.  This is not at a fixed offset from
the start of the structure.

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