[Bf-blender-cvs] [c370fffc9bd] blender2.8: Resolve MSVC C2229

Campbell Barton noreply at git.blender.org
Mon Dec 4 16:51:03 CET 2017


Commit: c370fffc9bd0900a30e04ac631641d43e0f217a5
Author: Campbell Barton
Date:   Tue Dec 5 03:03:50 2017 +1100
Branches: blender2.8
https://developer.blender.org/rBc370fffc9bd0900a30e04ac631641d43e0f217a5

Resolve MSVC C2229

Code works as expected, but MSVC disallows

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

M	source/blender/windowmanager/message_bus/intern/wm_message_bus.c
M	source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h
M	source/blender/windowmanager/message_bus/wm_message_bus.h

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

diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus.c b/source/blender/windowmanager/message_bus/intern/wm_message_bus.c
index 0e7486fa293..7183655b0de 100644
--- a/source/blender/windowmanager/message_bus/intern/wm_message_bus.c
+++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus.c
@@ -95,9 +95,10 @@ void WM_msgbus_clear_by_owner(struct wmMsgBus *mbus, void *owner)
 		}
 
 		if (BLI_listbase_is_empty(&msg_key->values)) {
-			wmMsgTypeInfo *info = &wm_msg_types[msg_key->msg->type];
+			const wmMsg *msg = wm_msg_subscribe_value_msg_cast(msg_key);
+			wmMsgTypeInfo *info = &wm_msg_types[msg->type];
 			BLI_remlink(&mbus->messages, msg_key);
-			bool ok = BLI_gset_remove(mbus->messages_gset[msg_key->msg->type], msg_key, info->gset.key_free_fn);
+			bool ok = BLI_gset_remove(mbus->messages_gset[msg->type], msg_key, info->gset.key_free_fn);
 			BLI_assert(ok);
 			UNUSED_VARS_NDEBUG(ok);
 		}
@@ -108,7 +109,8 @@ void WM_msg_dump(struct wmMsgBus *mbus, const char *info_str)
 {
 	printf(">>>> %s\n", info_str);
 	for (wmMsgSubscribeKey *key = mbus->messages.first; key; key = key->next) {
-		const wmMsgTypeInfo *info = &wm_msg_types[key->msg->type];
+		const wmMsg *msg = wm_msg_subscribe_value_msg_cast(key);
+		const wmMsgTypeInfo *info = &wm_msg_types[msg->type];
 		info->repr(stdout, key);
 	}
 	printf("<<<< %s\n", info_str);
@@ -157,11 +159,11 @@ wmMsgSubscribeKey *WM_msg_subscribe_with_key(
         const wmMsgSubscribeKey *msg_key_test,
         const wmMsgSubscribeValue *msg_val_params)
 {
-	const uint type = msg_key_test->msg->type;
+	const uint type = wm_msg_subscribe_value_msg_cast(msg_key_test)->type;
 	const wmMsgTypeInfo *info = &wm_msg_types[type];
 	wmMsgSubscribeKey *key;
 
-	BLI_assert(msg_key_test->msg->id != NULL);
+	BLI_assert(wm_msg_subscribe_value_msg_cast(msg_key_test)->id != NULL);
 
 	void **r_key;
 	if (!BLI_gset_ensure_p_ex(mbus->messages_gset[type], msg_key_test, &r_key)) {
diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h b/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h
index 8d7b9d4ced2..db8b481a3c2 100644
--- a/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h
+++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h
@@ -38,4 +38,18 @@ struct wmMsgBus {
 void wm_msg_subscribe_value_free(
         struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValueLink *msg_lnk);
 
+typedef struct wmMsgSubscribeKey_Generic {
+	wmMsgSubscribeKey head;
+	wmMsg msg;
+} wmMsgSubscribeKey_Generic;
+
+BLI_INLINE const wmMsg *wm_msg_subscribe_value_msg_cast(const wmMsgSubscribeKey *key)
+{
+	return &((wmMsgSubscribeKey_Generic *)key)->msg;
+}
+BLI_INLINE wmMsg *wm_msg_subscribe_value_msg_cast_mut(wmMsgSubscribeKey *key)
+{
+	return &((wmMsgSubscribeKey_Generic *)key)->msg;
+}
+
 #endif /* __WM_MESSAGE_BUS_INTERN_H__ */
diff --git a/source/blender/windowmanager/message_bus/wm_message_bus.h b/source/blender/windowmanager/message_bus/wm_message_bus.h
index fd158e2cd7f..53f283cacd2 100644
--- a/source/blender/windowmanager/message_bus/wm_message_bus.h
+++ b/source/blender/windowmanager/message_bus/wm_message_bus.h
@@ -80,9 +80,8 @@ typedef struct wmMsgSubscribeKey {
 	/** Linked list for predicable ordering, otherwise we would depend on ghash bucketing. */
 	struct wmMsgSubscribeKey *next, *prev;
 	ListBase values;
-
 	/* over-alloc, eg: wmMsgSubscribeKey_RNA */
-	wmMsg msg[0];
+	/* Last member will be 'wmMsg_*' */
 } wmMsgSubscribeKey;
 
 /** One of many in #wmMsgSubscribeKey.values */



More information about the Bf-blender-cvs mailing list