annotate Python/dynload_win.c @ 58664:993f703a61ba

Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done partially before. Also add a comment describing how this might have to work with different versions of the interpreter. ........ r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line Fixed typo ........ r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line #7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such. ........ r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line Add note about usage of STRINGLIB_EMPTY. ........ r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line Fix internal reference. ........ r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines data descriptors do not override the class dictionary if __get__ is not defined Adjust documentation and add a test to verify this behavior. See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for discussion. ........ r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines Do not compile stubs for the sha2 series hashes in the openssl hashlib module when the openssl version is too old to support them. That leads both compiled code bloat and to unittests attempting to test implementations that don't exist for comparison purposes on such platforms. ........ r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line Add two more test_strtod test values. ........ r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line #7762: fix refcount annotation of PyUnicode_Tailmatch(). ........ r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line #7725: fix referencing issue. ........ r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line mention from_float() in error message ........ r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line #7802: fix invalid example (heh). ........ r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines Fix-up ftplib documentation: move exception descriptions to toplevel, not inside a class remove attribution in "versionadded" spell and grammar check docstring of FTP_TLS ........ r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line Minor modification to unittest documentation. ........
author Benjamin Peterson <benjamin@python.org>
date Wed, 03 Feb 2010 02:35:45 +0000
parents 0522cfee879a
children cab14be0ada1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 37879
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>
39442
654c380cf8b9 Merged revisions 46753-51188 via svnmerge from
Thomas Wouters <thomas@python.org>
parents: 37879
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...
0522cfee879a Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents: 47584
diff changeset
15 extern ULONG_PTR _Py_ActivateActCtx();
0522cfee879a Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents: 47584
diff changeset
16 void _Py_DeactivateActCtx(ULONG_PTR cookie);
0522cfee879a Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents: 47584
diff changeset
17
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 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
19 #ifdef _DEBUG
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 {"_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
21 #else
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 {".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
23 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 {0, 0}
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 };
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
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
28 /* 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
29 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
30
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 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
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 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
34
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 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
36 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
37 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
38 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
39 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
40 } 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
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 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
43 }
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
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
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 /* 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
47 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
48 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
49 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
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 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
52 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
53
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 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
55 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
56 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
57 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
58 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
59 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
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 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
62 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
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 #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
65 #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
66
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 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
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 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
70 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
71 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
72 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
73
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 /* 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
75 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
76 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
77 }
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
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 /* 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
80 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
81 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
82 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
83 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
84
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 /* 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
86 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
87 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
88 }
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
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 /* 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
91 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
92 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
93 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
94 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
95
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 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
97 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
98 (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
99 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
100 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
101
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 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
103 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
104 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
105 /* 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
106 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
107 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
108 } 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
109 /* 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
110 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
111 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
112 } 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
113 /* 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
114 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
115 }
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
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 /* 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
118 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
119 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
120 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
121 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
122
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 if (DWORD_AT(dllbase + opt_offset + num_dict_off) >= 2) {
32469
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
124 /* We have at least 2 tables - the import table is the second
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
125 one. But still it may be that the table size is zero */
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
126 if (0 == DWORD_AT(dllbase + opt_offset + import_off + sizeof(DWORD)))
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
127 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
128 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
129 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
130 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
131 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
132 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
133 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
134 !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
135 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
136
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 /* 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
138 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
139 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
140 #ifdef _DEBUG
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
141 while (*pch && pch[0] != '_' && pch[1] != 'd' && pch[2] != '.') {
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
142 #else
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
143 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
144 #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
145 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
146 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
147 } 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
148 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
149 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
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 }
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 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
154 /* 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
155 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
156 }
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
157 }
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
158 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
159 }
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 }
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
161
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
162 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
163 }
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
164
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
165
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
166 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
167 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
168 {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 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
170 char funcname[258], *import_python;
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
171
47584
b833a40098c0 Fix typo.
Martin v. Löwis <martin@v.loewis.de>
parents: 47580
diff changeset
172 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
173
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 {
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
175 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
176 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
177 LPTSTR dummy;
44905
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
178 unsigned int old_mode;
51130
0522cfee879a Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents: 47584
diff changeset
179 ULONG_PTR cookie = 0;
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
180 /* 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
181 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
182 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
183 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
184 will certainly fail too, so use its error code */
44905
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
185
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
186 /* Don't display a message box when Python can't load a DLL */
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
187 old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
188
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
189 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
190 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
191 pathbuf,
51130
0522cfee879a Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents: 47584
diff changeset
192 &dummy)) {
0522cfee879a Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents: 47584
diff changeset
193 ULONG_PTR cookie = _Py_ActivateActCtx();
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
194 /* 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
195 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
196 LOAD_WITH_ALTERED_SEARCH_PATH);
51130
0522cfee879a Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents: 47584
diff changeset
197 _Py_DeactivateActCtx(cookie);
0522cfee879a Merged revisions 69041 via svnmerge from
Mark Hammond <mhammond@skippinet.com.au>
parents: 47584
diff changeset
198 }
44905
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
199
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
200 /* restore old error mode settings */
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
201 SetErrorMode(old_mode);
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
202
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 if (hDLL==NULL){
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
204 PyObject *message;
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 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
206
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 /* Get an error string from Win32 error code */
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
208 wchar_t theInfo[256]; /* Pointer to 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
209 from system */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 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
211
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
212 errorCode = GetLastError();
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
213
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
214 theLength = FormatMessageW(
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
215 FORMAT_MESSAGE_FROM_SYSTEM |
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
216 FORMAT_MESSAGE_IGNORE_INSERTS, /* flags */
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 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
218 errorCode, /* the message (error) ID */
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
219 MAKELANGID(LANG_NEUTRAL,
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
220 SUBLANG_DEFAULT),
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
221 /* Default language */
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
222 theInfo, /* the buffer */
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
223 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
224 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
225
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
226 /* 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
227 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
228 if (theLength == 0) {
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
229 message = PyUnicode_FromFormat(
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
230 "DLL load failed with error code %d",
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
231 errorCode);
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
232 } else {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 /* 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
234 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
235 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
236 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
237 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
238 theLength -= 2;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 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
240 }
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
241 message = PyUnicode_FromString(
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
242 "DLL load failed: ");
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
243
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
244 PyUnicode_AppendAndDel(&message,
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
245 PyUnicode_FromUnicode(
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
246 theInfo,
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
247 theLength));
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 }
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
249 PyErr_SetObject(PyExc_ImportError, message);
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
250 Py_XDECREF(message);
25041
ed0b02672f09 Fix a couple of whitespace consistency nits.
Fred Drake <fdrake@acm.org>
parents: 24071
diff changeset
251 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
252 } 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
253 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
254
32469
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
255 #ifdef _DEBUG
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
256 PyOS_snprintf(buffer, sizeof(buffer), "python%d%d_d.dll",
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
257 #else
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
258 PyOS_snprintf(buffer, sizeof(buffer), "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
259 #endif
25041
ed0b02672f09 Fix a couple of whitespace consistency nits.
Fred Drake <fdrake@acm.org>
parents: 24071
diff changeset
260 PY_MAJOR_VERSION,PY_MINOR_VERSION);
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
261 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
262
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
263 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
264 strcasecmp(buffer,import_python)) {
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
265 PyOS_snprintf(buffer, sizeof(buffer),
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
266 "Module use of %.150s conflicts "
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
267 "with this version of Python.",
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
268 import_python);
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
269 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
270 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
271 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
272 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
274 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
275 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
276
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 return p;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 }