How do I add method dynamically to module using C API?

Martin v. Loewis martin at v.loewis.de
Thu Jul 8 01:23:15 EDT 2010


> And since things work for a single method when I declare 'def' as
> 'static', I suspect that means that the function object created by
> PyCFunction_NewEx holds on to a pointer to the PyMethodDef structure?

Correct; it doesn't make a copy of the struct. So when you want the
function object to outlive the setRoutine call, you need to allocate
the PyMethodDef on the heap.

Regards,
Martin



More information about the Python-list mailing list