C API : Creating a Py_Method object from a C function.
"Martin v. Löwis"
martin at v.loewis.de
Wed Jul 13 02:34:34 EDT 2005
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
More information about the Python-list
mailing list