From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Carlo Marcelo Arenas Belón" <carenas@gmail.com>,
"Han-Wen Nienhuys" <hanwen@google.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [RFC PATCH 1/2] reftable: remove the "return_block" abstraction
Date: Fri, 15 Apr 2022 12:21:35 +0200 [thread overview]
Message-ID: <RFC-patch-1.2-76ed86bf88c-20220415T101740Z-avarab@gmail.com> (raw)
In-Reply-To: <RFC-cover-0.2-00000000000-20220415T101740Z-avarab@gmail.com>
This abstraction added in 1214aa841bc (reftable: add blocksource, an
abstraction for random access reads, 2021-10-07) has the caller
provide a "blockp->data", so there's not point in having the vtable
have a custom free() function.
In addition this had what looked like a poor man's SANITIZE=address
doing a memset() to 0xff just before the data was free'd.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
reftable/block.c | 4 +---
reftable/blocksource.c | 28 +---------------------------
reftable/reftable-blocksource.h | 2 --
3 files changed, 2 insertions(+), 32 deletions(-)
diff --git a/reftable/block.c b/reftable/block.c
index 34d4d073692..bb17cc32372 100644
--- a/reftable/block.c
+++ b/reftable/block.c
@@ -442,9 +442,7 @@ void block_writer_release(struct block_writer *bw)
void reftable_block_done(struct reftable_block *blockp)
{
- struct reftable_block_source source = blockp->source;
- if (blockp && source.ops)
- source.ops->return_block(source.arg, blockp);
+ FREE_AND_NULL(blockp->data);
blockp->data = NULL;
blockp->len = 0;
blockp->source.ops = NULL;
diff --git a/reftable/blocksource.c b/reftable/blocksource.c
index 2605371c28d..d9e47cc316b 100644
--- a/reftable/blocksource.c
+++ b/reftable/blocksource.c
@@ -13,12 +13,6 @@ license that can be found in the LICENSE file or at
#include "reftable-blocksource.h"
#include "reftable-error.h"
-static void strbuf_return_block(void *b, struct reftable_block *dest)
-{
- memset(dest->data, 0xff, dest->len);
- reftable_free(dest->data);
-}
-
static void strbuf_close(void *b)
{
}
@@ -42,7 +36,6 @@ static uint64_t strbuf_size(void *b)
static struct reftable_block_source_vtable strbuf_vtable = {
.size = &strbuf_size,
.read_block = &strbuf_read_block,
- .return_block = &strbuf_return_block,
.close = &strbuf_close,
};
@@ -54,19 +47,7 @@ void block_source_from_strbuf(struct reftable_block_source *bs,
bs->arg = buf;
}
-static void malloc_return_block(void *b, struct reftable_block *dest)
-{
- memset(dest->data, 0xff, dest->len);
- reftable_free(dest->data);
-}
-
-static struct reftable_block_source_vtable malloc_vtable = {
- .return_block = &malloc_return_block,
-};
-
-static struct reftable_block_source malloc_block_source_instance = {
- .ops = &malloc_vtable,
-};
+static struct reftable_block_source malloc_block_source_instance = { 0 };
struct reftable_block_source malloc_block_source(void)
{
@@ -83,12 +64,6 @@ static uint64_t file_size(void *b)
return ((struct file_block_source *)b)->size;
}
-static void file_return_block(void *b, struct reftable_block *dest)
-{
- memset(dest->data, 0xff, dest->len);
- reftable_free(dest->data);
-}
-
static void file_close(void *b)
{
int fd = ((struct file_block_source *)b)->fd;
@@ -115,7 +90,6 @@ static int file_read_block(void *v, struct reftable_block *dest, uint64_t off,
static struct reftable_block_source_vtable file_vtable = {
.size = &file_size,
.read_block = &file_read_block,
- .return_block = &file_return_block,
.close = &file_close,
};
diff --git a/reftable/reftable-blocksource.h b/reftable/reftable-blocksource.h
index 5aa3990a573..7b7cb280b73 100644
--- a/reftable/reftable-blocksource.h
+++ b/reftable/reftable-blocksource.h
@@ -35,8 +35,6 @@ struct reftable_block_source_vtable {
beyond the end of the block */
int (*read_block)(void *source, struct reftable_block *dest,
uint64_t off, uint32_t size);
- /* mark the block as read; may return the data back to malloc */
- void (*return_block)(void *source, struct reftable_block *blockp);
/* release all resources associated with the block source */
void (*close)(void *source);
--
2.36.0.rc2.863.gfc2c14e3b91
next prev parent reply other threads:[~2022-04-15 10:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-15 7:02 [PATCH] reftable: avoid undefined behaviour breaking t0032 Carlo Marcelo Arenas Belón
2022-04-15 7:10 ` Junio C Hamano
2022-04-15 8:30 ` [PATCH v2] " Carlo Marcelo Arenas Belón
2022-04-15 10:21 ` [RFC PATCH 0/2] reftable: remove poor man's SANITIZE=address, fix a memset() bug Ævar Arnfjörð Bjarmason
2022-04-15 10:21 ` Ævar Arnfjörð Bjarmason [this message]
2022-04-15 13:37 ` [RFC PATCH 1/2] reftable: remove the "return_block" abstraction René Scharfe
2022-04-25 9:57 ` Han-Wen Nienhuys
2022-04-25 17:30 ` Junio C Hamano
2022-04-15 10:21 ` [RFC PATCH 2/2] reftable: don't memset() a NULL from failed malloc() Ævar Arnfjörð Bjarmason
2022-04-15 13:37 ` René Scharfe
2022-04-15 13:53 ` Ævar Arnfjörð Bjarmason
2022-04-15 14:30 ` Phillip Wood
2022-04-15 15:20 ` Ævar Arnfjörð Bjarmason
2022-04-15 16:23 ` Junio C Hamano
2022-04-25 10:30 ` Han-Wen Nienhuys
2022-04-25 10:18 ` [PATCH v2] reftable: avoid undefined behaviour breaking t0032 Han-Wen Nienhuys
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=RFC-patch-1.2-76ed86bf88c-20220415T101740Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=carenas@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hanwen@google.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).