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

Skip to content

Commit 83dd1de

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 83dd1de

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

setupext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ 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"]}
400-
.get(sys.platform, [])),
399+
libraries=({"linux": ["dl"], "win32": ["psapi", "user32"],
400+
"cygwin": ["psapi"]}.get(sys.platform, [])),
401401
extra_link_args={"win32": ["-mwindows"]}.get(sys.platform, []))
402402
add_numpy_flags(ext)
403403
add_libagg_flags(ext)

src/_tkagg.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
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
19+
* Windows OS, at least currently. Therefore, a symbol may be loaded from a
20+
* module by dlsym() only if it is really located in the given modile,
21+
* dependencies are not included. So we have to use native WinAPI on Cygwin
22+
* also.
23+
*/
24+
#define WIN32_DLL
25+
#endif
26+
27+
#ifdef WIN32_DLL
1428
#include <windows.h>
1529
#define PSAPI_VERSION 1
1630
#include <psapi.h> // Must be linked with 'psapi' library
@@ -122,7 +136,7 @@ int load_tk(T lib)
122136
(Tk_PhotoPutBlock_NoComposite_t)dlsym(lib, "Tk_PhotoPutBlock_NoComposite"));
123137
}
124138

125-
#ifdef _WIN32
139+
#ifdef WIN32_DLL
126140

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

0 commit comments

Comments
 (0)