2
0
Fork 0

[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.
personal/stbuehler/wip
Stefan Bühler 2014-05-22 14:58:01 +02:00
parent 55042a89a9
commit d58d98a62d
7 changed files with 140 additions and 123 deletions

View File

@ -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 \

View File

@ -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})

View File

@ -1,5 +1,7 @@
#include <lighttpd/angel_base.h>
#include "../common/value_impl.c"
liValue* li_value_copy(liValue* val) {
return li_common_value_copy_(val);
}

View File

@ -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 $@ $<

View File

@ -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 "<unknown>";
}
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;

132
src/common/value_impl.c Normal file
View File

@ -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);
}

View File

@ -1,5 +1,7 @@
#include <lighttpd/base.h>
#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;