-
-
Notifications
You must be signed in to change notification settings - Fork 29.3k
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
Bug for ctypes when calling name-conflicting functions in shared lib #118892
Comments
This is the expected behavior for the given implementation of libfoo. Here are some options to explore:
|
Hi, thanks a lot for your review. Here are my replies:
My expectation is that, the ctypes loaded functions should search for names inside the shared lib first, just as what the I thinks it may be good to let ctypes to search for names inside the shared lib file first, as default, or warn the users to be careful about the name conflicts. I do physical research myself, and I did not know |
On Linux, the value of the mode constant
POSIX
|
I forgot to address this. |
Thanks a lot for your detailed explanation. I've learned a lot. The
In my example Mimic_ELEGANT.tar.gz, set
|
Use the following for warper.py: import os
from ctypes import *
lib = CDLL("./libelegant.so", mode=os.RTLD_DEEPBIND)
lib.elegant_main() There was an initial Here's the output I get:
|
Hi @eryksun , this perfectly solve my problem. I really appreciate. Although |
Bug report
Bug description:
Hi,
I'm new here, and apologize if not writing this properly.
I found a bug when using ctypes on Ubuntu 22.04.4 LTS 64-bit, and both python versions 3.10.12. and 3.12.2 have been tested. The attachment show how it occurs.
show_ctypes_bug.tar.gz
Unpack this file, go to the folder, and run show_bug.sh. This file firstly create the shared lib libfoo.so, and link to create the executable main. Then it runs the executable and has expected output. But then it runs warper.py, which use ctypes to call the function foo(), and we obtain unexpected results. The outputs are the following:
We can see that
main
has correctly called the functionshcreate
,hdestroy
, andwhateverelse
, butpython warper.py
has not called the correcthcreate
andhdestroy
. The reason is that the self-defined function nameshcreate
andhdestroy
conflict with the system library. The regularly linked executablemain
has correctly treated the conflict, but ctypes has not, and it may have called the functions in the system library instead of the self-defined ones.I also show the testing files in the following:
foo.c
main.c
warper.py
show_bug.sh
CPython versions tested on:
3.12
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: