Skip to content

Commit a5a15a4

Browse files
pks-tgitster
authored andcommitted
reftable/basics: merge "publicbasics" into "basics"
The split between "basics" and "publicbasics" is somewhat arbitrary and not in line with how we typically structure code in the reftable library. While we do indeed split up headers into a public and internal part, we don't do that for the compilation unit itself. Furthermore, the declarations for "publicbasics.c" are in "reftable-malloc.h", which isn't in line with our naming schema, either. Fix these inconsistencies by: - Merging "publicbasics.c" into "basics.c". - Renaming "reftable-malloc.h" to "reftable-basics.h" as the public header. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bcd5a40 commit a5a15a4

File tree

6 files changed

+76
-85
lines changed

6 files changed

+76
-85
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2683,7 +2683,6 @@ REFTABLE_OBJS += reftable/error.o
26832683
REFTABLE_OBJS += reftable/block.o
26842684
REFTABLE_OBJS += reftable/blocksource.o
26852685
REFTABLE_OBJS += reftable/iter.o
2686-
REFTABLE_OBJS += reftable/publicbasics.o
26872686
REFTABLE_OBJS += reftable/merged.o
26882687
REFTABLE_OBJS += reftable/pq.o
26892688
REFTABLE_OBJS += reftable/reader.o

reftable/basics.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,49 @@ license that can be found in the LICENSE file or at
77
*/
88

99
#include "basics.h"
10+
#include "reftable-basics.h"
11+
12+
static void *(*reftable_malloc_ptr)(size_t sz);
13+
static void *(*reftable_realloc_ptr)(void *, size_t);
14+
static void (*reftable_free_ptr)(void *);
15+
16+
void *reftable_malloc(size_t sz)
17+
{
18+
if (reftable_malloc_ptr)
19+
return (*reftable_malloc_ptr)(sz);
20+
return malloc(sz);
21+
}
22+
23+
void *reftable_realloc(void *p, size_t sz)
24+
{
25+
if (reftable_realloc_ptr)
26+
return (*reftable_realloc_ptr)(p, sz);
27+
return realloc(p, sz);
28+
}
29+
30+
void reftable_free(void *p)
31+
{
32+
if (reftable_free_ptr)
33+
reftable_free_ptr(p);
34+
else
35+
free(p);
36+
}
37+
38+
void *reftable_calloc(size_t nelem, size_t elsize)
39+
{
40+
size_t sz = st_mult(nelem, elsize);
41+
void *p = reftable_malloc(sz);
42+
memset(p, 0, sz);
43+
return p;
44+
}
45+
46+
void reftable_set_alloc(void *(*malloc)(size_t),
47+
void *(*realloc)(void *, size_t), void (*free)(void *))
48+
{
49+
reftable_malloc_ptr = malloc;
50+
reftable_realloc_ptr = realloc;
51+
reftable_free_ptr = free;
52+
}
1053

1154
void put_be24(uint8_t *out, uint32_t i)
1255
{
@@ -121,3 +164,15 @@ int common_prefix_size(struct strbuf *a, struct strbuf *b)
121164

122165
return p;
123166
}
167+
168+
int hash_size(uint32_t id)
169+
{
170+
switch (id) {
171+
case 0:
172+
case GIT_SHA1_FORMAT_ID:
173+
return GIT_SHA1_RAWSZ;
174+
case GIT_SHA256_FORMAT_ID:
175+
return GIT_SHA256_RAWSZ;
176+
}
177+
abort();
178+
}

reftable/basics.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ license that can be found in the LICENSE file or at
1414
*/
1515

1616
#include "system.h"
17+
#include "reftable-basics.h"
1718

1819
/* Bigendian en/decoding of integers */
1920

@@ -71,4 +72,6 @@ void *reftable_calloc(size_t nelem, size_t elsize);
7172
struct strbuf;
7273
int common_prefix_size(struct strbuf *a, struct strbuf *b);
7374

75+
int hash_size(uint32_t id);
76+
7477
#endif

reftable/publicbasics.c

Lines changed: 0 additions & 66 deletions
This file was deleted.

reftable/reftable-basics.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
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+
*/
8+
9+
#ifndef REFTABLE_BASICS_H
10+
#define REFTABLE_BASICS_H
11+
12+
#include <stddef.h>
13+
14+
/* Overrides the functions to use for memory management. */
15+
void reftable_set_alloc(void *(*malloc)(size_t),
16+
void *(*realloc)(void *, size_t), void (*free)(void *));
17+
18+
#endif

reftable/reftable-malloc.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)