[Zope] Can't locate PyObject_SetItem

Jonathan Hobbs toolkit at magma.ca
Wed Sep 22 07:47:00 EDT 2004


From: "Tim Peters" <tim.peters at gmail.com>
> [Jonathan Hobbs]
> ...
> > I have a better grasp on the situation now, but confusion still
reigns... I
> > don't understand how PyObject_SetItem (a python/C API) can increase the
size
> > of an IIBucket (which usually uses 'Bucket_grow' from BucketTemplate.c),
but
> > I will take it on faith that it magically works somehow, so that I can
> > continue my search for the performance problem with ZCTextIndex!
>
> Sounds normal.  PyObject_SetItem(obj, key, val) is the C way to spell
> the Python obj.__setitem__(key, val), which is in turn a low-level way
> to spell the Python "obj[key] = val".
>
> Then, in BucketTemplate.c, the BucketType struct's tp_mapping slot is
> set to the address of Bucket_as_mapping, and Bucket_as_mapping's
> mp_ass_subscript slot is in turn set to the function bucket_setitem.
> That means PyObject_Setitem resolves to calling bucket_setitem when
> called with a bucket obj.  bucket_setitem in turn calls _bucket_set,
> which *may* call Bucket_grow.
>
> An excruciating twist at the C level is that setitem functions are
> used both for setting a key in a mapping, and for deleting a key; the
> latter occurs if the associated "value" is C's NULL.


Great explanation!  Thanks Tim, that removes most of the magic!

Jonathan




More information about the Zope mailing list