Skip to content

Commit

Permalink
corelib: serialization - fix macos unity builds
Browse files Browse the repository at this point in the history
CarbonCore defines `DEBUG`, which can nameclash with the `DEBUG` define
in the json parser when using unity builds

Change-Id: Ic9f666a1da98aaebe30836abf877228f2f83004c
Pick-to: 6.7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
timblechmann committed Feb 6, 2024
1 parent 6833adf commit cadc239
Showing 1 changed file with 50 additions and 42 deletions.
92 changes: 50 additions & 42 deletions src/corelib/serialization/qjsonparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@

//#define PARSER_DEBUG
#ifdef PARSER_DEBUG
# error currently broken after `current` was moved to StashedContainer
Q_CONSTINIT static int indent = 0;
#define BEGIN qDebug() << QByteArray(4*indent++, ' ').constData() << "pos=" << current
#define END --indent
#define DEBUG qDebug() << QByteArray(4*indent, ' ').constData()
# define QT_PARSER_TRACING_BEGIN \
qDebug() << QByteArray(4 * indent++, ' ').constData() << "pos=" << current
# define QT_PARSER_TRACING_END --indent
# define QT_PARSER_TRACING_DEBUG qDebug() << QByteArray(4 * indent, ' ').constData()
#else
#define BEGIN if (1) ; else qDebug()
#define END do {} while (0)
#define DEBUG if (1) ; else qDebug()
# define QT_PARSER_TRACING_BEGIN QT_NO_QDEBUG_MACRO()
# define QT_PARSER_TRACING_END \
do { \
} while (0)
# define QT_PARSER_TRACING_DEBUG QT_NO_QDEBUG_MACRO()
#endif

static const int nestingLimit = 1024;
Expand Down Expand Up @@ -301,7 +305,7 @@ QCborValue Parser::parse(QJsonParseError *error)

QCborValue data;

DEBUG << Qt::hex << (uint)token;
QT_PARSER_TRACING_DEBUG << Qt::hex << (uint)token;
if (token == BeginArray) {
container = new QCborContainerPrivate;
if (!parseArray())
Expand All @@ -325,7 +329,7 @@ QCborValue Parser::parse(QJsonParseError *error)
goto error;
}

END;
QT_PARSER_TRACING_END;
{
if (error) {
error->offset = 0;
Expand Down Expand Up @@ -457,7 +461,7 @@ bool Parser::parseObject()
return false;
}

BEGIN << "parseObject" << json;
QT_PARSER_TRACING_BEGIN << "parseObject" << json;

char token = nextToken();
while (token == Quote) {
Expand All @@ -475,13 +479,13 @@ bool Parser::parseObject()
}
}

DEBUG << "end token=" << token;
QT_PARSER_TRACING_DEBUG << "end token=" << token;
if (token != EndObject) {
lastError = QJsonParseError::UnterminatedObject;
return false;
}

END;
QT_PARSER_TRACING_END;

--nestingLevel;

Expand All @@ -495,7 +499,7 @@ bool Parser::parseObject()
*/
bool Parser::parseMember()
{
BEGIN << "parseMember";
QT_PARSER_TRACING_BEGIN << "parseMember";

if (!parseString())
return false;
Expand All @@ -511,7 +515,7 @@ bool Parser::parseMember()
if (!parseValue())
return false;

END;
QT_PARSER_TRACING_END;
return true;
}

Expand All @@ -520,7 +524,7 @@ bool Parser::parseMember()
*/
bool Parser::parseArray()
{
BEGIN << "parseArray";
QT_PARSER_TRACING_BEGIN << "parseArray";

if (++nestingLevel > nestingLimit) {
lastError = QJsonParseError::DeepNesting;
Expand Down Expand Up @@ -556,8 +560,8 @@ bool Parser::parseArray()
}
}

DEBUG << "size =" << (container ? container->elements.size() : 0);
END;
QT_PARSER_TRACING_DEBUG << "size =" << (container ? container->elements.size() : 0);
QT_PARSER_TRACING_END;

--nestingLevel;

Expand All @@ -571,7 +575,7 @@ value = false / null / true / object / array / number / string

bool Parser::parseValue()
{
BEGIN << "parse Value" << json;
QT_PARSER_TRACING_BEGIN << "parse Value" << json;

switch (*json++) {
case 'n':
Expand All @@ -583,8 +587,8 @@ bool Parser::parseValue()
*json++ == 'l' &&
*json++ == 'l') {
container->append(QCborValue(QCborValue::Null));
DEBUG << "value: null";
END;
QT_PARSER_TRACING_DEBUG << "value: null";
QT_PARSER_TRACING_END;
return true;
}
lastError = QJsonParseError::IllegalValue;
Expand All @@ -598,8 +602,8 @@ bool Parser::parseValue()
*json++ == 'u' &&
*json++ == 'e') {
container->append(QCborValue(true));
DEBUG << "value: true";
END;
QT_PARSER_TRACING_DEBUG << "value: true";
QT_PARSER_TRACING_END;
return true;
}
lastError = QJsonParseError::IllegalValue;
Expand All @@ -614,33 +618,33 @@ bool Parser::parseValue()
*json++ == 's' &&
*json++ == 'e') {
container->append(QCborValue(false));
DEBUG << "value: false";
END;
QT_PARSER_TRACING_DEBUG << "value: false";
QT_PARSER_TRACING_END;
return true;
}
lastError = QJsonParseError::IllegalValue;
return false;
case Quote: {
if (!parseString())
return false;
DEBUG << "value: string";
END;
QT_PARSER_TRACING_DEBUG << "value: string";
QT_PARSER_TRACING_END;
return true;
}
case BeginArray: {
StashedContainer stashedContainer(&container, QCborValue::Array);
if (!parseArray())
return false;
DEBUG << "value: array";
END;
QT_PARSER_TRACING_DEBUG << "value: array";
QT_PARSER_TRACING_END;
return true;
}
case BeginObject: {
StashedContainer stashedContainer(&container, QCborValue::Map);
if (!parseObject())
return false;
DEBUG << "value: object";
END;
QT_PARSER_TRACING_DEBUG << "value: object";
QT_PARSER_TRACING_END;
return true;
}
case ValueSeparator:
Expand All @@ -656,8 +660,8 @@ bool Parser::parseValue()
--json;
if (!parseNumber())
return false;
DEBUG << "value: number";
END;
QT_PARSER_TRACING_DEBUG << "value: number";
QT_PARSER_TRACING_END;
}

return true;
Expand All @@ -683,7 +687,7 @@ bool Parser::parseValue()

bool Parser::parseNumber()
{
BEGIN << "parseNumber" << json;
QT_PARSER_TRACING_BEGIN << "parseNumber" << json;

const char *start = json;
bool isInt = true;
Expand Down Expand Up @@ -725,14 +729,14 @@ bool Parser::parseNumber()
}

const QByteArray number = QByteArray::fromRawData(start, json - start);
DEBUG << "numberstring" << number;
QT_PARSER_TRACING_DEBUG << "numberstring" << number;

if (isInt) {
bool ok;
qlonglong n = number.toLongLong(&ok);
if (ok) {
container->append(QCborValue(n));
END;
QT_PARSER_TRACING_END;
return true;
}
}
Expand All @@ -751,7 +755,7 @@ bool Parser::parseNumber()
else
container->append(QCborValue(d));

END;
QT_PARSER_TRACING_END;
return true;
}

Expand Down Expand Up @@ -795,7 +799,7 @@ static inline bool scanEscapeSequence(const char *&json, const char *end, char32
if (json >= end)
return false;

DEBUG << "scan escape" << (char)*json;
QT_PARSER_TRACING_DEBUG << "scan escape" << (char)*json;
uchar escaped = *json++;
switch (escaped) {
case '"':
Expand Down Expand Up @@ -853,7 +857,7 @@ bool Parser::parseString()

// try to parse a utf-8 string without escape sequences, and note whether it's 7bit ASCII.

BEGIN << "parse string" << json;
QT_PARSER_TRACING_BEGIN << "parse string" << json;
bool isUtf8 = true;
bool isAscii = true;
while (json < end) {
Expand All @@ -874,10 +878,10 @@ bool Parser::parseString()
}
if (ch > 0x7f)
isAscii = false;
DEBUG << " " << ch << char(ch);
QT_PARSER_TRACING_DEBUG << " " << ch << char(ch);
}
++json;
DEBUG << "end of string";
QT_PARSER_TRACING_DEBUG << "end of string";
if (json >= end) {
lastError = QJsonParseError::UnterminatedString;
return false;
Expand All @@ -889,11 +893,11 @@ bool Parser::parseString()
container->appendAsciiString(start, json - start - 1);
else
container->appendUtf8String(start, json - start - 1);
END;
QT_PARSER_TRACING_END;
return true;
}

DEBUG << "has escape sequences";
QT_PARSER_TRACING_DEBUG << "has escape sequences";

json = start;

Expand Down Expand Up @@ -924,8 +928,12 @@ bool Parser::parseString()

container->appendByteData(reinterpret_cast<const char *>(ucs4.constData()), ucs4.size() * 2,
QCborValue::String, QtCbor::Element::StringIsUtf16);
END;
QT_PARSER_TRACING_END;
return true;
}

QT_END_NAMESPACE

#undef QT_PARSER_TRACING_BEGIN
#undef QT_PARSER_TRACING_END
#undef QT_PARSER_TRACING_DEBUG

0 comments on commit cadc239

Please sign in to comment.