Skip to content
2 changes: 2 additions & 0 deletions c/c_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !(linux && arm64 && !android)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The exclusion only special-cases linux/arm64, but c.LongDouble/c.LongDoubleSize are defined solely by ldouble_float64.go and ldouble_x87.go, whose tags cover linux only on amd64, arm, mips, mipsle. So on other linux arches that otherwise compile (e.g. 386, riscv64, s390x — all have Long defined via ctypes_*.go), c.LongDouble is still undefined and a plain go test ./c fails to compile c_test.go exactly as it did before, since those arches aren't excluded here.

This fixes the one arch the PR adds bindings for while leaving the broader gap. Consider tying the constraint to the real LongDouble coverage (mirror the ldouble_*.go union) or moving TestLongDouble into its own file tagged identically to ldouble_*.go, and adding a one-line comment explaining the cross-file coupling.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This exclusion is needed because c.LongDouble / c.LongDoubleSize are undefined on linux/arm64: ldouble_x87.go is amd64-only and ldouble_float64.go's constraint covers arm (32-bit) but not linux && arm64. So the build tag works around a real platform gap rather than fixing it — on linux/arm64 c.LongDouble simply does not exist, even though the other two native targets (linux/amd64, darwin/arm64) have it, so any user code referencing it there won't compile. Note AArch64 long double is IEEE binary128 (16 bytes), so adding linux/arm64 to ldouble_float64.go (8 bytes) would be wrong — it needs its own 16-byte definition. Consider a brief comment here explaining the exclusion, and tracking proper linux/arm64 LongDouble support as follow-up.


/*
* Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved.
*
Expand Down
53 changes: 53 additions & 0 deletions c/generated_native_llgo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//go:build llgo && ((darwin && arm64 && !ios) || (linux && (amd64 || arm64) && !android))

package c_test

import (
"github.com/goplus/lib/c"
"testing"
"unsafe"
)

func TestGeneratedMemoryCalls(t *testing.T) {
input := [6]byte{0, 1, 127, 128, 254, 255}
var output [6]byte
if p := c.Memcpy(unsafe.Pointer(&output[0]), unsafe.Pointer(&input[0]), 6); p != unsafe.Pointer(&output[0]) {
t.Fatal("memcpy returned another buffer")
}
if output != input || c.Memcmp(unsafe.Pointer(&output[0]), unsafe.Pointer(&input[0]), 6) != 0 {
t.Fatal("native memory copy differs")
}
c.Memset(unsafe.Pointer(&output[0]), 0, 6)
if output != [6]byte{} {
t.Fatalf("memset result %v", output)
}
value := c.Str("native libc")
if got := c.Strlen(value); got != 11 {
t.Fatalf("strlen = %d, want 11", got)
}
}
func TestGeneratedStdioCalls(t *testing.T) {
stream := c.Tmpfile()
if stream == nil {
t.Fatal("tmpfile returned nil")
}
defer func() {
if result := c.Fclose(stream); result != 0 {
t.Errorf("fclose = %d", result)
}
}()
input := [6]byte{0, 1, 127, 128, 254, 255}
var output [6]byte
if got := c.Fwrite(unsafe.Pointer(&input[0]), 1, 6, stream); got != 6 {
t.Fatalf("fwrite = %d", got)
}
if got := c.Fseek(stream, 0, 0); got != 0 {
t.Fatalf("fseek = %d", got)
}
if got := c.Fread(unsafe.Pointer(&output[0]), 1, 6, stream); got != 6 {
t.Fatalf("fread = %d", got)
}
if output != input {
t.Fatalf("stdio result %v, want %v", output, input)
}
}
Loading
Loading