git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* va_copy is not available on all systems.
@ 2007-08-20 13:16 Johannes Sixt
  2007-08-20 13:39 ` Michael Poole
  2007-08-20 19:15 ` Alex Riesen
  0 siblings, 2 replies; 6+ messages in thread
From: Johannes Sixt @ 2007-08-20 13:16 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Junio C Hamano, git

This is just too ugly to be included...

die_nicely() uses the variable argument list twice. The recent fix for
this in 7e5dcea8311 uses va_copy. However, on older systems this function
is not available. This fix assumes that those systems that do have
the function actually implement it as macro, and we use it to remove
the entire nicely() functionality.

Since va_copy() must be provided by the compiler, we don't have a
reasonable chance to provide a working definition in git_compat_util.h.
---
 fast-import.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 2d5224c..edc76a4 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -349,6 +349,7 @@ static unsigned int cmd_save = 100;
 static uintmax_t next_mark;
 static struct dbuf new_data;
 
+#ifdef va_copy
 static void write_branch_report(FILE *rpt, struct branch *b)
 {
 	fprintf(rpt, "%s:\n", b->name);
@@ -456,6 +457,7 @@ static NORETURN void die_nicely(const char *err, va_list params)
 	va_end(x_params);
 	exit(128);
 }
+#endif
 
 static void alloc_objects(unsigned int cnt)
 {
@@ -2381,7 +2383,9 @@ int main(int argc, const char **argv)
 
 	prepare_packed_git();
 	start_packfile();
+#ifdef va_copy
 	set_die_routine(die_nicely);
+#endif
 	for (;;) {
 		read_next_command();
 		if (command_buf.eof)
-- 
1.5.3.rc5.15.g8ddb

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: va_copy is not available on all systems.
  2007-08-20 13:16 va_copy is not available on all systems Johannes Sixt
@ 2007-08-20 13:39 ` Michael Poole
  2007-08-20 19:15 ` Alex Riesen
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Poole @ 2007-08-20 13:39 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Shawn O. Pearce, Junio C Hamano, git

Johannes Sixt writes:

> This is just too ugly to be included...
>
> die_nicely() uses the variable argument list twice. The recent fix for
> this in 7e5dcea8311 uses va_copy. However, on older systems this function
> is not available. This fix assumes that those systems that do have
> the function actually implement it as macro, and we use it to remove
> the entire nicely() functionality.
>
> Since va_copy() must be provided by the compiler, we don't have a
> reasonable chance to provide a working definition in git_compat_util.h.

Some older (pre-C99) versions of gcc name it __va_copy() instead.  Is
there any guarantee that va_copy() will be a macro on systems that
provide it?  If neither va_copy() nor __va_copy() are available,
memcpy(&(DEST), &(SRC), sizeof(DEST)) should work for any va_list
type.  It's what I use on one project:

#ifdef HAVE_VA_COPY
#define VA_COPY(DEST, SRC) va_copy(DEST, SRC)
#elif HAVE___VA_COPY
#define VA_COPY(DEST, SRC) __va_copy(DEST, SRC)
#else
#define VA_COPY(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(DEST))
#endif

with appropriate autoconf tests, basically two copies of this:

dnl How to copy one va_list to another?
AC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy, [AC_LINK_IFELSE(
  [AC_LANG_PROGRAM([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);])],
  [ac_cv_c_va_copy="yes"],
  [ac_cv_c_va_copy="no"]
)])
if test "$ac_cv_c_va_copy" = "yes" ; then
  AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])
fi

I'm not sure how to translate the tests to git's coding style most
easily.

Michael Poole

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: va_copy is not available on all systems.
  2007-08-20 13:16 va_copy is not available on all systems Johannes Sixt
  2007-08-20 13:39 ` Michael Poole
@ 2007-08-20 19:15 ` Alex Riesen
  2007-08-21  3:38   ` Shawn O. Pearce
  1 sibling, 1 reply; 6+ messages in thread
From: Alex Riesen @ 2007-08-20 19:15 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Shawn O. Pearce, Junio C Hamano, git

Johannes Sixt, Mon, Aug 20, 2007 15:16:56 +0200:
> Since va_copy() must be provided by the compiler, we don't have a
> reasonable chance to provide a working definition in git_compat_util.h.

Maybe we don't have to:

Subject: [PATCH] Avoid using va_copy in fast-import: it seem to be unportable

diff --git a/fast-import.c b/fast-import.c
index 2d5224c..04948e9 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -375,7 +375,7 @@ static void write_branch_report(FILE *rpt, struct branch *b)
 	fputc('\n', rpt);
 }
 
-static void write_crash_report(const char *err, va_list params)
+static void write_crash_report(const char *err)
 {
 	char *loc = git_path("fast_import_crash_%d", getpid());
 	FILE *rpt = fopen(loc, "w");
@@ -396,9 +396,7 @@ static void write_crash_report(const char *err, va_list params)
 	fprintf(rpt, "    at %s\n", show_date(time(NULL), 0, DATE_LOCAL));
 	fputc('\n', rpt);
 
-	fputs("fatal: ", rpt);
-	vfprintf(rpt, err, params);
-	fputc('\n', rpt);
+	fprintf(rpt, "fatal: %s\n", err);
 
 	fputc('\n', rpt);
 	fputs("Most Recent Commands Before Crash\n", rpt);
@@ -442,18 +440,15 @@ static void write_crash_report(const char *err, va_list params)
 static NORETURN void die_nicely(const char *err, va_list params)
 {
 	static int zombie;
-	va_list x_params;
+	char message[BUFSIZ];
 
-	va_copy(x_params, params);
-	fputs("fatal: ", stderr);
-	vfprintf(stderr, err, params);
-	fputc('\n', stderr);
+	vsnprintf(message, sizeof(message), err, params);
+	fprintf(stderr, "fatal: %s\n", message);
 
 	if (!zombie) {
 		zombie = 1;
-		write_crash_report(err, x_params);
+		write_crash_report(message);
 	}
-	va_end(x_params);
 	exit(128);
 }
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: va_copy is not available on all systems.
  2007-08-20 19:15 ` Alex Riesen
