[Bf-blender-cvs] [1e60ac33949] master: RNA: report error on struct naming collision

Campbell Barton noreply at git.blender.org
Wed Aug 23 06:58:45 CEST 2017


Commit: 1e60ac33949ae533857fc6a48ce5fbc2402dd060
Author: Campbell Barton
Date:   Wed Aug 23 14:59:14 2017 +1000
Branches: master
https://developer.blender.org/rB1e60ac33949ae533857fc6a48ce5fbc2402dd060

RNA: report error on struct naming collision

Fixes T52463, error instead of crash.

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

M	source/blender/makesrna/RNA_access.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_nodetree.c
M	source/blender/makesrna/intern/rna_render.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

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

diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index a1af3f98274..2a1554bcb8c 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -783,6 +783,8 @@ const struct ListBase *RNA_struct_type_functions(StructRNA *srna);
 
 char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len);
 
+bool RNA_struct_available_or_report(struct ReportList *reports, const char *identifier);
+
 /* Properties
  *
  * Access to struct properties. All this works with RNA pointers rather than
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index a74758a4f71..9d7dd7f424a 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -273,6 +273,10 @@ 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 89348bb8f6c..15b535625df 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -814,6 +814,38 @@ char *RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, i
 	return NULL;
 }
 
+bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
+{
+	const StructRNA *srna_exists = RNA_struct_find(identifier);
+	if (UNLIKELY(srna_exists != NULL)) {
+		/* Use comprehensive string construction since this is such a rare occurrence
+		 * and information here may cut down time troubleshooting. */
+		DynStr *dynstr = BLI_dynstr_new();
+		BLI_dynstr_appendf(dynstr, "Type identifier '%s' is already in use: '", identifier);
+		BLI_dynstr_append(dynstr, srna_exists->identifier);
+		int i = 0;
+		if (srna_exists->base) {
+			for (const StructRNA *base = srna_exists->base; base; base = base->base) {
+				BLI_dynstr_append(dynstr, "(");
+				BLI_dynstr_append(dynstr, base->identifier);
+				i += 1;
+			}
+			while (i--) {
+				BLI_dynstr_append(dynstr, ")");
+			}
+		}
+		BLI_dynstr_append(dynstr, "'.");
+		char *result = BLI_dynstr_get_cstring(dynstr);
+		BLI_dynstr_free(dynstr);
+		BKE_report(reports, RPT_ERROR, result);
+		MEM_freeN(result);
+		return false;
+	}
+	else {
+		return true;
+	}
+}
+
 /* Property Information */
 
 const char *RNA_property_identifier(PropertyRNA *prop)
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index f271bccd326..b0a51fd8c73 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -270,9 +270,13 @@ static StructRNA *rna_KeyingSetInfo_register(Main *bmain, ReportList *reports, v
 	
 	/* check if we have registered this info before, and remove it */
 	ksi = ANIM_keyingset_info_find_name(dummyksi.idname);
-	if (ksi && ksi->ext.srna)
+	if (ksi && ksi->ext.srna) {
 		rna_KeyingSetInfo_unregister(bmain, ksi->ext.srna);
-	
+	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
+
 	/* create a new KeyingSetInfo type */
 	ksi = MEM_callocN(sizeof(KeyingSetInfo), "python keying set info");
 	memcpy(ksi, &dummyksi, sizeof(KeyingSetInfo));
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 00b881dabc7..f15605d0f83 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -630,9 +630,13 @@ static StructRNA *rna_NodeTree_register(
 
 	/* check if we have registered this tree type before, and remove it */
 	nt = ntreeTypeFind(dummynt.idname);
-	if (nt)
+	if (nt) {
 		rna_NodeTree_unregister(bmain, nt->ext.srna);
-	
+	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
+
 	/* create a new node tree type */
 	nt = MEM_callocN(sizeof(bNodeTreeType), "node tree type");
 	memcpy(nt, &dummynt, sizeof(dummynt));
@@ -1389,11 +1393,18 @@ static bNodeType *rna_Node_register_base(Main *bmain, ReportList *reports, Struc
 		            identifier, (int)sizeof(dummynt.idname));
 		return NULL;
 	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
 
 	/* check if we have registered this node type before, and remove it */
 	nt = nodeTypeFind(dummynt.idname);
-	if (nt)
+	if (nt) {
 		rna_Node_unregister(bmain, nt->ext.srna);
+	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		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 a66c160ed1a..0c0484e633b 100644
--- a/source/blender/makesrna/intern/rna_render.c
+++ b/source/blender/makesrna/intern/rna_render.c
@@ -321,6 +321,9 @@ static StructRNA *rna_RenderEngine_register(Main *bmain, ReportList *reports, vo
 			break;
 		}
 	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
 	
 	/* create a new engine type */
 	et = MEM_callocN(sizeof(RenderEngineType), "python render engine");
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index 64b41ac789f..0fc0739f860 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -229,6 +229,9 @@ static StructRNA *rna_Panel_register(Main *bmain, ReportList *reports, void *dat
 			break;
 		}
 	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
 	
 	/* create a new panel type */
 	pt = MEM_callocN(sizeof(PanelType), "python buttons panel");
@@ -488,8 +491,12 @@ static StructRNA *rna_UIList_register(Main *bmain, ReportList *reports, void *da
 
 	/* check if we have registered this uilist type before, and remove it */
 	ult = WM_uilisttype_find(dummyult.idname, true);
-	if (ult && ult->ext.srna)
+	if (ult && ult->ext.srna) {
 		rna_UIList_unregister(bmain, ult->ext.srna);
+	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
 
 	/* create a new menu type */
 	ult = MEM_callocN(sizeof(uiListType) + over_alloc, "python uilist");
@@ -592,6 +599,9 @@ static StructRNA *rna_Header_register(Main *bmain, ReportList *reports, void *da
 			break;
 		}
 	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
 	
 	/* create a new header type */
 	ht = MEM_callocN(sizeof(HeaderType), "python buttons header");
@@ -712,8 +722,12 @@ static StructRNA *rna_Menu_register(Main *bmain, ReportList *reports, void *data
 
 	/* check if we have registered this menu type before, and remove it */
 	mt = WM_menutype_find(dummymt.idname, true);
-	if (mt && mt->ext.srna)
+	if (mt && mt->ext.srna) {
 		rna_Menu_unregister(bmain, mt->ext.srna);
+	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
 	
 	/* create a new menu type */
 	if (_menu_descr[0]) {
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 19a25b4df11..3ecacd11a5c 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -638,10 +638,11 @@ static StructRNA *rna_AddonPref_register(Main *bmain, ReportList *reports, void
 
 	/* check if we have registered this header type before, and remove it */
 	apt = BKE_addon_pref_type_find(dummyaddon.module, true);
-	if (apt) {
-		if (apt->ext.srna) {
-			rna_AddonPref_unregister(bmain, apt->ext.srna);
-		}
+	if (apt && apt->ext.srna) {
+		rna_AddonPref_unregister(bmain, apt->ext.srna);
+	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
 	}
 
 	/* create a new header type */
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 4aee03025f6..a7afc405048 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -1147,6 +1147,16 @@ static StructRNA *rna_Operator_register(
 	if (validate(&dummyotr, data, have_function) != 0)
 		return NULL;
 
+	/* check if we have registered this operator type before, and remove it */
+	{
+		wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true);
+		if (ot && ot->ext.srna)
+			rna_Operator_unregister(bmain, ot->ext.srna);
+	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
+
 	{   /* convert foo.bar to FOO_OT_bar
 		 * allocate the description and the idname in 1 go */
 
@@ -1214,13 +1224,6 @@ static StructRNA *rna_Operator_register(
 		}
 	}
 
-	/* check if we have registered this operator type before, and remove it */
-	{
-		wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true);
-		if (ot && ot->ext.srna)
-			rna_Operator_unregister(bmain, ot->ext.srna);
-	}
-
 	/* XXX, this doubles up with the operator name [#29666]
 	 * for now just remove from dir(bpy.types) */
 
@@ -1323,6 +1326,16 @@ static StructRNA *rna_MacroOperator_register(
 		return NULL;
 	}
 
+	/* check if we have registered this operator type before, and remove it */
+	{
+		wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true);
+		if (ot && ot->ext.srna)
+			rna_Operator_unregister(bmain, ot->ext.srna);
+	}
+	if (!RNA_struct_available_or_report(reports, identifier)) {
+		return NULL;
+	}
+
 	{   /* convert foo.bar to FOO_OT_bar
 		 * allocate the description and the idname in 1 go */
 		const uint idname_len = strlen(temp_buffers.idname) + 4;
@@ -1349,13 +1362,6 @@ static StructRNA *rna_MacroOperator_register(
 		dummyot.undo_group = ch;
 	}
 
-	/* check if we have registered this operator type before, and remove it */
-	{
-		wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true);
-		if (ot && ot->ext.srna)
-			rna_Operator_unregister(bmain, ot->ext.srna);
-	}
-
 	/* XXX, this doubles up with the operator name [#29666]
 	 * for now just remove from dir(bpy.types) */



More information about the Bf-blender-cvs mailing list