diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 275 |
1 files changed, 80 insertions, 195 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index e4bda24cf20..7b8edb6c341 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -209,41 +209,7 @@ static IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name) return NULL; } -static int rna_ensure_property_array_length(PointerRNA *ptr, PropertyRNA *prop) -{ - if(prop->magic == RNA_MAGIC) { - int arraylen[RNA_MAX_ARRAY_DIMENSION]; - return (prop->getlength)? prop->getlength(ptr, arraylen): prop->totarraylength; - } - else { - IDProperty *idprop= (IDProperty*)prop; - - if(idprop->type == IDP_ARRAY) - return idprop->len; - else - return 0; - } -} - -static void rna_ensure_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int length[]) -{ - if(prop->magic == RNA_MAGIC) { - if(prop->getlength) - prop->getlength(ptr, length); - else - memcpy(length, prop->arraylength, prop->arraydimension*sizeof(int)); - } - else { - IDProperty *idprop= (IDProperty*)prop; - - if(idprop->type == IDP_ARRAY) - length[0]= idprop->len; - else - length[0]= 0; - } -} - -static int rna_idproperty_verify_valid(PointerRNA *ptr, PropertyRNA *prop, IDProperty *idprop) +static int rna_idproperty_verify_valid(PropertyRNA *prop, IDProperty *idprop) { /* this verifies if the idproperty actually matches the property * description and otherwise removes it. this is to ensure that @@ -256,7 +222,7 @@ static int rna_idproperty_verify_valid(PointerRNA *ptr, PropertyRNA *prop, IDPro return 0; break; case IDP_ARRAY: - if(rna_ensure_property_array_length(ptr, prop) != idprop->len) + if(prop->arraylength != idprop->len) return 0; if(idprop->subtype == IDP_FLOAT && prop->type != PROP_FLOAT) @@ -317,7 +283,7 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) if((*prop)->flag & PROP_IDPROPERTY) { IDProperty *idprop= rna_idproperty_find(ptr, (*prop)->identifier); - if(idprop && !rna_idproperty_verify_valid(ptr, *prop, idprop)) { + if(idprop && !rna_idproperty_verify_valid(*prop, idprop)) { IDProperty *group= RNA_struct_idproperties(ptr, 0); IDP_RemFromGroup(group, idprop); @@ -344,7 +310,7 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr) } } -static PropertyRNA *rna_ensure_property(PropertyRNA *prop) +PropertyRNA *rna_ensure_property(PropertyRNA *prop) { /* the quick version if we don't need the idproperty */ @@ -361,7 +327,7 @@ static PropertyRNA *rna_ensure_property(PropertyRNA *prop) } } -static const char *rna_ensure_property_identifier(PropertyRNA *prop) +const char *rna_ensure_property_identifier(PropertyRNA *prop) { if(prop->magic == RNA_MAGIC) return prop->identifier; @@ -369,7 +335,7 @@ static const char *rna_ensure_property_identifier(PropertyRNA *prop) return ((IDProperty*)prop)->name; } -static const char *rna_ensure_property_name(PropertyRNA *prop) +const char *rna_ensure_property_name(PropertyRNA *prop) { if(prop->magic == RNA_MAGIC) return prop->name; @@ -377,6 +343,20 @@ static const char *rna_ensure_property_name(PropertyRNA *prop) return ((IDProperty*)prop)->name; } +int rna_ensure_property_array_length(PropertyRNA *prop) +{ + if(prop->magic == RNA_MAGIC) + return prop->arraylength; + else { + IDProperty *idprop= (IDProperty*)prop; + + if(idprop->type == IDP_ARRAY) + return idprop->len; + else + return 0; + } +} + /* Structs */ const char *RNA_struct_identifier(StructRNA *type) @@ -569,30 +549,9 @@ int RNA_property_flag(PropertyRNA *prop) return rna_ensure_property(prop)->flag; } -int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop) +int RNA_property_array_length(PropertyRNA *prop) { - return rna_ensure_property_array_length(ptr, prop); -} - -/* used by BPY to make an array from the python object */ -int RNA_property_array_dimension(PointerRNA *ptr, PropertyRNA *prop, int length[]) -{ - PropertyRNA *rprop= rna_ensure_property(prop); - - if(length && rprop->arraydimension > 1) - rna_ensure_property_multi_array_length(ptr, prop, length); - - return rprop->arraydimension; -} - -/* Return the size of Nth dimension. */ -int RNA_property_multi_array_length(PointerRNA *ptr, PropertyRNA *prop, int dim) -{ - int len[RNA_MAX_ARRAY_DIMENSION]; - - rna_ensure_property_multi_array_length(ptr, prop, len); - - return len[dim]; + return rna_ensure_property_array_length(prop); } char RNA_property_array_item_char(PropertyRNA *prop, int index) @@ -895,40 +854,27 @@ void RNA_property_boolean_get_array(PointerRNA *ptr, PropertyRNA *prop, int *val IDProperty *idprop; if((idprop=rna_idproperty_check(&prop, ptr))) { - if(prop->arraydimension == 0) + if(prop->arraylength == 0) values[0]= RNA_property_boolean_get(ptr, prop); else memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len); } - else if(prop->arraydimension == 0) + else if(prop->arraylength == 0) values[0]= RNA_property_boolean_get(ptr, prop); else if(bprop->getarray) bprop->getarray(ptr, values); else if(bprop->defaultarray) - memcpy(values, bprop->defaultarray, sizeof(int)*prop->totarraylength); + memcpy(values, bprop->defaultarray, sizeof(int)*prop->arraylength); else - memset(values, 0, sizeof(int)*prop->totarraylength); + memset(values, 0, sizeof(int)*prop->arraylength); } 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); - - if(len <= RNA_MAX_ARRAY_LENGTH) { - RNA_property_boolean_get_array(ptr, prop, tmp); - return tmp[index]; - } - else { - int *tmparray, value; + int tmp[RNA_MAX_ARRAY]; - tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index"); - RNA_property_boolean_get_array(ptr, prop, tmparray); - value= tmparray[index]; - MEM_freeN(tmparray); - - return value; - } + RNA_property_boolean_get_array(ptr, prop, tmp); + return tmp[index]; } void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values) @@ -937,12 +883,12 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const in IDProperty *idprop; if((idprop=rna_idproperty_check(&prop, ptr))) { - if(prop->arraydimension == 0) + if(prop->arraylength == 0) IDP_Int(idprop)= values[0]; else memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len); } - else if(prop->arraydimension == 0) + else if(prop->arraylength == 0) RNA_property_boolean_set(ptr, prop, values[0]); else if(bprop->setarray) bprop->setarray(ptr, values); @@ -950,7 +896,7 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const in IDPropertyTemplate val = {0}; IDProperty *group; - val.array.len= prop->totarraylength; + val.array.len= prop->arraylength; val.array.type= IDP_INT; group= RNA_struct_idproperties(ptr, 1); @@ -964,23 +910,11 @@ void RNA_property_boolean_set_array(PointerRNA *ptr, PropertyRNA *prop, const in void RNA_property_boolean_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value) { - int tmp[RNA_MAX_ARRAY_LENGTH]; - int len= rna_ensure_property_array_length(ptr, prop); - - if(len <= RNA_MAX_ARRAY_LENGTH) { - RNA_property_boolean_get_array(ptr, prop, tmp); - tmp[index]= value; - RNA_property_boolean_set_array(ptr, prop, tmp); - } - else { - int *tmparray; + int tmp[RNA_MAX_ARRAY]; - tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_boolean_get_index"); - RNA_property_boolean_get_array(ptr, prop, tmparray); - tmparray[index]= value; - RNA_property_boolean_set_array(ptr, prop, tmparray); - MEM_freeN(tmparray); - } + RNA_property_boolean_get_array(ptr, prop, tmp); + tmp[index]= value; + RNA_property_boolean_set_array(ptr, prop, tmp); } int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop) @@ -1023,40 +957,27 @@ void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values) IDProperty *idprop; if((idprop=rna_idproperty_check(&prop, ptr))) { - if(prop->arraydimension == 0) + if(prop->arraylength == 0) values[0]= RNA_property_int_get(ptr, prop); else memcpy(values, IDP_Array(idprop), sizeof(int)*idprop->len); } - else if(prop->arraydimension == 0) + else if(prop->arraylength == 0) values[0]= RNA_property_int_get(ptr, prop); else if(iprop->getarray) iprop->getarray(ptr, values); else if(iprop->defaultarray) - memcpy(values, iprop->defaultarray, sizeof(int)*prop->totarraylength); + memcpy(values, iprop->defaultarray, sizeof(int)*prop->arraylength); else - memset(values, 0, sizeof(int)*prop->totarraylength); + memset(values, 0, sizeof(int)*prop->arraylength); } int RNA_property_int_get_index(PointerRNA *ptr, PropertyRNA *prop, int index) { - int tmp[RNA_MAX_ARRAY_LENGTH]; - int len= rna_ensure_property_array_length(ptr, prop); - - if(len <= RNA_MAX_ARRAY_LENGTH) { - RNA_property_int_get_array(ptr, prop, tmp); - return tmp[index]; - } - else { - int *tmparray, value; + int tmp[RNA_MAX_ARRAY]; - tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index"); - RNA_property_int_get_array(ptr, prop, tmparray); - value= tmparray[index]; - MEM_freeN(tmparray); - - return value; - } + RNA_property_int_get_array(ptr, prop, tmp); + return tmp[index]; } void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values) @@ -1065,12 +986,12 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v IDProperty *idprop; if((idprop=rna_idproperty_check(&prop, ptr))) { - if(prop->arraydimension == 0) + if(prop->arraylength == 0) IDP_Int(idprop)= values[0]; else memcpy(IDP_Array(idprop), values, sizeof(int)*idprop->len);\ } - else if(prop->arraydimension == 0) + else if(prop->arraylength == 0) RNA_property_int_set(ptr, prop, values[0]); else if(iprop->setarray) iprop->setarray(ptr, values); @@ -1078,7 +999,7 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v IDPropertyTemplate val = {0}; IDProperty *group; - val.array.len= prop->totarraylength; + val.array.len= prop->arraylength; val.array.type= IDP_INT; group= RNA_struct_idproperties(ptr, 1); @@ -1092,23 +1013,11 @@ void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *v void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, int value) { - int tmp[RNA_MAX_ARRAY_LENGTH]; - int len= rna_ensure_property_array_length(ptr, prop); - - if(len <= RNA_MAX_ARRAY_LENGTH) { - RNA_property_int_get_array(ptr, prop, tmp); - tmp[index]= value; - RNA_property_int_set_array(ptr, prop, tmp); - } - else { - int *tmparray; + int tmp[RNA_MAX_ARRAY]; - tmparray= MEM_callocN(sizeof(int)*len, "RNA_property_int_get_index"); - RNA_property_int_get_array(ptr, prop, tmparray); - tmparray[index]= value; - RNA_property_int_set_array(ptr, prop, tmparray); - MEM_freeN(tmparray); - } + RNA_property_int_get_array(ptr, prop, tmp); + tmp[index]= value; + RNA_property_int_set_array(ptr, prop, tmp); } float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop) @@ -1161,7 +1070,7 @@ void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *val int i; if((idprop=rna_idproperty_check(&prop, ptr))) { - if(prop->arraydimension == 0) + if(prop->arraylength == 0) values[0]= RNA_property_float_get(ptr, prop); else if(idprop->subtype == IDP_FLOAT) { memcpy(values, IDP_Array(idprop), sizeof(float)*idprop->len); @@ -1171,36 +1080,22 @@ void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *val values[i]= (float)(((double*)IDP_Array(idprop))[i]); } } - else if(prop->arraydimension == 0) + else if(prop->arraylength == 0) values[0]= RNA_property_float_get(ptr, prop); else if(fprop->getarray) fprop->getarray(ptr, values); else if(fprop->defaultarray) - memcpy(values, fprop->defaultarray, sizeof(float)*prop->totarraylength); + memcpy(values, fprop->defaultarray, sizeof(float)*prop->arraylength); else - memset(values, 0, sizeof(float)*prop->totarraylength); + memset(values, 0, sizeof(float)*prop->arraylength); } float RNA_property_float_get_index(PointerRNA *ptr, PropertyRNA *prop, int index) { - float tmp[RNA_MAX_ARRAY_LENGTH]; - int len= rna_ensure_property_array_length(ptr, prop); - - if(len <= RNA_MAX_ARRAY_LENGTH) { - RNA_property_float_get_array(ptr, prop, tmp); - return tmp[index]; - } - else { - float *tmparray, value; - - tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index"); - RNA_property_float_get_array(ptr, prop, tmparray); - value= tmparray[index]; - MEM_freeN(tmparray); - - return value; - } + float tmp[RNA_MAX_ARRAY]; + RNA_property_float_get_array(ptr, prop, tmp); + return tmp[index]; } void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const float *values) @@ -1210,7 +1105,7 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa int i; if((idprop=rna_idproperty_check(&prop, ptr))) { - if(prop->arraydimension == 0) + if(prop->arraylength == 0) IDP_Double(idprop)= values[0]; else if(idprop->subtype == IDP_FLOAT) { memcpy(IDP_Array(idprop), values, sizeof(float)*idprop->len); @@ -1220,7 +1115,7 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa ((double*)IDP_Array(idprop))[i]= values[i]; } } - else if(prop->arraydimension == 0) + else if(prop->arraylength == 0) RNA_property_float_set(ptr, prop, values[0]); else if(fprop->setarray) { fprop->setarray(ptr, values); @@ -1229,7 +1124,7 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa IDPropertyTemplate val = {0}; IDProperty *group; - val.array.len= prop->totarraylength; + val.array.len= prop->arraylength; val.array.type= IDP_FLOAT; group= RNA_struct_idproperties(ptr, 1); @@ -1243,23 +1138,11 @@ void RNA_property_float_set_array(PointerRNA *ptr, PropertyRNA *prop, const floa void RNA_property_float_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, float value) { - float tmp[RNA_MAX_ARRAY_LENGTH]; - int len= rna_ensure_property_array_length(ptr, prop); + float tmp[RNA_MAX_ARRAY]; - if(len <= RNA_MAX_ARRAY_LENGTH) { - RNA_property_float_get_array(ptr, prop, tmp); - tmp[index]= value; - RNA_property_float_set_array(ptr, prop, tmp); - } - else { - float *tmparray; - - tmparray= MEM_callocN(sizeof(float)*len, "RNA_property_float_get_index"); - RNA_property_float_get_array(ptr, prop, tmparray); - tmparray[index]= value; - RNA_property_float_set_array(ptr, prop, tmparray); - MEM_freeN(tmparray); - } + RNA_property_float_get_array(ptr, prop, tmp); + tmp[index]= value; + RNA_property_float_set_array(ptr, prop, tmp); } void RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop, char *value) @@ -1801,7 +1684,7 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro } /* check item array */ - itemlen= RNA_property_array_length(&itemptr, itemprop); + itemlen= RNA_property_array_length(itemprop); /* try to access as raw array */ if(RNA_property_collection_raw_array(ptr, prop, itemprop, &out)) { @@ -1853,7 +1736,7 @@ static int rna_raw_access(ReportList *reports, PointerRNA *ptr, PropertyRNA *pro iprop= RNA_struct_find_property(&itemptr, propname); if(iprop) { - itemlen= RNA_property_array_length(&itemptr, iprop); + itemlen= RNA_property_array_length(iprop); itemtype= RNA_property_type(iprop); } else { @@ -2748,7 +2631,7 @@ int RNA_property_is_set(PointerRNA *ptr, const char *name) return (rna_idproperty_find(ptr, name) != NULL); } else { - // printf("RNA_property_is_set: %s.%s not found.\n", ptr->type->identifier, name); + printf("RNA_property_is_set: %s.%s not found.\n", ptr->type->identifier, name); return 0; } } @@ -2792,7 +2675,7 @@ char *RNA_pointer_as_string(PointerRNA *ptr) char *RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop) { int type = RNA_property_type(prop); - int len = RNA_property_array_length(ptr, prop); + int len = RNA_property_array_length(prop); int i; DynStr *dynstr= BLI_dynstr_new(); @@ -2981,15 +2864,15 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *ptr, if(!(parm->flag & PROP_REQUIRED)) { switch(parm->type) { case PROP_BOOLEAN: - if(parm->arraydimension) memcpy(data, &((BooleanPropertyRNA*)parm)->defaultarray, size); + if(parm->arraylength) memcpy(data, &((BooleanPropertyRNA*)parm)->defaultarray, size); else memcpy(data, &((BooleanPropertyRNA*)parm)->defaultvalue, size); break; case PROP_INT: - if(parm->arraydimension) memcpy(data, &((IntPropertyRNA*)parm)->defaultarray, size); + if(parm->arraylength) memcpy(data, &((IntPropertyRNA*)parm)->defaultarray, size); else memcpy(data, &((IntPropertyRNA*)parm)->defaultvalue, size); break; case PROP_FLOAT: - if(parm->arraydimension) memcpy(data, &((FloatPropertyRNA*)parm)->defaultarray, size); + if(parm->arraylength) memcpy(data, &((FloatPropertyRNA*)parm)->defaultarray, size); else memcpy(data, &((FloatPropertyRNA*)parm)->defaultvalue, size); break; case PROP_ENUM: @@ -3020,13 +2903,15 @@ void RNA_parameter_list_free(ParameterList *parms) parm= parms->func->cont.properties.first; for(tot= 0; parm; parm= parm->next) { - if(parm->type == PROP_COLLECTION) + if(parm->type == PROP_COLLECTION) { BLI_freelistN((ListBase*)((char*)parms->data+tot)); - else if (parm->flag & PROP_DYNAMIC) { + } + else if(parm == parms->func->ret) { /* for dynamic arrays and strings, data is a pointer to an array */ - char *array= *(char**)((char*)parms->data+tot); - if(array) - MEM_freeN(array); + char *ptr= *(char**)((char*)parms->data+tot); + if((parm->flag & PROP_DYNAMIC_ARRAY || parm->type == PROP_STRING) && ptr) { + MEM_freeN(ptr); + } } tot+= rna_parameter_size(parm); @@ -3400,7 +3285,7 @@ int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *pt type= RNA_property_type(parm); ftype= format[ofs++]; - len= RNA_property_array_length(&funcptr, parm); + len= RNA_property_array_length(parm); alen= rna_function_format_array_length(format, ofs, flen); if (len!=alen) { @@ -3465,7 +3350,7 @@ int RNA_function_call_direct_va(bContext *C, ReportList *reports, PointerRNA *pt type= RNA_property_type(parm); ftype= format[ofs++]; - len= RNA_property_array_length(&funcptr, parm); + len= RNA_property_array_length(parm); alen= rna_function_format_array_length(format, ofs, flen); if (len!=alen) { |