Message 27388 - Python tracker (original) (raw)

signature is:

int PyImport_AppendInittab(char *name, void (*initfunc)(void))

if the 'name' pointer is freed or overwritten directly after the call to PyImport_AppendInittab, this call returns true but fails making the module known, and the interpreter crashes on PyFinalize(); this suggests that PyImport_AppendInittab stores the name pointer and uses it later, after leaving this function. this is undocumented and leads to crashes if name is freed in the meantime. (a typical c problem)

this function is important to boost::python library to extend python with c++.

workaround for c/c++ users: -malloc a char* for the name, -copy the modulename to name -call PyImport_AppendInittab with this name -DONT free name. (leaving a memory-leak)

btw, 'char ' should be 'const char', but this applies to most other Python API functions.