This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Segfault reading null VMA (works fine in python 2.x)
Type: crash Stage: resolved
Components: ctypes Versions: Python 3.2
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: albertomilone, amaury.forgeotdarc, belopolsky, meador.inge, pitrou
Priority: normal Keywords:

Created on 2012-08-13 12:20 by albertomilone, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
randr_test albertomilone, 2012-08-13 12:20 test-case
Messages (5)
msg168087 - (view) Author: Alberto Milone (albertomilone) Date: 2012-08-13 12:20
The attached test case works fine in Python 2.7 but causes Pyhton 3.2 to segfault.
msg168126 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-08-13 16:46
I can reproduce, but it's not obvious to me what the test does or why it should succeed rather than fail.

For the record, here is the gdb traceback:

#0  0x00007ffff53c6dc8 in XQueryExtension () from /usr/lib64/libX11.so.6
#1  0x00007ffff53ba4d4 in XInitExtension () from /usr/lib64/libX11.so.6
#2  0x00007ffff4959672 in XextAddDisplay () from /usr/lib64/libXext.so.6
#3  0x00007ffff4b5ea96 in ?? () from /usr/lib64/libXrandr.so.2
#4  0x00007ffff4b5ee36 in XRRQueryVersion () from /usr/lib64/libXrandr.so.2
#5  0x00007ffff59274ec in ffi_call_unix64 ()
    at /home/antoine/cpython/default/Modules/_ctypes/libffi/src/x86/unix64.S:75
#6  0x00007ffff5926f5e in ffi_call (cif=0x7fffffffbd30, fn=0x7ffff4b5ee10 <XRRQueryVersion>, rvalue=
    0x7fffffffbe10, avalue=0x7fffffffbde0)
    at /home/antoine/cpython/default/Modules/_ctypes/libffi/src/x86/ffi64.c:492
#7  0x00007ffff590ed27 in _call_function_pointer (flags=4353, pProc=0x7ffff4b5ee10 <XRRQueryVersion>, 
    avalues=0x7fffffffbde0, atypes=0x7fffffffbdb0, restype=0x7ffff5b587e8, resmem=0x7fffffffbe10, argcount=3)
    at /home/antoine/cpython/default/Modules/_ctypes/callproc.c:800
#8  0x00007ffff590f90c in _ctypes_callproc (pProc=0x7ffff4b5ee10 <XRRQueryVersion>, argtuple=
    (0, <CArgObject at remote 0x7ffff5b4c120>, <CArgObject at remote 0x7ffff5b4c350>), flags=4353, argtypes=
    0x0, restype=<_ctypes.PyCSimpleType at remote 0xa171c0>, checker=0x0)
    at /home/antoine/cpython/default/Modules/_ctypes/callproc.c:1143
#9  0x00007ffff5908dec in PyCFuncPtr_call (self=0x7ffff5b4de60, inargs=
    (0, <CArgObject at remote 0x7ffff5b4c120>, <CArgObject at remote 0x7ffff5b4c350>), kwds=0x0)
    at /home/antoine/cpython/default/Modules/_ctypes/_ctypes.c:3804
#10 0x0000000000593e7b in PyObject_Call (func=
    <_FuncPtr(__name__='XRRQueryVersion') at remote 0x7ffff5b4de60>, arg=
    (0, <CArgObject at remote 0x7ffff5b4c120>, <CArgObject at remote 0x7ffff5b4c350>), kw=0x0)
    at Objects/abstract.c:2083
[...]
msg168131 - (view) Author: Alberto Milone (albertomilone) Date: 2012-08-13 17:54
it should just be possible to retrieve major and minor which we pass by reference to XRRQueryVersion. Without this pretty much any other call fails.

Also, it works without problems with python 2.7.
msg168773 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-08-21 14:16
The example script has two errors IMO:
- XOpenDisplay accepts a char*, but display_url is certainly a unicode string; it should be converted to a bytes string::
    xlib.XOpenDisplay(display_url.encode('utf-8'))
- XOpenDisplay.restype is not set, so it will be coerced to a C int (and truncated in the case of a 64bit pointer)

I strongly suggest to set .argtypes and .restype, to ensure proper type check and conversion.
msg168786 - (view) Author: Alberto Milone (albertomilone) Date: 2012-08-21 14:59
I can confirm that the suggested changes solve the problem here. Thanks everyone!
History
Date User Action Args
2022-04-11 14:57:34adminsetgithub: 59842
2012-08-21 21:23:40r.david.murraysetstatus: open -> closed
stage: resolved
2012-08-21 14:59:51albertomilonesetresolution: not a bug
messages: + msg168786
2012-08-21 14:16:39amaury.forgeotdarcsetmessages: + msg168773
2012-08-13 17:54:35albertomilonesetmessages: + msg168131
versions: - Python 3.3
2012-08-13 16:46:40pitrousetnosy: + amaury.forgeotdarc, meador.inge, pitrou, belopolsky

messages: + msg168126
versions: + Python 3.3
2012-08-13 12:20:14albertomilonecreate