From 0bbdb6c2046a7da49adb28e965f948f9bd4e9c01 Mon Sep 17 00:00:00 2001 From: Haolan Date: Wed, 10 Sep 2025 14:14:22 +0800 Subject: [PATCH] fix: change clite's LLGoPackage to true to execute its init() --- 1 | 6 ++++++ runtime/internal/clite/c.go | 3 ++- runtime/internal/clite/stdio_baremetal.go | 13 ++++++++----- runtime/internal/runtime/z_print.go | 12 ------------ 4 files changed, 16 insertions(+), 18 deletions(-) create mode 100644 1 diff --git a/1 b/1 new file mode 100644 index 00000000..203b44de --- /dev/null +++ b/1 @@ -0,0 +1,6 @@ +Merge branch 'main' of https://github.com/goplus/llgo into emb-runtime +# Please enter a commit message to explain why this merge is necessary, +# especially if it merges an updated upstream into a topic branch. +# +# Lines starting with '#' will be ignored, and an empty message aborts +# the commit. diff --git a/runtime/internal/clite/c.go b/runtime/internal/clite/c.go index dbbe80d9..53d06c61 100644 --- a/runtime/internal/clite/c.go +++ b/runtime/internal/clite/c.go @@ -21,7 +21,8 @@ import ( ) const ( - LLGoPackage = "link" + // we want to execute init(), link / decl skips executing init() + LLGoPackage = true ) type ( diff --git a/runtime/internal/clite/stdio_baremetal.go b/runtime/internal/clite/stdio_baremetal.go index fe009932..194e5779 100644 --- a/runtime/internal/clite/stdio_baremetal.go +++ b/runtime/internal/clite/stdio_baremetal.go @@ -18,9 +18,12 @@ package c -import _ "unsafe" +import ( + _ "unsafe" -// initialized by z_print because LLGoPackage skips calling init() -var Stdin FilePtr -var Stdout FilePtr -var Stderr FilePtr + "github.com/goplus/lib/c" +) + +var Stdin FilePtr = c.Fopen(c.Str("/dev/stdin"), c.Str("r")) +var Stdout FilePtr = c.Fopen(c.Str("/dev/stdout"), c.Str("w")) +var Stderr FilePtr = Stdout diff --git a/runtime/internal/runtime/z_print.go b/runtime/internal/runtime/z_print.go index 11e04640..d20f9ead 100644 --- a/runtime/internal/runtime/z_print.go +++ b/runtime/internal/runtime/z_print.go @@ -22,18 +22,6 @@ import ( c "github.com/goplus/llgo/runtime/internal/clite" ) -func init() { - if c.Stdin == nil { - c.Stdin = c.Fopen(c.Str("/dev/stdin"), c.Str("r")) - } - if c.Stdout == nil { - c.Stdout = c.Fopen(c.Str("/dev/stdout"), c.Str("w")) - } - if c.Stderr == nil { - c.Stderr = c.Stdout - } -} - func boolCStr(v bool) *c.Char { if v { return c.Str("true")