[Bf-blender-cvs] [bae1b645252] master: Fix broken 'undocumented' case in registration of Macro opertators.

Bastien Montagne noreply at git.blender.org
Mon Jul 19 16:05:30 CEST 2021


Commit: bae1b64525237617ef5c3ab30acfd042e8eca9eb
Author: Bastien Montagne
Date:   Mon Jul 19 15:59:26 2021 +0200
Branches: master
https://developer.blender.org/rBbae1b64525237617ef5c3ab30acfd042e8eca9eb

Fix broken 'undocumented' case in registration of Macro opertators.

Code dealing with macro operators missing description field was slightly
different than the one from Operator registration.

This lead to invalid memory accesses in some python introspection cases
like the i18n messages extraction code in `bl_i18n_utils` module.

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

M	source/blender/windowmanager/intern/wm_operator_type.c

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

diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c
index e17d5a9ae70..39435721d1a 100644
--- a/source/blender/windowmanager/intern/wm_operator_type.c
+++ b/source/blender/windowmanager/intern/wm_operator_type.c
@@ -498,12 +498,11 @@ wmOperatorType *WM_operatortype_append_macro(const char *idname,
   ot->cancel = wm_macro_cancel;
   ot->poll = NULL;
 
-  if (!ot->description) {
-    /* XXX All ops should have a description but for now allow them not to. */
-    ot->description = UNDOCUMENTED_OPERATOR_TIP;
-  }
+  /* XXX All ops should have a description but for now allow them not to. */
+  BLI_assert((ot->description == NULL) || (ot->description[0]));
 
-  RNA_def_struct_ui_text(ot->srna, ot->name, ot->description);
+  RNA_def_struct_ui_text(
+      ot->srna, ot->name, ot->description ? ot->description : UNDOCUMENTED_OPERATOR_TIP);
   RNA_def_struct_identifier(&BLENDER_RNA, ot->srna, ot->idname);
   /* Use i18n context from rna_ext.srna if possible (py operators). */
   i18n_context = ot->rna_ext.srna ? RNA_struct_translation_context(ot->rna_ext.srna) :
@@ -530,16 +529,16 @@ void WM_operatortype_append_macro_ptr(void (*opfunc)(wmOperatorType *, void *),
   ot->cancel = wm_macro_cancel;
   ot->poll = NULL;
 
-  if (!ot->description) {
-    ot->description = UNDOCUMENTED_OPERATOR_TIP;
-  }
+  /* XXX All ops should have a description but for now allow them not to. */
+  BLI_assert((ot->description == NULL) || (ot->description[0]));
 
   /* Set the default i18n context now, so that opfunc can redefine it if needed! */
   RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
   ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT;
   opfunc(ot, userdata);
 
-  RNA_def_struct_ui_text(ot->srna, ot->name, ot->description);
+  RNA_def_struct_ui_text(
+      ot->srna, ot->name, ot->description ? ot->description : UNDOCUMENTED_OPERATOR_TIP);
   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