Mercurial > cpython-lru_cache-weakref
annotate PC/getpathp.c @ 20737:00a581bdedeb legacy-trunk
When overriding __str__ or __repr__, set the tp_print slot to NULL.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Oct 2001 14:33:44 +0000 |
| parents | 9c54a16ac8b9 |
| children | c64fc56f6072 |
| 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 #if HAVE_UNISTD_H |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
70 #include <unistd.h> |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 #endif /* HAVE_UNISTD_H */ |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
72 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 /* 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
|
74 * |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 * 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
|
76 * |
|
7407
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
77 * 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
|
78 * ../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
|
79 * information sources. |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
80 */ |
|
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 #ifndef LANDMARK |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12116
diff
changeset
|
83 #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
|
84 #endif |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
85 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 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
|
87 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
|
88 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
|
89 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
90 |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
92 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
|
93 { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
94 #ifdef ALTSEP |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 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
|
96 #else |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
97 return ch == SEP; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 #endif |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
99 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 |
|
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
|
101 /* 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
|
102 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
|
103 */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 static void |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
105 reduce(char *dir) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 { |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
107 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
|
108 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
|
109 --i; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 dir[i] = '\0'; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 } |
|
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 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
115 exists(char *filename) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 struct stat buf; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 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
|
119 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 |
|
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
|
121 /* 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
|
122 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
|
123 */ |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
124 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
125 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
|
126 { |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
127 if (exists(filename)) |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
128 return 1; |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
129 |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
130 /* Check for the compiled version of prefix. */ |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
131 if (strlen(filename) < MAXPATHLEN) { |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
132 strcat(filename, Py_OptimizeFlag ? "o" : "c"); |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
133 if (exists(filename)) |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
134 return 1; |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
135 } |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
136 return 0; |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
137 } |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
138 |
|
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
|
139 /* 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
|
140 static void |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
141 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
|
142 { |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
143 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
|
144 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
|
145 n = 0; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 else { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 n = strlen(buffer); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 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
|
149 buffer[n++] = SEP; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 k = strlen(stuff); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 if (n + k > MAXPATHLEN) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 k = MAXPATHLEN - n; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 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
|
155 buffer[n+k] = '\0'; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 |
|
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
|
158 /* 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
|
159 '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
|
160 '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
|
161 */ |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
163 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
|
164 { |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
165 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
|
166 |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 } |
|
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
173 |
|
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
|
174 /* 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
|
175 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
|
176 static int |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
177 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
|
178 { |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
179 /* 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
|
180 strcpy(prefix, argv0_path); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 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
|
182 if (gotlandmark(landmark)) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 return 1; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 reduce(prefix); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 } while (prefix[0]); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 return 0; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
189 #ifdef MS_WIN32 |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
190 |
|
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
|
191 /* 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
|
192 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
|
193 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
194 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
195 /* 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
|
196 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
|
197 |
|
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
|
198 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
|
199 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
|
200 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
201 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
|
202 |
|
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
|
203 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
|
204 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
|
205 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
|
206 */ |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
207 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
208 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
|
209 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
|
210 { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 LONG rc; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 static const TCHAR keySuffix[] = _T("\\PythonPath"); |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 |
|
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 /* 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
|
226 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
|
227 /* 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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 |
|
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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 /* 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
|
238 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
|
239 /* 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 &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
|
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 /* 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 /* 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
|
252 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
|
253 */ |
|
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 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
|
255 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
|
256 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
|
257 /* 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 /* 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
|
263 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
|
264 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
|
265 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
|
266 /* 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
|
267 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
|
268 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
|
269 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
|
270 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
|
271 &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
|
272 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
|
273 /* 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 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
|
279 (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
|
280 &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
|
281 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
|
282 } |
|
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 } |
|
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 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
|
285 } |
|
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
|
286 /* 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 /* 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
|
292 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
|
293 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
|
294 *(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
|
295 dataSize--; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
296 } |
|
14500
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
297 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
|
298 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
|
299 _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
|
300 szCur += len; |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
301 dataSize -= len; |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
302 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
303 } |
|
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
|
304 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
|
305 *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
|
306 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
|
307 /* 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
|
308 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
|
309 *(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
|
310 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
|
311 } |
|
14500
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
312 /* 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
|
313 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
|
314 */ |
|
21d847653f54
Patch for [ Bug #113828 ] getpythonregpath with null data in registry key
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
315 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
|
316 (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
|
317 } |
|
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
|
318 /* 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
|
319 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
|
320 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
|
321 */ |
|
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 #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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 #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
|
331 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
|
332 #endif |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
333 } |
|
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
|
334 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
|
335 /* 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
341 if (newKey) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 return retval; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
346 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
347 #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
|
348 |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
349 static void |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
350 get_progpath(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
351 { |
|
13668
d7d81ea9c82d
ANSIfication: remove very-old-varargs code, fix function declarations so
Thomas Wouters <thomas@python.org>
parents:
13660
diff
changeset
|
352 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
|
353 char *path = getenv("PATH"); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
354 char *prog = Py_GetProgramName(); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
355 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
356 #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
|
357 #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
|
358 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
|
359 /* 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
|
360 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
|
361 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
|
362 */ |
|
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 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
|
364 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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 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
|
370 } |
|
e6ab3c603ff9
Revamped path access again, by Mark Hammond, to be more robust in the
Guido van Rossum <guido@python.org>
parents:
12090
diff
changeset
|
371 #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
|
372 /* 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
|
373 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
|
374 return; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
375 #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
|
376 #endif |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
377 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
|
378 prog = "python"; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
379 |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
380 /* 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
|
381 * 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
|
382 * 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
|
383 * $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
|
384 */ |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
385 #ifdef ALTSEP |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
386 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
|
387 #else |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
388 if (strchr(prog, SEP)) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
389 #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
|
390 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
|
391 else if (path) { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
392 while (1) { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
393 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
|
394 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
395 if (delim) { |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
396 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
|
397 /* 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
|
398 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
|
399 strncpy(progpath, path, len); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
400 *(progpath + len) = '\0'; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
401 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
402 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
|
403 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
|
404 |
|
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
|
405 /* 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
|
406 join(progpath, prog); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
407 if (exists(progpath)) |
|
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 if (!delim) { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
411 progpath[0] = '\0'; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
412 break; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
413 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
414 path = delim + 1; |
|
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 else |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
418 progpath[0] = '\0'; |
|
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 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
421 static void |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
422 calculate_path(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
423 { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
424 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
|
425 char *buf; |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
426 size_t bufsz; |
| 8758 | 427 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
|
428 char *envpath = Py_GETENV("PYTHONPATH"); |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
429 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
430 #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
|
431 int skiphome, skipdefault; |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
432 char *machinepath = NULL; |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
433 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
|
434 #endif |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
435 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
436 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
|
437 /* 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
|
438 strcpy(argv0_path, progpath); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
439 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
|
440 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
|
441 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
|
442 pythonhome = prefix; |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
443 else |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
444 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
|
445 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
446 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
|
447 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
|
448 |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
449 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
|
450 envpath = NULL; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
451 |
|
12090
9877e978170e
Changes to completely ignore the registry when it detects that you are
Guido van Rossum <guido@python.org>
parents:
8967
diff
changeset
|
452 |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
453 #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
|
454 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
|
455 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
|
456 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
|
457 /* 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
|
458 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
|
459 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
|
460 machinepath!=NULL || userpath!=NULL; |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
461 #endif |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
462 |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
463 /* 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
|
464 (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
|
465 (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
|
466 (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
|
467 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
|
468 (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
|
469 The length calculation calculates #3 first. |
|
8902
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
470 Extra rules: |
|
6f73ae1cf934
Sigh. More restructuring was needed.
Guido van Rossum <guido@python.org>
parents:
8895
diff
changeset
|
471 - 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
|
472 - 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
|
473 */ |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
474 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
475 /* 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
|
476 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
|
477 char *p; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
478 bufsz = 1; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
479 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
|
480 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
|
481 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
|
482 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
483 bufsz *= strlen(pythonhome); |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
484 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
485 else |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
486 bufsz = 0; |
|
6826
a1545cbf0adf
Allocate one byte extra in some cases.
Guido van Rossum <guido@python.org>
parents:
6356
diff
changeset
|
487 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
|
488 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
|
489 #ifdef MS_WIN32 |
|
8892
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
490 if (userpath) |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
491 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
|
492 if (machinepath) |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
493 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
|
494 #endif |
|
8892
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
495 if (envpath != NULL) |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
496 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
|
497 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
498 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
|
499 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
|
500 /* 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
|
501 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
|
502 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
|
503 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
|
504 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
|
505 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
506 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
|
507 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
|
508 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
|
509 } |
|
7407
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
510 #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
|
511 if (machinepath) |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
512 free(machinepath); |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
513 if (userpath) |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
514 free(userpath); |
|
2c54901471f5
Fix some outdated comments (mostly by removing a large comment block
Guido van Rossum <guido@python.org>
parents:
6826
diff
changeset
|
515 #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
|
516 return; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
517 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
518 |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
519 if (envpath) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
520 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
|
521 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
|
522 *buf++ = DELIM; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
523 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
524 #ifdef MS_WIN32 |
|
8892
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
525 if (userpath) { |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
526 strcpy(buf, userpath); |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
527 buf = strchr(buf, '\0'); |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
528 *buf++ = DELIM; |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
529 free(userpath); |
|
a7083295eb38
Different version games:
Guido van Rossum <guido@python.org>
parents:
8758
diff
changeset
|
530 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
531 if (machinepath) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
532 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
|
533 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
|
534 *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
|
535 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
|
536 } |
|
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
|
537 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
|
538 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
|
539 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
|
540 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
|
541 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
542 } |
|
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
|
543 #else |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
544 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
|
545 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
|
546 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
|
547 } |
|
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
|
548 #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
|
549 else { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
550 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
|
551 char *q; |
|
13101
3cea73a2bbd8
Trent Mick: familiar simple Win64 patches
Guido van Rossum <guido@python.org>
parents:
12775
diff
changeset
|
552 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
|
553 for (;;) { |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
554 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
|
555 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
|
556 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
|
557 else |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
558 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
|
559 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
|
560 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
|
561 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
|
562 p++; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
563 n--; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
564 } |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
565 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
|
566 buf += n; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
567 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
|
568 break; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
569 *buf++ = DELIM; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
570 p = q+1; |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
571 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
572 } |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
573 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
|
574 *buf++ = DELIM; |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
575 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
|
576 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
|
577 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
578 *buf = '\0'; |
|
19795
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
579 /* 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
|
580 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
|
581 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
|
582 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
|
583 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
|
584 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
|
585 the parent of that. |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
586 */ |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
587 if (*prefix=='\0') { |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
588 char lookBuf[MAXPATHLEN+1]; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
589 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
|
590 while (1) { |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
591 int nchars; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
592 char *lookEnd = look; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
593 /* '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
|
594 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
|
595 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
|
596 */ |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
597 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
|
598 look--; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
599 nchars = lookEnd-look; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
600 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
|
601 lookBuf[nchars] = '\0'; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
602 /* 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
|
603 reduce(lookBuf); |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
604 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
|
605 break; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
606 } |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
607 /* 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
|
608 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
|
609 break; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
610 look--; |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
611 } |
|
9c54a16ac8b9
Fix bug #410274 - sys.prefix isn't always set.
Mark Hammond <mhammond@skippinet.com.au>
parents:
18808
diff
changeset
|
612 } |
|
5545
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 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
615 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
616 /* External interface */ |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
617 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
618 char * |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
619 Py_GetPath(void) |
|
5545
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 if (!module_search_path) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
622 calculate_path(); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
623 return module_search_path; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
624 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
625 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
626 char * |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
627 Py_GetPrefix(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
628 { |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
629 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
|
630 calculate_path(); |
|
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
631 return prefix; |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
632 } |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
633 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
634 char * |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
635 Py_GetExecPrefix(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
636 { |
|
6001
8056169ec448
Much rewritten. Added Win32 registry stuff (from getpath_nt.c, which
Guido van Rossum <guido@python.org>
parents:
5999
diff
changeset
|
637 return Py_GetPrefix(); |
|
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 |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
640 char * |
|
13660
a1ce07218781
Miscelaneous ANSIfications. I'm assuming here 'main' should take (int,
Thomas Wouters <thomas@python.org>
parents:
13256
diff
changeset
|
641 Py_GetProgramFullPath(void) |
|
5545
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
642 { |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
643 if (!module_search_path) |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
644 calculate_path(); |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
645 return progpath; |
|
7e4228780ff8
Jim Ahlstrom's contributions for DOS, OS/2, WIN3.1.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
646 } |
