mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-30 23:28:06 +02:00
util: SWAP macro implementation for older MSVC versions
Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Acked-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36682>
This commit is contained in:
parent
fe42a3d0eb
commit
3bd0badd3a
1 changed files with 13 additions and 0 deletions
|
|
@ -31,6 +31,7 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _GAMING_XBOX
|
||||
#define strdup _strdup
|
||||
|
|
@ -528,11 +529,23 @@ typedef int lock_cap_t;
|
|||
/*
|
||||
* SWAP - swap value of @a and @b
|
||||
*/
|
||||
#if !defined(_MSC_VER) || _MSC_VER >= 1939 /* MSVC 17.9 or later for __typeof__ */
|
||||
#define SWAP(a, b) \
|
||||
do { \
|
||||
__typeof__(a) __tmp = (a); \
|
||||
(a) = (b); \
|
||||
(b) = __tmp; \
|
||||
} while (0)
|
||||
#else
|
||||
#define SWAP(a, b) \
|
||||
do { \
|
||||
/* NOLINTBEGIN(bugprone-sizeof-expression) */ \
|
||||
char __tmp[sizeof(a) == sizeof(b) ? (ptrdiff_t)sizeof(a) : -1]; \
|
||||
memcpy(__tmp, &(b), sizeof(a)); \
|
||||
memcpy(&(b), &(a), sizeof(a)); \
|
||||
memcpy(&(a), __tmp, sizeof(a)); \
|
||||
/* NOLINTEND(bugprone-sizeof-expression) */ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#endif /* UTIL_MACROS_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue