cython / cython

The most widely used Python to C compiler

Home Page:https://cython.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Unnecessary refnanny gil handling in __init__/__del__ (and maybe other slots)

da-woods opened this issue · comments

Describe the bug

The __init__ and __del__ slots generate code like:

  __Pyx_RefNannySetupContext("__del__", 1);

where the 1 is an indication of "may need to acquire the GIL". I'm fairly sure this is unnecessary. The "wrapper" functions are correct though with

__Pyx_RefNannySetupContext("__del__ (wrapper)", 0);

Code to reproduce the behaviour:

class C:
    def __init__(self):
        pass
    def __del__(self):
        pass

Expected behaviour

Not trying to acquire the GIL

OS

Linux

Python version

3.11

Cython version

Current master 19f67cb

Additional context

This is fairly low priority in that refnanny is only really a testing tool, and the code generated still works. It does appear to affect a free-threading bug (#6214 (comment)) but I think that's mainly a Python bug and you could hit it in other ways.

Fixed in 67be460