backend-drm: simplify compile time array copy

In drm_fb_get_from_dmabuf() we have some compile time array copies, and
multiple static_assert() calls are needed (for safety). This makes the
code unpleasant to read.

Add ARRAY_COPY macro, to simplify the code.

Signed-off-by: Leandro Ribeiro <leandro.ribeiro@collabora.com>
This commit is contained in:
Leandro Ribeiro
2021-04-27 19:00:34 -03:00
parent bdb37b30b3
commit 3193ab5807
2 changed files with 24 additions and 36 deletions
+19
View File
@@ -41,6 +41,25 @@ extern "C" {
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
#endif
#define STRING(s) #s
/**
* Compile-time copy of hardcoded arrays.
*
* @param dst the array to copy to.
* @param src the source array.
*/
#ifndef ARRAY_COPY
#define ARRAY_COPY(dst, src) \
do { \
static_assert(ARRAY_LENGTH(src) == ARRAY_LENGTH(dst), \
"src and dst sizes must match"); \
static_assert(sizeof(src) == sizeof(dst), \
"src and dst sizes must match"); \
memcpy((src), (dst), sizeof(src)); \
} while (0)
#endif
/**
* Returns the smaller of two values.
*