corelib: serialization - fix macos unity builds

CarbonCore defines `DEBUG`, which can nameclash with the `DEBUG` define
in the json parser when using unity builds

Change-Id: Ic9f666a1da98aaebe30836abf877228f2f83004c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit cadc239c485ee4f1ab3587f3c53c548238c40fa5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tim Blechmann 2024-01-27 16:55:53 +08:00 committed by Qt Cherry-pick Bot
parent b21556bf2b
commit e7f10f7e76

View File

@ -15,14 +15,18 @@
//#define PARSER_DEBUG //#define PARSER_DEBUG
#ifdef PARSER_DEBUG #ifdef PARSER_DEBUG
# error currently broken after `current` was moved to StashedContainer
Q_CONSTINIT static int indent = 0; Q_CONSTINIT static int indent = 0;
#define BEGIN qDebug() << QByteArray(4*indent++, ' ').constData() << "pos=" << current # define QT_PARSER_TRACING_BEGIN \
#define END --indent qDebug() << QByteArray(4 * indent++, ' ').constData() << "pos=" << current
#define DEBUG qDebug() << QByteArray(4*indent, ' ').constData() # define QT_PARSER_TRACING_END --indent
# define QT_PARSER_TRACING_DEBUG qDebug() << QByteArray(4 * indent, ' ').constData()
#else #else
#define BEGIN if (1) ; else qDebug() # define QT_PARSER_TRACING_BEGIN QT_NO_QDEBUG_MACRO()
#define END do {} while (0) # define QT_PARSER_TRACING_END \
#define DEBUG if (1) ; else qDebug() do { \
} while (0)
# define QT_PARSER_TRACING_DEBUG QT_NO_QDEBUG_MACRO()
#endif #endif
static const int nestingLimit = 1024; static const int nestingLimit = 1024;
@ -301,7 +305,7 @@ QCborValue Parser::parse(QJsonParseError *error)
QCborValue data; QCborValue data;
DEBUG << Qt::hex << (uint)token; QT_PARSER_TRACING_DEBUG << Qt::hex << (uint)token;
if (token == BeginArray) { if (token == BeginArray) {
container = new QCborContainerPrivate; container = new QCborContainerPrivate;
if (!parseArray()) if (!parseArray())
@ -325,7 +329,7 @@ QCborValue Parser::parse(QJsonParseError *error)
goto error; goto error;
} }
END; QT_PARSER_TRACING_END;
{ {
if (error) { if (error) {
error->offset = 0; error->offset = 0;
@ -457,7 +461,7 @@ bool Parser::parseObject()
return false; return false;
} }
BEGIN << "parseObject" << json; QT_PARSER_TRACING_BEGIN << "parseObject" << json;
char token = nextToken(); char token = nextToken();
while (token == Quote) { while (token == Quote) {
@ -475,13 +479,13 @@ bool Parser::parseObject()
} }
} }
DEBUG << "end token=" << token; QT_PARSER_TRACING_DEBUG << "end token=" << token;
if (token != EndObject) { if (token != EndObject) {
lastError = QJsonParseError::UnterminatedObject; lastError = QJsonParseError::UnterminatedObject;
return false; return false;
} }
END; QT_PARSER_TRACING_END;
--nestingLevel; --nestingLevel;
@ -495,7 +499,7 @@ bool Parser::parseObject()
*/ */
bool Parser::parseMember() bool Parser::parseMember()
{ {
BEGIN << "parseMember"; QT_PARSER_TRACING_BEGIN << "parseMember";
if (!parseString()) if (!parseString())
return false; return false;
@ -511,7 +515,7 @@ bool Parser::parseMember()
if (!parseValue()) if (!parseValue())
return false; return false;
END; QT_PARSER_TRACING_END;
return true; return true;
} }
@ -520,7 +524,7 @@ bool Parser::parseMember()
*/ */
bool Parser::parseArray() bool Parser::parseArray()
{ {
BEGIN << "parseArray"; QT_PARSER_TRACING_BEGIN << "parseArray";
if (++nestingLevel > nestingLimit) { if (++nestingLevel > nestingLimit) {
lastError = QJsonParseError::DeepNesting; lastError = QJsonParseError::DeepNesting;
@ -556,8 +560,8 @@ bool Parser::parseArray()
} }
} }
DEBUG << "size =" << (container ? container->elements.size() : 0); QT_PARSER_TRACING_DEBUG << "size =" << (container ? container->elements.size() : 0);
END; QT_PARSER_TRACING_END;
--nestingLevel; --nestingLevel;
@ -571,7 +575,7 @@ value = false / null / true / object / array / number / string
bool Parser::parseValue() bool Parser::parseValue()
{ {
BEGIN << "parse Value" << json; QT_PARSER_TRACING_BEGIN << "parse Value" << json;
switch (*json++) { switch (*json++) {
case 'n': case 'n':
@ -583,8 +587,8 @@ bool Parser::parseValue()
*json++ == 'l' && *json++ == 'l' &&
*json++ == 'l') { *json++ == 'l') {
container->append(QCborValue(QCborValue::Null)); container->append(QCborValue(QCborValue::Null));
DEBUG << "value: null"; QT_PARSER_TRACING_DEBUG << "value: null";
END; QT_PARSER_TRACING_END;
return true; return true;
} }
lastError = QJsonParseError::IllegalValue; lastError = QJsonParseError::IllegalValue;
@ -598,8 +602,8 @@ bool Parser::parseValue()
*json++ == 'u' && *json++ == 'u' &&
*json++ == 'e') { *json++ == 'e') {
container->append(QCborValue(true)); container->append(QCborValue(true));
DEBUG << "value: true"; QT_PARSER_TRACING_DEBUG << "value: true";
END; QT_PARSER_TRACING_END;
return true; return true;
} }
lastError = QJsonParseError::IllegalValue; lastError = QJsonParseError::IllegalValue;
@ -614,8 +618,8 @@ bool Parser::parseValue()
*json++ == 's' && *json++ == 's' &&
*json++ == 'e') { *json++ == 'e') {
container->append(QCborValue(false)); container->append(QCborValue(false));
DEBUG << "value: false"; QT_PARSER_TRACING_DEBUG << "value: false";
END; QT_PARSER_TRACING_END;
return true; return true;
} }
lastError = QJsonParseError::IllegalValue; lastError = QJsonParseError::IllegalValue;
@ -623,24 +627,24 @@ bool Parser::parseValue()
case Quote: { case Quote: {
if (!parseString()) if (!parseString())
return false; return false;
DEBUG << "value: string"; QT_PARSER_TRACING_DEBUG << "value: string";
END; QT_PARSER_TRACING_END;
return true; return true;
} }
case BeginArray: { case BeginArray: {
StashedContainer stashedContainer(&container, QCborValue::Array); StashedContainer stashedContainer(&container, QCborValue::Array);
if (!parseArray()) if (!parseArray())
return false; return false;
DEBUG << "value: array"; QT_PARSER_TRACING_DEBUG << "value: array";
END; QT_PARSER_TRACING_END;
return true; return true;
} }
case BeginObject: { case BeginObject: {
StashedContainer stashedContainer(&container, QCborValue::Map); StashedContainer stashedContainer(&container, QCborValue::Map);
if (!parseObject()) if (!parseObject())
return false; return false;
DEBUG << "value: object"; QT_PARSER_TRACING_DEBUG << "value: object";
END; QT_PARSER_TRACING_END;
return true; return true;
} }
case ValueSeparator: case ValueSeparator:
@ -656,8 +660,8 @@ bool Parser::parseValue()
--json; --json;
if (!parseNumber()) if (!parseNumber())
return false; return false;
DEBUG << "value: number"; QT_PARSER_TRACING_DEBUG << "value: number";
END; QT_PARSER_TRACING_END;
} }
return true; return true;
@ -683,7 +687,7 @@ bool Parser::parseValue()
bool Parser::parseNumber() bool Parser::parseNumber()
{ {
BEGIN << "parseNumber" << json; QT_PARSER_TRACING_BEGIN << "parseNumber" << json;
const char *start = json; const char *start = json;
bool isInt = true; bool isInt = true;
@ -725,14 +729,14 @@ bool Parser::parseNumber()
} }
const QByteArray number = QByteArray::fromRawData(start, json - start); const QByteArray number = QByteArray::fromRawData(start, json - start);
DEBUG << "numberstring" << number; QT_PARSER_TRACING_DEBUG << "numberstring" << number;
if (isInt) { if (isInt) {
bool ok; bool ok;
qlonglong n = number.toLongLong(&ok); qlonglong n = number.toLongLong(&ok);
if (ok) { if (ok) {
container->append(QCborValue(n)); container->append(QCborValue(n));
END; QT_PARSER_TRACING_END;
return true; return true;
} }
} }
@ -751,7 +755,7 @@ bool Parser::parseNumber()
else else
container->append(QCborValue(d)); container->append(QCborValue(d));
END; QT_PARSER_TRACING_END;
return true; return true;
} }
@ -795,7 +799,7 @@ static inline bool scanEscapeSequence(const char *&json, const char *end, char32
if (json >= end) if (json >= end)
return false; return false;
DEBUG << "scan escape" << (char)*json; QT_PARSER_TRACING_DEBUG << "scan escape" << (char)*json;
uchar escaped = *json++; uchar escaped = *json++;
switch (escaped) { switch (escaped) {
case '"': case '"':
@ -853,7 +857,7 @@ bool Parser::parseString()
// try to parse a utf-8 string without escape sequences, and note whether it's 7bit ASCII. // 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 isUtf8 = true;
bool isAscii = true; bool isAscii = true;
while (json < end) { while (json < end) {
@ -874,10 +878,10 @@ bool Parser::parseString()
} }
if (ch > 0x7f) if (ch > 0x7f)
isAscii = false; isAscii = false;
DEBUG << " " << ch << char(ch); QT_PARSER_TRACING_DEBUG << " " << ch << char(ch);
} }
++json; ++json;
DEBUG << "end of string"; QT_PARSER_TRACING_DEBUG << "end of string";
if (json >= end) { if (json >= end) {
lastError = QJsonParseError::UnterminatedString; lastError = QJsonParseError::UnterminatedString;
return false; return false;
@ -889,11 +893,11 @@ bool Parser::parseString()
container->appendAsciiString(start, json - start - 1); container->appendAsciiString(start, json - start - 1);
else else
container->appendUtf8String(start, json - start - 1); container->appendUtf8String(start, json - start - 1);
END; QT_PARSER_TRACING_END;
return true; return true;
} }
DEBUG << "has escape sequences"; QT_PARSER_TRACING_DEBUG << "has escape sequences";
json = start; json = start;
@ -924,8 +928,12 @@ bool Parser::parseString()
container->appendByteData(reinterpret_cast<const char *>(ucs4.constData()), ucs4.size() * 2, container->appendByteData(reinterpret_cast<const char *>(ucs4.constData()), ucs4.size() * 2,
QCborValue::String, QtCbor::Element::StringIsUtf16); QCborValue::String, QtCbor::Element::StringIsUtf16);
END; QT_PARSER_TRACING_END;
return true; return true;
} }
QT_END_NAMESPACE QT_END_NAMESPACE
#undef QT_PARSER_TRACING_BEGIN
#undef QT_PARSER_TRACING_END
#undef QT_PARSER_TRACING_DEBUG