Skip to content

rm c/bdwgc - #58

Closed
xushiwei wants to merge 1 commit into
goplus:mainfrom
xushiwei:q
Closed

xushiwei wants to merge 1 commit into
goplus:mainfrom
xushiwei:q

Conversation

@xushiwei

Copy link
Copy Markdown
Member

No description provided.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: rm c/bdwgc

This PR deletes the entire c/bdwgc package. The intent is clear, but the deletion is incomplete: an in-tree dependent still imports the removed package, which breaks the default build.


🔴 Blocker — dangling import breaks the default build

cpp/std/std_gc.go still imports and uses the deleted package:

  • cpp/std/std_gc.go:26 — import "github.com/goplus/lib/c/bdwgc"
  • cpp/std/std_gc.go:32 — bdwgc.Malloc(unsafe.Sizeof(String{}))
  • cpp/std/std_gc.go:33 — bdwgc.RegisterFinalizer(...)

This file is the default build variant (//go:build !nogc); std_nogc.go only compiles under -tags nogc. So the standard build path is broken, not an edge case. Verified against the toolchain:

$ go vet ./cpp/std/
cpp/std/std_gc.go:26:2: no required module provides package github.com/goplus/lib/c/bdwgc

(go vet -tags nogc ./cpp/std/ passes, confirming only the default path is affected.)

This must be resolved in the same change — either don't delete c/bdwgc, or migrate allocString() in std_gc.go off the bdwgc API.


⚠️ When fixing: preserve finalizer semantics (don't just copy the nogc path)

std_gc.go and std_nogc.go have intentionally different allocString():

  • GC path (std_gc.go): bdwgc.Malloc + RegisterFinalizer(... Dispose()) — the GC reclaims the String wrapper and runs Dispose() to free the underlying std::string buffer when the object becomes unreachable.
  • nogc path (std_nogc.go:30-33): plain c.Malloc, no finalizer, no free.

If std_gc.go is "fixed" by simply cloning the nogc body, the default build would silently lose automatic Dispose(), leaking the String struct and the std::string buffer on every NewString*/Str call (cpp/std/string.go). Whatever lands should keep finalizer-backed cleanup for the GC build, or give callers an explicit ownership/Dispose() contract.


📝 Minor notes

  • Scope / consistency: c/pthread/pthread_gc.go still links bdw-gc (LLGoPackage = "link: $(pkg-config --libs bdw-gc); -lgc", line 29) and binds C.GC_pthread_create / C.GC_pthread_join (lines 58, 79). It does not import the deleted Go package, so it's not broken — but if the goal is to drop bdw-gc entirely, this leaves a half-migration worth clarifying. If the goal is only to remove the typed Go binding while bdw-gc stays a runtime dependency, that's worth stating too.
  • Breaking change / rationale: The commit message is just rm c/bdwgc with no body. Removing an exported package path is a breaking change for downstream importers; a short rationale and a note on the cpp/std impact would help reviewers and consumers.

Recommendation: Resolve the cpp/std/std_gc.go import before merge and confirm go build ./... / go vet ./... pass in both default and -tags nogc configurations.

@xushiwei xushiwei closed this Oct 24, 2026
@xushiwei
xushiwei deleted the q branch October 24, 2026 13:59
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