Hello,
I'm trying to write some extensions to python, and the point I am at now is such that I have a new type and I would like a member of this type to be a pointer to another python extension which is only a module method in a different module. The reason for this situation is that there is already an extension module written which consists only of various functions (all requiring the same arguments) and no types. No I have a type, and I would like to assign to this new type any of the previously defined funtions from the Python interpreter. For example:
Code:
from OldModule import oldfunc
from NewModule import MyType
cl = MyType()
cl.meth = oldfunc
My C structure looks like this.
Code:
typedef struct {
PyObject_HEAD;
PyObject * (*func)(PyObject *,PyObject *) meth;
} MyType_obj;
The compiler doesn't complain at that, but that isn't really saying much. The problem I'm encountering is in the getter and setter for the meth member. Any attempt to Py_INCREF or Py_DECREF on the meth member is a problem for the compiler. Perhaps I'm mistaken in the way Python counts references to function pointers. For the moment I'm concentrating on the setter function. If I ignore the reference counting I just mentioned, there is still a problem converting the generic PyObject pointer passed to the function to this function pointer type. I've assumed this is properly done by something like
Code:
PyArg_ParseTuple(value,"O!",&MyFunc_Type,&tmpmeth)
However, how is it best to define the pointer MyFunc_Type?
I'm looking into this because I think this is in the end is the more elegant option, but I do realise that I could simply rewrite the old module extensions. What are your thoughts and suggestions; I am interested to read them.
Thanks,
C