From 636baa598a5698d84eca89d17c67a74092cef4d0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 31 Aug 2017 23:32:21 +1000 Subject: RNA: Limit which classes struct-map contains Only add subclasses of: Menu, Panel, Header, UIList, Operator This helps avoid unnecessary naming collisions, See T52599 for details --- source/blender/makesrna/intern/rna_define.c | 49 ++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'source/blender/makesrna/intern/rna_define.c') diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index cbe9684e821..2a6a3d06b15 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -142,7 +142,9 @@ static void rna_brna_structs_add(BlenderRNA *brna, StructRNA *srna) /* This exception is only needed for pre-processing. * otherwise we don't allow empty names. */ - if (srna->identifier[0] != '\0') { + if ((srna->flag & STRUCT_PUBLIC_NAMESPACE) && + (srna->identifier[0] != '\0')) + { BLI_ghash_insert(brna->structs_map, (void *)srna->identifier, srna); } } @@ -150,7 +152,7 @@ static void rna_brna_structs_add(BlenderRNA *brna, StructRNA *srna) #ifdef RNA_RUNTIME static void rna_brna_structs_remove_and_free(BlenderRNA *brna, StructRNA *srna) { - if (brna->structs_map) { + if ((srna->flag & STRUCT_PUBLIC_NAMESPACE) && brna->structs_map) { if (srna->identifier[0] != '\0') { BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, NULL, NULL); } @@ -763,12 +765,19 @@ StructRNA *RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRN BLI_listbase_clear(&srna->functions); srna->py_type = NULL; + srna->base = srnafrom; + if (DefRNA.preprocess) { - srna->base = srnafrom; dsfrom = rna_find_def_struct(srnafrom); } - else - srna->base = srnafrom; + else { + if (srnafrom->flag & STRUCT_PUBLIC_NAMESPACE_INHERIT) { + srna->flag |= STRUCT_PUBLIC_NAMESPACE | STRUCT_PUBLIC_NAMESPACE_INHERIT; + } + else { + srna->flag &= ~(STRUCT_PUBLIC_NAMESPACE | STRUCT_PUBLIC_NAMESPACE_INHERIT); + } + } } srna->identifier = identifier; @@ -780,6 +789,10 @@ StructRNA *RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRN if (!srnafrom) srna->icon = ICON_DOT; + if (DefRNA.preprocess) { + srna->flag |= STRUCT_PUBLIC_NAMESPACE; + } + rna_brna_structs_add(brna, srna); if (DefRNA.preprocess) { @@ -1001,12 +1014,14 @@ void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *id } /* Operator registration may set twice, see: operator_properties_init */ - if (identifier != srna->identifier) { - if (srna->identifier[0] != '\0') { - BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, NULL, NULL); - } - if (identifier[0] != '\0') { - BLI_ghash_insert(brna->structs_map, (void *)identifier, srna); + if (srna->flag & STRUCT_PUBLIC_NAMESPACE) { + if (identifier != srna->identifier) { + if (srna->identifier[0] != '\0') { + BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, NULL, NULL); + } + if (identifier[0] != '\0') { + BLI_ghash_insert(brna->structs_map, (void *)identifier, srna); + } } } @@ -3316,8 +3331,10 @@ void RNA_enum_item_end(EnumPropertyItem **items, int *totitem) void RNA_def_struct_duplicate_pointers(BlenderRNA *brna, StructRNA *srna) { if (srna->identifier) { - srna->identifier = BLI_strdup(srna->identifier); - BLI_ghash_replace_key(brna->structs_map, (void *)srna->identifier); + if (srna->flag & STRUCT_PUBLIC_NAMESPACE) { + srna->identifier = BLI_strdup(srna->identifier); + BLI_ghash_replace_key(brna->structs_map, (void *)srna->identifier); + } } if (srna->name) { srna->name = BLI_strdup(srna->name); @@ -3333,8 +3350,10 @@ void RNA_def_struct_free_pointers(BlenderRNA *brna, StructRNA *srna) { if (srna->flag & STRUCT_FREE_POINTERS) { if (srna->identifier) { - if (brna != NULL) { - BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, NULL, NULL); + if (srna->flag & STRUCT_PUBLIC_NAMESPACE) { + if (brna != NULL) { + BLI_ghash_remove(brna->structs_map, (void *)srna->identifier, NULL, NULL); + } } MEM_freeN((void *)srna->identifier); } -- cgit v1.2.3