diff --git a/all_test.go b/all_test.go index 7cf7d57b..0259b00c 100644 --- a/all_test.go +++ b/all_test.go @@ -103,6 +103,7 @@ type GoType struct { IntValue int Int64Value int64 Int32Value int32 + Uint32Value uint32 Float64Value float64 Float32Value float32 AnyValue interface{} @@ -191,7 +192,11 @@ var getSetTests = []struct{ set, get interface{} }{ {"value", same}, {true, same}, {false, same}, - {int64(42), int64(42)}, + {int(42), same}, + {int32(42), int(42)}, + {int64(42), same}, + {uint32(42), same}, + {uint64(42), same}, {float64(42), same}, {float32(42), same}, {new(GoType), same}, diff --git a/cpp/capi.cpp b/cpp/capi.cpp index cfba0880..f9329283 100644 --- a/cpp/capi.cpp +++ b/cpp/capi.cpp @@ -611,6 +611,12 @@ void unpackDataValue(DataValue *value, QVariant_ *var) case DTInt32: *qvar = *(qint32*)(value->data); break; + case DTUint64: + *qvar = *(quint64*)(value->data); + break; + case DTUint32: + *qvar = *(quint32*)(value->data); + break; case DTFloat64: *qvar = *(double*)(value->data); break; @@ -667,13 +673,23 @@ void packDataValue(QVariant_ *var, DataValue *value) *(qint8*)(value->data) = (qint8)qvar->toInt(); break; case QMetaType::LongLong: + // Some of these entries will have to be fixed when handling platforms + // where sizeof(long long) != 8 or sizeof(int) != 4. value->dataType = DTInt64; *(qint64*)(value->data) = qvar->toLongLong(); break; + case QMetaType::ULongLong: + value->dataType = DTUint64; + *(quint64*)(value->data) = qvar->toLongLong(); + break; case QMetaType::Int: value->dataType = DTInt32; *(qint32*)(value->data) = qvar->toInt(); break; + case QMetaType::UInt: + value->dataType = DTUint32; + *(quint32*)(value->data) = qvar->toUInt(); + break; case QMetaType::VoidStar: value->dataType = DTUintptr; *(uintptr_t*)(value->data) = (uintptr_t)qvar->value(); diff --git a/cpp/capi.h b/cpp/capi.h index ca4ae998..64d21cb7 100644 --- a/cpp/capi.h +++ b/cpp/capi.h @@ -43,10 +43,12 @@ typedef enum { DTBool = 11, DTInt64 = 12, DTInt32 = 13, - DTUintptr = 14, - DTFloat64 = 15, - DTFloat32 = 16, - DTColor = 17, + DTUint64 = 14, + DTUint32 = 15, + DTUintptr = 16, + DTFloat64 = 17, + DTFloat32 = 18, + DTColor = 19, DTGoAddr = 100, DTObject = 101, diff --git a/datatype.go b/datatype.go index 492e4664..487a35f7 100644 --- a/datatype.go +++ b/datatype.go @@ -89,6 +89,12 @@ func packDataValue(value interface{}, dvalue *C.DataValue, engine *Engine, owner case int32: dvalue.dataType = C.DTInt32 *(*int32)(datap) = value + case uint64: + dvalue.dataType = C.DTUint64 + *(*uint64)(datap) = value + case uint32: + dvalue.dataType = C.DTUint32 + *(*uint32)(datap) = value case float64: dvalue.dataType = C.DTFloat64 *(*float64)(datap) = value @@ -132,6 +138,10 @@ func unpackDataValue(dvalue *C.DataValue, engine *Engine) interface{} { return *(*int64)(datap) case C.DTInt32: return int(*(*int32)(datap)) + case C.DTUint64: + return *(*uint64)(datap) + case C.DTUint32: + return *(*uint32)(datap) case C.DTUintptr: return *(*uintptr)(datap) case C.DTFloat64: @@ -257,6 +267,10 @@ func typeInfo(v interface{}) *C.GoTypeInfo { // TODO Only do that if it's a struct? vtptr := reflect.PtrTo(vt) + if vt.Kind() != reflect.Struct { + panic(fmt.Sprintf("handling of %s (%#v) is incomplete; please report to the developers", vt, v)) + } + numField := vt.NumField() numMethod := vtptr.NumMethod() privateFields := 0 diff --git a/qml.go b/qml.go index 54accb86..233ae896 100644 --- a/qml.go +++ b/qml.go @@ -530,12 +530,13 @@ func (obj *Common) Property(name string) interface{} { // Int panics if the property cannot be represented as an int. func (obj *Common) Int(property string) int { switch value := obj.Property(property).(type) { + case int64: + return int(value) case int: return value - case int64: - if int64(int(value)) != value { - panic(fmt.Sprintf("value of property %q is too large for int: %#v", property, value)) - } + case uint64: + return int(value) + case uint32: return int(value) case uintptr: return int(value) @@ -552,10 +553,14 @@ func (obj *Common) Int(property string) int { // Int64 panics if the property cannot be represented as an int64. func (obj *Common) Int64(property string) int64 { switch value := obj.Property(property).(type) { - case int: - return int64(value) case int64: return value + case int: + return int64(value) + case uint64: + return int64(value) + case uint32: + return int64(value) case uintptr: return int64(value) case float32: @@ -571,9 +576,13 @@ func (obj *Common) Int64(property string) int64 { // Float64 panics if the property cannot be represented as float64. func (obj *Common) Float64(property string) float64 { switch value := obj.Property(property).(type) { + case int64: + return float64(value) case int: return float64(value) - case int64: + case uint64: + return float64(value) + case uint32: return float64(value) case uintptr: return float64(value)