genbindings: more const correctness

This commit is contained in:
mappu 2024-08-29 17:38:18 +12:00
parent 421c229771
commit a4baeabbcb
2 changed files with 10 additions and 0 deletions

View File

@ -45,6 +45,13 @@ func (p CppParameter) RenderTypeCabi() string {
ret = "ptrdiff_t"
}
if p.Const {
// This is needed for const-correctness for calling some overloads
// e.g. QShortcut ctor taking (QWidget* parent, const char* member) signal -
// the signal/slot requires that member is const, not just plain char*
ret = "const " + ret
}
if p.IsFlagType() {
ret = "int"

View File

@ -106,6 +106,9 @@ func (p CppParameter) parameterTypeCgo() string {
return "C.char"
}
tmp := strings.Replace(p.RenderTypeCabi(), `*`, "", -1)
if strings.HasPrefix(tmp, "const ") {
tmp = tmp[6:] // Constness doesn't survive the CABI boundary
}
if strings.HasPrefix(tmp, "unsigned ") {
tmp = "u" + tmp[9:] // Cgo uses uchar, uint instead of full name
}