Commit 411fcce
Honor ForbidPythonThreadsAttribute when binding methods (fix GC crash)
MethodObject always constructed its binder with allow_threads = true (the
default), ignoring [ForbidPythonThreads]. The per-method check that upstream
performs (MethodObject.AllowThreads) had been dropped, leaving only a
"TODO: ForbidPythonThreadsAttribute per method info" comment.
As a result, methods marked [ForbidPythonThreads] - e.g.
Runtime.TryCollectingGarbage - released the GIL (PythonEngine.BeginAllowThreads)
around their invocation. Calling the CPython C-API without the GIL corrupts the
interpreter, so the very first PyGC_Collect() inside TryCollectingGarbage
faulted with an access violation (0xC0000005), crashing the host. This is why
test_constructors.py::test_constructor_leak aborted the whole pytest run while
a plain Python gc.collect() (GIL held) was fine.
Port the upstream behavior: compute allow_threads from
ForbidPythonThreadsAttribute on the overloads so such methods keep the GIL.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent f95650f commit 411fcce
1 file changed
Lines changed: 35 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
| |||
30 | 27 | | |
31 | 28 | | |
32 | 29 | | |
33 | | - | |
| 30 | + | |
34 | 31 | | |
35 | 32 | | |
36 | 33 | | |
| |||
42 | 39 | | |
43 | 40 | | |
44 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
45 | 76 | | |
46 | 77 | | |
47 | 78 | | |
| |||
0 commit comments