Mercurial > cpython-lru_cache-weakref
annotate PC/import_nt.c @ 79675:c0a2294de787 2.7
Issue #16199: Backport 2to3 typo fix from 3.2.
| author | Chris Jerdonek <chris.jerdonek@gmail.com> |
|---|---|
| date | Thu, 11 Oct 2012 16:15:46 -0700 |
| parents | fd25030223b0 |
| children | 2f89cbbec0b4 |
| rev | line source |
|---|---|
|
4087
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 /******************************************************************** |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
3 import_nt.c |
|
4087
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 Win32 specific import code. |
|
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 */ |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
5406
c2254754192c
Include Python.h, not allobjects.h (which no longer exists).
Guido van Rossum <guido@python.org>
parents:
4127
diff
changeset
|
9 #include "Python.h" |
|
4087
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 #include "osdefs.h" |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 #include <windows.h> |
|
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 #include "importdl.h" |
|
13332
5626d4255fce
Squash signed-vs-unsigned warning. Also edits to bring into line
Tim Peters <tim.peters@gmail.com>
parents:
13101
diff
changeset
|
13 #include "malloc.h" /* for alloca */ |
|
5626d4255fce
Squash signed-vs-unsigned warning. Also edits to bring into line
Tim Peters <tim.peters@gmail.com>
parents:
13101
diff
changeset
|
14 |
|
5626d4255fce
Squash signed-vs-unsigned warning. Also edits to bring into line
Tim Peters <tim.peters@gmail.com>
parents:
13101
diff
changeset
|
15 /* a string loaded from the DLL at startup */ |
|
5626d4255fce
Squash signed-vs-unsigned warning. Also edits to bring into line
Tim Peters <tim.peters@gmail.com>
parents:
13101
diff
changeset
|
16 extern const char *PyWin_DLLVersionString; |
|
6356
a857d2f87336
Seem to be some changes related to DLL version from string resource,
Guido van Rossum <guido@python.org>
parents:
5998
diff
changeset
|
17 |
|
13332
5626d4255fce
Squash signed-vs-unsigned warning. Also edits to bring into line
Tim Peters <tim.peters@gmail.com>
parents:
13101
diff
changeset
|
18 FILE *PyWin_FindRegisteredModule(const char *moduleName, |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
19 struct filedescr **ppFileDesc, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
20 char *pathBuf, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
21 Py_ssize_t pathLen) |
|
4087
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 { |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
23 char *moduleKey; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
24 const char keyPrefix[] = "Software\\Python\\PythonCore\\"; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
25 const char keySuffix[] = "\\Modules\\"; |
| 8421 | 26 #ifdef _DEBUG |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
27 /* In debugging builds, we _must_ have the debug version |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
28 * registered. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
29 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
30 const char debugString[] = "\\Debug"; |
| 8421 | 31 #else |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
32 const char debugString[] = ""; |
| 8421 | 33 #endif |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
34 struct filedescr *fdp = NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
35 FILE *fp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
36 HKEY keyBase = HKEY_CURRENT_USER; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
37 int modNameSize; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
38 long regStat; |
|
6356
a857d2f87336
Seem to be some changes related to DLL version from string resource,
Guido van Rossum <guido@python.org>
parents:
5998
diff
changeset
|
39 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
40 /* Calculate the size for the sprintf buffer. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
41 * Get the size of the chars only, plus 1 NULL. |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
42 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
43 size_t bufSize = sizeof(keyPrefix)-1 + |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
44 strlen(PyWin_DLLVersionString) + |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
45 sizeof(keySuffix) + |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
46 strlen(moduleName) + |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
47 sizeof(debugString) - 1; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
48 /* alloca == no free required, but memory only local to fn, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
49 * also no heap fragmentation! |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
50 */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
51 moduleKey = alloca(bufSize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
52 PyOS_snprintf(moduleKey, bufSize, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
53 "Software\\Python\\PythonCore\\%s\\Modules\\%s%s", |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
54 PyWin_DLLVersionString, moduleName, debugString); |
|
6356
a857d2f87336
Seem to be some changes related to DLL version from string resource,
Guido van Rossum <guido@python.org>
parents:
5998
diff
changeset
|
55 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
56 assert(pathLen < INT_MAX); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
57 modNameSize = (int)pathLen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
58 regStat = RegQueryValue(keyBase, moduleKey, pathBuf, &modNameSize); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
59 if (regStat != ERROR_SUCCESS) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
60 /* No user setting - lookup in machine settings */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
61 keyBase = HKEY_LOCAL_MACHINE; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
62 /* be anal - failure may have reset size param */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
63 modNameSize = (int)pathLen; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
64 regStat = RegQueryValue(keyBase, moduleKey, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
65 pathBuf, &modNameSize); |
|
14119
f6338d74dca1
Registered modules could only exist in HKEY_LOCAL_MACHINE - now HKEY_CURRENT_USER can override.
Mark Hammond <mhammond@skippinet.com.au>
parents:
13332
diff
changeset
|
66 |
|
61463
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
67 if (regStat != ERROR_SUCCESS) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
68 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
69 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
70 /* use the file extension to locate the type entry. */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
71 for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) { |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
72 size_t extLen = strlen(fdp->suffix); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
73 assert(modNameSize >= 0); /* else cast to size_t is wrong */ |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
74 if ((size_t)modNameSize > extLen && |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
75 strnicmp(pathBuf + ((size_t)modNameSize-extLen-1), |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
76 fdp->suffix, |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
77 extLen) == 0) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
78 break; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
79 } |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
80 if (fdp->suffix == NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
81 return NULL; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
82 fp = fopen(pathBuf, fdp->mode); |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
83 if (fp != NULL) |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
84 *ppFileDesc = fdp; |
|
fd25030223b0
Untabify C files. Will watch buildbots.
Antoine Pitrou <solipsis@pitrou.net>
parents:
36501
diff
changeset
|
85 return fp; |
|
4087
740def697d8b
NT specific files supplied by Mark Hammond
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 } |
