Skip to content

Commit 57c9090

Browse files
pks-tgitster
authored andcommitted
reftable/blocksource: drop malloc block source
The reftable blocksource provides a generic interface to read blocks via different sources, e.g. from disk or from memory. One of the block sources is the malloc block source, which can in theory read data from memory. We nowadays also have a strbuf block source though, which provides essentially the same functionality with better ergonomics. Adapt the only remaining user of the malloc block source in our tests to use the strbuf block source, instead, and remove the now-unused malloc block source. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a3c387 commit 57c9090

File tree

3 files changed

+2
-23
lines changed

3 files changed

+2
-23
lines changed

reftable/block_test.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ static void test_block_read_write(void)
3434
struct block_reader br = { 0 };
3535
struct block_iter it = BLOCK_ITER_INIT;
3636
int j = 0;
37+
struct strbuf block_data = STRBUF_INIT;
3738
struct strbuf want = STRBUF_INIT;
3839

3940
REFTABLE_CALLOC_ARRAY(block.data, block_size);
4041
block.len = block_size;
41-
block.source = malloc_block_source();
42+
block_source_from_strbuf(&block.source, &block_data);
4243
block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
4344
header_off, hash_size(GIT_SHA1_FORMAT_ID));
4445

reftable/blocksource.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,6 @@ void block_source_from_strbuf(struct reftable_block_source *bs,
5555
bs->arg = buf;
5656
}
5757

58-
static void malloc_return_block(void *b, struct reftable_block *dest)
59-
{
60-
if (dest->len)
61-
memset(dest->data, 0xff, dest->len);
62-
reftable_free(dest->data);
63-
}
64-
65-
static struct reftable_block_source_vtable malloc_vtable = {
66-
.return_block = &malloc_return_block,
67-
};
68-
69-
static struct reftable_block_source malloc_block_source_instance = {
70-
.ops = &malloc_vtable,
71-
};
72-
73-
struct reftable_block_source malloc_block_source(void)
74-
{
75-
return malloc_block_source_instance;
76-
}
77-
7858
struct file_block_source {
7959
uint64_t size;
8060
unsigned char *data;

reftable/blocksource.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,4 @@ struct reftable_block_source;
1717
void block_source_from_strbuf(struct reftable_block_source *bs,
1818
struct strbuf *buf);
1919

20-
struct reftable_block_source malloc_block_source(void);
21-
2220
#endif

0 commit comments

Comments
 (0)