Mercurial > cpython-lru_cache-weakref
annotate Modules/getpath.c @ 86127:a3d09c19bb93
merge with 3.3
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sun, 06 Oct 2013 19:24:00 +0200 |
| parents | 01597384531f |
| children | a7a8ccf69708 |
| 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 |
|
41554
06145fbc7ab9
Merged revisions 53952-54987 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
39442
diff
changeset
|
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 |
|
63981
794eb40bef3a
Add comments about Windows in Modules/getpath.c
Antoine Pitrou <solipsis@pitrou.net>
parents:
63964
diff
changeset
|
51 * pybuilddir.txt. 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. |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
92 * |
|
64955
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
93 * An embedding application can use Py_SetPath() to override all of |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
94 * these authomatic path computations. |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
95 * |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
96 * NOTE: Windows MSVC builds use PC/getpathp.c instead! |
|
5316
c8e24c4b8bfb
Removed two unused static function: string_addsep() and
Barry Warsaw <barry@python.org>
parents:
5300
diff
changeset
|
97 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
98 |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
99 #ifdef __cplusplus |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
100 extern "C" { |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
101 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
102 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
103 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
104 #ifndef VERSION |
|
16147
fbf8abec93d1
Clean up some comments and the default VERSION.
Guido van Rossum <guido@python.org>
parents:
14907
diff
changeset
|
105 #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
|
106 #endif |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
107 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
108 #ifndef VPATH |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
109 #define VPATH "." |
| 2896 | 110 #endif |
| 111 | |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
112 #ifndef PREFIX |
|
39442
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
113 # ifdef __VMS |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
114 # define PREFIX "" |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
115 # else |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
116 # define PREFIX "/usr/local" |
|
654c380cf8b9
Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents:
37879
diff
changeset
|
117 # endif |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
118 #endif |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
119 |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
120 #ifndef EXEC_PREFIX |
|
3878
4286910080a9
Don't have "." in the default path.
Guido van Rossum <guido@python.org>
parents:
3674
diff
changeset
|
121 #define EXEC_PREFIX PREFIX |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
122 #endif |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
123 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
124 #ifndef PYTHONPATH |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
125 #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
|
126 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
|
127 #endif |
| 2896 | 128 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
129 #ifndef LANDMARK |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
130 #define LANDMARK L"os.py" |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
131 #endif |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
132 |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
133 static wchar_t prefix[MAXPATHLEN+1]; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
134 static wchar_t exec_prefix[MAXPATHLEN+1]; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
135 static wchar_t progpath[MAXPATHLEN+1]; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
136 static wchar_t *module_search_path = NULL; |
|
68662
a791dd7d51f3
Issue #10914: fix bogus memory management in Modules/getpath.c, leading to a possible crash when calling Py_SetPath()
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
137 static int module_search_path_malloced = 0; |
|
59041
9b5806a008e7
#4532: fixes to make 3.x compile on QNX 6.3.2 (reported by Matt Kraai)
Andrew M. Kuchling <amk@amk.ca>
parents:
51560
diff
changeset
|
138 static wchar_t *lib_python = L"lib/python" VERSION; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
139 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
140 static void |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
141 reduce(wchar_t *dir) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
142 { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
143 size_t i = wcslen(dir); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
144 while (i > 0 && dir[i] != SEP) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
145 --i; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
146 dir[i] = '\0'; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
147 } |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
148 |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
149 static int |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
150 isfile(wchar_t *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
|
151 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
152 struct stat buf; |
|
65162
39014f0abc32
Create fileutils.c/.h
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65161
diff
changeset
|
153 if (_Py_wstat(filename, &buf) != 0) |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
154 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
155 if (!S_ISREG(buf.st_mode)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
156 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
157 return 1; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
158 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
159 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
160 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
161 static int |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
162 ismodule(wchar_t *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
|
163 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
164 if (isfile(filename)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
165 return 1; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
166 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
167 /* Check for the compiled version of prefix. */ |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
168 if (wcslen(filename) < MAXPATHLEN) { |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
169 wcscat(filename, Py_OptimizeFlag ? L"o" : L"c"); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
170 if (isfile(filename)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
171 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
172 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
173 return 0; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
174 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
175 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
176 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
177 static int |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
178 isxfile(wchar_t *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
|
179 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
180 struct stat buf; |
|
65162
39014f0abc32
Create fileutils.c/.h
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65161
diff
changeset
|
181 if (_Py_wstat(filename, &buf) != 0) |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
182 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
183 if (!S_ISREG(buf.st_mode)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
184 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
185 if ((buf.st_mode & 0111) == 0) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
186 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
187 return 1; |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
188 } |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
189 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
190 |
|
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
191 static int |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
192 isdir(wchar_t *filename) /* Is directory */ |
|
7117
419dca2b3a61
Instead of a single exists(), differentiate between files, modules,
Guido van Rossum <guido@python.org>
parents:
6823
diff
changeset
|
193 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
194 struct stat buf; |
|
65162
39014f0abc32
Create fileutils.c/.h
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65161
diff
changeset
|
195 if (_Py_wstat(filename, &buf) != 0) |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
196 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
197 if (!S_ISDIR(buf.st_mode)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
198 return 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
199 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
200 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
201 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
202 |
|
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
|
203 /* 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
212 static void |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
213 joinpath(wchar_t *buffer, wchar_t *stuff) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
214 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
215 size_t n, k; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
216 if (stuff[0] == SEP) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
217 n = 0; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
218 else { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
219 n = wcslen(buffer); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
220 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
|
221 buffer[n++] = SEP; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
222 } |
|
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
|
223 if (n > MAXPATHLEN) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
224 Py_FatalError("buffer overflow in getpath.c's joinpath()"); |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
225 k = wcslen(stuff); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
226 if (n + k > MAXPATHLEN) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
227 k = MAXPATHLEN - n; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
228 wcsncpy(buffer+n, stuff, k); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
229 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
|
230 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
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 /* 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
|
233 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
|
234 static void |
|
65312
a27fc0ff3678
_Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogates
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65169
diff
changeset
|
235 copy_absolute(wchar_t *path, wchar_t *p, size_t pathlen) |
|
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
|
236 { |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
237 if (p[0] == SEP) |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
238 wcscpy(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
|
239 else { |
|
65312
a27fc0ff3678
_Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogates
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65169
diff
changeset
|
240 if (!_Py_wgetcwd(path, pathlen)) { |
|
65171
39a0b943e3e1
copy_absolute(): keep the relative path if _wgetcwd() failed
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63983
diff
changeset
|
241 /* unable to get the current directory */ |
|
39a0b943e3e1
copy_absolute(): keep the relative path if _wgetcwd() failed
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63983
diff
changeset
|
242 wcscpy(path, p); |
|
39a0b943e3e1
copy_absolute(): keep the relative path if _wgetcwd() failed
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63983
diff
changeset
|
243 return; |
|
39a0b943e3e1
copy_absolute(): keep the relative path if _wgetcwd() failed
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63983
diff
changeset
|
244 } |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
245 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
|
246 p += 2; |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
247 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
|
248 } |
|
88d3a8974409
fix bug #114290: when interpreter's argv[0] has a relative path make
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14375
diff
changeset
|
249 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
250 |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
251 /* 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
|
252 static void |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
253 absolutize(wchar_t *path) |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
254 { |
|
65312
a27fc0ff3678
_Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogates
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65169
diff
changeset
|
255 wchar_t buffer[MAXPATHLEN+1]; |
|
20156
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 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
|
258 return; |
|
65312
a27fc0ff3678
_Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogates
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65169
diff
changeset
|
259 copy_absolute(buffer, path, MAXPATHLEN+1); |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
260 wcscpy(path, buffer); |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
261 } |
|
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
262 |
|
77154
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
263 /* search for a prefix value in an environment file. If found, copy it |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
264 to the provided buffer, which is expected to be no more than MAXPATHLEN |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
265 bytes long. |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
266 */ |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
267 |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
268 static int |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
269 find_env_config_value(FILE * env_file, const wchar_t * key, wchar_t * value) |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
270 { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
271 int result = 0; /* meaning not found */ |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
272 char buffer[MAXPATHLEN*2+1]; /* allow extra for key, '=', etc. */ |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
273 |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
274 fseek(env_file, 0, SEEK_SET); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
275 while (!feof(env_file)) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
276 char * p = fgets(buffer, MAXPATHLEN*2, env_file); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
277 wchar_t tmpbuffer[MAXPATHLEN*2+1]; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
278 PyObject * decoded; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
279 int n; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
280 |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
281 if (p == NULL) |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
282 break; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
283 n = strlen(p); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
284 if (p[n - 1] != '\n') { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
285 /* line has overflowed - bail */ |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
286 break; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
287 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
288 if (p[0] == '#') /* Comment - skip */ |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
289 continue; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
290 decoded = PyUnicode_DecodeUTF8(buffer, n, "surrogateescape"); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
291 if (decoded != NULL) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
292 Py_ssize_t k; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
293 wchar_t * state; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
294 k = PyUnicode_AsWideChar(decoded, |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
295 tmpbuffer, MAXPATHLEN * 2); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
296 Py_DECREF(decoded); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
297 if (k >= 0) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
298 wchar_t * tok = wcstok(tmpbuffer, L" \t\r\n", &state); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
299 if ((tok != NULL) && !wcscmp(tok, key)) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
300 tok = wcstok(NULL, L" \t", &state); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
301 if ((tok != NULL) && !wcscmp(tok, L"=")) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
302 tok = wcstok(NULL, L"\r\n", &state); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
303 if (tok != NULL) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
304 wcsncpy(value, tok, MAXPATHLEN); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
305 result = 1; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
306 break; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
307 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
308 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
309 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
310 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
311 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
312 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
313 return result; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
314 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
315 |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
316 /* 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
|
317 bytes long. |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
318 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
319 static int |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
320 search_for_prefix(wchar_t *argv0_path, wchar_t *home, wchar_t *_prefix) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
321 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
322 size_t n; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
323 wchar_t *vpath; |
|
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) { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
327 wchar_t *delim; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
328 wcsncpy(prefix, home, MAXPATHLEN); |
|
84785
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
329 prefix[MAXPATHLEN] = L'\0'; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
330 delim = wcschr(prefix, DELIM); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
331 if (delim) |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
332 *delim = L'\0'; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
333 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
334 joinpath(prefix, LANDMARK); |
|
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 } |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
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 */ |
|
84785
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
339 wcsncpy(prefix, argv0_path, MAXPATHLEN); |
|
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
340 prefix[MAXPATHLEN] = L'\0'; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
341 joinpath(prefix, L"Modules/Setup"); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
342 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
|
343 /* Check VPATH to see if argv0_path is in the build directory. */ |
|
65600
5b6e13b6b473
Issue #6011: getpath: decode VPATH env var from the locale encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65414
diff
changeset
|
344 vpath = _Py_char2wchar(VPATH, NULL); |
|
5b6e13b6b473
Issue #6011: getpath: decode VPATH env var from the locale encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65414
diff
changeset
|
345 if (vpath != NULL) { |
|
84785
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
346 wcsncpy(prefix, argv0_path, MAXPATHLEN); |
|
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
347 prefix[MAXPATHLEN] = L'\0'; |
|
65600
5b6e13b6b473
Issue #6011: getpath: decode VPATH env var from the locale encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65414
diff
changeset
|
348 joinpath(prefix, vpath); |
|
84490
18bb92b0c458
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents:
80186
diff
changeset
|
349 PyMem_RawFree(vpath); |
|
65600
5b6e13b6b473
Issue #6011: getpath: decode VPATH env var from the locale encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65414
diff
changeset
|
350 joinpath(prefix, L"Lib"); |
|
5b6e13b6b473
Issue #6011: getpath: decode VPATH env var from the locale encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65414
diff
changeset
|
351 joinpath(prefix, LANDMARK); |
|
5b6e13b6b473
Issue #6011: getpath: decode VPATH env var from the locale encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65414
diff
changeset
|
352 if (ismodule(prefix)) |
|
5b6e13b6b473
Issue #6011: getpath: decode VPATH env var from the locale encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65414
diff
changeset
|
353 return -1; |
|
5b6e13b6b473
Issue #6011: getpath: decode VPATH env var from the locale encoding
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65414
diff
changeset
|
354 } |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
355 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
356 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
357 /* Search from argv0_path, until root is found */ |
|
65312
a27fc0ff3678
_Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogates
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65169
diff
changeset
|
358 copy_absolute(prefix, argv0_path, MAXPATHLEN+1); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
359 do { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
360 n = wcslen(prefix); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
361 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
362 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
363 if (ismodule(prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
364 return 1; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
365 prefix[n] = L'\0'; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
366 reduce(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
367 } while (prefix[0]); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
368 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
369 /* Look at configure's PREFIX */ |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
370 wcsncpy(prefix, _prefix, MAXPATHLEN); |
|
84785
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
371 prefix[MAXPATHLEN] = L'\0'; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
372 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
373 joinpath(prefix, LANDMARK); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
374 if (ismodule(prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
375 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
376 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
377 /* Fail */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
378 return 0; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
379 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
380 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
381 |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
382 /* 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
|
383 MAXPATHLEN bytes long. |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
384 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
385 static int |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
386 search_for_exec_prefix(wchar_t *argv0_path, wchar_t *home, wchar_t *_exec_prefix) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
387 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
388 size_t n; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
389 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
390 /* 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
|
391 if (home) { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
392 wchar_t *delim; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
393 delim = wcschr(home, DELIM); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
394 if (delim) |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
395 wcsncpy(exec_prefix, delim+1, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
396 else |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
397 wcsncpy(exec_prefix, home, MAXPATHLEN); |
|
84785
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
398 exec_prefix[MAXPATHLEN] = L'\0'; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
399 joinpath(exec_prefix, lib_python); |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
400 joinpath(exec_prefix, L"lib-dynload"); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
401 return 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
402 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
403 |
|
63961
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
404 /* Check to see if argv[0] is in the build directory. "pybuilddir.txt" |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
405 is written by setup.py and contains the relative path to the location |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
406 of shared library modules. */ |
|
84785
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
407 wcsncpy(exec_prefix, argv0_path, MAXPATHLEN); |
|
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
408 exec_prefix[MAXPATHLEN] = L'\0'; |
|
63961
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
409 joinpath(exec_prefix, L"pybuilddir.txt"); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
410 if (isfile(exec_prefix)) { |
|
63961
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
411 FILE *f = _Py_wfopen(exec_prefix, L"rb"); |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
412 if (f == NULL) |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
413 errno = 0; |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
414 else { |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
415 char buf[MAXPATHLEN+1]; |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
416 PyObject *decoded; |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
417 wchar_t rel_builddir_path[MAXPATHLEN+1]; |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
418 n = fread(buf, 1, MAXPATHLEN, f); |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
419 buf[n] = '\0'; |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
420 fclose(f); |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
421 decoded = PyUnicode_DecodeUTF8(buf, n, "surrogateescape"); |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
422 if (decoded != NULL) { |
|
66141
7cec0dd391d6
getpath.c: fix test to detech PyUnicode_AsWideChar() failure
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66096
diff
changeset
|
423 Py_ssize_t k; |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
66141
diff
changeset
|
424 k = PyUnicode_AsWideChar(decoded, |
|
63964
ab6946972b7f
Kill a gcc warning introduced by r83988
Victor Stinner <victor.stinner@haypocalc.com>
parents:
63962
diff
changeset
|
425 rel_builddir_path, MAXPATHLEN); |
|
63961
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
426 Py_DECREF(decoded); |
|
66141
7cec0dd391d6
getpath.c: fix test to detech PyUnicode_AsWideChar() failure
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66096
diff
changeset
|
427 if (k >= 0) { |
|
7cec0dd391d6
getpath.c: fix test to detech PyUnicode_AsWideChar() failure
Victor Stinner <victor.stinner@haypocalc.com>
parents:
66096
diff
changeset
|
428 rel_builddir_path[k] = L'\0'; |
|
84785
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
429 wcsncpy(exec_prefix, argv0_path, MAXPATHLEN); |
|
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
430 exec_prefix[MAXPATHLEN] = L'\0'; |
|
63961
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
431 joinpath(exec_prefix, rel_builddir_path); |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
432 return -1; |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
433 } |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
434 } |
|
4742e7aea2f5
Reimplement addbuilddir() in C inside getpath.c, so as to execute it
Antoine Pitrou <solipsis@pitrou.net>
parents:
63168
diff
changeset
|
435 } |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
436 } |
|
12775
8e2b35d386aa
Patch from M.-A. Lemburg:
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
12576
diff
changeset
|
437 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
438 /* Search from argv0_path, until root is found */ |
|
65312
a27fc0ff3678
_Py_wgetcwd() decodes the path using _Py_char2wchar() to support surrogates
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65169
diff
changeset
|
439 copy_absolute(exec_prefix, argv0_path, MAXPATHLEN+1); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
440 do { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
441 n = wcslen(exec_prefix); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
442 joinpath(exec_prefix, lib_python); |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
443 joinpath(exec_prefix, L"lib-dynload"); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
444 if (isdir(exec_prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
445 return 1; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
446 exec_prefix[n] = L'\0'; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
447 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
448 } 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
|
449 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
450 /* Look at configure's EXEC_PREFIX */ |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
451 wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN); |
|
84785
dca92e8a011a
Issue #15905: Fix theoretical buffer overflow in handling of sys.argv[0],
Christian Heimes <christian@cheimes.de>
parents:
78160
diff
changeset
|
452 exec_prefix[MAXPATHLEN] = L'\0'; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
453 joinpath(exec_prefix, lib_python); |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
454 joinpath(exec_prefix, L"lib-dynload"); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
455 if (isdir(exec_prefix)) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
456 return 1; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
457 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
458 /* Fail */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
459 return 0; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
460 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
461 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
462 static void |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
463 calculate_path(void) |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
464 { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
465 extern wchar_t *Py_GetProgramName(void); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
466 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
467 static wchar_t delimiter[2] = {DELIM, '\0'}; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
468 static wchar_t separator[2] = {SEP, '\0'}; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
469 char *_rtpypath = Py_GETENV("PYTHONPATH"); /* XXX use wide version on Windows */ |
|
70898
f571ed28a9ba
calculate_path() decodes the PYTHONPATH environment variable from the locale
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68662
diff
changeset
|
470 wchar_t *rtpypath = NULL; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
471 wchar_t *home = Py_GetPythonHome(); |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
472 char *_path = getenv("PATH"); |
|
65414
9306ff1c3d46
Oops, fix my previous commit (r85583) on calculate_path()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65413
diff
changeset
|
473 wchar_t *path_buffer = NULL; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
474 wchar_t *path = NULL; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
475 wchar_t *prog = Py_GetProgramName(); |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
476 wchar_t argv0_path[MAXPATHLEN+1]; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
477 wchar_t zip_path[MAXPATHLEN+1]; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
478 int pfound, efound; /* 1 if found; -1 if found build directory */ |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
479 wchar_t *buf; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
480 size_t bufsz; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
481 size_t prefixsz; |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
482 wchar_t *defpath; |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
483 #ifdef WITH_NEXT_FRAMEWORK |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
484 NSModule pythonModule; |
|
78160
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
485 const char* modPath; |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
486 #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
|
487 #ifdef __APPLE__ |
|
36205
01cbed5e8731
squash compiler warning on Mac OSX 10.3
Skip Montanaro <skip@pobox.com>
parents:
35578
diff
changeset
|
488 #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
|
489 uint32_t nsexeclength = MAXPATHLEN; |
|
36205
01cbed5e8731
squash compiler warning on Mac OSX 10.3
Skip Montanaro <skip@pobox.com>
parents:
35578
diff
changeset
|
490 #else |
|
01cbed5e8731
squash compiler warning on Mac OSX 10.3
Skip Montanaro <skip@pobox.com>
parents:
35578
diff
changeset
|
491 unsigned long nsexeclength = MAXPATHLEN; |
|
01cbed5e8731
squash compiler warning on Mac OSX 10.3
Skip Montanaro <skip@pobox.com>
parents:
35578
diff
changeset
|
492 #endif |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
493 char execpath[MAXPATHLEN+1]; |
|
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
|
494 #endif |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
495 wchar_t *_pythonpath, *_prefix, *_exec_prefix; |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
496 |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
497 _pythonpath = _Py_char2wchar(PYTHONPATH, NULL); |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
498 _prefix = _Py_char2wchar(PREFIX, NULL); |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
499 _exec_prefix = _Py_char2wchar(EXEC_PREFIX, NULL); |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
500 |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
501 if (!_pythonpath || !_prefix || !_exec_prefix) { |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
502 Py_FatalError( |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
503 "Unable to decode path variables in getpath.c: " |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
504 "memory error"); |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
505 } |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
506 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
507 if (_path) { |
|
65414
9306ff1c3d46
Oops, fix my previous commit (r85583) on calculate_path()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65413
diff
changeset
|
508 path_buffer = _Py_char2wchar(_path, NULL); |
|
9306ff1c3d46
Oops, fix my previous commit (r85583) on calculate_path()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65413
diff
changeset
|
509 path = path_buffer; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
510 } |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
511 |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
512 /* If there is no slash in the argv0 path, then we have to |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
513 * assume python is on the user's $PATH, since there's no |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
514 * other way to find a directory to start the search from. If |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
515 * $PATH isn't exported, you lose. |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
516 */ |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
517 if (wcschr(prog, SEP)) |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
518 wcsncpy(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
|
519 #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
|
520 /* 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
|
521 * "#!/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
|
522 * 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
|
523 * 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
|
524 * 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
|
525 * 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
|
526 * 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
|
527 * 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
|
528 * 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
|
529 */ |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
530 else if(0 == _NSGetExecutablePath(execpath, &nsexeclength) && execpath[0] == SEP) { |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
531 size_t r = mbstowcs(progpath, execpath, MAXPATHLEN+1); |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
532 if (r == (size_t)-1 || r > MAXPATHLEN) { |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
533 /* Could not convert execpath, or it's too long. */ |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
534 progpath[0] = '\0'; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
535 } |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
536 } |
|
32399
472023d0a10d
Change comment from C++ style to C.
Brett Cannon <bcannon@gmail.com>
parents:
32229
diff
changeset
|
537 #endif /* __APPLE__ */ |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
538 else if (path) { |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
539 while (1) { |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
540 wchar_t *delim = wcschr(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
|
541 |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
542 if (delim) { |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
543 size_t len = delim - path; |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
544 if (len > MAXPATHLEN) |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
545 len = MAXPATHLEN; |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
546 wcsncpy(progpath, path, len); |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
547 *(progpath + len) = '\0'; |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
548 } |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
549 else |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
550 wcsncpy(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
|
551 |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
552 joinpath(progpath, prog); |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
553 if (isxfile(progpath)) |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
554 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
|
555 |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
556 if (!delim) { |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
557 progpath[0] = L'\0'; |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
558 break; |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
559 } |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
560 path = delim + 1; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
561 } |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
562 } |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
563 else |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
564 progpath[0] = '\0'; |
|
84490
18bb92b0c458
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents:
80186
diff
changeset
|
565 PyMem_RawFree(path_buffer); |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
566 if (progpath[0] != SEP && progpath[0] != '\0') |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
567 absolutize(progpath); |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
568 wcsncpy(argv0_path, progpath, MAXPATHLEN); |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
569 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
|
570 |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
571 #ifdef WITH_NEXT_FRAMEWORK |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
572 /* On Mac OS X we have a special case if we're running from a framework. |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
573 ** This is because the python home should be set relative to the library, |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
574 ** which is in the framework, not relative to the executable, which may |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
575 ** be outside of the framework. Except when we're in the build directory... |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
576 */ |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
577 pythonModule = NSModuleForSymbol(NSLookupAndBindSymbol("_Py_Initialize")); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
578 /* Use dylib functions to find out where the framework was loaded from */ |
|
78160
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
579 modPath = NSLibraryNameForModule(pythonModule); |
|
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
580 if (modPath != NULL) { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
581 /* 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
|
582 /* 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
|
583 ** 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
|
584 ** 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
|
585 ** 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
|
586 ** 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
|
587 ** 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
|
588 */ |
|
78160
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
589 wchar_t* wbuf = _Py_char2wchar(modPath, NULL); |
|
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
590 if (wbuf == NULL) { |
|
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
591 Py_FatalError("Cannot decode framework location"); |
|
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
592 } |
|
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
593 |
|
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
594 wcsncpy(argv0_path, wbuf, 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
|
595 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
|
596 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
|
597 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
|
598 if (!ismodule(argv0_path)) { |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
599 /* We are in the build directory so use the name of the |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
600 executable - we know that the absolute path is passed */ |
|
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
601 wcsncpy(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
|
602 } |
|
ca7dbacbbe18
With WITH_NEXT_FRAMEWORK defined we now also expect a normal Python
Jack Jansen <jack.jansen@cwi.nl>
parents:
19061
diff
changeset
|
603 else { |
|
63983
293e332b8b4b
Merged revisions 84008-84009 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
63169
diff
changeset
|
604 /* Use the location of the library as the progpath */ |
|
78160
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
605 wcsncpy(argv0_path, wbuf, 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
|
606 } |
|
84490
18bb92b0c458
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents:
80186
diff
changeset
|
607 PyMem_RawFree(wbuf); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
608 } |
|
9970
8efa37a770c6
Patches by William Lewis for Nextstep descendants.
Guido van Rossum <guido@python.org>
parents:
8203
diff
changeset
|
609 #endif |
|
20156
416f0bc228e8
Be more rigorous about making pathnames absolute, to address SF bug
Guido van Rossum <guido@python.org>
parents:
19261
diff
changeset
|
610 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
611 #if HAVE_READLINK |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
612 { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
613 wchar_t tmpbuffer[MAXPATHLEN+1]; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
614 int linklen = _Py_wreadlink(progpath, tmpbuffer, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
615 while (linklen != -1) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
616 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
|
617 /* 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
|
618 but extra check does not hurt */ |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
619 wcsncpy(argv0_path, tmpbuffer, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
620 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
621 /* Interpret relative to progpath */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
622 reduce(argv0_path); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
623 joinpath(argv0_path, tmpbuffer); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
624 } |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
625 linklen = _Py_wreadlink(argv0_path, tmpbuffer, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
626 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
627 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
628 #endif /* HAVE_READLINK */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
629 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
630 reduce(argv0_path); |
|
14898
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
631 /* 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
|
632 MAXPATHLEN bytes long. |
|
4bea4f59c4e4
Fix buffer overflow vulnerabilities in calculate_path(). Code used
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
14845
diff
changeset
|
633 */ |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
634 |
|
77154
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
635 /* Search for an environment configuration file, first in the |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
636 executable's directory and then in the parent directory. |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
637 If found, open it for use when searching for prefixes. |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
638 */ |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
639 |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
640 { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
641 wchar_t tmpbuffer[MAXPATHLEN+1]; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
642 wchar_t *env_cfg = L"pyvenv.cfg"; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
643 FILE * env_file = NULL; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
644 |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
645 wcscpy(tmpbuffer, argv0_path); |
|
78160
b79d276041a8
Closes #15307: symlinks now work on OS X with framework Python builds. Patch by Ronald Oussoren.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
77154
diff
changeset
|
646 |
|
77154
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
647 joinpath(tmpbuffer, env_cfg); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
648 env_file = _Py_wfopen(tmpbuffer, L"r"); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
649 if (env_file == NULL) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
650 errno = 0; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
651 reduce(tmpbuffer); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
652 reduce(tmpbuffer); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
653 joinpath(tmpbuffer, env_cfg); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
654 env_file = _Py_wfopen(tmpbuffer, L"r"); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
655 if (env_file == NULL) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
656 errno = 0; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
657 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
658 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
659 if (env_file != NULL) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
660 /* Look for a 'home' variable and set argv0_path to it, if found */ |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
661 if (find_env_config_value(env_file, L"home", tmpbuffer)) { |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
662 wcscpy(argv0_path, tmpbuffer); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
663 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
664 fclose(env_file); |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
665 env_file = NULL; |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
666 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
667 } |
|
294f8aeb4d4b
Implemented PEP 405 (Python virtual environments).
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents:
70898
diff
changeset
|
668 |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
669 if (!(pfound = search_for_prefix(argv0_path, home, _prefix))) { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
670 if (!Py_FrozenFlag) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
671 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
|
672 "Could not find platform independent libraries <prefix>\n"); |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
673 wcsncpy(prefix, _prefix, MAXPATHLEN); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
674 joinpath(prefix, lib_python); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
675 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
676 else |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
677 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
|
678 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
679 wcsncpy(zip_path, prefix, MAXPATHLEN); |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
680 zip_path[MAXPATHLEN] = L'\0'; |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
681 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
|
682 reduce(zip_path); |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
683 reduce(zip_path); |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
684 } |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
685 else |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
686 wcsncpy(zip_path, _prefix, MAXPATHLEN); |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
687 joinpath(zip_path, L"lib/python00.zip"); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
688 bufsz = wcslen(zip_path); /* Replace "00" with version */ |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
689 zip_path[bufsz - 6] = VERSION[0]; |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
690 zip_path[bufsz - 5] = VERSION[2]; |
|
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
691 |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
692 if (!(efound = search_for_exec_prefix(argv0_path, home, _exec_prefix))) { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
693 if (!Py_FrozenFlag) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
694 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
|
695 "Could not find platform dependent libraries <exec_prefix>\n"); |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
696 wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN); |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
697 joinpath(exec_prefix, L"lib/lib-dynload"); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
698 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
699 /* 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
|
700 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
701 if ((!pfound || !efound) && !Py_FrozenFlag) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
702 fprintf(stderr, |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
703 "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
|
704 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
705 /* Calculate size of return buffer. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
706 */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
707 bufsz = 0; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
708 |
|
80186
05f8f7544f92
Issue #16309: Make PYTHONPATH= behavior the same as if PYTHONPATH not set at all.
Andrew Svetlov <andrew.svetlov@gmail.com>
parents:
78160
diff
changeset
|
709 if (_rtpypath && _rtpypath[0] != '\0') { |
|
70898
f571ed28a9ba
calculate_path() decodes the PYTHONPATH environment variable from the locale
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68662
diff
changeset
|
710 size_t rtpypath_len; |
|
f571ed28a9ba
calculate_path() decodes the PYTHONPATH environment variable from the locale
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68662
diff
changeset
|
711 rtpypath = _Py_char2wchar(_rtpypath, &rtpypath_len); |
|
f571ed28a9ba
calculate_path() decodes the PYTHONPATH environment variable from the locale
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68662
diff
changeset
|
712 if (rtpypath != NULL) |
|
f571ed28a9ba
calculate_path() decodes the PYTHONPATH environment variable from the locale
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68662
diff
changeset
|
713 bufsz += rtpypath_len + 1; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
714 } |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
715 |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
716 defpath = _pythonpath; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
717 prefixsz = wcslen(prefix) + 1; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
718 while (1) { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
719 wchar_t *delim = wcschr(defpath, DELIM); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
720 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
721 if (defpath[0] != SEP) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
722 /* Paths are relative to prefix */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
723 bufsz += prefixsz; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
724 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
725 if (delim) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
726 bufsz += delim - defpath + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
727 else { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
728 bufsz += wcslen(defpath) + 1; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
729 break; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
730 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
731 defpath = delim + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
732 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
733 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
734 bufsz += wcslen(zip_path) + 1; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
735 bufsz += wcslen(exec_prefix) + 1; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
736 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
737 buf = (wchar_t *)PyMem_Malloc(bufsz*sizeof(wchar_t)); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
738 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
739 if (buf == NULL) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
740 /* 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
|
741 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
|
742 fprintf(stderr, "Using default static PYTHONPATH.\n"); |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
743 module_search_path = L"" PYTHONPATH; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
744 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
745 else { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
746 /* Run-time value of $PYTHONPATH goes first */ |
|
70898
f571ed28a9ba
calculate_path() decodes the PYTHONPATH environment variable from the locale
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68662
diff
changeset
|
747 if (rtpypath) { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
748 wcscpy(buf, rtpypath); |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
749 wcscat(buf, delimiter); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
750 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
751 else |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
752 buf[0] = '\0'; |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
753 |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
754 /* Next is the default zip path */ |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
755 wcscat(buf, zip_path); |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
756 wcscat(buf, delimiter); |
|
26885
54aacb87beda
PEP 302 + zipimport:
Just van Rossum <just@letterror.com>
parents:
26764
diff
changeset
|
757 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
758 /* 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
|
759 * dynamically located prefix. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
760 */ |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
761 defpath = _pythonpath; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
762 while (1) { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
763 wchar_t *delim = wcschr(defpath, DELIM); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
764 |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
765 if (defpath[0] != SEP) { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
766 wcscat(buf, prefix); |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
767 wcscat(buf, separator); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
768 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
769 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
770 if (delim) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
771 size_t len = delim - defpath + 1; |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
772 size_t end = wcslen(buf) + len; |
|
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
773 wcsncat(buf, defpath, len); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
774 *(buf + end) = '\0'; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
775 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
776 else { |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
777 wcscat(buf, defpath); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
778 break; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
779 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
780 defpath = delim + 1; |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
781 } |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
782 wcscat(buf, delimiter); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
783 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
784 /* Finally, on goes the directory for dynamic-load modules */ |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
785 wcscat(buf, exec_prefix); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
786 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
787 /* And publish the results */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
788 module_search_path = buf; |
|
68662
a791dd7d51f3
Issue #10914: fix bogus memory management in Modules/getpath.c, leading to a possible crash when calling Py_SetPath()
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
789 module_search_path_malloced = 1; |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
790 } |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
791 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
792 /* 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
|
793 * 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
|
794 * 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
|
795 * return the compiled-in defaults instead. |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
796 */ |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
797 if (pfound > 0) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
798 reduce(prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
799 reduce(prefix); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
800 /* The prefix is the root directory, but reduce() chopped |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
801 * off the "/". */ |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
802 if (!prefix[0]) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
803 wcscpy(prefix, separator); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
804 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
805 else |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
806 wcsncpy(prefix, _prefix, MAXPATHLEN); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
807 |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
808 if (efound > 0) { |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
809 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
810 reduce(exec_prefix); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
811 reduce(exec_prefix); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
812 if (!exec_prefix[0]) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
59856
diff
changeset
|
813 wcscpy(exec_prefix, separator); |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
814 } |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
815 else |
|
66096
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
816 wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN); |
|
75e02fdbd33e
Issue #6011: decode PREFIX, EXEC_PREFIX and PYTHONPATH variables using
Victor Stinner <victor.stinner@haypocalc.com>
parents:
65600
diff
changeset
|
817 |
|
84490
18bb92b0c458
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents:
80186
diff
changeset
|
818 PyMem_RawFree(_pythonpath); |
|
18bb92b0c458
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents:
80186
diff
changeset
|
819 PyMem_RawFree(_prefix); |
|
18bb92b0c458
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents:
80186
diff
changeset
|
820 PyMem_RawFree(_exec_prefix); |
|
18bb92b0c458
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents:
80186
diff
changeset
|
821 PyMem_RawFree(rtpypath); |
|
5300
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
822 } |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
823 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
824 |
|
e77942562dd3
Completely revamped the way the default path is constructed.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
825 /* External interface */ |
|
64955
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
826 void |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
827 Py_SetPath(const wchar_t *path) |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
828 { |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
829 if (module_search_path != NULL) { |
|
68662
a791dd7d51f3
Issue #10914: fix bogus memory management in Modules/getpath.c, leading to a possible crash when calling Py_SetPath()
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
830 if (module_search_path_malloced) |
|
84490
18bb92b0c458
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents:
80186
diff
changeset
|
831 PyMem_RawFree(module_search_path); |
|
64955
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
832 module_search_path = NULL; |
|
68662
a791dd7d51f3
Issue #10914: fix bogus memory management in Modules/getpath.c, leading to a possible crash when calling Py_SetPath()
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
833 module_search_path_malloced = 0; |
|
64955
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
834 } |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
835 if (path != NULL) { |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
836 extern wchar_t *Py_GetProgramName(void); |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
837 wchar_t *prog = Py_GetProgramName(); |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
838 wcsncpy(progpath, prog, MAXPATHLEN); |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
839 exec_prefix[0] = prefix[0] = L'\0'; |
|
84490
18bb92b0c458
Issue #18203: Replace malloc() with PyMem_RawMalloc() at Python initialization
Victor Stinner <victor.stinner@gmail.com>
parents:
80186
diff
changeset
|
840 module_search_path = PyMem_RawMalloc((wcslen(path) + 1) * sizeof(wchar_t)); |
|
68662
a791dd7d51f3
Issue #10914: fix bogus memory management in Modules/getpath.c, leading to a possible crash when calling Py_SetPath()
Antoine Pitrou <solipsis@pitrou.net>
parents:
68257
diff
changeset
|
841 module_search_path_malloced = 1; |
|
64955
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
842 if (module_search_path != NULL) |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
843 wcscpy(module_search_path, path); |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
844 } |
|
fd5e51035335
issue 9910
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents:
63982
diff
changeset
|
845 } |
| 2896 | 846 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
847 wchar_t * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
848 Py_GetPath(void) |
| 2896 | 849 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
850 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
851 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
852 return module_search_path; |
| 2896 | 853 } |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
854 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
855 wchar_t * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
856 Py_GetPrefix(void) |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
857 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
858 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
859 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
860 return prefix; |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
861 } |
|
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
862 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
863 wchar_t * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
864 Py_GetExecPrefix(void) |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
865 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
866 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
867 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
868 return exec_prefix; |
|
3674
3eaf2c673a11
provide access to $(exec_)prefix
Guido van Rossum <guido@python.org>
parents:
3621
diff
changeset
|
869 } |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
870 |
|
46318
22a74eaf6b22
Change command line processing API to use wchar_t.
Martin v. Löwis <martin@v.loewis.de>
parents:
41554
diff
changeset
|
871 wchar_t * |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13620
diff
changeset
|
872 Py_GetProgramFullPath(void) |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
873 { |
|
13428
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
874 if (!module_search_path) |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
875 calculate_path(); |
|
0d6af303a86c
ANSI-fied sources, converted to four-space indentation.
Fred Drake <fdrake@acm.org>
parents:
13256
diff
changeset
|
876 return progpath; |
|
5568
139ab21d2629
Make delimiter and separator static for K&R C.
Guido van Rossum <guido@python.org>
parents:
5500
diff
changeset
|
877 } |
|
37879
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
878 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
879 |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
880 #ifdef __cplusplus |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
881 } |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
882 #endif |
|
f731859e9b3b
Merge p3yk branch with the trunk up to revision 45595. This breaks a fair
Thomas Wouters <thomas@python.org>
parents:
36623
diff
changeset
|
883 |
