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:
authorHans Goudey <h.goudey@me.com>2022-07-19 18:30:10 +0300
committerHans Goudey <h.goudey@me.com>2022-07-19 18:30:19 +0300
commit35b4e3a3501c9c797f2269421bc778e949fb46af (patch)
tree0f11dd7841601c1a50bf9636c8d3a26bf8bd7cab /source/blender/makesrna/intern/makesrna.c
parentc771dd5e9c85335aa5e4cf60cfa61bc286c26229 (diff)
RNA: Don't allocate empty char pointer properties
Instead of allocating a single 0 char, set the `char *` DNA pointer to null. This avoids the overhead of allocating and copying single-bytes. rBeed45b655c9f didn't do this for safety reasons, but I checked the existing uses of this behavior in DNA/RNA. Out of 43 total `char *` members, this change only affects 7 recently added properties. For a complete list, see the patch description. Differential Revision: https://developer.blender.org/D14779
Diffstat (limited to 'source/blender/makesrna/intern/makesrna.c')
-rw-r--r--source/blender/makesrna/intern/makesrna.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index b5354514205..a25fe201fa2 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -1117,8 +1117,10 @@ static char *rna_def_property_set_func(
fprintf(
f, " if (data->%s != NULL) { MEM_freeN(data->%s); }\n", dp->dnaname, dp->dnaname);
fprintf(f, " const int length = strlen(value);\n");
- fprintf(f, " data->%s = MEM_mallocN(length + 1, __func__);\n", dp->dnaname);
- fprintf(f, " %s(data->%s, value, length + 1);\n", string_copy_func, dp->dnaname);
+ fprintf(f, " if (length > 0) {\n");
+ fprintf(f, " data->%s = MEM_mallocN(length + 1, __func__);\n", dp->dnaname);
+ fprintf(f, " %s(data->%s, value, length + 1);\n", string_copy_func, dp->dnaname);
+ fprintf(f, " } else { data->%s = NULL; }\n", dp->dnaname);
}
else {
/* Handle char array properties. */