mirror of https://github.com/go-python/gopy.git
Merge pull request #351 from EvanOman/346/fix-handleFromPtr-missing-reference-slices
Adds missing pointer reference for slices along with test
This commit is contained in:
commit
50c71dc954
|
@ -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
|
||||
}
|
|
@ -44,4 +44,11 @@ for root, orig in zip(sqrts, cmplx):
|
|||
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")
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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
|
||||
`),
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue