Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2009-07-22 00:05:16 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2009-07-22 00:05:16 +0400
commit6b8dae0874d774888374992fc3923affb451c45a (patch)
tree3783cb8c8039971d1ddfaad1a93cc1738be0f5b3 /source/blender/makesrna/intern/rna_define.c
parentb8445173c4c8588a64870e93dd781d181d31c78b (diff)
RNA
* ID blocks can now get RNA properties defined from python, e.g.: bpy.types.Scene.BoolProperty(..) * RNA structs/functions/properties can now get pointers duplicated (mostly strings), since we can't point to some static string then. * Added ExtensionRNA struct to add into *Type structs for subclassing, is a bit more compact than defining the 4 variables each time. Only disadvantage is it requires including RNA in more places.
Diffstat (limited to 'source/blender/makesrna/intern/rna_define.c')
-rw-r--r--source/blender/makesrna/intern/rna_define.c152
1 files changed, 150 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 491095a0bd6..2530f452393 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -39,6 +39,7 @@
#include "RNA_types.h"
#include "BLI_ghash.h"
+#include "BLI_string.h"
#include "rna_internal.h"
@@ -445,6 +446,7 @@ void RNA_define_verify_sdna(int verify)
void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
{
+#ifdef RNA_RUNTIME
FunctionRNA *func, *nextfunc;
PropertyRNA *prop, *nextprop;
PropertyRNA *parm, *nextparm;
@@ -452,6 +454,8 @@ void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
for(prop=srna->cont.properties.first; prop; prop=nextprop) {
nextprop= prop->next;
+ RNA_def_property_free_pointers(prop);
+
if(prop->flag & PROP_RUNTIME)
rna_freelinkN(&srna->cont.properties, prop);
}
@@ -462,17 +466,23 @@ void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
for(parm=func->cont.properties.first; parm; parm=nextparm) {
nextparm= parm->next;
+ RNA_def_property_free_pointers(parm);
+
if(parm->flag & PROP_RUNTIME)
rna_freelinkN(&func->cont.properties, parm);
}
- if(func->flag & FUNC_RUNTIME) {
+ RNA_def_func_free_pointers(func);
+
+ if(func->flag & FUNC_RUNTIME)
rna_freelinkN(&srna->functions, func);
- }
}
+ RNA_def_struct_free_pointers(srna);
+
if(srna->flag & STRUCT_RUNTIME)
rna_freelinkN(&brna->structs, srna);
+#endif
}
void RNA_free(BlenderRNA *brna)
@@ -2327,3 +2337,141 @@ void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
RNA_enum_item_add(items, totitem, &empty);
}
+/* Memory management */
+
+#ifdef RNA_RUNTIME
+void RNA_def_struct_duplicate_pointers(StructRNA *srna)
+{
+ if(srna->identifier) srna->identifier= BLI_strdup(srna->identifier);
+ if(srna->name) srna->name= BLI_strdup(srna->name);
+ if(srna->description) srna->description= BLI_strdup(srna->description);
+
+ srna->flag |= STRUCT_FREE_POINTERS;
+}
+
+void RNA_def_struct_free_pointers(StructRNA *srna)
+{
+ if(srna->flag & STRUCT_FREE_POINTERS) {
+ if(srna->identifier) MEM_freeN((void*)srna->identifier);
+ if(srna->name) MEM_freeN((void*)srna->name);
+ if(srna->description) MEM_freeN((void*)srna->description);
+ }
+}
+
+void RNA_def_func_duplicate_pointers(FunctionRNA *func)
+{
+ if(func->identifier) func->identifier= BLI_strdup(func->identifier);
+ if(func->description) func->description= BLI_strdup(func->description);
+
+ func->flag |= FUNC_FREE_POINTERS;
+}
+
+void RNA_def_func_free_pointers(FunctionRNA *func)
+{
+ if(func->flag & FUNC_FREE_POINTERS) {
+ if(func->identifier) MEM_freeN((void*)func->identifier);
+ if(func->description) MEM_freeN((void*)func->description);
+ }
+}
+
+void RNA_def_property_duplicate_pointers(PropertyRNA *prop)
+{
+ EnumPropertyItem *earray;
+ float *farray;
+ int *iarray;
+
+ if(prop->identifier) prop->identifier= BLI_strdup(prop->identifier);
+ if(prop->name) prop->name= BLI_strdup(prop->name);
+ if(prop->description) prop->description= BLI_strdup(prop->description);
+
+ switch(prop->type) {
+ case PROP_BOOLEAN: {
+ BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
+
+ if(bprop->defaultarray) {
+ iarray= MEM_callocN(sizeof(int)*prop->arraylength, "RNA_def_property_store");
+ memcpy(iarray, bprop->defaultarray, sizeof(int)*prop->arraylength);
+ bprop->defaultarray= iarray;
+ }
+ break;
+ }
+ case PROP_INT: {
+ IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
+
+ if(iprop->defaultarray) {
+ iarray= MEM_callocN(sizeof(int)*prop->arraylength, "RNA_def_property_store");
+ memcpy(iarray, iprop->defaultarray, sizeof(int)*prop->arraylength);
+ iprop->defaultarray= iarray;
+ }
+ break;
+ }
+ case PROP_ENUM: {
+ EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
+
+ if(eprop->item) {
+ earray= MEM_callocN(sizeof(EnumPropertyItem)*(eprop->totitem+1), "RNA_def_property_store"),
+ memcpy(earray, eprop->item, sizeof(EnumPropertyItem)*(eprop->totitem+1));
+ eprop->item= earray;
+ }
+ }
+ case PROP_FLOAT: {
+ FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
+
+ if(fprop->defaultarray) {
+ farray= MEM_callocN(sizeof(float)*prop->arraylength, "RNA_def_property_store");
+ memcpy(farray, fprop->defaultarray, sizeof(float)*prop->arraylength);
+ fprop->defaultarray= farray;
+ }
+ break;
+ }
+ case PROP_STRING: {
+ StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
+ if(sprop->defaultvalue) sprop->defaultvalue= BLI_strdup(sprop->defaultvalue);
+ break;
+ }
+ default:
+ break;
+ }
+
+ prop->flag |= PROP_FREE_POINTERS;
+}
+
+void RNA_def_property_free_pointers(PropertyRNA *prop)
+{
+ if(prop->flag & PROP_FREE_POINTERS) {
+ if(prop->identifier) MEM_freeN((void*)prop->identifier);
+ if(prop->name) MEM_freeN((void*)prop->name);
+ if(prop->description) MEM_freeN((void*)prop->description);
+
+ switch(prop->type) {
+ case PROP_BOOLEAN: {
+ BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
+ if(bprop->defaultarray) MEM_freeN((void*)bprop->defaultarray);
+ break;
+ }
+ case PROP_INT: {
+ IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
+ if(iprop->defaultarray) MEM_freeN((void*)iprop->defaultarray);
+ break;
+ }
+ case PROP_FLOAT: {
+ FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
+ if(fprop->defaultarray) MEM_freeN((void*)fprop->defaultarray);
+ break;
+ }
+ case PROP_ENUM: {
+ EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
+ if(eprop->item) MEM_freeN((void*)eprop->item);
+ }
+ case PROP_STRING: {
+ StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
+ if(sprop->defaultvalue) MEM_freeN((void*)sprop->defaultvalue);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}
+#endif
+