summaryrefslogtreecommitdiffstats
path: root/Modules/getpath.c
Commit message (Collapse)AuthorAgeFilesLines
...
* 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.
* calculate_path(): use _Py_char2wchar() to decode the PATH environment variable,Victor Stinner2010-10-161-9/+4
| | | | to support surrogate characters
* _Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogatesVictor Stinner2010-10-141-6/+6
|
* copy_absolute() keeps the relative path on _Py_wgetcwd() failureVictor Stinner2010-10-071-2/+5
| | | | | .. instead of raising a fatal error. Even if the current directory was deleted, use relative paths may still work (eg. run Python with "../python").
* copy_absolute() raises a fatal error on _Py_wgetcwd() failureVictor Stinner2010-10-071-1/+2
|
* Create fileutils.c/.hVictor Stinner2010-10-071-77/+4
| | | | | | | * _Py_fopen() and _Py_stat() come from Python/import.c * (_Py)_wrealpath() comes from Python/sysmodule.c * _Py_char2wchar(), _Py_wchar2char() and _Py_wfopen() come from Modules/main.c * (_Py)_wstat(), (_Py)_wgetcwd(), _Py_wreadlink() come from Modules/getpath.c
* _wrealpath() and _Py_wreadlink() support surrogates (PEP 383)Victor Stinner2010-10-071-3/+6
| | | | Use _Py_wchar2char() to support surrogate characters in the input path.
* issue 9910Kristján Valur Jónsson2010-09-271-0/+20
| | | | Add a Py_SetPath api to override magic path computations when starting up python.
* Fix indentation in Modules/getpath.cAntoine Pitrou2010-08-141-59/+59
|
* Add comments about Windows in Modules/getpath.cAntoine Pitrou2010-08-141-2/+7
|