CBOR: disable UUID and QRegularExpression support in bootstrapped builds

We don't need them.

Drive-by opportunity to ensure byteData() didn't return null. It could
happen.

Change-Id: I74249c52dc02478ba93cfffd16d1e1fc060cdaef
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Thiago Macieira 2022-02-08 10:10:11 -08:00
parent a1b2c474fd
commit 1f7089437a
3 changed files with 27 additions and 22 deletions

View File

@ -1861,7 +1861,6 @@ QCborValue::QCborValue(const QUrl &url)
t = Url; t = Url;
container->elements[1].type = String; container->elements[1].type = String;
} }
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
/*! /*!
@ -1900,6 +1899,7 @@ QCborValue::QCborValue(const QUuid &uuid)
// change our type // change our type
t = Uuid; t = Uuid;
} }
#endif
// destructor // destructor
void QCborValue::dispose() void QCborValue::dispose()
@ -2031,7 +2031,6 @@ QUrl QCborValue::toUrl(const QUrl &defaultValue) const
return QUrl::fromEncoded(byteData->asByteArrayView()); return QUrl::fromEncoded(byteData->asByteArrayView());
} }
#endif
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
/*! /*!
@ -2074,6 +2073,7 @@ QUuid QCborValue::toUuid(const QUuid &defaultValue) const
return QUuid::fromRfc4122(byteData->asByteArrayView()); return QUuid::fromRfc4122(byteData->asByteArrayView());
} }
#endif
/*! /*!
\fn QCborArray QCborValue::toArray() const \fn QCborArray QCborValue::toArray() const
@ -2896,13 +2896,13 @@ size_t qHash(const QCborValue &value, size_t seed)
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
case QCborValue::Url: case QCborValue::Url:
return qHash(value.toUrl(), seed); return qHash(value.toUrl(), seed);
#endif # if QT_CONFIG(regularexpression)
#if QT_CONFIG(regularexpression)
case QCborValue::RegularExpression: case QCborValue::RegularExpression:
return qHash(value.toRegularExpression(), seed); return qHash(value.toRegularExpression(), seed);
#endif # endif
case QCborValue::Uuid: case QCborValue::Uuid:
return qHash(value.toUuid(), seed); return qHash(value.toUuid(), seed);
#endif
case QCborValue::Invalid: case QCborValue::Invalid:
return seed; return seed;
default: default:

View File

@ -166,11 +166,11 @@ public:
explicit QCborValue(const QDateTime &dt); explicit QCborValue(const QDateTime &dt);
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
explicit QCborValue(const QUrl &url); explicit QCborValue(const QUrl &url);
#endif # if QT_CONFIG(regularexpression)
#if QT_CONFIG(regularexpression)
explicit QCborValue(const QRegularExpression &rx); explicit QCborValue(const QRegularExpression &rx);
#endif # endif
explicit QCborValue(const QUuid &uuid); explicit QCborValue(const QUuid &uuid);
#endif
~QCborValue() { if (container) dispose(); } ~QCborValue() { if (container) dispose(); }
@ -238,11 +238,13 @@ public:
QByteArray toByteArray(const QByteArray &defaultValue = {}) const; QByteArray toByteArray(const QByteArray &defaultValue = {}) const;
QString toString(const QString &defaultValue = {}) const; QString toString(const QString &defaultValue = {}) const;
QDateTime toDateTime(const QDateTime &defaultValue = {}) const; QDateTime toDateTime(const QDateTime &defaultValue = {}) const;
#ifndef QT_BOOTSTRAPPED
QUrl toUrl(const QUrl &defaultValue = {}) const; QUrl toUrl(const QUrl &defaultValue = {}) const;
#if QT_CONFIG(regularexpression) # if QT_CONFIG(regularexpression)
QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const; QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const;
#endif # endif
QUuid toUuid(const QUuid &defaultValue = {}) const; QUuid toUuid(const QUuid &defaultValue = {}) const;
#endif
// only forward-declared, need split functions // only forward-declared, need split functions
QCborArray toArray() const; QCborArray toArray() const;
@ -385,13 +387,13 @@ public:
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
QUrl toUrl(const QUrl &defaultValue = {}) const QUrl toUrl(const QUrl &defaultValue = {}) const
{ return concrete().toUrl(defaultValue); } { return concrete().toUrl(defaultValue); }
#endif # if QT_CONFIG(regularexpression)
#if QT_CONFIG(regularexpression)
QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const
{ return concrete().toRegularExpression(defaultValue); } { return concrete().toRegularExpression(defaultValue); }
#endif # endif
QUuid toUuid(const QUuid &defaultValue = {}) const QUuid toUuid(const QUuid &defaultValue = {}) const
{ return concrete().toUuid(defaultValue); } { return concrete().toUuid(defaultValue); }
#endif
// only forward-declared, need split functions. Implemented in qcbor{array,map}.h // only forward-declared, need split functions. Implemented in qcbor{array,map}.h
inline QCborArray toArray() const; inline QCborArray toArray() const;
@ -538,13 +540,13 @@ public:
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
QUrl toUrl(const QUrl &defaultValue = {}) const QUrl toUrl(const QUrl &defaultValue = {}) const
{ return concrete().toUrl(defaultValue); } { return concrete().toUrl(defaultValue); }
#endif # if QT_CONFIG(regularexpression)
#if QT_CONFIG(regularexpression)
QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const QRegularExpression toRegularExpression(const QRegularExpression &defaultValue = {}) const
{ return concrete().toRegularExpression(defaultValue); } { return concrete().toRegularExpression(defaultValue); }
#endif # endif
QUuid toUuid(const QUuid &defaultValue = {}) const QUuid toUuid(const QUuid &defaultValue = {}) const
{ return concrete().toUuid(defaultValue); } { return concrete().toUuid(defaultValue); }
#endif
// only forward-declared, need split functions. Implemented in qcbor{array,map}.h // only forward-declared, need split functions. Implemented in qcbor{array,map}.h
QCborArray toArray() const; QCborArray toArray() const;

View File

@ -98,7 +98,6 @@ static QString maybeEncodeTag(const QCborContainerPrivate *d)
{ {
qint64 tag = d->elements.at(0).value; qint64 tag = d->elements.at(0).value;
const Element &e = d->elements.at(1); const Element &e = d->elements.at(1);
const ByteData *b = d->byteData(e);
switch (tag) { switch (tag) {
case qint64(QCborKnownTags::DateTimeString): case qint64(QCborKnownTags::DateTimeString):
@ -115,8 +114,12 @@ static QString maybeEncodeTag(const QCborContainerPrivate *d)
break; break;
case qint64(QCborKnownTags::Uuid): case qint64(QCborKnownTags::Uuid):
if (e.type == QCborValue::ByteArray && b->len == sizeof(QUuid)) #ifndef QT_BOOTSTRAPPED
if (const ByteData *b = d->byteData(e); e.type == QCborValue::ByteArray && b
&& b->len == sizeof(QUuid))
return QUuid::fromRfc4122(b->asByteArrayView()).toString(QUuid::WithoutBraces); return QUuid::fromRfc4122(b->asByteArrayView()).toString(QUuid::WithoutBraces);
#endif
break;
} }
// don't know what to do, bail out // don't know what to do, bail out
@ -586,15 +589,15 @@ QVariant QCborValue::toVariant() const
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
case Url: case Url:
return toUrl(); return toUrl();
#endif
#if QT_CONFIG(regularexpression) # if QT_CONFIG(regularexpression)
case RegularExpression: case RegularExpression:
return toRegularExpression(); return toRegularExpression();
#endif # endif
case Uuid: case Uuid:
return toUuid(); return toUuid();
#endif
case Invalid: case Invalid:
return QVariant(); return QVariant();
@ -763,9 +766,9 @@ QCborValue QCborValue::fromVariant(const QVariant &variant)
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
case QMetaType::QUrl: case QMetaType::QUrl:
return QCborValue(variant.toUrl()); return QCborValue(variant.toUrl());
#endif
case QMetaType::QUuid: case QMetaType::QUuid:
return QCborValue(variant.toUuid()); return QCborValue(variant.toUuid());
#endif
case QMetaType::QVariantList: case QMetaType::QVariantList:
return QCborArray::fromVariantList(variant.toList()); return QCborArray::fromVariantList(variant.toList());
case QMetaType::QVariantMap: case QMetaType::QVariantMap: