From 6f1fa7aa256d2acc4bc91ff459c369db55ff8a02 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Mon, 2 Sep 2019 18:33:55 +0200 Subject: [PATCH] Fix/enhance new RNA path from real ID helpers. Main issue was that `rna_prepend_real_ID_path()` would return nothing in case given path was NULL, when it should actually return the `prefix` computed by `RNA_find_real_ID_and_path()` in that case... Also make return `real_id` pointer optionnal, no reasons to make it mandatory here. And some general naming fixes. --- source/blender/makesrna/RNA_access.h | 2 +- source/blender/makesrna/intern/rna_access.c | 26 ++++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index c1199ac94b6..f9f05348c5c 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -1168,7 +1168,7 @@ char *RNA_path_from_real_ID_to_property_index(struct Main *bmain, PropertyRNA *prop, int array_dim, int index, - struct ID **r_real); + struct ID **r_real_id); char *RNA_path_resolve_from_type_to_property(struct PointerRNA *ptr, struct PropertyRNA *prop, diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 531c2ef2003..61634a84d41 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -5794,15 +5794,23 @@ ID *RNA_find_real_ID_and_path(Main *bmain, ID *id, const char **r_path) } } -static char *rna_prepend_real_ID_path(Main *bmain, ID *id, char *path, ID **r_real) +static char *rna_prepend_real_ID_path(Main *bmain, ID *id, char *path, ID **r_real_id) { - if (path) { - const char *prefix; + if (r_real_id != NULL) { + *r_real_id = NULL; + } + + const char *prefix; + ID *real_id = RNA_find_real_ID_and_path(bmain, id, &prefix); + + if (r_real_id != NULL) { + *r_real_id = real_id; + } + + if (path != NULL) { char *new_path = NULL; - *r_real = RNA_find_real_ID_and_path(bmain, id, &prefix); - - if (*r_real) { + if (real_id) { if (prefix[0]) { new_path = BLI_sprintfN("%s%s%s", prefix, path[0] == '[' ? "" : ".", path); } @@ -5815,7 +5823,7 @@ static char *rna_prepend_real_ID_path(Main *bmain, ID *id, char *path, ID **r_re return new_path; } else { - return NULL; + return prefix[0] != '\0' ? BLI_strdup(prefix) : NULL; } } @@ -5975,11 +5983,11 @@ char *RNA_path_from_ID_to_property(PointerRNA *ptr, PropertyRNA *prop) } char *RNA_path_from_real_ID_to_property_index( - Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index, ID **r_real) + Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index_dim, int index, ID **r_real_id) { char *path = RNA_path_from_ID_to_property_index(ptr, prop, index_dim, index); - return rna_prepend_real_ID_path(bmain, ptr->owner_id, path, r_real); + return rna_prepend_real_ID_path(bmain, ptr->owner_id, path, r_real_id); } /**