mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
reftable/writer: handle allocation failures in reftable_new_writer()
Handle allocation failures in `reftable_new_writer()`. Adapt the function to return an error code to return such failures. While at it, rename it to match our code style as we have to touch up every callsite anyway. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
b680af2dba
commit
74d1c18757
@@ -117,13 +117,17 @@ static void writer_reinit_block_writer(struct reftable_writer *w, uint8_t typ)
|
||||
w->block_writer->restart_interval = w->opts.restart_interval;
|
||||
}
|
||||
|
||||
struct reftable_writer *
|
||||
reftable_new_writer(ssize_t (*writer_func)(void *, const void *, size_t),
|
||||
int (*flush_func)(void *),
|
||||
void *writer_arg, const struct reftable_write_options *_opts)
|
||||
int reftable_writer_new(struct reftable_writer **out,
|
||||
ssize_t (*writer_func)(void *, const void *, size_t),
|
||||
int (*flush_func)(void *),
|
||||
void *writer_arg, const struct reftable_write_options *_opts)
|
||||
{
|
||||
struct reftable_writer *wp = reftable_calloc(1, sizeof(*wp));
|
||||
struct reftable_write_options opts = {0};
|
||||
struct reftable_writer *wp;
|
||||
|
||||
wp = reftable_calloc(1, sizeof(*wp));
|
||||
if (!wp)
|
||||
return REFTABLE_OUT_OF_MEMORY_ERROR;
|
||||
|
||||
if (_opts)
|
||||
opts = *_opts;
|
||||
@@ -134,13 +138,19 @@ reftable_new_writer(ssize_t (*writer_func)(void *, const void *, size_t),
|
||||
strbuf_init(&wp->block_writer_data.last_key, 0);
|
||||
strbuf_init(&wp->last_key, 0);
|
||||
REFTABLE_CALLOC_ARRAY(wp->block, opts.block_size);
|
||||
if (!wp->block) {
|
||||
reftable_free(wp);
|
||||
return REFTABLE_OUT_OF_MEMORY_ERROR;
|
||||
}
|
||||
wp->write = writer_func;
|
||||
wp->write_arg = writer_arg;
|
||||
wp->opts = opts;
|
||||
wp->flush = flush_func;
|
||||
writer_reinit_block_writer(wp, BLOCK_TYPE_REF);
|
||||
|
||||
return wp;
|
||||
*out = wp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reftable_writer_set_limits(struct reftable_writer *w, uint64_t min,
|
||||
|
||||
Reference in New Issue
Block a user