From d4d1a59728005a50639926b363da1fac45036ff6 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 2 Jun 2014 05:23:00 +0800 Subject: [PATCH 1/2] fix autotools for check --- configure.ac | 21 +++++++++++++-------- tests/Makefile.am | 11 ++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 27ffb21..7158f20 100644 --- a/configure.ac +++ b/configure.ac @@ -100,14 +100,19 @@ AM_CONDITIONAL(ENABLE_JSON, test "x$enable_json" = "xyes") # This does not work because configure does not look into /opt/local/include... # AC_CHECK_HEADERS([check.h],[ enable_check=yes ],[ enable_check=unset ]) -AC_ARG_ENABLE(check, AS_HELP_STRING([--enable-check], [enable unit testing])) -if test "$enable_check" = "xyes"; then - PKG_CHECK_MODULES(CHECK,[check >= 0.9.4],:,[ - ifdef([AM_PATH_CHECK], - [AM_PATH_CHECK(,[have_check="yes"])], - AC_MSG_WARN([Check not found; cannot run unit tests!]) - [have_check="no"])] - ]) + + +AC_ARG_ENABLE(check, + AS_HELP_STRING([--enable-check], + [enable unit testing]), + , enable_check=unset) +if test "x$enable_check" != "xunset" ; then +PKG_CHECK_MODULES(CHECK,[check >= 0.9.4],:,[ + ifdef([AM_PATH_CHECK], + [AM_PATH_CHECK(,[have_check="yes"])], + AC_MSG_WARN([Check not found; cannot run unit tests!]) + [have_check="no"])] +]) fi AM_CONDITIONAL(HAVE_CHECK, test x"$have_check" = "xyes") diff --git a/tests/Makefile.am b/tests/Makefile.am index fb15e51..8b3a270 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,13 +1,7 @@ -# INCLUDES = @CHECK_CFLAGS@ -# if HAVE_CHECK -# TESTS = check_tree -# else -# TESTS = -# endif TESTS = -AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) $(JSONC_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/src -I$(top_builddir)/3rdparty -Wall -std=c99 -ggdb -Wall -AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS) $(JSONC_LIBS) -L$(top_builddir) -lcheck @CHECK_LIBS@ $(top_builddir)/libr3.la +AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) $(JSONC_CFLAGS) @CHECK_CFLAGS@ -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/src -I$(top_builddir)/3rdparty -Wall -std=c99 -ggdb -Wall +AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS) $(JSONC_LIBS) @CHECK_LIBS@ $(top_builddir)/libr3.la if USE_JEMALLOC AM_CFLAGS += -ljemalloc @@ -24,7 +18,6 @@ dist_noinst_DATA = \ TESTS += check_slug check_slug_SOURCES = check_slug.c - TESTS += check_tree check_tree_SOURCES = check_tree.c From 20e3f1a3ba35548cd2494801592eafd1a438f79d Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 2 Jun 2014 05:48:27 +0800 Subject: [PATCH 2/2] asprintf returns memory pointer which is from malloc() not zmalloc() --- configure.ac | 4 +--- src/slug.c | 3 +++ tests/check_slug.c | 12 ++++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/configure.ac b/configure.ac index 7158f20..5d4c10b 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,6 @@ AC_INIT([r3], 1.0.0) AC_PREREQ([2.64]) +AC_USE_SYSTEM_EXTENSIONS AC_CONFIG_HEADERS(config.h) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign subdir-objects]) @@ -18,9 +19,6 @@ AC_TYPE_SIZE_T AC_FUNC_MALLOC AC_FUNC_REALLOC AC_CHECK_FUNCS([gettimeofday memset strchr strdup strndup strstr]) - - - PKG_PROG_PKG_CONFIG diff --git a/src/slug.c b/src/slug.c index fdd039a..d19df8a 100644 --- a/src/slug.c +++ b/src/slug.c @@ -4,6 +4,7 @@ * * Distributed under terms of the MIT license. */ +#include #include #include #include "config.h" @@ -19,6 +20,8 @@ inline int contains_slug_char(const char * str) { r3_slug_t * r3_slug_new(char * path, int path_len) { r3_slug_t * s = zmalloc(sizeof(r3_slug_t)); + if (!s) + return NULL; s->path = path; s->path_len = path_len; diff --git a/tests/check_slug.c b/tests/check_slug.c index bae4d42..aeb0544 100644 --- a/tests/check_slug.c +++ b/tests/check_slug.c @@ -100,11 +100,13 @@ START_TEST (test_slug_parse_with_pattern) { char * pattern = "/user/{name:\\d{3}}"; char * errstr = NULL; - r3_slug_t *s = r3_slug_parse(pattern, strlen(pattern), pattern, &errstr); + const r3_slug_t *s = r3_slug_parse(pattern, strlen(pattern), pattern, &errstr); + ck_assert(s); char * out = r3_slug_to_str(s); + ck_assert(out); printf("%s\n",out); - zfree(out); + free(out); r3_slug_free(s); } @@ -115,11 +117,13 @@ START_TEST (test_slug_parse_without_pattern) { char * pattern = "/user/{name}"; char * errstr = NULL; - r3_slug_t *s = r3_slug_parse(pattern, strlen(pattern), pattern, &errstr); + const r3_slug_t *s = r3_slug_parse(pattern, strlen(pattern), pattern, &errstr); + ck_assert(s); char * out = r3_slug_to_str(s); + ck_assert(out); printf("%s\n",out); - zfree(out); + free(out); r3_slug_free(s); }