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

"Martin v. Löwis" martin at v.loewis.de
Wed Jul 13 08:34:34 CEST 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,

Since you have to write the C(++) functions statically, you can also
provide the PyMethodDef objects statically.


More information about the Python-list mailing list