Cleanup/refactor `rna_idp_path` code.
Factorize common processes and checks, early `continue` in invalid cases, etc.
This commit is contained in:
parent
ad63d2f60e
commit
7f3601e70d
Notes:
blender-bot
2023-02-13 22:39:58 +01:00
Referenced by commit e22a36e80a
, Cleanup: Use proper `RNA_pointer_is_null` helper.
|
@ -5696,8 +5696,7 @@ static char *rna_idp_path(PointerRNA *ptr,
|
|||
BLI_assert(haystack->type == IDP_GROUP);
|
||||
|
||||
link.up = parent_link;
|
||||
/* always set both name and index,
|
||||
* else a stale value might get used */
|
||||
/* Always set both name and index, else a stale value might get used. */
|
||||
link.name = NULL;
|
||||
link.index = -1;
|
||||
|
||||
|
@ -5708,19 +5707,28 @@ static char *rna_idp_path(PointerRNA *ptr,
|
|||
path = rna_idp_path_create(&link);
|
||||
break;
|
||||
}
|
||||
if (iter->type == IDP_GROUP) {
|
||||
/* Ensure this is RNA. */
|
||||
PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name);
|
||||
|
||||
/* NOTE: `iter` might be a fully user-defined IDProperty (a.k.a. custom data), which name
|
||||
* collides with an actual fully static RNA property of the same struct (which would then not
|
||||
* be flagged with `PROP_IDPROPERTY`).
|
||||
*
|
||||
* That case must be ignored here, we only want to deal with runtime RNA properties stored in
|
||||
* IDProps here.
|
||||
*
|
||||
* See T84091. */
|
||||
if (prop != NULL && prop->type == PROP_POINTER && (prop->flag & PROP_IDPROPERTY) != 0) {
|
||||
/* Early out in case the IDProperty type cannot contain RNA properties. */
|
||||
if (!ELEM(iter->type, IDP_GROUP, IDP_IDPARRAY)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Ensure this is RNA. */
|
||||
/* NOTE: `iter` might be a fully user-defined IDProperty (a.k.a. custom data), which name
|
||||
* collides with an actual fully static RNA property of the same struct (which would then not
|
||||
* be flagged with `PROP_IDPROPERTY`).
|
||||
*
|
||||
* That case must be ignored here, we only want to deal with runtime RNA properties stored in
|
||||
* IDProps.
|
||||
*
|
||||
* See T84091. */
|
||||
PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name);
|
||||
if (prop == NULL || (prop->flag & PROP_IDPROPERTY) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (iter->type == IDP_GROUP) {
|
||||
if (prop->type == PROP_POINTER) {
|
||||
PointerRNA child_ptr = RNA_property_pointer_get(ptr, prop);
|
||||
BLI_assert(child_ptr.type != NULL);
|
||||
link.name = iter->name;
|
||||
|
@ -5731,9 +5739,7 @@ static char *rna_idp_path(PointerRNA *ptr,
|
|||
}
|
||||
}
|
||||
else if (iter->type == IDP_IDPARRAY) {
|
||||
PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name);
|
||||
/* See comment above in `IDP_GROUP` case, same applies here. */
|
||||
if (prop != NULL && prop->type == PROP_COLLECTION && (prop->flag & PROP_IDPROPERTY) != 0) {
|
||||
if (prop->type == PROP_COLLECTION) {
|
||||
IDProperty *array = IDP_IDPArray(iter);
|
||||
if (needle >= array && needle < (iter->len + array)) { /* found! */
|
||||
link.name = iter->name;
|
||||
|
|
Loading…
Reference in New Issue