From ae375b4cdc737646b770a722c8a47c22f6992dc4 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 16 Feb 2019 12:54:33 +1100 Subject: 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. --- source/blender/makesdna/intern/dna_rename_defs.h | 3 +++ source/blender/makesdna/intern/makesdna.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'source') 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 +} + +/** \} */ -- cgit v1.2.3