Skip to content

Commit f529b60

Browse files
aykevldeadprogram
authored andcommitted
interp: do not register runtime timers during interp
The runtime hasn't been initialized yet so this leads to problems. This fixes #4123.
1 parent 5557e97 commit f529b60

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

interp/interpreter.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
239239
// already be emitted in initAll.
240240
continue
241241
case strings.HasPrefix(callFn.name, "runtime.print") || callFn.name == "runtime._panic" || callFn.name == "runtime.hashmapGet" || callFn.name == "runtime.hashmapInterfaceHash" ||
242-
callFn.name == "os.runtime_args" || callFn.name == "internal/task.start" || callFn.name == "internal/task.Current":
242+
callFn.name == "os.runtime_args" || callFn.name == "internal/task.start" || callFn.name == "internal/task.Current" ||
243+
callFn.name == "time.startTimer" || callFn.name == "time.stopTimer" || callFn.name == "time.resetTimer":
243244
// These functions should be run at runtime. Specifically:
244245
// * Print and panic functions are best emitted directly without
245246
// 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
252253
// at runtime.
253254
// * internal/task.start, internal/task.Current: start and read shcheduler state,
254255
// which is modified elsewhere.
256+
// * Timer functions access runtime internal state which may
257+
// not be initialized.
255258
err := r.runAtRuntime(fn, inst, locals, &mem, indent)
256259
if err != nil {
257260
return nil, mem, err

testdata/timers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import "time"
44

5+
var timer = time.NewTimer(time.Millisecond)
6+
57
func main() {
68
// Test ticker.
79
ticker := time.NewTicker(time.Millisecond * 500)

0 commit comments

Comments
 (0)