Skip to content

DRAFT relating to three seventy#1

Draft
b-long wants to merge 10 commits into
masterfrom
fix/issue-370-v2
Draft

DRAFT relating to three seventy#1
b-long wants to merge 10 commits into
masterfrom
fix/issue-370-v2

Conversation

@b-long
Copy link
Copy Markdown
Owner

@b-long b-long commented May 8, 2026

No description provided.

@b-long b-long force-pushed the fix/issue-370-v2 branch from 513e1a5 to aa42e5f Compare May 8, 2026 00:11
b-long added 4 commits May 7, 2026 20:26
malloc(strlen(str)) left no room for the null terminator; sprintf wrote
one byte past the end, corrupting the next heap chunk.  Previously masked
by GOGC=off; now detected by glibc malloc with normal GC enabled.
Python's gc.collect() releases Python wrappers and calls DecRef(), removing
Go objects from the handle map.  However, Go's own GC does not run at that
point, so Go-heap memory (structs, slices) stays resident until Go's
allocator threshold is reached.  On macOS, ru_maxrss is in bytes instead of
KB, making the leak threshold meaningful (~82 MB), so the second test pass
can see RSS growth before Go GC has had a chance to reclaim the first
pass's allocations -- causing a false-positive leak report.

Fix in bind/gen.go:
- Add RunGC() (calls runtime.GC()) to the generated Go extension.
- Register a Python gc.callbacks handler in the generated Python wrapper
  that calls _{pkg}.RunGC() whenever Python GC stops.  This is transparent
  to users: Go GC fires automatically after every Python GC cycle, keeping
  the two runtimes in sync without any user-visible API change.

Remove the darwin skip from main_test.go: now that Go GC is synchronised
with Python GC, TestCStrings is reliable on all platforms including both
macOS/Intel and macOS/ARM.
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.

2 participants