[New-bugs-announce] [issue7160] Crash when returning a 64-bit char pointer in Python 2.6.3 ctypes
Michael J. Fromberger
report at bugs.python.org
Sat Oct 17 18:31:04 CEST 2009
New submission from Michael J. Fromberger <michael.j.fromberger at gmail.com>:
A segmentation fault is generated in _ctypes.so when calling a function that returns a char pointer on a system
with 64-bit pointer types. The attached crash dump is from a Python 2.6.3 built from MacPorts ("port install
python26 +no_tkinter"), but the same behaviour occurs with the Python 2.6.1 installed by Apple.
To reproduce, build the attached sample program ("testlib.c"):
% gcc -Wall -c testlib.o
% ld -dylib -o testlib.so 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
MacOS 10.6.1
Darwin gorion.local 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-
1456.1.25~1/RELEASE_I386 i386
% python
Python 2.6.3 (r263:75183, Oct 17 2009, 01:49:30)
[GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin
% gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646) (dot 1)
----------
assignee: theller
components: ctypes
files: testlib.c
messages: 94181
nosy: creachadair, theller
severity: normal
status: open
title: Crash when returning a 64-bit char pointer in Python 2.6.3 ctypes
type: crash
versions: Python 2.6
Added file: http://bugs.python.org/file15154/testlib.c
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7160>
_______________________________________
More information about the New-bugs-announce
mailing list