I wrote:

[snip]

> What am I missing?

The fundamental problem is that this:

   if (!(ro = PyObject_New(MyIter, &MyIterType)))
      return NULL;

is really only a malloc() - it doesn't call the tp_new function at all. This is not really clear in the 2.3 version of the C API document that I was consulting - the 2.4 version is much clearer.


I have no idea how to do in C all the things that calling a class constructor in Python does. Am I supposed to be calling tp_new & tp_init directly?

In the end, this particular class really only needs to be created from a factory function, so I removed the tp_new member altogether and just wrote a C function to initialise the object, and called that from the C factory function.

[The above is not particular to the fact that my class is an iterator - all C classes have the same behaviour. My test of a plain-old class probably looked like it worked due to lucky memory patterns.]


-- http://mail.python.org/mailman/listinfo/python-list

Reply via email to