Mercurial > cpython-lru_cache-weakref
annotate Python/dynload_win.c @ 87690:66c1c9f32567 default tip
Add use_weakref option to functools.lru_cache
The use_weakref option makes lru_cache create weak references to the function
arguments when creating the cache key, which prevents them from staying in the
memory forever even after all other references to them are gone.
This is a proof of concept for http://bugs.python.org/issue19859
| author | Radomir Dopieralski <devel@sheep.art.pl> |
|---|---|
| date | Tue, 03 Dec 2013 16:02:48 +0100 |
| parents | ec854f76d6b9 |
| children |
| rev | line source |
|---|---|
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 /* Support for dynamic loading of extension modules */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 |
|
44535
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44443
diff
changeset
|
4 #include "Python.h" |
|
420fe6d7d5f4
Merged revisions 59703-59773 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44443
diff
changeset
|
5 |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
37459
diff
changeset
|
6 #ifdef HAVE_DIRECT_H |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 #include <direct.h> |
|
38716
42808526511c
Patch #1495999: Part two of Windows CE changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
37459
diff
changeset
|
8 #endif |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
9 #include <ctype.h> |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 #include "importdl.h" |
|
41969
9d02a4adf574
Merged revisions 55631-55794 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41554
diff
changeset
|
12 #include <windows.h> |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
51130
0522cfee879a
Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents:
47584
diff
changeset
|
14 // "activation context" magic - see dl_nt.c... |
|
76898
38d7d944370e
Fix #13210. Port the Windows build from VS2008 to VS2010.
Brian Curtin <brian@python.org>
parents:
76754
diff
changeset
|
15 #if HAVE_SXS |
|
51130
0522cfee879a
Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents:
47584
diff
changeset
|
16 extern ULONG_PTR _Py_ActivateActCtx(); |
|
0522cfee879a
Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents:
47584
diff
changeset
|
17 void _Py_DeactivateActCtx(ULONG_PTR cookie); |
|
76898
38d7d944370e
Fix #13210. Port the Windows build from VS2008 to VS2010.
Brian Curtin <brian@python.org>
parents:
76754
diff
changeset
|
18 #endif |
|
51130
0522cfee879a
Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents:
47584
diff
changeset
|
19 |
|
76754
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76379
diff
changeset
|
20 const char *_PyImport_DynLoadFiletab[] = { |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 #ifdef _DEBUG |
|
76754
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76379
diff
changeset
|
22 "_d.pyd", |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 #else |
|
76754
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76379
diff
changeset
|
24 ".pyd", |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 #endif |
|
76754
257cbd2fac38
Issue #13959: Re-implement imp.get_suffixes() in Lib/imp.py.
Brett Cannon <brett@python.org>
parents:
76379
diff
changeset
|
26 NULL |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 }; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
30 /* Case insensitive string compare, to avoid any dependencies on particular |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
31 C RTL implementations */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
32 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
33 static int strcasecmp (char *string1, char *string2) |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
34 { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
35 int first, second; |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
36 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
37 do { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
38 first = tolower(*string1); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
39 second = tolower(*string2); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
40 string1++; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
41 string2++; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
42 } while (first && first == second); |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
43 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
44 return (first - second); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
45 } |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
46 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
47 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
48 /* Function to return the name of the "python" DLL that the supplied module |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
49 directly imports. Looks through the list of imported modules and |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
50 returns the first entry that starts with "python" (case sensitive) and |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
51 is followed by nothing but numbers until the separator (period). |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
52 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
53 Returns a pointer to the import name, or NULL if no matching name was |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
54 located. |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
55 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
56 This function parses through the PE header for the module as loaded in |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
57 memory by the system loader. The PE header is accessed as documented by |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
58 Microsoft in the MSDN PE and COFF specification (2/99), and handles |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
59 both PE32 and PE32+. It only worries about the direct import table and |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
60 not the delay load import table since it's unlikely an extension is |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
61 going to be delay loading Python (after all, it's already loaded). |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
62 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
63 If any magic values are not found (e.g., the PE header or optional |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
64 header magic), then this function simply returns NULL. */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
65 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
66 #define DWORD_AT(mem) (*(DWORD *)(mem)) |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
67 #define WORD_AT(mem) (*(WORD *)(mem)) |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
68 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
69 static char *GetPythonImport (HINSTANCE hModule) |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
70 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
71 unsigned char *dllbase, *import_data, *import_name; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
72 DWORD pe_offset, opt_offset; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
73 WORD opt_magic; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
74 int num_dict_off, import_off; |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
75 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
76 /* Safety check input */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
77 if (hModule == NULL) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
78 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
79 } |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
80 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
81 /* Module instance is also the base load address. First portion of |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
82 memory is the MS-DOS loader, which holds the offset to the PE |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
83 header (from the load base) at 0x3C */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
84 dllbase = (unsigned char *)hModule; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
85 pe_offset = DWORD_AT(dllbase + 0x3C); |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
86 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
87 /* The PE signature must be "PE\0\0" */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
88 if (memcmp(dllbase+pe_offset,"PE\0\0",4)) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
89 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
90 } |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
91 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
92 /* Following the PE signature is the standard COFF header (20 |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
93 bytes) and then the optional header. The optional header starts |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
94 with a magic value of 0x10B for PE32 or 0x20B for PE32+ (PE32+ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
95 uses 64-bits for some fields). It might also be 0x107 for a ROM |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
96 image, but we don't process that here. |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
97 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
98 The optional header ends with a data dictionary that directly |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
99 points to certain types of data, among them the import entries |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
100 (in the second table entry). Based on the header type, we |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
101 determine offsets for the data dictionary count and the entry |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
102 within the dictionary pointing to the imports. */ |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
103 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
104 opt_offset = pe_offset + 4 + 20; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
105 opt_magic = WORD_AT(dllbase+opt_offset); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
106 if (opt_magic == 0x10B) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
107 /* PE32 */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
108 num_dict_off = 92; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
109 import_off = 104; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
110 } else if (opt_magic == 0x20B) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
111 /* PE32+ */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
112 num_dict_off = 108; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
113 import_off = 120; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
114 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
115 /* Unsupported */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
116 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
117 } |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
118 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
119 /* Now if an import table exists, offset to it and walk the list of |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
120 imports. The import table is an array (ending when an entry has |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
121 empty values) of structures (20 bytes each), which contains (at |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
122 offset 12) a relative address (to the module base) at which a |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
123 string constant holding the import name is located. */ |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
124 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
125 if (DWORD_AT(dllbase + opt_offset + num_dict_off) >= 2) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
126 /* We have at least 2 tables - the import table is the second |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
127 one. But still it may be that the table size is zero */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
128 if (0 == DWORD_AT(dllbase + opt_offset + import_off + sizeof(DWORD))) |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
129 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
130 import_data = dllbase + DWORD_AT(dllbase + |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
131 opt_offset + |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
132 import_off); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
133 while (DWORD_AT(import_data)) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
134 import_name = dllbase + DWORD_AT(import_data+12); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
135 if (strlen(import_name) >= 6 && |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
136 !strncmp(import_name,"python",6)) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
137 char *pch; |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
138 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
139 #ifndef _DEBUG |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
140 /* In a release version, don't claim that python3.dll is |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
141 a Python DLL. */ |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
142 if (strcmp(import_name, "python3.dll") == 0) { |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
143 import_data += 20; |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
144 continue; |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
145 } |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
146 #endif |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
147 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
148 /* Ensure python prefix is followed only |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
149 by numbers to the end of the basename */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
150 pch = import_name + 6; |
|
32469
b8710e6d8d78
When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents:
25041
diff
changeset
|
151 #ifdef _DEBUG |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
152 while (*pch && pch[0] != '_' && pch[1] != 'd' && pch[2] != '.') { |
|
32469
b8710e6d8d78
When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents:
25041
diff
changeset
|
153 #else |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
154 while (*pch && *pch != '.') { |
|
32469
b8710e6d8d78
When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents:
25041
diff
changeset
|
155 #endif |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
156 if (*pch >= '0' && *pch <= '9') { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
157 pch++; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
158 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
159 pch = NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
160 break; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
161 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
162 } |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
163 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
164 if (pch) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
165 /* Found it - return the name */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
166 return import_name; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
167 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
168 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
169 import_data += 20; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
170 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
171 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
172 |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
173 return NULL; |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
174 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
175 |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
176 dl_funcptr _PyImport_GetDynLoadWindows(const char *shortname, |
|
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
177 PyObject *pathname, FILE *fp) |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
178 { |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
179 dl_funcptr p; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
180 char funcname[258], *import_python; |
|
73650
071cc767a28e
Check for PyUnicode_AS_UNICODE() failure
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72592
diff
changeset
|
181 wchar_t *wpathname; |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
182 |
|
66664
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
183 #ifndef _DEBUG |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
184 _Py_CheckPython3(); |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
185 #endif |
|
62b61abd02b8
Merge branches/pep-0384.
Martin v. Löwis <martin@v.loewis.de>
parents:
61466
diff
changeset
|
186 |
|
73650
071cc767a28e
Check for PyUnicode_AS_UNICODE() failure
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72592
diff
changeset
|
187 wpathname = PyUnicode_AsUnicode(pathname); |
|
071cc767a28e
Check for PyUnicode_AS_UNICODE() failure
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72592
diff
changeset
|
188 if (wpathname == NULL) |
|
071cc767a28e
Check for PyUnicode_AS_UNICODE() failure
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72592
diff
changeset
|
189 return NULL; |
|
071cc767a28e
Check for PyUnicode_AS_UNICODE() failure
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72592
diff
changeset
|
190 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
191 PyOS_snprintf(funcname, sizeof(funcname), "PyInit_%.200s", shortname); |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
193 { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
194 HINSTANCE hDLL = NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
195 unsigned int old_mode; |
|
76898
38d7d944370e
Fix #13210. Port the Windows build from VS2008 to VS2010.
Brian Curtin <brian@python.org>
parents:
76754
diff
changeset
|
196 #if HAVE_SXS |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
197 ULONG_PTR cookie = 0; |
|
76898
38d7d944370e
Fix #13210. Port the Windows build from VS2008 to VS2010.
Brian Curtin <brian@python.org>
parents:
76754
diff
changeset
|
198 #endif |
|
72592
8d29cdf28216
Check error when calling PyUnicode_AppendAndDel()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
70749
diff
changeset
|
199 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
200 /* Don't display a message box when Python can't load a DLL */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
201 old_mode = SetErrorMode(SEM_FAILCRITICALERRORS); |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
202 |
|
76898
38d7d944370e
Fix #13210. Port the Windows build from VS2008 to VS2010.
Brian Curtin <brian@python.org>
parents:
76754
diff
changeset
|
203 #if HAVE_SXS |
|
70749
f8aacfd3b070
Removed a Windows 9x trick used before LoadLibraryExW.
Brian Curtin <brian@python.org>
parents:
69145
diff
changeset
|
204 cookie = _Py_ActivateActCtx(); |
|
76898
38d7d944370e
Fix #13210. Port the Windows build from VS2008 to VS2010.
Brian Curtin <brian@python.org>
parents:
76754
diff
changeset
|
205 #endif |
|
70749
f8aacfd3b070
Removed a Windows 9x trick used before LoadLibraryExW.
Brian Curtin <brian@python.org>
parents:
69145
diff
changeset
|
206 /* We use LoadLibraryEx so Windows looks for dependent DLLs |
|
f8aacfd3b070
Removed a Windows 9x trick used before LoadLibraryExW.
Brian Curtin <brian@python.org>
parents:
69145
diff
changeset
|
207 in directory of pathname first. */ |
|
f8aacfd3b070
Removed a Windows 9x trick used before LoadLibraryExW.
Brian Curtin <brian@python.org>
parents:
69145
diff
changeset
|
208 /* XXX This call doesn't exist in Windows CE */ |
|
73650
071cc767a28e
Check for PyUnicode_AS_UNICODE() failure
Victor Stinner <victor.stinner@haypocalc.com>
parents:
72592
diff
changeset
|
209 hDLL = LoadLibraryExW(wpathname, NULL, |
|
70749
f8aacfd3b070
Removed a Windows 9x trick used before LoadLibraryExW.
Brian Curtin <brian@python.org>
parents:
69145
diff
changeset
|
210 LOAD_WITH_ALTERED_SEARCH_PATH); |
|
76898
38d7d944370e
Fix #13210. Port the Windows build from VS2008 to VS2010.
Brian Curtin <brian@python.org>
parents:
76754
diff
changeset
|
211 #if HAVE_SXS |
|
70749
f8aacfd3b070
Removed a Windows 9x trick used before LoadLibraryExW.
Brian Curtin <brian@python.org>
parents:
69145
diff
changeset
|
212 _Py_DeactivateActCtx(cookie); |
|
76898
38d7d944370e
Fix #13210. Port the Windows build from VS2008 to VS2010.
Brian Curtin <brian@python.org>
parents:
76754
diff
changeset
|
213 #endif |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
214 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
215 /* restore old error mode settings */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
216 SetErrorMode(old_mode); |
|
44905
c0f048356c36
Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44535
diff
changeset
|
217 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
218 if (hDLL==NULL){ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
219 PyObject *message; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
220 unsigned int errorCode; |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
222 /* Get an error string from Win32 error code */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
223 wchar_t theInfo[256]; /* Pointer to error text |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
224 from system */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
225 int theLength; /* Length of error text */ |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
226 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
227 errorCode = GetLastError(); |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
229 theLength = FormatMessageW( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
230 FORMAT_MESSAGE_FROM_SYSTEM | |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
231 FORMAT_MESSAGE_IGNORE_INSERTS, /* flags */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
232 NULL, /* message source */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
233 errorCode, /* the message (error) ID */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
234 MAKELANGID(LANG_NEUTRAL, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
235 SUBLANG_DEFAULT), |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
236 /* Default language */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
237 theInfo, /* the buffer */ |
|
82936
4db1b0bb3683
Fixes issue4653 - Correctly specify the buffer size to FormatMessageW and
Gregory P. Smith <greg@krypto.org>
parents:
76898
diff
changeset
|
238 sizeof(theInfo) / sizeof(wchar_t), /* size in wchars */ |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
239 NULL); /* no additional format args. */ |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
240 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
241 /* Problem: could not get the error message. |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
242 This should not happen if called correctly. */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
243 if (theLength == 0) { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
244 message = PyUnicode_FromFormat( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
245 "DLL load failed with error code %d", |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
246 errorCode); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
247 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
248 /* For some reason a \r\n |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
249 is appended to the text */ |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
250 if (theLength >= 2 && |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
251 theInfo[theLength-2] == '\r' && |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
252 theInfo[theLength-1] == '\n') { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
253 theLength -= 2; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
254 theInfo[theLength] = '\0'; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
255 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
256 message = PyUnicode_FromString( |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
257 "DLL load failed: "); |
|
44443
c73210ea61c8
On Windows, when import fails to load a dll module, the message says
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
41969
diff
changeset
|
258 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
259 PyUnicode_AppendAndDel(&message, |
|
73683
d48b4a1c511a
Use the new Unicode API
Victor Stinner <victor.stinner@haypocalc.com>
parents:
73650
diff
changeset
|
260 PyUnicode_FromWideChar( |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
261 theInfo, |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
262 theLength)); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
263 } |
|
72592
8d29cdf28216
Check error when calling PyUnicode_AppendAndDel()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
70749
diff
changeset
|
264 if (message != NULL) { |
|
84078
ec854f76d6b9
Issue #18180: Fix ref leak in _PyImport_GetDynLoadWindows().
Richard Oudkerk <shibturn@gmail.com>
parents:
82936
diff
changeset
|
265 PyObject *shortname_obj = PyUnicode_FromString(shortname); |
|
ec854f76d6b9
Issue #18180: Fix ref leak in _PyImport_GetDynLoadWindows().
Richard Oudkerk <shibturn@gmail.com>
parents:
82936
diff
changeset
|
266 PyErr_SetImportError(message, shortname_obj, pathname); |
|
ec854f76d6b9
Issue #18180: Fix ref leak in _PyImport_GetDynLoadWindows().
Richard Oudkerk <shibturn@gmail.com>
parents:
82936
diff
changeset
|
267 Py_XDECREF(shortname_obj); |
|
76379
7a32b9380ffd
Fix #14600. Correct reference handling and naming of ImportError convenience function
Brian Curtin <brian@python.org>
parents:
76344
diff
changeset
|
268 Py_DECREF(message); |
|
72592
8d29cdf28216
Check error when calling PyUnicode_AppendAndDel()
Victor Stinner <victor.stinner@haypocalc.com>
parents:
70749
diff
changeset
|
269 } |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
270 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
271 } else { |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
272 char buffer[256]; |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
273 |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
274 PyOS_snprintf(buffer, sizeof(buffer), |
|
32469
b8710e6d8d78
When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents:
25041
diff
changeset
|
275 #ifdef _DEBUG |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
276 "python%d%d_d.dll", |
|
32469
b8710e6d8d78
When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents:
25041
diff
changeset
|
277 #else |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
278 "python%d%d.dll", |
|
32469
b8710e6d8d78
When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents:
25041
diff
changeset
|
279 #endif |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
280 PY_MAJOR_VERSION,PY_MINOR_VERSION); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
281 import_python = GetPythonImport(hDLL); |
|
15027
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
282 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
283 if (import_python && |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
284 strcasecmp(buffer,import_python)) { |
|
69145
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
285 PyErr_Format(PyExc_ImportError, |
|
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
286 "Module use of %.150s conflicts " |
|
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
287 "with this version of Python.", |
|
1b7f484bab6e
Issue #11619: _PyImport_LoadDynamicModule() doesn't encode the path to bytes
Victor Stinner <victor.stinner@haypocalc.com>
parents:
68108
diff
changeset
|
288 import_python); |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
289 FreeLibrary(hDLL); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
290 return NULL; |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
291 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
292 } |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
293 p = GetProcAddress(hDLL, funcname); |
|
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
294 } |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
295 |
|
61466
cab14be0ada1
Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
51130
diff
changeset
|
296 return p; |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
297 } |
