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
Crash when returning a 64-bit char pointer in Python 2.6.3 ctypes #51409
Comments
A segmentation fault is generated in _ctypes.so when calling a function that returns a char pointer on a system To reproduce, build the attached sample program ("testlib.c"): % gcc -Wall -c testlib.o Then, in Python: # Common setup for each of the cases below.
>>> from ctypes import *
>>> lib = CDLL('testlib.so')
# Case 1: Integer return value (no crash).
>>> get_value = CFUNCTYPE(c_int)(lib.get_value)
>>> get_value()
12345
# Case 2: Pointer argument value (no crash).
>>> buf = create_string_buffer(256)
>>> copy_message = CFUNCTYPE(None, c_char_p)(lib.copy_message)
>>> copy_message(buf)
# Case 3: Pointer return value (crash).
>>> get_message = CFUNCTYPE(c_char_p)(lib.get_message)
>>> get_message()
Segmentation fault -- System information: % uname -a % python % gcc --version |
I believe this error occurs because a pointer value is being truncated to KERN_INVALID_ADDRESS at 0x00000000002fe020 If you add a diagnostic printout to the body of get_message(), you will |
You are using I think what you are really looking for is |
Thank you for setting me straight. I see now that I misunderstood the scope of [1] <http://www.python.org/doc/2.6.3/library/ctypes.html#function- |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: