Re: [PATCH 2/6] config: add 'git_config_string' to refactor string config variables.
- From
Christian Couder <chriscool@tuxfamily.org>
- Date
- Feb 16, 2008, 18:21 UTC
- Message-ID
- <200802161921.43346.chriscool@tuxfamily.org>
- In-Reply-To
- <20080216115310.GA11318@sigill.intra.peff.net>
Le samedi 16 février 2008, Jeff King a écrit :
Show 15 quoted lines
> On Sat, Feb 16, 2008 at 06:00:24AM +0100, Christian Couder wrote:
> > +int git_config_string(const char **dest, const char *var, const char
> > *value) +{
> > + if (!value)
> > + return config_error_nonbool(var);
> > + *dest = xstrdup(value);
> > + return 0;
> > +}
>
> I'm not sure I see the point in using a 'const char *' as the
> destination. The string isn't inherently const, since it is allocated on
> the heap; callers are free to use it as they please (and are responsible
> for freeing it; while constness doesn't impact calling free() at a
> language level, I think that stylistically it is uncommon for a
> heap-allocated string to be stored as 'const').Well, in many places where this function could be used the dest string is a "const char *" and in many other places it's a "char *", but it feels safer to try to promote the latter into the former (like I did in the following patches) rather than the other way around.
Christian.