summaryrefslogtreecommitdiff
path: root/reftable/basics.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-02-12 13:16:10 -0800
committerJunio C Hamano <gitster@pobox.com>2024-02-12 13:16:10 -0800
commitf424d7c33df373fb8eb4c9dc63ab6dc24de24aa5 (patch)
tree0a4a0ce4fd72be818d68f736c9eb98a42edbe123 /reftable/basics.h
parentcf4a3bd8f1dc85b20766efe1381511fb4cb15a4f (diff)
parent3ddef475d008b8a705a53e6bb1405bb773ffdc50 (diff)
Merge branch 'ps/reftable-styles'
Code clean-up in various reftable code paths. * ps/reftable-styles: reftable/record: improve semantics when initializing records reftable/merged: refactor initialization of iterators reftable/merged: refactor seeking of records reftable/stack: use `size_t` to track stack length reftable/stack: use `size_t` to track stack slices during compaction reftable/stack: index segments with `size_t` reftable/stack: fix parameter validation when compacting range reftable: introduce macros to allocate arrays reftable: introduce macros to grow arrays
Diffstat (limited to 'reftable/basics.h')
-rw-r--r--reftable/basics.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/reftable/basics.h b/reftable/basics.h
index 096b36862b..91f3533efe 100644
--- a/reftable/basics.h
+++ b/reftable/basics.h
@@ -44,14 +44,27 @@ void parse_names(char *buf, int size, char ***namesp);
int names_equal(char **a, char **b);
/* returns the array size of a NULL-terminated array of strings. */
-int names_length(char **names);
+size_t names_length(char **names);
/* Allocation routines; they invoke the functions set through
* reftable_set_alloc() */
void *reftable_malloc(size_t sz);
void *reftable_realloc(void *p, size_t sz);
void reftable_free(void *p);
-void *reftable_calloc(size_t sz);
+void *reftable_calloc(size_t nelem, size_t elsize);
+
+#define REFTABLE_ALLOC_ARRAY(x, alloc) (x) = reftable_malloc(st_mult(sizeof(*(x)), (alloc)))
+#define REFTABLE_CALLOC_ARRAY(x, alloc) (x) = reftable_calloc((alloc), sizeof(*(x)))
+#define REFTABLE_REALLOC_ARRAY(x, alloc) (x) = reftable_realloc((x), st_mult(sizeof(*(x)), (alloc)))
+#define REFTABLE_ALLOC_GROW(x, nr, alloc) \
+ do { \
+ if ((nr) > alloc) { \
+ alloc = 2 * (alloc) + 1; \
+ if (alloc < (nr)) \
+ alloc = (nr); \
+ REFTABLE_REALLOC_ARRAY(x, alloc); \
+ } \
+ } while (0)
/* Find the longest shared prefix size of `a` and `b` */
struct strbuf;