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

Exit code appears when using _ffi.dlopen #132

Open
kjdsfbchkadwbcuiwbcfiw opened this issue Sep 25, 2024 · 3 comments
Open

Exit code appears when using _ffi.dlopen #132

kjdsfbchkadwbcuiwbcfiw opened this issue Sep 25, 2024 · 3 comments

Comments

@kjdsfbchkadwbcuiwbcfiw
Copy link

I recently encountered an issue while executing the following Python code on my Windows 11 system:

> import cffi
> _ffi = cffi.FFI()
> _ffi.cdef("int raise(int);")
> _lib = _ffi.dlopen("api-ms-win-crt-runtime-l1-1-0.dll")

Upon running this script, the process terminated abruptly with an exit code of -1073740791 (0xC0000409). I verified that the 'api-ms-win-crt-runtime-l1-1-0.dll' file is located in the C:\Windows\System32\downlevel directory. Could you please help me identify the cause of this problem?

@arigo
Copy link
Contributor

arigo commented Sep 25, 2024

I have no solid idea, but my guess would be that loading this DLL into the Python process just crashes; this might be because the DLL contains code to make sure that you don't try to load multiple incompatible versions of the basic "crt" runtime.

I'm unsure what you are trying to do. If you want to call a basic function like raise() then it should be provided by the standard C library that the Python process is using, which might be a different one. I'm not sure how you do that, but Google might help. Maybe you can find about it by googling "how to find out which standard C library DLL a process is using on Windows" or something with the keyword "ctypes".

@arigo
Copy link
Contributor

arigo commented Sep 25, 2024

Note: if I remember correctly, on Python 2.7 you could use ffi.dlopen(None) to do exactly that. This doesn't work any more on Python 3.x.

Note 2: if you have the compiler toolchain, then you can just call ffi.setsource("#include <signal.h>") and ffi.compile() and it should work out of the box.

Note 3: if all you want is call raise(), note that you should be able to just use the signal module from Python.

@kjdsfbchkadwbcuiwbcfiw
Copy link
Author

This is not my code. I encountered this error when importing the trio library, so I checked the source code of the library and found that the problem was caused by the code above. Thank you for your reply, I will take a closer look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants