diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 142 |
1 files changed, 92 insertions, 50 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 806b9d0d5ad..2a0fd14e13b 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -241,13 +241,13 @@ static IDProperty *rna_idproperty_ui(PropertyRNA *prop) IDProperty *idprop; for (idprop = ((IDProperty *)prop)->prev; idprop; idprop = idprop->prev) { - if (strcmp(RNA_IDP_UI, idprop->name) == 0) + if (STREQ(RNA_IDP_UI, idprop->name)) break; } if (idprop == NULL) { for (idprop = ((IDProperty *)prop)->next; idprop; idprop = idprop->next) { - if (strcmp(RNA_IDP_UI, idprop->name) == 0) + if (STREQ(RNA_IDP_UI, idprop->name)) break; } } @@ -466,7 +466,7 @@ static const char *rna_ensure_property_identifier(const PropertyRNA *prop) if (prop->magic == RNA_MAGIC) return prop->identifier; else - return ((IDProperty *)prop)->name; + return ((const IDProperty *)prop)->name; } static const char *rna_ensure_property_description(PropertyRNA *prop) @@ -499,7 +499,7 @@ static const char *rna_ensure_property_name(const PropertyRNA *prop) if (prop->magic == RNA_MAGIC) name = prop->name; else - name = ((IDProperty *)prop)->name; + name = ((const IDProperty *)prop)->name; return name; } @@ -511,7 +511,7 @@ StructRNA *RNA_struct_find(const char *identifier) StructRNA *type; if (identifier) { for (type = BLENDER_RNA.structs.first; type; type = type->cont.next) - if (strcmp(type->identifier, identifier) == 0) + if (STREQ(type->identifier, identifier)) return type; } return NULL; @@ -719,7 +719,7 @@ FunctionRNA *RNA_struct_find_function(StructRNA *srna, const char *identifier) RNA_PROP_BEGIN (&tptr, funcptr, iterprop) { - if (strcmp(identifier, RNA_function_identifier(funcptr.data)) == 0) { + if (STREQ(identifier, RNA_function_identifier(funcptr.data))) { func = funcptr.data; break; } @@ -1630,9 +1630,10 @@ bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop) if (RNA_property_array_check(prop)) len = RNA_property_array_length(ptr, prop); - for (index = 0; index < len; index++) - if (rna_get_fcurve(ptr, prop, index, NULL, &driven)) + for (index = 0; index < len; index++) { + if (rna_get_fcurve(ptr, prop, index, NULL, NULL, &driven)) return true; + } return false; } @@ -1825,18 +1826,23 @@ int RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop) { BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop; IDProperty *idprop; + int value; BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN); BLI_assert(RNA_property_array_check(prop) == false); if ((idprop = rna_idproperty_check(&prop, ptr))) - return IDP_Int(idprop); + value = IDP_Int(idprop); else if (bprop->get) - return bprop->get(ptr); + value = bprop->get(ptr); else if (bprop->get_ex) - return bprop->get_ex(ptr, prop); + value = bprop->get_ex(ptr, prop); else - return bprop->defaultvalue; + value = bprop->defaultvalue; + + BLI_assert(ELEM(value, false, true)); + + return value; } void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value) @@ -1846,6 +1852,7 @@ void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, int value) BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN); BLI_assert(RNA_property_array_check(prop) == false); + BLI_assert(ELEM(value, false, true)); /* just in case other values are passed */ if (value) value = 1; @@ -1902,25 +1909,29 @@ int RNA_property_boolean_get_index(PointerRNA *ptr, PropertyRNA *prop, int index { int tmp[RNA_MAX_ARRAY_LENGTH]; int len = rna_ensure_property_array_length(ptr, prop); + int value; BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN); BLI_assert(RNA_property_array_check(prop) != false); BLI_assert(index >= 0); + BLI_assert(index < len); if (len <= RNA_MAX_ARRAY_LENGTH) { RNA_property_boolean_get_array(ptr, prop, tmp); - return tmp[index]; + value = tmp[index]; } else { - int *tmparray, value; + int *tmparray; - tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_boolean_get_index"); + tmparray = MEM_mallocN(sizeof(int) * len, __func__); RNA_property_boolean_get_array(ptr, prop, tmparray); value = tmparray[index]; MEM_freeN(tmparray); - - return value; } + + BLI_assert(ELEM(value, false, true)); + + return value; } void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values) @@ -1969,6 +1980,8 @@ void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int inde BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN); BLI_assert(RNA_property_array_check(prop) != false); BLI_assert(index >= 0); + BLI_assert(index < len); + BLI_assert(ELEM(value, false, true)); if (len <= RNA_MAX_ARRAY_LENGTH) { RNA_property_boolean_get_array(ptr, prop, tmp); @@ -1978,7 +1991,7 @@ void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int inde else { int *tmparray; - tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_boolean_get_index"); + tmparray = MEM_mallocN(sizeof(int) * len, __func__); RNA_property_boolean_get_array(ptr, prop, tmparray); tmparray[index] = value; RNA_property_boolean_set_array(ptr, prop, tmparray); @@ -1992,6 +2005,7 @@ int RNA_property_boolean_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop) BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN); BLI_assert(RNA_property_array_check(prop) == false); + BLI_assert(ELEM(bprop->defaultvalue, false, true)); return bprop->defaultvalue; } @@ -2019,6 +2033,7 @@ int RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop, i BLI_assert(RNA_property_type(prop) == PROP_BOOLEAN); BLI_assert(RNA_property_array_check(prop) != false); BLI_assert(index >= 0); + BLI_assert(index < prop->totarraylength); if (len <= RNA_MAX_ARRAY_LENGTH) { RNA_property_boolean_get_default_array(ptr, prop, tmp); @@ -2027,7 +2042,7 @@ int RNA_property_boolean_get_default_index(PointerRNA *ptr, PropertyRNA *prop, i else { int *tmparray, value; - tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_boolean_get_default_index"); + tmparray = MEM_mallocN(sizeof(int) * len, __func__); RNA_property_boolean_get_default_array(ptr, prop, tmparray); value = tmparray[index]; MEM_freeN(tmparray); @@ -2131,7 +2146,7 @@ void RNA_property_int_get_array_range(PointerRNA *ptr, PropertyRNA *prop, int va int i; if (array_len > 32) { - arr = MEM_mallocN(sizeof(int) * array_len, "RNA_property_int_get_array_range"); + arr = MEM_mallocN(sizeof(int) * array_len, __func__); } else { arr = arr_stack; @@ -2158,6 +2173,7 @@ int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index) BLI_assert(RNA_property_type(prop) == PROP_INT); BLI_assert(RNA_property_array_check(prop) != false); BLI_assert(index >= 0); + BLI_assert(index < len); if (len <= RNA_MAX_ARRAY_LENGTH) { RNA_property_int_get_array(ptr, prop, tmp); @@ -2166,7 +2182,7 @@ int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index) else { int *tmparray, value; - tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_int_get_index"); + tmparray = MEM_mallocN(sizeof(int) * len, __func__); RNA_property_int_get_array(ptr, prop, tmparray); value = tmparray[index]; MEM_freeN(tmparray); @@ -2224,6 +2240,7 @@ void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, i BLI_assert(RNA_property_type(prop) == PROP_INT); BLI_assert(RNA_property_array_check(prop) != false); BLI_assert(index >= 0); + BLI_assert(index < len); if (len <= RNA_MAX_ARRAY_LENGTH) { RNA_property_int_get_array(ptr, prop, tmp); @@ -2233,7 +2250,7 @@ void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, i else { int *tmparray; - tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_int_get_index"); + tmparray = MEM_mallocN(sizeof(int) * len, __func__); RNA_property_int_get_array(ptr, prop, tmparray); tmparray[index] = value; RNA_property_int_set_array(ptr, prop, tmparray); @@ -2270,6 +2287,7 @@ int RNA_property_int_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int i BLI_assert(RNA_property_type(prop) == PROP_INT); BLI_assert(RNA_property_array_check(prop) != false); BLI_assert(index >= 0); + BLI_assert(index < prop->totarraylength); if (len <= RNA_MAX_ARRAY_LENGTH) { RNA_property_int_get_default_array(ptr, prop, tmp); @@ -2278,7 +2296,7 @@ int RNA_property_int_get_default_index(PointerRNA *ptr, PropertyRNA *prop, int i else { int *tmparray, value; - tmparray = MEM_callocN(sizeof(int) * len, "RNA_property_int_get_default_index"); + tmparray = MEM_mallocN(sizeof(int) * len, __func__); RNA_property_int_get_default_array(ptr, prop, tmparray); value = tmparray[index]; MEM_freeN(tmparray); @@ -2398,7 +2416,7 @@ void RNA_property_float_get_array_range(PointerRNA *ptr, PropertyRNA *prop, floa int i; if (array_len > 32) { - arr = MEM_mallocN(sizeof(float) * array_len, "RNA_property_float_get_array_range"); + arr = MEM_mallocN(sizeof(float) * array_len, __func__); } else { arr = arr_stack; @@ -2425,6 +2443,7 @@ float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index BLI_assert(RNA_property_type(prop) == PROP_FLOAT); BLI_assert(RNA_property_array_check(prop) != false); BLI_assert(index >= 0); + BLI_assert(index < len); if (len <= RNA_MAX_ARRAY_LENGTH) { RNA_property_float_get_array(ptr, prop, tmp); @@ -2433,7 +2452,7 @@ float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index else { float *tmparray, value; - tmparray = MEM_callocN(sizeof(float) * len, "RNA_property_float_get_index"); + tmparray = MEM_mallocN(sizeof(float) * len, __func__); RNA_property_float_get_array(ptr, prop, tmparray); value = tmparray[index]; MEM_freeN(tmparray); @@ -2503,6 +2522,7 @@ void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, BLI_assert(RNA_property_type(prop) == PROP_FLOAT); BLI_assert(RNA_property_array_check(prop) != false); BLI_assert(index >= 0); + BLI_assert(index < len); if (len <= RNA_MAX_ARRAY_LENGTH) { RNA_property_float_get_array(ptr, prop, tmp); @@ -2512,7 +2532,7 @@ void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, else { float *tmparray; - tmparray = MEM_callocN(sizeof(float) * len, "RNA_property_float_get_index"); + tmparray = MEM_mallocN(sizeof(float) * len, __func__); RNA_property_float_get_array(ptr, prop, tmparray); tmparray[index] = value; RNA_property_float_set_array(ptr, prop, tmparray); @@ -2553,6 +2573,7 @@ float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, i BLI_assert(RNA_property_type(prop) == PROP_FLOAT); BLI_assert(RNA_property_array_check(prop) != false); BLI_assert(index >= 0); + BLI_assert(index < prop->totarraylength); if (len <= RNA_MAX_ARRAY_LENGTH) { RNA_property_float_get_default_array(ptr, prop, tmp); @@ -2561,7 +2582,7 @@ float RNA_property_float_get_default_index(PointerRNA *ptr, PropertyRNA *prop, i else { float *tmparray, value; - tmparray = MEM_callocN(sizeof(float) * len, "RNA_property_float_get_default_index"); + tmparray = MEM_mallocN(sizeof(float) * len, __func__); RNA_property_float_get_default_array(ptr, prop, tmparray); value = tmparray[index]; MEM_freeN(tmparray); @@ -3228,7 +3249,7 @@ int RNA_property_collection_lookup_string(PointerRNA *ptr, PropertyRNA *prop, co nameptr = RNA_property_string_get_alloc(&iter.ptr, nameprop, name, sizeof(name), &namelen); - if ((keylen == namelen) && (strcmp(nameptr, key) == 0)) { + if ((keylen == namelen) && STREQ(nameptr, key)) { *r_ptr = iter.ptr; found = 1; } @@ -3546,7 +3567,7 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro tmparray = NULL; } if (!tmparray) { - tmparray = MEM_callocN(sizeof(float) * itemlen, "RNA tmparray\n"); + tmparray = MEM_callocN(sizeof(float) * itemlen, "RNA tmparray"); tmplen = itemlen; } @@ -3889,7 +3910,7 @@ static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen, int if (len + 1 < fixedlen) buf = fixedbuf; else - buf = MEM_callocN(sizeof(char) * (len + 1), "rna_path_token"); + buf = MEM_mallocN(sizeof(char) * (len + 1), "rna_path_token"); /* copy string, taking into account escaped ] */ if (bracket) { @@ -4283,7 +4304,7 @@ char *RNA_path_append(const char *path, PointerRNA *UNUSED(ptr), PropertyRNA *pr /* add .identifier */ if (path) { - BLI_dynstr_append(dynstr, (char *)path); + BLI_dynstr_append(dynstr, path); if (*path) BLI_dynstr_append(dynstr, "."); } @@ -4739,8 +4760,9 @@ char *RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index) /* this may not be an ID at all, check for simple when pointer owns property. * TODO, more complex nested case */ if (!RNA_struct_is_ID(ptr->type)) { - if (RNA_struct_find_property(ptr, RNA_property_identifier(prop)) == prop) { - data_path = BLI_strdup(RNA_property_identifier(prop)); + const char *prop_identifier = RNA_property_identifier(prop); + if (RNA_struct_find_property(ptr, prop_identifier) == prop) { + data_path = BLI_strdup(prop_identifier); } } } @@ -4959,7 +4981,7 @@ bool RNA_enum_is_equal(bContext *C, PointerRNA *ptr, const char *name, const cha if (prop) { int i; - bool cmp; + bool cmp = false; RNA_property_enum_items(C, ptr, prop, &item, NULL, &free); i = RNA_enum_from_identifier(item, enumname); @@ -5263,7 +5285,7 @@ char *RNA_pointer_as_string_id(bContext *C, PointerRNA *ptr) { propname = RNA_property_identifier(prop); - if (strcmp(propname, "rna_type") == 0) + if (STREQ(propname, "rna_type")) continue; if (first_time == 0) @@ -5334,7 +5356,7 @@ char *RNA_pointer_as_string_keywords_ex(bContext *C, PointerRNA *ptr, arg_name = RNA_property_identifier(prop); - if (strcmp(arg_name, "rna_type") == 0) { + if (STREQ(arg_name, "rna_type")) { continue; } @@ -5440,14 +5462,20 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in BLI_dynstr_append(dynstr, bool_as_py_string(RNA_property_boolean_get_index(ptr, prop, index))); } else { + int fixedbuf[RNA_MAX_ARRAY_LENGTH]; + int *buf = ARRAY_SIZE(fixedbuf) >= len ? fixedbuf : MEM_mallocN(sizeof(*buf) * len, __func__); + + RNA_property_boolean_get_array(ptr, prop, buf); BLI_dynstr_append(dynstr, "("); for (i = 0; i < len; i++) { - BLI_dynstr_appendf(dynstr, i ? ", %s" : "%s", - bool_as_py_string(RNA_property_boolean_get_index(ptr, prop, i))); + BLI_dynstr_appendf(dynstr, i ? ", %s" : "%s", bool_as_py_string(buf[i])); } if (len == 1) BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */ BLI_dynstr_append(dynstr, ")"); + if (buf != fixedbuf) { + MEM_freeN(buf); + } } } break; @@ -5460,13 +5488,20 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in BLI_dynstr_appendf(dynstr, "%d", RNA_property_int_get_index(ptr, prop, index)); } else { + int fixedbuf[RNA_MAX_ARRAY_LENGTH]; + int *buf = ARRAY_SIZE(fixedbuf) >= len ? fixedbuf : MEM_mallocN(sizeof(*buf) * len, __func__); + + RNA_property_int_get_array(ptr, prop, buf); BLI_dynstr_append(dynstr, "("); for (i = 0; i < len; i++) { - BLI_dynstr_appendf(dynstr, i ? ", %d" : "%d", RNA_property_int_get_index(ptr, prop, i)); + BLI_dynstr_appendf(dynstr, i ? ", %d" : "%d", buf[i]); } if (len == 1) BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */ BLI_dynstr_append(dynstr, ")"); + if (buf != fixedbuf) { + MEM_freeN(buf); + } } } break; @@ -5479,13 +5514,20 @@ char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, in BLI_dynstr_appendf(dynstr, "%g", RNA_property_float_get_index(ptr, prop, index)); } else { + float fixedbuf[RNA_MAX_ARRAY_LENGTH]; + float *buf = ARRAY_SIZE(fixedbuf) >= len ? fixedbuf : MEM_mallocN(sizeof(*buf) * len, __func__); + + RNA_property_float_get_array(ptr, prop, buf); BLI_dynstr_append(dynstr, "("); for (i = 0; i < len; i++) { - BLI_dynstr_appendf(dynstr, i ? ", %g" : "%g", RNA_property_float_get_index(ptr, prop, i)); + BLI_dynstr_appendf(dynstr, i ? ", %g" : "%g", buf[i]); } if (len == 1) BLI_dynstr_append(dynstr, ","); /* otherwise python wont see it as a tuple */ BLI_dynstr_append(dynstr, ")"); + if (buf != fixedbuf) { + MEM_freeN(buf); + } } } break; @@ -5631,7 +5673,7 @@ PropertyRNA *RNA_function_find_parameter(PointerRNA *UNUSED(ptr), FunctionRNA *f parm = func->cont.properties.first; for (; parm; parm = parm->next) - if (strcmp(RNA_property_identifier(parm), identifier) == 0) + if (STREQ(RNA_property_identifier(parm), identifier)) break; return parm; @@ -5829,7 +5871,7 @@ void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void parm = parms->func->cont.properties.first; for (; parm; parm = parm->next) - if (strcmp(RNA_property_identifier(parm), identifier) == 0) + if (STREQ(RNA_property_identifier(parm), identifier)) break; if (parm) @@ -5885,7 +5927,7 @@ void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, cons parm = parms->func->cont.properties.first; for (; parm; parm = parm->next) - if (strcmp(RNA_property_identifier(parm), identifier) == 0) + if (STREQ(RNA_property_identifier(parm), identifier)) break; if (parm) @@ -6629,8 +6671,8 @@ bool RNA_property_equals(PointerRNA *a, PointerRNA *b, PropertyRNA *prop, eRNAEq int *array_a, *array_b; bool equals; - array_a = (len > 16) ? MEM_callocN(sizeof(int) * len, "RNA equals") : fixed_a; - array_b = (len > 16) ? MEM_callocN(sizeof(int) * len, "RNA equals") : fixed_b; + array_a = (len > 16) ? MEM_mallocN(sizeof(int) * len, "RNA equals") : fixed_a; + array_b = (len > 16) ? MEM_mallocN(sizeof(int) * len, "RNA equals") : fixed_b; RNA_property_boolean_get_array(a, prop, array_a); RNA_property_boolean_get_array(b, prop, array_b); @@ -6655,8 +6697,8 @@ bool RNA_property_equals(PointerRNA *a, PointerRNA *b, PropertyRNA *prop, eRNAEq int *array_a, *array_b; bool equals; - array_a = (len > 16) ? MEM_callocN(sizeof(int) * len, "RNA equals") : fixed_a; - array_b = (len > 16) ? MEM_callocN(sizeof(int) * len, "RNA equals") : fixed_b; + array_a = (len > 16) ? MEM_mallocN(sizeof(int) * len, "RNA equals") : fixed_a; + array_b = (len > 16) ? MEM_mallocN(sizeof(int) * len, "RNA equals") : fixed_b; RNA_property_int_get_array(a, prop, array_a); RNA_property_int_get_array(b, prop, array_b); @@ -6681,8 +6723,8 @@ bool RNA_property_equals(PointerRNA *a, PointerRNA *b, PropertyRNA *prop, eRNAEq float *array_a, *array_b; bool equals; - array_a = (len > 16) ? MEM_callocN(sizeof(float) * len, "RNA equals") : fixed_a; - array_b = (len > 16) ? MEM_callocN(sizeof(float) * len, "RNA equals") : fixed_b; + array_a = (len > 16) ? MEM_mallocN(sizeof(float) * len, "RNA equals") : fixed_a; + array_b = (len > 16) ? MEM_mallocN(sizeof(float) * len, "RNA equals") : fixed_b; RNA_property_float_get_array(a, prop, array_a); RNA_property_float_get_array(b, prop, array_b); @@ -6712,7 +6754,7 @@ bool RNA_property_equals(PointerRNA *a, PointerRNA *b, PropertyRNA *prop, eRNAEq int len_a, len_b; char *value_a = RNA_property_string_get_alloc(a, prop, fixed_a, sizeof(fixed_a), &len_a); char *value_b = RNA_property_string_get_alloc(b, prop, fixed_b, sizeof(fixed_b), &len_b); - bool equals = strcmp(value_a, value_b) == 0; + bool equals = STREQ(value_a, value_b); if (value_a != fixed_a) MEM_freeN(value_a); if (value_b != fixed_b) MEM_freeN(value_b); |