aboutsummaryrefslogtreecommitdiff
path: root/starlark/interp.go
diff options
context:
space:
mode:
Diffstat (limited to 'starlark/interp.go')
-rw-r--r--starlark/interp.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/starlark/interp.go b/starlark/interp.go
index 004763e..f00382c 100644
--- a/starlark/interp.go
+++ b/starlark/interp.go
@@ -5,6 +5,8 @@ package starlark
import (
"fmt"
"os"
+ "sync/atomic"
+ "unsafe"
"go.starlark.net/internal/compile"
"go.starlark.net/internal/spell"
@@ -85,6 +87,15 @@ func (fn *Function) CallInternal(thread *Thread, args Tuple, kwargs []Tuple) (Va
code := f.Code
loop:
for {
+ thread.steps++
+ if thread.steps >= thread.maxSteps {
+ thread.Cancel("too many steps")
+ }
+ if reason := atomic.LoadPointer((*unsafe.Pointer)(unsafe.Pointer(&thread.cancelReason))); reason != nil {
+ err = fmt.Errorf("Starlark computation cancelled: %s", *(*string)(reason))
+ break loop
+ }
+
fr.pc = pc
op := compile.Opcode(code[pc])