[Bf-blender-cvs] [800fc173674] master: Fix/workaround MSVC compile error with messag-bus

Julian Eisel noreply at git.blender.org
Thu Jan 13 20:44:46 CET 2022


Commit: 800fc17367480b82e07570d5234726aa61c38563
Author: Julian Eisel
Date:   Thu Jan 13 20:40:52 2022 +0100
Branches: master
https://developer.blender.org/rB800fc17367480b82e07570d5234726aa61c38563

Fix/workaround MSVC compile error with messag-bus

Some of the message-bus macros are not safe to use in C++. This has come
up before, but no good solution was found. Now @LazyDodo, @HooglyBoogly
and I concluded this is the best duct tape "solution" for the moment.
The message-bus API should address this.

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

M	source/blender/editors/space_outliner/outliner_collections.cc
M	source/blender/editors/space_outliner/outliner_draw.cc
M	source/blender/editors/space_outliner/outliner_tools.cc
M	source/blender/editors/space_outliner/space_outliner.cc
M	source/blender/windowmanager/message_bus/wm_message_bus.h

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

diff --git a/source/blender/editors/space_outliner/outliner_collections.cc b/source/blender/editors/space_outliner/outliner_collections.cc
index 9fc841fcba9..e4c4d41a04b 100644
--- a/source/blender/editors/space_outliner/outliner_collections.cc
+++ b/source/blender/editors/space_outliner/outliner_collections.cc
@@ -385,6 +385,8 @@ void outliner_collection_delete(
   BLI_gset_free(data.collections_to_edit, nullptr);
 }
 
+/* FIXME: See comment above #WM_msg_publish_rna_prop(). */
+extern "C" {
 static int collection_hierarchy_delete_exec(bContext *C, wmOperator *op)
 {
   Main *bmain = CTX_data_main(C);
@@ -408,6 +410,7 @@ static int collection_hierarchy_delete_exec(bContext *C, wmOperator *op)
 
   return OPERATOR_FINISHED;
 }
+}
 
 void OUTLINER_OT_collection_hierarchy_delete(wmOperatorType *ot)
 {
diff --git a/source/blender/editors/space_outliner/outliner_draw.cc b/source/blender/editors/space_outliner/outliner_draw.cc
index 9c522effa5e..3d29f1762ec 100644
--- a/source/blender/editors/space_outliner/outliner_draw.cc
+++ b/source/blender/editors/space_outliner/outliner_draw.cc
@@ -668,6 +668,8 @@ static void scenes__collection_set_flag_recursive_fn(bContext *C, void *poin, vo
   outliner_collection_set_flag_recursive_fn(C, nullptr, collection, propname);
 }
 
+/* FIXME: See comment above #WM_msg_publish_rna_prop(). */
+extern "C" {
 static void namebutton_fn(bContext *C, void *tsep, char *oldname)
 {
   Main *bmain = CTX_data_main(C);
@@ -865,6 +867,7 @@ static void namebutton_fn(bContext *C, void *tsep, char *oldname)
     tselem->flag &= ~TSE_TEXTBUT;
   }
 }
+}
 
 typedef struct RestrictProperties {
   bool initialized;
diff --git a/source/blender/editors/space_outliner/outliner_tools.cc b/source/blender/editors/space_outliner/outliner_tools.cc
index 097d7181c99..89d35f54e8c 100644
--- a/source/blender/editors/space_outliner/outliner_tools.cc
+++ b/source/blender/editors/space_outliner/outliner_tools.cc
@@ -1686,6 +1686,8 @@ static TreeTraversalAction outliner_find_objects_to_delete(TreeElement *te, void
   return TRAVERSE_CONTINUE;
 }
 
+/* FIXME: See comment above #WM_msg_publish_rna_prop(). */
+extern "C" {
 static int outliner_delete_exec(bContext *C, wmOperator *op)
 {
   Main *bmain = CTX_data_main(C);
@@ -1745,6 +1747,7 @@ static int outliner_delete_exec(bContext *C, wmOperator *op)
 
   return OPERATOR_FINISHED;
 }
+}
 
 void OUTLINER_OT_delete(wmOperatorType *ot)
 {
diff --git a/source/blender/editors/space_outliner/space_outliner.cc b/source/blender/editors/space_outliner/space_outliner.cc
index ea6ecbfe84c..d3a78425242 100644
--- a/source/blender/editors/space_outliner/space_outliner.cc
+++ b/source/blender/editors/space_outliner/space_outliner.cc
@@ -262,6 +262,8 @@ static void outliner_main_region_listener(const wmRegionListenerParams *params)
   }
 }
 
+/* FIXME: See comment above #WM_msg_publish_rna_prop(). */
+extern "C" {
 static void outliner_main_region_message_subscribe(const wmRegionMessageSubscribeParams *params)
 {
   struct wmMsgBus *mbus = params->message_bus;
@@ -278,6 +280,7 @@ static void outliner_main_region_message_subscribe(const wmRegionMessageSubscrib
     WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
   }
 }
+}
 
 /* ************************ header outliner area region *********************** */
 
diff --git a/source/blender/windowmanager/message_bus/wm_message_bus.h b/source/blender/windowmanager/message_bus/wm_message_bus.h
index e9f99979e93..a93a7bbcea7 100644
--- a/source/blender/windowmanager/message_bus/wm_message_bus.h
+++ b/source/blender/windowmanager/message_bus/wm_message_bus.h
@@ -244,6 +244,17 @@ void WM_msg_subscribe_ID(struct wmMsgBus *mbus,
                          const char *id_repr);
 void WM_msg_publish_ID(struct wmMsgBus *mbus, struct ID *id);
 
+/* FIXME
+ *
+ * For C++ code, some of the following macros need to be called in functions wrapped in
+ * `extern "C"` blocks. That is, the ones doing `extern PropertyRNA` declarations (trips up the
+ * MSVC linker).
+ * Although this shouldn't cause problems normally, if it does, the bits calling the macros can be
+ * moved to a separate function wrapped in `extern "C"`.
+ *
+ * Obviously this should be fixed properly (by not relying on inline `extern` declarations).
+ */
+
 #define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_) \
   { \
     wmMsgParams_RNA msg_key_params_ = {{0}}; \



More information about the Bf-blender-cvs mailing list