From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: Tanay Abhra <tanayabh@gmail.com>,
git@vger.kernel.org, Ramkumar Ramachandra <artagnon@gmail.com>,
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: Re: [PATCH] config.c: change the function signature of `git_config_string()`
Date: Tue, 22 Jul 2014 09:47:48 -0700 [thread overview]
Message-ID: <xmqqk375gx1n.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20140722110720.GA386@peff.net> (Jeff King's message of "Tue, 22 Jul 2014 07:07:20 -0400")
Jeff King <peff@peff.net> writes:
> So I would not mind lifting this unnecessary restriction on
> git_config_string, but I do not see a way to do it without making the
> rest of the code much uglier (and I do not see a particular advantage in
> modifying git_config_string here that would make it worth the trouble).
I do not think changing the existing one is warranted, either.
Given that C's type system does not allow us to pass "const char *"
as "char *" without cast (and vice versa), a function that takes an
out parameter that points at the location to store the pointer to a
string (instead of returning the pointer to a string as value) has
to take either one of these forms:
get_mutable(char **dest);
get_const(const char **dest);
and half the callers need to pass their variables with a cast, i.e.
char *mutable_string;
const char *const_string;
get_mutable((char **)&const_string);
get_mutable(&mutable_string);
get_const(&const_string);
get_const((const char **)&mutable_string);
If we have to cast some [*1*], I'd prefer to see the type describe
what it really is, and I think a function that gives a newly
allocated storage for the callers' own use is better described by
taking a pointer to non-const "char *" location. So I'd encourage a
new function being introduced that does not have existing callers to
use that as the criterion to decide which to take.
Changing the existing function with existing calling site needs two
other pros-and-cons evaluation, in addition to the above "does the
type describe what it really is?", which are "is it worth the
churn?" and "does the end result make more sense than the original?"
[Footnote]
*1* We have safe_create_leading_directories_const() that works
around this for input parameter around its _const less counterpart,
which is ugly but livable solution.
next prev parent reply other threads:[~2014-07-22 16:48 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-22 10:49 [PATCH] config.c: change the function signature of `git_config_string()` Tanay Abhra
2014-07-22 11:07 ` Jeff King
2014-07-22 11:41 ` Tanay Abhra
2014-07-22 11:44 ` Matthieu Moy
2014-07-22 11:48 ` Tanay Abhra
2014-07-22 15:53 ` Junio C Hamano
2014-07-22 16:03 ` Matthieu Moy
2014-07-22 16:47 ` Junio C Hamano [this message]
2014-07-23 8:42 ` Matthieu Moy
2014-07-23 17:25 ` Junio C Hamano
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=xmqqk375gx1n.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=tanayabh@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.