зеркало из https://github.com/microsoft/git.git
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 <gitster@pobox.com> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
09884f352e
Коммит
1891846fa4
|
@ -1093,8 +1093,11 @@ int xstrncmpz(const char *s, const char *t, size_t len);
|
|||
#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))
|
||||
#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))
|
||||
|
||||
#define BARF_UNLESS_COPYABLE(dst, src) \
|
||||
BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src)))
|
||||
|
||||
#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \
|
||||
BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src))))
|
||||
BARF_UNLESS_COPYABLE((dst), (src)))
|
||||
static inline void copy_array(void *dst, const void *src, size_t n, size_t size)
|
||||
{
|
||||
if (n)
|
||||
|
@ -1102,7 +1105,7 @@ static inline void copy_array(void *dst, const void *src, size_t n, size_t size)
|
|||
}
|
||||
|
||||
#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \
|
||||
BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src))))
|
||||
BARF_UNLESS_COPYABLE((dst), (src)))
|
||||
static inline void move_array(void *dst, const void *src, size_t n, size_t size)
|
||||
{
|
||||
if (n)
|
||||
|
|
Загрузка…
Ссылка в новой задаче