[Bf-blender-cvs] [ae375b4cdc7] master: DNA: ensure new names exist when renaming

Campbell Barton noreply at git.blender.org
Sat Feb 16 03:15:12 CET 2019


Commit: ae375b4cdc737646b770a722c8a47c22f6992dc4
Author: Campbell Barton
Date:   Sat Feb 16 12:54:33 2019 +1100
Branches: master
https://developer.blender.org/rBae375b4cdc737646b770a722c8a47c22f6992dc4

DNA: ensure new names exist when renaming

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.

===================================================================

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

===================================================================

diff --git a/source/blender/makesdna/intern/dna_rename_defs.h b/source/blender/makesdna/intern/dna_rename_defs.h
index 62752d6693a..4107797c8a1 100644
--- a/source/blender/makesdna/intern/dna_rename_defs.h
+++ b/source/blender/makesdna/intern/dna_rename_defs.h
@@ -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.
  */
 
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index 952318482bb..2a6a4545634 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -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
+}
+
+/** \} */



More information about the Bf-blender-cvs mailing list