genbindings: fixes for integer types

This commit is contained in:
mappu 2024-08-25 15:31:21 +12:00
parent 3121a7c610
commit 8fb92cfd3a
3 changed files with 16 additions and 27 deletions

View File

@ -125,8 +125,8 @@ func emitParametersCabi(m CppMethod, selfType string) string {
} else if t, ok := p.QListOf(); ok {
if t.ParameterType == "QString" {
// Combov
tmp = append(tmp, "char** "+p.ParameterName+", int64_t* "+p.ParameterName+"_Lengths, size_t "+p.ParameterName+"_len")
// Combo
tmp = append(tmp, "char** "+p.ParameterName+", uint64_t* "+p.ParameterName+"_Lengths, size_t "+p.ParameterName+"_len")
} else {
// The Go code has called this with two arguments: T* and len

View File

@ -6,7 +6,6 @@ import (
"log"
"sort"
"strings"
"unsafe"
)
func goReservedWord(s string) bool {
@ -22,15 +21,9 @@ func (p CppParameter) RenderTypeGo() string {
if p.Pointer && p.ParameterType == "char" {
return "string"
}
if p.ParameterType == "char" {
return "byte"
}
if p.ParameterType == "QString" {
return "string"
}
if p.ParameterType == "uintptr_t" {
return "uintptr"
}
if t, ok := p.QListOf(); ok {
return "[]" + t.RenderTypeGo()
@ -70,7 +63,7 @@ func (p CppParameter) RenderTypeGo() string {
}
case "unsigned int":
return "uint"
ret += "uint"
case "qint32":
ret += "int32"
case "quint32":
@ -89,20 +82,8 @@ func (p CppParameter) RenderTypeGo() string {
} else {
ret += "uint64"
}
case "qintptr":
var ptr *int
if unsafe.Sizeof(ptr) == 8 {
ret += "int64"
} else {
ret += "int32"
}
case "quintptr":
var ptr *int
if unsafe.Sizeof(ptr) == 8 {
ret += "uint64"
} else {
ret += "uint32"
}
case "qintptr", "uintptr_t", "intptr_t", "quintptr":
ret += "uintptr"
default:
// Do not transform this type
ret += p.ParameterType

View File

@ -45,18 +45,26 @@ func (p CppParameter) QSetOf() bool {
}
func (p CppParameter) IntType() bool {
switch p.ParameterType {
case "int", "unsigned int", "uint",
"short", "unsigned short", "ushort", "qint16", "quint16",
"qint8", "quint8",
// "char", "uchar", // Don't count char or char* as integer types that need cast assertions
"unsigned char", "uchar",
"long", "unsigned long", "ulong", "qint32", "quint32",
"longlong", "ulonglong", "qlonglong", "qulonglong", "qint64", "quint64", "int64_t", "uint64_t", "long long", "unsigned long long",
"QRgb", // unsigned int
"qintptr", "quintptr",
"QRgb", // QRgb is an unsigned int
"qintptr", "quintptr", "uintptr_t", "intptr_t",
"qsizetype", "size_t",
"double", "float", "qreal":
return true
case "char":
// Only count char as an integer type with cast assertions if it's
// not possibly a char* string in disguise
// (However, unsigned chars are always like ints)
return !p.Pointer
default:
return false
}