aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2024-02-19 15:12:16 +0100
committerRon Evans <[email protected]>2024-02-19 22:17:19 +0100
commitf529b6071da269323704b3d3bb5e4fc92dcf6af5 (patch)
tree0d0f7cc92f2052b5fa9ff67588478a9ecc21770d
parent5557e97888ad5ea1fe3ca005ecb3aa88bd174bcc (diff)
downloadtinygo-f529b6071da269323704b3d3bb5e4fc92dcf6af5.tar.gz
tinygo-f529b6071da269323704b3d3bb5e4fc92dcf6af5.zip
interp: do not register runtime timers during interp
The runtime hasn't been initialized yet so this leads to problems. This fixes https://github.com/tinygo-org/tinygo/issues/4123.
-rw-r--r--interp/interpreter.go5
-rw-r--r--testdata/timers.go2
2 files changed, 6 insertions, 1 deletions
diff --git a/interp/interpreter.go b/interp/interpreter.go
index 24f5e9e85..24735eb26 100644
--- a/interp/interpreter.go
+++ b/interp/interpreter.go
@@ -239,7 +239,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
// already be emitted in initAll.
continue
case strings.HasPrefix(callFn.name, "runtime.print") || callFn.name == "runtime._panic" || callFn.name == "runtime.hashmapGet" || callFn.name == "runtime.hashmapInterfaceHash" ||
- callFn.name == "os.runtime_args" || callFn.name == "internal/task.start" || callFn.name == "internal/task.Current":
+ callFn.name == "os.runtime_args" || callFn.name == "internal/task.start" || callFn.name == "internal/task.Current" ||
+ callFn.name == "time.startTimer" || callFn.name == "time.stopTimer" || callFn.name == "time.resetTimer":
// These functions should be run at runtime. Specifically:
// * Print and panic functions are best emitted directly without
// interpreting them, otherwise we get a ton of putchar (etc.)
@@ -252,6 +253,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
// at runtime.
// * internal/task.start, internal/task.Current: start and read shcheduler state,
// which is modified elsewhere.
+ // * Timer functions access runtime internal state which may
+ // not be initialized.
err := r.runAtRuntime(fn, inst, locals, &mem, indent)
if err != nil {
return nil, mem, err
diff --git a/testdata/timers.go b/testdata/timers.go
index d0d9d4c77..c179e4744 100644
--- a/testdata/timers.go
+++ b/testdata/timers.go
@@ -2,6 +2,8 @@ package main
import "time"
+var timer = time.NewTimer(time.Millisecond)
+
func main() {
// Test ticker.
ticker := time.NewTicker(time.Millisecond * 500)