refs/reftable: print errors on compaction failure
[alt-git.git] / reftable / publicbasics.c
blob44b84a125e43b3f0de9460b019854e22835d39e6
1 /*
2 Copyright 2020 Google LLC
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
7 */
9 #include "system.h"
10 #include "reftable-malloc.h"
12 #include "basics.h"
14 static void *(*reftable_malloc_ptr)(size_t sz);
15 static void *(*reftable_realloc_ptr)(void *, size_t);
16 static void (*reftable_free_ptr)(void *);
18 void *reftable_malloc(size_t sz)
20 if (reftable_malloc_ptr)
21 return (*reftable_malloc_ptr)(sz);
22 return malloc(sz);
25 void *reftable_realloc(void *p, size_t sz)
27 if (reftable_realloc_ptr)
28 return (*reftable_realloc_ptr)(p, sz);
29 return realloc(p, sz);
32 void reftable_free(void *p)
34 if (reftable_free_ptr)
35 reftable_free_ptr(p);
36 else
37 free(p);
40 void *reftable_calloc(size_t nelem, size_t elsize)
42 size_t sz = st_mult(nelem, elsize);
43 void *p = reftable_malloc(sz);
44 memset(p, 0, sz);
45 return p;
48 void reftable_set_alloc(void *(*malloc)(size_t),
49 void *(*realloc)(void *, size_t), void (*free)(void *))
51 reftable_malloc_ptr = malloc;
52 reftable_realloc_ptr = realloc;
53 reftable_free_ptr = free;
56 int hash_size(uint32_t id)
58 switch (id) {
59 case 0:
60 case GIT_SHA1_FORMAT_ID:
61 return GIT_SHA1_RAWSZ;
62 case GIT_SHA256_FORMAT_ID:
63 return GIT_SHA256_RAWSZ;
65 abort();