diff options
author | Jacques Lucke <jacques@blender.org> | 2021-03-23 13:46:00 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-03-23 13:47:09 +0300 |
commit | eed45b655c9ff27718572da7359749ee615c5191 (patch) | |
tree | d176c01b06597de42a4667bc8429c5231cd8940d /source/blender/makesrna/intern/rna_nodetree.c | |
parent | 4e0fd7fff11b76e52a5f11ba8704028c9b3c3ab0 (diff) |
RNA: support automatically mapping string property to char pointer
The goal of this patch is to remove the boilerplate code required to get
a string property that maps to an allocated char pointer in dna.
Previously, one to to provide three callbacks, all of which are not necessary
anymore for a simple string property.
Currently, when an empty string is assigned, the `set` function will always
allocate it as well, instead of assigning `NULL` to the pointer. Some structs
might support `NULL` while others don't, so this is the safer option for now.
Differential Revision: https://developer.blender.org/D10773
Diffstat (limited to 'source/blender/makesrna/intern/rna_nodetree.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 36 |
1 files changed, 0 insertions, 36 deletions
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 3aba3e51217..d69a1e3dd06 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -4290,38 +4290,6 @@ void rna_ShaderNodePointDensity_density_minmax(bNode *self, RE_point_density_minmax(depsgraph, pd, r_min, r_max); } -static void rna_NodeInputString_string_get(PointerRNA *ptr, char *value) -{ - bNode *node = (bNode *)ptr->data; - NodeInputString *storage = node->storage; - - strcpy(value, (storage->string) ? storage->string : ""); -} - -static int rna_NodeInputString_string_length(PointerRNA *ptr) -{ - bNode *node = (bNode *)ptr->data; - NodeInputString *storage = node->storage; - - return (storage->string) ? strlen(storage->string) : 0; -} - -static void rna_NodeInputString_string_set(PointerRNA *ptr, const char *value) -{ - bNode *node = (bNode *)ptr->data; - NodeInputString *storage = node->storage; - - if (storage->string) { - MEM_freeN(storage->string); - } - - if (value && value[0]) { - storage->string = BLI_strdup(value); - } - else { - storage->string = NULL; - } -} #else static const EnumPropertyItem prop_image_layer_items[] = { @@ -4744,10 +4712,6 @@ static void def_fn_input_string(StructRNA *srna) RNA_def_struct_sdna_from(srna, "NodeInputString", "storage"); prop = RNA_def_property(srna, "string", PROP_STRING, PROP_NONE); - RNA_def_property_string_funcs(prop, - "rna_NodeInputString_string_get", - "rna_NodeInputString_string_length", - "rna_NodeInputString_string_set"); RNA_def_property_ui_text(prop, "String", ""); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); } |