summaryrefslogtreecommitdiffstats
path: root/Modules/getpath.c
Commit message (Collapse)AuthorAgeFilesLines
* bpo-32030: Add _Py_FindEnvConfigValue() (#4963)Victor Stinner2017-12-211-72/+9
| | | | | | | | | | | | | | | Add a new _Py_FindEnvConfigValue() function: code shared between Windows and Unix implementations of _PyPathConfig_Calculate() to read the pyenv.cfg file. _Py_FindEnvConfigValue() now uses _Py_DecodeUTF8_surrogateescape() instead of using a Python Unicode string, the Python API must not be used early during Python initialization. Same change in Unix search_for_exec_prefix(): use _Py_DecodeUTF8_surrogateescape(). Cleanup also encode_current_locale(): PyMem_RawFree/PyMem_Free can be called with NULL. Fix also "NUL byte" => "NULL byte" typo.
* bpo-32030: Add _Py_EncodeLocaleRaw() (#4961)Victor Stinner2017-12-211-2/+2
| | | | | | | | | | | | Replace Py_EncodeLocale() with _Py_EncodeLocaleRaw() in: * _Py_wfopen() * _Py_wreadlink() * _Py_wrealpath() * _Py_wstat() * pymain_open_filename() These functions are called early during Python intialization, only the RAW memory allocator must be used.
* bpo-29240, bpo-32030: Py_Main() re-reads config if encoding changes (#4899)Victor Stinner2017-12-161-1/+1
| | | | | | | | | | | | | | | | | | bpo-29240, bpo-32030: If the encoding change (C locale coerced or UTF-8 Mode changed), Py_Main() now reads again the configuration with the new encoding. Changes: * Add _Py_UnixMain() called by main(). * Rename pymain_free_pymain() to pymain_clear_pymain(), it can now be called multipled times. * Rename pymain_parse_cmdline_envvars() to pymain_read_conf(). * Py_Main() now clears orig_argc and orig_argv at exit. * Remove argv_copy2, Py_Main() doesn't modify argv anymore. There is no need anymore to get two copies of the wchar_t** argv. * _PyCoreConfig: add coerce_c_locale and coerce_c_locale_warn. * Py_UTF8Mode is now initialized to -1. * Locale coercion (PEP 538) now respects -I and -E options.
* bpo-32030: Rewrite _PyMainInterpreterConfig (#4854)Victor Stinner2017-12-141-30/+29
| | | | | | | | | | | | | | | | | | | | _PyMainInterpreterConfig now contains Python objects, whereas _PyCoreConfig contains wchar_t* strings. Core config: * Rename _PyMainInterpreterConfig_ReadEnv() to _PyCoreConfig_ReadEnv() * Move 3 strings from _PyMainInterpreterConfig to _PyCoreConfig: module_search_path_env, home, program_name. * Add _PyCoreConfig_Clear() * _PyPathConfig_Calculate() now takes core config rather than main config * _PyMainInterpreterConfig_Read() now requires also a core config Main config: * Add _PyMainInterpreterConfig.module_search_path: sys.path list * Add _PyMainInterpreterConfig.argv: sys.argv list * _PyMainInterpreterConfig_Read() now computes module_search_path
* bpo-32241: Add the const qualifire to declarations of umodifiable strings. ↵Serhiy Storchaka2017-12-121-1/+1
| | | | (#4748)
* Revert "bpo-32197: Try to fix a compiler error on OS X introduced in ↵Victor Stinner2017-12-041-151/+46
| | | | | | | | | | | | | | | | | | | | | | | bpo-32030. (#4681)" (#4694) * Revert "bpo-32197: Try to fix a compiler error on OS X introduced in bpo-32030. (#4681)" This reverts commit 13badcbc60cdbfae1dba1683fd2fae9d70717143. Re-apply commits: * "bpo-32030: _PyPathConfig_Init() sets home and program_name (#4673)" commit af5a895073c24637c094772b27526b94a12ec897. * "bpo-32030: Fix config_get_program_name() on macOS (#4669)" commit e23c06e2b03452c9aaf0dae52296c85e572f9bcd. * "bpo-32030: Add Python/pathconfig.c (#4668)" commit 0ea395ae964c9cd0f499e2ef0d0030c971201220. * "bpo-32030: Don't call _PyPathConfig_Fini() in Py_FinalizeEx() (#4667)" commit ebac19dad6263141d5db0a2c923efe049dba99d2. * "bpo-32030: Fix Py_GetPath(): init program_name (#4665)" commit 9ac3d8882712c9675c3d2f9f84af6b5729575cde. * Fix compilation error on macOS
* bpo-32197: Try to fix a compiler error on OS X introduced in bpo-32030. (#4681)Serhiy Storchaka2017-12-021-46/+151
| | | | | | | | | | | | | | | | | | | | | | * Revert "bpo-32030: _PyPathConfig_Init() sets home and program_name (#4673)" This reverts commit af5a895073c24637c094772b27526b94a12ec897. * Revert "bpo-32030: Fix config_get_program_name() on macOS (#4669)" This reverts commit e23c06e2b03452c9aaf0dae52296c85e572f9bcd. * Revert "bpo-32030: Add Python/pathconfig.c (#4668)" This reverts commit 0ea395ae964c9cd0f499e2ef0d0030c971201220. * Revert "bpo-32030: Don't call _PyPathConfig_Fini() in Py_FinalizeEx() (#4667)" This reverts commit ebac19dad6263141d5db0a2c923efe049dba99d2. * Revert "bpo-32030: Fix Py_GetPath(): init program_name (#4665)" This reverts commit 9ac3d8882712c9675c3d2f9f84af6b5729575cde.
* bpo-32030: _PyPathConfig_Init() sets home and program_name (#4673)Victor Stinner2017-12-021-14/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | _PyPathConfig_Init() now also initialize home and program_name: * Rename existing _PyPathConfig_Init() to _PyPathConfig_Calculate(). Add a new _PyPathConfig_Init() function in pathconfig.c which handles the _Py_path_config variable and call _PyPathConfig_Calculate(). * Add home and program_name fields to _PyPathConfig.home * _PyPathConfig_Init() now initialize home and program_name from main_config * Py_SetProgramName(), Py_SetPythonHome() and Py_GetPythonHome() now calls Py_FatalError() on failure, instead of silently ignoring failures. * config_init_home() now gets directly _Py_path_config.home to only get the value set by Py_SetPythonHome(), or NULL if Py_SetPythonHome() was not called. * config_get_program_name() now gets directly _Py_path_config.program_name to only get the value set by Py_SetProgramName(), or NULL if Py_SetProgramName() was not called. * pymain_init_python() doesn't call Py_SetProgramName() anymore, _PyPathConfig_Init() now always sets the program name * Call _PyMainInterpreterConfig_Read() in pymain_parse_cmdline_envvars_impl() to control the memory allocator * C API documentation: it's no more safe to call Py_GetProgramName() before Py_Initialize().
* bpo-32030: Add Python/pathconfig.c (#4668)Victor Stinner2017-12-011-113/+1
| | | | | | | * Factorize code from PC/getpathp.c and Modules/getpath.c to remove duplicated code * rename pathconfig_clear() to _PyPathConfig_Clear() * Inline _PyPathConfig_Fini() in pymain_impl() and then remove it, since it's a oneliner
* bpo-32030: Don't call _PyPathConfig_Fini() in Py_FinalizeEx() (#4667)Victor Stinner2017-12-011-4/+6
| | | | | | | | | | | | | | | Changes: * _PyPathConfig_Fini() cannot be called in Py_FinalizeEx(). Py_Initialize() and Py_Finalize() can be called multiple times, but it must not "forget" parameters set by Py_SetProgramName(), Py_SetPath() or Py_SetPythonHome(), whereas _PyPathConfig_Fini() clear all these parameters. * config_get_program_name() and calculate_program_full_path() now also decode paths using Py_DecodeLocale() to use the surrogateescape error handler, rather than decoding using mbstowcs() which is strict. * Change _Py_CheckPython3() prototype: () => (void) * Truncate a few lines which were too long
* bpo-32030: Fix Py_GetPath(): init program_name (#4665)Victor Stinner2017-12-011-38/+54
| | | | | | | | | | | | | | | * _PyMainInterpreterConfig_ReadEnv() now sets program_name from environment variables and pymain_parse_envvars() implements the falls back on argv[0]. * Remove _PyMain.program_name: use the program_name from _PyMainInterpreterConfig * Move the Py_SetProgramName() call back to pymain_init_python(), just before _Py_InitializeCore(). * pathconfig_global_init() now also calls _PyMainInterpreterConfig_Read() to set program_name if it isn't set yet * Cleanup PyCalculatePath: pass main_config to subfunctions to get directly fields from main_config (home, module_search_path_env and program_name)
* bpo-32030: Cleanup "path config" code (#4663)Victor Stinner2017-12-011-64/+54
| | | | | | | | | | * Rename PyPathConfig structure to _PyPathConfig and move it to Include/internal/pystate.h * Rename path_config to _Py_path_config * _PyPathConfig: Rename program_name field to program_full_path * Add assert(str != NULL); to _PyMem_RawWcsdup(), _PyMem_RawStrdup() and _PyMem_Strdup(). * Rename calculate_path() to pathconfig_global_init(). The function now does nothing if it's already initiallized.
* bpo-32030: Add _PyPathConfig_Init() (#4551)Victor Stinner2017-11-251-181/+247
| | | | | | | | | | | | | | * Add _PyPathConfig_Init() and _PyPathConfig_Fini() * Remove _Py_GetPathWithConfig() * _PyPathConfig_Init() returns _PyInitError to allow to handle errors properly * Add pathconfig_clear() * Windows calculate_path_impl(): replace Py_FatalError() with _PyInitError * Py_FinalizeEx() now calls _PyPathConfig_Fini() to release memory * Fix _Py_InitializeMainInterpreter() regression: don't initialize path config if _disable_importlib is false * PyPathConfig now uses dynamically allocated memory
* bpo-32030: Add _PyMainInterpreterConfig.program_name (#4548)Victor Stinner2017-11-241-28/+32
| | | | | | * Py_Main() now calls Py_SetProgramName() earlier to be able to get the program name in _PyMainInterpreterConfig_ReadEnv(). * Rename prog to program_name * Rename progpath to program_name
* bpo-32030: Add _PyMainInterpreterConfig_ReadEnv() (#4542)Victor Stinner2017-11-241-36/+34
| | | | | | | | | | | | | | | | | | Py_GetPath() and Py_Main() now call _PyMainInterpreterConfig_ReadEnv() to share the same code to get environment variables. Changes: * Add _PyMainInterpreterConfig_ReadEnv() * Add _PyMainInterpreterConfig_Clear() * Add _PyMem_RawWcsdup() * _PyMainInterpreterConfig: rename pythonhome to home * Rename _Py_ReadMainInterpreterConfig() to _PyMainInterpreterConfig_Read() * Use _Py_INIT_USER_ERR(), instead of _Py_INIT_ERR(), for decoding errors: the user is able to fix the issue, it's not a bug in Python. Same change was made in _Py_INIT_NO_MEMORY(). * Remove _Py_GetPythonHomeWithConfig()
* bpo-32030: Fix calculate_path() on macOS (#4526)Victor Stinner2017-11-231-8/+9
|
* bpo-32030: Rewrite calculate_path() (#4521)Victor Stinner2017-11-231-338/+517
| | | | | | | | | | | | | | | | | * 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)
* bpo-32030: Add _PyMainInterpreterConfig.pythonhome (#4513)Victor Stinner2017-11-231-3/+3
| | | | | | | | | | | | * Py_Main() now reads the PYTHONHOME environment variable * Add _Py_GetPythonHomeWithConfig() private function * Add _PyWarnings_InitWithConfig() * init_filters() doesn't get the current core configuration from the current interpreter or Python thread anymore. Pass explicitly the configuration to _PyWarnings_InitWithConfig(). * _Py_InitializeCore() now fails on _PyWarnings_InitWithConfig() failure. * Pass configuration as constant
* bpo-32030: Move PYTHONPATH to _PyMainInterpreterConfig (#4511)Victor Stinner2017-11-231-9/+9
| | | | Move _PyCoreConfig.module_search_path_env to _PyMainInterpreterConfig structure.
* bpo-32030: Add _PyCoreConfig.module_search_path_env (#4504)Victor Stinner2017-11-221-18/+43
| | | | | | | | | | | Changes: * Py_Main() initializes _PyCoreConfig.module_search_path_env from the PYTHONPATH environment variable. * PyInterpreterState_New() now initializes core_config and config fields * Compute sys.path a little bit ealier in _Py_InitializeMainInterpreter() and new_interpreter() * Add _Py_GetPathWithConfig() private function.
* bpo-31532: Fix memory corruption due to allocator mix (#3679)nurelin2017-09-211-1/+1
| | | | | | | | | | | | Fix a memory corruption in getpath.c due to mixed memory allocators between Py_GetPath() and Py_SetPath(). The fix use the Raw allocator to mimic the windows version. This patch should be used from python3.6 to the current version for more details, see the bug report and https://github.com/pyinstaller/pyinstaller/issues/2812
* Issue #19398: Extra slash no longer added to sys.path components in case ofSerhiy Storchaka2016-11-111-1/+4
|\ | | | | | | | | empty compile-time PYTHONPATH components. This fixes some tests in -S or -I modes.
| * Issue #19398: Extra slash no longer added to sys.path components in case ofSerhiy Storchaka2016-11-111-1/+4
| | | | | | | | | | empty compile-time PYTHONPATH components. This fixes some tests in -S or -I modes.
* | merge 3.5Benjamin Peterson2016-06-021-19/+2
|\ \ | |/
| * remove (hilarious) defaults for various constants getpath.c needsBenjamin Peterson2016-06-021-19/+2
| |
* | Issue #25923: Added the const qualifier to static constant arrays.Serhiy Storchaka2015-12-251-2/+2
|/
* Issue #23731: Implement PEP 488.Brett Cannon2015-04-131-3/+2
| | | | | | The concept of .pyo files no longer exists. Now .pyc files have an optional `opt-` tag which specifies if any extra optimizations beyond the peepholer were applied.
* Issue #23753: Move _Py_wstat() from Python/fileutils.c to Modules/getpath.cVictor Stinner2015-03-241-0/+17
| | | | | | | I expected more users of _Py_wstat(), but in practice it's only used by Modules/getpath.c. Move the function because it's not needed on Windows. Windows uses PC/getpathp.c which uses the Win32 API (ex: GetFileAttributesW()) not the POSIX API.
* Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integerSerhiy Storchaka2015-02-161-1/+1
|\ | | | | | | overflows. Added few missed PyErr_NoMemory().
| * Issue #23446: Use PyMem_New instead of PyMem_Malloc to avoid possible integerSerhiy Storchaka2015-02-161-1/+1
| | | | | | | | overflows. Added few missed PyErr_NoMemory().
* | Issue #17095: merge from 3.4Ned Deily2014-09-151-14/+0
|\ \ | |/
| * Issue #17095: Temporarily revert getpath.c change that added the ModulesNed Deily2014-09-151-14/+0
| | | | | | | | | | | | directory to sys.path when running from a build directory. That has proven to be problematic for several standard library modules with C extension modules whose builds can fail on some platforms.
* | Issue #18395: Rename ``_Py_char2wchar()`` to :c:func:`Py_DecodeLocale`, renameVictor Stinner2014-08-011-8/+8
|/ | | | | ``_Py_wchar2char()`` to :c:func:`Py_EncodeLocale`, and document these functions.
* Issue #17095: Fix Modules/Setup *shared* support.Ned Deily2014-06-021-0/+14
| | | | Original patch by Thomas Wouters.
* Issue #16136: Remove VMS support and VMS-related codeChristian Heimes2013-12-211-5/+1
|
* calculate_path() now fails with a fatal error when it fails to allocate memoryVictor Stinner2013-11-161-49/+40
| | | | for module_search_path. It was already the case on _Py_char2wchar() failure.
* Don't mix wide character strings and byte strings (L"lib/python" VERSION): useVictor Stinner2013-11-151-6/+13
| | | | | | | _Py_char2wchar() to decode lib_python instead. Some compilers don't support concatenating literals: L"wide" "bytes". Example: IRIX compiler.
* Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],Christian Heimes2013-07-221-4/+12
|\ | | | | | | prefix and exec_prefix if the operation system does not obey MAXPATHLEN.
| * Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],Christian Heimes2013-07-221-4/+12
| | | | | | | | prefix and exec_prefix if the operation system does not obey MAXPATHLEN.
* | Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initializationVictor Stinner2013-07-071-11/+9
| | | | | | | | | | | | | | * Replace malloc() with PyMem_RawMalloc() * Replace PyMem_Malloc() with PyMem_RawMalloc() where the GIL is not held. * _Py_char2wchar() now returns a buffer allocated by PyMem_RawMalloc(), instead of PyMem_Malloc()
* | Issue #16309: Make PYTHONPATH= behavior the same as if PYTHONPATH not set at ↵Andrew Svetlov2012-11-031-3/+1
|/ | | | | | all. Thanks to Armin Rigo and Alexey Kachayev.
* Closes #15307: symlinks now work on OS X with framework Python builds. ↵Vinay Sajip2012-07-171-4/+12
| | | | Patch by Ronald Oussoren.
* Implemented PEP 405 (Python virtual environments).Vinay Sajip2012-05-261-0/+86
|
* calculate_path() decodes the PYTHONPATH environment variable from the localeVictor Stinner2011-06-201-7/+9
| | | | | | encoding using _Py_char2wchar() instead of mbstowcs() to store undecodable bytes as surrogates characters (PEP 383) instead of ignoring silently the PYTHONPATH variable.
* Issue #10914: fix bogus memory management in Modules/getpath.c, leading to a ↵Antoine Pitrou2011-03-171-3/+7
| | | | possible crash when calling Py_SetPath()
* Merge branches/pep-0384.Martin v. Löwis2010-12-031-1/+1
|
* getpath.c: fix test to detech PyUnicode_AsWideChar() failureVictor Stinner2010-11-101-4/+4
| | | | | | PyUnicode_AsWideChar() result is signed, whereas it was stored in a unsigned variable, and then the test was "n >= 0" which is always true to an unsigned number. Patch written by Hallvard B Furuseth.
* Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables usingVictor Stinner2010-11-081-17/+30
| | | | | _Py_char2wchar(), instead of L"" VAR hack, to escape undecodable bytes using the surrogateescape error handler.
* Issue #6011: getpath: decode VPATH env var from the locale encodingVictor Stinner2010-10-231-7/+10
| | | | | | Instead of casting it to wchar_t* without conversion. It fixes a bug if Python is compiled a non-ascii directory, different than the source code directory, with C locale.
* Oops, fix my previous commit (r85583) on calculate_path()Victor Stinner2010-10-161-4/+7
| | | | path value may be changed, so keep a copy in a new variable.