Don't hardcode the number 14 in meta-object generators
authorKent Hansen <kent.hansen@nokia.com>
Mon, 6 Feb 2012 07:32:59 +0000 (08:32 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 16 Feb 2012 00:57:05 +0000 (01:57 +0100)
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>
src/corelib/kernel/qmetaobject_p.h
src/corelib/kernel/qmetaobjectbuilder.cpp
src/tools/moc/generator.cpp

index 5fc0555..d6e49b9 100644 (file)
@@ -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)
index a19f1fd..e22257b 100644 (file)
@@ -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;
index e2055e4..8242fb4 100644 (file)
@@ -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));