diff options
author | Campbell Barton <ideasman42@gmail.com> | 2010-12-31 07:12:20 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2010-12-31 07:12:20 +0300 |
commit | 55934366521da478ad8f4674152c00742c2f5f1e (patch) | |
tree | 52413cd412034e70536d885dac6f69d8c0cbea68 /source/blender/makesrna/intern/rna_define.c | |
parent | a8406439938d3eb405c144a50d87100f48f77c7e (diff) |
Continue from my commit r33952, which disallowed floats to be wrapped as ints.
this missed some cases, now also disallow ints to be wrapped as floats.
This commit also exposed a number of cases where ints/floats were incorrectly wrapped.
Bugs like [#25416] wont slip through the cracks anymore.
Diffstat (limited to 'source/blender/makesrna/intern/rna_define.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_define.c | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 214a79dbd34..963c4b98758 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -1492,8 +1492,19 @@ void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, co return; } - if((dp=rna_def_property_sdna(prop, structname, propname))) + if((dp=rna_def_property_sdna(prop, structname, propname))) { + + if(DefRNA.silent == 0) { + /* error check to ensure floats are not wrapped as ints/bools */ + if(dp->dnatype && *dp->dnatype && IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) { + fprintf(stderr, "RNA_def_property_boolean_sdna: %s.%s is a '%s' but wrapped as type '%s'.\n", srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type)); + DefRNA.error= 1; + return; + } + } + dp->booleanbit= bit; + } } void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int booleanbit) @@ -1526,6 +1537,16 @@ void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const } if((dp= rna_def_property_sdna(prop, structname, propname))) { + + /* error check to ensure floats are not wrapped as ints/bools */ + if(DefRNA.silent == 0) { + if(dp->dnatype && *dp->dnatype && IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) { + fprintf(stderr, "RNA_def_property_int_sdna: %s.%s is a '%s' but wrapped as type '%s'.\n", srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type)); + DefRNA.error= 1; + return; + } + } + /* SDNA doesn't pass us unsigned unfortunately .. */ if(dp->dnatype && strcmp(dp->dnatype, "char") == 0) { iprop->hardmin= iprop->softmin= CHAR_MIN; @@ -1550,6 +1571,7 @@ void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname) { + PropertyDefRNA *dp; StructRNA *srna= DefRNA.laststruct; if(!DefRNA.preprocess) { @@ -1563,6 +1585,19 @@ void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, cons return; } + if((dp= rna_def_property_sdna(prop, structname, propname))) { + /* silent is for internal use */ + if(DefRNA.silent == 0) { + if(dp->dnatype && *dp->dnatype && IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) { + if(prop->subtype != PROP_COLOR_GAMMA) { /* colors are an exception. these get translated */ + fprintf(stderr, "RNA_def_property_float_sdna: %s.%s is a '%s' but wrapped as type '%s'.\n", srna->identifier, prop->identifier, dp->dnatype, RNA_property_typename(prop->type)); + DefRNA.error= 1; + return; + } + } + } + } + rna_def_property_sdna(prop, structname, propname); } @@ -2799,3 +2834,17 @@ int RNA_def_property_free_identifier(StructOrFunctionRNA *cont_, const char *ide } #endif +const char *RNA_property_typename(PropertyType type) +{ + switch(type) { + case PROP_BOOLEAN: return "PROP_BOOLEAN"; + case PROP_INT: return "PROP_INT"; + case PROP_FLOAT: return "PROP_FLOAT"; + case PROP_STRING: return "PROP_STRING"; + case PROP_ENUM: return "PROP_ENUM"; + case PROP_POINTER: return "PROP_POINTER"; + case PROP_COLLECTION: return "PROP_COLLECTION"; + } + + return "PROP_UNKNOWN"; +} |