mirror of
https://github.com/mappu/miqt.git
synced 2024-12-22 08:58:37 +00:00
genbindings/go: implement cabi type roundtrips for pointer types
This commit is contained in:
parent
5a3c3556a1
commit
caee076af8
@ -478,6 +478,13 @@ func emitAssignCppToCabi(assignExpression string, p CppParameter, rvalue string)
|
||||
} else if p.Const {
|
||||
shouldReturn += "(" + p.RenderTypeCabi() + ") "
|
||||
|
||||
} else {
|
||||
// Basic type
|
||||
if p.ByRef {
|
||||
// The C++ type is a reference, the CABI type is a pointer type
|
||||
shouldReturn += "&"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return indent + shouldReturn + rvalue + ";\n" + afterCall
|
||||
|
@ -169,6 +169,11 @@ func (p CppParameter) parameterTypeCgo() string {
|
||||
return "C.struct_miqt_map"
|
||||
}
|
||||
|
||||
// Cgo internally binds void* as unsafe.Pointer{}
|
||||
if p.ParameterType == "void" && p.Pointer {
|
||||
return "unsafe.Pointer"
|
||||
}
|
||||
|
||||
tmp := strings.Replace(p.RenderTypeCabi(), `*`, "", -1)
|
||||
|
||||
if strings.HasPrefix(tmp, "const ") && tmp != "const char" { // Special typedef to make this work for const char* signal parameters
|
||||
@ -542,6 +547,14 @@ func (gfs *goFileState) emitCabiToGo(assignExpr string, rt CppParameter, rvalue
|
||||
return shouldReturn + " " + rvalue + "\n" + afterword
|
||||
|
||||
} else if rt.IntType() || rt.IsKnownEnum() || rt.IsFlagType() || rt.ParameterType == "bool" || rt.QtCppOriginalType != nil {
|
||||
|
||||
if rt.Pointer || rt.ByRef {
|
||||
// Cast must go via unsafe.Pointer
|
||||
gfs.imports["unsafe"] = struct{}{}
|
||||
return assignExpr + "(" + rt.RenderTypeGo(gfs) + ")(unsafe.Pointer(" + rvalue + "))\n"
|
||||
|
||||
}
|
||||
|
||||
// Need to cast Cgo type to Go int type
|
||||
// Optimize assignment to avoid temporary
|
||||
return assignExpr + "(" + rt.RenderTypeGo(gfs) + ")(" + rvalue + ")\n"
|
||||
|
Loading…
Reference in New Issue
Block a user