[CentralOH] New Types
David Car
david.car at earthlink.net
Wed Jun 13 23:22:32 CEST 2007
Hey Python Gang,
I have a question about new types in Python. Just finished reading up and
trying a few things out, but I'm a little confused about one thing. When
declaring a new type, we basically have two new structures. One is the per
instance structure (your PyObject structure), which is basically an expansion
of the PyObject structure. At the beginning of that structure is the macro
declaration of PyObject_HEAD which contains the reference counter and a
pointer to the new type which is a structure of _typeobject. Then for your
new type (i.e. your _typeobject structure) there is a place holder for the
size of your per instance PyObject structure along with all the necessary
function pointers your new type will support. My question is this: Where
and when does the pointer in your per instance PyObject structure get set?
How does the interpreter know that your PyObject structure is related to your
PyTypeObject structure? Since your PyObject structure naming convention is
not tied to your PyTypeObject name, how are the two associated? I see how
your type is statically instantiated in the initialization, but I don't see
where your per instance PyObject is related to it? Is it simply that the two
structures co-exist in the same module? Thanks.
--
Regards,
David
More information about the CentralOH
mailing list