◐ Shell
clean mode source ↗

bpo-32030: Rewrite calculate_path() by vstinner · Pull Request #4521 · python/cpython

* calculate_path() rewritten in Modules/getpath.c and PC/getpathp.c
* Move global variables into a new PyPathConfig structure.
* calculate_path():

  * Split the huge calculate_path() function into subfunctions.
  * Add PyCalculatePath structure to pass data between subfunctions.
  * Document PyCalculatePath fields.
  * Move cleanup code into a new calculate_free() subfunction
  * calculate_init() now handles Py_DecodeLocale() failures properly
  * calculate_path() is now atomic: only replace PyPathConfig
    (path_config) at once on success.

* _Py_GetPythonHomeWithConfig() now returns an error on failure
* Add _Py_INIT_NO_MEMORY() helper: report a memory allocation failure
* Coding style fixes (PEP 7)
* Add PyCalculatePath.prog
* Remove extern Py_GetProgramName
* calculate_path() works on a temporary configuration, and only
  writes the new full configuration at once on success
Use config->xxx rather than xxx, so later it will be possible to use
wchar_t* rather than wchar_t[] in PyPathConfig.
Mark calculate_module_search_path() as private.