genbindings/qstringlist: need a larger malloc for qstring now

This commit is contained in:
mappu 2024-10-19 15:49:28 +13:00
parent b0344564cd
commit 9e7349d4e3

View File

@ -291,8 +291,17 @@ func (gfs *goFileState) emitParameterGo2CABIForwarding(p CppParameter) (preamble
gfs.imports["runtime"] = struct{}{}
gfs.imports["unsafe"] = struct{}{}
preamble += "// For the C ABI, malloc a C array of raw pointers\n"
preamble += nameprefix + "_CArray := (*[0xffff]" + listType.parameterTypeCgo() + ")(C.malloc(C.size_t(8 * len(" + p.ParameterName + "))))\n"
var mallocSize string
if listType.ParameterType == "QString" || listType.ParameterType == "QByteArray" {
preamble += "// For the C ABI, malloc a C array of structs\n"
mallocSize = "int(unsafe.Sizeof(C.struct_miqt_string{}))"
} else {
preamble += "// For the C ABI, malloc a C array of raw pointers\n"
mallocSize = "8"
}
preamble += nameprefix + "_CArray := (*[0xffff]" + listType.parameterTypeCgo() + ")(C.malloc(C.size_t(" + mallocSize + " * len(" + p.ParameterName + "))))\n"
preamble += "defer C.free(unsafe.Pointer(" + nameprefix + "_CArray))\n"
preamble += "for i := range " + p.ParameterName + "{\n"