genbindings: avoid pointer copy when returning qt type by reference

This commit is contained in:
mappu 2024-08-20 20:20:26 +12:00
parent ae3de5a64c
commit cd16ed9028
1 changed files with 14 additions and 0 deletions

View File

@ -507,6 +507,20 @@ extern "C" {
}
} else if m.ReturnType.QtClassType() && m.ReturnType.ByRef {
// It's a pointer in disguise, just needs one cast
shouldReturn = m.ReturnType.RenderTypeQtCpp() + " ret = "
afterCall += "\t// Cast returned reference into pointer\n"
if m.ReturnType.Const {
nonConst := m.ReturnType // copy
nonConst.Const = false
nonConst.ByRef = false
nonConst.Pointer = true
afterCall += "\treturn const_cast<" + nonConst.RenderTypeQtCpp() + ">(&ret);\n"
} else {
afterCall += "\treturn &ret;\n"
}
} else if m.ReturnType.QtClassType() && !m.ReturnType.Pointer {
shouldReturn = m.ReturnType.ParameterType + " ret = "
afterCall = "\t// Copy-construct value returned type into heap-allocated copy\n"