Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak the logic for LoadLibraryEx() calls following ctypes #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/c/misc_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,19 @@ static PyObject *b_getwinerror(PyObject *self, PyObject *args, PyObject *kwds)
#define RTLD_GLOBAL 0
#define RTLD_LOCAL 0

#define MAX_BUF_FULLPATH 32768

static void *dlopen(const char *filename, int flags)
{
char buffer[MAX_BUF_FULLPATH];
if (flags == 0) {
flags = LOAD_LIBRARY_SEARCH_DEFAULT_DIRS;
for (const char *p = filename; *p != 0; p++)
if (*p == '\\' || *p == '/') {
flags = LOAD_LIBRARY_SEARCH_DEFAULT_DIRS |
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
DWORD r = GetFullPathNameA(filename, MAX_BUF_FULLPATH, buffer, NULL);
if (r > 0 && r < MAX_BUF_FULLPATH)
filename = buffer;
flags |= LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
break;
}
}
Expand All @@ -206,11 +212,15 @@ static void *dlopen(const char *filename, int flags)

static void *dlopenWinW(const wchar_t *filename, int flags)
{
wchar_t buffer[MAX_BUF_FULLPATH];
if (flags == 0) {
flags = LOAD_LIBRARY_SEARCH_DEFAULT_DIRS;
for (const wchar_t *p = filename; *p != 0; p++)
if (*p == '\\' || *p == '/') {
flags = LOAD_LIBRARY_SEARCH_DEFAULT_DIRS |
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
DWORD r = GetFullPathNameW(filename, MAX_BUF_FULLPATH, buffer, NULL);
if (r > 0 && r < MAX_BUF_FULLPATH)
filename = buffer;
flags |= LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR;
break;
}
}
Expand Down
Loading