{"thread":{"id":"9589","subject":"va_copy is not available on all systems.","startedAt":"2007-08-20T13:16:56Z","lastAt":"2007-08-21T18:37:09Z","messageCount":6,"participants":["Johannes Sixt","Michael Poole","Alex Riesen","Shawn O. Pearce","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"51086","messageId":"46C99448.2AB33DFF@eudaptics.com","threadId":"9589","inReplyTo":null,"subject":"va_copy is not available on all systems.","fromName":"Johannes Sixt","fromEmail":"j.sixt@eudaptics.com","sentAt":"2007-08-20T13:16:56Z","receivedAt":"2007-08-20T13:16:56Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"This is just too ugly to be included...\n\ndie_nicely() uses the variable argument list twice. The recent fix for\nthis in 7e5dcea8311 uses va_copy. However, on older systems this function\nis not available. This fix assumes that those systems that do have\nthe function actually implement it as macro, and we use it to remove\nthe entire nicely() functionality.\n\nSince va_copy() must be provided by the compiler, we don't have a\nreasonable chance to provide a working definition in git_compat_util.h.\n---\n fast-import.c |    4 ++++\n 1 files changed, 4 insertions(+), 0 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 2d5224c..edc76a4 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -349,6 +349,7 @@ static unsigned int cmd_save = 100;\n static uintmax_t next_mark;\n static struct dbuf new_data;\n \n+#ifdef va_copy\n static void write_branch_report(FILE *rpt, struct branch *b)\n {\n \tfprintf(rpt, \"%s:\\n\", b->name);\n@@ -456,6 +457,7 @@ static NORETURN void die_nicely(const char *err, va_list params)\n \tva_end(x_params);\n \texit(128);\n }\n+#endif\n \n static void alloc_objects(unsigned int cnt)\n {\n@@ -2381,7 +2383,9 @@ int main(int argc, const char **argv)\n \n \tprepare_packed_git();\n \tstart_packfile();\n+#ifdef va_copy\n \tset_die_routine(die_nicely);\n+#endif\n \tfor (;;) {\n \t\tread_next_command();\n \t\tif (command_buf.eof)\n-- \n1.5.3.rc5.15.g8ddb\n"},{"id":"51090","messageId":"87y7g6wcix.fsf@graviton.dyn.troilus.org","threadId":"9589","inReplyTo":"46C99448.2AB33DFF@eudaptics.com","subject":"Re: va_copy is not available on all systems.","fromName":"Michael Poole","fromEmail":"mdpoole@troilus.org","sentAt":"2007-08-20T13:39:34Z","receivedAt":"2007-08-20T13:39:34Z","isPatch":false,"sender":{"key":"mdpoole@troilus.org","avatar":null},"body":"Johannes Sixt writes:\n\n> This is just too ugly to be included...\n>\n> die_nicely() uses the variable argument list twice. The recent fix for\n> this in 7e5dcea8311 uses va_copy. However, on older systems this function\n> is not available. This fix assumes that those systems that do have\n> the function actually implement it as macro, and we use it to remove\n> the entire nicely() functionality.\n>\n> Since va_copy() must be provided by the compiler, we don't have a\n> reasonable chance to provide a working definition in git_compat_util.h.\n\nSome older (pre-C99) versions of gcc name it __va_copy() instead.  Is\nthere any guarantee that va_copy() will be a macro on systems that\nprovide it?  If neither va_copy() nor __va_copy() are available,\nmemcpy(&(DEST), &(SRC), sizeof(DEST)) should work for any va_list\ntype.  It's what I use on one project:\n\n#ifdef HAVE_VA_COPY\n#define VA_COPY(DEST, SRC) va_copy(DEST, SRC)\n#elif HAVE___VA_COPY\n#define VA_COPY(DEST, SRC) __va_copy(DEST, SRC)\n#else\n#define VA_COPY(DEST, SRC) memcpy(&(DEST), &(SRC), sizeof(DEST))\n#endif\n\nwith appropriate autoconf tests, basically two copies of this:\n\ndnl How to copy one va_list to another?\nAC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy, [AC_LINK_IFELSE(\n  [AC_LANG_PROGRAM([#include <stdarg.h>], [va_list ap1, ap2; va_copy(ap1, ap2);])],\n  [ac_cv_c_va_copy=\"yes\"],\n  [ac_cv_c_va_copy=\"no\"]\n)])\nif test \"$ac_cv_c_va_copy\" = \"yes\" ; then\n  AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])\nfi\n\nI'm not sure how to translate the tests to git's coding style most\neasily.\n\nMichael Poole\n"},{"id":"51111","messageId":"20070820191509.GB5544@steel.home","threadId":"9589","inReplyTo":"46C99448.2AB33DFF@eudaptics.com","subject":"Re: va_copy is not available on all systems.","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-08-20T19:15:09Z","receivedAt":"2007-08-20T19:15:09Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Johannes Sixt, Mon, Aug 20, 2007 15:16:56 +0200:\n> Since va_copy() must be provided by the compiler, we don't have a\n> reasonable chance to provide a working definition in git_compat_util.h.\n\nMaybe we don't have to:\n\nSubject: [PATCH] Avoid using va_copy in fast-import: it seem to be unportable\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 2d5224c..04948e9 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -375,7 +375,7 @@ static void write_branch_report(FILE *rpt, struct branch *b)\n \tfputc('\\n', rpt);\n }\n \n-static void write_crash_report(const char *err, va_list params)\n+static void write_crash_report(const char *err)\n {\n \tchar *loc = git_path(\"fast_import_crash_%d\", getpid());\n \tFILE *rpt = fopen(loc, \"w\");\n@@ -396,9 +396,7 @@ static void write_crash_report(const char *err, va_list params)\n \tfprintf(rpt, \"    at %s\\n\", show_date(time(NULL), 0, DATE_LOCAL));\n \tfputc('\\n', rpt);\n \n-\tfputs(\"fatal: \", rpt);\n-\tvfprintf(rpt, err, params);\n-\tfputc('\\n', rpt);\n+\tfprintf(rpt, \"fatal: %s\\n\", err);\n \n \tfputc('\\n', rpt);\n \tfputs(\"Most Recent Commands Before Crash\\n\", rpt);\n@@ -442,18 +440,15 @@ static void write_crash_report(const char *err, va_list params)\n static NORETURN void die_nicely(const char *err, va_list params)\n {\n \tstatic int zombie;\n-\tva_list x_params;\n+\tchar message[BUFSIZ];\n \n-\tva_copy(x_params, params);\n-\tfputs(\"fatal: \", stderr);\n-\tvfprintf(stderr, err, params);\n-\tfputc('\\n', stderr);\n+\tvsnprintf(message, sizeof(message), err, params);\n+\tfprintf(stderr, \"fatal: %s\\n\", message);\n \n \tif (!zombie) {\n \t\tzombie = 1;\n-\t\twrite_crash_report(err, x_params);\n+\t\twrite_crash_report(message);\n \t}\n-\tva_end(x_params);\n \texit(128);\n }\n \n"},{"id":"51146","messageId":"20070821033813.GF27913@spearce.org","threadId":"9589","inReplyTo":"20070820191509.GB5544@steel.home","subject":"Re: va_copy is not available on all systems.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-08-21T03:38:14Z","receivedAt":"2007-08-21T03:38:14Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Alex Riesen <raa.lkml@gmail.com> wrote:\n> Johannes Sixt, Mon, Aug 20, 2007 15:16:56 +0200:\n> > Since va_copy() must be provided by the compiler, we don't have a\n> > reasonable chance to provide a working definition in git_compat_util.h.\n> \n> Maybe we don't have to:\n> \n> Subject: [PATCH] Avoid using va_copy in fast-import: it seem to be unportable\n\nThanks Alex.  This feels more like the right solution to the problem.\nI made a few minor edits, any comment?\n \n-->8--\nFrom: Alex Riesen <raa.lkml@gmail.com>\nSubject: [PATCH] Avoid using va_copy in fast-import: it seems to be unportable.\n\n[sp: minor change to use fputs, thus reducing the patch size]\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n fast-import.c |   13 ++++++-------\n 1 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex 2d5224c..078079d 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -375,7 +375,7 @@ static void write_branch_report(FILE *rpt, struct branch *b)\n \tfputc('\\n', rpt);\n }\n \n-static void write_crash_report(const char *err, va_list params)\n+static void write_crash_report(const char *err)\n {\n \tchar *loc = git_path(\"fast_import_crash_%d\", getpid());\n \tFILE *rpt = fopen(loc, \"w\");\n@@ -397,7 +397,7 @@ static void write_crash_report(const char *err, va_list params)\n \tfputc('\\n', rpt);\n \n \tfputs(\"fatal: \", rpt);\n-\tvfprintf(rpt, err, params);\n+\tfputs(err, rpt);\n \tfputc('\\n', rpt);\n \n \tfputc('\\n', rpt);\n@@ -442,18 +442,17 @@ static void write_crash_report(const char *err, va_list params)\n static NORETURN void die_nicely(const char *err, va_list params)\n {\n \tstatic int zombie;\n-\tva_list x_params;\n+\tchar message[2 * PATH_MAX];\n \n-\tva_copy(x_params, params);\n+\tvsnprintf(message, sizeof(message), err, params);\n \tfputs(\"fatal: \", stderr);\n-\tvfprintf(stderr, err, params);\n+\tfputs(message, stderr);\n \tfputc('\\n', stderr);\n \n \tif (!zombie) {\n \t\tzombie = 1;\n-\t\twrite_crash_report(err, x_params);\n+\t\twrite_crash_report(message);\n \t}\n-\tva_end(x_params);\n \texit(128);\n }\n \n-- \n1.5.3.rc5.40.g2f82\n\n-- \nShawn.\n"},{"id":"51147","messageId":"7vabslpjyl.fsf@gitster.siamese.dyndns.org","threadId":"9589","inReplyTo":"20070821033813.GF27913@spearce.org","subject":"Re: va_copy is not available on all systems.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-21T04:53:06Z","receivedAt":"2007-08-21T04:53:06Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks, I think the patch makes sense.\n"},{"id":"51192","messageId":"20070821183709.GA22102@steel.home","threadId":"9589","inReplyTo":"20070821033813.GF27913@spearce.org","subject":"Re: va_copy is not available on all systems.","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-08-21T18:37:09Z","receivedAt":"2007-08-21T18:37:09Z","isPatch":false,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Shawn O. Pearce, Tue, Aug 21, 2007 05:38:14 +0200:\n> Alex Riesen <raa.lkml@gmail.com> wrote:\n> > Johannes Sixt, Mon, Aug 20, 2007 15:16:56 +0200:\n> > > Since va_copy() must be provided by the compiler, we don't have a\n> > > reasonable chance to provide a working definition in git_compat_util.h.\n> > \n> > Maybe we don't have to:\n> > \n> > Subject: [PATCH] Avoid using va_copy in fast-import: it seem to be unportable\n> \n> Thanks Alex.  This feels more like the right solution to the problem.\n> I made a few minor edits, any comment?\n\nLike editing in my sign-off which I didn't provide :)\n\nI actually think fprintf was less object code, but thanks to admins(*) of\nmy employer, I am too late anyway.\n\n* The admins blocked gmail because of it being virus infected. Ha!\n  Of course it is, it is a mailbox, for gods sake!\n"}]}