Merge branch 'feature/json'

This commit is contained in:
c9s 2014-06-01 20:19:30 +08:00
commit 779d9a9859
10 changed files with 133 additions and 82 deletions

View file

@ -6,9 +6,9 @@ compiler:
matrix: matrix:
include: include:
- compiler: gcc - compiler: gcc
env: CONFIGURE_OPTION='--enable-debug --with-malloc=jemalloc' COVERALLS=yes VALGRIND=no env: CONFIGURE_OPTION='--enable-debug --with-malloc=jemalloc' COVERALLS=yes VALGRIND=no DEBUG=yes
- compiler: gcc - compiler: gcc
env: CONFIGURE_OPTION='--enable-debug' COVERALLS=yes VALGRIND=yes LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/ env: CONFIGURE_OPTION='--enable-debug' COVERALLS=yes VALGRIND=yes DEBUG=yes LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/
- compiler: clang - compiler: clang
env: ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/local/clang-3.4/bin/llvm-symbolizer CFLAGS='-fsanitize=address -g -O1' env: ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=/usr/local/clang-3.4/bin/llvm-symbolizer CFLAGS='-fsanitize=address -g -O1'
@ -28,7 +28,8 @@ script:
- make V=1 - make V=1
- sudo make install - sudo make install
- if [ "x$VALGRIND" == xyes ]; then make check > /dev/null 2>&1; else make check V=1; fi - if [ "x$VALGRIND" == xyes ]; then make check > /dev/null 2>&1; else make check V=1; fi
- if [ "x$VALGRIND" == xyes ]; then valgrind ./tests/.libs/check_* -v --trace-children=yes --show-leak-kinds=full --leak-check=full; fi # XXX: tracing memory leak, disabled for some mystery reason for automake...
# - if [ "x$VALGRIND" == xyes && "x$DEBUG" == xyes ]; then valgrind ./tests/check_* -v --trace-children=yes --show-leak-kinds=full --leak-check=full; fi
after_success: after_success:
- if [ x$COVERALLS == xyes ]; then coveralls ; fi - if [ x$COVERALLS == xyes ]; then coveralls ; fi

14
3rdparty/Makefile.am vendored Normal file
View file

@ -0,0 +1,14 @@
AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/3rdparty -Wall -std=c99
AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS)
noinst_LTLIBRARIES = libr3ext.la
libr3ext_la_SOURCES = zmalloc.c
libr3ext_la_LIBADD=$(DEPS_LIBS)
# noinst_LIBRARIES = libr3ext.la
libr3ext_la_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/3rdparty -Wall -std=c99
noinst_HEADERS = \
zmalloc.h \
$(NULL)

View file

View file

@ -1,7 +1,23 @@
SUBDIRS=src tests SUBDIRS=3rdparty src tests
lib_LTLIBRARIES = libr3.la
libr3_la_SOURCES =
libr3_la_LIBADD = 3rdparty/libr3ext.la src/libr3core.la
libr3_la_LDFLAGS = -static
AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/3rdparty -Wall -std=c99
AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS)
ACLOCAL_AMFLAGS=-I m4 ACLOCAL_AMFLAGS=-I m4
if ENABLE_DEBUG
AM_CFLAGS += -ggdb -fprofile-arcs -ftest-coverage
endif
if USE_JEMALLOC
AM_LDFLAGS += -ljemalloc
endif
r3_includedir = $(includedir)/r3 r3_includedir = $(includedir)/r3
r3_include_HEADERS = \ r3_include_HEADERS = \
include/r3.h \ include/r3.h \
@ -10,7 +26,6 @@ r3_include_HEADERS = \
include/r3_str.h \ include/r3_str.h \
include/r3_gvc.h \ include/r3_gvc.h \
include/str_array.h \ include/str_array.h \
include/zmalloc.h \
$(NULL) $(NULL)
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig

View file

