Skip to content

Commit 3ed3f5f

Browse files
tanayabhgitster
authored andcommitted
string-list: add string_list initializer helper function
The string-list API has STRING_LIST_INIT_* macros to be used to define variables with initializers, but lacks functions to initialize an uninitialized piece of memory to be used as a string-list at the run-time. Introduce `string_list_init()` function for that. Signed-off-by: Tanay Abhra <[email protected]> Reviewed-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d15f53 commit 3ed3f5f

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Documentation/technical/api-string-list.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ Functions
6868

6969
* General ones (works with sorted and unsorted lists as well)
7070

71+
`string_list_init`::
72+
73+
Initialize the members of the string_list, set `strdup_strings`
74+
member according to the value of the second parameter.
75+
7176
`filter_string_list`::
7277

7378
Apply a function to each item in a list, retaining only the

string-list.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#include "cache.h"
22
#include "string-list.h"
33

4+
void string_list_init(struct string_list *list, int strdup_strings)
5+
{
6+
memset(list, 0, sizeof(*list));
7+
list->strdup_strings = strdup_strings;
8+
}
9+
410
/* if there is no exact match, point to the index where the entry could be
511
* inserted */
612
static int get_entry_index(const struct string_list *list, const char *string,

string-list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ struct string_list {
1818
#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0, NULL }
1919
#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1, NULL }
2020

21+
void string_list_init(struct string_list *list, int strdup_strings);
22+
2123
void print_string_list(const struct string_list *p, const char *text);
2224
void string_list_clear(struct string_list *list, int free_util);
2325

0 commit comments

Comments
 (0)