Mercurial > cpython-lru_cache-weakref
annotate PC/getpath_nt.c @ 4566:6403c94de50d legacy-trunk
Added safeguard against failure in __del__.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 27 Nov 1996 19:39:58 +0000 |
| parents | 2eacd2c8eabf |
| children | 217cfb6199be |
| rev | line source |
|---|---|
|
4087
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 #include "Python.h" |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 #include "osdefs.h" |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 #include <windows.h> |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 /* PREFIX and EXEC_PREFIX are meaningless on Windows */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 #ifndef PREFIX |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 #define PREFIX "" |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 #endif |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 #ifndef EXEC_PREFIX |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 #define EXEC_PREFIX "" |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 #endif |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 /* |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 This is a special Win32 version of getpath. |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 * There is no default path. There is nothing even remotely resembling |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 a standard location. Maybe later "Program Files/Python", but not yet. |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 * The Registry is used as the primary store for the Python path. |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 * The environment variable PYTHONPATH _overrides_ the registry. This should |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 allow a "standard" Python environment, but allow you to manually setup |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 another (eg, a beta version). |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 BOOL PyWin_IsWin32s() |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 static BOOL bIsWin32s = -1; // flag as "not yet looked" |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 if (bIsWin32s==-1) { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
34 OSVERSIONINFO ver; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 ver.dwOSVersionInfoSize = sizeof(ver); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
36 GetVersionEx(&ver); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 bIsWin32s = ver.dwPlatformId == VER_PLATFORM_WIN32s; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 return bIsWin32s; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 /* Load a PYTHONPATH value from the registry |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 Load from either HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 Returns NULL, or a pointer that should be free'd. |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 static char * |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 getpythonregpath(HKEY keyBase, BOOL bWin32s) |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 HKEY newKey = 0; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
51 DWORD nameSize = 0; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
52 DWORD dataSize = 0; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
53 DWORD numEntries = 0; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
54 LONG rc; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
55 char *retval = NULL; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
56 char *dataBuf; |
|
4127
a7a9d83505c4
Use MS_DLL_ID and similar changes
Guido van Rossum <guido@python.org>
parents:
4105
diff
changeset
|
57 if ((rc=RegOpenKey(keyBase, "Software\\Python\\PythonCore\\" MS_DLL_ID "\\PythonPath", |
|
4087
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 &newKey))==ERROR_SUCCESS) { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
59 RegQueryInfoKey(newKey, NULL, NULL, NULL, NULL, NULL, NULL, |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 &numEntries, &nameSize, &dataSize, NULL, NULL ); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
61 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
62 if (bWin32s && numEntries==0 && dataSize==0) { /* must hardcode for Win32s */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
63 numEntries = 1; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
64 dataSize = 511; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
66 if (numEntries) { |
|
4419
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
67 /* Loop over all subkeys. */ |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
68 /* Win32s doesnt know how many subkeys, so we do |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
69 it twice */ |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
70 char keyBuf[MAX_PATH+1]; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
71 int index = 0; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
72 int off = 0; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
73 for(index=0;;index++) { |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
74 long reqdSize = 0; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
75 DWORD rc = RegEnumKey(newKey, index, keyBuf,MAX_PATH+1); |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
76 if (rc) break; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
77 rc = RegQueryValue(newKey, keyBuf, NULL, &reqdSize); |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
78 if (rc) break; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
79 if (bWin32s && reqdSize==0) reqdSize = 512; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
80 dataSize += reqdSize + 1; /* 1 for the ";" */ |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
81 } |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
82 dataBuf = malloc(dataSize+1); |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
83 if (dataBuf==NULL) return NULL; /* pretty serious? Raise error? */ |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
84 /* Now loop over, grabbing the paths. Subkeys before main library */ |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
85 for(index=0;;index++) { |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
86 int adjust; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
87 long reqdSize = dataSize; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
88 DWORD rc = RegEnumKey(newKey, index, keyBuf,MAX_PATH+1); |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
89 if (rc) break; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
90 rc = RegQueryValue(newKey, keyBuf, dataBuf+off, &reqdSize); |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
91 if (rc) break; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
92 adjust = strlen(dataBuf+off); |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
93 dataSize -= adjust; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
94 off += adjust; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
95 dataBuf[off++] = ';'; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
96 dataBuf[off] = '\0'; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
97 dataSize--; |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
98 } |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
99 /* Additionally, win32s doesnt work as expected, so |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
100 the specific strlen() is required for 3.1. */ |
|
2eacd2c8eabf
From: "Mark Hammond" <MHammond@skippinet.com.au>
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
101 rc = RegQueryValue(newKey, "", dataBuf+off, &dataSize); |
|
4087
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 if (rc==ERROR_SUCCESS) { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 if (strlen(dataBuf)==0) |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
104 free(dataBuf); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
105 else |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 retval = dataBuf; // caller will free |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
107 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 else |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
109 free(dataBuf); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
110 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
111 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 if (newKey) |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
113 CloseHandle(newKey); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 return retval; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 /* Return the initial python search path. This is called once from |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
117 initsys() to initialize sys.path. The environment variable |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 PYTHONPATH is fetched and the default path appended. The default |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 path may be passed to the preprocessor; if not, a system-dependent |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 default is used. */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 char * |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
123 Py_GetPath() |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
125 char *path = getenv("PYTHONPATH"); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
126 char *defpath = PYTHONPATH; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
127 static char *buf = NULL; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
128 char *p; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
129 int n; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
130 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
131 if (buf != NULL) { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
132 free(buf); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 buf = NULL; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
134 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
135 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
136 if (path == NULL) { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
137 char *machinePath, *userPath; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
138 int machineLen, userLen; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
139 /* lookup the registry */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 BOOL bWin32s = PyWin_IsWin32s(); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
141 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 if (bWin32s) { /* are we running under Windows 3.1 Win32s */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 /* only CLASSES_ROOT is supported */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
144 machinePath = getpythonregpath(HKEY_CLASSES_ROOT, TRUE); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 userPath = NULL; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 } else { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
147 machinePath = getpythonregpath(HKEY_LOCAL_MACHINE, FALSE); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
148 userPath = getpythonregpath(HKEY_CURRENT_USER, FALSE); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 if (machinePath==NULL && userPath==NULL) return defpath; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
151 machineLen = machinePath ? strlen(machinePath) : 0; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 userLen = userPath ? strlen(userPath) : 0; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
153 n = machineLen + userLen + 1; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
154 // this is a memory leak, as Python never frees it. Only ever called once, so big deal! |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
155 buf = malloc(n); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
156 if (buf == NULL) |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 Py_FatalError("not enough memory to copy module search path"); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 p = buf; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 *p = '\0'; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
160 if (machineLen) { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
161 strcpy(p, machinePath); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
162 p += machineLen; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
163 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 if (userLen) { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 if (machineLen) |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
166 *p++ = DELIM; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 strcpy(p, userPath); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 if (userPath) free(userPath); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
170 if (machinePath) free(machinePath); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 } else { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
172 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 buf = malloc(strlen(path)+1); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
174 if (buf == NULL) |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 Py_FatalError("not enough memory to copy module search path"); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 strcpy(buf, path); |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 return buf; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
180 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 /* Similar for Makefile variables $prefix and $exec_prefix */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 char * |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 Py_GetPrefix() |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 return PREFIX; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 } |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 char * |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 Py_GetExecPrefix() |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 { |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 return EXEC_PREFIX; |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 } |
