From aaae5636aec4ad6185b97b361d9a6e938ad2ae46 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 29 Jul 2011 12:28:03 +1000 Subject: [PATCH] Fix alias warnings in QV8QObjectWrapper Task-number: QTBUG-19736 QTBUG-19693 Change-Id: I4f6c56dc4f60224dd79e669099c198b883429f54 Reviewed-on: http://codereview.qt.nokia.com/2363 Reviewed-by: Aaron Kennedy --- src/declarative/qml/v8/qv8engine_p.h | 2 +- src/declarative/qml/v8/qv8qobjectwrapper.cpp | 119 +++++++++++++++------------ 2 files changed, 69 insertions(+), 52 deletions(-) diff --git a/src/declarative/qml/v8/qv8engine_p.h b/src/declarative/qml/v8/qv8engine_p.h index 82d6969..340945c 100644 --- a/src/declarative/qml/v8/qv8engine_p.h +++ b/src/declarative/qml/v8/qv8engine_p.h @@ -195,7 +195,7 @@ public: return QDeclarativeV8Handle(*h); } v8::Handle toHandle() const { - return reinterpret_cast &>(*this); + return v8::Handle((v8::Value *)d); } private: QDeclarativeV8Handle(void *d) : d(d) {} diff --git a/src/declarative/qml/v8/qv8qobjectwrapper.cpp b/src/declarative/qml/v8/qv8qobjectwrapper.cpp index 393f837..cc0380e 100644 --- a/src/declarative/qml/v8/qv8qobjectwrapper.cpp +++ b/src/declarative/qml/v8/qv8qobjectwrapper.cpp @@ -122,9 +122,26 @@ private: inline void cleanup(); - char data[4 * sizeof(void *)]; + union { + float floatValue; + double doubleValue; + quint32 intValue; + bool boolValue; + QObject *qobjectPtr; + + char allocData[sizeof(QVariant)]; + }; + + // Pointers to allocData + union { + QString *qstringPtr; + QVariant *qvariantPtr; + QList *qlistPtr; + QScriptValue *qscriptValuePtr; + QDeclarativeV8Handle *handlePtr; + }; + int type; - bool isObjectType; }; } @@ -316,7 +333,7 @@ static v8::Handle LoadProperty(QV8Engine *engine, QObject *object, QDeclarativeV8Handle handle; void *args[] = { &handle, 0 }; QMetaObject::metacall(object, QMetaObject::ReadProperty, property.coreIndex, args); - return reinterpret_cast &>(handle); + return handle.toHandle(); } else if (QDeclarativeValueTypeFactory::isValueType((uint)property.propType)) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine()); QDeclarativeValueType *valueType = ep->valueTypes[property.propType]; @@ -361,7 +378,7 @@ static v8::Handle LoadPropertyDirect(QV8Engine *engine, QObject *obje QDeclarativeV8Handle handle; void *args[] = { &handle, 0 }; object->qt_metacall(QMetaObject::ReadProperty, property.coreIndex, args); - return reinterpret_cast &>(handle); + return handle.toHandle(); } else if (QDeclarativeValueTypeFactory::isValueType((uint)property.propType)) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine()); QDeclarativeValueType *valueType = ep->valueTypes[property.propType]; @@ -1805,7 +1822,7 @@ v8::Handle QV8QObjectWrapper::Invoke(const v8::Arguments &args) } MetaCallArgument::MetaCallArgument() -: type(QVariant::Invalid), isObjectType(false) +: type(QVariant::Invalid) { } @@ -1817,22 +1834,22 @@ MetaCallArgument::~MetaCallArgument() void MetaCallArgument::cleanup() { if (type == QMetaType::QString) { - ((QString *)&data)->~QString(); - } else if (type == -1 || type == qMetaTypeId()) { - ((QVariant *)&data)->~QVariant(); + qstringPtr->~QString(); + } else if (type == -1 || type == QMetaType::QVariant) { + qvariantPtr->~QVariant(); } else if (type == qMetaTypeId()) { - ((QScriptValue *)&data)->~QScriptValue(); + qscriptValuePtr->~QScriptValue(); } else if (type == qMetaTypeId >()) { - ((QList *)&data)->~QList(); - } + qlistPtr->~QList(); + } } void *MetaCallArgument::dataPtr() { if (type == -1) - return ((QVariant *)data)->data(); + return qvariantPtr->data(); else - return (void *)&data; + return (void *)&allocData; } void MetaCallArgument::initAsType(int callType) @@ -1841,7 +1858,7 @@ void MetaCallArgument::initAsType(int callType) if (callType == 0) return; if (callType == qMetaTypeId()) { - new (&data) QScriptValue(); + qscriptValuePtr = new (&allocData) QScriptValue(); type = callType; } else if (callType == QMetaType::Int || callType == QMetaType::UInt || @@ -1850,23 +1867,23 @@ void MetaCallArgument::initAsType(int callType) callType == QMetaType::Float) { type = callType; } else if (callType == QMetaType::QObjectStar) { - *((QObject **)&data) = 0; + qobjectPtr = 0; type = callType; } else if (callType == QMetaType::QString) { - new (&data) QString(); + qstringPtr = new (&allocData) QString(); type = callType; - } else if (callType == qMetaTypeId()) { + } else if (callType == QMetaType::QVariant) { type = callType; - new (&data) QVariant(); + qvariantPtr = new (&allocData) QVariant(); } else if (callType == qMetaTypeId >()) { type = callType; - new (&data) QList(); + qlistPtr = new (&allocData) QList(); } else if (callType == qMetaTypeId()) { type = callType; - new (&data) v8::Handle(); + handlePtr = new (&allocData) QDeclarativeV8Handle; } else { type = -1; - new (&data) QVariant(callType, (void *)0); + qvariantPtr = new (&allocData) QVariant(callType, (void *)0); } } @@ -1875,61 +1892,61 @@ void MetaCallArgument::fromValue(int callType, QV8Engine *engine, v8::Handle()) { - new (&data) QScriptValue(); + qscriptValuePtr = new (&allocData) QScriptValue(); type = qMetaTypeId(); } else if (callType == QMetaType::Int) { - *((int *)&data) = int(value->Int32Value()); + intValue = quint32(value->Int32Value()); type = callType; } else if (callType == QMetaType::UInt) { - *((uint *)&data) = uint(value->Uint32Value()); + intValue = quint32(value->Uint32Value()); type = callType; } else if (callType == QMetaType::Bool) { - *((bool *)&data) = value->BooleanValue(); + boolValue = value->BooleanValue(); type = callType; } else if (callType == QMetaType::Double) { - *((double *)&data) = double(value->NumberValue()); + doubleValue = double(value->NumberValue()); type = callType; } else if (callType == QMetaType::Float) { - *((float *)&data) = float(value->NumberValue()); + floatValue = float(value->NumberValue()); type = callType; } else if (callType == QMetaType::QString) { if (value->IsNull() || value->IsUndefined()) - new (&data) QString(); + qstringPtr = new (&allocData) QString(); else - new (&data) QString(engine->toString(value->ToString())); + qstringPtr = new (&allocData) QString(engine->toString(value->ToString())); type = callType; } else if (callType == QMetaType::QObjectStar) { - *((QObject **)&data) = engine->toQObject(value); + qobjectPtr = engine->toQObject(value); type = callType; } else if (callType == qMetaTypeId()) { - new (&data) QVariant(engine->toVariant(value, -1)); + qvariantPtr = new (&allocData) QVariant(engine->toVariant(value, -1)); type = callType; } else if (callType == qMetaTypeId >()) { - QList *list = new (&data) QList(); + qlistPtr = new (&allocData) QList(); if (value->IsArray()) { v8::Handle array = v8::Handle::Cast(value); uint32_t length = array->Length(); for (uint32_t ii = 0; ii < length; ++ii) - list->append(engine->toQObject(array->Get(ii))); + qlistPtr->append(engine->toQObject(array->Get(ii))); } else { - list->append(engine->toQObject(value)); + qlistPtr->append(engine->toQObject(value)); } type = callType; } else if (callType == qMetaTypeId()) { - new (&data) v8::Handle(value); + handlePtr = new (&allocData) QDeclarativeV8Handle(QDeclarativeV8Handle::fromHandle(value)); type = callType; } else { - new (&data) QVariant(); + qvariantPtr = new (&allocData) QVariant(); type = -1; QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine->engine()); QVariant v = engine->toVariant(value, -1); if (v.userType() == callType) { - *((QVariant *)&data) = v; + *qvariantPtr = v; } else if (v.canConvert((QVariant::Type)callType)) { - *((QVariant *)&data) = v; - ((QVariant *)&data)->convert((QVariant::Type)callType); + *qvariantPtr = v; + qvariantPtr->convert((QVariant::Type)callType); } else if (const QMetaObject *mo = ep->rawMetaObjectForType(callType)) { QObject *obj = ep->toQObject(v); @@ -1939,9 +1956,9 @@ void MetaCallArgument::fromValue(int callType, QV8Engine *engine, v8::Handle MetaCallArgument::toValue(QV8Engine *engine) if (type == qMetaTypeId()) { return v8::Undefined(); } else if (type == QMetaType::Int) { - return v8::Integer::New(*((int *)&data)); + return v8::Integer::New(int(intValue)); } else if (type == QMetaType::UInt) { - return v8::Integer::NewFromUnsigned(*((uint *)&data)); + return v8::Integer::NewFromUnsigned(intValue); } else if (type == QMetaType::Bool) { - return v8::Boolean::New(*((bool *)&data)); + return v8::Boolean::New(boolValue); } else if (type == QMetaType::Double) { - return v8::Number::New(*((double *)&data)); + return v8::Number::New(doubleValue); } else if (type == QMetaType::Float) { - return v8::Number::New(*((float *)&data)); + return v8::Number::New(floatValue); } else if (type == QMetaType::QString) { - return engine->toString(*((QString *)&data)); + return engine->toString(*qstringPtr); } else if (type == QMetaType::QObjectStar) { - QObject *object = *((QObject **)&data); + QObject *object = qobjectPtr; if (object) QDeclarativeData::get(object, true)->setImplicitDestructible(); return engine->newQObject(object); } else if (type == qMetaTypeId >()) { // XXX Can this be made more by using Array as a prototype and implementing // directly against QList? - QList &list = *(QList*)&data; + QList &list = *qlistPtr; v8::Local array = v8::Array::New(list.count()); for (int ii = 0; ii < list.count(); ++ii) array->Set(ii, engine->newQObject(list.at(ii))); return array; } else if (type == qMetaTypeId()) { - return *(v8::Handle*)&data; + return handlePtr->toHandle(); } else if (type == -1 || type == qMetaTypeId()) { - QVariant value = *((QVariant *)&data); + QVariant value = *qvariantPtr; v8::Handle rv = engine->fromVariant(value); if (QObject *object = engine->toQObject(rv)) QDeclarativeData::get(object, true)->setImplicitDestructible(); -- 2.7.4