From fc3a9862a10c67bba4ba8d02bc76f2d1c8f7ee56 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 22 Apr 2026 13:28:33 -0700 Subject: [PATCH] terminal: fix checkptr failure under -race for cgo.Handle userdata Converting a cgo.Handle (uintptr) directly to unsafe.Pointer in NewTerminal triggered a checkptr "bad pointer value" panic when running tests with -race. The handle is an opaque integer, not a real Go pointer, so checkptr incorrectly rejects it. Extract the conversion into a small handleToPointer helper annotated with //go:nocheckptr to suppress the false positive. --- terminal.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/terminal.go b/terminal.go index 2e0a45a..d29cee8 100644 --- a/terminal.go +++ b/terminal.go @@ -239,7 +239,7 @@ func NewTerminal(opts ...TerminalOption) (*Terminal, error) { C.ghostty_terminal_set( t.ptr, C.GHOSTTY_TERMINAL_OPT_USERDATA, - unsafe.Pointer(t.handle), + handleToPointer(t.handle), ) // Register any effects that were provided via options. @@ -408,3 +408,13 @@ func (t *Terminal) GridRef(point Point) (*GridRef, error) { } return &GridRef{ref: ref}, nil } + +// handleToPointer converts a cgo.Handle (uintptr) to unsafe.Pointer +// for passing as C userdata. The handle is an opaque integer, not a +// real Go pointer, so we suppress checkptr which would otherwise +// reject it under -race. +// +//go:nocheckptr +func handleToPointer(h cgo.Handle) unsafe.Pointer { + return unsafe.Pointer(h) +}