All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Matheus Tavares" <matheus.bernardino@usp.br>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"René Scharfe" <l.s.r@web.de>, "Elijah Newren" <newren@gmail.com>
Subject: [PATCH v3 0/3] Extend and add a little more generalization to the mem_pool API
Date: Sat, 15 Aug 2020 17:37:54 +0000	[thread overview]
Message-ID: <pull.830.v3.git.git.1597513078.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.830.v2.git.git.1597384820.gitgitgadget@gmail.com>

In my new merge algorithm, I made use of the mem_pool API in a few
places...but I also needed to add a few more functions and also needed to
make the API a bit more general.

Changes since v2:

 * Remove 'x' from mem_pool_xstr[n]?dup() names and remove check for NULL
   since mem_pool_alloc() already handles that (via xmalloc), as suggested
   by René
 * Rewrite mem_pool_strndup() to not rely on strnlen(), since that may be
   too new from some systems (comes from POSIX 2008 ). Also pointed out by
   René

Elijah Newren (3):
  mem-pool: add convenience functions for strdup and strndup
  mem-pool: use more standard initialization and finalization
  mem-pool: use consistent pool variable name

 fast-import.c | 12 ++-------
 mem-pool.c    | 69 ++++++++++++++++++++++++++++++---------------------
 mem-pool.h    | 14 ++++++++---
 read-cache.c  | 21 ++++++++++------
 split-index.c |  6 +++--
 5 files changed, 70 insertions(+), 52 deletions(-)


base-commit: 7814e8a05a59c0cf5fb186661d1551c75d1299b5
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-830%2Fnewren%2Fmem_pool_api-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-830/newren/mem_pool_api-v3
Pull-Request: https://github.com/git/git/pull/830

Range-diff vs v2:

 1:  6d679c5b46 ! 1:  e7f6bf8a8c mem-pool: add convenience functions for xstrdup and xstrndup
     @@ Metadata
      Author: Elijah Newren <newren@gmail.com>
      
       ## Commit message ##
     -    mem-pool: add convenience functions for xstrdup and xstrndup
     +    mem-pool: add convenience functions for strdup and strndup
      
     -    fast-import had a special mem_pool_xstrdup() convenience function that I
     +    fast-import had a special mem_pool_strdup() 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()
     +    it from fast-import to mem-pool, and also add a mem_pool_strndup()
          while at it that I also want to use.
      
          Signed-off-by: Elijah Newren <newren@gmail.com>
     @@ fast-import.c: static struct branch *new_branch(const char *name)
       
       	b = mem_pool_calloc(&fi_mem_pool, 1, sizeof(struct branch));
      -	b->name = pool_strdup(name);
     -+	b->name = mem_pool_xstrdup(&fi_mem_pool, name);
     ++	b->name = mem_pool_strdup(&fi_mem_pool, name);
       	b->table_next_branch = branch_table[hc];
       	b->branch_tree.versions[0].mode = S_IFDIR;
       	b->branch_tree.versions[1].mode = S_IFDIR;
     @@ fast-import.c: static void parse_new_tag(const char *arg)
       	t = mem_pool_alloc(&fi_mem_pool, sizeof(struct tag));
       	memset(t, 0, sizeof(struct tag));
      -	t->name = pool_strdup(arg);
     -+	t->name = mem_pool_xstrdup(&fi_mem_pool, arg);
     ++	t->name = mem_pool_strdup(&fi_mem_pool, arg);
       	if (last_tag)
       		last_tag->next_tag = t;
       	else
     @@ mem-pool.c: void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_
       	return r;
       }
       
     -+char *mem_pool_xstrdup(struct mem_pool *pool, const char *str)
     ++char *mem_pool_strdup(struct mem_pool *pool, const char *str)
      +{
      +	size_t len = strlen(str) + 1;
      +	char *ret = mem_pool_alloc(pool, len);
      +
     -+	if (!ret)
     -+		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)
     ++char *mem_pool_strndup(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(_("mem_pool_xstrndup: out of memory"));
     ++	char *p = memchr(str, '\0', len);
     ++	size_t actual_len = (p ? p - str : len);
     ++	char *ret = mem_pool_alloc(pool, actual_len+1);
      +
     -+	ret[minlen] = '\0';
     -+	return memcpy(ret, str, minlen);
     ++	ret[actual_len] = '\0';
     ++	return memcpy(ret, str, actual_len);
      +}
      +
       int mem_pool_contains(struct mem_pool *mem_pool, void *mem)
     @@ mem-pool.h: void *mem_pool_alloc(struct mem_pool *pool, size_t len);
      +/*
      + * Allocate memory from the memory pool and copy str into it.
      + */
     -+char *mem_pool_xstrdup(struct mem_pool *pool, const char *str);
     -+char *mem_pool_xstrndup(struct mem_pool *pool, const char *str, size_t len);
     ++char *mem_pool_strdup(struct mem_pool *pool, const char *str);
     ++char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len);
      +
       /*
        * Move the memory associated with the 'src' pool to the 'dst' pool. The 'src'
 2:  e04ba96b22 = 2:  65f334f5cf mem-pool: use more standard initialization and finalization
 3:  616402c64e ! 3:  09976779c3 mem-pool: use consistent pool variable name
     @@ mem-pool.c: void *mem_pool_alloc(struct mem_pool *mem_pool, size_t len)
       	memset(r, 0, len);
       	return r;
       }
     -@@ mem-pool.c: char *mem_pool_xstrndup(struct mem_pool *pool, const char *str, size_t len)
     - 	return memcpy(ret, str, minlen);
     +@@ mem-pool.c: char *mem_pool_strndup(struct mem_pool *pool, const char *str, size_t len)
     + 	return memcpy(ret, str, actual_len);
       }
       
      -int mem_pool_contains(struct mem_pool *mem_pool, void *mem)

-- 
gitgitgadget

  parent reply	other threads:[~2020-08-15 22:07 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
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   ` Elijah Newren via GitGitGadget [this message]
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

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

  git send-email \
    --in-reply-to=pull.830.v3.git.git.1597513078.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=l.s.r@web.de \
    --cc=matheus.bernardino@usp.br \
    --cc=newren@gmail.com \
    --cc=sunshine@sunshineco.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.