Skip to content

fix: support python 3.13+ & docstring dedent tests - #405

Draft
b-long wants to merge 4 commits into
masterfrom
fix/py313-plus-and-docstring-dedent-tests
Draft

b-long wants to merge 4 commits into
masterfrom
fix/py313-plus-and-docstring-dedent-tests

Conversation

@b-long

@b-long b-long commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Extends #401

b-long added 4 commits July 31, 2026 15:43
Convert Python-side arguments whose marshalling touches a raw
*C.PyObject (complex64/complex128, via needsGILForArgMarshal) before
releasing the GIL for the wrapped Go call, instead of inline afterward
once it has already been released. Self-bracket buildTuple's
PyTuple_New/PyTuple_SetItem output with PyGILState_Ensure/Release so it
does not rely on its caller already holding the GIL.

Adds a complex64/128 round-trip stress test that hammers the fix from
a churn thread, and TestBuildTupleHoldsGIL.
addSignatureType released the GIL before converting the *C.PyObject
return value from an invoked Python callback back to Go (e.g. via
PyLong_AsLongLong/PyBytes_AsString) and never decref'd it. Both now
happen before PyGILState_Release, closing a live GIL-less window (hit
by any callback with a return value, e.g. _examples/funcs'
CallBackRval) and a one-object-per-call leak.

Drop buildTuple's self-bracketing GIL, added in the previous commit:
its only caller (addSignatureType) already holds the GIL across the
whole build/call/decref region, so the extra Ensure/Release was
redundant. Replace TestBuildTupleHoldsGIL, which only checked the
tuple-build fragment and could pass in the broken case, with a test on
addSignatureType's full output.

Extract argCallExpr as the single function deciding both an argument's
call-site expression and whether it needs GIL premarshalling, so a
premarshalled variable can no longer be declared without also being
the expression consumed at the call site. Trim the complex stress test
from 20000 to 500 iterations; the pre-fix crash is deterministic on
the first call.
CPython 3.13+ strips docstring indentation; update expected test output.
Base automatically changed from fix/proper-fix-gil-handling to master December 1, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant