diff options
author | Campbell Barton <ideasman42@gmail.com> | 2014-07-28 14:00:33 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2014-07-28 14:08:25 +0400 |
commit | df01833477cc66b6bb7fe08b5c3678fcc900b664 (patch) | |
tree | 1938573b54c298f8eed2281072f522b20af1d807 /source/blender/makesrna/intern/makesrna.c | |
parent | 115458b53e5e98ee6bc8cd97fcc38cdc51f89df7 (diff) |
RNA: check for valid ranges with int properties (C11 only)
Diffstat (limited to 'source/blender/makesrna/intern/makesrna.c')
-rw-r--r-- | source/blender/makesrna/intern/makesrna.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 7f1f04cdb6a..9023f25e3d5 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -745,6 +745,24 @@ static void rna_clamp_value_range(FILE *f, PropertyRNA *prop) } } +#ifdef USE_RNA_RANGE_CHECK +static void rna_clamp_value_range_check( + FILE *f, PropertyRNA *prop, + const char *dnaname_prefix, const char *dnaname) +{ + if (prop->type == PROP_INT) { + IntPropertyRNA *iprop = (IntPropertyRNA *)prop; + fprintf(f, + " { BLI_STATIC_ASSERT(" + "(TYPEOF_MAX(%s%s) >= %d) && " + "(TYPEOF_MIN(%s%s) <= %d), " + "\"invalid limits\"); }\n", + dnaname_prefix, dnaname, iprop->hardmax, + dnaname_prefix, dnaname, iprop->hardmin); + } +} +#endif /* USE_RNA_RANGE_CHECK */ + static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array) { if (prop->type == PROP_INT) { @@ -944,6 +962,18 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr } fprintf(f, " }\n"); } + +#ifdef USE_RNA_RANGE_CHECK + if (dp->dnaname && manualfunc == NULL) { + if (dp->dnaarraylength == 1) { + rna_clamp_value_range_check(f, prop, "data->", dp->dnaname); + } + else { + rna_clamp_value_range_check(f, prop, "*data->", dp->dnaname); + } + } +#endif + fprintf(f, "}\n\n"); } else { @@ -975,6 +1005,13 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr rna_clamp_value(f, prop, 0); } } + +#ifdef USE_RNA_RANGE_CHECK + if (dp->dnaname && manualfunc == NULL) { + rna_clamp_value_range_check(f, prop, "data->", dp->dnaname); + } +#endif + fprintf(f, "}\n\n"); } break; |