[Bf-blender-cvs] [636baa598a5] master: RNA: Limit which classes struct-map contains

Campbell Barton noreply at git.blender.org
Thu Aug 31 15:43:18 CEST 2017


Commit: 636baa598a5698d84eca89d17c67a74092cef4d0
Author: Campbell Barton
Date:   Thu Aug 31 23:32:21 2017 +1000
Branches: master
https://developer.blender.org/rB636baa598a5698d84eca89d17c67a74092cef4d0

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

===================================================================

M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/rna_ID.c
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/makesrna/intern/rna_animation.c
M	source/blender/makesrna/intern/rna_define.c
M	source/blender/makesrna/intern/rna_internal_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_render.c
M	source/blender/makesrna/intern/rna_rna.c
M	source/blender/makesrna/intern/rna_ui.c
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/python/intern/bpy_operator_wrap.c
M	source/blender/python/intern/bpy_rna.c

===================================================================

diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index ecd7f3211bb..e119c49401e 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -436,6 +436,8 @@ typedef enum StructFlag {
 	STRUCT_NO_IDPROPERTIES = (1 << 6), /* Menus and Panels don't need properties */
 	STRUCT_NO_DATABLOCK_IDPROPERTIES = (1 << 7), /* e.g. for Operator */
 	STRUCT_CONTAINS_DATABLOCK_IDPROPERTIES = (1 << 8), /* for PropertyGroup which contains pointers to datablocks */
+	STRUCT_PUBLIC_NAMESPACE = (1 << 9), /* Added to type-map #BlenderRNA.structs_map */
+	STRUCT_PUBLIC_NAMESPACE_INHERIT = (1 << 10), /* All subtypes are added too. */
 } StructFlag;
 
 typedef int (*StructValidateFunc)(struct PointerRNA *ptr, void *data, int *have_function);
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 9d7dd7f424a..a74758a4f71 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -273,10 +273,6 @@ StructRNA *rna_PropertyGroup_register(Main *UNUSED(bmain), ReportList *reports,
 		return NULL;
 	}
 
-	if (!RNA_struct_available_or_report(reports, identifier)) {
-		return NULL;
-	}
-
 	return RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_PropertyGroup);  /* XXX */
 }
 
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 15b535625df..6f2cfbdb6bd 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -89,6 +89,7 @@ void RNA_init(void)
 				}
 			}
 		}
+		BLI_assert(srna->flag & STRUCT_PUBLIC_NAMESPACE);
 		BLI_ghash_insert(BLENDER_RNA.structs_map, (void *)srna->identifier, srna);
 		BLENDER_RNA.structs_len += 1;
 	}
@@ -814,6 +815,9 @@ char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, i
 	return NULL;
 }
 
+/**
+ * Use when registering structs with the #STRUCT_PUBLIC_NAMESPACE flag.
+ */
 bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
 {
 	const StructRNA *srna_exists = RNA_struct_find(identifier);
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index cc3c140c5c6..d9f673acf89 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -273,9 +273,6 @@ static StructRNA *rna_KeyingSetInfo_register(Main *bmain, ReportList *reports, v
 	if (ksi && ksi->ext.srna) {
 		rna_KeyingSetInfo_unregister(bmain, ksi->ext.srna);
 	}
-	if (!RNA_struct_available_or_report(reports, dummyksi.idname)) {
-		return NULL;
-	}
 
 	/* create a new KeyingSetInfo type */
 	ksi = MEM_callocN(sizeof(KeyingSetInfo), "python keying set info");
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);
 		}
diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h
index b52f6c78f3a..a470c807091 100644
--- a/source/blender/makesrna/intern/rna_internal_types.h
+++ b/source/blender/makesrna/intern/rna_internal_types.h
@@ -413,6 +413,8 @@ struct StructRNA {
 
 struct BlenderRNA {
 	ListBase structs;
+	/* A map of structs: {StructRNA.identifier -> StructRNA}
+	 * These are ensured to have unique names (with STRUCT_PUBLIC_NAMESPACE enabled). */
 	struct GHash *structs_map;
 	/* Needed because types with an empty identifier aren't included in 'structs_map'. */
 	unsigned int  structs_len;
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 1c7d7816f0f..4de91a1c57c 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -633,9 +633,6 @@ static StructRNA *rna_NodeTree_register(
 	if (nt) {
 		rna_NodeTree_unregister(bmain, nt->ext.srna);
 	}
-	if (!RNA_struct_available_or_report(reports, dummynt.idname)) {
-		return NULL;
-	}
 
 	/* create a new node tree type */
 	nt = MEM_callocN(sizeof(bNodeTreeType), "node tree type");
@@ -1399,9 +1396,6 @@ static bNodeType *rna_Node_register_base(Main *bmain, ReportList *reports, Struc
 	if (nt) {
 		rna_Node_unregister(bmain, nt->ext.srna);
 	}
-	if (!RNA_struct_available_or_report(reports, dummynt.idname)) {
-		return NULL;
-	}
 	
 	/* create a new node type */
 	nt = MEM_callocN(sizeof(bNodeType), "node type");
diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c
index 360b8831f8c..a66c160ed1a 100644
--- a/source/blender/makesrna/intern/rna_render.c
+++ b/source/blender/makesrna/intern/rna_render.c
@@ -321,9 +321,6 @@ static StructRNA *rna_RenderEngine_register(Main *bmain, ReportList *reports, vo
 			break;
 		}
 	}
-	if (!RNA_struct_available_or_report(reports, dummyet.idname)) {
-		return NULL;
-	}
 	
 	/* create a new engine type */
 	et = MEM_callocN(sizeof(RenderEngineType), "python render engine");
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index bbd0fe2486e..b50ac7a61ef 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -983,10 +983,18 @@ static int rna_Function_use_self_type_get(PointerRNA *ptr)
 
 /* Blender RNA */
 
+static int rna_struct_is_publc(CollectionPropertyIterator *UNUSED(iter), void *data)
+{
+	StructRNA *srna = data;
+
+	return !(srna->flag & STRUCT_PUBLIC_NAMESPACE);
+}
+
+
 static void rna_BlenderRNA_structs_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
 	BlenderRNA *brna = ptr->data;
-	rna_iterator_listbase_begin(iter, &brna->structs, NULL);
+	rna_iterator_listbase_begin(iter, &brna->structs, rna_struct_is_publc);
 }
 
 /* optional, for faster lookups */
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index 84e446ef330..0e8f47e59ef 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -949,6 +949,7 @@ static void rna_def_panel(BlenderRNA *brna)
 	RNA_def_struct_refine_func(srna, "rna_Panel_refine");
 	RNA_def_struct_register_funcs(srna, "rna_Panel_register", "rna_Panel_unregister", NULL);
 	RNA_def_struct_translation_context(srna, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
+	RNA_def_struct_flag(srna, STRUCT_PUBLIC_NAMESPACE_INHERIT);
 
 	/* poll */
 	func = RNA_def_function(srna, "poll", NULL);
@@ -1051,7 +1052,7 @@ static void rna_def_uilist(BlenderRNA *brna)
 	RNA_def_struct_refine_func(srna, "rna_UIList_refine");
 	RNA_def_str

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list