Better handling of slice size vs. capacity in pointers to pointers.
This commit is contained in:
parent
840a055a11
commit
2f4d76c6af
|
@ -83,9 +83,9 @@ func main() {
|
||||||
ns.NSArrayWithObjects(nst("obj1"),nst("obj2")),
|
ns.NSArrayWithObjects(nst("obj1"),nst("obj2")),
|
||||||
ns.NSArrayWithObjects(nst("key1"),nst("key2")),
|
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))
|
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")
|
fmt.Printf("\nGetObjects()\n")
|
||||||
d.GetObjects(&os,&ks,4)
|
d.GetObjects(&os,&ks,4)
|
||||||
fmt.Printf("Length of os is now %d\n",len(os))
|
fmt.Printf("Length of os is now %d\n",len(os))
|
||||||
|
|
|
@ -402,13 +402,14 @@ func GoToC(name string, pnames, snames []string, rtype *Type, ptypes []*Type, fu
|
||||||
for i,sname := range snames {
|
for i,sname := range snames {
|
||||||
if sname == "" { continue }
|
if sname == "" { continue }
|
||||||
ret.WriteString(fmt.Sprintf(`
|
ret.WriteString(fmt.Sprintf(`
|
||||||
|
(*%s) = (*%s)[:cap(*%s)]
|
||||||
for i := 0; i < len(*%s); i++ {
|
for i := 0; i < len(*%s); i++ {
|
||||||
if %s[i] == nil {
|
if %s[i] == nil {
|
||||||
(*%s) = (*%s)[:i]
|
(*%s) = (*%s)[:i]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
(*%s)[i].ptr = %s[i]
|
(*%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" {
|
if rt != "void" {
|
||||||
ret.WriteString(`
|
ret.WriteString(`
|
||||||
|
|
|
@ -977,7 +977,7 @@ func %s%s(%s) %s {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
w.goCode.WriteString(fmt.Sprintf(`
|
w.goCode.WriteString(fmt.Sprintf(`
|
||||||
%s := make([]unsafe.Pointer,len(*%s))
|
%s := make([]unsafe.Pointer,cap(*%s))
|
||||||
for i := 0; i < len(*%s); i++ {
|
for i := 0; i < len(*%s); i++ {
|
||||||
%s[i] = (*%s)[i].Ptr()
|
%s[i] = (*%s)[i].Ptr()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user