Don't hardcode the number 14 in meta-object generators
14 is the number of fields (ints) in the QMetaObjectPrivate struct as of revision 6. Use the calculated number of fields instead, so that the code will still be correct when more fields are added in future revisions. Change-Id: I4f2c2bfc125f3fabc8e8caedf5c6ba6c17a34d06 Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@nokia.com>bb10
parent
10de7f77f4
commit
6a6425dff5
|
|
@ -152,6 +152,10 @@ struct QMetaObjectPrivate
|
|||
#endif
|
||||
};
|
||||
|
||||
// For meta-object generators
|
||||
|
||||
enum { MetaObjectPrivateFieldCount = sizeof(QMetaObjectPrivate) / sizeof(int) };
|
||||
|
||||
#ifndef UTILS_H
|
||||
// mirrored in moc's utils.h
|
||||
static inline bool is_ident_char(char s)
|
||||
|
|
|
|||
|
|
@ -1160,7 +1160,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
|
|||
QMetaObjectPrivate *pmeta
|
||||
= reinterpret_cast<QMetaObjectPrivate *>(buf + size);
|
||||
int pmetaSize = size;
|
||||
dataIndex = 14; // Number of fields in the QMetaObjectPrivate.
|
||||
dataIndex = MetaObjectPrivateFieldCount;
|
||||
for (index = 0; index < d->properties.size(); ++index) {
|
||||
if (d->properties[index].notifySignal != -1) {
|
||||
hasNotifySignals = true;
|
||||
|
|
@ -1238,7 +1238,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
|
|||
}
|
||||
|
||||
// Reset the current data position to just past the QMetaObjectPrivate.
|
||||
dataIndex = 14;
|
||||
dataIndex = MetaObjectPrivateFieldCount;
|
||||
|
||||
// Add the class name to the string table.
|
||||
int offset = 0;
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ void Generator::generateCode()
|
|||
QByteArray qualifiedClassNameIdentifier = cdef->qualified;
|
||||
qualifiedClassNameIdentifier.replace(':', '_');
|
||||
|
||||
int index = 14;
|
||||
int index = MetaObjectPrivateFieldCount;
|
||||
fprintf(out, "static const uint qt_meta_data_%s[] = {\n", qualifiedClassNameIdentifier.constData());
|
||||
fprintf(out, "\n // content:\n");
|
||||
fprintf(out, " %4d, // revision\n", int(QMetaObjectPrivate::OutputRevision));
|
||||
|
|
|
|||
Loading…
Reference in New Issue