-
Notifications
You must be signed in to change notification settings - Fork 42
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
old-style callback in Windows worked with cffi 1.16, crashes with cffi 1.17.1. #139
Comments
These lines seem wrong for windows
Looking at the meaning of 1 in the documentation it says
On linux, 1 is Edit: |
Thank you; I was a bit puzzled by the flags on Windows. Changing to flags = ut_ffi.RTLD_LAZY
ut_dll = ut_ffi.dlopen(str(native_lib_path), flags) # Lazy loading then the loading process fails in
0x57 seems to be for ERROR_INVALID_PARAMETER according to https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes--0-499- . |
The logic added in 9c2dfe8 is copied directly from ctypes. But for your example where you specify a relative path, it seems bogus. Does it work if you specify an absolute path, e.g. with |
Ah, modern ctypes does exactly that: they make the path absolute, in https://github.com/python/cpython/blob/dc2552d429c91310b0c410c3e856728d8866b05f/Lib/ctypes/__init__.py#L393 |
Spot on; full_path = os.path.abspath(str(native_lib_path))
ut_dll = ut_ffi.dlopen(full_path, 0) and now it passes even with cffi 1.17.1 So, my legacy hard coded flag 1 was ignored on windows previously when it was using Thank |
Can you try with these changes manually applied? c915708 My github-fu is failing me and I'm not managing to make a pull request containing only this commit. If anyone else wants to do so, please do! |
I will give a try tomorrow morning, see if I can make a PR. Thanks you |
Context
A colleague reported an issue that I first reproduced as a 0xC0000005: Access violation executing location on some windows platforms. After a bit of diagnosing I noticed a change of implementation of
dlopen
for Windows incffi=1.17
, and the crash does not occur withcffi=1.16
.Also relates to this google group post
Repro
A repro is available from jmp75/py-cffi-callback-repro @ f7e1267. The program completes with
cffi==1.16
, but crashes withcffi==1.17.1
when activating the callback:Observations
The change in the underlying implementation of dlopen for Windows may have been motivated by cffi/issues/64 , leading to the change Win32: pass the flags from dlopen() to LoadLibraryEx() #65.
dlopen
under the hood in windows used to callreturn (void *)LoadLibraryA(filename);
and it has now changed toreturn (void *)LoadLibraryExA(filename, NULL, flags);
I note I always passed
flag(s) = 1
, and note it seems to have been previously ignored on Windows.The text was updated successfully, but these errors were encountered: