Commit 8740cc3
committed
fix: acquire GIL before C→Go argument conversion in generated CGo wrappers
C.GoString (and other py2go converters) call runtime.gostring → mallocgc
inside a CGo callback. If those conversions run after PyEval_SaveThread
releases the GIL, Go's GC can observe a corrupted sweep-generation counter,
causing "fatal error: bad sweepgen in refill" on Go ≥1.24 / macOS x86_64
(issue #370).
In genFuncBody(), pre-convert each py2go argument into a local variable
while the GIL is held via PyGILState_Ensure/Release, then release the GIL
for the actual Go function call as before. Interface-handle arguments
(ifchandle && goname == "interface{}") are excluded from pre-conversion,
matching the existing callArgs switch logic to avoid type mismatches in
generated code for the iface example.
Also documents Idea 2 (unsafe.String zero-alloc approach) as a future
defence-in-depth option in a code comment.1 parent 55ee3fa commit 8740cc3
1 file changed
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
| 290 | + | |
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
| 298 | + | |
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
| |||
0 commit comments