Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds missing pointer reference for slices along with test #351

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions _examples/slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,16 @@ func CmplxSqrt(arr SliceComplex) SliceComplex {
}
return res
}

func GetEmptyMatrix(xSize int, ySize int) [][]bool {
result := [][]bool{}

for i := 0; i < xSize; i++ {
result = append(result, []bool{})
for j := 0; j < ySize; j++ {
result[i] = append(result[i], false)
}
}

return result
}
7 changes: 7 additions & 0 deletions _examples/slices/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@
assert math.isclose(root_squared.real, orig.real)
assert math.isclose(root_squared.imag, orig.imag)


matrix = slices.GetEmptyMatrix(4,4)
for i in range(4):
for j in range(4):
assert not matrix[i][j]
print("[][]bool working as expected")

print("OK")
9 changes: 6 additions & 3 deletions bind/gen_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,14 @@ otherwise parameter is a python list that we copy from
g.gofile.Indent()
g.gofile.Printf("s := deptrFromHandle_%s(handle)\n", slNm)
if esym.go2py != "" {
if !esym.isPointer() && esym.isStruct() {
g.gofile.Printf("return %s(&(s[_idx]))%s\n", esym.go2py, esym.go2pyParenEx)
// If the go2py starts with handleFromPtr_, use reference &, otherwise just return the value
val_str := ""
if strings.HasPrefix(esym.go2py, "handleFromPtr_") {
val_str = "&(s[_idx])"
} else {
g.gofile.Printf("return %s(s[_idx])%s\n", esym.go2py, esym.go2pyParenEx)
val_str = "s[_idx]"
}
g.gofile.Printf("return %s(%s)%s\n", esym.go2py, val_str, esym.go2pyParenEx)
} else {
g.gofile.Printf("return s[_idx]\n")
}
Expand Down
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,7 @@ struct slice: slices.Slice_Ptr_slices_S len: 3 handle: 11 [slices.S{Name=S0, ha
struct slice[0]: slices.S{Name=S0, handle=15}
struct slice[1]: slices.S{Name=S1, handle=16}
struct slice[2].Name: S2
[][]bool working as expected
OK
`),
})
Expand Down
Loading