Skip to content

Commit 1891846

Browse files
rscharfegitster
authored andcommitted
factor out BARF_UNLESS_COPYABLE
Move the common basic element type check of COPY_ARRAY and MOVE_ARRAY to a new macro. This reduces code duplication and simplifies adding more elaborate checks. Suggested-by: Junio C Hamano <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 09884f3 commit 1891846

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

git-compat-util.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,16 +1093,19 @@ int xstrncmpz(const char *s, const char *t, size_t len);
10931093
#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))
10941094
#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))
10951095

1096+
#define BARF_UNLESS_COPYABLE(dst, src) \
1097+
BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src)))
1098+
10961099
#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \
1097-
BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src))))
1100+
BARF_UNLESS_COPYABLE((dst), (src)))
10981101
static inline void copy_array(void *dst, const void *src, size_t n, size_t size)
10991102
{
11001103
if (n)
11011104
memcpy(dst, src, st_mult(size, n));
11021105
}
11031106

11041107
#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \
1105-
BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src))))
1108+
BARF_UNLESS_COPYABLE((dst), (src)))
11061109
static inline void move_array(void *dst, const void *src, size_t n, size_t size)
11071110
{
11081111
if (n)

0 commit comments

Comments
 (0)