@matheusbsbs / matheus-bagliano / commits / 66dbfd55e3
Fork 0

Rewrite dynamic structure initializations to runtime assignment

Unfortunately, there are still plenty of production systems with vendor compilers that choke unless all compound declarations can be determined statically at compile time, for example hpux10.20 (I can provide a comprehensive list of our supported platforms that exhibit this problem if necessary). This patch simply breaks apart any compound declarations with dynamic initialisation expressions, and moves the initialisation until after the last declaration in the same block, in all the places necessary to have the offending compilers accept the code. Signed-off-by: Gary V. Vaughan <gary@thewrittenword.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Gary V. Vaughan committed May 14, 2010 at 09:31 UTC 66dbfd55e38128db02eb340fcd89f54b734d4c6e
14 files changed +68 -46
builtin/add.c
+3 -1
@@ -261,12 +261,14 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
261 {
262 char *file = xstrdup(git_path("ADD_EDIT.patch"));
263 const char *apply_argv[] = { "apply", "--recount", "--cached",
264 - file, NULL };
264 + NULL, NULL };
265 struct child_process child;
266 struct rev_info rev;
267 int out;
268 struct stat st;
269
270 + apply_argv[3] = file;
271 +
272 git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
273
274 if (read_cache() < 0)
builtin/blame.c
+6 -4
@@ -733,10 +733,11 @@ static int pass_blame_to_parent(struct scoreboard *sb,
733 {
734 int last_in_target;
735 mmfile_t file_p, file_o;
736 - struct blame_chunk_cb_data d = { sb, target, parent, 0, 0 };
736 + struct blame_chunk_cb_data d;
737 xpparam_t xpp;
738 xdemitconf_t xecfg;
739 -
739 + memset(&d, 0, sizeof(d));
740 + d.sb = sb; d.target = target; d.parent = parent;
741 last_in_target = find_last_in_target(sb, target);
742 if (last_in_target < 0)
743 return 1; /* nothing remains for this target */
@@ -875,10 +876,11 @@ static void find_copy_in_blob(struct scoreboard *sb,
876 const char *cp;
877 int cnt;
878 mmfile_t file_o;
878 - struct handle_split_cb_data d = { sb, ent, parent, split, 0, 0 };
879 + struct handle_split_cb_data d;
880 xpparam_t xpp;
881 xdemitconf_t xecfg;
881 -
882 + memset(&d, 0, sizeof(d));
883 + d.sb = sb; d.ent = ent; d.parent = parent; d.split = split;
884 /*
885 * Prepare mmfile that contains only the lines in ent.
886 */
builtin/cat-file.c
+3 -1
@@ -118,7 +118,9 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
118
119 /* custom pretty-print here */
120 if (type == OBJ_TREE) {
121 - const char *ls_args[3] = {"ls-tree", obj_name, NULL};
121 + const char *ls_args[3] = { NULL };
122 + ls_args[0] = "ls-tree";
123 + ls_args[1] = obj_name;
124 return cmd_ls_tree(2, ls_args, NULL);
125 }
126
builtin/checkout.c
+2 -1
@@ -609,7 +609,8 @@ static int check_tracking_name(const char *refname, const unsigned char *sha1,
609
610 static const char *unique_tracking_name(const char *name)
611 {
612 - struct tracking_name_data cb_data = { name, NULL, 1 };
612 + struct tracking_name_data cb_data = { NULL, NULL, 1 };
613 + cb_data.name = name;
614 for_each_ref(check_tracking_name, &cb_data);
615 if (cb_data.unique)
616 return cb_data.remote;
builtin/commit.c
+2 -1
@@ -717,7 +717,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
717
718 if (use_editor) {
719 char index[PATH_MAX];
720 - const char *env[2] = { index, NULL };
720 + const char *env[2] = { NULL };
721 + env[0] = index;
722 snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
723 if (launch_editor(git_path(commit_editmsg), NULL, env)) {
724 fprintf(stderr,
builtin/fetch.c
+4 -2
@@ -574,9 +574,10 @@ static void find_non_local_tags(struct transport *transport,
574 {
575 struct string_list existing_refs = { NULL, 0, 0, 0 };
576 struct string_list remote_refs = { NULL, 0, 0, 0 };
577 - struct tag_data data = {head, tail};
577 + struct tag_data data;
578 const struct ref *ref;
579 struct string_list_item *item = NULL;
580 + data.head = head; data.tail = tail;
581
582 for_each_ref(add_existing, &existing_refs);
583 for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
@@ -778,7 +779,8 @@ static int get_remote_group(const char *key, const char *value, void *priv)
779 static int add_remote_or_group(const char *name, struct string_list *list)
780 {
781 int prev_nr = list->nr;
781 - struct remote_group_data g = { name, list };
782 + struct remote_group_data g;
783 + g.name = name; g.list = list;
784
785 git_config(get_remote_group, &g);
786 if (list->nr == prev_nr) {
builtin/remote.c
+6 -3
@@ -705,11 +705,14 @@ static int rm(int argc, const char **argv)
705 struct known_remotes known_remotes = { NULL, NULL };
706 struct string_list branches = { NULL, 0, 0, 1 };
707 struct string_list skipped = { NULL, 0, 0, 1 };
708 - struct branches_for_remote cb_data = {
709 - NULL, &branches, &skipped, &known_remotes
710 - };
708 + struct branches_for_remote cb_data;
709 int i, result;
710
711 + memset(&cb_data, 0, sizeof(cb_data));
712 + cb_data.branches = &branches;
713 + cb_data.skipped = &skipped;
714 + cb_data.keep = &known_remotes;
715 +
716 if (argc != 2)
717 usage_with_options(builtin_remote_rm_usage, options);
718
convert.c
+3 -1
@@ -249,7 +249,9 @@ static int filter_buffer(int in, int out, void *data)
249 struct child_process child_process;
250 struct filter_params *params = (struct filter_params *)data;
251 int write_err, status;
252 - const char *argv[] = { params->cmd, NULL };
252 + const char *argv[] = { NULL, NULL };
253 +
254 + argv[0] = params->cmd;
255
256 memset(&child_process, 0, sizeof(child_process));
257 child_process.argv = argv;
daemon.c
+11 -10
@@ -141,15 +141,14 @@ static char *path_ok(char *directory)
141 }
142 else if (interpolated_path && saw_extended_args) {
143 struct strbuf expanded_path = STRBUF_INIT;
144 - struct strbuf_expand_dict_entry dict[] = {
145 - { "H", hostname },
146 - { "CH", canon_hostname },
147 - { "IP", ip_address },
148 - { "P", tcp_port },
149 - { "D", directory },
150 - { NULL }
151 - };
152 -
144 + struct strbuf_expand_dict_entry dict[6];
145 +
146 + dict[0].placeholder = "H"; dict[0].value = hostname;
147 + dict[1].placeholder = "CH"; dict[1].value = canon_hostname;
148 + dict[2].placeholder = "IP"; dict[2].value = ip_address;
149 + dict[3].placeholder = "P"; dict[3].value = tcp_port;
150 + dict[4].placeholder = "D"; dict[4].value = directory;
151 + dict[5].placeholder = NULL; dict[5].value = NULL;
152 if (*dir != '/') {
153 /* Allow only absolute */
154 logerror("'%s': Non-absolute path denied (interpolated-path active)", dir);
@@ -343,7 +342,9 @@ static int upload_pack(void)
342 {
343 /* Timeout as string */
344 char timeout_buf[64];
346 - const char *argv[] = { "upload-pack", "--strict", timeout_buf, ".", NULL };
345 + const char *argv[] = { "upload-pack", "--strict", NULL, ".", NULL };
346 +
347 + argv[2] = timeout_buf;
348
349 snprintf(timeout_buf, sizeof timeout_buf, "--timeout=%u", timeout);
350 return run_service_command(argv);
ll-merge.c
+7 -7
@@ -139,17 +139,17 @@ static int ll_ext_merge(const struct ll_merge_driver *fn,
139 {
140 char temp[4][50];
141 struct strbuf cmd = STRBUF_INIT;
142 - struct strbuf_expand_dict_entry dict[] = {
143 - { "O", temp[0] },
144 - { "A", temp[1] },
145 - { "B", temp[2] },
146 - { "L", temp[3] },
147 - { NULL }
148 - };
142 + struct strbuf_expand_dict_entry dict[5];
143 const char *args[] = { NULL, NULL };
144 int status, fd, i;
145 struct stat st;
146
147 + dict[0].placeholder = "O"; dict[0].value = temp[0];
148 + dict[1].placeholder = "A"; dict[1].value = temp[1];
149 + dict[2].placeholder = "B"; dict[2].value = temp[2];
150 + dict[3].placeholder = "L"; dict[3].value = temp[3];
151 + dict[4].placeholder = NULL; dict[4].value = NULL;
152 +
153 if (fn->cmdline == NULL)
154 die("custom merge driver %s lacks command line.", fn->name);
155
refs.c
+5 -1
@@ -314,7 +314,11 @@ static int warn_if_dangling_symref(const char *refname, const unsigned char *sha
314
315 void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
316 {
317 - struct warn_if_dangling_data data = { fp, refname, msg_fmt };
317 + struct warn_if_dangling_data data;
318 +
319 + data.fp = fp;
320 + data.refname = refname;
321 + data.msg_fmt = msg_fmt;
322 for_each_rawref(warn_if_dangling_symref, &data);
323 }
324
remote.c
+1 -2
@@ -657,10 +657,9 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp
657
658 int valid_fetch_refspec(const char *fetch_refspec_str)
659 {
660 - const char *fetch_refspec[] = { fetch_refspec_str };
660 struct refspec *refspec;
661
663 - refspec = parse_refspec_internal(1, fetch_refspec, 1, 1);
662 + refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1);
663 free_refspecs(refspec, 1);
664 return !!refspec;
665 }
unpack-trees.c
+3 -1
@@ -287,9 +287,11 @@ static void add_same_unmerged(struct cache_entry *ce,
287 static int unpack_index_entry(struct cache_entry *ce,
288 struct unpack_trees_options *o)
289 {
290 - struct cache_entry *src[5] = { ce, NULL, };
290 + struct cache_entry *src[5] = { NULL };
291 int ret;
292
293 + src[0] = ce;
294 +
295 mark_ce_used(ce, o);
296 if (ce_stage(ce)) {
297 if (o->skip_unmerged) {
wt-status.c
+12 -11
@@ -498,17 +498,18 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
498 struct child_process sm_summary;
499 char summary_limit[64];
500 char index[PATH_MAX];
501 - const char *env[] = { index, NULL };
502 - const char *argv[] = {
503 - "submodule",
504 - "summary",
505 - uncommitted ? "--files" : "--cached",
506 - "--for-status",
507 - "--summary-limit",
508 - summary_limit,
509 - uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD"),
510 - NULL
511 - };
501 + const char *env[] = { NULL, NULL };
502 + const char *argv[8];
503 +
504 + env[0] = index;
505 + argv[0] = "submodule";
506 + argv[1] = "summary";
507 + argv[2] = uncommitted ? "--files" : "--cached";
508 + argv[3] = "--for-status";
509 + argv[4] = "--summary-limit";
510 + argv[5] = summary_limit;
511 + argv[6] = uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD");
512 + argv[7] = NULL;
513
514 sprintf(summary_limit, "%d", s->submodule_summary);
515 snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);