DNA: ensure new names exist when renaming
authorCampbell Barton <ideasman42@gmail.com>
Sat, 16 Feb 2019 01:54:33 +0000 (12:54 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 16 Feb 2019 02:10:32 +0000 (13:10 +1100)
Fail to build on errors in new names - without this renamed values
would be written to DNA breaking backwards & forwards compatibility.

Note that errors in old names aren't detected.

source/blender/makesdna/intern/dna_rename_defs.h
source/blender/makesdna/intern/makesdna.c

index 62752d6693add9c3c9a01d7137ffbcd1ac2413a3..4107797c8a1ad55f1979c85c299ef0965eb08e5f 100644 (file)
@@ -33,6 +33,9 @@
  *   All references to the previous destination name can be removed since they're
  *   never written to disk.
  *
+ * - Old names aren't sanity checked (since this file is the only place that knows about them)
+ *   typos in the old names will break both backwards & forwards compatibility **TAKE CARE**.
+ *
  * \see versioning_dna.c for a actual version patching.
  */
 
index 952318482bbb6212f49e259b4e09414c8222582f..2a6a4545634d50d416bb149f4225fef876101de7 100644 (file)
@@ -1464,3 +1464,23 @@ int main(int argc, char **argv)
 /* end of list */
 
 /** \} */
+
+
+/* -------------------------------------------------------------------- */
+/** \name DNA Renaming Sanity Check
+ *
+ * Without this it's possible to reference struct members that don't exist,
+ * breaking backward & forward compatibility.
+ *
+ * \{ */
+
+static void UNUSED_FUNCTION(dna_rename_defs_ensure)(void)
+{
+#define DNA_STRUCT_RENAME(old, new) (void)sizeof(new);
+#define DNA_STRUCT_RENAME_ELEM(struct_name, old, new) (void)offsetof(struct_name, new);
+#include "dna_rename_defs.h"
+#undef DNA_STRUCT_RENAME
+#undef DNA_STRUCT_RENAME_ELEM
+}
+
+/** \} */