QMetaObjectBuilder: remove unused serialization code

Change-Id: I73a13265a69079581d2974400b3311d3fdfda2d0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Fabian Kosmale 2021-03-19 13:11:20 +01:00
parent 90fd142b09
commit 411ab34c96
3 changed files with 0 additions and 325 deletions

View File

@ -1526,274 +1526,6 @@ void QMetaObjectBuilder::setStaticMetacallFunction
d->staticMetacallFunction = value;
}
#ifndef QT_NO_DATASTREAM
/*!
Serializes the contents of the meta object builder onto \a stream.
\sa deserialize()
*/
void QMetaObjectBuilder::serialize(QDataStream &stream) const
{
int index;
// Write the class and super class names.
stream << d->className;
if (d->superClass)
stream << QByteArray(d->superClass->className());
else
stream << QByteArray();
// Write the counts for each type of class member.
stream << int(d->classInfoNames.size());
stream << int(d->methods.size());
stream << int(d->properties.size());
stream << int(d->enumerators.size());
stream << int(d->constructors.size());
stream << int(d->relatedMetaObjects.size());
// Write the items of class information.
for (index = 0; index < d->classInfoNames.size(); ++index) {
stream << d->classInfoNames[index];
stream << d->classInfoValues[index];
}
// Write the methods.
for (const auto &method : d->methods) {
stream << method.signature;
stream << method.returnType;
stream << method.parameterNames;
stream << method.tag;
stream << method.attributes;
if (method.revision)
stream << method.revision;
}
// Write the properties.
for (const auto &property : d->properties) {
stream << property.name;
stream << property.type;
stream << property.flags;
stream << property.notifySignal;
stream << property.revision;
}
// Write the enumerators.
for (const auto &enumerator : d->enumerators) {
stream << enumerator.name;
stream << enumerator.isFlag;
stream << enumerator.isScoped;
stream << enumerator.keys;
stream << enumerator.values;
}
// Write the constructors.
for (const auto &ctor : d->constructors) {
stream << ctor.signature;
stream << ctor.returnType;
stream << ctor.parameterNames;
stream << ctor.tag;
stream << ctor.attributes;
}
// Write the related meta objects.
for (index = 0; index < d->relatedMetaObjects.size(); ++index) {
const QMetaObject *meta = d->relatedMetaObjects[index];
stream << QByteArray(meta->className());
}
// Add an extra empty QByteArray for additional data in future versions.
// This should help maintain backwards compatibility, allowing older
// versions to read newer data.
stream << QByteArray();
}
// Resolve a class name using the name reference map.
static const QMetaObject *resolveClassName(const QMap<QByteArray, const QMetaObject *> &references,
const QByteArray &name)
{
if (name == QByteArray("QObject"))
return &QObject::staticMetaObject;
else
return references.value(name, nullptr);
}
/*!
Deserializes a meta object builder from \a stream into
this meta object builder.
The \a references parameter specifies a mapping from class names
to QMetaObject instances for resolving the super class name and
related meta objects in the object that is deserialized.
The meta object for QObject is implicitly added to \a references
and does not need to be supplied.
The QDataStream::status() value on \a stream will be set to
QDataStream::ReadCorruptData if the input data is corrupt.
The status will be set to QDataStream::ReadPastEnd if the
input was exhausted before the full meta object was read.
\sa serialize()
*/
void QMetaObjectBuilder::deserialize
(QDataStream& stream,
const QMap<QByteArray, const QMetaObject *>& references)
{
QByteArray name;
const QMetaObject *cl;
int index;
// Clear all members in the builder to their default states.
d->className.clear();
d->superClass = &QObject::staticMetaObject;
d->classInfoNames.clear();
d->classInfoValues.clear();
d->methods.clear();
d->properties.clear();
d->enumerators.clear();
d->constructors.clear();
d->relatedMetaObjects.clear();
d->staticMetacallFunction = nullptr;
// Read the class and super class names.
stream >> d->className;
stream >> name;
if (name.isEmpty()) {
d->superClass = nullptr;
} else if ((cl = resolveClassName(references, name)) != nullptr) {
d->superClass = cl;
} else {
stream.setStatus(QDataStream::ReadCorruptData);
return;
}
// Read the counts for each type of class member.
int classInfoCount, methodCount, propertyCount;
int enumeratorCount, constructorCount, relatedMetaObjectCount;
stream >> classInfoCount;
stream >> methodCount;
stream >> propertyCount;
stream >> enumeratorCount;
stream >> constructorCount;
stream >> relatedMetaObjectCount;
if (classInfoCount < 0 || methodCount < 0 ||
propertyCount < 0 || enumeratorCount < 0 ||
constructorCount < 0 || relatedMetaObjectCount < 0) {
stream.setStatus(QDataStream::ReadCorruptData);
return;
}
// Read the items of class information.
for (index = 0; index < classInfoCount; ++index) {
if (stream.status() != QDataStream::Ok)
return;
QByteArray value;
stream >> name;
stream >> value;
addClassInfo(name, value);
}
// Read the member methods.
for (index = 0; index < methodCount; ++index) {
if (stream.status() != QDataStream::Ok)
return;
stream >> name;
addMethod(name);
QMetaMethodBuilderPrivate &method = d->methods[index];
stream >> method.returnType;
stream >> method.parameterNames;
stream >> method.tag;
stream >> method.attributes;
if (method.attributes & MethodRevisioned)
stream >> method.revision;
if (method.methodType() == QMetaMethod::Constructor) {
// Cannot add a constructor in this set of methods.
stream.setStatus(QDataStream::ReadCorruptData);
return;
}
}
// Read the properties.
for (index = 0; index < propertyCount; ++index) {
if (stream.status() != QDataStream::Ok)
return;
QByteArray type;
stream >> name;
stream >> type;
addProperty(name, type);
QMetaPropertyBuilderPrivate &property = d->properties[index];
stream >> property.flags;
stream >> property.notifySignal;
if (property.notifySignal < -1 ||
property.notifySignal >= int(d->methods.size())) {
// Notify signal method index is out of range.
stream.setStatus(QDataStream::ReadCorruptData);
return;
}
if (property.notifySignal >= 0 &&
d->methods[property.notifySignal].methodType() != QMetaMethod::Signal) {
// Notify signal method index does not refer to a signal.
stream.setStatus(QDataStream::ReadCorruptData);
return;
}
stream >> property.revision;
}
// Read the enumerators.
for (index = 0; index < enumeratorCount; ++index) {
if (stream.status() != QDataStream::Ok)
return;
stream >> name;
addEnumerator(name);
QMetaEnumBuilderPrivate &enumerator = d->enumerators[index];
stream >> enumerator.isFlag;
stream >> enumerator.isScoped;
stream >> enumerator.keys;
stream >> enumerator.values;
if (enumerator.keys.size() != enumerator.values.size()) {
// Mismatch between number of keys and number of values.
stream.setStatus(QDataStream::ReadCorruptData);
return;
}
}
// Read the constructor methods.
for (index = 0; index < constructorCount; ++index) {
if (stream.status() != QDataStream::Ok)
return;
stream >> name;
addConstructor(name);
QMetaMethodBuilderPrivate &method = d->constructors[index];
stream >> method.returnType;
stream >> method.parameterNames;
stream >> method.tag;
stream >> method.attributes;
if (method.methodType() != QMetaMethod::Constructor) {
// The type must be Constructor.
stream.setStatus(QDataStream::ReadCorruptData);
return;
}
}
// Read the related meta objects.
for (index = 0; index < relatedMetaObjectCount; ++index) {
if (stream.status() != QDataStream::Ok)
return;
stream >> name;
cl = resolveClassName(references, name);
if (!cl) {
stream.setStatus(QDataStream::ReadCorruptData);
return;
}
addRelatedMetaObject(cl);
}
// Read the extra data block, which is reserved for future use.
stream >> name;
}
#endif // !QT_NO_DATASTREAM
/*!
\class QMetaMethodBuilder
\inmodule QtCore

View File

@ -168,13 +168,6 @@ public:
QMetaObject *toMetaObject() const;
#ifndef QT_NO_DATASTREAM
void serialize(QDataStream& stream) const;
void deserialize
(QDataStream& stream,
const QMap<QByteArray, const QMetaObject *>& references);
#endif
private:
Q_DISABLE_COPY_MOVE(QMetaObjectBuilder)

View File

@ -51,7 +51,6 @@ private slots:
void relatedMetaObject();
void staticMetacall();
void copyMetaObject();
void serialize();
void removeNotifySignal();
void usage_signal();
@ -1026,55 +1025,6 @@ void tst_QMetaObjectBuilder::copyMetaObject()
QVERIFY2(compared, qPrintable(compared.details));
}
// Serialize and deserialize a meta object and check that
// it round-trips to the exact same value.
void tst_QMetaObjectBuilder::serialize()
{
// Full QMetaObjectBuilder
{
QMetaObjectBuilder builder(&SomethingOfEverything::staticMetaObject);
QMetaObject *meta = builder.toMetaObject();
dynamicMetaObjectsPendingFree.push_back(meta);
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly | QIODevice::Append);
builder.serialize(stream);
QMetaObjectBuilder builder2;
QDataStream stream2(data);
QMap<QByteArray, const QMetaObject *> references;
references.insert(QByteArray("QLocale"), &QLocale::staticMetaObject);
builder2.deserialize(stream2, references);
builder2.setStaticMetacallFunction(builder.staticMetacallFunction());
QMetaObject *meta2 = builder2.toMetaObject();
dynamicMetaObjectsPendingFree.push_back(meta2);
auto compared = sameMetaObject(meta, meta2);
QVERIFY2(compared, qPrintable(compared.details));
}
// Partial QMetaObjectBuilder
{
QMetaObjectBuilder builder;
builder.setClassName("Test");
builder.addProperty("foo", "int");
QByteArray data;
QDataStream stream(&data, QIODevice::WriteOnly | QIODevice::Append);
builder.serialize(stream);
QMetaObjectBuilder builder2;
QDataStream stream2(data);
builder2.deserialize(stream2, QMap<QByteArray, const QMetaObject *>());
QCOMPARE(builder.superClass(), builder2.superClass());
QCOMPARE(builder.className(), builder2.className());
QCOMPARE(builder.propertyCount(), builder2.propertyCount());
QCOMPARE(builder.property(0).name(), builder2.property(0).name());
QCOMPARE(builder.property(0).type(), builder2.property(0).type());
}
}
// Check that removing a method updates notify signals appropriately
void tst_QMetaObjectBuilder::removeNotifySignal()
{