A classic idiom preventing all kinds of bad interactions with
surrounding code when the macro is expanded. Newer compilers may also
warn against empty statements of the form

    { expressions... };

where the ending ; is actually an empty statement.

https://gcc.gnu.org/onlinedocs/cpp/Swallowing-the-Semicolon.html

Signed-off-by: Antonin Décimo <anto...@tarides.com>
---
 mingw-w64-libraries/winpthreads/src/barrier.h |  7 +++--
 mingw-w64-libraries/winpthreads/src/cond.h    | 10 ++++---
 mingw-w64-libraries/winpthreads/src/misc.h    | 30 ++++++++++++-------
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/src/barrier.h 
b/mingw-w64-libraries/winpthreads/src/barrier.h
index b3e2146e7..b1d80d1bb 100644
--- a/mingw-w64-libraries/winpthreads/src/barrier.h
+++ b/mingw-w64-libraries/winpthreads/src/barrier.h
@@ -28,8 +28,11 @@
 
 #define _PTHREAD_BARRIER_FLAG (1<<30)
 
-#define CHECK_BARRIER(b)  { \
-    if (!(b) || ( ((barrier_t *)(*b))->valid != (unsigned int)LIFE_BARRIER ) ) 
return EINVAL; }
+#define CHECK_BARRIER(b)                                                \
+    do {                                                                \
+        if (!(b) || ( ((barrier_t *)(*b))->valid != (unsigned int)LIFE_BARRIER 
) ) \
+            return EINVAL;                                              \
+    } while (0)
 
 #include "../include/semaphore.h"
 
diff --git a/mingw-w64-libraries/winpthreads/src/cond.h 
b/mingw-w64-libraries/winpthreads/src/cond.h
index c70d31146..5e869e957 100644
--- a/mingw-w64-libraries/winpthreads/src/cond.h
+++ b/mingw-w64-libraries/winpthreads/src/cond.h
@@ -25,10 +25,12 @@
 
 #include <windows.h>
 
-#define CHECK_COND(c)  { \
-    if (!(c) || !*c || (*c == PTHREAD_COND_INITIALIZER) \
-        || ( ((cond_t *)(*c))->valid != (unsigned int)LIFE_COND ) ) \
-        return EINVAL; }
+#define CHECK_COND(c)                                                   \
+    do {                                                                \
+        if (!(c) || !*c || (*c == PTHREAD_COND_INITIALIZER)             \
+            || ( ((cond_t *)(*c))->valid != (unsigned int)LIFE_COND ) ) \
+            return EINVAL;                                              \
+    } while (0)
 
 #define LIFE_COND 0xC0BAB1FD
 #define DEAD_COND 0xC0DEADBF
diff --git a/mingw-w64-libraries/winpthreads/src/misc.h 
b/mingw-w64-libraries/winpthreads/src/misc.h
index 15f4c3743..fc67b009f 100644
--- a/mingw-w64-libraries/winpthreads/src/misc.h
+++ b/mingw-w64-libraries/winpthreads/src/misc.h
@@ -67,22 +67,30 @@ typedef long LONGBAG;
 #define GetHandleInformation(h,f)  (1)
 #endif
 
-#define CHECK_HANDLE(h) { DWORD dwFlags; \
+#define CHECK_HANDLE(h)                                                 \
+  do {                                                                  \
+    DWORD dwFlags;                                                      \
     if (!(h) || ((h) == INVALID_HANDLE_VALUE) || !GetHandleInformation((h), 
&dwFlags)) \
-    return EINVAL; }
+      return EINVAL;                                                    \
+  } while (0)
 
-#define CHECK_PTR(p)    if (!(p)) return EINVAL;
+#define CHECK_PTR(p) do { if (!(p)) return EINVAL; } while (0)
 
-#define UPD_RESULT(x,r)    { int _r=(x); r = r ? r : _r; }
+#define UPD_RESULT(x,r) do { (r) = (r) ? (r) : (x); } while (0)
 
-#define CHECK_THREAD(t)  { \
-    CHECK_PTR(t); \
-    CHECK_HANDLE(t->h); }
+#define CHECK_THREAD(t)                         \
+  do {                                          \
+    CHECK_PTR(t);                               \
+    CHECK_HANDLE((t)->h);                       \
+  } while (0)
 
-#define CHECK_OBJECT(o, e)  { DWORD dwFlags; \
-    if (!(o)) return e; \
+#define CHECK_OBJECT(o, e)                                              \
+  do {                                                                  \
+    DWORD dwFlags;                                                      \
+    if (!(o)) return e;                                                 \
     if (!((o)->h) || (((o)->h) == INVALID_HANDLE_VALUE) || 
!GetHandleInformation(((o)->h), &dwFlags)) \
-        return e; }
+      return e;                                                         \
+  } while (0)
 
 #define VALID(x)    if (!(p)) return EINVAL;
 
@@ -94,7 +102,7 @@ static WINPTHREADS_INLINE unsigned long dwMilliSecs(unsigned 
long long ms)
 }
 
 #ifndef _mm_pause
-#define _mm_pause()                    {__asm__ __volatile__("pause");}
+#define _mm_pause() do { __asm__ __volatile__("pause"); } while (0)
 #endif
 
 #ifndef _ReadWriteBarrier
-- 
2.43.0



_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to