From 77756bd12faa94a221356f326d404c1da478fad3 Mon Sep 17 00:00:00 2001 From: Fredrik Widlund Date: Sat, 30 Jan 2021 18:52:43 +0100 Subject: [PATCH] build --- Makefile.am | 6 +++--- configure.ac | 6 ++---- example/Makefile.am | 13 +++++++++++++ {examples => example}/async.c | 0 {examples => example}/list.c | 0 {examples => example}/mapi.c | 0 {examples => example}/maps.c | 0 examples/Makefile.am | 23 ----------------------- src/dynamic/buffer.c | 19 ++----------------- test/buffer.c | 16 +--------------- 10 files changed, 21 insertions(+), 62 deletions(-) create mode 100644 example/Makefile.am rename {examples => example}/async.c (100%) rename {examples => example}/list.c (100%) rename {examples => example}/mapi.c (100%) rename {examples => example}/maps.c (100%) delete mode 100644 examples/Makefile.am diff --git a/Makefile.am b/Makefile.am index 0eedcb3..fb6fe3d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,9 +1,9 @@ AUTOMAKE_OPTIONS = subdir-objects ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4 -AM_CFLAGS = -std=gnu11 -g -O3 -march=native -flto -I$(srcdir)/src -fPIC +AM_CFLAGS = -std=gnu11 -I$(srcdir)/src -fPIC AM_LDFLAGS = -static -DIST_SUBDIRS = docs examples +DIST_SUBDIRS = docs example EXTRA_DIST = \ CHANGES \ @@ -50,7 +50,7 @@ mainheader_HEADERS = src/dynamic.h pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libdynamic.pc -MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in docs/Makefile.in benchmark/Makefile.in examples/Makefile.in libdynamic-?.?.?.tar.gz +MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in docs/Makefile.in example/Makefile.in libdynamic-?.?.?.tar.gz maintainer-clean-local:; rm -rf autotools m4 libdynamic-?.?.? ### unit tests ### diff --git a/configure.ac b/configure.ac index 7f376c8..ea402be 100644 --- a/configure.ac +++ b/configure.ac @@ -3,14 +3,12 @@ AC_CONFIG_AUX_DIR(autotools) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([-Wall -Werror foreign no-define]) -: ${CFLAGS="-Wall -Wextra -Wpedantic"} -: ${CXXFLAGS="-Wall -Wextra -Wpedantic"} +: ${CFLAGS="-Wall -Wextra -Wpedantic -g -O3 -march=native -flto"} AM_PROG_AR LT_INIT AM_PROG_CC_C_O -AC_PROG_CXX AC_PREFIX_DEFAULT(/usr) -AC_CONFIG_FILES([Makefile docs/Makefile examples/Makefile libdynamic.pc]) +AC_CONFIG_FILES([Makefile docs/Makefile example/Makefile libdynamic.pc]) AC_OUTPUT diff --git a/example/Makefile.am b/example/Makefile.am new file mode 100644 index 0000000..f05d94f --- /dev/null +++ b/example/Makefile.am @@ -0,0 +1,13 @@ +ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4 +AM_CFLAGS = -std=gnu11 -std=gnu11 +LDADD = -L.. -ldynamic + +bin_PROGRAMS = \ +maps \ +mapi \ +list \ +async + +async_LDFLAGS = -pthread + +MAINTAINERCLEANFILES = Makefile.in diff --git a/examples/async.c b/example/async.c similarity index 100% rename from examples/async.c rename to example/async.c diff --git a/examples/list.c b/example/list.c similarity index 100% rename from examples/list.c rename to example/list.c diff --git a/examples/mapi.c b/example/mapi.c similarity index 100% rename from examples/mapi.c rename to example/mapi.c diff --git a/examples/maps.c b/example/maps.c similarity index 100% rename from examples/maps.c rename to example/maps.c diff --git a/examples/Makefile.am b/examples/Makefile.am deleted file mode 100644 index b06f1ec..0000000 --- a/examples/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ -ACLOCAL_AMFLAGS = ${ACLOCAL_FLAGS} -I m4 -COMMON_FLAGS = -g -O3 -flto -Isupport -I../src -AM_CFLAGS = -std=gnu11 -AM_CXXFLAGS = -std=gnu++11 -AM_CPPFLAGS = $(COMMON_FLAGS) -AM_LDFLAGS = $(COMMON_FLAGS) - -bin_PROGRAMS = maps mapi list async - -maps_SOURCES = maps.c -maps_LDADD = ../libdynamic.la - -mapi_SOURCES = mapi.c -mapi_LDADD = ../libdynamic.la - -list_SOURCES = list.c -list_LDADD = ../libdynamic.la - -async_SOURCES = async.c -async_LDADD = ../libdynamic.la -async_LDFLAGS = -pthread - -MAINTAINERCLEANFILES = Makefile.in diff --git a/src/dynamic/buffer.c b/src/dynamic/buffer.c index 3db105d..3e272cb 100644 --- a/src/dynamic/buffer.c +++ b/src/dynamic/buffer.c @@ -18,12 +18,6 @@ static size_t buffer_roundup(size_t size) return size; } -static inline void buffer_assert(int value) -{ - if (!value) - abort(); -} - /* constructor/destructor */ void buffer_construct(buffer *b) @@ -50,14 +44,10 @@ size_t buffer_capacity(buffer *b) void buffer_reserve(buffer *b, size_t capacity) { - void *data; - if (capacity > b->capacity) { capacity = buffer_roundup(capacity); - data = realloc(b->data, capacity); - buffer_assert(data != NULL); - b->data = data; + b->data = realloc(b->data, capacity); b->capacity = capacity; } } @@ -71,14 +61,9 @@ void buffer_resize(buffer *b, size_t size) void buffer_compact(buffer *b) { - void *data; - if (b->capacity > b->size) { - data = realloc(b->data, b->size); - if (b->size) - buffer_assert(data != NULL); - b->data = data; + b->data = realloc(b->data, b->size); b->capacity = b->size; } } diff --git a/test/buffer.c b/test/buffer.c index 27fefc5..9726733 100644 --- a/test/buffer.c +++ b/test/buffer.c @@ -49,24 +49,10 @@ void core(__attribute__((unused)) void **state) buffer_destruct(&b); } -void alloc(__attribute__((unused)) void **state) -{ - buffer b; - - buffer_construct(&b); - debug_out_of_memory = 1; - debug_abort = 1; - expect_assert_failure(buffer_reserve(&b, 100)); - debug_abort = 0; - debug_out_of_memory = 0; - buffer_destruct(&b); -} - int main() { const struct CMUnitTest tests[] = { - cmocka_unit_test(core), - cmocka_unit_test(alloc), + cmocka_unit_test(core) }; return cmocka_run_group_tests(tests, NULL, NULL);