Mercurial > cpython-lru_cache-weakref
annotate Modules/getpath.c @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | fa6e50208d93 |
| children | be3b4aa2ad28 |
| rev | line source |
|---|---|
|
3621
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
3416
diff
changeset
|
1 /* Return the initial module search path. */ |
|
f158edccc72c
grand renaming; added copyright to some files
Guido van Rossum <guido@python.org>
parents:
3416
diff
changeset
|
2 |
| 2896 | 3 #include "Python.h" |
| 4 #include "osdefs.h" | |
| 5 | |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
6 #include <sys/types.h> |
|
5698
ba860dc0a585
Use string.h, not strings.h
Guido van Rossum <guido@python.org>
parents:
5568
diff
changeset
|
7 #include <string.h> |
| 2896 | 8 |
|
32410
8444849c9448
Modules/getpath.c now compiles properly under OS X when using the
Brett Cannon <bcannon@gmail.com>
parents:
32399
diff
changeset
|
9 #ifdef __APPLE__ |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
10 #include <mach-o/dyld.h> |
|
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
11 #endif |
|
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
12 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
13 /* Search in some common locations for the associated Python libraries. |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
14 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
15 * Two directories must be found, the platform independent directory |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
16 * (prefix), containing the common .py and .pyc files, and the platform |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
17 * dependent directory (exec_prefix), containing the shared library |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
18 * modules. Note that prefix and exec_prefix can be the same directory, |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
19 * but for some installations, they are different. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
20 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
21 * Py_GetPath() carries out separate searches for prefix and exec_prefix. |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
22 * Each search tries a number of different locations until a ``landmark'' |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
23 * file or directory is found. If no prefix or exec_prefix is found, a |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
24 * warning message is issued and the preprocessor defined PREFIX and |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
25 * EXEC_PREFIX are used (even though they will not work); python carries on |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
26 * as best as is possible, but most imports will fail. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
27 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
28 * Before any searches are done, the location of the executable is |
| 41102 | 29 * determined. If argv[0] has one or more slashes in it, it is used |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
30 * unchanged. Otherwise, it must have been invoked from the shell's path, |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
31 * so we search $PATH for the named executable and use that. If the |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
32 * executable was not found on $PATH (or there was no $PATH environment |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
33 * variable), the original argv[0] string is used. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
34 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
35 * Next, the executable location is examined to see if it is a symbolic |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
36 * link. If so, the link is chased (correctly interpreting a relative |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
37 * pathname if one is found) and the directory of the link target is used. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
38 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
39 * Finally, argv0_path is set to the directory containing the executable |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
40 * (i.e. the last component is stripped). |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
41 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
42 * With argv0_path in hand, we perform a number of steps. The same steps |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
43 * are performed for prefix and for exec_prefix, but with a different |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
44 * landmark. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
45 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
46 * Step 1. Are we running python out of the build directory? This is |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
47 * checked by looking for a different kind of landmark relative to |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
48 * argv0_path. For prefix, the landmark's path is derived from the VPATH |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
49 * preprocessor variable (taking into account that its value is almost, but |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
50 * not quite, what we need). For exec_prefix, the landmark is |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
51 * Modules/Setup. If the landmark is found, we're done. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
52 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
53 * For the remaining steps, the prefix landmark will always be |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
54 * lib/python$VERSION/os.py and the exec_prefix will always be |
|
6498
4981fd2b3211
Change sharedmodules to lib-dynload.
Guido van Rossum <guido@python.org>
parents:
6121
diff
changeset
|
55 * lib/python$VERSION/lib-dynload, where $VERSION is Python's version |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
56 * number as supplied by the Makefile. Note that this means that no more |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
57 * build directory checking is performed; if the first step did not find |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
58 * the landmarks, the assumption is that python is running from an |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
59 * installed setup. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
60 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
61 * Step 2. See if the $PYTHONHOME environment variable points to the |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
62 * installed location of the Python libraries. If $PYTHONHOME is set, then |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
63 * it points to prefix and exec_prefix. $PYTHONHOME can be a single |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
64 * directory, which is used for both, or the prefix and exec_prefix |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
65 * directories separated by a colon. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
66 * |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
67 * Step 3. Try to find prefix and exec_prefix relative to argv0_path, |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
68 * backtracking up the path until it is exhausted. This is the most common |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
69 * step to succeed. Note that if prefix and exec_prefix are different, |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
70 * exec_prefix is more likely to be found; however if exec_prefix is a |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
71 * subdirectory of prefix, both will be found. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
72 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
73 * Step 4. Search the directories pointed to by the preprocessor variables |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
74 * PREFIX and EXEC_PREFIX. These are supplied by the Makefile but can be |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
75 * passed in as options to the configure script. |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
76 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
77 * That's it! |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
78 * |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
79 * Well, almost. Once we have determined prefix and exec_prefix, the |
|
13620
5b727ab37092
Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents:
13428
diff
changeset
|
80 * preprocessor variable PYTHONPATH is used to construct a path. Each |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
81 * relative path on PYTHONPATH is prefixed with prefix. Then the directory |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
82 * containing the shared library modules is appended. The environment |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
83 * variable $PYTHONPATH is inserted in front of it all. Finally, the |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
84 * prefix and exec_prefix globals are tweaked so they reflect the values |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
85 * expected by other code, by stripping the "lib/python$VERSION/..." stuff |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
86 * off. If either points to the build directory, the globals are reset to |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
87 * the corresponding preprocessor variables (so sys.prefix will reflect the |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
88 * installation location, even though sys.path points into the build |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
89 * directory). This seems to make more sense given that currently the only |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
90 * known use of sys.prefix and sys.exec_prefix is for the ILU installation |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
91 * process to find the installed Python tree. |
|
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
92 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
93 |
|
37655
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
94 #ifdef __cplusplus |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
95 extern "C" { |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
96 #endif |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
97 |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
98 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
99 #ifndef VERSION |
|
16147
fbf8abec93d1
Clean up some comments and the default VERSION.
Guido van Rossum <guido@python.org>
parents:
14907
diff
changeset
|
100 #define VERSION "2.1" |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
101 #endif |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
102 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
103 #ifndef VPATH |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
104 #define VPATH "." |
| 2896 | 105 #endif |
| 106 | |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
107 #ifndef PREFIX |
|
39043
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
37655
diff
changeset
|
108 # ifdef __VMS |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
37655
diff
changeset
|
109 # define PREFIX "" |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
37655
diff
changeset
|
110 # else |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
37655
diff
changeset
|
111 # define PREFIX "/usr/local" |
|
c67b23397f30
Patch #1516912: improve Modules support for OpenVMS.
Neal Norwitz <nnorwitz@gmail.com>
parents:
37655
diff
changeset
|
112 # endif |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
113 #endif |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
114 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
115 #ifndef EXEC_PREFIX |
|
3878
4286910080a9
Don't have "." in the default path.
Guido van Rossum <guido@python.org>
parents:
3674
diff
changeset
|
116 #define EXEC_PREFIX PREFIX |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
117 #endif |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
118 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
119 #ifndef PYTHONPATH |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
120 #define PYTHONPATH PREFIX "/lib/python" VERSION ":" \ |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
121 EXEC_PREFIX "/lib/python" VERSION "/lib-dynload" |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
122 #endif |
| 2896 | 123 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
124 #ifndef LANDMARK |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
125 #define LANDMARK "os.py" |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
126 #endif |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
127 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
128 static char prefix[MAXPATHLEN+1]; |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
129 static char exec_prefix[MAXPATHLEN+1]; |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
130 static char progpath[MAXPATHLEN+1]; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
131 static char *module_search_path = NULL; |
|
14907
d01394b0aa69
Minor ANSIfication: lib_python no longer needs to be initialized
Fred Drake <fdrake@acm.org>
parents:
14898
diff
changeset
|
132 static char lib_python[] = "lib/python" VERSION; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
133 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
134 static void |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
135 reduce(char *dir) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
136 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
137 size_t i = strlen(dir); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
138 while (i > 0 && dir[i] != SEP) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
139 --i; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
140 dir[i] = '\0'; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
141 } |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
142 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
143 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
144 static int |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
145 isfile(char *filename) /* Is file, not directory */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
146 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
147 struct stat buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
148 if (stat(filename, &buf) != 0) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
149 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
150 if (!S_ISREG(buf.st_mode)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
151 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
152 return 1; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
153 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
154 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
155 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
156 static int |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
157 ismodule(char *filename) /* Is module -- check for .pyc/.pyo too */ |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
158 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
159 if (isfile(filename)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
160 return 1; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
161 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
162 /* Check for the compiled version of prefix. */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
163 if (strlen(filename) < MAXPATHLEN) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
164 strcat(filename, Py_OptimizeFlag ? "o" : "c"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
165 if (isfile(filename)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
166 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
167 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
168 return 0; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
169 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
170 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
171 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
172 static int |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
173 isxfile(char *filename) /* Is executable file */ |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
174 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
175 struct stat buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
176 if (stat(filename, &buf) != 0) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
177 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
178 if (!S_ISREG(buf.st_mode)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
179 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
180 if ((buf.st_mode & 0111) == 0) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
181 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
182 return 1; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
183 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
184 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
185 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
186 static int |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
187 isdir(char *filename) /* Is directory */ |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
188 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
189 struct stat buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
190 if (stat(filename, &buf) != 0) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
191 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
192 if (!S_ISDIR(buf.st_mode)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
193 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
194 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
195 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
196 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
197 |
|
33038
fee2038b8fa9
Bug 1003471: Python 1.5.2 security vulnerability still present in 2.3.4
Tim Peters <tim.peters@gmail.com>
parents:
32410
diff
changeset
|
198 /* Add a path component, by appending stuff to buffer. |
|
fee2038b8fa9
Bug 1003471: Python 1.5.2 security vulnerability still present in 2.3.4
Tim Peters <tim.peters@gmail.com>
parents:
32410
diff
changeset
|
199 buffer must have at least MAXPATHLEN + 1 bytes allocated, and contain a |
|
fee2038b8fa9
Bug 1003471: Python 1.5.2 security vulnerability still present in 2.3.4
Tim Peters <tim.peters@gmail.com>
parents:
32410
diff
changeset
|
200 NUL-terminated string with no more than MAXPATHLEN characters (not counting |
|
fee2038b8fa9
Bug 1003471: Python 1.5.2 security vulnerability still present in 2.3.4
Tim Peters <tim.peters@gmail.com>
parents:
32410
diff
changeset
|
201 the trailing NUL). It's a fatal error if it contains a string longer than |
|
fee2038b8fa9
Bug 1003471: Python 1.5.2 security vulnerability still present in 2.3.4
Tim Peters <tim.peters@gmail.com>
parents:
32410
diff
changeset
|
202 that (callers must be careful!). If these requirements are met, it's |
|
fee2038b8fa9
Bug 1003471: Python 1.5.2 security vulnerability still present in 2.3.4
Tim Peters <tim.peters@gmail.com>
parents:
32410
diff
changeset
|
203 guaranteed that buffer will still be a NUL-terminated string with no more |
|
fee2038b8fa9
Bug 1003471: Python 1.5.2 security vulnerability still present in 2.3.4
Tim Peters <tim.peters@gmail.com>
parents:
32410
diff
changeset
|
204 than MAXPATHLEN characters at exit. If stuff is too long, only as much of |
|
fee2038b8fa9
Bug 1003471: Python 1.5.2 security vulnerability still present in 2.3.4
Tim Peters <tim.peters@gmail.com>
parents:
32410
diff
changeset
|
205 stuff as fits will be appended. |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
206 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
207 static void |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
208 joinpath(char *buffer, char *stuff) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
209 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
210 size_t n, k; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
211 if (stuff[0] == SEP) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
212 n = 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
213 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
214 n = strlen(buffer); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
215 if (n > 0 && buffer[n-1] != SEP && n < MAXPATHLEN) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
216 buffer[n++] = SEP; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
217 } |
|
33038
fee2038b8fa9
Bug 1003471: Python 1.5.2 security vulnerability still present in 2.3.4
Tim Peters <tim.peters@gmail.com>
parents:
32410
diff
changeset
|
218 if (n > MAXPATHLEN) |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
219 Py_FatalError("buffer overflow in getpath.c's joinpath()"); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
220 k = strlen(stuff); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
221 if (n + k > MAXPATHLEN) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
222 k = MAXPATHLEN - n; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
223 strncpy(buffer+n, stuff, k); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
224 buffer[n+k] = '\0'; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
225 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
226 |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
227 /* copy_absolute requires that path be allocated at least |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
228 MAXPATHLEN + 1 bytes and that p be no more than MAXPATHLEN bytes. */ |
|
14845
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
229 static void |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
230 copy_absolute(char *path, char *p) |
|
14845
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
231 { |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
232 if (p[0] == SEP) |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
233 strcpy(path, p); |
|
14845
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
234 else { |
|
65170
fa6e50208d93
copy_absolute(): keep the relative path if getcwd() failed
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63170
diff
changeset
|
235 if (!getcwd(path, MAXPATHLEN)) { |
|
fa6e50208d93
copy_absolute(): keep the relative path if getcwd() failed
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63170
diff
changeset
|
236 /* unable to get the current directory */ |
|
fa6e50208d93
copy_absolute(): keep the relative path if getcwd() failed
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63170
diff
changeset
|
237 strcpy(path, p); |
|
fa6e50208d93
copy_absolute(): keep the relative path if getcwd() failed
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63170
diff
changeset
|
238 return; |
|
fa6e50208d93
copy_absolute(): keep the relative path if getcwd() failed
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63170
diff
changeset
|
239 } |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
240 if (p[0] == '.' && p[1] == SEP) |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
241 p += 2; |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
242 joinpath(path, p); |
|
14845
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
243 } |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
244 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
245 |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
246 /* absolutize() requires that path be allocated at least MAXPATHLEN+1 bytes. */ |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
247 static void |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
248 absolutize(char *path) |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
249 { |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
250 char buffer[MAXPATHLEN + 1]; |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
251 |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
252 if (path[0] == SEP) |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
253 return; |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
254 copy_absolute(buffer, path); |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
255 strcpy(path, buffer); |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
256 } |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
257 |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
258 /* search_for_prefix requires that argv0_path be no more than MAXPATHLEN |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
259 bytes long. |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
260 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
261 static int |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
262 search_for_prefix(char *argv0_path, char *home) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
263 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
264 size_t n; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
265 char *vpath; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
266 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
267 /* If PYTHONHOME is set, we believe it unconditionally */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
268 if (home) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
269 char *delim; |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
270 strncpy(prefix, home, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
271 delim = strchr(prefix, DELIM); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
272 if (delim) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
273 *delim = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
274 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
275 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
276 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
277 } |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
278 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
279 /* Check to see if argv[0] is in the build directory */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
280 strcpy(prefix, argv0_path); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
281 joinpath(prefix, "Modules/Setup"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
282 if (isfile(prefix)) { |
|
16222
a0e46c3be63e
Build now happens in toplevel directory, not Modules. Don't monkey with
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
16147
diff
changeset
|
283 /* Check VPATH to see if argv0_path is in the build directory. */ |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
284 vpath = VPATH; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
285 strcpy(prefix, argv0_path); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
286 joinpath(prefix, vpath); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
287 joinpath(prefix, "Lib"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
288 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
289 if (ismodule(prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
290 return -1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
291 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
292 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
293 /* Search from argv0_path, until root is found */ |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
294 copy_absolute(prefix, argv0_path); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
295 do { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
296 n = strlen(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
297 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
298 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
299 if (ismodule(prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
300 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
301 prefix[n] = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
302 reduce(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
303 } while (prefix[0]); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
304 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
305 /* Look at configure's PREFIX */ |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
306 strncpy(prefix, PREFIX, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
307 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
308 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
309 if (ismodule(prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
310 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
311 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
312 /* Fail */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
313 return 0; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
314 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
315 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
316 |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
317 /* search_for_exec_prefix requires that argv0_path be no more than |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
318 MAXPATHLEN bytes long. |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
319 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
320 static int |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
321 search_for_exec_prefix(char *argv0_path, char *home) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
322 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
323 size_t n; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
324 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
325 /* If PYTHONHOME is set, we believe it unconditionally */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
326 if (home) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
327 char *delim; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
328 delim = strchr(home, DELIM); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
329 if (delim) |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
330 strncpy(exec_prefix, delim+1, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
331 else |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
332 strncpy(exec_prefix, home, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
333 joinpath(exec_prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
334 joinpath(exec_prefix, "lib-dynload"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
335 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
336 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
337 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
338 /* Check to see if argv[0] is in the build directory */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
339 strcpy(exec_prefix, argv0_path); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
340 joinpath(exec_prefix, "Modules/Setup"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
341 if (isfile(exec_prefix)) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
342 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
343 return -1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
344 } |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
345 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
346 /* Search from argv0_path, until root is found */ |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
347 copy_absolute(exec_prefix, argv0_path); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
348 do { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
349 n = strlen(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
350 joinpath(exec_prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
351 joinpath(exec_prefix, "lib-dynload"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
352 if (isdir(exec_prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
353 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
354 exec_prefix[n] = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
355 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
356 } while (exec_prefix[0]); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
357 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
358 /* Look at configure's EXEC_PREFIX */ |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
359 strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
360 joinpath(exec_prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
361 joinpath(exec_prefix, "lib-dynload"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
362 if (isdir(exec_prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
363 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
364 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
365 /* Fail */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
366 return 0; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
367 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
368 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
369 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
370 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
371 calculate_path(void) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
372 { |
|
13667
a6c7bfdd6777
Even more ANSIfication: fix as many function pointers and declarations as
Thomas Wouters <thomas@python.org>
parents:
13651
diff
changeset
|
373 extern char *Py_GetProgramName(void); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
374 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
375 static char delimiter[2] = {DELIM, '\0'}; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
376 static char separator[2] = {SEP, '\0'}; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
377 char *pythonpath = PYTHONPATH; |
|
18808
a8b1acc7a21f
Add -E command line switch (ignore environment variables like PYTHONHOME
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents:
16222
diff
changeset
|
378 char *rtpypath = Py_GETENV("PYTHONPATH"); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
379 char *home = Py_GetPythonHome(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
380 char *path = getenv("PATH"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
381 char *prog = Py_GetProgramName(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
382 char argv0_path[MAXPATHLEN+1]; |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
383 char zip_path[MAXPATHLEN+1]; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
384 int pfound, efound; /* 1 if found; -1 if found build directory */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
385 char *buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
386 size_t bufsz; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
387 size_t prefixsz; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
388 char *defpath = pythonpath; |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
389 #ifdef WITH_NEXT_FRAMEWORK |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
390 NSModule pythonModule; |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
391 #endif |
|
32229
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
392 #ifdef __APPLE__ |
|
36205
01cbed5e8731
squash compiler warning on Mac OSX 10.3
Skip Montanaro <skip@pobox.com>
parents:
35578
diff
changeset
|
393 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
|
35578
c28d0ed86ff0
Change type on variable to silence gcc 4 warning. Call signature was found at
Brett Cannon <bcannon@gmail.com>
parents:
33038
diff
changeset
|
394 uint32_t nsexeclength = MAXPATHLEN; |
|
36205
01cbed5e8731
squash compiler warning on Mac OSX 10.3
Skip Montanaro <skip@pobox.com>
parents:
35578
diff
changeset
|
395 #else |
|
01cbed5e8731
squash compiler warning on Mac OSX 10.3
Skip Montanaro <skip@pobox.com>
parents:
35578
diff
changeset
|
396 unsigned long nsexeclength = MAXPATHLEN; |
|
01cbed5e8731
squash compiler warning on Mac OSX 10.3
Skip Montanaro <skip@pobox.com>
parents:
35578
diff
changeset
|
397 #endif |
|
32229
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
398 #endif |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
399 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
400 /* If there is no slash in the argv0 path, then we have to |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
401 * assume python is on the user's $PATH, since there's no |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
402 * other way to find a directory to start the search from. If |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
403 * $PATH isn't exported, you lose. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
404 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
405 if (strchr(prog, SEP)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
406 strncpy(progpath, prog, MAXPATHLEN); |
|
32229
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
407 #ifdef __APPLE__ |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
408 /* On Mac OS X, if a script uses an interpreter of the form |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
409 * "#!/opt/python2.3/bin/python", the kernel only passes "python" |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
410 * as argv[0], which falls through to the $PATH search below. |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
411 * If /opt/python2.3/bin isn't in your path, or is near the end, |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
412 * this algorithm may incorrectly find /usr/bin/python. To work |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
413 * around this, we can use _NSGetExecutablePath to get a better |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
414 * hint of what the intended interpreter was, although this |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
415 * will fail if a relative path was used. but in that case, |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
416 * absolutize() should help us out below |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
417 */ |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
418 else if(0 == _NSGetExecutablePath(progpath, &nsexeclength) && progpath[0] == SEP) |
|
27967fbba48f
Fix for #932977: MacOSX does not pass the whole pathname in argv[0] for
Jack Jansen <jack.jansen@cwi.nl>
parents:
26944
diff
changeset
|
419 ; |
|
32399
472023d0a10d
Change comment from C++ style to C.
Brett Cannon <bcannon@gmail.com>
parents:
32229
diff
changeset
|
420 #endif /* __APPLE__ */ |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
421 else if (path) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
422 while (1) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
423 char *delim = strchr(path, DELIM); |
|
21141
51b4572cf013
Changed logic for finding python home in Mac OS X framework Pythons.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20156
diff
changeset
|
424 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
425 if (delim) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
426 size_t len = delim - path; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
427 if (len > MAXPATHLEN) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
428 len = MAXPATHLEN; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
429 strncpy(progpath, path, len); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
430 *(progpath + len) = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
431 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
432 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
433 strncpy(progpath, path, MAXPATHLEN); |
|
21141
51b4572cf013
Changed logic for finding python home in Mac OS X framework Pythons.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20156
diff
changeset
|
434 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
435 joinpath(progpath, prog); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
436 if (isxfile(progpath)) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
437 break; |
|
21141
51b4572cf013
Changed logic for finding python home in Mac OS X framework Pythons.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20156
diff
changeset
|
438 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
439 if (!delim) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
440 progpath[0] = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
441 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
442 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
443 path = delim + 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
444 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
445 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
446 else |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
447 progpath[0] = '\0'; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
448 if (progpath[0] != SEP && progpath[0] != '\0') |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
449 absolutize(progpath); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
450 strncpy(argv0_path, progpath, MAXPATHLEN); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
451 argv0_path[MAXPATHLEN] = '\0'; |
|
21141
51b4572cf013
Changed logic for finding python home in Mac OS X framework Pythons.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20156
diff
changeset
|
452 |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
453 #ifdef WITH_NEXT_FRAMEWORK |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
454 /* On Mac OS X we have a special case if we're running from a framework. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
455 ** This is because the python home should be set relative to the library, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
456 ** which is in the framework, not relative to the executable, which may |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
457 ** be outside of the framework. Except when we're in the build directory... |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
458 */ |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
459 pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize")); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
460 /* Use dylib functions to find out where the framework was loaded from */ |
|
26764
6b31b26e418d
Squashed compiler warnings by adding casts, making sure prototypes are in
Jack Jansen <jack.jansen@cwi.nl>
parents:
26550
diff
changeset
|
461 buf = (char *)NSLibraryNameForModule(pythonModule); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
462 if (buf != NULL) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
463 /* We're in a framework. */ |
|
19261
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
464 /* See if we might be in the build directory. The framework in the |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
465 ** build directory is incomplete, it only has the .dylib and a few |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
466 ** needed symlinks, it doesn't have the Lib directories and such. |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
467 ** If we're running with the framework from the build directory we must |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
468 ** be running the interpreter in the build directory, so we use the |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
469 ** build-directory-specific logic to find Lib and such. |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
470 */ |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
471 strncpy(argv0_path, buf, MAXPATHLEN); |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
472 reduce(argv0_path); |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
473 joinpath(argv0_path, lib_python); |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
474 joinpath(argv0_path, LANDMARK); |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
475 if (!ismodule(argv0_path)) { |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
476 /* We are in the build directory so use the name of the |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
477 executable - we know that the absolute path is passed */ |
|
63170
97b841b3b0b4
Merged revisions 83096 via svnmerge from
Ronald Oussoren <ronaldoussoren@mac.com>
parents:
61463
diff
changeset
|
478 strncpy(argv0_path, progpath, MAXPATHLEN); |
|
19261
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
479 } |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
480 else { |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
481 /* Use the location of the library as the progpath */ |
|
21141
51b4572cf013
Changed logic for finding python home in Mac OS X framework Pythons.
Jack Jansen <jack.jansen@cwi.nl>
parents:
20156
diff
changeset
|
482 strncpy(argv0_path, buf, MAXPATHLEN); |
|
19261
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
483 } |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
484 } |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
485 #endif |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
486 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
487 #if HAVE_READLINK |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
488 { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
489 char tmpbuffer[MAXPATHLEN+1]; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
490 int linklen = readlink(progpath, tmpbuffer, MAXPATHLEN); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
491 while (linklen != -1) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
492 /* It's not null terminated! */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
493 tmpbuffer[linklen] = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
494 if (tmpbuffer[0] == SEP) |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
495 /* tmpbuffer should never be longer than MAXPATHLEN, |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
496 but extra check does not hurt */ |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
497 strncpy(argv0_path, tmpbuffer, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
498 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
499 /* Interpret relative to progpath */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
500 reduce(argv0_path); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
501 joinpath(argv0_path, tmpbuffer); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
502 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
503 linklen = readlink(argv0_path, tmpbuffer, MAXPATHLEN); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
504 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
505 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
506 #endif /* HAVE_READLINK */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
507 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
508 reduce(argv0_path); |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
509 /* At this point, argv0_path is guaranteed to be less than |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
510 MAXPATHLEN bytes long. |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
511 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
512 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
513 if (!(pfound = search_for_prefix(argv0_path, home))) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
514 if (!Py_FrozenFlag) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
515 fprintf(stderr, |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
516 "Could not find platform independent libraries <prefix>\n"); |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
517 strncpy(prefix, PREFIX, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
518 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
519 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
520 else |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
521 reduce(prefix); |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
522 |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
523 strncpy(zip_path, prefix, MAXPATHLEN); |
|
26944
beea42152787
Make sure zip_path is null-terminated, since it's on the stack
Neal Norwitz <nnorwitz@gmail.com>
parents:
26885
diff
changeset
|
524 zip_path[MAXPATHLEN] = '\0'; |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
525 if (pfound > 0) { /* Use the reduced prefix returned by Py_GetPrefix() */ |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
526 reduce(zip_path); |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
527 reduce(zip_path); |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
528 } |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
529 else |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
530 strncpy(zip_path, PREFIX, MAXPATHLEN); |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
531 joinpath(zip_path, "lib/python00.zip"); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
532 bufsz = strlen(zip_path); /* Replace "00" with version */ |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
533 zip_path[bufsz - 6] = VERSION[0]; |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
534 zip_path[bufsz - 5] = VERSION[2]; |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
535 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
536 if (!(efound = search_for_exec_prefix(argv0_path, home))) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
537 if (!Py_FrozenFlag) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
538 fprintf(stderr, |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
539 "Could not find platform dependent libraries <exec_prefix>\n"); |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
540 strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
541 joinpath(exec_prefix, "lib/lib-dynload"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
542 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
543 /* If we found EXEC_PREFIX do *not* reduce it! (Yet.) */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
544 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
545 if ((!pfound || !efound) && !Py_FrozenFlag) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
546 fprintf(stderr, |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
547 "Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]\n"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
548 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
549 /* Calculate size of return buffer. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
550 */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
551 bufsz = 0; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
552 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
553 if (rtpypath) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
554 bufsz += strlen(rtpypath) + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
555 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
556 prefixsz = strlen(prefix) + 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
557 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
558 while (1) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
559 char *delim = strchr(defpath, DELIM); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
560 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
561 if (defpath[0] != SEP) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
562 /* Paths are relative to prefix */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
563 bufsz += prefixsz; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
564 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
565 if (delim) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
566 bufsz += delim - defpath + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
567 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
568 bufsz += strlen(defpath) + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
569 break; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
570 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
571 defpath = delim + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
572 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
573 |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
574 bufsz += strlen(zip_path) + 1; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
575 bufsz += strlen(exec_prefix) + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
576 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
577 /* This is the only malloc call in this file */ |
|
37607
480a5625e286
Some more changes to make code compile under a C++ compiler.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
36623
diff
changeset
|
578 buf = (char *)PyMem_Malloc(bufsz); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
579 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
580 if (buf == NULL) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
581 /* We can't exit, so print a warning and limp along */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
582 fprintf(stderr, "Not enough memory for dynamic PYTHONPATH.\n"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
583 fprintf(stderr, "Using default static PYTHONPATH.\n"); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
584 module_search_path = PYTHONPATH; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
585 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
586 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
587 /* Run-time value of $PYTHONPATH goes first */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
588 if (rtpypath) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
589 strcpy(buf, rtpypath); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
590 strcat(buf, delimiter); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
591 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
592 else |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
593 buf[0] = '\0'; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
594 |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
595 /* Next is the default zip path */ |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
596 strcat(buf, zip_path); |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
597 strcat(buf, delimiter); |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
598 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
599 /* Next goes merge of compile-time $PYTHONPATH with |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
600 * dynamically located prefix. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
601 */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
602 defpath = pythonpath; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
603 while (1) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
604 char *delim = strchr(defpath, DELIM); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
605 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
606 if (defpath[0] != SEP) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
607 strcat(buf, prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
608 strcat(buf, separator); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
609 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
610 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
611 if (delim) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
612 size_t len = delim - defpath + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
613 size_t end = strlen(buf) + len; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
614 strncat(buf, defpath, len); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
615 *(buf + end) = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
616 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
617 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
618 strcat(buf, defpath); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
619 break; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
620 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
621 defpath = delim + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
622 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
623 strcat(buf, delimiter); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
624 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
625 /* Finally, on goes the directory for dynamic-load modules */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
626 strcat(buf, exec_prefix); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
627 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
628 /* And publish the results */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
629 module_search_path = buf; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
630 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
631 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
632 /* Reduce prefix and exec_prefix to their essence, |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
633 * e.g. /usr/local/lib/python1.5 is reduced to /usr/local. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
634 * If we're loading relative to the build directory, |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
635 * return the compiled-in defaults instead. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
636 */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
637 if (pfound > 0) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
638 reduce(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
639 reduce(prefix); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
640 /* The prefix is the root directory, but reduce() chopped |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
641 * off the "/". */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
642 if (!prefix[0]) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
643 strcpy(prefix, separator); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
644 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
645 else |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
646 strncpy(prefix, PREFIX, MAXPATHLEN); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
647 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
648 if (efound > 0) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
649 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
650 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
651 reduce(exec_prefix); |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
652 if (!exec_prefix[0]) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
59508
diff
changeset
|
653 strcpy(exec_prefix, separator); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
654 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
655 else |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
656 strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
657 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
658 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
659 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
660 /* External interface */ |
| 2896 | 661 |
| 662 char * | |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
663 Py_GetPath(void) |
| 2896 | 664 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
665 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
666 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
667 return module_search_path; |
| 2896 | 668 } |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
669 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
670 char * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
671 Py_GetPrefix(void) |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
672 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
673 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
674 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
675 return prefix; |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
676 } |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
677 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
678 char * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
679 Py_GetExecPrefix(void) |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
680 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
681 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
682 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
683 return exec_prefix; |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
684 } |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
685 |
|
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
686 char * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
687 Py_GetProgramFullPath(void) |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
688 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
689 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
690 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
691 return progpath; |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
692 } |
|
37655
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
693 |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
694 |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
695 #ifdef __cplusplus |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
696 } |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
697 #endif |
|
2f3f2e32dfd9
spread the extern "C" { } magic pixie dust around. Python itself builds now
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37607
diff
changeset
|
698 |
