Mercurial > cpython-lru_cache-weakref
annotate Python/dynload_win.c @ 20737:00a581bdedeb legacy-trunk
When overriding __str__ or __repr__, set the tp_print slot to NULL.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 29 Oct 2001 14:33:44 +0000 |
| parents | 5e3bab8aef7b |
| children | 225c7dd17e37 |
| 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 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 #include <windows.h> |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 #include <direct.h> |
|
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
|
6 #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
|
7 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 #include "Python.h" |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 #include "importdl.h" |
|
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 const struct filedescr _PyImport_DynLoadFiletab[] = { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 #ifdef _DEBUG |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 {"_d.pyd", "rb", C_EXTENSION}, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 {"_d.dll", "rb", C_EXTENSION}, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 #else |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 {".pyd", "rb", C_EXTENSION}, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 {".dll", "rb", C_EXTENSION}, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 #endif |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 {0, 0} |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 }; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 |
|
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
|
23 #ifdef MS_WIN32 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
24 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
25 /* 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
|
26 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
|
27 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
28 static int strcasecmp (char *string1, char *string2) |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
29 { |
|
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 int first, second; |
|
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 |
|
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 do { |
|
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 first = tolower(*string1); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
34 second = tolower(*string2); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
35 string1++; |
|
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 string2++; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
37 } while (first && first == second); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
38 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
39 return (first - second); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
40 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
41 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
42 |
|
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 /* 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
|
44 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
|
45 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
|
46 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
|
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 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
|
49 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
|
50 |
|
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 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 |
|
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 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
|
59 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
|
60 |
|
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 #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
|
62 #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
|
63 |
|
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 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
|
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 unsigned char *dllbase, *import_data, *import_name; |
|
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 DWORD pe_offset, opt_offset; |
|
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 WORD opt_magic; |
|
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 int num_dict_off, import_off; |
|
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 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
71 /* Safety check input */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
72 if (hModule == 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
|
73 return 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
|
74 } |
|
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 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
76 /* Module instance is also the base load address. First portion of |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
77 memory is the MS-DOS loader, which holds the offset to the PE |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
78 header (from the load base) at 0x3C */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
79 dllbase = (unsigned char *)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
|
80 pe_offset = DWORD_AT(dllbase + 0x3C); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
81 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
82 /* The PE signature must be "PE\0\0" */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
83 if (memcmp(dllbase+pe_offset,"PE\0\0",4)) { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
84 return 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
|
85 } |
|
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 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
87 /* Following the PE signature is the standard COFF header (20 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
88 bytes) and then the optional header. The optional header starts |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
89 with a magic value of 0x10B for PE32 or 0x20B for PE32+ (PE32+ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
90 uses 64-bits for some fields). It might also be 0x107 for a ROM |
|
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 image, but we don't process that here. |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
92 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
93 The optional header ends with a data dictionary that directly |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
94 points to certain types of data, among them the import entries |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
95 (in the second table entry). Based on the header type, we |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
96 determine offsets for the data dictionary count and the entry |
|
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 within the dictionary pointing to the imports. */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
98 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
99 opt_offset = pe_offset + 4 + 20; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
100 opt_magic = WORD_AT(dllbase+opt_offset); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
101 if (opt_magic == 0x10B) { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
102 /* PE32 */ |
|
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 num_dict_off = 92; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
104 import_off = 104; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
105 } else if (opt_magic == 0x20B) { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
106 /* PE32+ */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
107 num_dict_off = 108; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
108 import_off = 120; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
109 } else { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
110 /* Unsupported */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
111 return 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
|
112 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
113 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
114 /* Now if an import table exists, offset to it and walk the list of |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
115 imports. The import table is an array (ending when an entry has |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
116 empty values) of structures (20 bytes each), which contains (at |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
117 offset 12) a relative address (to the module base) at which a |
|
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 string constant holding the import name is 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
|
119 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
120 if (DWORD_AT(dllbase + opt_offset + num_dict_off) >= 2) { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
121 import_data = dllbase + DWORD_AT(dllbase + |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
122 opt_offset + |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
123 import_off); |
|
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 while (DWORD_AT(import_data)) { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
125 import_name = dllbase + DWORD_AT(import_data+12); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
126 if (strlen(import_name) >= 6 && |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
127 !strncmp(import_name,"python",6)) { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
128 char *pch; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
129 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
130 /* Ensure python prefix is followed only |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
131 by numbers to the end of the basename */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
132 pch = import_name + 6; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
133 while (*pch && *pch != '.') { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
134 if (*pch >= '0' && *pch <= '9') { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
135 pch++; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
136 } else { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
137 pch = 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
|
138 break; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
139 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
140 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
141 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
142 if (pch) { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
143 /* Found it - return the name */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
144 return import_name; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
145 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
146 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
147 import_data += 20; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
148 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
149 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
150 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
151 return 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
|
152 } |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
153 #endif /* MS_WIN32 */ |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
154 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
155 |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
156 dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname, |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
157 const char *pathname, FILE *fp) |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
158 { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
159 dl_funcptr p; |
|
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
|
160 char funcname[258], *import_python; |
|
11618
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
161 |
|
528559a0b2f2
Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents:
11599
diff
changeset
|
162 sprintf(funcname, "init%.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
|
163 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
164 #ifdef MS_WIN32 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 { |
|
17713
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
166 HINSTANCE hDLL = NULL; |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 char pathbuf[260]; |
|
17713
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
168 LPTSTR dummy; |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
169 /* We use LoadLibraryEx so Windows looks for dependent DLLs |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
170 in directory of pathname first. However, Windows95 |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
171 can sometimes not work correctly unless the absolute |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
172 path is used. If GetFullPathName() fails, the LoadLibrary |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
173 will certainly fail too, so use its error code */ |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
174 if (GetFullPathName(pathname, |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
175 sizeof(pathbuf), |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
176 pathbuf, |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
177 &dummy)) |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
178 /* XXX This call doesn't exist in Windows CE */ |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
179 hDLL = LoadLibraryEx(pathname, NULL, |
|
5e3bab8aef7b
Always pass a full path name to LoadLibraryEx(). Fixes some Windows 9x problems. As discussed on python-dev
Mark Hammond <mhammond@skippinet.com.au>
parents:
15027
diff
changeset
|
180 LOAD_WITH_ALTERED_SEARCH_PATH); |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 if (hDLL==NULL){ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
182 char errBuf[256]; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
183 unsigned int errorCode; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 /* Get an error string from Win32 error code */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
186 char theInfo[256]; /* Pointer to error text |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 from system */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
188 int theLength; /* Length of error text */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
189 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 errorCode = GetLastError(); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
191 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 theLength = FormatMessage( |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
193 FORMAT_MESSAGE_FROM_SYSTEM, /* flags */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 NULL, /* message source */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 errorCode, /* the message (error) ID */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 0, /* default language environment */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 (LPTSTR) theInfo, /* the buffer */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
198 sizeof(theInfo), /* the buffer size */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 NULL); /* no additional format args. */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
200 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 /* Problem: could not get the error message. |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
202 This should not happen if called correctly. */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 if (theLength == 0) { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
204 sprintf(errBuf, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 "DLL load failed with error code %d", |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
206 errorCode); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 } else { |
|
13096
8c8de5b736dc
Trent Mick's Win64 changes: size_t vs. int or long; also some overflow
Guido van Rossum <guido@python.org>
parents:
11618
diff
changeset
|
208 size_t len; |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 /* For some reason a \r\n |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
210 is appended to the text */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 if (theLength >= 2 && |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 theInfo[theLength-2] == '\r' && |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
213 theInfo[theLength-1] == '\n') { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 theLength -= 2; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
215 theInfo[theLength] = '\0'; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
217 strcpy(errBuf, "DLL load failed: "); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
218 len = strlen(errBuf); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 strncpy(errBuf+len, theInfo, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
220 sizeof(errBuf)-len); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
221 errBuf[sizeof(errBuf)-1] = '\0'; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
222 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
223 PyErr_SetString(PyExc_ImportError, errBuf); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
224 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
|
225 } else { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
226 char buffer[256]; |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
227 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
228 sprintf(buffer,"python%d%d.dll", |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
229 PY_MAJOR_VERSION,PY_MINOR_VERSION); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
230 import_python = GetPythonImport(hDLL); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
231 |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
232 if (import_python && |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
233 strcasecmp(buffer,import_python)) { |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
234 sprintf(buffer, |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
235 "Module use of %s conflicts " |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
236 "with this version of Python.", |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
237 import_python); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
238 PyErr_SetString(PyExc_ImportError,buffer); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
239 FreeLibrary(hDLL); |
|
5ffa515e620e
Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents:
14375
diff
changeset
|
240 return 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
|
241 } |
|
11599
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
242 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
243 p = GetProcAddress(hDLL, funcname); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
244 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
245 #endif /* MS_WIN32 */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
246 #ifdef MS_WIN16 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
247 { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
248 HINSTANCE hDLL; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
249 char pathbuf[16]; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
250 if (strchr(pathname, '\\') == NULL && |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
251 strchr(pathname, '/') == NULL) |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
252 { |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
253 /* Prefix bare filename with ".\" */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
254 sprintf(pathbuf, ".\\%-.13s", pathname); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
255 pathname = pathbuf; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
256 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
257 hDLL = LoadLibrary(pathname); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
258 if (hDLL < HINSTANCE_ERROR){ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
259 char errBuf[256]; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
260 sprintf(errBuf, |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
261 "DLL load failed with error code %d", hDLL); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
262 PyErr_SetString(PyExc_ImportError, errBuf); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
263 return NULL; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
264 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
265 p = GetProcAddress(hDLL, funcname); |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
266 } |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
267 #endif /* MS_WIN16 */ |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
268 |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
269 return p; |
|
78fe87ce0ded
The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
270 } |
