Skip to content

Commit

Permalink
Update capi.cpp
Browse files Browse the repository at this point in the history
Removes all dynamic_cast, in order to make it work without RTTI. This is due to golang/go#10023 (duplicate of golang/go#4069) and solves go-qml#19.
  • Loading branch information
neclepsio authored and KellyLSB committed May 27, 2016
1 parent 1feaf27 commit bc32fe2
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions cpp/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <string.h>

#include <stdio.h>

#include "govalue.h"
#include "govaluetype.h"
#include "connector.h"
Expand Down Expand Up @@ -535,34 +537,37 @@ QQmlContext_ *objectContext(QObject_ *object)
int objectIsComponent(QObject_ *object)
{
QObject *qobject = static_cast<QObject *>(object);
return dynamic_cast<QQmlComponent *>(qobject) ? 1 : 0;
return qobject->inherits("QQmlComponent") ? 1 : 0;
//return dynamic_cast<QQmlComponent *>(qobject) ? 1 : 0;
}

int objectIsWindow(QObject_ *object)
{
QObject *qobject = static_cast<QObject *>(object);
return dynamic_cast<QQuickWindow *>(qobject) ? 1 : 0;
return qobject->inherits("QQuickWindow") ? 1 : 0;
//return dynamic_cast<QQuickWindow *>(qobject) ? 1 : 0;
}

int objectIsView(QObject_ *object)
{
QObject *qobject = static_cast<QObject *>(object);
return dynamic_cast<QQuickView *>(qobject) ? 1 : 0;
return qobject->inherits("QQuickView") ? 1 : 0;
//return dynamic_cast<QQuickView *>(qobject) ? 1 : 0;
}

error *objectGoAddr(QObject_ *object, GoAddr **addr)
{
QObject *qobject = static_cast<QObject *>(object);
GoValue *goValue = dynamic_cast<GoValue *>(qobject);
if (goValue) {
QObject *qobject = static_cast<QObject *>(object);
if (qobject->inherits("GoValue")) {
GoValue *goValue = static_cast<GoValue *>(qobject);
*addr = goValue->addr;
return 0;
}
GoPaintedValue *goPaintedValue = dynamic_cast<GoPaintedValue *>(qobject);
if (goPaintedValue) {
return 0;
}
if (qobject->inherits("GoPaintedValue")) {
GoPaintedValue *goPaintedValue = static_cast<GoPaintedValue *>(qobject);
*addr = goPaintedValue->addr;
return 0;
}
return 0;
}
return errorf("QML object is not backed by a Go value");
}

Expand Down Expand Up @@ -762,18 +767,16 @@ void packDataValue(QVariant_ *var, DataValue *value)
default:
if (qvar->type() == (int)QMetaType::QObjectStar || qvar->canConvert<QObject *>()) {
QObject *qobject = qvar->value<QObject *>();
GoValue *goValue = dynamic_cast<GoValue *>(qobject);
if (goValue) {
if (qobject->inherits("GoValue")) {
value->dataType = DTGoAddr;
*(void **)(value->data) = goValue->addr;
*(void **)(value->data) = (static_cast<GoValue*>(qobject))->addr;
break;
}
GoPaintedValue *goPaintedValue = dynamic_cast<GoPaintedValue *>(qobject);
if (goPaintedValue) {
}
if (qobject->inherits("GoPaintedValue")) {
value->dataType = DTGoAddr;
*(void **)(value->data) = goPaintedValue->addr;
*(void **)(value->data) = (static_cast<GoPaintedValue*>(qobject))->addr;
break;
}
}
value->dataType = DTObject;
*(void **)(value->data) = qobject;
break;
Expand Down

0 comments on commit bc32fe2

Please sign in to comment.