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.
This commit is contained in:
Campbell Barton 2010-12-31 04:12:20 +00:00
parent a840643993
commit 5593436652
8 changed files with 91 additions and 35 deletions

@ -197,6 +197,12 @@ void RNA_def_property_duplicate_pointers(StructOrFunctionRNA *cont_, PropertyRNA
void RNA_def_property_free_pointers(PropertyRNA *prop);
int RNA_def_property_free_identifier(StructOrFunctionRNA *cont_, const char *identifier);
/* utilities */
const char *RNA_property_typename(PropertyType type);
#define IS_DNATYPE_FLOAT_COMPAT(_str) (strcmp(_str, "float") == 0 || strcmp(_str, "double") == 0)
#define IS_DNATYPE_INT_COMPAT(_str) (strcmp(_str, "int") == 0 || strcmp(_str, "short") == 0 || strcmp(_str, "char") == 0)
#ifdef __cplusplus
}
#endif

@ -45,8 +45,6 @@
#endif
#endif
static const char *rna_property_typename(PropertyType type);
/* Replace if different */
#define TMP_EXT ".tmp"
@ -463,6 +461,28 @@ static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *pr
DefRNA.error= 1;
return NULL;
}
/* typecheck, */
if(dp->dnatype && *dp->dnatype) {
if(prop->type == PROP_FLOAT) {
if(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_get_func1: %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 NULL;
}
}
}
else if(prop->type == PROP_INT || prop->type == PROP_BOOLEAN || prop->type == PROP_ENUM) {
if(IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
fprintf(stderr, "rna_def_property_get_func2: %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 NULL;
}
}
}
}
func= rna_alloc_function_name(srna->identifier, prop->identifier, "get");
@ -646,13 +666,6 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
}
return NULL;
}
/* error check to ensure floats are not wrapped as ints/bools */
if(dp->dnatype && (strcmp(dp->dnatype, "float") == 0 || strcmp(dp->dnatype, "double") == 0) && prop->type != PROP_FLOAT) {
fprintf(stderr, "rna_def_property_set_func: %s.%s is a float but wrapped as type '%s'.\n", srna->identifier, prop->identifier, rna_property_typename(prop->type));
DefRNA.error= 1;
return NULL;
}
}
func= rna_alloc_function_name(srna->identifier, prop->identifier, "set");
@ -1710,20 +1723,6 @@ static const char *rna_property_structname(PropertyType type)
}
}
static 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";
default: return "PROP_UNKNOWN";
}
}
static const char *rna_property_subtypename(PropertySubType type)
{
switch(type) {
@ -2106,7 +2105,7 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
fprintf(f, "%d,\n", prop->icon);
fprintf(f, "\t%s, %s|%s, %s, %d, {%d, %d, %d}, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), rna_property_subtype_unit(prop->subtype), rna_function_string(prop->getlength), prop->arraydimension, prop->arraylength[0], prop->arraylength[1], prop->arraylength[2], prop->totarraylength);
fprintf(f, "\t%s, %s|%s, %s, %d, {%d, %d, %d}, %d,\n", RNA_property_typename(prop->type), rna_property_subtypename(prop->subtype), rna_property_subtype_unit(prop->subtype), rna_function_string(prop->getlength), prop->arraydimension, prop->arraylength[0], prop->arraylength[1], prop->arraylength[2], prop->totarraylength);
fprintf(f, "\t%s%s, %d, %s, %s,\n", (prop->flag & PROP_CONTEXT_UPDATE)? "(UpdateFunc)": "", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable), rna_function_string(prop->itemeditable));
if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);

@ -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";
}

@ -747,8 +747,8 @@ static void rna_def_fmodifier_cycles(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Before Mode", "Cycling mode to use before first keyframe");
RNA_def_property_update(prop, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
prop= RNA_def_property(srna, "cycles_before", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "before_cycles");
prop= RNA_def_property(srna, "cycles_before", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "before_cycles");
RNA_def_property_ui_text(prop, "Before Cycles", "Maximum number of cycles to allow before first keyframe. (0 = infinite)");
RNA_def_property_update(prop, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
@ -759,8 +759,8 @@ static void rna_def_fmodifier_cycles(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "After Mode", "Cycling mode to use after last keyframe");
RNA_def_property_update(prop, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
prop= RNA_def_property(srna, "cycles_after", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "after_cycles");
prop= RNA_def_property(srna, "cycles_after", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "after_cycles");
RNA_def_property_ui_text(prop, "After Cycles", "Maximum number of cycles to allow after last keyframe. (0 = infinite)");
RNA_def_property_update(prop, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
}

@ -1135,7 +1135,9 @@ static void rna_def_mvert(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
prop= RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION);
RNA_def_property_float_sdna(prop, NULL, "no");
// RNA_def_property_float_sdna(prop, NULL, "no");
RNA_def_property_array(prop, 3);
RNA_def_property_range(prop, -1.0f, 1.0f);
RNA_def_property_float_funcs(prop, "rna_MeshVertex_normal_get", "rna_MeshVertex_normal_set", NULL);
RNA_def_property_ui_text(prop, "Normal", "Vertex Normal");

@ -154,7 +154,7 @@ void RNA_def_gameproperty(BlenderRNA *brna)
RNA_def_struct_sdna(srna, "bProperty");
prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "data");
// RNA_def_property_float_sdna(prop, NULL, "data");
RNA_def_property_ui_text(prop, "Value", "Property value");
RNA_def_property_range(prop, -10000, 10000);
RNA_def_property_float_funcs(prop, "rna_GameFloatProperty_value_get", "rna_GameFloatProperty_value_set", NULL);
@ -166,7 +166,7 @@ void RNA_def_gameproperty(BlenderRNA *brna)
RNA_def_struct_sdna(srna, "bProperty");
prop= RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "data");
// RNA_def_property_float_sdna(prop, NULL, "data");
RNA_def_property_ui_text(prop, "Value", "Property value");
RNA_def_property_range(prop, -10000, 10000);
RNA_def_property_float_funcs(prop, "rna_GameFloatProperty_value_get", "rna_GameFloatProperty_value_set", NULL);

@ -1736,8 +1736,8 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Physics Gravity", "Gravitational constant used for physics simulation in the game engine");
RNA_def_property_update(prop, NC_SCENE, NULL);
prop= RNA_def_property(srna, "occlusion_culling_resolution", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "occlusionRes");
prop= RNA_def_property(srna, "occlusion_culling_resolution", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "occlusionRes");
RNA_def_property_range(prop, 128.0, 1024.0);
RNA_def_property_ui_text(prop, "Occlusion Resolution", "The size of the occlusion buffer in pixel, use higher value for better precision (slower)");
RNA_def_property_update(prop, NC_SCENE, NULL);

@ -164,7 +164,7 @@ static void rna_def_text_marker(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Edit All", "Edit all markers of the same group as one");
prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
prop= RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Color", "Color to display the marker with");
}