From fd93d2e60ea66fc3796904ff53ead3ef4755b137 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 18 Apr 2012 14:08:49 -0700 Subject: argv-array: refactor empty_argv initialization An empty argv-array is initialized to point to a static empty NULL-terminated array. The original implementation separates the actual storage of the NULL-terminator from the pointer to the list. This makes the exposed type a "const char **", which nicely matches the type stored by the argv-array. However, this indirection means that one cannot use empty_argv to initialize a static variable, since it is not a constant. Instead, we can expose empty_argv directly, as an array of pointers. The only place we use it is in the ARGV_ARRAY_INIT initializer, and it decays to a pointer appropriately there. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- argv-array.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'argv-array.c') diff --git a/argv-array.c b/argv-array.c index a4e04201e6..110a61b93a 100644 --- a/argv-array.c +++ b/argv-array.c @@ -2,8 +2,7 @@ #include "argv-array.h" #include "strbuf.h" -static const char *empty_argv_storage = NULL; -const char **empty_argv = &empty_argv_storage; +const char *empty_argv[] = { NULL }; void argv_array_init(struct argv_array *array) { -- cgit v1.2.3 From d15bbe1379a12e2d9a5f18f7dc96b38afafc6c5d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 18 Apr 2012 14:10:05 -0700 Subject: argv-array: add a new "pushl" method It can be convenient to push many strings in a single line (e.g., if you are initializing an array with defaults). This patch provides a convenience wrapper to allow this. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- argv-array.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'argv-array.c') diff --git a/argv-array.c b/argv-array.c index 110a61b93a..0b5f8898a1 100644 --- a/argv-array.c +++ b/argv-array.c @@ -38,6 +38,17 @@ void argv_array_pushf(struct argv_array *array, const char *fmt, ...) argv_array_push_nodup(array, strbuf_detach(&v, NULL)); } +void argv_array_pushl(struct argv_array *array, ...) +{ + va_list ap; + const char *arg; + + va_start(ap, array); + while((arg = va_arg(ap, const char *))) + argv_array_push(array, arg); + va_end(ap); +} + void argv_array_clear(struct argv_array *array) { if (array->argv != empty_argv) { -- cgit v1.2.3