git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/5] *.h: move some *_INIT to designated initializers

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jul 1, 2021, 10:51 UTC
Message-ID
<patch-1.5-9a92e7c216f-20210701T104855Z-avarab@gmail.com>
In-Reply-To
<cover-0.5-00000000000-20210701T104855Z-avarab@gmail.com>

Move *_INIT macros I'll use in a subsequent commits to designated initializers. This isn't required for those follow-up changes, but since I'm changing things in this are let's use the modern pattern over the old one while we're at it.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 credential.h  | 4 +++-
 json-writer.h | 5 ++++-
 run-command.h | 5 ++++-
 string-list.h | 4 ++--
 4 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/credential.h b/credential.h
index c0e17e3554f..f430e77fea4 100644
--- a/credential.h
+++ b/credential.h
@@ -128,7 +128,9 @@ struct credential {
 	char *path;
 };
 
-#define CREDENTIAL_INIT { STRING_LIST_INIT_DUP }
+#define CREDENTIAL_INIT { \
+	.helpers = STRING_LIST_INIT_DUP, \
+}
 
 /* Initialize a credential structure, setting all fields to empty. */
 void credential_init(struct credential *);
diff --git a/json-writer.h b/json-writer.h
index 83906b09c17..209355e0f12 100644
--- a/json-writer.h
+++ b/json-writer.h
@@ -64,7 +64,10 @@ struct json_writer
 	unsigned int pretty:1;
 };
 
-#define JSON_WRITER_INIT { STRBUF_INIT, STRBUF_INIT, 0, 0 }
+#define JSON_WRITER_INIT { \
+	.json = STRBUF_INIT, \
+	.open_stack = STRBUF_INIT, \
+}
 
 void jw_init(struct json_writer *jw);
 void jw_release(struct json_writer *jw);
diff --git a/run-command.h b/run-command.h
index d08414a92e7..62a922d23fb 100644
--- a/run-command.h
+++ b/run-command.h
@@ -141,7 +141,10 @@ struct child_process {
 	void *clean_on_exit_handler_cbdata;
 };
 
-#define CHILD_PROCESS_INIT { NULL, STRVEC_INIT, STRVEC_INIT }
+#define CHILD_PROCESS_INIT { \
+	.args = STRVEC_INIT, \
+	.env_array = STRVEC_INIT, \
+}
 
 /**
  * The functions: child_process_init, start_command, finish_command,
diff --git a/string-list.h b/string-list.h
index 6c5d274126a..521b9c0748d 100644
--- a/string-list.h
+++ b/string-list.h
@@ -91,8 +91,8 @@ struct string_list {
 	compare_strings_fn cmp; /* NULL uses strcmp() */
 };
 
-#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0, NULL }
-#define STRING_LIST_INIT_DUP   { NULL, 0, 0, 1, NULL }
+#define STRING_LIST_INIT_NODUP { 0 }
+#define STRING_LIST_INIT_DUP   { .strdup_strings = 1 }
 
 /* General functions which work with both sorted and unsorted lists. */
 
-- 
2.32.0.623.ge833f40cd87
Previous: Ævar Arnfjörð BjarmasonNext: Martin Ågren
Message 4 of 10 in “*.[ch]: don't duplicate *_init() and *_INIT logic”
  1. 0/5 *.[ch]: don't duplicate *_init() and *_INIT logicÆvar Arnfjörð Bjarmason, Jul 1, 2021
  2. 3/5 dir.[ch]: replace dir_init() with DIR_INITÆvar Arnfjörð Bjarmason, Jul 1, 2021
  3. 2/5 *.c *_init(): define in terms of corresponding *_INIT macroÆvar Arnfjörð Bjarmason, Jul 1, 2021
  4. 1/5 *.h: move some *_INIT to designated initializersÆvar Arnfjörð Bjarmason, Jul 1, 2021
  5. Martin ÅgrenJul 1, 2021
  6. Junio C HamanoJul 1, 2021
  7. Ævar Arnfjörð BjarmasonJul 1, 2021
  8. 5/5 string-list.h users: change to use *_{nodup,dup}()Ævar Arnfjörð Bjarmason, Jul 1, 2021
  9. 4/5 string-list.[ch]: add a string_list_init_{nodup,dup}()Ævar Arnfjörð Bjarmason, Jul 1, 2021
  10. Jeff KingJul 1, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.