Repository navigation
feat(c): add libc bindings with native ABI coverage #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1369a5d
f8d2a81
fb6df3b
a009209
b45b3df
d468d94
398a99e
66d060e
99ddac9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| //go:build !(linux && arm64 && !android) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This exclusion is needed because |
||
|
|
||
| /* | ||
| * Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved. | ||
| * | ||
|
|
||
| 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) | ||
| } | ||
| } |
There was a problem hiding this comment.
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, butc.LongDouble/c.LongDoubleSizeare defined solely byldouble_float64.goandldouble_x87.go, whose tags coverlinuxonly onamd64,arm,mips,mipsle. So on other linux arches that otherwise compile (e.g.386,riscv64,s390x— all haveLongdefined viactypes_*.go),c.LongDoubleis still undefined and a plaingo test ./cfails to compilec_test.goexactly 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
LongDoublecoverage (mirror theldouble_*.gounion) or movingTestLongDoubleinto its own file tagged identically toldouble_*.go, and adding a one-line comment explaining the cross-file coupling.