Skip to content

Commit 0067c2a

Browse files
committed
Mark private/static functions
1 parent 3481661 commit 0067c2a

File tree

4 files changed

+29
-15
lines changed

4 files changed

+29
-15
lines changed

Makefile

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $(TARGET): $(OBJS) $(MAIN_OBJS)
2929
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
3030

3131
.PHONY: test-build
32-
test-build: CFLAGS += -Wno-implicit-function-declaration -g
32+
test-build: CFLAGS += -DUNIT_TEST -Wno-implicit-function-declaration -g
3333
test-build: $(TESTS_TARGET)
3434

3535
.PHONY: test
@@ -100,12 +100,18 @@ valgrind:
100100

101101
.PHONY: check
102102
check:
103-
cppcheck --enable=all --inline-suppr --check-level=exhaustive \
104-
--suppress=missingIncludeSystem \
105-
--suppress=constParameterPointer \
106-
--suppress=constVariablePointer \
107-
--suppress=variableScope \
108-
.
103+
cppcheck \
104+
--language=c \
105+
-UUNIT_TEST \
106+
--safety \
107+
--inline-suppr \
108+
--enable=all \
109+
--check-level=exhaustive \
110+
--suppress=missingIncludeSystem \
111+
--suppress=constParameterPointer \
112+
--suppress=constVariablePointer \
113+
--suppress=variableScope \
114+
.
109115

110116
.PHONY: clean
111117
clean:

hashmap.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
#include "alloc.h"
77
#include "hashmap.h"
8+
#include "private.h"
89

9-
static int hashmap_ensure_size(hashmap *hm);
10-
static int hashmap_resize(hashmap *hm);
11-
static uint32_t _hashmap_find_empty_index(hashmap *hm, uint32_t hash);
10+
private int hashmap_ensure_size(hashmap *hm);
11+
private int hashmap_resize(hashmap *hm);
12+
private uint32_t _hashmap_find_empty_index(hashmap *hm, uint32_t hash);
13+
private int32_t _hashmap_find_index(hashmap *hm, char *key, uint32_t hash);
1214

1315
/**
1416
* Allocate and initialize a new hashmap with default capacity
@@ -167,7 +169,7 @@ int hashmap_set(hashmap *hm, char *key, int value)
167169
*
168170
* Return: 0 on success, error code on failure
169171
*/
170-
static int hashmap_ensure_size(hashmap *hm)
172+
private int hashmap_ensure_size(hashmap *hm)
171173
{
172174
int result;
173175
if (hm->count >= USABLE_FRACTION(hm->length)) {
@@ -188,7 +190,7 @@ static int hashmap_ensure_size(hashmap *hm)
188190
*
189191
* Return: 0 on success, error code on failure
190192
*/
191-
static int hashmap_resize(hashmap *hm)
193+
private int hashmap_resize(hashmap *hm)
192194
{
193195
hashmap_item *item;
194196
hashmap_item **old_items = hm->items;
@@ -299,7 +301,7 @@ hashmap_item *hashmap_get(hashmap *hm, char *key)
299301
*
300302
* Return: Non-negative index if found, -E_HASHMAP_KEY_NOT_FOUND if not found
301303
*/
302-
int32_t _hashmap_find_index(hashmap *hm, char *key, uint32_t hash)
304+
private int32_t _hashmap_find_index(hashmap *hm, char *key, uint32_t hash)
303305
{
304306
uint32_t mask = hm->length - 1;
305307
uint32_t i = hash & mask;
@@ -336,7 +338,7 @@ int32_t _hashmap_find_index(hashmap *hm, char *key, uint32_t hash)
336338
*
337339
* Return: Index of empty/deleted slot, or -E_HASHMAP_KEY_NOT_FOUND if table is full
338340
*/
339-
static uint32_t _hashmap_find_empty_index(hashmap *hm, uint32_t hash)
341+
private uint32_t _hashmap_find_empty_index(hashmap *hm, uint32_t hash)
340342
{
341343
uint32_t mask = hm->length - 1;
342344
uint32_t i = hash & mask;

hashmap.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,4 @@ uint32_t hashmap_get_length(hashmap *hm);
3737
int hashmap_set(hashmap*, char *key, int value);
3838
hashmap_item *hashmap_get(hashmap *hm, char *key);
3939
int hashmap_delete(hashmap *hm, char *key);
40-
int32_t _hashmap_find_index(hashmap *hm, char *key, uint32_t hash);
4140
unsigned long hash(char *s);

private.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
#ifdef UNIT_TEST
4+
# define private
5+
#else
6+
# define private static
7+
#endif

0 commit comments

Comments
 (0)