Skip to content

Commit 26db0f2

Browse files
jrngitster
authored andcommitted
compat: fall back on __va_copy if available
Since an obvious implementation of va_list is to make it a pointer into the stack frame, implementing va_copy as "dst = src" will work on many systems. Platforms that use something different (e.g., a size-1 array of structs, to be assigned with *(dst) = *(src)) will need some other compatibility macro, though. Luckily, as the glibc manual hints, such systems tend to provide the __va_copy macro (introduced in GCC in March, 1997). By using that if it is available, we can cover our bases pretty well. Discovered by building with CC="gcc -std=c89" on an amd64 machine: $ make CC=c89 strbuf.o [...] strbuf.c: In function 'strbuf_vaddf': strbuf.c:211:2: error: incompatible types when assigning to type 'va_list' from type 'struct __va_list_tag *' make: *** [strbuf.o] Error 1 Explained-by: Junio C Hamano <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ebeb609 commit 26db0f2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

git-compat-util.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,16 @@ void git_qsort(void *base, size_t nmemb, size_t size,
536536
#endif
537537

538538
#ifndef va_copy
539-
#define va_copy(dst,src) (dst) = (src)
539+
/*
540+
* Since an obvious implementation of va_list would be to make it a
541+
* pointer into the stack frame, a simple assignment will work on
542+
* many systems. But let's try to be more portable.
543+
*/
544+
#ifdef __va_copy
545+
#define va_copy(dst, src) __va_copy(dst, src)
546+
#else
547+
#define va_copy(dst, src) ((dst) = (src))
548+
#endif
540549
#endif
541550

542551
/*

0 commit comments

Comments
 (0)