diff --git a/src/GC/Makefile b/src/GC/Makefile index add6d73..1fda452 100644 --- a/src/GC/Makefile +++ b/src/GC/Makefile @@ -63,4 +63,13 @@ static_lib: # create test program static_lib_test: static_lib - $(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/extern_lib.out tests/extern_lib.cpp lib/gcoll.a \ No newline at end of file + $(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -o tests/extern_lib.out tests/extern_lib.cpp lib/gcoll.a + +wrapper: + rm -f lib/event.o lib/profiler.o lib/heap.o lib/coll.a tests/wrapper.out + $(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/event.o lib/event.cpp -fPIC + $(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/profiler.o lib/profiler.cpp -fPIC + $(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/heap.o lib/heap.cpp -fPIC + $(CC) $(STDFLAGS) $(WFLAGS) $(LIB_INCL) -O3 -g -c -o lib/cheap.o lib/cheap.cpp -fPIC + ar rcs lib/gcoll.a lib/event.o lib/profiler.o lib/heap.o lib/cheap.o + clang -stdlib=libc++ $(WFLAGS) $(LIB_INCL) -o tests/wrapper.out tests/wrapper.c lib/gcoll.a -lstdc++ diff --git a/src/GC/include/cheap.h b/src/GC/include/cheap.h index 1e11ae2..d2c649d 100644 --- a/src/GC/include/cheap.h +++ b/src/GC/include/cheap.h @@ -7,7 +7,7 @@ extern "C" { #endif -#define DEBUG +// #define DEBUG #ifdef DEBUG typedef struct cheap @@ -19,11 +19,11 @@ struct cheap; typedef struct cheap cheap_t; #endif -cheap_t *cheap_the() noexcept; -void cheap_init() noexcept; -void cheap_dispose() noexcept; -void *cheap_alloc(unsigned long size) noexcept; -void cheap_set_profiler(cheap_t *cheap, bool mode) noexcept; +cheap_t *cheap_the(); +void cheap_init(); +void cheap_dispose(); +void *cheap_alloc(unsigned long size); +void cheap_set_profiler(cheap_t *cheap, bool mode); #ifdef __cplusplus } diff --git a/src/GC/lib/cheap.cpp b/src/GC/lib/cheap.cpp index 1643e17..29a0b10 100644 --- a/src/GC/lib/cheap.cpp +++ b/src/GC/lib/cheap.cpp @@ -1,12 +1,15 @@ #include +#include #include "heap.hpp" #include "cheap.h" +#ifndef DEBUG struct cheap { void *obj; }; +#endif cheap_t *cheap_the() { @@ -27,7 +30,9 @@ void cheap_init() void cheap_dispose() { + std::cout << "In dispose\n"; GC::Heap::dispose(); + std::cout << "Out dispose" << std::endl; } void *cheap_alloc(unsigned long size) diff --git a/src/GC/tests/wrapper.c b/src/GC/tests/wrapper.c index 1a77472..bcd4859 100644 --- a/src/GC/tests/wrapper.c +++ b/src/GC/tests/wrapper.c @@ -1,5 +1,6 @@ #include #include +#include #include "cheap.h" @@ -18,23 +19,25 @@ void test_init() printf("----- EXIT TEST_INIT --------------------------\n"); } -cheap_t *test_the() -{ - printf("----- IN TEST_THE -----------------------------\n"); +/* Uncomment ONLY if run with DEBUG defined in cheap.h */ - cheap_t *fst_heap = cheap_the(); +// cheap_t *test_the() +// { +// printf("----- IN TEST_THE -----------------------------\n"); - printf("Heap 1:\t%p\n", fst_heap->obj); +// cheap_t *fst_heap = cheap_the(); - cheap_t *snd_heap = cheap_the(); +// printf("Heap 1:\t%p\n", fst_heap->obj); - printf("Heap 2:\t%p\n", snd_heap->obj); +// cheap_t *snd_heap = cheap_the(); - printf("----- EXIT TEST_THE ---------------------------\n"); +// printf("Heap 2:\t%p\n", snd_heap->obj); - free(snd_heap); - return fst_heap; -} +// printf("----- EXIT TEST_THE ---------------------------\n"); + +// free(snd_heap); +// return fst_heap; +// } void test_profiler(cheap_t *heap) { @@ -71,20 +74,22 @@ void test_dispose() printf("----- EXIT TEST_DISPOSE -----------------------\n"); } -int main(int argc, char **argv) +int main() { test_init(); - cheap_t *heap = test_the(); - - test_profiler(heap); + /* Uncomment ONLY if run with DEBUG defined in cheap.h */ + // cheap_t *heap = test_the(); + // test_profiler(heap); Object *o = test_alloc(); + printf("Object size: %lu\n", sizeof(Object)); printf("Object:\n\tx: %d\n\ty: %d\n\tz: %d\n\tvel: %f\n", o->x, o->y, o->z, o->velocity); test_dispose(); - free(heap); - free(o); + /* Sefault I don't understand, don't uncomment */ + // free(heap); + // free(o); return 0; } \ No newline at end of file