NSTextInputContext segfaults on destruction Mac OS 10.13.2

Issue #235 invalid
Ilia Pozhilov
created an issue

This simple script segfaults reproducibly:

from AppKit import NSTextInputContext
ic = NSTextInputContext.new()

Attached are stacktraces reported by mac os in "Send Report" dialog. stacktrace is for python from homebrew and pip2 install'ed pyobjc, stacktrace.system is from system pyobjc (_AppKit.so dated Dec 1 somehow, don't quite sure how it's installed to the system).

Comments (7)

  1. Ronald Oussoren repo owner


    Annoyingly enough I haven't been able to reproduce the problem.

    • What is the value of objc.__version__?

    • What is the value of objc.__file__?

    • What is the version of Python?

    • What is the version of macOS?

  2. Ilia Pozhilov reporter

    System python + system pyobjc

    >>> objc.__version__
    >>> objc.__file__
    python 2.7.10

    mac os as in the subject line: 10.13.2 High Sierra

  3. Ilia Pozhilov reporter

    Homebrew python + homebrew pyobjc

    >>> objc.__version___
    >>> objc.__file__
    python version 2.7.14
  4. Ilia Pozhilov reporter

    Have you been able to reproduce? It is reproduced on machines of a couple of colleagues. I have to manually patch code of some tools I use, don't see any other way to continue working. Can I help in any way?

  5. Ronald Oussoren repo owner

    I finally managed te reproduce:

    Python 3.6.3 (v3.6.3:2c5fed86e0, Oct  3 2017, 00:32:08) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from AppKit import NSTextInputContext
    >>> ic = NSTextInputContext.new()
    >>> del ic
    Segmentation fault: 11

    The line with del ic was necessary to get a crash. I haven't tried to debug the issue yet, but it looks like this is not a PyObjC bug but is instead a crash due to Apple not guarding agains incorrect API usage.

    In particular, the Objective-C code below does the same as my shell fragment and also crashes:

    #import <Cocoa/Cocoa.h>
    int main(void)
            NSTextInputContext* v = [NSTextInputContext new];
            NSLog(@"%@", v);
            [v release];

    The documentation for NSTextInputContext says that the initialiser is -[NSTextInputContext initWithClient:] and doesn't mention the argument less init method. The header file mentions that the init method is not available.

    All in all I'm fairly sure that this is not something I can fix in PyObjC: This is another example of how Apple's frameworks can crash when used incorrectly.

  6. Ilia Pozhilov reporter

    Oh, okay, thank you very much! Really looks like the bugreport is incorrect. I'm just trying to fix a bug in certain software that started crashing after updating mac os. This code is the minimal sample I could come up with, but now it looks like the bug is actually in the code of that software. Will report there then, thank you!

  7. Log in to comment