Skip to content

Commit

Permalink
Issue #16 Bug fix vector memory allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
epatrizio committed Feb 27, 2022
1 parent 276217f commit 537485f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ compile_test:
tests/tests_utils.c tests/tests_hash_set.c tests/tests_hash_map.c tests/tests_graph.c tests/main.c \
-lm -L./tests/lib -lctestfmk

run_test:
./cds_test

run_test_debug:
valgrind ./cds_test

compile_example_intl:
gcc -g -o intl -Wall -Wextra \
src/vector.c src/hash_utils.c src/hash_map.c examples/intl/intl.c examples/intl/main.c
Expand All @@ -28,7 +34,7 @@ clean:
# Adjust src/*.c list to compile according to the data structures to be used elsewhere
libcds_static:
mkdir -p lib
gcc -c -Wall -Wextra src/vector.c
gcc -c -Wall -Wextra -O3 src/vector.c
mv vector.o lib/vector.o
cp src/vector.h lib/vector.h
ar -rc lib/libvector.a lib/*.o
Expand Down
16 changes: 8 additions & 8 deletions src/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
vector_struct(T) \
vector_create_sign(T)

#define vector_create_fct(T) \
T##_vector T##_vector_create(size_t capacity) { \
size_t cap = (capacity > 0) ? capacity : MIN_CAPACITY; \
T##_vector v = malloc(sizeof(T##_vector)); \
v->elts = malloc(cap * sizeof(T)); \
v->capacity = cap; \
v->size = 0; \
return v; \
#define vector_create_fct(T) \
T##_vector T##_vector_create(size_t capacity) { \
size_t cap = (capacity > 0) ? capacity : MIN_CAPACITY; \
T##_vector v = malloc(sizeof(struct T##_resizable_array)); \
v->elts = malloc(cap * sizeof(T)); \
v->capacity = cap; \
v->size = 0; \
return v; \
}

#define vector_destroy_fct(T) \
Expand Down

1 comment on commit 537485f

@epatrizio
Copy link
Owner Author

@epatrizio epatrizio commented on 537485f Feb 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem previous commit : only new commit message to have issue #16 direct link

Please sign in to comment.