mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-01 08:42:55 +08:00
pkg/eval: Move intCh from Evaler to Frame.
This avoids a race condition when using EvalInTTY concurrently. This addresses #73.
This commit is contained in:
parent
8c71635ca3
commit
bcd1c1df6f
|
@ -307,7 +307,7 @@ func evalModule(fm *Frame, key string, src *Source) (Ns, error) {
|
|||
fm.Evaler, src,
|
||||
diag.Ranging{From: 0, To: len(src.Code)},
|
||||
modGlobal, make(Ns),
|
||||
fm.ports,
|
||||
fm.intCh, fm.ports,
|
||||
fm.addTraceback(), false,
|
||||
}
|
||||
|
||||
|
|
|
@ -47,9 +47,6 @@ type Evaler struct {
|
|||
beforeChdir []func(string)
|
||||
afterChdir []func(string)
|
||||
|
||||
// Used to receive SIGINT.
|
||||
intCh chan struct{}
|
||||
|
||||
// State of the module system.
|
||||
libDir string
|
||||
bundled map[string]string
|
||||
|
@ -142,7 +139,6 @@ func NewEvaler() *Evaler {
|
|||
},
|
||||
bundled: bundled.Get(),
|
||||
Editor: nil,
|
||||
intCh: nil,
|
||||
}
|
||||
|
||||
beforeChdirElvish, afterChdirElvish := vector.Empty, vector.Empty
|
||||
|
@ -282,10 +278,8 @@ func (ev *Evaler) EvalInTTY(op Op) error {
|
|||
defer stdPorts.close()
|
||||
|
||||
intCh, cleanupInt := listenInterrupts()
|
||||
ev.intCh = intCh
|
||||
defer func() {
|
||||
cleanupInt()
|
||||
ev.intCh = nil
|
||||
// Put myself in foreground, in case some command has put me in background.
|
||||
err := putSelfInFg()
|
||||
if err != nil {
|
||||
|
@ -293,7 +287,9 @@ func (ev *Evaler) EvalInTTY(op Op) error {
|
|||
}
|
||||
}()
|
||||
|
||||
return ev.Eval(op, stdPorts.ports[:])
|
||||
ec := NewTopFrame(ev, op.Src, stdPorts.ports[:])
|
||||
ec.intCh = intCh
|
||||
return ec.eval(op.Inner)
|
||||
}
|
||||
|
||||
// Compile compiles Elvish code in the global scope. If the error is not nil, it
|
||||
|
|
|
@ -16,11 +16,14 @@ import (
|
|||
// shortly after creation; new Frame's are "forked" when needed.
|
||||
type Frame struct {
|
||||
*Evaler
|
||||
|
||||
srcMeta *Source
|
||||
srcRange diag.Ranging
|
||||
|
||||
local, up Ns
|
||||
ports []*Port
|
||||
|
||||
intCh chan struct{}
|
||||
ports []*Port
|
||||
|
||||
traceback *stackTrace
|
||||
|
||||
|
@ -35,7 +38,7 @@ func NewTopFrame(ev *Evaler, src *Source, ports []*Port) *Frame {
|
|||
ev, src,
|
||||
diag.Ranging{From: 0, To: len(src.Code)},
|
||||
ev.Global, make(Ns),
|
||||
ports,
|
||||
nil, ports,
|
||||
nil, false,
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +131,7 @@ func (fm *Frame) fork(name string) *Frame {
|
|||
return &Frame{
|
||||
fm.Evaler, fm.srcMeta, fm.srcRange,
|
||||
fm.local, fm.up,
|
||||
newPorts,
|
||||
fm.intCh, newPorts,
|
||||
fm.traceback, fm.background,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user