@ 2007-08-21  3:38   ` Shawn O. Pearce
  2007-08-21  4:53     ` Junio C Hamano
  2007-08-21 18:37     ` Alex Riesen
  0 siblings, 2 replies; 6+ messages in thread
From: Shawn O. Pearce @ 2007-08-21  3:38 UTC (permalink / raw)
  To: Alex Riesen; +Cc: Johannes Sixt, Junio C Hamano, git

Alex Riesen <raa.lkml@gmail.com> wrote:
> Johannes Sixt, Mon, Aug 20, 2007 15:16:56 +0200:
> > Since va_copy() must be provided by the compiler, we don't have a
> > reasonable chance to provide a working definition in git_compat_util.h.
> 
> Maybe we don't have to:
> 
> Subject: [PATCH] Avoid using va_copy in fast-import: it seem to be unportable

Thanks Alex.  This feels more like the right solution to the problem.
I made a few minor edits, any comment?
 
-->8--
From: Alex Riesen <raa.lkml@gmail.com>
Subject: [PATCH] Avoid using va_copy in fast-import: it seems to be unportable.

[sp: minor change to use fputs, thus reducing the patch size]

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 fast-import.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/fast-import.c b/fast-import.c
index 2d5224c..078079d 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -375,7 +375,7 @@ static void write_branch_report(FILE *rpt, struct branch *b)
 	fputc('\n', rpt);
 }
 
-static void write_crash_report(const char *err, va_list params)
+static void write_crash_report(const char *err)
 {
 	char *loc = git_path("fast_import_crash_%d", getpid());
 	FILE *rpt = fopen(loc, "w");
@@ -397,7 +397,7 @@ static void write_crash_report(const char *err, va_list params)
 	fputc('\n', rpt);
 
 	fputs("fatal: ", rpt);
-	vfprintf(rpt, err, params);
+	fputs(err, rpt);
 	fputc('\n', rpt);
 
 	fputc('\n', rpt);
@@ -442,18 +442,17 @@ static void write_crash_report(const char *err, va_list params)
 static NORETURN void die_nicely(const char *err, va_list params)
 {
 	static int zombie;
-	va_list x_params;
+	char message[2 * PATH_MAX];
 
-	va_copy(x_params, params);
+	vsnprintf(message, sizeof(message), err, params);
 	fputs("fatal: ", stderr);
-	vfprintf(stderr, err, params);
+	fputs(message, stderr);
 	fputc('\n', stderr);
 
 	if (!zombie) {
 		zombie = 1;
-		write_crash_report(err, x_params);
+		write_crash_report(message);
 	}
-	va_end(x_params);
 	exit(128);
 }
 
-- 
1.5.3.rc5.40.g2f82

-- 
Shawn.

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: va_copy is not available on all systems.
  2007-08-21  3:38   ` Shawn O. Pearce
@ 2007-08-21  4:53     ` Junio C Hamano
  2007-08-21 18:37     ` Alex Riesen
  1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2007-08-21  4:53 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Alex Riesen, Johannes Sixt, git

Thanks, I think the patch makes sense.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: va_copy is not available on all systems.
  2007-08-21  3:38   ` Shawn O. Pearce
  2007-08-21  4:53     ` Junio C Hamano
@ 2007-08-21 18:37     ` Alex Riesen
  1 sibling, 0 replies; 6+ messages in thread
From: Alex Riesen @ 2007-08-21 18:37 UTC (permalink / raw)
  To: Shawn O. Pearce; +Cc: Johannes Sixt, Junio C Hamano, git

Shawn O. Pearce, Tue, Aug 21, 2007 05:38:14 +0200:
> Alex Riesen <raa.lkml@gmail.com> wrote:
> > Johannes Sixt, Mon, Aug 20, 2007 15:16:56 +0200:
> > > Since va_copy() must be provided by the compiler, we don't have a
> > > reasonable chance to provide a working definition in git_compat_util.h.
> > 
> > Maybe we don't have to:
> > 
> > Subject: [PATCH] Avoid using va_copy in fast-import: it seem to be unportable
> 
> Thanks Alex.  This feels more like the right solution to the problem.
> I made a few minor edits, any comment?

Like editing in my sign-off which I didn't provide :)

I actually think fprintf was less object code, but thanks to admins(*) of
my employer, I am too late anyway.

* The admins blocked gmail because of it being virus infected. Ha!
  Of course it is, it is a mailbox, for gods sake!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-08-21 18:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-20 13:16 va_copy is not available on all systems Johannes Sixt
2007-08-20 13:39 ` Michael Poole
2007-08-20 19:15 ` Alex Riesen
2007-08-21  3:38   ` Shawn O. Pearce
2007-08-21  4:53     ` Junio C Hamano
2007-08-21 18:37     ` Alex Riesen

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).