You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While integrating tengo into a program, I had a simple nil pointer dereference error, but it was difficult to track down without patching tengo. I don't think it's right to change the interface of RunContext(), so I have the following proposed patch. Thoughts?
---script.go.orig2024-01-2212:25:56+++ script.go2024-01-2212:27:48
@@ -200,6+200,7 @@
globals []ObjectmaxAllocsint64lock sync.RWMutex+disableRecoverbool
}
// Run executes the compiled script in the virtual machine.
@@ -211,6+212,12 @@
returnv.Run()
}
+// EnableRescue toggles whether or not the runtime recovery method should be+// enabled or not (default enabled).+func (c*Compiled) EnableRescue(bbool) {
+c.disableRecover=!b+}
+// RunContext is like Run but includes a context.func (c*Compiled) RunContext(ctxcontext.Context) (errerror) {
c.lock.Lock()
@@ -219,6+226,7 @@
v:=NewVM(c.bytecode, c.globals, c.maxAllocs)
ch:=make(chanerror, 1)
gofunc() {
+if!c.disableRecover {
deferfunc() {
ifr:=recover(); r!=nil {
switche:=r.(type) {
@@ -231,6+239,7 @@
}
}
}()
+ }
ch<-v.Run()
}()
The text was updated successfully, but these errors were encountered:
While integrating
tengo
into a program, I had a simplenil
pointer dereference error, but it was difficult to track down without patchingtengo
. I don't think it's right to change the interface ofRunContext()
, so I have the following proposed patch. Thoughts?The text was updated successfully, but these errors were encountered: