Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6c54c13

Browse files
committed
Cygwin fixes
Use native windows API for loading symbols from dlls instead of libdl. dlsym() inherits underlying Windows restrictions and does not find symbols located in dependencies of the library being explored. This fixes issue #5962
1 parent 22eade6 commit 6c54c13

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

setupext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def get_extensions(self):
396396
include_dirs=["src"],
397397
# psapi library needed for finding Tcl/Tk at run time.
398398
# user32 library needed for window manipulation functions.
399-
libraries=({"linux": ["dl"], "win32": ["psapi", "user32"]}
399+
libraries=({"linux": ["dl"], "win32": ["psapi", "user32"], "cygwin": ["psapi"]}
400400
.get(sys.platform, [])),
401401
extra_link_args={"win32": ["-mwindows"]}.get(sys.platform, []))
402402
add_numpy_flags(ext)

src/_tkagg.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111
#include <Python.h>
1212

1313
#ifdef _WIN32
14+
#define WIN32_DLL
15+
#endif
16+
#ifdef __CYGWIN__
17+
/*
18+
* Unfortunately cygwin's libdl inherits restrictions from the underlying Windows OS,
19+
* at least currently. Therefore, a symbol may be loaded from a module by dlsym() only
20+
* if it is really located in the given modile, dependencies are not included.
21+
* Cygwin does not honor the software accessing underlying WinAPI directly, but we
22+
* seem to have no other way here, and we're doing it carefully; all the magic is
23+
* localized in this file.
24+
*/
25+
#define WIN32_DLL
26+
#endif
27+
28+
#ifdef WIN32_DLL
1429
#include <windows.h>
1530
#define PSAPI_VERSION 1
1631
#include <psapi.h> // Must be linked with 'psapi' library
@@ -122,7 +137,7 @@ int load_tk(T lib)
122137
(Tk_PhotoPutBlock_NoComposite_t)dlsym(lib, "Tk_PhotoPutBlock_NoComposite"));
123138
}
124139

125-
#ifdef _WIN32
140+
#ifdef WIN32_DLL
126141

127142
/*
128143
* On Windows, we can't load the tkinter module to get the Tk symbols, because

0 commit comments

Comments
 (0)