[Bf-blender-cvs] [daa834bc116] master: RNA: Operators were excluded from struct map

Campbell Barton noreply at git.blender.org
Fri Aug 11 12:12:40 CEST 2017


Commit: daa834bc116719ffc884905238969b98ac4eb2c9
Author: Campbell Barton
Date:   Fri Aug 11 20:09:22 2017 +1000
Branches: master
https://developer.blender.org/rBdaa834bc116719ffc884905238969b98ac4eb2c9

RNA: Operators were excluded from struct map

Recent changes meant structs that were registered without a name
wouldn't get added to the map.
Now assigning identifiers manages the struct-map.

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

M	source/blender/blenkernel/intern/node.c
M	source/blender/makesrna/RNA_define.h
M	source/blender/makesrna/intern/rna_define.c
M	source/blender/python/intern/bpy_operator_wrap.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index b11b328a01c..07fdd667425 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -2280,7 +2280,7 @@ StructRNA *ntreeInterfaceTypeGet(bNodeTree *ntree, int create)
 			
 			/* rename the RNA type */
 			RNA_def_struct_free_pointers(srna);
-			RNA_def_struct_identifier(srna, identifier);
+			RNA_def_struct_identifier(&BLENDER_RNA, srna, identifier);
 			RNA_def_struct_ui_text(srna, name, description);
 			RNA_def_struct_duplicate_pointers(srna);
 		}
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h
index 6e62313b00a..b49cea0263b 100644
--- a/source/blender/makesrna/RNA_define.h
+++ b/source/blender/makesrna/RNA_define.h
@@ -62,7 +62,8 @@ void RNA_def_struct_refine_func(StructRNA *srna, const char *refine);
 void RNA_def_struct_idprops_func(StructRNA *srna, const char *refine);
 void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg, const char *instance);
 void RNA_def_struct_path_func(StructRNA *srna, const char *path);
-void RNA_def_struct_identifier(StructRNA *srna, const char *identifier);
+void RNA_def_struct_identifier_no_struct_map(StructRNA *srna, const char *identifier);
+void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *identifier);
 void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description);
 void RNA_def_struct_ui_icon(StructRNA *srna, int icon);
 void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *ext);
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 0f8bc19bd6c..b10a2b33317 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -993,7 +993,30 @@ void RNA_def_struct_path_func(StructRNA *srna, const char *path)
 	if (path) srna->path = (StructPathFunc)path;
 }
 
-void RNA_def_struct_identifier(StructRNA *srna, const char *identifier)
+void RNA_def_struct_identifier(BlenderRNA *brna, StructRNA *srna, const char *identifier)
+{
+	if (DefRNA.preprocess) {
+		fprintf(stderr, "%s: only at runtime.\n", __func__);
+		return;
+	}
+
+	/* 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);
+		}
+	}
+
+	srna->identifier = identifier;
+}
+
+/**
+ * Only used in one case when we name the struct for the purpose of useful error messages.
+ */
+void RNA_def_struct_identifier_no_struct_map(StructRNA *srna, const char *identifier)
 {
 	if (DefRNA.preprocess) {
 		fprintf(stderr, "%s: only at runtime.\n", __func__);
diff --git a/source/blender/python/intern/bpy_operator_wrap.c b/source/blender/python/intern/bpy_operator_wrap.c
index 90719905a79..9d57adca946 100644
--- a/source/blender/python/intern/bpy_operator_wrap.c
+++ b/source/blender/python/intern/bpy_operator_wrap.c
@@ -48,10 +48,12 @@ static void operator_properties_init(wmOperatorType *ot)
 	PyTypeObject *py_class = ot->ext.data;
 	RNA_struct_blender_type_set(ot->ext.srna, ot);
 
-	/* only call this so pyrna_deferred_register_class gives a useful error
-	 * WM_operatortype_append_ptr will call RNA_def_struct_identifier
-	 * later */
-	RNA_def_struct_identifier(ot->srna, ot->idname);
+	/* Only call this so pyrna_deferred_register_class gives a useful error
+	 * WM_operatortype_append_ptr will call RNA_def_struct_identifier later.
+	 *
+	 * Note the 'no_struct_map' function is used since the actual struct name is already used by the operator.
+	 */
+	RNA_def_struct_identifier_no_struct_map(ot->srna, ot->idname);
 
 	if (pyrna_deferred_register_class(ot->srna, py_class) != 0) {
 		PyErr_Print(); /* failed to register operator props */
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index aa27254bbaa..cd3bebb48ee 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -177,7 +177,7 @@ void WM_operatortype_append(void (*opfunc)(wmOperatorType *))
 
 	/* XXX All ops should have a description but for now allow them not to. */
 	RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description : UNDOCUMENTED_OPERATOR_TIP);
-	RNA_def_struct_identifier(ot->srna, ot->idname);
+	RNA_def_struct_identifier(&BLENDER_RNA, ot->srna, ot->idname);
 
 	BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot);
 }
@@ -193,7 +193,7 @@ void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType *, void *), void *
 	ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT;
 	opfunc(ot, userdata);
 	RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description : UNDOCUMENTED_OPERATOR_TIP);
-	RNA_def_struct_identifier(ot->srna, ot->idname);
+	RNA_def_struct_identifier(&BLENDER_RNA, ot->srna, ot->idname);
 
 	BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot);
 }
@@ -398,7 +398,7 @@ wmOperatorType *WM_operatortype_append_macro(const char *idname, const char *nam
 		ot->description = UNDOCUMENTED_OPERATOR_TIP;
 	
 	RNA_def_struct_ui_text(ot->srna, ot->name, ot->description);
-	RNA_def_struct_identifier(ot->srna, ot->idname);
+	RNA_def_struct_identifier(&BLENDER_RNA, ot->srna, ot->idname);
 	/* Use i18n context from ext.srna if possible (py operators). */
 	i18n_context = ot->ext.srna ? RNA_struct_translation_context(ot->ext.srna) : BLT_I18NCONTEXT_OPERATOR_DEFAULT;
 	RNA_def_struct_translation_context(ot->srna, i18n_context);
@@ -432,7 +432,7 @@ void WM_operatortype_append_macro_ptr(void (*opfunc)(wmOperatorType *, void *),
 	opfunc(ot, userdata);
 
 	RNA_def_struct_ui_text(ot->srna, ot->name, ot->description);
-	RNA_def_struct_identifier(ot->srna, ot->idname);
+	RNA_def_struct_identifier(&BLENDER_RNA, ot->srna, ot->idname);
 
 	BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot);
 }




More information about the Bf-blender-cvs mailing list