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

[demo/PATCH 1/3] string-list: introduce string_list_init()

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Sep 5, 2010, 20:04 UTC
Message-ID
<20100905200429.GB14497@burratino>
In-Reply-To
<20100905200323.GA14497@burratino>
Instead of asking callers to
	memset(&list, 0, sizeof(list));
	list.strdup_strings = strdup_strings;

we can take care of that ourselves, providing the flexibility to change the details of string_list layout later if wanted.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 string-list.c |    7 +++++++
 string-list.h |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/string-list.c b/string-list.c
index 9b023a2..8e992a7 100644
--- a/string-list.c
+++ b/string-list.c
@@ -102,6 +102,13 @@ int for_each_string_list(struct string_list *list,
 	return ret;
 }
 
+void string_list_init(struct string_list *list, int strdup_strings)
+{
+	list->items = NULL;
+	list->nr = list->alloc = 0;
+	list->strdup_strings = strdup_strings ? 1 : 0;
+}
+
 void string_list_clear(struct string_list *list, int free_util)
 {
 	if (list->items) {
diff --git a/string-list.h b/string-list.h
index 4946938..07e075c 100644
--- a/string-list.h
+++ b/string-list.h
@@ -15,6 +15,7 @@ struct string_list
 #define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 }
 #define STRING_LIST_INIT_DUP   { NULL, 0, 0, 1 }
 
+void string_list_init(struct string_list *list, int strdup_strings);
 void print_string_list(const struct string_list *p, const char *text);
 void string_list_clear(struct string_list *list, int free_util);
 
-- 
1.7.2.3
Previous: Jonathan NiederNext: Jonathan Nieder
Message 3 of 6 in “Documentation: document the string-list macros.”
  1. Documentation: document the string-list macros.Thiago Farina, Sep 5, 2010
  2. 0/3 Re: [PATCH] Documentation: document the string-list macros.Jonathan Nieder, Sep 5, 2010
  3. 1/3 string-list: introduce string_list_init()Jonathan Nieder, Sep 5, 2010
  4. 1/3 string-list: Document STRING_LIST_INIT_* and string_list_init()Jonathan Nieder, Sep 5, 2010
  5. 3/3 Make initialization of string_lists more consistentJonathan Nieder, Sep 5, 2010
  6. Thiago FarinaSep 5, 2010

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.