ronaldoussoren / pyobjc

The Python <-> Objective-C Bridge with bindings for macOS frameworks
https://pyobjc.readthedocs.io
552 stars 47 forks source link

Some issues when overriding memory management methods #409

Open ronaldoussoren opened 2 years ago

ronaldoussoren commented 2 years ago

test_nsobject.py found a number of related problems:

  1. The implementation of retain, release and dealloc cannot use objc.super, for some reason that doesn't find the methods This was a bug in the test.

  2. Overriding dealloc and raising in it hangs the interpreter (waiting for the GIL)

  3. The test for overriding dealloc crashes when one of the tests reuses an existing object (see comment)

I haven't investigated either.

Note that this doesn't affect user code, overriding these methods in Python Is never necessary.

ronaldoussoren commented 2 years ago

For (2) this only fails when also implementing the retain method, this ends up with nested GILState_Ensure states (which should work just fine...).

This happens with both 3.9 and 3.10.

ronaldoussoren commented 2 years ago

Next up: try to reproduce in a C extension that does something similar without all of the PyObjC machinery, hopefully that helps pinpointing the issue.

ronaldoussoren commented 2 years ago

As expected a simple extension that uses nested code with and without holding the GIL works just fine. This is almost certainly a bug in PyObjC, and one that requires more thought to fully understand.