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

[demo/PATCH 1/3] string-list: Document STRING_LIST_INIT_* and string_list_init()

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Sep 5, 2010, 20:06 UTC
Message-ID
<20100905200634.GC14497@burratino>
In-Reply-To
<20100905200323.GA14497@burratino>

Clarify the modern ways to initialize a string_list. Text roughly based on the analogous passage from api-strbuf.txt.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/technical/api-string-list.txt |   18 +++++++++++-------
 1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt
index 3f575bd..0f0e579 100644
--- a/Documentation/technical/api-string-list.txt
+++ b/Documentation/technical/api-string-list.txt
@@ -9,12 +9,17 @@ because it is not specific to paths.
 
 The caller:
 
-. Allocates and clears a `struct string_list` variable.
+. Allocates a `struct string_list` variable
 
-. Initializes the members. You might want to set the flag `strdup_strings`
-  if the strings should be strdup()ed. For example, this is necessary
-  when you add something like git_path("..."), since that function returns
-  a static buffer that will change with the next call to git_path().
+. Initializes the members. A string_list has to be initialized by
+  `string_list_init()` or by `= STRING_LIST_INIT_DUP` or
+  `= STRING_LIST_INIT_NODUP` before it can be used.
++
+Strings in lists initialized with the _DUP variant will be
+automatically strdup()ed on insertion and free()ed on removal.
+For example, this is necessary when you add something like
+git_path("..."), since that function returns a static buffer
+that will change with the next call to git_path().
 +
 If you need something advanced, you can manually malloc() the `items`
 member (you need this if you add things later) and you should set the
@@ -34,10 +39,9 @@ member (you need this if you add things later) and you should set the
 Example:
 
 ----
-struct string_list list;
+struct string_list list STRING_LIST_INIT_NODUP;
 int i;
 
-memset(&list, 0, sizeof(struct string_list));
 string_list_append(&list, "foo");
 string_list_append(&list, "bar");
 for (i = 0; i < list.nr; i++)
-- 
1.7.2.3
Previous: Jonathan NiederNext: Jonathan Nieder
Message 4 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.