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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Apr 18, 2012 at 14:08 UTC
fd93d2e60ea66fc3796904ff53ead3ef4755b137
2 files changed
+2
-3
argv-array.c
+1
-2
@@ -2,8 +2,7 @@
2
#include "argv-array.h"
3
#include "strbuf.h"
4
5
-static const char *empty_argv_storage = NULL;
6
-const char **empty_argv = &empty_argv_storage;
5
+const char *empty_argv[] = { NULL };
6
7
void argv_array_init(struct argv_array *array)
8
{
argv-array.h
+1
-1
@@ -1,7 +1,7 @@
1
#ifndef ARGV_ARRAY_H
2
#define ARGV_ARRAY_H
3
4
-extern const char **empty_argv;
4
+extern const char *empty_argv[];
5
6
struct argv_array {
7
const char **argv;