From 74177f891d463e1705081612b3b8e0529d0a43e5 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Sat, 23 Nov 2019 01:46:12 -0300 Subject: [PATCH] Fixing cmc_alloc_node_default error --- src/cmc/bidimap.h | 4 +++- src/cmc/deque.h | 4 +++- src/cmc/hashmap.h | 4 +++- src/cmc/hashset.h | 4 +++- src/cmc/heap.h | 4 +++- src/cmc/intervalheap.h | 4 +++- src/cmc/linkedlist.h | 4 +++- src/cmc/list.h | 4 +++- src/cmc/multimap.h | 4 +++- src/cmc/multiset.h | 4 +++- src/cmc/queue.h | 4 +++- src/cmc/sortedlist.h | 4 +++- src/cmc/stack.h | 4 +++- src/cmc/treemap.h | 4 +++- src/cmc/treeset.h | 4 +++- tests/Makefile | 4 ++-- tests/sep/collections.c | 17 ++++++++++++++ tests/sep/collections.h | 17 ++++++++++++++ tests/sep/main.c | 49 ++++++++++++++++++++++------------------- tests/sep/sep.c | 16 -------------- tests/sep/sep.h | 16 -------------- 21 files changed, 107 insertions(+), 72 deletions(-) create mode 100644 tests/sep/collections.c create mode 100644 tests/sep/collections.h delete mode 100644 tests/sep/sep.c delete mode 100644 tests/sep/sep.h diff --git a/src/cmc/bidimap.h b/src/cmc/bidimap.h index 6c984ca..7b12a4d 100644 --- a/src/cmc/bidimap.h +++ b/src/cmc/bidimap.h @@ -61,7 +61,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/deque.h b/src/cmc/deque.h index 71b0e89..2800733 100644 --- a/src/cmc/deque.h +++ b/src/cmc/deque.h @@ -66,7 +66,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/hashmap.h b/src/cmc/hashmap.h index c5fa4a2..6e23ee1 100644 --- a/src/cmc/hashmap.h +++ b/src/cmc/hashmap.h @@ -54,7 +54,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/hashset.h b/src/cmc/hashset.h index 3485bbd..e1b0c1a 100644 --- a/src/cmc/hashset.h +++ b/src/cmc/hashset.h @@ -54,7 +54,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/heap.h b/src/cmc/heap.h index 7893a2e..7d3cc06 100644 --- a/src/cmc/heap.h +++ b/src/cmc/heap.h @@ -65,7 +65,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/intervalheap.h b/src/cmc/intervalheap.h index 3616cb1..2e8dc4d 100644 --- a/src/cmc/intervalheap.h +++ b/src/cmc/intervalheap.h @@ -56,7 +56,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/linkedlist.h b/src/cmc/linkedlist.h index f03b26b..da060a5 100644 --- a/src/cmc/linkedlist.h +++ b/src/cmc/linkedlist.h @@ -63,7 +63,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/list.h b/src/cmc/list.h index 094f6ec..9a31d93 100644 --- a/src/cmc/list.h +++ b/src/cmc/list.h @@ -78,7 +78,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/multimap.h b/src/cmc/multimap.h index c93eab7..efcd532 100644 --- a/src/cmc/multimap.h +++ b/src/cmc/multimap.h @@ -78,7 +78,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/multiset.h b/src/cmc/multiset.h index 79f3c83..d19efff 100644 --- a/src/cmc/multiset.h +++ b/src/cmc/multiset.h @@ -56,7 +56,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/queue.h b/src/cmc/queue.h index ee92cd8..daca648 100644 --- a/src/cmc/queue.h +++ b/src/cmc/queue.h @@ -78,7 +78,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/sortedlist.h b/src/cmc/sortedlist.h index e67339c..6fd6741 100644 --- a/src/cmc/sortedlist.h +++ b/src/cmc/sortedlist.h @@ -57,7 +57,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/stack.h b/src/cmc/stack.h index c0a1a58..a9f47c4 100644 --- a/src/cmc/stack.h +++ b/src/cmc/stack.h @@ -63,7 +63,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/treemap.h b/src/cmc/treemap.h index cb936d6..8090420 100644 --- a/src/cmc/treemap.h +++ b/src/cmc/treemap.h @@ -54,7 +54,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/src/cmc/treeset.h b/src/cmc/treeset.h index 163efda..294ed53 100644 --- a/src/cmc/treeset.h +++ b/src/cmc/treeset.h @@ -54,7 +54,9 @@ struct cmc_alloc_node void *(*calloc)(size_t, size_t); void *(*realloc)(void *, size_t); void (*free)(void *); -} cmc_alloc_node_default = {malloc, calloc, realloc, free}; +}; + +static struct cmc_alloc_node cmc_alloc_node_default = {malloc, calloc, realloc, free}; #endif /* CMC_CORE_H */ diff --git a/tests/Makefile b/tests/Makefile index 25dfa00..84e8804 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -11,9 +11,9 @@ main: FORCE ./contains.exe $(CC) types.c -o types.exe $(CFLAGS) ./types.exe - $(CC) -c ./sep/sep.c -o ./sep/sep.o $(CFLAGS) + $(CC) -c ./sep/collections.c -o ./sep/collections.o $(CFLAGS) $(CC) -c ./sep/main.c -o ./sep/main.o $(CFLAGS) - $(CC) ./sep/sep.o ./sep/main.o -o ./sep/sep.exe + $(CC) ./sep/collections.o ./sep/main.o -o ./sep/sep.exe ./sep/sep.exe dev: main diff --git a/tests/sep/collections.c b/tests/sep/collections.c new file mode 100644 index 0000000..0063216 --- /dev/null +++ b/tests/sep/collections.c @@ -0,0 +1,17 @@ +#include "collections.h" + +CMC_COLLECTION_GENERATE_SOURCE( BIDIMAP, bm, bmap, int, int) +CMC_COLLECTION_GENERATE_SOURCE( DEQUE, d, deque, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( HASHMAP, hm, hmap, int, int) +CMC_COLLECTION_GENERATE_SOURCE( HASHSET, hs, hset, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( HEAP, h, heap, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE(INTERVALHEAP, ih, iheap, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( LINKEDLIST, ll, linked, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( LIST, l, list, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( MULTIMAP, mm, mmap, int, int) +CMC_COLLECTION_GENERATE_SOURCE( MULTISET, ms, mset, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( QUEUE, q, queue, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( SORTEDLIST, sl, slist, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( STACK, s, stack, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( TREESET, ts, tset, /* K */, int) +CMC_COLLECTION_GENERATE_SOURCE( TREEMAP, tm, tmap, int, int) diff --git a/tests/sep/collections.h b/tests/sep/collections.h new file mode 100644 index 0000000..966a307 --- /dev/null +++ b/tests/sep/collections.h @@ -0,0 +1,17 @@ +#include "../../src/macro_collections.h" + +CMC_COLLECTION_GENERATE_HEADER( BIDIMAP, bm, bmap, int, int) +CMC_COLLECTION_GENERATE_HEADER( DEQUE, d, deque, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( HASHMAP, hm, hmap, int, int) +CMC_COLLECTION_GENERATE_HEADER( HASHSET, hs, hset, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( HEAP, h, heap, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER(INTERVALHEAP, ih, iheap, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( LINKEDLIST, ll, linked, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( LIST, l, list, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( MULTIMAP, mm, mmap, int, int) +CMC_COLLECTION_GENERATE_HEADER( MULTISET, ms, mset, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( QUEUE, q, queue, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( SORTEDLIST, sl, slist, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( STACK, s, stack, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( TREESET, ts, tset, /* K */, int) +CMC_COLLECTION_GENERATE_HEADER( TREEMAP, tm, tmap, int, int) diff --git a/tests/sep/main.c b/tests/sep/main.c index 74a231c..4b86695 100644 --- a/tests/sep/main.c +++ b/tests/sep/main.c @@ -1,4 +1,4 @@ -#include "sep.h" +#include "collections.h" #include int intcmp(int a, int b) @@ -20,38 +20,41 @@ size_t inthash(int t) int main(void) { - struct list *l = l_new(1000); - struct stack *s = s_new(1000); - struct queue *q = q_new(1000); - struct deque *d = d_new(1000); - struct linked *ll = ll_new(); - struct heap *h = h_new(1000, cmc_max_heap, intcmp); - struct tset *ts = ts_new(intcmp); - struct tmap *tm = tm_new(intcmp); - struct hset *hs = hs_new(1000, 0.6, intcmp, inthash); - struct hmap *hm = hm_new(1000, 0.6, intcmp, inthash); - struct iheap *ih = ih_new(1000, intcmp); - struct mmap *mm = mm_new(1000, 0.8, intcmp, inthash); - struct mset *ms = ms_new(1000, 0.6, intcmp, inthash); + struct bmap *bm = bm_new_custom(100, 0.7, NULL, NULL, NULL, NULL, NULL, NULL); + struct deque *d = d_new_custom(100, NULL, NULL); + struct hmap *hm = hm_new_custom(100, 0.6, NULL, NULL, NULL, NULL); + struct hset *hs = hs_new_custom(100, 0.6, NULL, NULL, NULL, NULL); + struct heap *h = h_new_custom(100, cmc_max_heap, NULL, NULL, NULL); + struct iheap *ih = ih_new_custom(100, NULL, NULL, NULL); + struct linked *ll = ll_new_custom(NULL, NULL); + struct list *l = l_new_custom(100, NULL, NULL); + struct mmap *mm = mm_new_custom(100, 0.8, NULL, NULL, NULL, NULL); + struct mset *ms = ms_new_custom(100, 0.6, NULL, NULL, NULL, NULL); + struct queue *q = q_new_custom(100, NULL, NULL); + struct slist *sl = sl_new_custom(100, NULL, NULL, NULL); + struct stack *s = s_new_custom(100, NULL, NULL); + struct tmap *tm = tm_new_custom(NULL, NULL, NULL); + struct tset *ts = ts_new_custom(NULL, NULL, NULL); printf("+--------------------------------------------------+\n"); printf("| Separate Header and Source is Working |\n"); printf("+--------------------------------------------------+\n"); - l_free(l, NULL); - ll_free(ll, NULL); - s_free(s, NULL); - q_free(q, NULL); + bm_free(bm, NULL); d_free(d, NULL); - h_free(h, NULL); - ts_free(ts, NULL); - tm_free(tm, NULL); - hs_free(hs, NULL); hm_free(hm, NULL); - + hs_free(hs, NULL); + h_free(h, NULL); ih_free(ih, NULL); + ll_free(ll, NULL); + l_free(l, NULL); mm_free(mm, NULL); ms_free(ms, NULL); + q_free(q, NULL); + sl_free(sl, NULL); + s_free(s, NULL); + tm_free(tm, NULL); + ts_free(ts, NULL); return 0; } diff --git a/tests/sep/sep.c b/tests/sep/sep.c deleted file mode 100644 index e42664e..0000000 --- a/tests/sep/sep.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "sep.h" - -CMC_COLLECTION_GENERATE_SOURCE(LIST, l, list, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE(STACK, s, stack, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE(QUEUE, q, queue, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE(DEQUE, d, deque, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE(LINKEDLIST, ll, linked, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE(HEAP, h, heap, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE(TREESET, ts, tset, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE(TREEMAP, tm, tmap, int, int) -CMC_COLLECTION_GENERATE_SOURCE(HASHSET, hs, hset, /* K */, int) -CMC_COLLECTION_GENERATE_SOURCE(HASHMAP, hm, hmap, int, int) - -CMC_COLLECTION_GENERATE_SOURCE(INTERVALHEAP, ih, iheap, , int) -CMC_COLLECTION_GENERATE_SOURCE(MULTIMAP, mm, mmap, int, int) -CMC_COLLECTION_GENERATE_SOURCE(MULTISET, ms, mset, , int) diff --git a/tests/sep/sep.h b/tests/sep/sep.h deleted file mode 100644 index 649b844..0000000 --- a/tests/sep/sep.h +++ /dev/null @@ -1,16 +0,0 @@ -#include "../../src/macro_collections.h" - -CMC_COLLECTION_GENERATE_HEADER(LIST, l, list, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER(STACK, s, stack, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER(QUEUE, q, queue, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER(DEQUE, d, deque, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER(LINKEDLIST, ll, linked, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER(HEAP, h, heap, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER(TREESET, ts, tset, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER(TREEMAP, tm, tmap, int, int) -CMC_COLLECTION_GENERATE_HEADER(HASHSET, hs, hset, /* K */, int) -CMC_COLLECTION_GENERATE_HEADER(HASHMAP, hm, hmap, int, int) - -CMC_COLLECTION_GENERATE_HEADER(INTERVALHEAP, ih, iheap, , int) -CMC_COLLECTION_GENERATE_HEADER(MULTIMAP, mm, mmap, int, int) -CMC_COLLECTION_GENERATE_HEADER(MULTISET, ms, mset, , int)