summaryrefslogtreecommitdiffstats
path: root/Python/pathconfig.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-45582: Port getpath[p].c to Python (GH-29041)Steve Dower2021-12-031-490/+143
| | | | | The getpath.py file is frozen at build time and executed as code over a namespace. It is never imported, nor is it meant to be importable or reusable. However, it should be easier to read, modify, and patch than the previous code. This commit attempts to preserve every previously tested quirk, but these may be changed in the future to better align platforms.
* bpo-45471: Do not set PyConfig.stdlib_dir in Py_SetPythonHome(). (gh-28954)Eric Snow2021-10-141-4/+1
| | | | | The change in gh-28586 (bpo-45211) should not have included code to set _Py_path_config.stdlib_dir in Py_SetPythonHome(). We fix that here. https://bugs.python.org/issue45471
* Fix typos in the Python directory (GH-28767)Christian Clauss2021-10-061-1/+1
|
* bpo-45211: Remember the stdlib dir during startup. (gh-28586)Eric Snow2021-09-281-1/+30
| | | | | During runtime startup we figure out the stdlib dir but currently throw that information away. This change preserves it and exposes it via PyConfig.stdlib_dir, _Py_GetStdlibDir(), and sys._stdlib_dir. https://bugs.python.org/issue45211
* bpo-42260: Fix _PyConfig_Read() if compute_path_config=0 (GH-23220)Victor Stinner2020-11-101-74/+15
| | | | | | | | | | | | | | | | | | | Fix _PyConfig_Read() if compute_path_config=0: use values set by Py_SetPath(), Py_SetPythonHome() and Py_SetProgramName(). Add compute_path_config parameter to _PyConfig_InitPathConfig(). The following functions now return NULL if called before Py_Initialize(): * Py_GetExecPrefix() * Py_GetPath() * Py_GetPrefix() * Py_GetProgramFullPath() * Py_GetProgramName() * Py_GetPythonHome() These functions no longer automatically computes the Python Path Configuration. Moreover, Py_SetPath() no longer computes program_full_path.
* bpo-29778: test_embed tests the path configuration (GH-21306)Victor Stinner2020-07-071-0/+74
|
* bpo-29778: Ensure python3.dll is loaded from correct locations when Python ↵Steve Dower2020-07-061-46/+0
| | | | | | is embedded (GH-21297) Also enables using debug build of `python3_d.dll` Reference: CVE-2020-15523
* bpo-41056: Fix reference to deallocated stack in pathconfig (Coverity) ↵Gregory P. Smith2020-06-221-1/+1
| | | | | | | (GH-21013) Reported by Coverity. (CID 1457554 RETURN_LOCAL) path0 is assigned as a pointer to this right before it goes out of scope.
* bpo-40268: Remove unused osdefs.h includes (GH-19532)Victor Stinner2020-04-151-1/+1
| | | When the include is needed, add required symbol in a comment.
* bpo-40268: Remove unused pycore_pymem.h includes (GH-19531)Victor Stinner2020-04-151-1/+1
|
* bpo-40268: Remove a few pycore_pystate.h includes (GH-19510)Victor Stinner2020-04-141-1/+3
|
* bpo-39882: Add _Py_FatalErrorFormat() function (GH-19157)Victor Stinner2020-03-251-4/+10
|
* bpo-39882: Py_FatalError() logs the function name (GH-18819)Victor Stinner2020-03-061-4/+4
| | | | | | | | | | | | The Py_FatalError() function is replaced with a macro which logs automatically the name of the current function, unless the Py_LIMITED_API macro is defined. Changes: * Add _Py_FatalErrorFunc() function. * Remove the function name from the message of Py_FatalError() calls which included the function name. * Update tests.
* bpo-39270: Remove dead assignment from config_init_module_search_paths ↵Alex Henrie2020-01-091-2/+1
| | | | (GH-17914)
* bpo-29778: Fix incorrect NULL check in _PyPathConfig_InitDLLPath() (GH-17818)Anthony Wee2020-01-061-1/+1
|
* bpo-38353: getpath.c: allocates strings on the heap (GH-16585)Victor Stinner2019-10-041-9/+20
| | | | | | | | | | | * _Py_FindEnvConfigValue() now returns a string allocated by PyMem_RawMalloc(). * calculate_init() now decodes VPATH macro. * Add calculate_open_pyenv() function. * Add substring() and joinpath2() functions. * Fix add_exe_suffix() And a few cleanup changes.
* bpo-38304: PyConfig_InitPythonConfig() cannot fail anymore (GH-16509)Victor Stinner2019-10-011-7/+2
| | | | PyConfig_InitPythonConfig() and PyConfig_InitIsolatedConfig() no longer return PyStatus: they cannot fail anymore.
* bpo-38304: Remove PyConfig.struct_size (GH-16500) (GH-16508)Victor Stinner2019-10-011-1/+0
| | | | | | | For now, we'll rely on the fact that the config structures aren't covered by the stable ABI. We may revisit this in the future if we further explore the idea of offering a stable embedding API. (cherry picked from commit bdace21b769998396d0ccc8da99a8ca9b507bfdf)
* bpo-38304: Add PyConfig.struct_size (GH-16451)Victor Stinner2019-09-281-1/+6
| | | | | | | | | | | | | | | | | Add a new struct_size field to PyPreConfig and PyConfig structures to allow to modify these structures in the future without breaking the backward compatibility. * Replace private _config_version field with public struct_size field in PyPreConfig and PyConfig. * Public PyPreConfig_InitIsolatedConfig() and PyPreConfig_InitPythonConfig() return type becomes PyStatus, instead of void. * Internal _PyConfig_InitCompatConfig(), _PyPreConfig_InitCompatConfig(), _PyPreConfig_InitFromConfig(), _PyPreConfig_InitFromPreConfig() return type becomes PyStatus, instead of void. * Remove _Py_CONFIG_VERSION * Update the Initialization Configuration documentation.
* bpo-38234: Py_Initialize() sets global path configuration (GH-16421)Victor Stinner2019-09-261-7/+22
| | | | | | * Py_InitializeFromConfig() now writes PyConfig path configuration to the global path configuration (_Py_path_config). * Add test_embed.test_get_pathconfig(). * Fix typo in _PyWideStringList_Join().
* bpo-38234: Add test_init_setpath_config() to test_embed (GH-16402)Victor Stinner2019-09-261-5/+28
| | | | | | | | | | | | * Add test_embed.test_init_setpath_config(): test Py_SetPath() with PyConfig. * test_init_setpath() and test_init_setpythonhome() no longer call Py_SetProgramName(), but use the default program name. * _PyPathConfig: isolated, site_import and base_executable fields are now only available on Windows. * If executable is set explicitly in the configuration, ignore calculated base_executable: _PyConfig_InitPathConfig() copies executable to base_executable. * Complete path config documentation.
* bpo-38234: Py_SetPath() uses the program full path (GH-16357)Victor Stinner2019-09-241-4/+7
| | | | | | | Py_SetPath() now sets sys.executable to the program full path (Py_GetProgramFullPath()), rather than to the program name (Py_GetProgramName()). Fix also memory leaks in pathconfig_set_from_config().
* bpo-38234: Fix _PyConfig_InitPathConfig() (GH-16335)Victor Stinner2019-09-231-149/+166
| | | | | | | | | | | | | | | | * _PyConfig_InitPathConfig() now starts by copying the global path configuration, and then override values set in PyConfig. * _PyPathConfig_Calculate() implementations no longer override _PyPathConfig fields which are already computed. For example, if _PyPathConfig.prefix is not NULL, leave it unchanged. * If Py_SetPath() has been called, _PyConfig_InitPathConfig() doesn't call _PyPathConfig_Calculate() anymore. * _PyPathConfig_Calculate() no longer uses PyConfig, except to initialize PyCalculatePath structure. * pathconfig_calculate(): remove useless temporary "_PyPathConfig new_config" variable. * calculate_module_search_path(): remove hack to workaround memory allocation failure, call Py_FatalError() instead. * Fix get_program_full_path(): handle memory allocation failure.
* bpo-38234: Fix PyConfig_Read() when Py_SetPath() was called (GH-16298)Victor Stinner2019-09-201-0/+7
| | | | | | * If Py_SetPath() has been called, _PyConfig_InitPathConfig() now uses its value. * Py_Initialize() now longer copies path configuration from PyConfig to the global path configuration (_Py_path_config).
* bpo-38234: Remove _PyPathConfig.dll_path (GH-16307)Victor Stinner2019-09-201-62/+43
| | | | | | | | | The DLL path is not computed from any user configuration and cannot be configured by PyConfig. Instead, add a new _Py_dll_path global variable. Remove _PyConfig_SetPathConfig(): replaced with _PyPathConfig_Init(). Py_Initialize() now longer sets the "global path configuration", but only initialize _Py_dll_path.
* bpo-23878: Remove an unneeded fseek() call in _Py_FindEnvConfigValue() ↵Zackery Spytz2019-08-281-1/+0
| | | | (GH-15424)
* bpo-37369: Fix initialization of sys members when launched via an app ↵Steve Dower2019-06-291-0/+30
| | | | | | | container (GH-14428) sys._base_executable is now always defined on all platforms, and can be overridden through configuration. Also adds test.support.PythonSymlink to encapsulate platform-specific logic for symlinking sys.executable
* bpo-36763: Implement the PEP 587 (GH-13592)Victor Stinner2019-05-271-108/+106
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add a whole new documentation page: "Python Initialization Configuration" * PyWideStringList_Append() return type is now PyStatus, instead of int * PyInterpreterState_New() now calls PyConfig_Clear() if PyConfig_InitPythonConfig() fails. * Rename files: * Python/coreconfig.c => Python/initconfig.c * Include/cpython/coreconfig.h => Include/cpython/initconfig.h * Include/internal/: pycore_coreconfig.h => pycore_initconfig.h * Rename structures * _PyCoreConfig => PyConfig * _PyPreConfig => PyPreConfig * _PyInitError => PyStatus * _PyWstrList => PyWideStringList * Rename PyConfig fields: * use_module_search_paths => module_search_paths_set * module_search_path_env => pythonpath_env * Rename PyStatus field: _func => func * PyInterpreterState: rename core_config field to config * Rename macros and functions: * _PyCoreConfig_SetArgv() => PyConfig_SetBytesArgv() * _PyCoreConfig_SetWideArgv() => PyConfig_SetArgv() * _PyCoreConfig_DecodeLocale() => PyConfig_SetBytesString() * _PyInitError_Failed() => PyStatus_Exception() * _Py_INIT_ERROR_TYPE_xxx enums => _PyStatus_TYPE_xxx * _Py_UnixMain() => Py_BytesMain() * _Py_ExitInitError() => Py_ExitStatusException() * _Py_PreInitializeFromArgs() => Py_PreInitializeFromBytesArgs() * _Py_PreInitializeFromWideArgs() => Py_PreInitializeFromArgs() * _Py_PreInitialize() => Py_PreInitialize() * _Py_RunMain() => Py_RunMain() * _Py_InitializeFromConfig() => Py_InitializeFromConfig() * _Py_INIT_XXX() => _PyStatus_XXX() * _Py_INIT_FAILED() => _PyStatus_EXCEPTION() * Rename 'err' PyStatus variables to 'status' * Convert RUN_CODE() macro to config_run_code() static inline function * Remove functions: * _Py_InitializeFromArgs() * _Py_InitializeFromWideArgs() * _PyInterpreterState_GetCoreConfig()
* bpo-36763: Add _PyPreConfig._config_init (GH-13481)Victor Stinner2019-05-221-1/+1
| | | | | | | | | | | | | | | | | | | * _PyPreConfig_GetGlobalConfig() and _PyCoreConfig_GetGlobalConfig() now do nothing if the configuration was not initialized with _PyPreConfig_InitCompatConfig() and _PyCoreConfig_InitCompatConfig() * Remove utf8_mode=-2 special case: use utf8_mode=-1 instead. * Fix _PyPreConfig_InitPythonConfig(): * isolated = 0 instead of -1 * use_environment = 1 instead of -1 * Rename _PyConfig_INIT to _PyConfig_INIT_COMPAT * Rename _PyPreConfig_Init() to _PyPreConfig_InitCompatConfig() * Rename _PyCoreConfig_Init() to _PyCoreConfig_InitCompatConfig() * PyInterpreterState_New() now uses _PyCoreConfig_InitPythonConfig() as default configuration, but it's very quickly overriden anyway. * _freeze_importlib.c uses _PyCoreConfig_SetString() to set program_name. * Cleanup preconfig_init_utf8_mode(): cmdline is always non-NULL.
* bpo-36763: Remove _PyCoreConfig.dll_path (GH-13402)Victor Stinner2019-05-181-13/+3
|
* bpo-36763: Add _PyCoreConfig_InitPythonConfig() (GH-13388)Victor Stinner2019-05-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add new functions to get the Python interpreter behavior: * _PyPreConfig_InitPythonConfig() * _PyCoreConfig_InitPythonConfig() Add new functions to get an isolated configuration: * _PyPreConfig_InitIsolatedConfig() * _PyCoreConfig_InitIsolatedConfig() Replace _PyPreConfig_INIT and _PyCoreConfig_INIT with new functions _PyPreConfig_Init() and _PyCoreConfig_Init(). _PyCoreConfig: set configure_c_stdio and parse_argv to 0 by default to behave as Python 3.6 in the default configuration. _PyCoreConfig_Read() no longer sets coerce_c_locale_warn to 1 if it's equal to 0. coerce_c_locale_warn must now be set to -1 (ex: using _PyCoreConfig_InitPythonConfig()) to enable C locale coercion warning. Add unit tests for _PyCoreConfig_InitPythonConfig() and _PyCoreConfig_InitIsolatedConfig(). Changes: * Rename _PyCoreConfig_GetCoreConfig() to _PyPreConfig_GetCoreConfig() * Fix core_read_precmdline(): handle parse_argv=0 * Fix _Py_PreInitializeFromCoreConfig(): pass coreconfig.argv to _Py_PreInitializeFromPyArgv(), except if parse_argv=0
* bpo-36763: _PyInitError always use int for exitcode (GH-13360)Victor Stinner2019-05-161-7/+11
| | | | | | | | | | | | | | | | | We cannot use "unsigned int" for exitcode on Windows, since Py_Main() and _Py_RunMain() always return an "int". Changes: * _PyPathConfig_ComputeSysPath0() now returns -1 if an exception is raised. * pymain_run_python() no longer uses _PyInitError but display the exception and set exitcode to 1 in case of error. * Fix _Py_RunMain(): return an exitcode rather than calling exit() on pymain_run_python() failure. * _Py_ExitInitError() no longer uses ExitProcess() on Windows, use exit() on all platforms. * _Py_ExitInitError() now fails with a fatal error if 'err' is not an error not an exit.
* bpo-36763: Add _PyCoreConfig_SetArgv() (GH-13030)Victor Stinner2019-05-011-1/+1
| | | | | | | | | * Add 2 new config methods: * _PyCoreConfig_SetArgv() * _PyCoreConfig_SetWideArgv() * Add also an internal _PyCoreConfig_SetPyArgv() method. * Remove 'args' parameter from _PyCoreConfig_Read().
* bpo-36301: Cleanup preconfig.c and coreconfig.c (GH-12563)Victor Stinner2019-03-261-1/+1
| | | | | | | | | | | | | | | * _PyCoreConfig_Write() now updates _PyRuntime.preconfig * Remove _PyPreCmdline_Copy() * _PyPreCmdline_Read() now accepts _PyPreConfig and _PyCoreConfig optional configurations. * Rename _PyPreConfig_ReadFromArgv() to _PyPreConfig_Read(). Simplify the code. * Calling _PyCoreConfig_Read() no longer adds the warning options twice: don't add a warning option if it's already in the list. * Rename _PyCoreConfig_ReadFromArgv() to _PyCoreConfig_Read(). * Rename config_from_cmdline() to _PyCoreConfig_ReadFromArgv(). * Add more assertions on _PyCoreConfig in _PyCoreConfig_Read(). * Move some functions. * Make some config functions private.
* bpo-36301: Remove _PyCoreConfig.preconfig (GH-12546)Victor Stinner2019-03-261-1/+1
| | | | | | * Replace _PyCoreConfig.preconfig with 3 new fields in _PyCoreConfig: isolated, use_environment, dev_mode. * Add _PyPreCmdline.dev_mode. * Add _Py_PreInitializeFromPreConfigInPlace().
* bpo-36301: Cleanup preconfig code (GH-12535)Victor Stinner2019-03-251-1/+1
| | | | | | | | | | | | | | | Prepare code to move some _PyPreConfig parameters into _PyPreCmdline. Changes: * _PyCoreConfig_ReadFromArgv(): remove preconfig parameter, use _PyRuntime.preconfig. * Add _PyPreCmdline_GetPreConfig() (called by _PyPreConfig_Read()). * Rename _PyPreCmdline_Init() to _PyPreCmdline_SetArgv() * Factorize _Py_PreInitializeFromPreConfig() code: add pyinit_preinit(). * _PyPreConfig_Read() now sets coerce_c_locale to 2 if it must be coerced. * Remove _PyCoreConfig_ReadPreConfig(). * _PyCoreConfig_Write() now copies updated preconfig into _PyRuntime.
* bpo-36236: Fix _PyPathConfig_ComputeSysPath0() for empty argv (GH-12441)Victor Stinner2019-03-191-55/+63
| | | | | * _PyPathConfig_ComputeSysPath0() now returns 0 if argv is empty. * Cleanup also _PyPathConfig_ComputeSysPath0() code: move variables definitions closer to where they are used.
* bpo-36236: Handle removed cwd at Python init (GH-12424)Victor Stinner2019-03-191-8/+23
| | | | | | | | At Python initialization, the current directory is no longer prepended to sys.path if it has been removed. Rename _PyPathConfig_ComputeArgv0() to _PyPathConfig_ComputeSysPath0() to avoid confusion between argv[0] and sys.path[0].
* bpo-36352: Avoid hardcoded MAXPATHLEN size in getpath.c (GH-12423)Victor Stinner2019-03-191-6/+8
| | | | * Use Py_ARRAY_LENGTH() rather than hardcoded MAXPATHLEN in getpath.c. * Pass string length to functions modifying strings.
* bpo-36301: Error if decoding pybuilddir.txt fails (GH-12422)Victor Stinner2019-03-191-1/+1
| | | | | | | | Python initialization now fails if decoding pybuilddir.txt configuration file fails at startup. _PyPathConfig_Calculate() now reports memory allocation failure and decoding error on decoding pybuilddir.txt content from UTF-8/surrogateescape.
* bpo-36301: Fix Py_Main() memory leaks (GH-12420)Victor Stinner2019-03-181-0/+5
| | | | | | | | | | bpo-36301, bpo-36333: * Fix memory allocator used by _PyPathConfig_ClearGlobal(): force the default allocator. * _PyPreConfig_ReadFromArgv(): free init_ctype_locale memory. * pymain_main(): call pymain_free() on init error Co-Authored-By: Stéphane Wirtel <stephane@wirtel.be>
* bpo-36301: Add _PyWstrList structure (GH-12343)Victor Stinner2019-03-151-21/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace messy _Py_wstrlist_xxx() functions with a new clean _PyWstrList structure and new _PyWstrList_xxx() functions. Changes: * Add _PyCoreConfig.use_module_search_paths to decide if _PyCoreConfig.module_search_paths should be computed or not, to support empty search path list. * _PyWstrList_Clear() sets length to 0 and items to NULL, whereas _Py_wstrlist_clear() only freed memory. * _PyWstrList_Append() returns an int, whereas _Py_wstrlist_append() returned _PyInitError. * _PyWstrList uses Py_ssize_t for the length, instead of int. * Replace (int, wchar_t**) with _PyWstrList in: * _PyPreConfig * _PyCoreConfig * _PyPreCmdline * _PyCmdline * Replace "int orig_argv; wchar_t **orig_argv;" with "_PyWstrList orig_argv". * _PyCmdline and _PyPreCmdline now also copy wchar_argv. * Rename _PyArgv_Decode() to _PyArgv_AsWstrList(). * PySys_SetArgvEx() now pass the fixed (argc, argv) to _PyPathConfig_ComputeArgv0() (don't pass negative argc or NULL argv). * _PyOS_GetOpt() uses Py_ssize_t
* bpo-36142: Add _PyPreConfig_ReadFromArgv() (GH-12173)Victor Stinner2019-03-051-1/+1
| | | | The new function is now responsible to parse -E and -I command line arguments.
* bpo-36142: Add _PyPreConfig structure (GH-12172)Victor Stinner2019-03-051-1/+1
| | | | | | * Add _PyPreConfig structure * Move 'ignored' and 'use_environment' fields from _PyCoreConfig to _PyPreConfig * Add a new "_PyPreConfig preconfig;" field to _PyCoreConfig
* bpo-36142: Rework error reporting in pymain_main() (GH-12113)Victor Stinner2019-03-011-1/+1
| | | | | | | | | | | Add a new _Py_INIT_EXIT() macro to be able to exit Python with an exitcode using _PyInitError API. Rewrite function calls by pymain_main() to use _PyInitError. Changes: * Remove _PyMain.err and _PyMain.status field * Add _Py_INIT_EXIT() macro and _PyInitError.exitcode field. * Rename _Py_FatalInitError() to _Py_ExitInitError().
* bpo-36142: Exclude coreconfig.h from Py_LIMITED_API (GH-12111)Victor Stinner2019-03-011-0/+1
| | | | | | | | | The whole coreconfig.h header is now excluded from Py_LIMITED_API. Move functions definitions into a new internal pycore_coreconfig.h header. * Move Include/coreconfig.h to Include/cpython/coreconfig.h * coreconfig.h header is now excluded from Py_LIMITED_API * Move functions to pycore_coreconfig.h
* bpo-35890 : Fix some API calling consistency (GH-11742)Minmin Gong2019-02-031-3/+9
| | | | Unicode version of Windows APIs are used in places, but not for GetVersionEx in Python/sysmodule.c The wcstok_s is called on Windows in Modules/main.c and PC/launcher.c, but not in Python/pathconfig.c
* bpo-34725: Adds _Py_SetProgramFullPath so embedders may override ↵Steve Dower2018-11-181-24/+33
| | | | sys.executable (GH-9860)
* bpo-35081: Rename internal headers (GH-10275)Victor Stinner2018-11-121-2/+2
| | | | | | | | | | | | | | Rename Include/internal/ headers: * pycore_hash.h -> pycore_pyhash.h * pycore_lifecycle.h -> pycore_pylifecycle.h * pycore_mem.h -> pycore_pymem.h * pycore_state.h -> pycore_pystate.h Add missing headers to Makefile.pre.in and PCbuild: * pycore_condvar.h. * pycore_hamt.h * pycore_pyhash.h
* bpo-35081: Add pycore_fileutils.h (GH-10371)Victor Stinner2018-11-061-0/+1
| | | | Move Py_BUILD_CORE code from Include/fileutils.h to a new Include/internal/pycore_fileutils.h file.