[PATCH jk/strbuf-vaddf] compat: fall back on __va_copy if available

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <gitster@xxxxxxxxx>
Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
Erik Faye-Lund wrote:

> Wouldn't it be even more portable to fall back on use __va_copy (if
> present), as suggested by Junio in
> <7vbpip86q5.fsf@xxxxxxxxxxxxxxxxxxxxxxxx>?

Yes, it seems so.

 git-compat-util.h |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index 00d41e4..f4cb0a9 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
 
 /*
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]