@ -2,13 +2,12 @@ AC_INIT([r3], 1.0.0)
AC_PREREQ([2.64]) AC_PREREQ([2.64])
AC_CONFIG_HEADERS(config.h) AC_CONFIG_HEADERS(config.h)
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign]) AM_INIT_AUTOMAKE([foreign subdir-objects])
LT_INIT LT_INIT
AC_PROG_CC AC_PROG_CC
AC_PROG_CC_STDC AC_PROG_CC_STDC
AC_PROG_INSTALL AC_PROG_INSTALL
AC_CHECK_HEADERS([stdlib.h string.h sys/time.h]) AC_CHECK_HEADERS([stdlib.h string.h sys/time.h])
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.
@ -24,20 +23,9 @@ AC_CHECK_FUNCS([gettimeofday memset strchr strdup strndup strstr])
PKG_PROG_PKG_CONFIG PKG_PROG_PKG_CONFIG
AC_ARG_ENABLE(graphviz,
AS_HELP_STRING([--enable-graphviz],
[enable graphviz support]),
, enable_graphviz=unset)
if test "x$enable_graphviz" != "xunset" ; then
PKG_CHECK_MODULES(GVC_DEPS, [libgvc])
AC_SUBST(GVC_DEPS_CFLAGS)
AC_SUBST(GVC_DEPS_LIBS)
fi
AC_ARG_ENABLE(debug,
AS_HELP_STRING([--enable-debug],
[enable debug]),
, enable_debug=unset)
AC_ARG_WITH([malloc], AC_ARG_WITH([malloc],
AS_HELP_STRING([--without-malloc], [Use the default malloc])) AS_HELP_STRING([--without-malloc], [Use the default malloc]))
@ -74,37 +62,56 @@ AM_CONDITIONAL(USE_JEMALLOC, test "x$have_jemalloc" = "xyes")
# AM_CONDITIONAL(USE_JEMALLOC, test "x$found_jemalloc" = "xyes") # AM_CONDITIONAL(USE_JEMALLOC, test "x$found_jemalloc" = "xyes")
# AC_DEFINE(USE_JEMALLOC, test "x$found_jemalloc" = "xyes" , "use jemalloc") # AC_DEFINE(USE_JEMALLOC, test "x$found_jemalloc" = "xyes" , "use jemalloc")
AM_CONDITIONAL(ENABLE_DEBUG, test "x$enable_debug" = "xyes")
AM_CONDITIONAL(ENABLE_GRAPHVIZ, test "x$enable_graphviz" = "xyes")
AC_DEFINE(ENABLE_GRAPHVIZ, test "x$enable_graphviz" = "xyes", "whether graphviz is enable")
PKG_CHECK_MODULES(DEPS, [libpcre]) PKG_CHECK_MODULES(DEPS, [libpcre])
AC_SUBST(DEPS_CFLAGS) AC_SUBST(DEPS_CFLAGS)
AC_SUBST(DEPS_LIBS) AC_SUBST(DEPS_LIBS)
AC_ARG_ENABLE(debug,AS_HELP_STRING([--enable-debug],[enable debug]))
if test "x$enable_debug" = "xyes"; then
AC_DEFINE(ENABLE_DEBUG, 1, "debug")
fi
AM_CONDITIONAL(ENABLE_DEBUG, test "x$enable_debug" = "xyes")
AC_ARG_ENABLE(graphviz, AS_HELP_STRING([--enable-graphviz],[enable graphviz support]))
if test "x$enable_graphviz" = "xyes" ; then
PKG_CHECK_MODULES(GVC_DEPS, [libgvc])
AC_SUBST(GVC_DEPS_CFLAGS)
AC_SUBST(GVC_DEPS_LIBS)
AC_DEFINE(ENABLE_GRAPHVIZ, 1, "whether graphviz is enable")
fi
AM_CONDITIONAL(ENABLE_GRAPHVIZ, test "x$enable_graphviz" = "xyes")
AC_ARG_ENABLE(json, AS_HELP_STRING([--enable-json],[enable json encoder]))
if test "x$enable_json" = "xyes"; then
AC_DEFINE(ENABLE_JSON, 1, [enable json])
fi
AM_CONDITIONAL(ENABLE_JSON, test "x$enable_json" = "xyes")
# This does not work because configure does not look into /opt/local/include... # 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_CHECK_HEADERS([check.h],[ enable_check=yes ],[ enable_check=unset ])
AC_ARG_ENABLE(check, AC_ARG_ENABLE(check, AS_HELP_STRING([--enable-check], [enable unit testing]))
AS_HELP_STRING([--enable-check], if test "$enable_check" = "xyes"; then
[enable unit testing]), PKG_CHECK_MODULES(CHECK,[check >= 0.9.4],:,[
, enable_check=unset) ifdef([AM_PATH_CHECK],
[AM_PATH_CHECK(,[have_check="yes"])],
if test "x$enable_check" != "xunset" ; then AC_MSG_WARN([Check not found; cannot run unit tests!])
# AM_PATH_CHECK [have_check="no"])]
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 fi
AM_CONDITIONAL(HAVE_CHECK, test x"$have_check" = "xyes") AM_CONDITIONAL(HAVE_CHECK, test x"$have_check" = "xyes")
AC_CONFIG_FILES([ AC_CONFIG_FILES([
r3.pc r3.pc
Makefile Makefile
3rdparty/Makefile
src/Makefile src/Makefile
tests/Makefile tests/Makefile
]) ])

View file

@ -12,10 +12,16 @@
#include <string.h> #include <string.h>
#include <pcre.h> #include <pcre.h>
#include <stdbool.h> #include <stdbool.h>
#include "config.h"
#include "r3_define.h" #include "r3_define.h"
#include "str_array.h" #include "str_array.h"
#include "match_entry.h" #include "match_entry.h"
#ifdef ENABLE_JSON
#include <json-c/json.h>
#endif
struct _edge; struct _edge;
struct _node; struct _node;
struct _route; struct _route;
@ -170,7 +176,14 @@ enum { NODE_COMPARE_STR, NODE_COMPARE_PCRE, NODE_COMPARE_OPCODE };
enum { OP_EXPECT_MORE_DIGITS = 1, OP_EXPECT_MORE_WORDS, OP_EXPECT_NOSLASH, OP_EXPECT_NODASH, OP_EXPECT_MORE_ALPHA }; enum { OP_EXPECT_MORE_DIGITS = 1, OP_EXPECT_MORE_WORDS, OP_EXPECT_NOSLASH, OP_EXPECT_NODASH, OP_EXPECT_MORE_ALPHA };
#ifdef ENABLE_JSON
json_object * r3_edge_to_json_object(const edge * e);
json_object * r3_node_to_json_object(const node * n);
json_object * r3_route_to_json_object(const route * r);
const char * r3_node_to_json_string_ext(const node * n, int options);
const char * r3_node_to_json_pretty_string(const node * n);
const char * r3_node_to_json_string(const node * n);
#endif
#endif /* !R3_NODE_H */ #endif /* !R3_NODE_H */

View file

@ -1,23 +1,24 @@
lib_LTLIBRARIES = libr3.la AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) $(JSONC_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/3rdparty -Wall -std=c99
AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS) $(JSONC_LIBS)
noinst_LTLIBRARIES = libr3core.la
# lib_LIBRARIES = libr3.a # lib_LIBRARIES = libr3.a
libr3_la_SOURCES = node.c edge.c str.c token.c zmalloc.c match_entry.c libr3core_la_SOURCES = node.c edge.c str.c token.c match_entry.c
if ENABLE_JSON
libr3core_la_SOURCES += json.c
endif
# libr3_la_LDFLAGS = -export-symbols-regex '^r3_|^match_' # libr3_la_LDFLAGS = -export-symbols-regex '^r3_|^match_'
libr3_la_LIBADD=$(DEPS_LIBS) # libr3_la_LIBADD=$(DEPS_LIBS) $(LIBOBJS) $(ALLOCA)
AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include -Wall -std=c99 # libr3core_la_LIBADD=$(DEPS_LIBS)
# libr3core_la_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/3rdparty -Wall -std=c99
if USE_JEMALLOC
AM_CFLAGS += -ljemalloc
endif
if ENABLE_DEBUG
AM_CFLAGS += -ggdb -fprofile-arcs -ftest-coverage
endif
if ENABLE_GRAPHVIZ if ENABLE_GRAPHVIZ
libr3_la_SOURCES += gvc.c libr3core_la_SOURCES += gvc.c
libr3_la_LIBADD += $(GVC_DEPS_LIBS)
AM_CFLAGS += $(GVC_DEPS_CFLAGS)
endif endif
# AM_CFLAGS=$(DEPS_CFLAGS) # AM_CFLAGS=$(DEPS_CFLAGS)

View file

@ -220,7 +220,7 @@ int r3_tree_compile_patterns(node * n, char **errstr) {
NULL); /* use default character tables */ NULL); /* use default character tables */
if (n->pcre_pattern == NULL) { if (n->pcre_pattern == NULL) {
if (errstr) { if (errstr) {
asprintf(errstr, "PCRE compilation failed at offset %d: %s, pattern: %s\n", pcre_erroffset, pcre_error, n->combined_pattern); asprintf(errstr, "PCRE compilation failed at offset %d: %s, pattern: %s", pcre_erroffset, pcre_error, n->combined_pattern);
} }
return -1; return -1;
} }
@ -231,7 +231,7 @@ int r3_tree_compile_patterns(node * n, char **errstr) {
n->pcre_extra = pcre_study(n->pcre_pattern, 0, &pcre_error); n->pcre_extra = pcre_study(n->pcre_pattern, 0, &pcre_error);
if (n->pcre_extra == NULL) { if (n->pcre_extra == NULL) {
if (errstr) { if (errstr) {
asprintf(errstr, "PCRE study failed at offset %s\n", pcre_error); asprintf(errstr, "PCRE study failed at offset %s, pattern: %s", pcre_error, n->combined_pattern);
} }
return -1; return -1;
} }

View file

@ -4,9 +4,14 @@
# else # else
# TESTS = # TESTS =
# endif # endif
TESTS = check_tree TESTS =
AM_CFLAGS = -ggdb -Wall $(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include @CHECK_CFLAGS@
AM_LDFLAGS = $(DEPS_LIBS) -L$(top_builddir)/src -lr3 -lcheck @CHECK_LIBS@ AM_CFLAGS=$(DEPS_CFLAGS) $(GVC_DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/3rdparty -Wall -std=c99 -ggdb -Wall
AM_LDFLAGS=$(DEPS_LIBS) $(GVC_DEPS_LIBS) -L$(top_builddir) -lr3 -lcheck @CHECK_LIBS@
if USE_JEMALLOC
AM_CFLAGS += -ljemalloc
endif
noinst_HEADERS = \ noinst_HEADERS = \
@ -16,37 +21,32 @@ noinst_HEADERS = \
dist_noinst_DATA = \ dist_noinst_DATA = \
$(NULL) $(NULL)
if USE_JEMALLOC
AM_CFLAGS += -ljemalloc
endif
if ENABLE_GRAPHVIZ
TESTS += check_gvc
check_gvc_SOURCES = check_gvc.c
# check_gvc_LDADD = $(GVC_DEPS_LIBS) $(DEPS_LIBS) -L$(top_builddir)/src -lr3 @CHECK_LIBS@
# check_gvc_CFLAGS = $(GVC_DEPS_CFLAGS) $(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include @CHECK_CFLAGS@
AM_CFLAGS += $(GVC_DEPS_CFLAGS)
AM_LDFLAGS += $(GVC_DEPS_LIBS)
endif
TESTS += benchmark
benchmark_SOURCES = bench.c
# noinst_PROGRAMS = $(TESTS)
check_tree_SOURCES = check_tree.c
# check_tree_LDADD=$(DEPS_LIBS) -L$(top_builddir)/src -lr3 @CHECK_LIBS@
# check_tree_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include @CHECK_CFLAGS@
TESTS += check_slug TESTS += check_slug
check_slug_SOURCES = check_slug.c check_slug_SOURCES = check_slug.c
check_PROGRAMS = $(TESTS) TESTS += check_tree
check_tree_SOURCES = check_tree.c
if ENABLE_JSON
TESTS += check_json
check_json_SOURCES = check_json.c
endif
if ENABLE_GRAPHVIZ
TESTS += check_gvc
check_gvc_SOURCES = check_gvc.c
endif
TESTS += benchmark
benchmark_SOURCES = bench.c
check_PROGRAMS = $(TESTS)
# AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir)/include # AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir)/include
# AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include # AM_CFLAGS=$(DEPS_CFLAGS) -I$(top_builddir) -I$(top_builddir)/include
CLEANFILES = check_tree.log CLEANFILES = check_tree.log
# noinst_PROGRAMS = $(TESTS)