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
#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;
@ -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())
@ -325,7 +329,7 @@ QCborValue Parser::parse(QJsonParseError *error)
goto error;
}
END;
QT_PARSER_TRACING_END;
{
if (error) {
error->offset = 0;
@ -457,7 +461,7 @@ bool Parser::parseObject()
return false;
}
BEGIN << "parseObject" << json;
QT_PARSER_TRACING_BEGIN << "parseObject" << json;
char token = nextToken();
while (token == Quote) {
@ -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;
@ -495,7 +499,7 @@ bool Parser::parseObject()
*/
bool Parser::parseMember()
{
BEGIN << "parseMember";
QT_PARSER_TRACING_BEGIN << "parseMember";
if (!parseString())
return false;
@ -511,7 +515,7 @@ bool Parser::parseMember()
if (!parseValue())
return false;
END;
QT_PARSER_TRACING_END;
return true;
}
@ -520,7 +524,7 @@ bool Parser::parseMember()
*/
bool Parser::parseArray()
{
BEGIN << "parseArray";
QT_PARSER_TRACING_BEGIN << "parseArray";
if (++nestingLevel > nestingLimit) {
lastError = QJsonParseError::DeepNesting;
@ -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;
@ -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':
@ -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;
@ -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;
@ -614,8 +618,8 @@ 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;
@ -623,24 +627,24 @@ bool Parser::parseValue()
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:
@ -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;
@ -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;
@ -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;
}
}
@ -751,7 +755,7 @@ bool Parser::parseNumber()
else
container->append(QCborValue(d));
END;
QT_PARSER_TRACING_END;
return true;
}
@ -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 '"':
@ -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) {
@ -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;
@ -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;
@ -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