C API : Creating a Py_Method object from a C function.

Hugh Macdonald hugh.macdonald at gmail.com
Mon Jul 11 13:07:49 EDT 2005


I've got a pure python module that parses a certain type of file. It
has a load() function that allows a callback function to be passed for
getting progress information.

In straight python, this works fine.

However, I'm now trying to use this from a C++ program. The current
flow that I'm trying to get is as follows:

C++ calls python interface function, passing a C++ function pointer
Python interface function stores C++ function pointer
Python interface function generates new Py_Object method pointer
pointing to a different C python function. (This different function
calls the stored C++ function pointer)
Python interface function calls python function
Python function calls the python method pointer it was passed
C python function then calls the stored C++ function pointer.


The problem in this workflow is taking the C python function that I've
defined (using the standard "static PyObject *someFunction(PyObject
*self, PyObject *args)" method) and converting this into a Py_Object.
Any ideas?

Py_Method doesn't seem to allow you to generate a new one with your own
pointers inside... and I can't see anything else in the docs that might
allow me to do this...


Thanks for any advice!

--
Hugh Macdonald




More information about the Python-list mailing list