git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 1/3] argv-array: refactor empty_argv initialization
Date: Wed, 18 Apr 2012 14:08:49 -0700	[thread overview]
Message-ID: <20120418210848.GA21301@sigill.intra.peff.net> (raw)
In-Reply-To: <20120418210740.GA21214@sigill.intra.peff.net>

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>
---
 argv-array.c |    3 +--
 argv-array.h |    2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/argv-array.c b/argv-array.c
index a4e0420..110a61b 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)
 {
diff --git a/argv-array.h b/argv-array.h
index 74dd2b1..c45c698 100644
--- a/argv-array.h
+++ b/argv-array.h
@@ -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;
-- 
1.7.9.6.8.g992e5

  reply	other threads:[~2012-04-18 21:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-17 23:32 [PATCH] gc: fix off-by-one in append_option Jeff King
2012-04-18 19:18 ` Jeff King
2012-04-18 19:34   ` Junio C Hamano
2012-04-18 20:21     ` Jeff King
2012-04-18 21:07       ` Jeff King
2012-04-18 21:08         ` Jeff King [this message]
2012-04-18 21:10         ` [PATCH 2/3] argv-array: add a new "pushl" method Jeff King
2012-04-18 21:10         ` [PATCH 3/3] gc: use argv-array for sub-commands Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120418210848.GA21301@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).