]> git.ipfire.org Git - thirdparty/git.git/commitdiff
argv-array: refactor empty_argv initialization
authorJeff King <peff@peff.net>
Wed, 18 Apr 2012 21:08:49 +0000 (14:08 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Apr 2012 23:16:16 +0000 (16:16 -0700)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
argv-array.c
argv-array.h

index a4e04201e61d0243dc225d85117341d993ca0c3b..110a61b93a088535c602a3945da8a97733f96845 100644 (file)
@@ -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)
 {
index 74dd2b1bc0487fb3493c1c2747ebe2bd8958616b..c45c698d53d6c8b59cac94b9f586c11863ceb372 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef ARGV_ARRAY_H
 #define ARGV_ARRAY_H
 
-extern const char **empty_argv;
+extern const char *empty_argv[];
 
 struct argv_array {
        const char **argv;