git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Cc: Git List <git@vger.kernel.org>,
	Matheus Tavares <matheus.bernardino@usp.br>,
	Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 1/3] mem-pool: add convenience functions for xstrdup and xstrndup
Date: Fri, 14 Aug 2020 00:42:19 -0400	[thread overview]
Message-ID: <CAPig+cQamHAUc9gV=pRAVYfxJKCwiMj=y6nqoN8w2kg6CtOT9Q@mail.gmail.com> (raw)
In-Reply-To: <eae8b2923f7834f3b1d030f6eb4dc093b94da91b.1597374135.git.gitgitgadget@gmail.com>

On Thu, Aug 13, 2020 at 11:02 PM Elijah Newren via GitGitGadget
<gitgitgadget@gmail.com> wrote:
> fast-import had a special mem_pool_xstrdup() convenience function that I
> want to be able to use from the new merge algorithm I am writing.  Move
> it from fast-import to mem-pool, and also add a mem_pool_xstrndup()
> while at it that I also want to use.
>
> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
> diff --git a/mem-pool.c b/mem-pool.c
> @@ -102,6 +102,29 @@ void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_t size)
> +char *mem_pool_xstrdup(struct mem_pool *pool, const char *str)
> +{
> +       size_t len = strlen(str) + 1;
> +       char *ret = mem_pool_alloc(pool, len);
> +
> +       if (!ret)
> +               die("Out of memory, mem_pool_xstrdup failed");

Nit: Not worth a re-roll, but I was wondering if it would make sense
to allow these to be localized (and follow current convention of not
capitalizing):

    die(_("mem_pool_xstrdup: out of memory"));

> +       return memcpy(ret, str, len);
> +}
> +
> +char *mem_pool_xstrndup(struct mem_pool *pool, const char *str, size_t len)
> +{
> +       size_t minlen = strnlen(str, len);
> +       char *ret = mem_pool_alloc(pool, minlen+1);
> +
> +       if (!ret)
> +               die("Out of memory, mem_pool_xstrndup failed");

Ditto.

> +
> +       ret[minlen] = '\0';
> +       return memcpy(ret, str, minlen);
> +}

  reply	other threads:[~2020-08-14  4:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-14  3:02 [PATCH 0/3] Extend and add a little more generalization to the mem_pool API Elijah Newren via GitGitGadget
2020-08-14  3:02 ` [PATCH 1/3] mem-pool: add convenience functions for xstrdup and xstrndup Elijah Newren via GitGitGadget
2020-08-14  4:42   ` Eric Sunshine [this message]
2020-08-14  3:02 ` [PATCH 2/3] mem-pool: use more standard initialization and finalization Elijah Newren via GitGitGadget
2020-08-14  4:38   ` Junio C Hamano
2020-08-14  3:02 ` [PATCH 3/3] mem-pool: use consistent pool variable name Elijah Newren via GitGitGadget
2020-08-14  3:51 ` [PATCH 0/3] Extend and add a little more generalization to the mem_pool API Matheus Tavares Bernardino
2020-08-14  6:00 ` [PATCH v2 " Elijah Newren via GitGitGadget
2020-08-14  6:00   ` [PATCH v2 1/3] mem-pool: add convenience functions for xstrdup and xstrndup Elijah Newren via GitGitGadget
2020-08-14  8:21     ` René Scharfe
2020-08-14  6:00   ` [PATCH v2 2/3] mem-pool: use more standard initialization and finalization Elijah Newren via GitGitGadget
2020-08-14  6:00   ` [PATCH v2 3/3] mem-pool: use consistent pool variable name Elijah Newren via GitGitGadget
2020-08-15 17:37   ` [PATCH v3 0/3] Extend and add a little more generalization to the mem_pool API Elijah Newren via GitGitGadget
2020-08-15 17:37     ` [PATCH v3 1/3] mem-pool: add convenience functions for strdup and strndup Elijah Newren via GitGitGadget
2020-08-15 17:37     ` [PATCH v3 2/3] mem-pool: use more standard initialization and finalization Elijah Newren via GitGitGadget
2020-08-15 17:37     ` [PATCH v3 3/3] mem-pool: use consistent pool variable name Elijah Newren via GitGitGadget
2020-08-18 19:27     ` [PATCH v3 0/3] Extend and add a little more generalization to the mem_pool API 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to='CAPig+cQamHAUc9gV=pRAVYfxJKCwiMj=y6nqoN8w2kg6CtOT9Q@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=matheus.bernardino@usp.br \
    --cc=newren@gmail.com \
    --subject='Re: [PATCH 1/3] mem-pool: add convenience functions for xstrdup and xstrndup' \
    /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

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).