bpo-40412: Nullify inittab_copy during finalization by indygreg · Pull Request #19746 · python/cpython (original) (raw)

Hum, inittab_copy is freed by pymain_free(). I added this function to clear objects and memory which cannot be freed by Py_Finalize() for backward compatibility.

The PEP 587 says:

PyImport_FrozenModules, PyImport_AppendInittab() and PyImport_ExtendInittab() functions are still relevant and continue to work as previously. They should be set or called after Python preinitialization and before the Python initialization.

I understood that PyImport_AppendInittab() can be called only once, but Py_Initialize() and Py_Finalized() can be called multiple times: the PyImport_AppendInittab() call is expected to be saved even after Py_Finalized().

I understand that this change only impacts C code which calls Py_RunMain() or Py_Main() multiple times. I'm not sure if it was supported previously, but it's a good thing if slowly Python supports it :-)