Hi,
It seems like there is a small bug (or a missing detail) in the example code of the main function in Chapter "1.4. The Module’s Method Table and Initialization Function".
In the example, the return value of PyImport_ImportModule is discarded. In my experience, this may cause a crash in Py_Finalize() if the return value is discarded and Py_DECREF is omitted.
Is my assumption correct that the example should actually be extended as follows?
...
/* Optionally import the module; alternatively,
import can be deferred until the embedded script
imports it. */
PyObject *pModule = PyImport_ImportModule("spam");
...
Py_DECREF(pModule);
if (Py_FinalizeEx() < 0) {
exit(120);
}
PyMem_RawFree(program);
return 0;