From 2186e42697da78728af71708bbae270c9f32932a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Mon, 30 Nov 2015 14:49:18 +0100 Subject: [PATCH] Debugger: Make sure there are no bools in Python code Python doesn't like lowercase "true" or "false", so we have to convert those to int before we send the command. Change-Id: Id30ebbb0714cae23b030c78eec5e59378ac467bb Reviewed-by: Christian Stenger --- src/plugins/debugger/debuggerprotocol.cpp | 33 +++++++++++++++++++---- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/plugins/debugger/debuggerprotocol.cpp b/src/plugins/debugger/debuggerprotocol.cpp index 23162320368..4a1a7574b4c 100644 --- a/src/plugins/debugger/debuggerprotocol.cpp +++ b/src/plugins/debugger/debuggerprotocol.cpp @@ -853,14 +853,37 @@ void DebuggerCommand::arg(const char *name, const QJsonValue &value) args = addToJsonObject(args, name, value); } +static QJsonValue translateJsonToPython(const QJsonValue &value) +{ + // TODO: Verify that this covers all incompatibilities between python and json. + switch (value.type()) { + case QJsonValue::Bool: + // Python doesn't understand lowercase "true" or "false" + return QJsonValue(value.toBool() ? 1 : 0); + case QJsonValue::Object: { + QJsonObject object = value.toObject(); + for (QJsonObject::iterator i = object.begin(); i != object.end(); ++i) + i.value() = translateJsonToPython(i.value()); + return object; + } + case QJsonValue::Array: { + QJsonArray array = value.toArray(); + for (QJsonArray::iterator i = array.begin(); i != array.end(); ++i) + *i = translateJsonToPython(*i); + return array; + } + default: + return value; + } +} + QByteArray DebuggerCommand::argsToPython() const { - // TODO: Verify that this is really Python. - - if (args.isArray()) - return QJsonDocument(args.toArray()).toJson(QJsonDocument::Compact); + QJsonValue pythonCompatible(translateJsonToPython(args)); + if (pythonCompatible.isArray()) + return QJsonDocument(pythonCompatible.toArray()).toJson(QJsonDocument::Compact); else - return QJsonDocument(args.toObject()).toJson(QJsonDocument::Compact); + return QJsonDocument(pythonCompatible.toObject()).toJson(QJsonDocument::Compact); } QByteArray DebuggerCommand::argsToString() const