Skip to content

Commit

Permalink
argv-array: refactor empty_argv initialization
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Apr 18, 2012
1 parent 7e52f56 commit fd93d2e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions argv-array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion argv-array.h
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit fd93d2e

Please sign in to comment.