[Bf-blender-cvs] [70648683a2a] master: Cleanup: add C++ compatible WL_ARRAY_FOR_EACH macro

Campbell Barton noreply at git.blender.org
Fri Jun 24 02:22:59 CEST 2022


Commit: 70648683a2aa97c7d0ebd310d7a2ab564bcd4fed
Author: Campbell Barton
Date:   Fri Jun 24 10:21:45 2022 +1000
Branches: master
https://developer.blender.org/rB70648683a2aa97c7d0ebd310d7a2ab564bcd4fed

Cleanup: add C++ compatible WL_ARRAY_FOR_EACH macro

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

M	.clang-format
A	intern/ghost/intern/GHOST_WaylandUtils.h
M	intern/ghost/intern/GHOST_WindowWayland.cpp

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

diff --git a/.clang-format b/.clang-format
index f7b785adaf2..7b8e0ef8eba 100644
--- a/.clang-format
+++ b/.clang-format
@@ -265,6 +265,7 @@ ForEachMacros:
   - SET_SLOT_PROBING_BEGIN
   - MAP_SLOT_PROBING_BEGIN
   - VECTOR_SET_SLOT_PROBING_BEGIN
+  - WL_ARRAY_FOR_EACH
 
 StatementMacros:
   - PyObject_HEAD
diff --git a/intern/ghost/intern/GHOST_WaylandUtils.h b/intern/ghost/intern/GHOST_WaylandUtils.h
new file mode 100644
index 00000000000..0e1e133bc4c
--- /dev/null
+++ b/intern/ghost/intern/GHOST_WaylandUtils.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup GHOST
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+#  undef wl_array_for_each
+/**
+ * This macro causes a warning for C++ code, define our own.
+ * See: https://gitlab.freedesktop.org/wayland/wayland/-/issues/34
+ */
+#  define WL_ARRAY_FOR_EACH(pos, array) \
+    for (pos = (decltype(pos))((array)->data); \
+         (const char *)pos < ((const char *)(array)->data + (array)->size); \
+         (pos)++)
+#endif
diff --git a/intern/ghost/intern/GHOST_WindowWayland.cpp b/intern/ghost/intern/GHOST_WindowWayland.cpp
index 394ad35082b..afaa2e11aa7 100644
--- a/intern/ghost/intern/GHOST_WindowWayland.cpp
+++ b/intern/ghost/intern/GHOST_WindowWayland.cpp
@@ -6,6 +6,7 @@
 
 #include "GHOST_WindowWayland.h"
 #include "GHOST_SystemWayland.h"
+#include "GHOST_WaylandUtils.h"
 #include "GHOST_WindowManager.h"
 
 #include "GHOST_Event.h"
@@ -134,12 +135,8 @@ static void xdg_toplevel_handle_configure(void *data,
   win->is_fullscreen = false;
   win->is_active = false;
 
-  /* Note that the macro 'wl_array_for_each' would typically be used to simplify this logic,
-   * however it's not compatible with C++, so perform casts instead.
-   * If this needs to be done more often we could define our own C++ compatible macro. */
-  for (enum xdg_toplevel_state *state = static_cast<xdg_toplevel_state *>(states->data);
-       reinterpret_cast<uint8_t *>(state) < (static_cast<uint8_t *>(states->data) + states->size);
-       state++) {
+  enum xdg_toplevel_state *state;
+  WL_ARRAY_FOR_EACH (state, states) {
     switch (*state) {
       case XDG_TOPLEVEL_STATE_MAXIMIZED:
         win->is_maximised = true;



More information about the Bf-blender-cvs mailing list