Seg fault on 2.7.14 and 3.6.3 OSX both system and brewed

Issue #223 resolved
Dave Fuller
created an issue

Happens with Cocoa, ScriptingBridge, and AppleScriptKit yet not objc. Is it expected to seg fault and burn?

tokyoghoul:python dave$ export PYTHONMALLOC=debug
tokyoghoul:python dave$ which python3
tokyoghoul:python dave$ python3
Python 3.6.3 (default, Nov 25 2017, 20:57:42) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Cocoa
>>> import objc
>>> help(Cocoa)
Fatal Python error: Segmentation fault

.... Continued in attachment

Comments (9)

  1. Ronald Oussoren repo owner

    Thanks for your report. This turned out the be incomplete error handling in the C extension for PyObjC, combined with some Objective-C methods that have Objective-C runtime information that PyObjC doesn't understand.

    I'm about to commit a fix for this.

    However: note that help(Cocoa) is not very useful due to the sheer size of the output, 4.5 million lines!, (and the time needed to calculate that output). Looking at the help for specific objects/functions/classes can be useful though.

    The easiest way to learn about the API is to read Apple's documentation, combined with PyObjC's mapping to Python syntax (as described here).

    In general I'm trying to expose the entire API of Apple's frameworks to Python, the exceptions are documented on PyObjC's website

  2. Dave Fuller reporter

    I actually use Dash for doc. I use PyCharm for development. I had wondered if the Docstrings were something that were used to provide hinting in PyCharm so I went to see what kind of information was available since I've never used Python help before. Its was simply serendipitous that I choked the interpreter.

  3. Ronald Oussoren repo owner

    W.r.t. PyCharm: I'm using issue #212 to track problems w.r.t. PyCharm not understanding PyObjC's framework wrappers. I don't use PyCharm myself and haven't had time to look into this yet.

    This might be related to this crash, but might also be caused by the fairly non-standard class hierarchy used by PyObjC (Cocoa's class methods are represented as methods on a metaclass instead of as @classmethod descriptors on the class. The result of this is that every Cocoa class (like NSObject) has its own metaclass and that tends to confuse tools.

  4. Dave Fuller reporter

    Well, if python help(sb) can return the documentation, including the methods of the app to which sb (ScriptingBridge) was connected, I do not see why there would be a problem with introspection. Unless, that is, PyCharm is starting from the framework and drilling down for some reason. Maybe a preload of the RTTI.

    I use PyCharm because on the right hand side of the terminal you can see and inspect all the instances that are loaded into the environment. It will create and manage virtual environments too.

    Screenshot 2017-11-30 00.21.01.png

    Though, the way doc is structured these days I sometimes think it could be more useful RTTI than actual RTTI. And, if they are preloading then they might as well figure out a way to incorporate the doc.

    I haven't yet applied the fix since I wasn't sure if you were going to push a release soon.

  5. Log in to comment