From d58d98a62dd8ecafacb42785527e6cac24b308e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Thu, 22 May 2014 14:58:01 +0200 Subject: [PATCH] [value] move value functions that depend on angel / main implementations into separate file, included in the other implementations this fixes building with --no-undefined. also link with libm in cmake. --- configure.ac | 2 +- src/CMakeLists.txt | 4 +- src/angel/angel_value.c | 2 + src/common/Makefile.am | 2 +- src/common/value.c | 114 ---------------------------------- src/common/value_impl.c | 132 ++++++++++++++++++++++++++++++++++++++++ src/main/value.c | 7 +-- 7 files changed, 140 insertions(+), 123 deletions(-) create mode 100644 src/common/value_impl.c diff --git a/configure.ac b/configure.ac index 060675f..7fab047 100644 --- a/configure.ac +++ b/configure.ac @@ -458,7 +458,7 @@ AC_ARG_ENABLE([extra-warnings], esac],[extrawarnings=false]) if test x$extrawarnings = xtrue; then - CFLAGS="${CFLAGS} -g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wno-pointer-sign -Wcast-align -Wsign-compare -Wnested-externs -Wpointer-arith -Wl,--as-needed -Wformat-security" + CFLAGS="${CFLAGS} -g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wno-pointer-sign -Wcast-align -Wsign-compare -Wnested-externs -Wpointer-arith -Wl,--as-needed -Wl,--no-undefined -Wformat-security" fi AC_CONFIG_FILES([Makefile \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 527268e..1cc192b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -338,7 +338,7 @@ SET(L_INSTALL_TARGETS ${L_INSTALL_TARGETS} lighttpd2-worker lighttpd2 lighttpd-$ IF(BUILD_EXTRA_WARNINGS) SET(WARN_CFLAGS " -g -O2 -g2 -Wall -Wmissing-declarations -Wdeclaration-after-statement -Wcast-align -Wsign-compare -Wnested-externs -Wpointer-arith -Wmissing-prototypes -Wshadow") - SET(WARN_LDFLAGS " -g -O2 -g2 -Wall -Wl,--as-needed") + SET(WARN_LDFLAGS " -g -O2 -g2 -Wall -Wl,--as-needed -Wl,--no-undefined") # -Werror ELSE(BUILD_EXTRA_WARNINGS) SET(WARN_CFLAGS "") @@ -397,7 +397,7 @@ ENDIF(WITH_OPENSSL) TARGET_LINK_LIBRARIES(lighttpd-${PACKAGE_VERSION}-common ${COMMON_LDFLAGS} ${UNWIND_LDFLAGS}) ADD_TARGET_PROPERTIES(lighttpd-${PACKAGE_VERSION}-common COMPILE_FLAGS ${COMMON_CFLAGS} ${UNWIND_CFLAGS}) -TARGET_LINK_LIBRARIES(lighttpd-${PACKAGE_VERSION}-shared ${COMMON_LDFLAGS}) +TARGET_LINK_LIBRARIES(lighttpd-${PACKAGE_VERSION}-shared ${COMMON_LDFLAGS} m) ADD_TARGET_PROPERTIES(lighttpd-${PACKAGE_VERSION}-shared COMPILE_FLAGS ${COMMON_CFLAGS}) TARGET_LINK_LIBRARIES(lighttpd-${PACKAGE_VERSION}-sharedangel ${COMMON_LDFLAGS}) diff --git a/src/angel/angel_value.c b/src/angel/angel_value.c index 09a3f64..ae06409 100644 --- a/src/angel/angel_value.c +++ b/src/angel/angel_value.c @@ -1,5 +1,7 @@ #include +#include "../common/value_impl.c" + liValue* li_value_copy(liValue* val) { return li_common_value_copy_(val); } diff --git a/src/common/Makefile.am b/src/common/Makefile.am index d36fe02..cfc39a3 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -32,7 +32,7 @@ EXTRA_liblighttpd2_common_la_SOURCES=profiler.c BUILT_SOURCES=$(parsers) CLEANFILES=$(parsers) -EXTRA_DIST=ip_parsers.rl +EXTRA_DIST=ip_parsers.rl value_impl.c ip_parsers.c: ip_parsers.rl $(RAGEL) -C -T1 -o $@ $< diff --git a/src/common/value.c b/src/common/value.c index c332fb6..6be092d 100644 --- a/src/common/value.c +++ b/src/common/value.c @@ -37,20 +37,6 @@ liValue* li_value_new_list(void) { return v; } -static void _value_hash_free_key(gpointer data) { - g_string_free((GString*) data, TRUE); -} - -static void _value_hash_free_value(gpointer data) { - li_value_free((liValue*) data); -} - -GHashTable *li_value_new_hashtable(void) { - return g_hash_table_new_full( - (GHashFunc) g_string_hash, (GEqualFunc) g_string_equal, - _value_hash_free_key, _value_hash_free_value); -} - void li_value_list_append(liValue *list, liValue *item) { LI_FORCE_ASSERT(LI_VALUE_LIST == list->type); g_ptr_array_add(list->data.list, item); @@ -66,64 +52,11 @@ void li_value_wrap_in_list(liValue *val) { g_ptr_array_add(val->data.list, item); } -liValue* li_common_value_copy_(liValue* val) { - liValue *n; - if (NULL == val) return NULL; - - switch (val->type) { - case LI_VALUE_NONE: return li_value_new_none(); - case LI_VALUE_BOOLEAN: return li_value_new_bool(val->data.boolean); - case LI_VALUE_NUMBER: return li_value_new_number(val->data.number); - case LI_VALUE_STRING: return li_value_new_string(g_string_new_len(GSTR_LEN(val->data.string))); - /* list: we have to copy every value in the list! */ - case LI_VALUE_LIST: - n = li_value_new_list(); - g_ptr_array_set_size(n->data.list, val->data.list->len); - for (guint i = 0; i < val->data.list->len; i++) { - g_ptr_array_index(n->data.list, i) = li_value_copy(g_ptr_array_index(val->data.list, i)); - } - return n; - } - return NULL; -} - static void _li_value_clear(liValue *val) { memset(val, 0, sizeof(*val)); val->type = LI_VALUE_NONE; } -void li_common_value_clear_(liValue *val) { - if (NULL == val) return; - - switch (val->type) { - case LI_VALUE_NONE: - case LI_VALUE_BOOLEAN: - case LI_VALUE_NUMBER: - /* Nothing to free */ - break; - case LI_VALUE_STRING: - g_string_free(val->data.string, TRUE); - break; - case LI_VALUE_LIST: - li_value_list_free(val->data.list); - break; - } - _li_value_clear(val); -} - -void li_value_free(liValue* val) { - if (NULL == val) return; - li_value_clear(val); - g_slice_free(liValue, val); -} - -void li_value_move(liValue *dest, liValue *src) { - LI_FORCE_ASSERT(NULL != dest && NULL != src && dest != src); - li_value_clear(dest); - *dest = *src; - _li_value_clear(src); -} - const char* li_common_valuetype_string_(liValueType type) { switch(type) { case LI_VALUE_NONE: @@ -140,53 +73,6 @@ const char* li_common_valuetype_string_(liValueType type) { return ""; } -void li_value_list_free(GPtrArray *vallist) { - if (NULL == vallist) return; - for (gsize i = 0; i < vallist->len; i++) { - li_value_free(g_ptr_array_index(vallist, i)); - } - g_ptr_array_free(vallist, TRUE); -} - -GString *li_common_value_to_string_(liValue *val) { - GString *str = NULL; - - switch (val->type) { - case LI_VALUE_NONE: - str = g_string_new("null"); - break; - case LI_VALUE_BOOLEAN: - str = g_string_new(val->data.boolean ? "true" : "false"); - break; - case LI_VALUE_NUMBER: - str = g_string_sized_new(0); - g_string_printf(str, "%" G_GINT64_FORMAT, val->data.number); - break; - case LI_VALUE_STRING: - str = g_string_new_len(CONST_STR_LEN("\"")); - g_string_append_len(str, GSTR_LEN(val->data.string)); - g_string_append_c(str, '"'); - break; - case LI_VALUE_LIST: - str = g_string_new_len(CONST_STR_LEN("(")); - if (val->data.list->len) { - GString *tmp = li_value_to_string(g_ptr_array_index(val->data.list, 0)); - g_string_append(str, tmp->str); - g_string_free(tmp, TRUE); - for (guint i = 1; i < val->data.list->len; i++) { - tmp = li_value_to_string(g_ptr_array_index(val->data.list, i)); - g_string_append_len(str, CONST_STR_LEN(", ")); - g_string_append(str, tmp->str); - g_string_free(tmp, TRUE); - } - } - g_string_append_c(str, ')'); - break; - } - - return str; -} - gpointer li_common_value_extract_ptr_(liValue *val) { gpointer ptr = NULL; diff --git a/src/common/value_impl.c b/src/common/value_impl.c new file mode 100644 index 0000000..2918fca --- /dev/null +++ b/src/common/value_impl.c @@ -0,0 +1,132 @@ +/* include from angel / main; + * as some "common" functions need to call the actual implementations + * in angel / main they cannot live in "common" + */ + +static void _li_value_clear(liValue *val) { + memset(val, 0, sizeof(*val)); + val->type = LI_VALUE_NONE; +} + +liValue* li_common_value_copy_(liValue* val) { + liValue *n; + if (NULL == val) return NULL; + + switch (val->type) { + case LI_VALUE_NONE: return li_value_new_none(); + case LI_VALUE_BOOLEAN: return li_value_new_bool(val->data.boolean); + case LI_VALUE_NUMBER: return li_value_new_number(val->data.number); + case LI_VALUE_STRING: return li_value_new_string(g_string_new_len(GSTR_LEN(val->data.string))); + /* list: we have to copy every value in the list! */ + case LI_VALUE_LIST: + n = li_value_new_list(); + g_ptr_array_set_size(n->data.list, val->data.list->len); + for (guint i = 0; i < val->data.list->len; i++) { + g_ptr_array_index(n->data.list, i) = li_value_copy(g_ptr_array_index(val->data.list, i)); + } + return n; + default: + /* other cases need to be handled by li_value_copy */ + break; + } + return NULL; +} + +GString *li_common_value_to_string_(liValue *val) { + GString *str = NULL; + + switch (val->type) { + case LI_VALUE_NONE: + str = g_string_new("null"); + break; + case LI_VALUE_BOOLEAN: + str = g_string_new(val->data.boolean ? "true" : "false"); + break; + case LI_VALUE_NUMBER: + str = g_string_sized_new(0); + g_string_printf(str, "%" G_GINT64_FORMAT, val->data.number); + break; + case LI_VALUE_STRING: + str = g_string_new_len(CONST_STR_LEN("\"")); + g_string_append_len(str, GSTR_LEN(val->data.string)); + g_string_append_c(str, '"'); + break; + case LI_VALUE_LIST: + str = g_string_new_len(CONST_STR_LEN("(")); + if (val->data.list->len) { + GString *tmp = li_value_to_string(g_ptr_array_index(val->data.list, 0)); + g_string_append(str, tmp->str); + g_string_free(tmp, TRUE); + for (guint i = 1; i < val->data.list->len; i++) { + tmp = li_value_to_string(g_ptr_array_index(val->data.list, i)); + g_string_append_len(str, CONST_STR_LEN(", ")); + g_string_append(str, tmp->str); + g_string_free(tmp, TRUE); + } + } + g_string_append_c(str, ')'); + break; + default: + /* other cases need to be handled by li_value_to_string */ + break; + } + + return str; +} + +void li_value_free(liValue* val) { + if (NULL == val) return; + li_value_clear(val); + g_slice_free(liValue, val); +} + +void li_value_move(liValue *dest, liValue *src) { + LI_FORCE_ASSERT(NULL != dest && NULL != src && dest != src); + li_value_clear(dest); + *dest = *src; + _li_value_clear(src); +} + +static void _value_hash_free_key(gpointer data) { + g_string_free((GString*) data, TRUE); +} + +static void _value_hash_free_value(gpointer data) { + li_value_free((liValue*) data); +} + +GHashTable *li_value_new_hashtable(void) { + return g_hash_table_new_full( + (GHashFunc) g_string_hash, (GEqualFunc) g_string_equal, + _value_hash_free_key, _value_hash_free_value); +} + +void li_value_list_free(GPtrArray *vallist) { + if (NULL == vallist) return; + for (gsize i = 0; i < vallist->len; i++) { + li_value_free(g_ptr_array_index(vallist, i)); + } + g_ptr_array_free(vallist, TRUE); +} + +void li_common_value_clear_(liValue *val) { + if (NULL == val) return; + + switch (val->type) { + case LI_VALUE_NONE: + case LI_VALUE_BOOLEAN: + case LI_VALUE_NUMBER: + /* Nothing to free */ + break; + case LI_VALUE_STRING: + g_string_free(val->data.string, TRUE); + break; + case LI_VALUE_LIST: + li_value_list_free(val->data.list); + break; + default: + /* other cases need to be handled by li_value_clear */ + break; + } + _li_value_clear(val); +} diff --git a/src/main/value.c b/src/main/value.c index 963f82a..5b8d03f 100644 --- a/src/main/value.c +++ b/src/main/value.c @@ -1,5 +1,7 @@ #include +#include "../common/value_impl.c" + liValue* li_value_new_action(liServer *srv, liAction *a) { liValue *v = g_slice_new0(liValue); v->data.val_action.srv = srv; @@ -35,11 +37,6 @@ liValue* li_value_copy(liValue* val) { return NULL; } -static void _li_value_clear(liValue *val) { - memset(val, 0, sizeof(*val)); - val->type = LI_VALUE_NONE; -} - void li_value_clear(liValue *val) { if (NULL == val) return;