Skip to content

cl: newPointer - #703

Merged
xushiwei merged 1 commit into
goplus:devfrom
xushiwei:q
Sep 11, 2026
Merged

cl: newPointer#703
xushiwei merged 1 commit into
goplus:devfrom
xushiwei:q

Conversation

@xushiwei

Copy link
Copy Markdown
Member

No description provided.

@xushiwei
xushiwei merged commit fb0b9de into goplus:dev Sep 11, 2026
2 checks passed

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: cl: newPointer

This PR implements toType/newPointer type conversion, handles void return types in compileFunc, threads a c gogen.PkgRef through blockCtx, and adds a cl/_mod test module. The structure is clean and the void-return handling reads correctly.

Two blocking correctness issues share a root cause: the c package reference is wired to the wrong import path and the wrong symbol name, which together break Int/UInt type resolution. Details inline.

Non-blocking notes:

  • toType (cl/type_and_var.go:66,68) calls ctx.c.Ref(...) per type node; since Int/UInt resolve to the same types.Type for the whole compilation, these could be resolved once at blockCtx construction rather than re-looked-up per occurrence. Optional, low impact.
  • newPointer's tyVoid branch (cl/type_and_var.go:43-48) is currently unreachable: toType has no lc.TypeVoid case, so a void* pointee hits panic("todo: toType ...") before newPointer ever sees tyVoid. Expected given the WIP status, but worth flagging as intended functionality that is silently inert.

No security concerns found. This is a compile-time codegen tool consuming trusted headers.

Comment thread cl/compile.go
// -----------------------------------------------------------------------------

func loadFile(p *gogen.Package, conf *Config, file Source) (pi *PkgInfo, err error) {
c := p.Import("github.com/lib/c")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P0] Wrong import path breaks c package resolution

This imports github.com/lib/c, but the package is github.com/goplus/lib/c everywhere else — the file's own import at compile.go:27, the test stub cl/_mod/stub.go:3, and cl/_mod/go.mod (require github.com/goplus/lib v0.5.2).

This PkgRef is stored in blockCtx.c and used by toType to resolve Int/UInt, so the mismatched path prevents type resolution from working.

c := p.Import("github.com/goplus/lib/c")

Comment thread cl/type_and_var.go
case lc.TypeInt:
return ctx.c.Ref("Int").Type()
case lc.TypeUInt:
return ctx.c.Ref("UInt").Type()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P0] Ref("UInt") does not exist; symbol is Uint

github.com/goplus/lib/c v0.5.2 defines the unsigned-int alias as Uint (Uint = uint32 in c/c.go:38), not UInt. ctx.c.Ref("UInt") will fail to resolve the object.

		return ctx.c.Ref("Uint").Type()

The adjacent Ref("Int") on line 66 is correct since Int exists.

Comment thread cl/type_and_var.go
)

var (
tyVoid = types.Typ[types.UntypedNil]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P3] tyVoid bound to UntypedNil is surprising

tyVoid is bound to types.Typ[types.UntypedNil] and compared in newPointer to emit unsafe.Pointer. This works, but the name suggests a distinct void type rather than the untyped-nil sentinel. A short comment explaining that untyped-nil is used as the void sentinel would prevent future confusion. Minor / WIP, non-blocking.

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