From ab8632ae36d2e5faf524309696725b60ec18e588 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 25 Feb 2011 23:08:25 -0600 Subject: compat: provide a fallback va_copy definition va_copy is C99. We have avoided using va_copy many times in the past, which has led to a bunch of cut-and-paste. From everything I found searching the web, implementations have historically either provided va_copy or just let your code assume that simple assignment of worked. So my guess is that this will be sufficient, though we won't really know for sure until somebody reports a problem. Signed-off-by: Jeff King Improved-by: Erik Faye-Lund Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- git-compat-util.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index 9c23622ed5..00d41e4f0e 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -535,6 +535,10 @@ void git_qsort(void *base, size_t nmemb, size_t size, #define fstat_is_reliable() 1 #endif +#ifndef va_copy +#define va_copy(dst,src) (dst) = (src) +#endif + /* * Preserves errno, prints a message, but gives no warning for ENOENT. * Always returns the return value of unlink(2). -- cgit v1.2.1 From 26db0f2e3afc043e184a5e0ce5eb7c53aeb1f644 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 8 Mar 2011 02:33:44 -0600 Subject: 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 Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- git-compat-util.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'git-compat-util.h') diff --git a/git-compat-util.h b/git-compat-util.h index 00d41e4f0e..f4cb0a9b01 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -536,7 +536,16 @@ void git_qsort(void *base, size_t nmemb, size_t size, #endif #ifndef va_copy -#define va_copy(dst,src) (dst) = (src) +/* + * Since an obvious implementation of va_list would be to make it a + * pointer into the stack frame, a simple assignment will work on + * many systems. But let's try to be more portable. + */ +#ifdef __va_copy +#define va_copy(dst, src) __va_copy(dst, src) +#else +#define va_copy(dst, src) ((dst) = (src)) +#endif #endif /* -- cgit v1.2.1