git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Erik Faye-Lund <kusmabite@gmail.com>
Cc: Jeff King <peff@peff.net>,
	Nguyen Thai Ngoc Duy <pclouds@gmail.com>,
	git@vger.kernel.org
Subject: [PATCH jk/strbuf-vaddf] compat: fall back on __va_copy if available
Date: Tue, 8 Mar 2011 02:33:44 -0600	[thread overview]
Message-ID: <20110308083344.GD26516@elie> (raw)
In-Reply-To: <AANLkTin7NBx5NVRkHpgymcZfnaZaJehMMpPv=zD+cKtV@mail.gmail.com>

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@pobox.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
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@alter.siamese.dyndns.org>?

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

  reply	other threads:[~2011-03-08  8:33 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-24 14:23 [PATCH/RFC 0/8] refactor trace code Jeff King
2011-02-24 14:26 ` [RFC/PATCH 1/8] compat: provide a fallback va_copy definition Jeff King
2011-02-24 15:57   ` Erik Faye-Lund
2011-03-08  8:33     ` Jonathan Nieder [this message]
2011-03-08 20:09       ` [PATCH jk/strbuf-vaddf] compat: fall back on __va_copy if available Junio C Hamano
2011-03-08 20:59         ` Jonathan Nieder
2011-02-24 20:33   ` [RFC/PATCH 1/8] compat: provide a fallback va_copy definition Jonathan Nieder
2011-02-24 14:27 ` [PATCH 2/8] strbuf: add strbuf_addv Jeff King
2011-02-24 15:05   ` Christian Couder
2011-02-24 15:07     ` Jeff King
2011-02-24 20:51   ` Jonathan Nieder
2011-02-24 14:28 ` [PATCH 3/8] trace: add trace_vprintf Jeff King
2011-02-24 21:08   ` Jonathan Nieder
2011-02-24 14:28 ` [PATCH 4/8] trace: refactor to support multiple env variables Jeff King
2011-02-24 18:25   ` Junio C Hamano
2011-02-24 19:02     ` Jeff King
2011-02-24 19:44       ` Junio C Hamano
2011-02-24 19:48         ` Jeff King
2011-02-24 20:50           ` Junio C Hamano
2011-02-24 21:23   ` Jonathan Nieder
2011-02-24 14:28 ` [PATCH 5/8] trace: factor out "do we want to trace" logic Jeff King
2011-02-24 15:07   ` Christian Couder
2011-02-24 14:29 ` [PATCH 6/8] trace: add trace_strbuf Jeff King
2011-02-24 14:30 ` [PATCH 7/8] add packet tracing debug code Jeff King
2011-02-24 21:44   ` Jonathan Nieder
2011-02-24 14:30 ` [PATCH 8/8] trace: give repo_setup trace its own key Jeff King
2011-02-24 15:59   ` Andreas Ericsson
2011-02-24 16:05     ` Jeff King
2011-02-24 20:01       ` Christian Couder
2011-02-24 21:49   ` Jonathan Nieder
2011-02-25  6:38     ` Nguyen Thai Ngoc Duy
2011-02-26  8:34   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110308083344.GD26516@elie \
    --to=jrnieder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kusmabite@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).