{"thread":{"id":"43483","subject":"Re: [PATCH 3/3] Remove unsupported C99 style struct initializers in git-archive.","startedAt":"2006-11-05T05:37:23Z","lastAt":"2006-11-05T07:36:34Z","messageCount":3,"participants":["Junio C Hamano","Shawn O. Pearce","Shawn Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"296056","messageId":"20061105053723.GC4193@spearce.org","threadId":"43483","inReplyTo":null,"subject":"[PATCH 3/3] Remove unsupported C99 style struct initializers in git-archive.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-11-05T05:37:23Z","receivedAt":"2006-11-05T05:37:23Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"At least one older version of the Solaris C compiler doesn't support\nthe newer C99 style struct initializers.  To allow Git to compile\non those systems use an archive description struct which is easier\nto initialize without the C99 struct initializer syntax.\n\nAlso since the archives array is not used by anyone other than\narchive.c we can make it static.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n archive.h         |    2 --\n builtin-archive.c |   23 ++++++++++++-----------\n 2 files changed, 12 insertions(+), 13 deletions(-)\n\ndiff --git a/archive.h b/archive.h\nindex 16dcdb8..6838dc7 100644\n--- a/archive.h\n+++ b/archive.h\n@@ -25,8 +25,6 @@ struct archiver {\n \tparse_extra_args_fn_t parse_extra;\n };\n \n-extern struct archiver archivers[];\n-\n extern int parse_archive_args(int argc,\n \t\t\t      const char **argv,\n \t\t\t      struct archiver *ar);\ndiff --git a/builtin-archive.c b/builtin-archive.c\nindex 9177379..2df1a84 100644\n--- a/builtin-archive.c\n+++ b/builtin-archive.c\n@@ -15,16 +15,14 @@\n static const char archive_usage[] = \\\n \"git-archive --format=<fmt> [--prefix=<prefix>/] [--verbose] [<extra>] <tree-ish> [path...]\";\n \n-struct archiver archivers[] = {\n-\t{\n-\t\t.name\t\t= \"tar\",\n-\t\t.write_archive\t= write_tar_archive,\n-\t},\n-\t{\n-\t\t.name\t\t= \"zip\",\n-\t\t.write_archive\t= write_zip_archive,\n-\t\t.parse_extra\t= parse_extra_zip_args,\n-\t},\n+static struct archiver_desc\n+{\n+\tconst char *name;\n+\twrite_archive_fn_t write_archive;\n+\tparse_extra_args_fn_t parse_extra;\n+} archivers[] = {\n+\t{ \"tar\", write_tar_archive, NULL },\n+\t{ \"zip\", write_zip_archive, parse_extra_zip_args },\n };\n \n static int run_remote_archiver(const char *remote, int argc,\n@@ -88,7 +86,10 @@ static int init_archiver(const char *nam\n \n \tfor (i = 0; i < ARRAY_SIZE(archivers); i++) {\n \t\tif (!strcmp(name, archivers[i].name)) {\n-\t\t\tmemcpy(ar, &archivers[i], sizeof(struct archiver));\n+\t\t\tmemset(ar, 0, sizeof(*ar));\n+\t\t\tar->name = archivers[i].name;\n+\t\t\tar->write_archive = archivers[i].write_archive;\n+\t\t\tar->parse_extra = archivers[i].parse_extra;\n \t\t\trv = 0;\n \t\t\tbreak;\n \t\t}\n-- \n"},{"id":"295049","messageId":"7vd582uz5b.fsf@assigned-by-dhcp.cox.net","threadId":"43483","inReplyTo":"20061105053723.GC4193@spearce.org","subject":"Re: [PATCH 3/3] Remove unsupported C99 style struct initializers in git-archive.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-05T07:32:32Z","receivedAt":"2006-11-05T07:32:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Shawn O. Pearce\" <spearce@spearce.org> writes:\n\n> +static struct archiver_desc\n> +{\n> +\tconst char *name;\n> +\twrite_archive_fn_t write_archive;\n> +\tparse_extra_args_fn_t parse_extra;\n> +} archivers[] = {\n> +\t{ \"tar\", write_tar_archive, NULL },\n> +\t{ \"zip\", write_zip_archive, parse_extra_zip_args },\n>  };\n\nIf this were a struct with bazillions of fields I might have had\ntrouble swallowing the change, but this is so small that it is\nno brainer.\n\nI think this actually is an improvement.\n\n>  static int run_remote_archiver(const char *remote, int argc,\n> @@ -88,7 +86,10 @@ static int init_archiver(const char *nam\n>  \n>  \tfor (i = 0; i < ARRAY_SIZE(archivers); i++) {\n>  \t\tif (!strcmp(name, archivers[i].name)) {\n> -\t\t\tmemcpy(ar, &archivers[i], sizeof(struct archiver));\n> +\t\t\tmemset(ar, 0, sizeof(*ar));\n> +\t\t\tar->name = archivers[i].name;\n> +\t\t\tar->write_archive = archivers[i].write_archive;\n> +\t\t\tar->parse_extra = archivers[i].parse_extra;\n\nBut is this change really needed?  Shouldn't a structure\nassignment just work?\n"},{"id":"298087","messageId":"20061105073634.GA4616@spearce.org","threadId":"43483","inReplyTo":"7vd582uz5b.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 3/3] Remove unsupported C99 style struct initializers in git-archive.","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-11-05T07:36:34Z","receivedAt":"2006-11-05T07:36:34Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> \"Shawn O. Pearce\" <spearce@spearce.org> writes:\n> \n> > +static struct archiver_desc\n> > +{\n> > +\tconst char *name;\n> > +\twrite_archive_fn_t write_archive;\n> > +\tparse_extra_args_fn_t parse_extra;\n> > +} archivers[] = {\n> > +\t{ \"tar\", write_tar_archive, NULL },\n> > +\t{ \"zip\", write_zip_archive, parse_extra_zip_args },\n> >  };\n> \n> If this were a struct with bazillions of fields I might have had\n> trouble swallowing the change, but this is so small that it is\n> no brainer.\n\nRight; if it was larger I would have been in trouble.  :-)\n\n> I think this actually is an improvement.\n> \n> >  static int run_remote_archiver(const char *remote, int argc,\n> > @@ -88,7 +86,10 @@ static int init_archiver(const char *nam\n> >  \n> >  \tfor (i = 0; i < ARRAY_SIZE(archivers); i++) {\n> >  \t\tif (!strcmp(name, archivers[i].name)) {\n> > -\t\t\tmemcpy(ar, &archivers[i], sizeof(struct archiver));\n> > +\t\t\tmemset(ar, 0, sizeof(*ar));\n> > +\t\t\tar->name = archivers[i].name;\n> > +\t\t\tar->write_archive = archivers[i].write_archive;\n> > +\t\t\tar->parse_extra = archivers[i].parse_extra;\n> \n> But is this change really needed?  Shouldn't a structure\n> assignment just work?\n\nNo, they are different structs...\n\nWhich I did to reduce the size of the initializer (see above)\nso that it was a no brainer for you to swallow.  :-)\n\n-- \n"}]}