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