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>,
Elijah Newren <newren@gmail.com>
Subject: [PATCH v2 0/3] Extend and add a little more generalization to the mem_pool API
Date: Fri, 14 Aug 2020 06:00:17 +0000 [thread overview]
Message-ID: <pull.830.v2.git.git.1597384820.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.830.git.git.1597374135.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 v1:
* Made the error message tweaks suggested by Eric
* Although mem_pool_init() intialized all members manually, add a memset()
to 0 for future-proofing, as suggested by Junio.
* Use 'pool' instead of 'mem_pool' in patch 2 so that patch 3 doesn't have
to change as much (as suggested by Junio).
Also, Matheus said he'd rebase his parallel-checkout RFC series (next yet in
next or seen) on top of mine to avoid the semantic conflict.
Elijah Newren (3):
mem-pool: add convenience functions for xstrdup and xstrndup
mem-pool: use more standard initialization and finalization
mem-pool: use consistent pool variable name
fast-import.c | 12 ++-------
mem-pool.c | 74 ++++++++++++++++++++++++++++++++-------------------
mem-pool.h | 14 +++++++---
read-cache.c | 21 +++++++++------
split-index.c | 6 +++--
5 files changed, 75 insertions(+), 52 deletions(-)
base-commit: 7814e8a05a59c0cf5fb186661d1551c75d1299b5
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-830%2Fnewren%2Fmem_pool_api-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-830/newren/mem_pool_api-v2
Pull-Request: https://github.com/git/git/pull/830
Range-diff vs v1:
1: eae8b2923f ! 1: 6d679c5b46 mem-pool: add convenience functions for xstrdup and xstrndup
@@ mem-pool.c: void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_
+ char *ret = mem_pool_alloc(pool, len);
+
+ if (!ret)
-+ die("Out of memory, mem_pool_xstrdup failed");
++ die(_("mem_pool_xstrdup: out of memory"));
+
+ return memcpy(ret, str, len);
+}
@@ mem-pool.c: void *mem_pool_calloc(struct mem_pool *mem_pool, size_t count, size_
+ char *ret = mem_pool_alloc(pool, minlen+1);
+
+ if (!ret)
-+ die("Out of memory, mem_pool_xstrndup failed");
++ die(_("mem_pool_xstrndup: out of memory"));
+
+ ret[minlen] = '\0';
+ return memcpy(ret, str, minlen);
2: f13a52055c ! 2: e04ba96b22 mem-pool: use more standard initialization and finalization
@@ mem-pool.c: static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_po
}
-void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size)
-+void mem_pool_init(struct mem_pool *mem_pool, size_t initial_size)
++void mem_pool_init(struct mem_pool *pool, size_t initial_size)
{
- struct mem_pool *pool;
-
@@ mem-pool.c: static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_po
-
- pool = xcalloc(1, sizeof(*pool));
-
-- pool->block_alloc = BLOCK_GROWTH_SIZE;
-+ mem_pool->mp_block = NULL;
-+ mem_pool->pool_alloc = 0;
-+ mem_pool->block_alloc = BLOCK_GROWTH_SIZE;
++ memset(pool, 0, sizeof(*pool));
+ pool->block_alloc = BLOCK_GROWTH_SIZE;
if (initial_size > 0)
-- mem_pool_alloc_block(pool, initial_size, NULL);
+ mem_pool_alloc_block(pool, initial_size, NULL);
-
- *mem_pool = pool;
-+ mem_pool_alloc_block(mem_pool, initial_size, NULL);
}
void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
@@ mem-pool.h: struct mem_pool {
* Initialize mem_pool with specified initial size.
*/
-void mem_pool_init(struct mem_pool **mem_pool, size_t initial_size);
-+void mem_pool_init(struct mem_pool *mem_pool, size_t initial_size);
++void mem_pool_init(struct mem_pool *pool, size_t initial_size);
/*
- * Discard a memory pool and free all the memory it is responsible for.
3: 62c2479fe6 ! 3: 616402c64e mem-pool: use consistent pool variable name
@@ mem-pool.c: static struct mp_block *mem_pool_alloc_block(struct mem_pool *mem_po
}
return p;
- }
-
--void mem_pool_init(struct mem_pool *mem_pool, size_t initial_size)
-+void mem_pool_init(struct mem_pool *pool, size_t initial_size)
- {
-- mem_pool->mp_block = NULL;
-- mem_pool->pool_alloc = 0;
-- mem_pool->block_alloc = BLOCK_GROWTH_SIZE;
-+ pool->mp_block = NULL;
-+ pool->pool_alloc = 0;
-+ pool->block_alloc = BLOCK_GROWTH_SIZE;
-
- if (initial_size > 0)
-- mem_pool_alloc_block(mem_pool, initial_size, NULL);
-+ mem_pool_alloc_block(pool, initial_size, NULL);
+@@ mem-pool.c: void mem_pool_init(struct mem_pool *pool, size_t initial_size)
+ mem_pool_alloc_block(pool, initial_size, NULL);
}
-void mem_pool_discard(struct mem_pool *mem_pool, int invalidate_memory)
@@ mem-pool.c: char *mem_pool_xstrndup(struct mem_pool *pool, const char *str, size
return 1;
## mem-pool.h ##
-@@ mem-pool.h: struct mem_pool {
- /*
- * Initialize mem_pool with specified initial size.
- */
--void mem_pool_init(struct mem_pool *mem_pool, size_t initial_size);
-+void mem_pool_init(struct mem_pool *pool, size_t initial_size);
-
+@@ mem-pool.h: void mem_pool_init(struct mem_pool *pool, size_t initial_size);
/*
* Discard all the memory the memory pool is responsible for.
*/
--
gitgitgadget
next prev parent reply other threads:[~2020-08-14 6:00 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 ` Elijah Newren via GitGitGadget [this message]
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=pull.830.v2.git.git.1597384820.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--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.
Code repositories for project(s) associated with this public 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).