diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2022-01-04 10:35:26 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2022-01-11 16:30:08 +0100 |
| commit | 983508d80442a85b78118e6c6a03d5ae4897e4df (patch) | |
| tree | 4d45c36a95a2ae407fa780a68925e0014c75e7e6 /prog | |
| parent | bad18a53de8fa8d3d097e3d701efb72a014661cb (diff) | |
prog: pass ctx by pointer to ForeachType callback
This will allow callbacks to stop iteration early by
setting ctx.Stop flag (as it works for ForeachArg).
Diffstat (limited to 'prog')
| -rw-r--r-- | prog/prio.go | 2 | ||||
| -rw-r--r-- | prog/prog_test.go | 4 | ||||
| -rw-r--r-- | prog/rand_test.go | 2 | ||||
| -rw-r--r-- | prog/resources.go | 6 | ||||
| -rw-r--r-- | prog/rotation.go | 2 | ||||
| -rw-r--r-- | prog/target.go | 6 | ||||
| -rw-r--r-- | prog/types.go | 12 |
7 files changed, 17 insertions, 17 deletions
diff --git a/prog/prio.go b/prog/prio.go index 4cf3daf90..c89869b95 100644 --- a/prog/prio.go +++ b/prog/prio.go @@ -67,7 +67,7 @@ func (target *Target) calcStaticPriorities() [][]int32 { func (target *Target) calcResourceUsage() map[string]map[int]weights { uses := make(map[string]map[int]weights) - ForeachType(target.Syscalls, func(t Type, ctx TypeCtx) { + ForeachType(target.Syscalls, func(t Type, ctx *TypeCtx) { c := ctx.Meta switch a := t.(type) { case *ResourceType: diff --git a/prog/prog_test.go b/prog/prog_test.go index a21c464a0..2247694a1 100644 --- a/prog/prog_test.go +++ b/prog/prog_test.go @@ -23,7 +23,7 @@ func TestGeneration(t *testing.T) { func TestDefault(t *testing.T) { target, _, _ := initTest(t) - ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) { + ForeachType(target.Syscalls, func(typ Type, ctx *TypeCtx) { arg := typ.DefaultArg(ctx.Dir) if !isDefault(arg) { t.Errorf("default arg is not default: %s\ntype: %#v\narg: %#v", @@ -222,7 +222,7 @@ func TestSpecialStructs(t *testing.T) { t.Run(special, func(t *testing.T) { var typ Type for i := 0; i < len(target.Syscalls) && typ == nil; i++ { - ForeachCallType(target.Syscalls[i], func(t Type, ctx TypeCtx) { + ForeachCallType(target.Syscalls[i], func(t Type, ctx *TypeCtx) { if ctx.Dir == DirOut { return } diff --git a/prog/rand_test.go b/prog/rand_test.go index 629dffaf5..030be8ec3 100644 --- a/prog/rand_test.go +++ b/prog/rand_test.go @@ -110,7 +110,7 @@ func TestEnabledCalls(t *testing.T) { func TestSizeGenerateConstArg(t *testing.T) { target, rs, iters := initRandomTargetTest(t, "test", "64") r := newRand(target, rs) - ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) { + ForeachType(target.Syscalls, func(typ Type, ctx *TypeCtx) { if _, ok := typ.(*IntType); !ok { return } diff --git a/prog/resources.go b/prog/resources.go index 3a38236aa..5af129d00 100644 --- a/prog/resources.go +++ b/prog/resources.go @@ -45,7 +45,7 @@ func (target *Target) calcResourceCtors(res *ResourceDesc, precise bool) []*Sysc func (target *Target) populateResourceCtors() { // Find resources that are created by each call. callsResources := make([][]*ResourceDesc, len(target.Syscalls)) - ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) { + ForeachType(target.Syscalls, func(typ Type, ctx *TypeCtx) { switch typ1 := typ.(type) { case *ResourceType: if ctx.Dir != DirIn { @@ -124,7 +124,7 @@ func isCompatibleResourceImpl(dst, src []string, precise bool) bool { func (target *Target) getInputResources(c *Syscall) []*ResourceDesc { var resources []*ResourceDesc - ForeachCallType(c, func(typ Type, ctx TypeCtx) { + ForeachCallType(c, func(typ Type, ctx *TypeCtx) { if ctx.Dir == DirOut { return } @@ -144,7 +144,7 @@ func (target *Target) getInputResources(c *Syscall) []*ResourceDesc { func (target *Target) getOutputResources(c *Syscall) []*ResourceDesc { var resources []*ResourceDesc - ForeachCallType(c, func(typ Type, ctx TypeCtx) { + ForeachCallType(c, func(typ Type, ctx *TypeCtx) { switch typ1 := typ.(type) { case *ResourceType: if ctx.Dir != DirIn { diff --git a/prog/rotation.go b/prog/rotation.go index 2eca62e55..5651b6e05 100644 --- a/prog/rotation.go +++ b/prog/rotation.go @@ -50,7 +50,7 @@ func MakeRotator(target *Target, calls map[*Syscall]bool, rnd *rand.Rand) *Rotat } // VMAs and filenames are effectively resources for our purposes // (but they don't have ctors). - ForeachCallType(call, func(t Type, _ TypeCtx) { + ForeachCallType(call, func(t Type, _ *TypeCtx) { switch a := t.(type) { case *BufferType: switch a.Kind { diff --git a/prog/target.go b/prog/target.go index cb485c069..182d46391 100644 --- a/prog/target.go +++ b/prog/target.go @@ -205,7 +205,7 @@ func restoreLinks(syscalls []*Syscall, resources []*ResourceDesc, types []Type) resourceMap[res.Name] = res } - ForeachType(syscalls, func(typ Type, ctx TypeCtx) { + ForeachType(syscalls, func(typ Type, ctx *TypeCtx) { if ref, ok := typ.(Ref); ok { typ = types[ref] *ctx.Ptr = typ @@ -230,7 +230,7 @@ func (target *Target) DefaultChoiceTable() *ChoiceTable { func (target *Target) GetGlobs() map[string]bool { globs := make(map[string]bool) - ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) { + ForeachType(target.Syscalls, func(typ Type, ctx *TypeCtx) { switch a := typ.(type) { case *BufferType: if a.Kind == BufferGlob { @@ -242,7 +242,7 @@ func (target *Target) GetGlobs() map[string]bool { } func (target *Target) UpdateGlobs(globFiles map[string][]string) { - ForeachType(target.Syscalls, func(typ Type, ctx TypeCtx) { + ForeachType(target.Syscalls, func(typ Type, ctx *TypeCtx) { switch a := typ.(type) { case *BufferType: if a.Kind == BufferGlob { diff --git a/prog/types.go b/prog/types.go index 08aed6d61..110ddabeb 100644 --- a/prog/types.go +++ b/prog/types.go @@ -678,23 +678,23 @@ type TypeCtx struct { Ptr *Type } -func ForeachType(syscalls []*Syscall, f func(t Type, ctx TypeCtx)) { +func ForeachType(syscalls []*Syscall, f func(t Type, ctx *TypeCtx)) { for _, meta := range syscalls { foreachTypeImpl(meta, true, f) } } -func ForeachTypePost(syscalls []*Syscall, f func(t Type, ctx TypeCtx)) { +func ForeachTypePost(syscalls []*Syscall, f func(t Type, ctx *TypeCtx)) { for _, meta := range syscalls { foreachTypeImpl(meta, false, f) } } -func ForeachCallType(meta *Syscall, f func(t Type, ctx TypeCtx)) { +func ForeachCallType(meta *Syscall, f func(t Type, ctx *TypeCtx)) { foreachTypeImpl(meta, true, f) } -func foreachTypeImpl(meta *Syscall, preorder bool, f func(t Type, ctx TypeCtx)) { +func foreachTypeImpl(meta *Syscall, preorder bool, f func(t Type, ctx *TypeCtx)) { // Note: we specifically don't create seen in ForeachType. // It would prune recursion more (across syscalls), but lots of users need to // visit each struct per-syscall (e.g. prio, used resources). @@ -702,7 +702,7 @@ func foreachTypeImpl(meta *Syscall, preorder bool, f func(t Type, ctx TypeCtx)) var rec func(*Type, Dir) rec = func(ptr *Type, dir Dir) { if preorder { - f(*ptr, TypeCtx{Meta: meta, Dir: dir, Ptr: ptr}) + f(*ptr, &TypeCtx{Meta: meta, Dir: dir, Ptr: ptr}) } switch a := (*ptr).(type) { case *PtrType: @@ -733,7 +733,7 @@ func foreachTypeImpl(meta *Syscall, preorder bool, f func(t Type, ctx TypeCtx)) panic("unknown type") } if !preorder { - f(*ptr, TypeCtx{Meta: meta, Dir: dir, Ptr: ptr}) + f(*ptr, &TypeCtx{Meta: meta, Dir: dir, Ptr: ptr}) } } for i := range meta.Args { |
