* [PATCH v2] string-list: Add a value to string_list initializer lists
@ 2014-06-03 9:13 Tanay Abhra
2014-06-03 15:20 ` Matthieu Moy
0 siblings, 1 reply; 2+ messages in thread
From: Tanay Abhra @ 2014-06-03 9:13 UTC (permalink / raw)
To: git; +Cc: Tanay Abhra, Ramkumar Ramachandra, Matthieu Moy, Junio C Hamano
STRING_LIST_INIT_{NODUP,DUP} initializers list values only
for earlier structure members, relying on the usual
convention in C that the omitted members are initailized to
0, i.e. the former is expanded to the latter:
struct string_list l = STRING_LIST_INIT_DUP;
struct string_list l = { NULL, 0, 0, 1 };
and the last member that is not mentioned (i.e. 'cmp') is
initialized to NULL.
While there is nothing wrong in this construct, spelling out
all the values where the macros are defined will serve also
as a documentation, so let's do so.
Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
---
V1: http://thread.gmane.org/gmane.comp.version-control.git/250560
Documentation/technical/api-string-list.txt | 2 ++
string-list.h | 4 ++--
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt
index 20be348..f1add51 100644
--- a/Documentation/technical/api-string-list.txt
+++ b/Documentation/technical/api-string-list.txt
@@ -200,3 +200,5 @@ Represents the list itself.
You should not tamper with it.
. Setting the `strdup_strings` member to 1 will strdup() the strings
before adding them, see above.
+. The `compare_strings_fn` member is used to specify a custom compare
+ function, otherwise `strcmp()` is used as the default function.
diff --git a/string-list.h b/string-list.h
index de6769c..dd5e294 100644
--- a/string-list.h
+++ b/string-list.h
@@ -15,8 +15,8 @@ struct string_list {
compare_strings_fn cmp; /* NULL uses strcmp() */
};
-#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 }
-#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1 }
+#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0, NULL }
+#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1, NULL }
void print_string_list(const struct string_list *p, const char *text);
void string_list_clear(struct string_list *list, int free_util);
--
1.9.0.GIT
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] string-list: Add a value to string_list initializer lists
2014-06-03 9:13 [PATCH v2] string-list: Add a value to string_list initializer lists Tanay Abhra
@ 2014-06-03 15:20 ` Matthieu Moy
0 siblings, 0 replies; 2+ messages in thread
From: Matthieu Moy @ 2014-06-03 15:20 UTC (permalink / raw)
To: Tanay Abhra; +Cc: git, Ramkumar Ramachandra, Junio C Hamano
Tanay Abhra <tanayabh@gmail.com> writes:
> diff --git a/Documentation/technical/api-string-list.txt b/Documentation/technical/api-string-list.txt
> index 20be348..f1add51 100644
> --- a/Documentation/technical/api-string-list.txt
> +++ b/Documentation/technical/api-string-list.txt
> @@ -200,3 +200,5 @@ Represents the list itself.
> You should not tamper with it.
> . Setting the `strdup_strings` member to 1 will strdup() the strings
> before adding them, see above.
> +. The `compare_strings_fn` member is used to specify a custom compare
> + function, otherwise `strcmp()` is used as the default function.
Is this change intentional? It seems good, but not really related to the
change described in the commit message.
In any case, this remark should not block patch inclusion, it's trivial
enough.
--
Matthieu Moy
http://www-verimag.imag.fr/~moy/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-03 15:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-03 9:13 [PATCH v2] string-list: Add a value to string_list initializer lists Tanay Abhra
2014-06-03 15:20 ` Matthieu Moy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox