1. Ronald Oussoren
  2. pyobjc

Issues

Issue #28 resolved

Segmentation fault when using CGEvents

Anonymous created an issue

I get a segmentation fault when running this code https://gist.github.com/4135908 in python2.7 and python3. It works in python2.6, but that might be that I have a very old version of pyobjc installed (I am unsure of how to check which version it has).

Comments (5)

  1. Ronald Oussoren repo owner

    The version of pyobjc is in the version attribute of module objc:

    >>> objc.__version__
    2.5b1
    

    I can reproduce the issue on my machine using recent check-outs of both pyobjc and python 2.7.x.

  2. Ronald Oussoren repo owner

    The problem appears to be in the CGEvent bindings:

    Program received signal EXC_BAD_ACCESS, Could not access memory.
    Reason: KERN_INVALID_ADDRESS at address: 0x00000001299346b1
    0x00007fff87036490 in objc_msgSend_vtable3 ()
    (gdb) where 10
    #0  0x00007fff87036490 in objc_msgSend_vtable3 ()
    #1  0x00000001004e0eac in pythonify_c_value () at   Modules/objc/objc_support.m:1752
    #2  0x00000001004edf1c in ID_to_py (idValue=0x1012dbf10) at Modules/objc/pointer-support.m:113
    #3  0x00000001004e0f09 in pythonify_c_value () at Modules/objc/objc_support.m:1797
    #4  0x00000001030deccd in m_CGEventTapCallBack (proxy=0x1012dbf10, type=10, event=0x1014bbd90, _info=0x104a885f0) at Modules/_callbacks.m:1511
    #5  0x00007fff8e2632d7 in processEventTapData ()
    #6  0x00007fff8e262f68 in _CGYPostEventTapData ()
    #7  0x00007fff8e26826a in _XPostEventTapData ()
    #8  0x00007fff8e268362 in CGYEventTap_server ()
    #9  0x00007fff8e263056 in eventTapMessageHandler ()
    (More stack frames follow...)
    

    Line 1511 in _callbacks.m tries to create a python representation for the CGEventTapProxy argument of the callback and that causes a crash.

    And looking at the documentation for even taps at http://developer.apple.com/library/mac/documentation/Carbon/Reference/QuartzEventServicesRef/Reference/reference.html#//apple_ref/doc/c_ref/CGEventTapProxy I see that an CGEventTabProxy isn't an object at all.

    Actions for me:

    1) Check if the C code in Modules/_callback.m is really necessary. With some luck the generic callback handling code can be used here (although that might cause a small interface change, and hence couldn't be done as soon as I'd like)

    2) Register 'CGEventTapProxy' as an opaque pointer type ("handle")

    3) Use that pointer type to create the python representation in _callback.m (or whatever replaces callback.m)

  3. Ronald Oussoren repo owner

    I've fixed the issue by registering CGEvenTapProxy as an opaque pointer instead of as a CFType. The code in _callbacks.m is unchanged, cleaning up that file can wait.

  4. Log in to comment