Skip to content

Commit

Permalink
Fixes to nested array of int in gadgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Eagle941 committed Sep 12, 2023
1 parent c8ef04e commit 297a530
Showing 1 changed file with 9 additions and 28 deletions.
37 changes: 9 additions & 28 deletions extractor/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,44 +118,25 @@ func (g *ExGadget) isOp() {}

func arrayToSlice(v reflect.Value) []frontend.Variable {
if v.Len() == 0 {
panic("Slice in flattenSlice can't have length of 0")
return []frontend.Variable{}
}

switch v.Index(0).Kind() {
switch v.Index(0).Kind() {
case reflect.Array:
args := []frontend.Variable{}
for i := 0; i < v.Len(); i++ {
args = append(args, arrayToSlice(v.Index(i)))
}
return args
case reflect.Interface:
case reflect.Interface:
res := make([]frontend.Variable, v.Len())
for i := 0; i < v.Len(); i++ {
res[i] = v.Index(i).Elem().Interface().(frontend.Variable)
res[i] = v.Index(i).Elem().Interface().(frontend.Variable)
}
return res
default:
return []frontend.Variable{}
}

// if v.Index(0).Kind() == reflect.Array {
// args := []frontend.Variable{}
// for i := 0; i < v.Len(); i++ {
// args = append(args, arrayToSlice(v.Index(i)))
// }
// return args
// }

// res := make([]frontend.Variable, v.Len())
// for i := 0; i < v.Len(); i++ {
// switch v.Index(i).Kind() {
// case reflect.Interface:
// res[i] = v.Index(i).Elem().Interface().(frontend.Variable)
// default:
// return []frontend.Variable{}
// }
// }
// return res
default:
return []frontend.Variable{}
}
}

// flattenSlice takes a slice and returns a single dimension
Expand All @@ -164,7 +145,7 @@ func arrayToSlice(v reflect.Value) []frontend.Variable {
// processed by sanitizeVars.
func flattenSlice(value reflect.Value) []frontend.Variable {
if value.Len() == 0 {
panic("Slice in flattenSlice can't have length of 0")
return []frontend.Variable{}
}
if value.Index(0).Kind() == reflect.Slice {
args := []frontend.Variable{}
Expand All @@ -190,7 +171,7 @@ func (g *ExGadget) Call(gadget abstractor.GadgetDefinition) []frontend.Variable
case reflect.Array:
// I can't convert from array to slice using Reflect because
// the field is unaddressable.
args = append(args, ArrayToSlice(v))
args = append(args, arrayToSlice(v))
case reflect.Interface:
args = append(args, v.Elem().Interface().(frontend.Variable))
}
Expand Down

0 comments on commit 297a530

Please sign in to comment.