I have written code to define a new-type in Python C extension (MyStatus). I wrote the C code to define allocation,deallocation etc as mentioned in this page.
I was able to compile the module and use it from python.
Now i am trying to use this new type in another Python C extension (TestStatus) My requirement is i need to have only one .so for this. I dont want to use MyStatus directly from Python code. I will be only importing TestStatus in my code and i want to initialize the MyStatus from my C extension written for TestStatus.
I have written code like this for TestStatus
static PyObject * TestStatus_checkPyObject *self, PyObject *args)
{
PyObject * mystatus = NULL;
const char *command;
/* Call the class object. */
mystatus = PyObject_CallObject((PyObject *) &MyStatusType, NULL);
return mystatus;
}
PyMODINIT_FUNC initTestStatus(void)
{
(void) Py_InitModule("TestStatus", TestMethods);
initMyStatus();//This is available in the C code written for MyStatus
}
I was able to create the so like what i have mentioned in code. But i am stuck on setting the variables for MyStatus which is a integer and char*(PyObject*) Can somebody throw some light on this, like whether my approach is right and how to initialize and use MyStatus from TestStatus with arguments.
I am trying this with Python 2.6.6 on Rhel 6.3
In MyStatus i have 2 variables
typedef struct {
PyObject_HEAD
int mStatus;
PyObject *mErrorString;
} MyStatus;
I need to initialize the same from TestStatus.
.sofile? Would it work, if you put the code of both modules in one file? - Sorry, but I did not quit get the problem, so it's hard to shed some light on it.