annotate Python/dynload_win.c @ 45852:30c4e1ca8421

Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r61431 | vinay.sajip | 2008-03-16 22:35:58 +0100 (So, 16 Mär 2008) | 1 line Clarified documentation on use of shutdown(). ........ r61433 | mark.summerfield | 2008-03-17 09:28:15 +0100 (Mo, 17 Mär 2008) | 5 lines Added a footnote to each pointing out that for XML output if an encoding string is given it should conform to the appropriate XML standards---for example, "UTF-8" is okay, but "UTF8" is not. ........ r61434 | eric.smith | 2008-03-17 12:01:01 +0100 (Mo, 17 Mär 2008) | 7 lines Issue 2264: empty float presentation type needs to have at least one digit past the decimal point. Added "Z" format_char to PyOS_ascii_formatd to support empty float presentation type. Renamed buf_size in PyOS_ascii_formatd to more accurately reflect it's meaning. Modified format.__float__ to use the new "Z" format as the default. Added test cases. ........ r61435 | eric.smith | 2008-03-17 13:14:29 +0100 (Mo, 17 Mär 2008) | 2 lines Reformated lines > 79 chars. Deleted unused macro ISXDIGIT. ........ r61436 | jeffrey.yasskin | 2008-03-17 15:40:53 +0100 (Mo, 17 Mär 2008) | 13 lines Allow Gnu gcc's to build python on OSX by removing -Wno-long-double, -no-cpp-precomp, and -mno-fused-madd from configure. * r22183 added -no-cpp-precomp, which http://gcc.gnu.org/ml/gcc/2005-12/msg00368.html claims hasn't been needed since gcc-3.1. * r25607 added -Wno-long-double to avoid a warning in Include/objimpl.h (issue 525481). The long double is still there, but OSX 10.4's gcc no longer warns about it. * r33666 fixed issue 775892 on OSX 10.3 by adding -mno-fused-madd, which changed the sign of some float 0s. Tim Peters said it wasn't a real issue anyway, and it no longer causes test failures. Fixes issue #1779871. ........ r61439 | martin.v.loewis | 2008-03-17 17:31:57 +0100 (Mo, 17 Mär 2008) | 2 lines Add Trent Nelson. ........ r61444 | travis.oliphant | 2008-03-17 18:36:12 +0100 (Mo, 17 Mär 2008) | 1 line Add necessary headers to back-port new buffer protocol to Python 2.6 ........ r61449 | gregory.p.smith | 2008-03-17 19:48:05 +0100 (Mo, 17 Mär 2008) | 8 lines Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms regardless of the native sizeof(long) used in the integer object. This somewhat odd behavior of returning a signed is maintained in 2.x for compatibility reasons of always returning an integer rather than a long object. Fixes Issue1202 for Python 2.6 ........ r61450 | neal.norwitz | 2008-03-17 20:02:45 +0100 (Mo, 17 Mär 2008) | 3 lines Use a buffer large enough to ensure we don't overrun, even if the value is outside the range we expect. ........ r61453 | steven.bethard | 2008-03-17 20:33:11 +0100 (Mo, 17 Mär 2008) | 1 line Document unicode.isnumeric() and unicode.isdecimal() (issue2326) ........ r61458 | neal.norwitz | 2008-03-17 21:22:43 +0100 (Mo, 17 Mär 2008) | 5 lines Issue 2321: reduce memory usage (increase the memory that is returned to the system) by using pymalloc for the data of unicode objects. Will backport. ........ r61465 | martin.v.loewis | 2008-03-17 22:55:30 +0100 (Mo, 17 Mär 2008) | 2 lines Add David Wolever. ........ r61468 | gregory.p.smith | 2008-03-18 01:20:01 +0100 (Di, 18 Mär 2008) | 3 lines Fix the IOError message text when opening a file with an invalid filename. Error reported by Ilan Schnell. ........ r61471 | brett.cannon | 2008-03-18 02:00:07 +0100 (Di, 18 Mär 2008) | 2 lines Convert test_strftime, test_getargs, and test_pep247 to use unittest. ........ r61472 | jeffrey.yasskin | 2008-03-18 02:09:59 +0100 (Di, 18 Mär 2008) | 2 lines Fix build on platforms that don't have intptr_t. Patch by Joseph Armbruster. ........ r61473 | brett.cannon | 2008-03-18 02:50:25 +0100 (Di, 18 Mär 2008) | 2 lines Convert test_dummy_threading and test_dbm to unittest. ........ r61474 | brett.cannon | 2008-03-18 02:58:56 +0100 (Di, 18 Mär 2008) | 2 lines Move test_extcall to doctest. ........ r61480 | brett.cannon | 2008-03-18 04:46:22 +0100 (Di, 18 Mär 2008) | 2 lines test_errno was a no-op test; now it actually tests things and uses unittest. ........ r61483 | brett.cannon | 2008-03-18 05:09:00 +0100 (Di, 18 Mär 2008) | 3 lines Remove our implementation of memmove() and strerror(); both are in the C89 standard library. ........ r61484 | brett.cannon | 2008-03-18 05:16:06 +0100 (Di, 18 Mär 2008) | 2 lines The output directory for tests that compare against stdout is now gone! ........ r61488 | jeffrey.yasskin | 2008-03-18 05:29:35 +0100 (Di, 18 Mär 2008) | 2 lines Block the "socket.ssl() is deprecated" warning from test_socket_ssl. ........ r61495 | jeffrey.yasskin | 2008-03-18 05:56:06 +0100 (Di, 18 Mär 2008) | 4 lines Speed test_thread up from 51.328s to 0.081s by reducing its sleep times. We still sleep at all to make it likely that all threads are active at the same time. ........ r61496 | jeffrey.yasskin | 2008-03-18 06:12:41 +0100 (Di, 18 Mär 2008) | 4 lines Speed up test_dict by about 10x by only checking selected dict literal sizes, instead of every integer from 0 to 400. Exhaustive testing wastes time without providing enough more assurance that the code is correct. ........ r61498 | neal.norwitz | 2008-03-18 06:20:29 +0100 (Di, 18 Mär 2008) | 1 line Try increasing the timeout to reduce the flakiness of this test. ........ r61503 | brett.cannon | 2008-03-18 06:43:04 +0100 (Di, 18 Mär 2008) | 2 lines Improve the error message for a test that failed on the S-390 Debian buildbot. ........ r61504 | jeffrey.yasskin | 2008-03-18 06:45:40 +0100 (Di, 18 Mär 2008) | 3 lines Add a -S/--slow flag to regrtest to have it print the 10 slowest tests with their times. ........ r61507 | neal.norwitz | 2008-03-18 07:03:46 +0100 (Di, 18 Mär 2008) | 1 line Add some info to the failure messages ........ r61509 | trent.nelson | 2008-03-18 08:02:12 +0100 (Di, 18 Mär 2008) | 1 line Issue 2286: bump up the stack size of the 64-bit debug python_d.exe to 2100000. The default value of 200000 causes a stack overflow at 1965 iterations of r_object() in marshal.c, 35 iterations before the 2000 limit enforced by MAX_MARSHAL_STACK_DEPTH. ........ r61510 | trent.nelson | 2008-03-18 08:32:47 +0100 (Di, 18 Mär 2008) | 5 lines The behaviour of winsound.Beep() seems to differ between different versions of Windows when there's either: a) no sound card entirely b) legacy beep driver has been disabled c) the legacy beep driver has been uninstalled Sometimes RuntimeErrors are raised, sometimes they're not. If _have_soundcard() returns False, don't expect winsound.Beep() to raise a RuntimeError, as this clearly isn't the case, as demonstrated by the various Win32 XP buildbots. ........ r61515 | martin.v.loewis | 2008-03-18 13:20:15 +0100 (Di, 18 Mär 2008) | 2 lines norwitz-amd64 (gentoo) has EREMOTEIO. ........ r61516 | martin.v.loewis | 2008-03-18 13:45:37 +0100 (Di, 18 Mär 2008) | 2 lines Add more Linux error codes. ........ r61517 | martin.v.loewis | 2008-03-18 14:05:03 +0100 (Di, 18 Mär 2008) | 2 lines Add WSA errors. ........ r61518 | martin.v.loewis | 2008-03-18 14:16:05 +0100 (Di, 18 Mär 2008) | 2 lines Note that the stderr output of the test is intentional. ........
author Christian Heimes <christian@cheimes.de>
date Tue, 18 Mar 2008 15:15:01 +0000
parents c0f048356c36
children 94f64f11fdd0
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 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
15 #ifdef _DEBUG
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 {"_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
17 #else
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 {".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
19 #endif
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 {0, 0}
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
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
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
24 /* 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
25 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
26
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 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
28 {
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 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
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 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
32 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
33 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
34 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
35 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
36 } 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
37
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 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
39 }
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 /* 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
43 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
44 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
45 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
46
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
47 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
48 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
49
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 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
51 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
52 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
53 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
54 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
55 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
56
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 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
58 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
59
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 #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
61 #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
62
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
63 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
64 {
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 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
66 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
67 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
68 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
69
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 /* 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
71 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
72 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
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
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 /* 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
76 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
77 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
78 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
79 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
80
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 /* 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
82 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
83 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
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
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 /* 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
87 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
88 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
89 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
90 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
91
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 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
93 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
94 (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
95 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
96 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
97
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 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
99 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
100 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
101 /* 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
102 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
103 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
104 } 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
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 = 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
107 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
108 } 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
109 /* 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
110 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
111 }
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 /* 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
114 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
115 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
116 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
117 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
118
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 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
120 /* 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 !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
131 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
132
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 /* 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
134 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
135 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
136 #ifdef _DEBUG
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
137 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
138 #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
139 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
140 #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
141 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
142 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 } 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
144 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
145 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
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 }
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 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
150 /* 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
151 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
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 }
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 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
155 }
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 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
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
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
162 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
163 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
164 {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 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
166 char funcname[258], *import_python;
11618
528559a0b2f2 Cleanup patches from Greg Stein:
Guido van Rossum <guido@python.org>
parents: 11599
diff changeset
167
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
168 PyOS_snprintf(funcname, sizeof(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
169
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 {
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
171 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
172 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
173 LPTSTR dummy;
44905
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
174 unsigned int old_mode;
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 /* 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
176 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
177 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
178 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
179 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
180
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
181 /* 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
182 old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
183
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
184 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
185 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
186 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
187 &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
188 /* 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
189 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
190 LOAD_WITH_ALTERED_SEARCH_PATH);
44905
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
191
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
192 /* restore old error mode settings */
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
193 SetErrorMode(old_mode);
c0f048356c36 Merged revisions 60210-60233 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents: 44535
diff changeset
194
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 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
196 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
197 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
198
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 /* 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
200 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
201 from system */
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 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
203
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 errorCode = GetLastError();
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
205
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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 /* 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
214 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
215 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
216 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
217
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 /* 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
219 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
220 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
221 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
222 "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
223 errorCode);
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
224 } else {
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 /* 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
226 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
227 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
228 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
229 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
230 theLength -= 2;
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
231 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
232 }
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
233 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
234 "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
235
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
236 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
237 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
238 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
239 theLength));
11599
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 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
242 Py_XDECREF(message);
25041
ed0b02672f09 Fix a couple of whitespace consistency nits.
Fred Drake <fdrake@acm.org>
parents: 24071
diff changeset
243 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
244 } 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
245 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
246
32469
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
247 #ifdef _DEBUG
b8710e6d8d78 When importing an extension on Windows, the code reads the PE 'import
Thomas Heller <theller@ctypes.org>
parents: 25041
diff changeset
248 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
249 #else
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
250 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
251 #endif
25041
ed0b02672f09 Fix a couple of whitespace consistency nits.
Fred Drake <fdrake@acm.org>
parents: 24071
diff changeset
252 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
253 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
254
5ffa515e620e Detect conflicting Python DLL on module import under Windows - as per [ Patch #101676 ]
Mark Hammond <mhammond@skippinet.com.au>
parents: 14375
diff changeset
255 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
256 strcasecmp(buffer,import_python)) {
21077
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
257 PyOS_snprintf(buffer, sizeof(buffer),
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
258 "Module use of %.150s conflicts "
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
259 "with this version of Python.",
379fc66f4c96 Use PyOS_snprintf instead of sprintf.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 21066
diff changeset
260 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
261 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
262 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
263 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
264 }
11599
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 }
78fe87ce0ded The old platform-specific contents of importdl.c, broken down into one
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 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
267 }
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 }