Mercurial > cpython-lru_cache-weakref
annotate PC/getpathp.c @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | e223397b26fa |
| children | 8142f8d668a0 |
| rev | line source |
|---|---|
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* Return the initial module search path. */ |
|
8895
9b4bc3b8b9d4
This file's previous log message is bogus. The real change is that
Guido van Rossum <guido@python.org>
parents:
8892
diff
changeset
|
3 /* Used by DOS, OS/2, Windows 3.1, Windows 95/98, Windows NT. */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
5 /* ---------------------------------------------------------------- |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
6 PATH RULES FOR WINDOWS: |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
7 This describes how sys.path is formed on Windows. It describes the |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
8 functionality, not the implementation (ie, the order in which these |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
9 are actually fetched is different) |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
10 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
11 * Python always adds an empty entry at the start, which corresponds |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
12 to the current directory. |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
13 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
14 * If the PYTHONPATH env. var. exists, it's entries are added next. |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
15 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
16 * We look in the registry for "application paths" - that is, sub-keys |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
17 under the main PythonPath registry key. These are added next (the |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
18 order of sub-key processing is undefined). |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
19 HKEY_CURRENT_USER is searched and added first. |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
20 HKEY_LOCAL_MACHINE is searched and added next. |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
21 (Note that all known installers only use HKLM, so HKCU is typically |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
22 empty) |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
23 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
24 * We attempt to locate the "Python Home" - if the PYTHONHOME env var |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
25 is set, we believe it. Otherwise, we use the path of our host .EXE's |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12116
diff
changeset
|
26 to try and locate our "landmark" (lib\\os.py) and deduce our home. |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
27 - If we DO have a Python Home: The relevant sub-directories (Lib, |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
28 plat-win, lib-tk, etc) are based on the Python Home |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
29 - If we DO NOT have a Python Home, the core Python Path is |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
30 loaded from the registry. This is the main PythonPath key, |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
31 and both HKLM and HKCU are combined to form the path) |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
32 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
33 * Iff - we can not locate the Python Home, have not had a PYTHONPATH |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
34 specified, and can't locate any Registry entries (ie, we have _nothing_ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
35 we can assume is a good path), a default path with relative entries is |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
36 used (eg. .\Lib;.\plat-win, etc) |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
37 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
38 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
39 The end result of all this is: |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
40 * When running python.exe, or any other .exe in the main Python directory |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
41 (either an installed version, or directly from the PCbuild directory), |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
42 the core path is deduced, and the core paths in the registry are |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
43 ignored. Other "application paths" in the registry are always read. |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
44 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
45 * When Python is hosted in another exe (different directory, embedded via |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
46 COM, etc), the Python Home will not be deduced, so the core path from |
|
19795
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
47 the registry is used. Other "application paths" in the registry are |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
48 always read. |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
49 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
50 * If Python can't find its home and there is no registry (eg, frozen |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
51 exe, some very strange installation setup) you get a path with |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
52 some default, but relative, paths. |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
53 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
54 ---------------------------------------------------------------- */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
55 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
56 |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 #include "Python.h" |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 #include "osdefs.h" |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 |
|
5999
f2d134bf6973
Some changes to make it work on NT; add the directory where the binary
Guido van Rossum <guido@python.org>
parents:
5545
diff
changeset
|
60 #ifdef MS_WIN32 |
|
f2d134bf6973
Some changes to make it work on NT; add the directory where the binary
Guido van Rossum <guido@python.org>
parents:
5545
diff
changeset
|
61 #include <windows.h> |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
62 #include <tchar.h> |
|
5999
f2d134bf6973
Some changes to make it work on NT; add the directory where the binary
Guido van Rossum <guido@python.org>
parents:
5545
diff
changeset
|
63 #endif |
|
f2d134bf6973
Some changes to make it work on NT; add the directory where the binary
Guido van Rossum <guido@python.org>
parents:
5545
diff
changeset
|
64 |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 #include <sys/types.h> |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 #include <sys/stat.h> |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
67 #include <string.h> |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
68 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 /* Search in some common locations for the associated Python libraries. |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 * |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 * Py_GetPath() tries to return a sensible Python module search path. |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 * |
|
7407
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
73 * The approach is an adaptation for Windows of the strategy used in |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
74 * ../Modules/getpath.c; it uses the Windows Registry as one of its |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
75 * information sources. |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
76 */ |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
77 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 #ifndef LANDMARK |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12116
diff
changeset
|
79 #define LANDMARK "lib\\os.py" |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 #endif |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 static char prefix[MAXPATHLEN+1]; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
83 static char progpath[MAXPATHLEN+1]; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 static char *module_search_path = NULL; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
86 |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
88 is_sep(char ch) /* determine if "ch" is a separator character */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
90 #ifdef ALTSEP |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 return ch == SEP || ch == ALTSEP; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
92 #else |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 return ch == SEP; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 #endif |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
97 /* assumes 'dir' null terminated in bounds. Never writes |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
98 beyond existing terminator. |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
99 */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 static void |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
101 reduce(char *dir) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 { |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
103 size_t i = strlen(dir); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 while (i > 0 && !is_sep(dir[i])) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 --i; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 dir[i] = '\0'; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
111 exists(char *filename) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 struct stat buf; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 return stat(filename, &buf) == 0; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
117 /* Assumes 'filename' MAXPATHLEN+1 bytes long - |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
118 may extend 'filename' by one character. |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
119 */ |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
120 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
121 ismodule(char *filename) /* Is module -- check for .pyc/.pyo too */ |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
122 { |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
123 if (exists(filename)) |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
124 return 1; |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
125 |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
126 /* Check for the compiled version of prefix. */ |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
127 if (strlen(filename) < MAXPATHLEN) { |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
128 strcat(filename, Py_OptimizeFlag ? "o" : "c"); |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
129 if (exists(filename)) |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
130 return 1; |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
131 } |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
132 return 0; |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
133 } |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
134 |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
135 /* guarantees buffer will never overflow MAXPATHLEN+1 bytes */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 static void |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
137 join(char *buffer, char *stuff) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 { |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
139 size_t n, k; |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 if (is_sep(stuff[0])) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 n = 0; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 else { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 n = strlen(buffer); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 if (n > 0 && !is_sep(buffer[n-1]) && n < MAXPATHLEN) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 buffer[n++] = SEP; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 k = strlen(stuff); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 if (n + k > MAXPATHLEN) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 k = MAXPATHLEN - n; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 strncpy(buffer+n, stuff, k); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 buffer[n+k] = '\0'; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
154 /* gotlandmark only called by search_for_prefix, which ensures |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
155 'prefix' is null terminated in bounds. join() ensures |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
156 'landmark' can not overflow prefix if too long. |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
157 */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
159 gotlandmark(char *landmark) |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
160 { |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
161 int n, ok; |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
162 |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
163 n = strlen(prefix); |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
164 join(prefix, landmark); |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
165 ok = ismodule(prefix); |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
166 prefix[n] = '\0'; |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
167 return ok; |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
168 } |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
169 |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
170 /* assumes argv0_path is MAXPATHLEN+1 bytes long, already \0 term'd. |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
171 assumption provided by only caller, calculate_path() */ |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
172 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
173 search_for_prefix(char *argv0_path, char *landmark) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 { |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
175 /* Search from argv0_path, until landmark is found */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 strcpy(prefix, argv0_path); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 do { |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
178 if (gotlandmark(landmark)) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 return 1; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 reduce(prefix); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 } while (prefix[0]); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 return 0; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
185 #ifdef MS_WIN32 |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
186 |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
187 /* a string loaded from the DLL at startup.*/ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
188 extern const char *PyWin_DLLVersionString; |
|
6356
a857d2f87336
Seem to be some changes related to DLL version from string resource,
Guido van Rossum <guido@python.org>
parents:
6001
diff
changeset
|
189 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
190 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
191 /* Load a PYTHONPATH value from the registry. |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
192 Load from either HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER. |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
193 |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
194 Works in both Unicode and 8bit environments. Only uses the |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
195 Ex family of functions so it also works with Windows CE. |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
196 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
197 Returns NULL, or a pointer that should be freed. |
|
16748
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
198 |
|
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
199 XXX - this code is pretty strange, as it used to also |
|
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
200 work on Win16, where the buffer sizes werent available |
|
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
201 in advance. It could be simplied now Win16/Win32s is dead! |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
202 */ |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
203 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
204 static char * |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
205 getpythonregpath(HKEY keyBase, int skipcore) |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
206 { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
207 HKEY newKey = 0; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
208 DWORD dataSize = 0; |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
209 DWORD numKeys = 0; |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
210 LONG rc; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
211 char *retval = NULL; |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
212 TCHAR *dataBuf = NULL; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
213 static const TCHAR keyPrefix[] = _T("Software\\Python\\PythonCore\\"); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
214 static const TCHAR keySuffix[] = _T("\\PythonPath"); |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
215 size_t versionLen; |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
216 DWORD index; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
217 TCHAR *keyBuf = NULL; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
218 TCHAR *keyBufPtr; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
219 TCHAR **ppPaths = NULL; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
220 |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
221 /* Tried to use sysget("winver") but here is too early :-( */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
222 versionLen = _tcslen(PyWin_DLLVersionString); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
223 /* Space for all the chars, plus one \0 */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
224 keyBuf = keyBufPtr = malloc(sizeof(keyPrefix) + |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
225 sizeof(TCHAR)*(versionLen-1) + |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
226 sizeof(keySuffix)); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
227 if (keyBuf==NULL) goto done; |
|
6356
a857d2f87336
Seem to be some changes related to DLL version from string resource,
Guido van Rossum <guido@python.org>
parents:
6001
diff
changeset
|
228 |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
229 memcpy(keyBufPtr, keyPrefix, sizeof(keyPrefix)-sizeof(TCHAR)); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
230 keyBufPtr += sizeof(keyPrefix)/sizeof(TCHAR) - 1; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
231 memcpy(keyBufPtr, PyWin_DLLVersionString, versionLen * sizeof(TCHAR)); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
232 keyBufPtr += versionLen; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
233 /* NULL comes with this one! */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
234 memcpy(keyBufPtr, keySuffix, sizeof(keySuffix)); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
235 /* Open the root Python key */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
236 rc=RegOpenKeyEx(keyBase, |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
237 keyBuf, /* subkey */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
238 0, /* reserved */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
239 KEY_READ, |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
240 &newKey); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
241 if (rc!=ERROR_SUCCESS) goto done; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
242 /* Find out how big our core buffer is, and how many subkeys we have */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
243 rc = RegQueryInfoKey(newKey, NULL, NULL, NULL, &numKeys, NULL, NULL, |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
244 NULL, NULL, &dataSize, NULL, NULL); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
245 if (rc!=ERROR_SUCCESS) goto done; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
246 if (skipcore) dataSize = 0; /* Only count core ones if we want them! */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
247 /* Allocate a temp array of char buffers, so we only need to loop |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
248 reading the registry once |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
249 */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
250 ppPaths = malloc( sizeof(TCHAR *) * numKeys ); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
251 if (ppPaths==NULL) goto done; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
252 memset(ppPaths, 0, sizeof(TCHAR *) * numKeys); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
253 /* Loop over all subkeys, allocating a temp sub-buffer. */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
254 for(index=0;index<numKeys;index++) { |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
255 TCHAR keyBuf[MAX_PATH+1]; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
256 HKEY subKey = 0; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
257 DWORD reqdSize = MAX_PATH+1; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
258 /* Get the sub-key name */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
259 DWORD rc = RegEnumKeyEx(newKey, index, keyBuf, &reqdSize, |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
260 NULL, NULL, NULL, NULL ); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
261 if (rc!=ERROR_SUCCESS) goto done; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
262 /* Open the sub-key */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
263 rc=RegOpenKeyEx(newKey, |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
264 keyBuf, /* subkey */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
265 0, /* reserved */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
266 KEY_READ, |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
267 &subKey); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
268 if (rc!=ERROR_SUCCESS) goto done; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
269 /* Find the value of the buffer size, malloc, then read it */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
270 RegQueryValueEx(subKey, NULL, 0, NULL, NULL, &reqdSize); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
271 if (reqdSize) { |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
272 ppPaths[index] = malloc(reqdSize); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
273 if (ppPaths[index]) { |
|
14500
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
274 RegQueryValueEx(subKey, NULL, 0, NULL, |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
275 (LPBYTE)ppPaths[index], |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
276 &reqdSize); |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
277 dataSize += reqdSize + 1; /* 1 for the ";" */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
278 } |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
279 } |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
280 RegCloseKey(subKey); |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
281 } |
|
16748
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
282 /* original datasize from RegQueryInfo doesn't include the \0 */ |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
283 dataBuf = malloc((dataSize+1) * sizeof(TCHAR)); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
284 if (dataBuf) { |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
285 TCHAR *szCur = dataBuf; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
286 DWORD reqdSize = dataSize; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
287 /* Copy our collected strings */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
288 for (index=0;index<numKeys;index++) { |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
289 if (index > 0) { |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
290 *(szCur++) = _T(';'); |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
291 dataSize--; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
292 } |
|
14500
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
293 if (ppPaths[index]) { |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
294 int len = _tcslen(ppPaths[index]); |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
295 _tcsncpy(szCur, ppPaths[index], len); |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
296 szCur += len; |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
297 dataSize -= len; |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
298 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
299 } |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
300 if (skipcore) |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
301 *szCur = '\0'; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
302 else { |
|
16748
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
303 /* If we have no values, we dont need a ';' */ |
|
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
304 if (numKeys) { |
|
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
305 *(szCur++) = _T(';'); |
|
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
306 dataSize--; |
|
e444a5271181
Checkin updated version of patch #103933 . As Thomas says, fixes the bugs #131064, #129584, #127722. See the discussion in bug #131064
Mark Hammond <mhammond@skippinet.com.au>
parents:
15084
diff
changeset
|
307 } |
|
14500
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
308 /* Now append the core path entries - |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
309 this will include the NULL |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
310 */ |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
311 rc = RegQueryValueEx(newKey, NULL, 0, NULL, |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
312 (LPBYTE)szCur, &dataSize); |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
313 } |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
314 /* And set the result - caller must free |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
315 If MBCS, it is fine as is. If Unicode, allocate new |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
316 buffer and convert. |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
317 */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
318 #ifdef UNICODE |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
319 retval = (char *)malloc(reqdSize+1); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
320 if (retval) |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
321 WideCharToMultiByte(CP_ACP, 0, |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
322 dataBuf, -1, /* source */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
323 retval, dataSize+1, /* dest */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
324 NULL, NULL); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
325 free(dataBuf); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
326 #else |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
327 retval = dataBuf; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
328 #endif |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
329 } |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
330 done: |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
331 /* Loop freeing my temp buffers */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
332 if (ppPaths) { |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
333 for(index=0;index<numKeys;index++) |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
334 if (ppPaths[index]) free(ppPaths[index]); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
335 free(ppPaths); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
336 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
337 if (newKey) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
338 RegCloseKey(newKey); |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
339 if (keyBuf) |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
340 free(keyBuf); |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
341 return retval; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
342 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
343 #endif /* MS_WIN32 */ |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
344 |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
345 static void |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
346 get_progpath(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
347 { |
|
13668
d7d81ea9c82d
ANSIfication: remove very-old-varargs code, fix function declarations so
Thomas Wouters <thomas@python.org>
parents:
13660
diff
changeset
|
348 extern char *Py_GetProgramName(void); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 char *path = getenv("PATH"); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
350 char *prog = Py_GetProgramName(); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
352 #ifdef MS_WIN32 |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
353 #ifdef UNICODE |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
354 WCHAR wprogpath[MAXPATHLEN+1]; |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
355 /* Windows documents that GetModuleFileName() will "truncate", |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
356 but makes no mention of the null terminator. Play it safe. |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
357 PLUS Windows itself defines MAX_PATH as the same, but anyway... |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
358 */ |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
359 wprogpath[MAXPATHLEN]=_T('\0')'; |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
360 if (GetModuleFileName(NULL, wprogpath, MAXPATHLEN)) { |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
361 WideCharToMultiByte(CP_ACP, 0, |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
362 wprogpath, -1, |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
363 progpath, MAXPATHLEN+1, |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
364 NULL, NULL); |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
365 return; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
366 } |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
367 #else |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
368 /* static init of progpath ensures final char remains \0 */ |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
369 if (GetModuleFileName(NULL, progpath, MAXPATHLEN)) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
370 return; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
371 #endif |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
372 #endif |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
373 if (prog == NULL || *prog == '\0') |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
374 prog = "python"; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
375 |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
376 /* If there is no slash in the argv0 path, then we have to |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
377 * assume python is on the user's $PATH, since there's no |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
378 * other way to find a directory to start the search from. If |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
379 * $PATH isn't exported, you lose. |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 */ |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
381 #ifdef ALTSEP |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
382 if (strchr(prog, SEP) || strchr(prog, ALTSEP)) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
383 #else |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
384 if (strchr(prog, SEP)) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 #endif |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
386 strncpy(progpath, prog, MAXPATHLEN); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
387 else if (path) { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 while (1) { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 char *delim = strchr(path, DELIM); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
390 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
391 if (delim) { |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
392 size_t len = delim - path; |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
393 /* ensure we can't overwrite buffer */ |
|
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
394 len = min(MAXPATHLEN,len); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 strncpy(progpath, path, len); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
396 *(progpath + len) = '\0'; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
397 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
398 else |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
399 strncpy(progpath, path, MAXPATHLEN); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
401 /* join() is safe for MAXPATHLEN+1 size buffer */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 join(progpath, prog); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
403 if (exists(progpath)) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
404 break; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
405 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
406 if (!delim) { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 progpath[0] = '\0'; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
408 break; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
409 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
410 path = delim + 1; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 else |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 progpath[0] = '\0'; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
415 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
416 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
417 static void |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
418 calculate_path(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
419 { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
420 char argv0_path[MAXPATHLEN+1]; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 char *buf; |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
422 size_t bufsz; |
| 8758 | 423 char *pythonhome = Py_GetPythonHome(); |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
16748
diff
changeset
|
424 char *envpath = Py_GETENV("PYTHONPATH"); |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
425 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
426 #ifdef MS_WIN32 |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
427 int skiphome, skipdefault; |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
428 char *machinepath = NULL; |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
429 char *userpath = NULL; |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
430 #endif |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
431 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
432 get_progpath(); |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
433 /* progpath guaranteed \0 terminated in MAXPATH+1 bytes. */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
434 strcpy(argv0_path, progpath); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 reduce(argv0_path); |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
436 if (pythonhome == NULL || *pythonhome == '\0') { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
437 if (search_for_prefix(argv0_path, LANDMARK)) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
438 pythonhome = prefix; |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
439 else |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
440 pythonhome = NULL; |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
441 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
442 else |
|
15084
9be67c5a823a
Prevent possible buffer overflow exploits under Windows. As per (the very quick) patch Patch #101801.
Mark Hammond <mhammond@skippinet.com.au>
parents:
14500
diff
changeset
|
443 strncpy(prefix, pythonhome, MAXPATHLEN); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
444 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
445 if (envpath && *envpath == '\0') |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
446 envpath = NULL; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
447 |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
448 |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
449 #ifdef MS_WIN32 |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
450 skiphome = pythonhome==NULL ? 0 : 1; |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
451 machinepath = getpythonregpath(HKEY_LOCAL_MACHINE, skiphome); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
452 userpath = getpythonregpath(HKEY_CURRENT_USER, skiphome); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
453 /* We only use the default relative PYTHONPATH if we havent |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
454 anything better to use! */ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
455 skipdefault = envpath!=NULL || pythonhome!=NULL || \ |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
456 machinepath!=NULL || userpath!=NULL; |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
457 #endif |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
458 |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
459 /* We need to construct a path from the following parts. |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
460 (1) the PYTHONPATH environment variable, if set; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
461 (2) for Win32, the machinepath and userpath, if set; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
462 (3) the PYTHONPATH config macro, with the leading "." |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
463 of each component replaced with pythonhome, if set; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
464 (4) the directory containing the executable (argv0_path). |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
465 The length calculation calculates #3 first. |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
466 Extra rules: |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
467 - If PYTHONHOME is set (in any way) item (2) is ignored. |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
468 - If registry values are used, (3) and (4) are ignored. |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
469 */ |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
470 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
471 /* Calculate size of return buffer */ |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
472 if (pythonhome != NULL) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
473 char *p; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
474 bufsz = 1; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
475 for (p = PYTHONPATH; *p; p++) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
476 if (*p == DELIM) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
477 bufsz++; /* number of DELIM plus one */ |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
478 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
479 bufsz *= strlen(pythonhome); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
480 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
481 else |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
482 bufsz = 0; |
|
6826
a1545cbf0adf
Allocate one byte extra in some cases.
Guido van Rossum <guido@python.org>
parents:
6356
diff
changeset
|
483 bufsz += strlen(PYTHONPATH) + 1; |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
484 bufsz += strlen(argv0_path) + 1; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
485 #ifdef MS_WIN32 |
|
8892
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
486 if (userpath) |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
487 bufsz += strlen(userpath) + 1; |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
488 if (machinepath) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
489 bufsz += strlen(machinepath) + 1; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
490 #endif |
|
8892
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
491 if (envpath != NULL) |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
492 bufsz += strlen(envpath) + 1; |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
493 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
494 module_search_path = buf = malloc(bufsz); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
495 if (buf == NULL) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
496 /* We can't exit, so print a warning and limp along */ |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
497 fprintf(stderr, "Can't malloc dynamic PYTHONPATH.\n"); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
498 if (envpath) { |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
499 fprintf(stderr, "Using environment $PYTHONPATH.\n"); |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
500 module_search_path = envpath; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
501 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
502 else { |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
503 fprintf(stderr, "Using default static path.\n"); |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
504 module_search_path = PYTHONPATH; |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
505 } |
|
7407
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
506 #ifdef MS_WIN32 |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
507 if (machinepath) |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
508 free(machinepath); |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
509 if (userpath) |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
510 free(userpath); |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
511 #endif /* MS_WIN32 */ |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
512 return; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
513 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
514 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
515 if (envpath) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
516 strcpy(buf, envpath); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
517 buf = strchr(buf, '\0'); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
518 *buf++ = DELIM; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
519 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
520 #ifdef MS_WIN32 |
|
8892
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
521 if (userpath) { |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
522 strcpy(buf, userpath); |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
523 buf = strchr(buf, '\0'); |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
524 *buf++ = DELIM; |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
525 free(userpath); |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
526 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
527 if (machinepath) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
528 strcpy(buf, machinepath); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
529 buf = strchr(buf, '\0'); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
530 *buf++ = DELIM; |
|
7407
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
531 free(machinepath); |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
532 } |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
533 if (pythonhome == NULL) { |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
534 if (!skipdefault) { |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
535 strcpy(buf, PYTHONPATH); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
536 buf = strchr(buf, '\0'); |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
537 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
538 } |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
539 #else |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
540 if (pythonhome == NULL) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
541 strcpy(buf, PYTHONPATH); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
542 buf = strchr(buf, '\0'); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
543 } |
|
12116
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
544 #endif /* MS_WIN32 */ |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
545 else { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
546 char *p = PYTHONPATH; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
547 char *q; |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
548 size_t n; |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
549 for (;;) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
550 q = strchr(p, DELIM); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
551 if (q == NULL) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
552 n = strlen(p); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
553 else |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
554 n = q-p; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
555 if (p[0] == '.' && is_sep(p[1])) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
556 strcpy(buf, pythonhome); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
557 buf = strchr(buf, '\0'); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
558 p++; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
559 n--; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
560 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
561 strncpy(buf, p, n); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
562 buf += n; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
563 if (q == NULL) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
564 break; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
565 *buf++ = DELIM; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
566 p = q+1; |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
567 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
568 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
569 if (argv0_path) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
570 *buf++ = DELIM; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
571 strcpy(buf, argv0_path); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
572 buf = strchr(buf, '\0'); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
573 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
574 *buf = '\0'; |
|
19795
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
575 /* Now to pull one last hack/trick. If sys.prefix is |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
576 empty, then try and find it somewhere on the paths |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
577 we calculated. We scan backwards, as our general policy |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
578 is that Python core directories are at the *end* of |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
579 sys.path. We assume that our "lib" directory is |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
580 on the path, and that our 'prefix' directory is |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
581 the parent of that. |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
582 */ |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
583 if (*prefix=='\0') { |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
584 char lookBuf[MAXPATHLEN+1]; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
585 char *look = buf - 1; /* 'buf' is at the end of the buffer */ |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
586 while (1) { |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
587 int nchars; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
588 char *lookEnd = look; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
589 /* 'look' will end up one character before the |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
590 start of the path in question - even if this |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
591 is one character before the start of the buffer |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
592 */ |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
593 while (*look != DELIM && look >= module_search_path) |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
594 look--; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
595 nchars = lookEnd-look; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
596 strncpy(lookBuf, look+1, nchars); |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
597 lookBuf[nchars] = '\0'; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
598 /* Up one level to the parent */ |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
599 reduce(lookBuf); |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
600 if (search_for_prefix(lookBuf, LANDMARK)) { |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
601 break; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
602 } |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
603 /* If we are out of paths to search - give up */ |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
604 if (look < module_search_path) |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
605 break; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
606 look--; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
607 } |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
608 } |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
609 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
610 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
611 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
612 /* External interface */ |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
613 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
614 char * |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
615 Py_GetPath(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 if (!module_search_path) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 calculate_path(); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
619 return module_search_path; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
620 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
621 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 char * |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
623 Py_GetPrefix(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 { |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
625 if (!module_search_path) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
626 calculate_path(); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
627 return prefix; |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
628 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
629 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
630 char * |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
631 Py_GetExecPrefix(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 { |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
633 return Py_GetPrefix(); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
634 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
635 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
636 char * |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
637 Py_GetProgramFullPath(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
638 { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
639 if (!module_search_path) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
640 calculate_path(); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
641 return progpath; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
642 } |
