Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 1 | |
| 2 | /* Support for dynamic loading of extension modules */ |
| 3 | |
Christian Heimes | faf2f63 | 2008-01-06 16:59:19 +0000 | [diff] [blame] | 4 | #include "Python.h" |
| 5 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 6 | #ifdef HAVE_DIRECT_H |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 7 | #include <direct.h> |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 8 | #endif |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 9 | #include <ctype.h> |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 10 | |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 11 | #include "importdl.h" |
Steve Dower | 03a144b | 2014-12-15 20:45:23 -0800 | [diff] [blame] | 12 | #include "patchlevel.h" |
Guido van Rossum | e7ba495 | 2007-06-06 23:52:48 +0000 | [diff] [blame] | 13 | #include <windows.h> |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 14 | |
Mark Hammond | 9844a1f | 2009-01-27 23:46:57 +0000 | [diff] [blame] | 15 | // "activation context" magic - see dl_nt.c... |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 16 | #if HAVE_SXS |
Mark Hammond | 9844a1f | 2009-01-27 23:46:57 +0000 | [diff] [blame] | 17 | extern ULONG_PTR _Py_ActivateActCtx(); |
| 18 | void _Py_DeactivateActCtx(ULONG_PTR cookie); |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 19 | #endif |
Mark Hammond | 9844a1f | 2009-01-27 23:46:57 +0000 | [diff] [blame] | 20 | |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 21 | #ifdef _DEBUG |
Steve Dower | 03a144b | 2014-12-15 20:45:23 -0800 | [diff] [blame] | 22 | #define PYD_DEBUG_SUFFIX "_d" |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 23 | #else |
Steve Dower | 03a144b | 2014-12-15 20:45:23 -0800 | [diff] [blame] | 24 | #define PYD_DEBUG_SUFFIX "" |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 25 | #endif |
Steve Dower | 03a144b | 2014-12-15 20:45:23 -0800 | [diff] [blame] | 26 | |
| 27 | #define STRINGIZE2(x) #x |
| 28 | #define STRINGIZE(x) STRINGIZE2(x) |
| 29 | #ifdef PYD_PLATFORM_TAG |
| 30 | #define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX ".cp" STRINGIZE(PY_MAJOR_VERSION) STRINGIZE(PY_MINOR_VERSION) "-" PYD_PLATFORM_TAG ".pyd" |
| 31 | #else |
| 32 | #define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX ".cp" STRINGIZE(PY_MAJOR_VERSION) STRINGIZE(PY_MINOR_VERSION) ".pyd" |
| 33 | #endif |
| 34 | |
| 35 | #define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd" |
| 36 | |
| 37 | const char *_PyImport_DynLoadFiletab[] = { |
| 38 | PYD_TAGGED_SUFFIX, |
| 39 | PYD_UNTAGGED_SUFFIX, |
Brett Cannon | 2657df4 | 2012-05-04 15:20:40 -0400 | [diff] [blame] | 40 | NULL |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 43 | /* Case insensitive string compare, to avoid any dependencies on particular |
| 44 | C RTL implementations */ |
| 45 | |
| 46 | static int strcasecmp (char *string1, char *string2) |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 47 | { |
| 48 | int first, second; |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 49 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 50 | do { |
| 51 | first = tolower(*string1); |
| 52 | second = tolower(*string2); |
| 53 | string1++; |
| 54 | string2++; |
| 55 | } while (first && first == second); |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 56 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 57 | return (first - second); |
| 58 | } |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 59 | |
| 60 | |
| 61 | /* Function to return the name of the "python" DLL that the supplied module |
| 62 | directly imports. Looks through the list of imported modules and |
| 63 | returns the first entry that starts with "python" (case sensitive) and |
| 64 | is followed by nothing but numbers until the separator (period). |
| 65 | |
| 66 | Returns a pointer to the import name, or NULL if no matching name was |
| 67 | located. |
| 68 | |
| 69 | This function parses through the PE header for the module as loaded in |
| 70 | memory by the system loader. The PE header is accessed as documented by |
| 71 | Microsoft in the MSDN PE and COFF specification (2/99), and handles |
| 72 | both PE32 and PE32+. It only worries about the direct import table and |
| 73 | not the delay load import table since it's unlikely an extension is |
| 74 | going to be delay loading Python (after all, it's already loaded). |
| 75 | |
| 76 | If any magic values are not found (e.g., the PE header or optional |
| 77 | header magic), then this function simply returns NULL. */ |
| 78 | |
| 79 | #define DWORD_AT(mem) (*(DWORD *)(mem)) |
| 80 | #define WORD_AT(mem) (*(WORD *)(mem)) |
| 81 | |
| 82 | static char *GetPythonImport (HINSTANCE hModule) |
| 83 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 84 | unsigned char *dllbase, *import_data, *import_name; |
| 85 | DWORD pe_offset, opt_offset; |
| 86 | WORD opt_magic; |
| 87 | int num_dict_off, import_off; |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 88 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 89 | /* Safety check input */ |
| 90 | if (hModule == NULL) { |
| 91 | return NULL; |
| 92 | } |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 93 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 94 | /* Module instance is also the base load address. First portion of |
| 95 | memory is the MS-DOS loader, which holds the offset to the PE |
| 96 | header (from the load base) at 0x3C */ |
| 97 | dllbase = (unsigned char *)hModule; |
| 98 | pe_offset = DWORD_AT(dllbase + 0x3C); |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 99 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 100 | /* The PE signature must be "PE\0\0" */ |
| 101 | if (memcmp(dllbase+pe_offset,"PE\0\0",4)) { |
| 102 | return NULL; |
| 103 | } |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 104 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 105 | /* Following the PE signature is the standard COFF header (20 |
| 106 | bytes) and then the optional header. The optional header starts |
| 107 | with a magic value of 0x10B for PE32 or 0x20B for PE32+ (PE32+ |
| 108 | uses 64-bits for some fields). It might also be 0x107 for a ROM |
| 109 | image, but we don't process that here. |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 110 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 111 | The optional header ends with a data dictionary that directly |
| 112 | points to certain types of data, among them the import entries |
| 113 | (in the second table entry). Based on the header type, we |
| 114 | determine offsets for the data dictionary count and the entry |
| 115 | within the dictionary pointing to the imports. */ |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 116 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 117 | opt_offset = pe_offset + 4 + 20; |
| 118 | opt_magic = WORD_AT(dllbase+opt_offset); |
| 119 | if (opt_magic == 0x10B) { |
| 120 | /* PE32 */ |
| 121 | num_dict_off = 92; |
| 122 | import_off = 104; |
| 123 | } else if (opt_magic == 0x20B) { |
| 124 | /* PE32+ */ |
| 125 | num_dict_off = 108; |
| 126 | import_off = 120; |
| 127 | } else { |
| 128 | /* Unsupported */ |
| 129 | return NULL; |
| 130 | } |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 131 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 132 | /* Now if an import table exists, offset to it and walk the list of |
| 133 | imports. The import table is an array (ending when an entry has |
| 134 | empty values) of structures (20 bytes each), which contains (at |
| 135 | offset 12) a relative address (to the module base) at which a |
| 136 | string constant holding the import name is located. */ |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 137 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 138 | if (DWORD_AT(dllbase + opt_offset + num_dict_off) >= 2) { |
| 139 | /* We have at least 2 tables - the import table is the second |
| 140 | one. But still it may be that the table size is zero */ |
| 141 | if (0 == DWORD_AT(dllbase + opt_offset + import_off + sizeof(DWORD))) |
| 142 | return NULL; |
| 143 | import_data = dllbase + DWORD_AT(dllbase + |
| 144 | opt_offset + |
| 145 | import_off); |
| 146 | while (DWORD_AT(import_data)) { |
| 147 | import_name = dllbase + DWORD_AT(import_data+12); |
| 148 | if (strlen(import_name) >= 6 && |
| 149 | !strncmp(import_name,"python",6)) { |
| 150 | char *pch; |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 151 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 152 | #ifndef _DEBUG |
| 153 | /* In a release version, don't claim that python3.dll is |
| 154 | a Python DLL. */ |
| 155 | if (strcmp(import_name, "python3.dll") == 0) { |
| 156 | import_data += 20; |
| 157 | continue; |
| 158 | } |
| 159 | #endif |
| 160 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 161 | /* Ensure python prefix is followed only |
| 162 | by numbers to the end of the basename */ |
| 163 | pch = import_name + 6; |
Thomas Heller | 1df0461 | 2004-07-02 08:53:57 +0000 | [diff] [blame] | 164 | #ifdef _DEBUG |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 165 | while (*pch && pch[0] != '_' && pch[1] != 'd' && pch[2] != '.') { |
Thomas Heller | 1df0461 | 2004-07-02 08:53:57 +0000 | [diff] [blame] | 166 | #else |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 167 | while (*pch && *pch != '.') { |
Thomas Heller | 1df0461 | 2004-07-02 08:53:57 +0000 | [diff] [blame] | 168 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 169 | if (*pch >= '0' && *pch <= '9') { |
| 170 | pch++; |
| 171 | } else { |
| 172 | pch = NULL; |
| 173 | break; |
| 174 | } |
| 175 | } |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 176 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 177 | if (pch) { |
| 178 | /* Found it - return the name */ |
| 179 | return import_name; |
| 180 | } |
| 181 | } |
| 182 | import_data += 20; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | return NULL; |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 187 | } |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 188 | |
Victor Stinner | 2d32227 | 2011-04-04 23:05:53 +0200 | [diff] [blame] | 189 | dl_funcptr _PyImport_GetDynLoadWindows(const char *shortname, |
| 190 | PyObject *pathname, FILE *fp) |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 191 | { |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 192 | dl_funcptr p; |
| 193 | char funcname[258], *import_python; |
Victor Stinner | 3335447 | 2011-11-21 02:01:41 +0100 | [diff] [blame] | 194 | wchar_t *wpathname; |
Guido van Rossum | 96a8fb7 | 1999-12-22 14:09:35 +0000 | [diff] [blame] | 195 | |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 196 | #ifndef _DEBUG |
| 197 | _Py_CheckPython3(); |
| 198 | #endif |
| 199 | |
Victor Stinner | 3335447 | 2011-11-21 02:01:41 +0100 | [diff] [blame] | 200 | wpathname = PyUnicode_AsUnicode(pathname); |
| 201 | if (wpathname == NULL) |
| 202 | return NULL; |
| 203 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 204 | PyOS_snprintf(funcname, sizeof(funcname), "PyInit_%.200s", shortname); |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 205 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 206 | { |
| 207 | HINSTANCE hDLL = NULL; |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 208 | unsigned int old_mode; |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 209 | #if HAVE_SXS |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 210 | ULONG_PTR cookie = 0; |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 211 | #endif |
Victor Stinner | 67002af | 2011-10-02 20:35:10 +0200 | [diff] [blame] | 212 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 213 | /* Don't display a message box when Python can't load a DLL */ |
| 214 | old_mode = SetErrorMode(SEM_FAILCRITICALERRORS); |
Christian Heimes | bbffeb6 | 2008-01-24 09:42:52 +0000 | [diff] [blame] | 215 | |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 216 | #if HAVE_SXS |
Brian Curtin | 589f89e | 2011-06-09 17:55:54 -0500 | [diff] [blame] | 217 | cookie = _Py_ActivateActCtx(); |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 218 | #endif |
Brian Curtin | 589f89e | 2011-06-09 17:55:54 -0500 | [diff] [blame] | 219 | /* We use LoadLibraryEx so Windows looks for dependent DLLs |
| 220 | in directory of pathname first. */ |
| 221 | /* XXX This call doesn't exist in Windows CE */ |
Victor Stinner | 3335447 | 2011-11-21 02:01:41 +0100 | [diff] [blame] | 222 | hDLL = LoadLibraryExW(wpathname, NULL, |
Brian Curtin | 589f89e | 2011-06-09 17:55:54 -0500 | [diff] [blame] | 223 | LOAD_WITH_ALTERED_SEARCH_PATH); |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 224 | #if HAVE_SXS |
Brian Curtin | 589f89e | 2011-06-09 17:55:54 -0500 | [diff] [blame] | 225 | _Py_DeactivateActCtx(cookie); |
Brian Curtin | 401f9f3 | 2012-05-13 11:19:23 -0500 | [diff] [blame] | 226 | #endif |
Christian Heimes | bbffeb6 | 2008-01-24 09:42:52 +0000 | [diff] [blame] | 227 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 228 | /* restore old error mode settings */ |
| 229 | SetErrorMode(old_mode); |
Christian Heimes | bbffeb6 | 2008-01-24 09:42:52 +0000 | [diff] [blame] | 230 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 231 | if (hDLL==NULL){ |
| 232 | PyObject *message; |
| 233 | unsigned int errorCode; |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 234 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 235 | /* Get an error string from Win32 error code */ |
| 236 | wchar_t theInfo[256]; /* Pointer to error text |
| 237 | from system */ |
| 238 | int theLength; /* Length of error text */ |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 239 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 240 | errorCode = GetLastError(); |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 241 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 242 | theLength = FormatMessageW( |
| 243 | FORMAT_MESSAGE_FROM_SYSTEM | |
| 244 | FORMAT_MESSAGE_IGNORE_INSERTS, /* flags */ |
| 245 | NULL, /* message source */ |
| 246 | errorCode, /* the message (error) ID */ |
| 247 | MAKELANGID(LANG_NEUTRAL, |
| 248 | SUBLANG_DEFAULT), |
| 249 | /* Default language */ |
| 250 | theInfo, /* the buffer */ |
Gregory P. Smith | b803c6c | 2013-03-23 16:05:36 -0700 | [diff] [blame] | 251 | sizeof(theInfo) / sizeof(wchar_t), /* size in wchars */ |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 252 | NULL); /* no additional format args. */ |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 253 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 254 | /* Problem: could not get the error message. |
| 255 | This should not happen if called correctly. */ |
| 256 | if (theLength == 0) { |
| 257 | message = PyUnicode_FromFormat( |
| 258 | "DLL load failed with error code %d", |
| 259 | errorCode); |
| 260 | } else { |
| 261 | /* For some reason a \r\n |
| 262 | is appended to the text */ |
| 263 | if (theLength >= 2 && |
| 264 | theInfo[theLength-2] == '\r' && |
| 265 | theInfo[theLength-1] == '\n') { |
| 266 | theLength -= 2; |
| 267 | theInfo[theLength] = '\0'; |
| 268 | } |
| 269 | message = PyUnicode_FromString( |
| 270 | "DLL load failed: "); |
Amaury Forgeot d'Arc | d6179e1 | 2008-01-03 23:42:13 +0000 | [diff] [blame] | 271 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 272 | PyUnicode_AppendAndDel(&message, |
Victor Stinner | 9d3b93b | 2011-11-22 02:27:30 +0100 | [diff] [blame] | 273 | PyUnicode_FromWideChar( |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 274 | theInfo, |
| 275 | theLength)); |
| 276 | } |
Victor Stinner | 67002af | 2011-10-02 20:35:10 +0200 | [diff] [blame] | 277 | if (message != NULL) { |
Richard Oudkerk | 409f902 | 2013-06-10 15:38:54 +0100 | [diff] [blame] | 278 | PyObject *shortname_obj = PyUnicode_FromString(shortname); |
| 279 | PyErr_SetImportError(message, shortname_obj, pathname); |
| 280 | Py_XDECREF(shortname_obj); |
Brian Curtin | 09b86d1 | 2012-04-17 16:57:09 -0500 | [diff] [blame] | 281 | Py_DECREF(message); |
Victor Stinner | 67002af | 2011-10-02 20:35:10 +0200 | [diff] [blame] | 282 | } |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 283 | return NULL; |
| 284 | } else { |
| 285 | char buffer[256]; |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 286 | |
Victor Stinner | 2d32227 | 2011-04-04 23:05:53 +0200 | [diff] [blame] | 287 | PyOS_snprintf(buffer, sizeof(buffer), |
Thomas Heller | 1df0461 | 2004-07-02 08:53:57 +0000 | [diff] [blame] | 288 | #ifdef _DEBUG |
Victor Stinner | 2d32227 | 2011-04-04 23:05:53 +0200 | [diff] [blame] | 289 | "python%d%d_d.dll", |
Thomas Heller | 1df0461 | 2004-07-02 08:53:57 +0000 | [diff] [blame] | 290 | #else |
Victor Stinner | 2d32227 | 2011-04-04 23:05:53 +0200 | [diff] [blame] | 291 | "python%d%d.dll", |
Thomas Heller | 1df0461 | 2004-07-02 08:53:57 +0000 | [diff] [blame] | 292 | #endif |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 293 | PY_MAJOR_VERSION,PY_MINOR_VERSION); |
| 294 | import_python = GetPythonImport(hDLL); |
Mark Hammond | 1f7838b | 2000-10-05 10:54:45 +0000 | [diff] [blame] | 295 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 296 | if (import_python && |
| 297 | strcasecmp(buffer,import_python)) { |
Victor Stinner | 2d32227 | 2011-04-04 23:05:53 +0200 | [diff] [blame] | 298 | PyErr_Format(PyExc_ImportError, |
| 299 | "Module use of %.150s conflicts " |
| 300 | "with this version of Python.", |
| 301 | import_python); |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 302 | FreeLibrary(hDLL); |
| 303 | return NULL; |
| 304 | } |
| 305 | } |
| 306 | p = GetProcAddress(hDLL, funcname); |
| 307 | } |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 308 | |
Antoine Pitrou | f95a1b3 | 2010-05-09 15:52:27 +0000 | [diff] [blame] | 309 | return p; |
Guido van Rossum | 22a1d36 | 1999-12-20 21:18:49 +0000 | [diff] [blame] | 310 | } |