-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18277 from lazka/update-python
Update Python
- Loading branch information
Showing
3 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
From a6cef77b4664e68982438130164b4cf120eca13f Mon Sep 17 00:00:00 2001 | ||
From: Christoph Reiter <reiter.christoph@gmail.com> | ||
Date: Sun, 27 Aug 2023 15:00:32 +0200 | ||
Subject: [PATCH 146/N] Port GetPythonImport() to mingw | ||
|
||
This looks for DLL names in the import table but while with MSVC the DLL | ||
is named python311.dll in our case it is named libpython3.11.dll. | ||
Adjust the strings and lengths accordingly. | ||
--- | ||
Python/dynload_win.c | 24 +++++++++++++++++------- | ||
1 file changed, 17 insertions(+), 7 deletions(-) | ||
|
||
diff --git a/Python/dynload_win.c b/Python/dynload_win.c | ||
index fcb7321..8a3ef4d 100644 | ||
--- a/Python/dynload_win.c | ||
+++ b/Python/dynload_win.c | ||
@@ -56,6 +56,16 @@ const char *_PyImport_DynLoadFiletab[] = { | ||
#define DWORD_AT(mem) (*(DWORD *)(mem)) | ||
#define WORD_AT(mem) (*(WORD *)(mem)) | ||
|
||
+#ifdef __MINGW32__ | ||
+#define DLL_PREFIX "libpython" | ||
+#define DLL_PREFIX_LEN 9 | ||
+#define DLL_NAME_FORMAT "libpython%d.%d" | ||
+#else | ||
+#define DLL_PREFIX "python" | ||
+#define DLL_PREFIX_LEN 6 | ||
+#define DLL_NAME_FORMAT "python%d%d" | ||
+#endif | ||
+ | ||
static char *GetPythonImport (HINSTANCE hModule) | ||
{ | ||
unsigned char *dllbase, *import_data, *import_name; | ||
@@ -122,15 +132,15 @@ static char *GetPythonImport (HINSTANCE hModule) | ||
import_off); | ||
while (DWORD_AT(import_data)) { | ||
import_name = dllbase + DWORD_AT(import_data+12); | ||
- if (strlen(import_name) >= 6 && | ||
- !strncmp(import_name,"python",6)) { | ||
+ if (strlen(import_name) >= DLL_PREFIX_LEN && | ||
+ !strncmp(import_name, DLL_PREFIX, DLL_PREFIX_LEN)) { | ||
char *pch; | ||
|
||
/* Don't claim that python3.dll is a Python DLL. */ | ||
#ifdef _DEBUG | ||
- if (strcmp(import_name, "python3_d.dll") == 0) { | ||
+ if (strcmp(import_name, DLL_PREFIX "3_d.dll") == 0) { | ||
#else | ||
- if (strcmp(import_name, "python3.dll") == 0) { | ||
+ if (strcmp(import_name, DLL_PREFIX "3.dll") == 0) { | ||
#endif | ||
import_data += 20; | ||
continue; | ||
@@ -138,7 +148,7 @@ static char *GetPythonImport (HINSTANCE hModule) | ||
|
||
/* Ensure python prefix is followed only | ||
by numbers to the end of the basename */ | ||
- pch = import_name + 6; | ||
+ pch = import_name + DLL_PREFIX_LEN; | ||
#ifdef _DEBUG | ||
while (*pch && pch[0] != '_' && pch[1] != 'd' && pch[2] != '.') { | ||
#else | ||
@@ -329,9 +339,9 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, | ||
|
||
PyOS_snprintf(buffer, sizeof(buffer), | ||
#ifdef _DEBUG | ||
- "python%d%d_d.dll", | ||
+ DLL_NAME_FORMAT "_d.dll", | ||
#else | ||
- "python%d%d.dll", | ||
+ DLL_NAME_FORMAT ".dll", | ||
#endif | ||
PY_MAJOR_VERSION,PY_MINOR_VERSION); | ||
import_python = GetPythonImport(hDLL); |
50 changes: 50 additions & 0 deletions
50
mingw-w64-python/0147-LoadLibraryExW-make-sure-to-only-use-backslashes-for.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
From 7a3aacf3cba0c35f8621a78fc2d239fe2c878c63 Mon Sep 17 00:00:00 2001 | ||
From: Christoph Reiter <reiter.christoph@gmail.com> | ||
Date: Sun, 27 Aug 2023 16:04:50 +0200 | ||
Subject: [PATCH 147/N] LoadLibraryExW: make sure to only use backslashes for | ||
paths | ||
|
||
It seems like in case the path passed to it is absolute, but contains | ||
forward slashes then LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR does not work | ||
and DLLs in the same directory as the extension are not considered. | ||
|
||
This occurs in our fork because in MSYS2-mode the extension loader will | ||
normalize to forward slashes before. | ||
|
||
Normalize everything to backslashes again before passing it to LoadLibraryExW. | ||
|
||
Fixes #151 | ||
--- | ||
Python/dynload_win.c | 12 ++++++++++++ | ||
1 file changed, 12 insertions(+) | ||
|
||
diff --git a/Python/dynload_win.c b/Python/dynload_win.c | ||
index 8a3ef4d..cd15e4a 100644 | ||
--- a/Python/dynload_win.c | ||
+++ b/Python/dynload_win.c | ||
@@ -250,6 +250,9 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, | ||
_Py_CheckPython3(); | ||
#endif | ||
|
||
+// So we can adjust the separators in the path below | ||
+#define USE_UNICODE_WCHAR_CACHE 0 | ||
+ | ||
#if USE_UNICODE_WCHAR_CACHE | ||
const wchar_t *wpathname = _PyUnicode_AsUnicode(pathname); | ||
#else /* USE_UNICODE_WCHAR_CACHE */ | ||
@@ -258,6 +261,15 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, | ||
if (wpathname == NULL) | ||
return NULL; | ||
|
||
+ // LoadLibraryExW only considers paths using backslashes as "fully qualified", | ||
+ // and for example LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR doesn't work with forward slashes. | ||
+ // https://github.com/msys2-contrib/cpython-mingw/issues/151 | ||
+ for (size_t i = 0; wpathname[i] != L'\0'; ++i) { | ||
+ if (wpathname[i] == L'/') { | ||
+ wpathname[i] = L'\\'; | ||
+ } | ||
+ } | ||
+ | ||
PyOS_snprintf(funcname, sizeof(funcname), "%.20s_%.200s", prefix, shortname); | ||
|
||
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters