| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 64f01dd commit 89535be
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -267,8 +267,6 @@ static PyMethodDef functions[] = { | |||
| 267 | 267 | #ifdef DYNAMIC_TKINTER | |
| 268 | 268 | // Functions to fill global TCL / Tk function pointers from tkinter module. | |
| 269 | 269 | ||
| 270 | - #include <dlfcn.h> | ||
| 271 | - | ||
| 272 | 270 | #if PY3K | |
| 273 | 271 | #define TKINTER_PKG "tkinter" | |
| 274 | 272 | #define TKINTER_MOD "_tkinter" | |
@@ -288,6 +286,31 @@ char *fname2char(PyObject *fname) | |||
| 288 | 286 | #define fname2char(s) (PyString_AsString(s)) | |
| 289 | 287 | #endif | |
| 290 | 288 | ||
| 289 | + #if defined(_MSC_VER) | ||
| 290 | + #include <windows.h> | ||
| 291 | + #define LIB_PTR_TYPE HMODULE | ||
| 292 | + #define LOAD_LIB(name) LoadLibrary(name) | ||
| 293 | + #define CLOSE_LIB(name) FreeLibrary(name) | ||
| 294 | + FARPROC _dfunc(LIB_PTR_TYPE lib_handle, const char *func_name) | ||
| 295 | + { | ||
| 296 | + // Load function `func_name` from `lib_handle`. | ||
| 297 | + // Set Python exception if we can't find `func_name` in `lib_handle`. | ||
| 298 | + // Returns function pointer or NULL if not present. | ||
| 299 | + | ||
| 300 | + char message[100]; | ||
| 301 | + | ||
| 302 | + FARPROC func = GetProcAddress(lib_handle, func_name); | ||
| 303 | + if (func == NULL) { | ||
| 304 | + sprintf(message, "Cannot load function %s", func_name); | ||
| 305 | + PyErr_SetString(PyExc_RuntimeError, message); | ||
| 306 | + } | ||
| 307 | + return func; | ||
| 308 | + } | ||
| 309 | + #else | ||
| 310 | + #include <dlfcn.h> | ||
| 311 | + #define LIB_PTR_TYPE void* | ||
| 312 | + #define LOAD_LIB(name) dlopen(name, RTLD_LAZY) | ||
| 313 | + #define CLOSE_LIB(name) dlclose(name) | ||
| 291 | 314 | void *_dfunc(void *lib_handle, const char *func_name) | |
| 292 | 315 | { | |
| 293 | 316 | // Load function `func_name` from `lib_handle`. | |
@@ -303,8 +326,9 @@ void *_dfunc(void *lib_handle, const char *func_name) | |||
| 303 | 326 | } | |
| 304 | 327 | return func; | |
| 305 | 328 | } | |
| 329 | + #endif | ||
| 306 | 330 | ||
| 307 | - int _func_loader(void *lib) | ||
| 331 | + int _func_loader(LIB_PTR_TYPE lib) | ||
| 308 | 332 | { | |
| 309 | 333 | // Fill global function pointers from dynamic lib. | |
| 310 | 334 | // Return 1 if any pointer is NULL, 0 otherwise. | |
@@ -328,7 +352,7 @@ int load_tkinter_funcs(void) | |||
| 328 | 352 | // Load tkinter global funcs from tkinter compiled module. | |
| 329 | 353 | // Return 0 for success, non-zero for failure. | |
| 330 | 354 | int ret = -1; | |
| 331 | - void *tkinter_lib; | ||
| 355 | + LIB_PTR_TYPE tkinter_lib; | ||
| 332 | 356 | char *tkinter_libname; | |
| 333 | 357 | PyObject *pModule = NULL, *pSubmodule = NULL, *pString = NULL; | |
| 334 | 358 | ||
@@ -348,15 +372,15 @@ int load_tkinter_funcs(void) | |||
| 348 | 372 | if (tkinter_libname == NULL) { | |
| 349 | 373 | goto exit; | |
| 350 | 374 | } | |
| 351 | - tkinter_lib = dlopen(tkinter_libname, RTLD_LAZY); | ||
| 375 | + tkinter_lib = LOAD_LIB(tkinter_libname); | ||
| 352 | 376 | if (tkinter_lib == NULL) { | |
| 353 | 377 | PyErr_SetString(PyExc_RuntimeError, | |
| 354 | 378 | "Cannot dlopen tkinter module file"); | |
| 355 | 379 | goto exit; | |
| 356 | 380 | } | |
| 357 | 381 | ret = _func_loader(tkinter_lib); | |
| 358 | 382 | // dlclose probably safe because tkinter has been imported. | |
| 359 | - dlclose(tkinter_lib); | ||
| 383 | + CLOSE_LIB(tkinter_lib); | ||
| 360 | 384 | exit: | |
| 361 | 385 | Py_XDECREF(pModule); | |
| 362 | 386 | Py_XDECREF(pSubmodule); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments