Better handling of slice size vs. capacity in pointers to pointers.

This commit is contained in:
Greg 2019-05-29 00:02:27 -04:00
parent 840a055a11
commit 2f4d76c6af
3 changed files with 6 additions and 5 deletions

View File

@ -83,9 +83,9 @@ func main() {
ns.NSArrayWithObjects(nst("obj1"),nst("obj2")),
ns.NSArrayWithObjects(nst("key1"),nst("key2")),
)
os := make([]ns.Id,4)
os := make([]ns.Id,0,5)
fmt.Printf("Length of os is %d\n",len(os))
ks := make([]ns.Id,4)
ks := make([]ns.Id,0,5)
fmt.Printf("\nGetObjects()\n")
d.GetObjects(&os,&ks,4)
fmt.Printf("Length of os is now %d\n",len(os))

View File

@ -402,13 +402,14 @@ func GoToC(name string, pnames, snames []string, rtype *Type, ptypes []*Type, fu
for i,sname := range snames {
if sname == "" { continue }
ret.WriteString(fmt.Sprintf(`
(*%s) = (*%s)[:cap(*%s)]
for i := 0; i < len(*%s); i++ {
if %s[i] == nil {
(*%s) = (*%s)[:i]
break
}
(*%s)[i].ptr = %s[i]
}`,pnames[i],sname,pnames[i],pnames[i],pnames[i],sname))
}`,pnames[i],pnames[i],pnames[i],pnames[i],sname,pnames[i],pnames[i],pnames[i],sname))
}
if rt != "void" {
ret.WriteString(`

View File

@ -977,7 +977,7 @@ func %s%s(%s) %s {
continue
}
w.goCode.WriteString(fmt.Sprintf(`
%s := make([]unsafe.Pointer,len(*%s))
%s := make([]unsafe.Pointer,cap(*%s))
for i := 0; i < len(*%s); i++ {
%s[i] = (*%s)[i].Ptr()
}