c: simplify integer mappings

`short` is perfectly fine as-is in C.

`qlonglong` is a bit trickier - Qt declares it to be `qint64` and
`qint64` to be `long long` - ergo, using `long long` in the C code is
fine but mapping `qint64` to `int64_t` actually might lead to trouble if
`int64_t` itself is not declared as `long long` (could be a mere `long
int` on some platforms) which in turn can lead to type-based pointer
aliasing violations :/ Ditto `qint32` vs `int32_t` which could be `int`
or `long`.
This commit is contained in:
Jacek Sieka 2025-04-11 22:59:04 +12:00 committed by mappu
parent d66a0915bf
commit ac1d692b52

View File

@ -105,10 +105,14 @@ func (p CppParameter) RenderTypeCabi() string {
return cabiClassName(p.ParameterType) + "*"
}
// https://github.com/qt/qtbase/blob/v5.15.16-lts-lgpl/src/corelib/global/qglobal.h#L233
// https://github.com/qt/qtbase/blob/v6.9.0/src/corelib/global/qtypes.h#L50
ret := p.ParameterType
switch p.ParameterType {
case "uchar":
ret = "unsigned char"
case "ushort":
ret = "unsigned short"
case "uint":
ret = "unsigned int"
case "ulong":
@ -117,18 +121,22 @@ func (p CppParameter) RenderTypeCabi() string {
ret = "int8_t"
case "quint8":
ret = "uint8_t"
case "qint16", "short":
case "qint16":
ret = "int16_t"
case "quint16", "ushort", "unsigned short":
case "quint16":
ret = "uint16_t"
case "qint32":
ret = "int32_t"
case "quint32":
ret = "uint32_t"
case "qlonglong", "qint64":
case "qlonglong":
ret = "long long"
case "qint64":
ret = "int64_t"
case "qulonglong", "quint64":
case "quint64":
ret = "uint64_t"
case "qulonglong":
ret = "unsigned long long"
case "qfloat16":
ret = "_Float16" // No idea where this typedef comes from, but it exists
case "qreal":