Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends #401