git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: Tanay Abhra <tanayabh@gmail.com>, git@vger.kernel.org
Cc: Ramkumar Ramachandra <artagnon@gmail.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: Re: [PATCH v3 1/3] string-list: add string_list initialiser helper functions
Date: Mon, 23 Jun 2014 14:36:21 +0200	[thread overview]
Message-ID: <53A81F45.70802@web.de> (raw)
In-Reply-To: <1403518300-23053-2-git-send-email-tanayabh@gmail.com>

On 2014-06-23 12.11, Tanay Abhra wrote:
> The string-list API has STRING_LIST_INIT_* macros to be used
> to define variables with initialisers, but lacks functions
> to initialise an uninitialised piece of memory to be used as
> a string-list at the run-time.
> Introduce string_list_init_{dup,nodup}() functions for that.
> 
> Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
> ---
>  string-list.c | 18 ++++++++++++++++++
>  string-list.h |  3 +++
>  2 files changed, 21 insertions(+)
> 
> diff --git a/string-list.c b/string-list.c
> index aabb25e..8c3a4eb 100644
> --- a/string-list.c
> +++ b/string-list.c
> @@ -1,6 +1,24 @@
>  #include "cache.h"
>  #include "string-list.h"
>  
> +void string_list_init_nodup(struct string_list *list)
> +{
> +	list->items = NULL;
> +	list->nr = 0;
> +	list->alloc = 0;
> +	list->strdup_strings = 0;
> +	list->cmp = NULL;
> +}
> +
If we look at the definition below:
struct string_list {
	struct string_list_item *items;
	unsigned int nr, alloc;
	unsigned int strdup_strings:1;
	compare_strings_fn cmp; /* NULL uses strcmp() */
I think a simple memset() will be easier to read,
and it will be more future proof:
In case elements are added, the will have 0 or NULL automatically:

void string_list_init_nodup(struct string_list *list)
{
	memset (list, 0, sizeof(*list));
}
(But then I wonder if we need the function at all ?)

Or does it make sense to have a common function similar to this,
which covers both cases:

void string_list_init(struct string_list *list, int strdup_strings)
{
	memset (list, 0, sizeof(*list));
	list->strdup_strings = strdup_strings;
}

  reply	other threads:[~2014-06-23 12:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-23 10:11 [PATCH v3 0/3] git config cache & special querying api utilizing the cache Tanay Abhra
2014-06-23 10:11 ` [PATCH v3 1/3] string-list: add string_list initialiser helper functions Tanay Abhra
2014-06-23 12:36   ` Torsten Bögershausen [this message]
2014-06-23 13:19     ` Tanay Abhra
2014-06-23 10:11 ` [PATCH v3 2/3] config: add hashtable for config parsing & retrieval Tanay Abhra
2014-06-23 11:55   ` Matthieu Moy
2014-06-24 12:06     ` Tanay Abhra
2014-06-25 20:25       ` Karsten Blees
2014-06-23 14:57   ` Ramsay Jones
2014-06-23 16:20     ` Tanay Abhra
2014-06-24 15:32       ` Ramsay Jones
2014-06-26 16:15         ` Matthieu Moy
2014-06-23 23:25     ` Junio C Hamano
2014-06-24  7:23       ` Tanay Abhra
2014-06-25 18:21         ` Junio C Hamano
2014-06-24  7:25       ` Tanay Abhra
2014-06-24 15:57       ` Ramsay Jones
2014-06-25 18:13         ` Junio C Hamano
2014-06-25 20:23           ` Karsten Blees
2014-06-25 20:53             ` Junio C Hamano
2014-06-26 17:37           ` Matthieu Moy
2014-06-26 19:00             ` Junio C Hamano
2014-06-26 19:19               ` Karsten Blees
2014-06-26 21:21                 ` Junio C Hamano
2014-06-27  8:19                   ` Karsten Blees
2014-06-27  8:19               ` Matthieu Moy
2014-06-27 17:13                 ` Junio C Hamano
2014-06-23 23:14   ` Junio C Hamano
2014-06-24 12:21     ` Tanay Abhra
2014-06-26 16:27       ` Matthieu Moy
2014-06-25 21:44   ` Karsten Blees
2014-06-26 16:43   ` Matthieu Moy
2014-06-23 10:11 ` [PATCH v3 3/3] test-config: add usage examples for non-callback query functions Tanay Abhra
2014-06-25 11:19   ` Eric Sunshine
2014-06-26  8:40     ` Tanay Abhra

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=53A81F45.70802@web.de \
    --to=tboegi@web.de \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --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 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).