Re: C API : Creating a Py_Method object from a C function.
Hugh Macdonald wrote: PyMethodDef *callbackFunctionDef = new PyMethodDef; callbackFunctionDef-ml_name = doLoadCallback; callbackFunctionDef-ml_meth = myPython_doLoadCallback; callbackFunctionDef-ml_flags = 1; I think this gives a memory leak. I was rather thinking of static PyMethodDef doLoadCallback = { doLoadCallback, myPython_doLoadCallback, 1 }; PyObject *pyCallbackFunc = PyCFunction_New(doLoadCallback, NULL); Since you have to write the C(++) functions statically, you can also provide the PyMethodDef objects statically. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
C API : Creating a Py_Method object from a C function.
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: C API : Creating a Py_Method object from a C function.
Hugh Macdonald wrote: 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? You should use PyCFunction_New(Ex), passing a static PyMethodDef variable that you define along with your function definition. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list