I have two different Python extension modules; call them A and B. Module A contains a storage class class called a container, which I want to use in module B as the type of the returned method of the class.
I can't seem to find documentation on how I should do this. I followed this article roughly to create modules / classes, except that I did not declare all methods static, so they would be available: http://nedbatchelder.com/text/whirlext.html
Then my question is: how can I create an instance of a container that I can pass back as the return value of the PyObject * class method in module B? The container definition is as follows:
typedef struct {
PyObject_HEAD
storageclass* cnt_;
} container;
I tried just doing the following in the method in question, where container_init is the method that I registered as tp_init for the container class:
pycnt::container* retval;
pycnt::container_init(retval, NULL, NULL);
return (PyObject*)retval;
However, according to the Python interpreter, I am returning the class to which I called the method. (i.e. myclassinstance.mymethod () returns myclassinstance).
I'm obviously wrong, but I have no idea what the right way is. Any suggestions? Just to cut someone out to suggest this - no, I'm not interested in using SWIG or Boost :: Python. I already tried this, and the main storage class for the container didn't play with it with anything (SWIG couldn't even parse it). So far, doing the extensions themselves has been pretty painless, but I'm at a standstill at that.