Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 66f8c43

Browse files
committed
#5924: on Windows, a large PYTHONPATH (more than 255 chars) was completely ignored.
Will backport to 3.0.
1 parent 5b4a54c commit 66f8c43

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

Lib/test/test_cmd_line.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ def test_unbuffered_input(self):
171171
self.assertEqual(rc, 0)
172172
self.assert_(data.startswith(b'x'), data)
173173

174+
def test_large_PYTHONPATH(self):
175+
with test.support.EnvironmentVarGuard() as env:
176+
path1 = "ABCDE" * 100
177+
path2 = "FGHIJ" * 100
178+
env['PYTHONPATH'] = path1 + os.pathsep + path2
179+
p = _spawn_python('-S', '-c', 'import sys; print(sys.path)')
180+
stdout, _ = p.communicate()
181+
self.assert_(path1.encode('ascii') in stdout)
182+
self.assert_(path2.encode('ascii') in stdout)
183+
174184

175185
def test_main():
176186
test.support.run_unittest(CmdLineTest)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.1 Release Candidate 2?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #5924: On Windows, a large PYTHONPATH environment variable
16+
(more than 255 characters) would be completely ignored.
17+
1518
- Issue #4547: When debugging a very large function, it was not always
1619
possible to update the lineno attribute of the current frame.
1720

PC/getpathp.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,6 @@ calculate_path(void)
424424
wchar_t *buf;
425425
size_t bufsz;
426426
wchar_t *pythonhome = Py_GetPythonHome();
427-
char *_envpath = Py_GETENV("PYTHONPATH");
428-
wchar_t wenvpath[MAXPATHLEN+1];
429427
wchar_t *envpath = NULL;
430428

431429
#ifdef MS_WINDOWS
@@ -434,13 +432,20 @@ calculate_path(void)
434432
wchar_t *userpath = NULL;
435433
wchar_t zip_path[MAXPATHLEN+1];
436434
size_t len;
437-
#endif
435+
436+
if (!Py_IgnoreEnvironmentFlag) {
437+
envpath = _wgetenv(L"PYTHONPATH");
438+
}
439+
#else
440+
char *_envpath = Py_GETENV("PYTHONPATH");
441+
wchar_t wenvpath[MAXPATHLEN+1];
438442
if (_envpath) {
439443
size_t r = mbstowcs(wenvpath, _envpath, MAXPATHLEN+1);
440444
envpath = wenvpath;
441445
if (r == (size_t)-1 || r >= MAXPATHLEN)
442446
envpath = NULL;
443447
}
448+
#endif
444449

445450
get_progpath();
446451
/* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */

0 commit comments

Comments
 (0)