diff --git a/c3s/Makefile b/c3s/Makefile
index 838551d..1c8f2e0 100644
--- a/c3s/Makefile
+++ b/c3s/Makefile
@@ -20,7 +20,10 @@ DISTCLEANFILES = ${CLEANFILES} config.mk
build: c3s
-all: build cov debug
+all:
+ ${MAKE} build
+ if ${HAVE_GCOV}; then ${MAKE} cov; fi
+ ${MAKE} debug
if ${HAVE_ASAN}; then ${MAKE} asan; fi
asan: c3s.asan
diff --git a/c3s/configure b/c3s/configure
index a732f39..6769787 100755
--- a/c3s/configure
+++ b/c3s/configure
@@ -30,8 +30,10 @@ echo "OBJECTS = $OBJECTS" >> ${CONFIG_MK}
OBJECTS_ASAN="$(c2ext .asan.lo "$SOURCES")"
echo "OBJECTS_ASAN = $OBJECTS_ASAN" >> ${CONFIG_MK}
-OBJECTS_COV="$(c2ext .cov.lo "$SOURCES")"
-echo "OBJECTS_COV = $OBJECTS_COV" >> ${CONFIG_MK}
+if $HAVE_GCOV; then
+ OBJECTS_COV="$(c2ext .cov.lo "$SOURCES")"
+ echo "OBJECTS_COV = $OBJECTS_COV" >> ${CONFIG_MK}
+fi
OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
@@ -86,10 +88,12 @@ echo >> ${CONFIG_MK}
echo "CFLAGS_ASAN = $CFLAGS_ASAN" >> ${CONFIG_MK}
echo "LDFLAGS_ASAN = $LDFLAGS_ASAN" >> ${CONFIG_MK}
echo "LIBS_ASAN = $LIBS_ASAN" >> ${CONFIG_MK}
-echo >> ${CONFIG_MK}
-echo "CFLAGS_COV = $CFLAGS_COV" >> ${CONFIG_MK}
-echo "LDFLAGS_COV = $LDFLAGS_COV" >> ${CONFIG_MK}
-echo "LIBS_COV = $LIBS_COV" >> ${CONFIG_MK}
+if $HAVE_GCOV; then
+ echo >> ${CONFIG_MK}
+ echo "CFLAGS_COV = $CFLAGS_COV" >> ${CONFIG_MK}
+ echo "LDFLAGS_COV = $LDFLAGS_COV" >> ${CONFIG_MK}
+ echo "LIBS_COV = $LIBS_COV" >> ${CONFIG_MK}
+fi
echo >> ${CONFIG_MK}
echo "CFLAGS_DEBUG = $CFLAGS_DEBUG" >> ${CONFIG_MK}
echo "LDFLAGS_DEBUG = $LDFLAGS_DEBUG" >> ${CONFIG_MK}
@@ -106,10 +110,12 @@ for SRC in $SOURCES; do
ext_rule .asan.lo "$SRC" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_ASAN} -c $SRC -o $SRC_ASAN_LO" >> ${CONFIG_MK}
- echo >> ${CONFIG_MK}
- SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
- ext_rule .cov.lo "$SRC" >> ${CONFIG_MK}
- echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_COV} -c $SRC -o $SRC_COV_LO" >> ${CONFIG_MK}
+ if $HAVE_GCOV; then
+ echo >> ${CONFIG_MK}
+ SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
+ ext_rule .cov.lo "$SRC" >> ${CONFIG_MK}
+ echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_COV} -c $SRC -o $SRC_COV_LO" >> ${CONFIG_MK}
+ fi
echo >> ${CONFIG_MK}
SRC_DEBUG_LO="$(c2ext .debug.lo "$SRC")"
@@ -125,9 +131,11 @@ echo >> ${CONFIG_MK}
echo "$PROG_ASAN: $LIBC3_ASAN $OBJECTS_ASAN" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_ASAN} \${LDFLAGS_ASAN} ${OBJECTS_ASAN} ${LIBS_ASAN} -o $PROG_ASAN" >> ${CONFIG_MK}
-echo >> ${CONFIG_MK}
-echo "$PROG_COV: $LIBC3_COV $OBJECTS_COV" >> ${CONFIG_MK}
-echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_COV} \${LDFLAGS_COV} ${OBJECTS_COV} ${LIBS_COV} -o $PROG_COV" >> ${CONFIG_MK}
+if $HAVE_GCOV; then
+ echo >> ${CONFIG_MK}
+ echo "$PROG_COV: $LIBC3_COV $OBJECTS_COV" >> ${CONFIG_MK}
+ echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_COV} \${LDFLAGS_COV} ${OBJECTS_COV} ${LIBS_COV} -o $PROG_COV" >> ${CONFIG_MK}
+fi
echo >> ${CONFIG_MK}
echo "$PROG_DEBUG: $LIBC3_DEBUG $OBJECTS_DEBUG" >> ${CONFIG_MK}
diff --git a/config.subr b/config.subr
index eef1b1e..03d468a 100644
--- a/config.subr
+++ b/config.subr
@@ -110,17 +110,23 @@ if test -z "$CC"; then
fi
echo "CC = $CC" >> ${CONFIG_MK}
-if test -z "$GCOV"; then
- if test -x "$(which gcov)"; then
- GCOV=gcov
- elif test -x "$(which egcov)"; then
- GCOV=egcov
- else
- GCOV=gcov
+if [ "x$GCOV" = "x" ]; then
+ if which gcov 2>/dev/null; then
+ GCOV=gcov
+ HAVE_GCOV=true
+ elif which egcov 2>/dev/null; then
+ GCOV=egcov
+ HAVE_GCOV=true
fi
+ HAVE_GCOV=false
+else
+ HAVE_GCOV=true
+fi
+echo "HAVE_GCOV = $HAVE_GCOV" >> ${CONFIG_MK}
+if ${HAVE_GCOV}; then
+ echo "GCOV = $GCOV" >> ${CONFIG_MK}
fi
-echo "GCOV = $GCOV" >> ${CONFIG_MK}
-
+
if test -z "$INSTALL"; then
if test -x "$(which install)"; then
INSTALL=install
diff --git a/ic3/Makefile b/ic3/Makefile
index 54a3699..05d1f9c 100644
--- a/ic3/Makefile
+++ b/ic3/Makefile
@@ -20,7 +20,10 @@ DISTCLEANFILES = ${CLEANFILES} config.mk
build: ic3
-all: build cov debug
+all:
+ ${MAKE} build
+ if ${HAVE_GCOV}; then ${MAKE} cov; fi
+ ${MAKE} debug
if ${HAVE_ASAN}; then ${MAKE} asan; fi
asan: ic3.asan
diff --git a/ic3/configure b/ic3/configure
index 8ed3b8c..b1c41e8 100755
--- a/ic3/configure
+++ b/ic3/configure
@@ -30,8 +30,10 @@ echo "OBJECTS = $OBJECTS" >> ${CONFIG_MK}
OBJECTS_ASAN="$(c2ext .asan.lo "$SOURCES")"
echo "OBJECTS_ASAN = $OBJECTS_ASAN" >> ${CONFIG_MK}
-OBJECTS_COV="$(c2ext .cov.lo "$SOURCES")"
-echo "OBJECTS_COV = $OBJECTS_COV" >> ${CONFIG_MK}
+if $HAVE_GCOV; then
+ OBJECTS_COV="$(c2ext .cov.lo "$SOURCES")"
+ echo "OBJECTS_COV = $OBJECTS_COV" >> ${CONFIG_MK}
+fi
OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
@@ -86,10 +88,12 @@ echo >> ${CONFIG_MK}
echo "CFLAGS_ASAN = $CFLAGS_ASAN" >> ${CONFIG_MK}
echo "LDFLAGS_ASAN = $LDFLAGS_ASAN" >> ${CONFIG_MK}
echo "LIBS_ASAN = $LIBS_ASAN" >> ${CONFIG_MK}
-echo >> ${CONFIG_MK}
-echo "CFLAGS_COV = $CFLAGS_COV" >> ${CONFIG_MK}
-echo "LDFLAGS_COV = $LDFLAGS_COV" >> ${CONFIG_MK}
-echo "LIBS_COV = $LIBS_COV" >> ${CONFIG_MK}
+if $HAVE_GCOV; then
+ echo >> ${CONFIG_MK}
+ echo "CFLAGS_COV = $CFLAGS_COV" >> ${CONFIG_MK}
+ echo "LDFLAGS_COV = $LDFLAGS_COV" >> ${CONFIG_MK}
+ echo "LIBS_COV = $LIBS_COV" >> ${CONFIG_MK}
+fi
echo >> ${CONFIG_MK}
echo "CFLAGS_DEBUG = $CFLAGS_DEBUG" >> ${CONFIG_MK}
echo "LDFLAGS_DEBUG = $LDFLAGS_DEBUG" >> ${CONFIG_MK}
@@ -106,10 +110,12 @@ for SRC in $SOURCES; do
ext_rule .asan.lo "$SRC" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_ASAN} -c $SRC -o $SRC_ASAN_LO" >> ${CONFIG_MK}
- echo >> ${CONFIG_MK}
- SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
- ext_rule .cov.lo "$SRC" >> ${CONFIG_MK}
- echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_COV} -c $SRC -o $SRC_COV_LO" >> ${CONFIG_MK}
+ if $HAVE_GCOV; then
+ echo >> ${CONFIG_MK}
+ SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
+ ext_rule .cov.lo "$SRC" >> ${CONFIG_MK}
+ echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_COV} -c $SRC -o $SRC_COV_LO" >> ${CONFIG_MK}
+ fi
echo >> ${CONFIG_MK}
SRC_DEBUG_LO="$(c2ext .debug.lo "$SRC")"
@@ -125,9 +131,11 @@ echo >> ${CONFIG_MK}
echo "$PROG_ASAN: $LIBC3_ASAN $OBJECTS_ASAN" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_ASAN} \${LDFLAGS_ASAN} ${OBJECTS_ASAN} ${LIBS_ASAN} -o $PROG_ASAN" >> ${CONFIG_MK}
-echo >> ${CONFIG_MK}
-echo "$PROG_COV: $LIBC3_COV $OBJECTS_COV" >> ${CONFIG_MK}
-echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_COV} \${LDFLAGS_COV} ${OBJECTS_COV} ${LIBS_COV} -o $PROG_COV" >> ${CONFIG_MK}
+if $HAVE_GCOV; then
+ echo >> ${CONFIG_MK}
+ echo "$PROG_COV: $LIBC3_COV $OBJECTS_COV" >> ${CONFIG_MK}
+ echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_COV} \${LDFLAGS_COV} ${OBJECTS_COV} ${LIBS_COV} -o $PROG_COV" >> ${CONFIG_MK}
+fi
echo >> ${CONFIG_MK}
echo "$PROG_DEBUG: $LIBC3_DEBUG $OBJECTS_DEBUG" >> ${CONFIG_MK}
diff --git a/libc3/Makefile b/libc3/Makefile
index b0ea012..e243847 100644
--- a/libc3/Makefile
+++ b/libc3/Makefile
@@ -22,7 +22,7 @@ build: libc3.la libc3.a
all:
${MAKE} build
- ${MAKE} cov
+ if ${HAVE_GCOV}; then ${MAKE} cov; fi
${MAKE} debug
if ${HAVE_ASAN}; then ${MAKE} asan; fi
diff --git a/libc3/buf_inspect.c b/libc3/buf_inspect.c
index 2608f7d..23f8641 100644
--- a/libc3/buf_inspect.c
+++ b/libc3/buf_inspect.c
@@ -1045,6 +1045,17 @@ sw buf_inspect_u64 (s_buf *buf, u64 x)
return size;
}
+sw buf_inspect_u32_hex (s_buf *buf, u32 i)
+{
+ const s8 basis[] = "0123456789ABCDEF";
+ uw shift = 32;
+ while (shift) {
+ shift -= 4;
+ buf_write_s8(buf, basis[(i >> shift) & 0xF]);
+ }
+ return 8;
+}
+
sw buf_inspect_u64_hex (s_buf *buf, u64 i)
{
const s8 basis[] = "0123456789ABCDEF";
diff --git a/libc3/configure b/libc3/configure
index a4e9f51..567a0bc 100755
--- a/libc3/configure
+++ b/libc3/configure
@@ -100,10 +100,12 @@ for SRC in $SOURCES; do
ext_rule .asan.lo "$SRC" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_ASAN} -c $SRC -o $SRC_ASAN_LO" >> ${CONFIG_MK}
- echo >> ${CONFIG_MK}
- SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
- ext_rule .cov.lo "$SRC" >> ${CONFIG_MK}
- echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_COV} -c $SRC -o $SRC_COV_LO" >> ${CONFIG_MK}
+ if [ -n "$GCOV" ]; then
+ echo >> ${CONFIG_MK}
+ SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
+ ext_rule .cov.lo "$SRC" >> ${CONFIG_MK}
+ echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_COV} -c $SRC -o $SRC_COV_LO" >> ${CONFIG_MK}
+ fi
echo >> ${CONFIG_MK}
SRC_DEBUG_LO="$(c2ext .debug.lo "$SRC")"
@@ -119,9 +121,11 @@ echo >> ${CONFIG_MK}
echo "$LIB_ASAN: $OBJECTS_ASAN" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${LDFLAGS_ASAN} ${OBJECTS_ASAN} \${LIBS_ASAN} -o ${LIB_ASAN}" >> ${CONFIG_MK}
-echo >> ${CONFIG_MK}
-echo "$LIB_COV: $OBJECTS_COV" >> ${CONFIG_MK}
-echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${LDFLAGS_COV} ${OBJECTS_COV} \${LIBS_COV} -o ${LIB_COV}" >> ${CONFIG_MK}
+if [ -n "$GCOV" ]; then
+ echo >> ${CONFIG_MK}
+ echo "$LIB_COV: $OBJECTS_COV" >> ${CONFIG_MK}
+ echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${LDFLAGS_COV} ${OBJECTS_COV} \${LIBS_COV} -o ${LIB_COV}" >> ${CONFIG_MK}
+fi
echo >> ${CONFIG_MK}
echo "$LIB_DEBUG: $OBJECTS_DEBUG" >> ${CONFIG_MK}
diff --git a/libc3/skiplist.c.in b/libc3/skiplist.c.in
index bd717e9..a7d0e02 100644
--- a/libc3/skiplist.c.in
+++ b/libc3/skiplist.c.in
@@ -95,7 +95,7 @@ skiplist_find___NAME$ (s_skiplist___NAME$ *skiplist, _TYPE$ _NAME$)
static void skiplist_height_table_init___NAME$ (s_skiplist___NAME$ *skiplist, f64 spacing)
{
- sw *height_table;
+ t_skiplist_height *height_table;
u8 h;
f64 w = spacing;
f64 end = w;
@@ -103,6 +103,7 @@ static void skiplist_height_table_init___NAME$ (s_skiplist___NAME$ *skiplist, f6
for (h = 0; h < skiplist->max_height; h++) {
w *= spacing;
end += w;
+ assert(end <= (f64) SKIPLIST_HEIGHT_MAX);
height_table[h] = end;
}
}
@@ -122,10 +123,12 @@ skiplist_init___NAME$ (s_skiplist___NAME$ *skiplist, u8 max_height, f64 spacing)
s_skiplist_node___NAME$ *
skiplist_insert___NAME$ (s_skiplist___NAME$ *skiplist, _TYPE$ _NAME$)
{
- s_skiplist_node___NAME$ *pred = skiplist_pred___NAME$(skiplist, _NAME$);
- s_skiplist_node___NAME$ *next = SKIPLIST_NODE_NEXT___NAME$(pred, 0);
+ s_skiplist_node___NAME$ *pred;
+ s_skiplist_node___NAME$ *next;
uw height;
s_skiplist_node___NAME$ *node;
+ pred = skiplist_pred___NAME$(skiplist, _NAME$);
+ next = SKIPLIST_NODE_NEXT___NAME$(pred, 0);
next = SKIPLIST_NODE_NEXT___NAME$(next, 0);
if (next && skiplist->compare(_NAME$, next->_NAME$) == 0)
return next;
@@ -149,13 +152,17 @@ skiplist_new___NAME$ (u8 max_height, f64 spacing)
s_skiplist_node___NAME$ *
skiplist_pred___NAME$ (s_skiplist___NAME$ *skiplist, _TYPE$ _NAME$)
{
- int level = skiplist->max_height;
- s_skiplist_node___NAME$ *pred =
- skiplist_node_new___NAME$(NULL, skiplist->max_height);
- s_skiplist_node___NAME$ *node = skiplist->head;
+ int level;
+ s_skiplist_node___NAME$ *pred;
+ s_skiplist_node___NAME$ *n;
+ s_skiplist_node___NAME$ *node;
+ assert(skiplist);
+ level = skiplist->max_height;
+ pred = skiplist_node_new___NAME$(NULL, skiplist->max_height);
+ node = skiplist->head;
assert(pred);
while (level--) {
- s_skiplist_node___NAME$ *n = node;
+ n = node;
while (n && skiplist->compare(_NAME$, n->_NAME$) > 0) {
node = n;
n = SKIPLIST_NODE_NEXT___NAME$(node, level);
@@ -168,14 +175,20 @@ skiplist_pred___NAME$ (s_skiplist___NAME$ *skiplist, _TYPE$ _NAME$)
u8
skiplist_random_height___NAME$ (s_skiplist___NAME$ *skiplist)
{
- const sw *height_table = SKIPLIST_HEIGHT_TABLE___NAME$(skiplist);
- sw max = height_table[skiplist->max_height - 1];
-
- sw k = random() % max;
+ u8 height;
+ const t_skiplist_height *height_table;
+ sw max;
+ t_skiplist_height k;
sw i;
- for (i = 0; k > height_table[i]; i++)
+ assert(skiplist);
+ height_table = SKIPLIST_HEIGHT_TABLE___NAME$(skiplist);
+ max = height_table[skiplist->max_height - 1];
+ k = random() % max;
+ for (i = 0; i < skiplist->max_height && k > height_table[i]; i++)
;
- return skiplist->max_height - i;
+ height = skiplist->max_height - i;
+ assert(height);
+ return height;
}
e_bool
diff --git a/libc3/skiplist.h.in b/libc3/skiplist.h.in
index 37f585e..0bf4676 100644
--- a/libc3/skiplist.h.in
+++ b/libc3/skiplist.h.in
@@ -24,10 +24,10 @@
#include "types.h"
#define SKIPLIST_HEIGHT_TABLE___NAME$(skiplist) \
- ((sw *) (((s_skiplist___NAME$ *) skiplist) + 1))
+ ((t_skiplist_height *) (((s_skiplist___NAME$ *) skiplist) + 1))
#define SKIPLIST_SIZE___NAME$(max_height) \
- (sizeof(s_skiplist___NAME$) + (max_height) * sizeof(sw))
+ (sizeof(s_skiplist___NAME$) + (max_height) * sizeof(t_skiplist_height))
#define SKIPLIST_INIT_ALLOCA___NAME$(max_height, spacing) \
(skiplist_init___NAME$(alloca(SKIPLIST_SIZE___NAME$(max_height)), \
diff --git a/libc3/skiplist__fact.c b/libc3/skiplist__fact.c
index 18c86da..ca98ec3 100644
--- a/libc3/skiplist__fact.c
+++ b/libc3/skiplist__fact.c
@@ -95,7 +95,7 @@ skiplist_find__fact (s_skiplist__fact *skiplist, s_fact * fact)
static void skiplist_height_table_init__fact (s_skiplist__fact *skiplist, f64 spacing)
{
- sw *height_table;
+ t_skiplist_height *height_table;
u8 h;
f64 w = spacing;
f64 end = w;
@@ -103,6 +103,7 @@ static void skiplist_height_table_init__fact (s_skiplist__fact *skiplist, f64 sp
for (h = 0; h < skiplist->max_height; h++) {
w *= spacing;
end += w;
+ assert(end <= (f64) SKIPLIST_HEIGHT_MAX);
height_table[h] = end;
}
}
@@ -122,10 +123,12 @@ skiplist_init__fact (s_skiplist__fact *skiplist, u8 max_height, f64 spacing)
s_skiplist_node__fact *
skiplist_insert__fact (s_skiplist__fact *skiplist, s_fact * fact)
{
- s_skiplist_node__fact *pred = skiplist_pred__fact(skiplist, fact);
- s_skiplist_node__fact *next = SKIPLIST_NODE_NEXT__fact(pred, 0);
+ s_skiplist_node__fact *pred;
+ s_skiplist_node__fact *next;
uw height;
s_skiplist_node__fact *node;
+ pred = skiplist_pred__fact(skiplist, fact);
+ next = SKIPLIST_NODE_NEXT__fact(pred, 0);
next = SKIPLIST_NODE_NEXT__fact(next, 0);
if (next && skiplist->compare(fact, next->fact) == 0)
return next;
@@ -149,13 +152,17 @@ skiplist_new__fact (u8 max_height, f64 spacing)
s_skiplist_node__fact *
skiplist_pred__fact (s_skiplist__fact *skiplist, s_fact * fact)
{
- int level = skiplist->max_height;
- s_skiplist_node__fact *pred =
- skiplist_node_new__fact(NULL, skiplist->max_height);
- s_skiplist_node__fact *node = skiplist->head;
+ int level;
+ s_skiplist_node__fact *pred;
+ s_skiplist_node__fact *n;
+ s_skiplist_node__fact *node;
+ assert(skiplist);
+ level = skiplist->max_height;
+ pred = skiplist_node_new__fact(NULL, skiplist->max_height);
+ node = skiplist->head;
assert(pred);
while (level--) {
- s_skiplist_node__fact *n = node;
+ n = node;
while (n && skiplist->compare(fact, n->fact) > 0) {
node = n;
n = SKIPLIST_NODE_NEXT__fact(node, level);
@@ -168,14 +175,20 @@ skiplist_pred__fact (s_skiplist__fact *skiplist, s_fact * fact)
u8
skiplist_random_height__fact (s_skiplist__fact *skiplist)
{
- const sw *height_table = SKIPLIST_HEIGHT_TABLE__fact(skiplist);
- sw max = height_table[skiplist->max_height - 1];
-
- sw k = random() % max;
+ u8 height;
+ const t_skiplist_height *height_table;
+ sw max;
+ t_skiplist_height k;
sw i;
- for (i = 0; k > height_table[i]; i++)
+ assert(skiplist);
+ height_table = SKIPLIST_HEIGHT_TABLE__fact(skiplist);
+ max = height_table[skiplist->max_height - 1];
+ k = random() % max;
+ for (i = 0; i < skiplist->max_height && k > height_table[i]; i++)
;
- return skiplist->max_height - i;
+ height = skiplist->max_height - i;
+ assert(height);
+ return height;
}
e_bool
diff --git a/libc3/skiplist__fact.h b/libc3/skiplist__fact.h
index 971e53a..b2961f0 100644
--- a/libc3/skiplist__fact.h
+++ b/libc3/skiplist__fact.h
@@ -24,10 +24,10 @@
#include "types.h"
#define SKIPLIST_HEIGHT_TABLE__fact(skiplist) \
- ((sw *) (((s_skiplist__fact *) skiplist) + 1))
+ ((t_skiplist_height *) (((s_skiplist__fact *) skiplist) + 1))
#define SKIPLIST_SIZE__fact(max_height) \
- (sizeof(s_skiplist__fact) + (max_height) * sizeof(sw))
+ (sizeof(s_skiplist__fact) + (max_height) * sizeof(t_skiplist_height))
#define SKIPLIST_INIT_ALLOCA__fact(max_height, spacing) \
(skiplist_init__fact(alloca(SKIPLIST_SIZE__fact(max_height)), \
diff --git a/libc3/skiplist_node.c.in b/libc3/skiplist_node.c.in
index 872aa0f..bd6d937 100644
--- a/libc3/skiplist_node.c.in
+++ b/libc3/skiplist_node.c.in
@@ -17,7 +17,7 @@
#include "skiplist_node___NAME$.h"
s_skiplist_node___NAME$ *
-skiplist_node_init (s_skiplist_node___NAME$ *node, _TYPE$ _NAME$, uw height)
+skiplist_node_init (s_skiplist_node___NAME$ *node, _TYPE$ _NAME$, u8 height)
{
node->_NAME$ = _NAME$;
node->height = height;
@@ -27,7 +27,7 @@ skiplist_node_init (s_skiplist_node___NAME$ *node, _TYPE$ _NAME$, uw height)
}
s_skiplist_node___NAME$ *
-skiplist_node_new___NAME$ (_TYPE$ _NAME$, uw height)
+skiplist_node_new___NAME$ (_TYPE$ _NAME$, u8 height)
{
s_skiplist_node___NAME$ *node = malloc(SKIPLIST_NODE_SIZE___NAME$(height));
if (node)
diff --git a/libc3/skiplist_node.h.in b/libc3/skiplist_node.h.in
index 39c129b..4d5d4ee 100644
--- a/libc3/skiplist_node.h.in
+++ b/libc3/skiplist_node.h.in
@@ -33,10 +33,10 @@
(sizeof(s_skiplist_node___NAME$) + (height) * sizeof(_TYPE$))
s_skiplist_node___NAME$ *
-skiplist_node_init (s_skiplist_node___NAME$ *node, _TYPE$ value, unsigned long height);
+skiplist_node_init (s_skiplist_node___NAME$ *node, _TYPE$ value, u8 height);
s_skiplist_node___NAME$ *
-skiplist_node_new___NAME$ (_TYPE$ value, unsigned long height);
+skiplist_node_new___NAME$ (_TYPE$ value, u8 height);
void
skiplist_node_delete___NAME$ (s_skiplist_node___NAME$ *node);
diff --git a/libc3/skiplist_node__fact.c b/libc3/skiplist_node__fact.c
index eaac61c..065dcf5 100644
--- a/libc3/skiplist_node__fact.c
+++ b/libc3/skiplist_node__fact.c
@@ -17,7 +17,7 @@
#include "skiplist_node__fact.h"
s_skiplist_node__fact *
-skiplist_node_init (s_skiplist_node__fact *node, s_fact * fact, uw height)
+skiplist_node_init (s_skiplist_node__fact *node, s_fact * fact, u8 height)
{
node->fact = fact;
node->height = height;
@@ -27,7 +27,7 @@ skiplist_node_init (s_skiplist_node__fact *node, s_fact * fact, uw height)
}
s_skiplist_node__fact *
-skiplist_node_new__fact (s_fact * fact, uw height)
+skiplist_node_new__fact (s_fact * fact, u8 height)
{
s_skiplist_node__fact *node = malloc(SKIPLIST_NODE_SIZE__fact(height));
if (node)
diff --git a/libc3/skiplist_node__fact.h b/libc3/skiplist_node__fact.h
index e2b7acf..ea64f5c 100644
--- a/libc3/skiplist_node__fact.h
+++ b/libc3/skiplist_node__fact.h
@@ -33,10 +33,10 @@
(sizeof(s_skiplist_node__fact) + (height) * sizeof(s_fact *))
s_skiplist_node__fact *
-skiplist_node_init (s_skiplist_node__fact *node, s_fact * value, unsigned long height);
+skiplist_node_init (s_skiplist_node__fact *node, s_fact * value, u8 height);
s_skiplist_node__fact *
-skiplist_node_new__fact (s_fact * value, unsigned long height);
+skiplist_node_new__fact (s_fact * value, u8 height);
void
skiplist_node_delete__fact (s_skiplist_node__fact *node);
diff --git a/libc3/types.h b/libc3/types.h
index 6ac238b..bf012df 100644
--- a/libc3/types.h
+++ b/libc3/types.h
@@ -14,21 +14,27 @@
#ifndef TYPES_H
#define TYPES_H
+#include <limits.h>
#include <setjmp.h>
#include <stdio.h>
+#include <sys/types.h>
#include "../libtommath/tommath.h"
/* Basic integer types. */
-typedef char s8;
-typedef short s16;
-typedef int s32;
-typedef long sw;
-typedef long long s64;
-typedef unsigned char u8;
-typedef unsigned short u16;
-typedef unsigned int u32;
-typedef unsigned long uw;
-typedef unsigned long long u64;
+typedef char s8;
+typedef int16_t s16;
+typedef int32_t s32;
+typedef long sw;
+typedef int64_t s64;
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef unsigned long uw;
+typedef uint64_t u64;
+
+#define S32_MAX LONG_MAX
+#define S64_MAX LLONG_MAX
+#define U64_MAX ULLONG_MAX
/* IEEE 754 floating point numbers. */
typedef float f32;
@@ -112,6 +118,10 @@ typedef s_tag **p_facts_spec;
typedef s_tag *p_quote;
typedef const s_tag *p_tag;
typedef const s_tag *p_var;
+typedef u64 t_skiplist_height;
+
+#define CHARACTER_MAX S32_MAX
+#define SKIPLIST_HEIGHT_MAX U64_MAX
/* 1 */
struct buf_save {
diff --git a/test/Makefile b/test/Makefile
index 6c346bf..b97d009 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -20,7 +20,10 @@ DISTCLEANFILES = ${CLEANFILES} config.mk
build: libc3_test
-all: build cov debug
+all:
+ ${MAKE} build
+ if ${HAVE_GCOV}; then ${MAKE} cov; fi
+ ${MAKE} debug
if ${HAVE_ASAN}; then ${MAKE} asan; fi
asan: libc3_test.asan
diff --git a/test/buf_parse_test.c b/test/buf_parse_test.c
index b9424ce..7e8898c 100644
--- a/test/buf_parse_test.c
+++ b/test/buf_parse_test.c
@@ -789,9 +789,9 @@ void buf_parse_test_digit_dec ()
void buf_parse_test_f32()
{
- BUF_PARSE_TEST_F32("123.123", 123.12299);
- BUF_PARSE_TEST_F32("3.14159", 3.141589641571045);
- BUF_PARSE_TEST_F32("2.1e+2", 209.9999847412109);
+ BUF_PARSE_TEST_F32("123.123", 123.123);
+ BUF_PARSE_TEST_F32("3.14159", 3.14159);
+ BUF_PARSE_TEST_F32("2.1e+2", 210);
}
void buf_parse_test_f64()
diff --git a/test/configure b/test/configure
index 44d4eeb..8d204bf 100755
--- a/test/configure
+++ b/test/configure
@@ -32,8 +32,10 @@ echo "OBJECTS = $OBJECTS" >> ${CONFIG_MK}
OBJECTS_ASAN="$(c2ext .asan.lo "$SOURCES")"
echo "OBJECTS_ASAN = $OBJECTS_ASAN" >> ${CONFIG_MK}
-OBJECTS_COV="$(c2ext .cov.lo "$SOURCES")"
-echo "OBJECTS_COV = $OBJECTS_COV" >> ${CONFIG_MK}
+if $HAVE_GCOV; then
+ OBJECTS_COV="$(c2ext .cov.lo "$SOURCES")"
+ echo "OBJECTS_COV = $OBJECTS_COV" >> ${CONFIG_MK}
+fi
OBJECTS_DEBUG="$(c2ext .debug.lo "$SOURCES")"
echo "OBJECTS_DEBUG = $OBJECTS_DEBUG" >> ${CONFIG_MK}
@@ -88,10 +90,12 @@ echo >> ${CONFIG_MK}
echo "CFLAGS_ASAN = $CFLAGS_ASAN" >> ${CONFIG_MK}
echo "LDFLAGS_ASAN = $LDFLAGS_ASAN" >> ${CONFIG_MK}
echo "LIBS_ASAN = $LIBS_ASAN" >> ${CONFIG_MK}
-echo >> ${CONFIG_MK}
-echo "CFLAGS_COV = $CFLAGS_COV" >> ${CONFIG_MK}
-echo "LDFLAGS_COV = $LDFLAGS_COV" >> ${CONFIG_MK}
-echo "LIBS_COV = $LIBS_COV" >> ${CONFIG_MK}
+if $HAVE_GCOV; then
+ echo >> ${CONFIG_MK}
+ echo "CFLAGS_COV = $CFLAGS_COV" >> ${CONFIG_MK}
+ echo "LDFLAGS_COV = $LDFLAGS_COV" >> ${CONFIG_MK}
+ echo "LIBS_COV = $LIBS_COV" >> ${CONFIG_MK}
+fi
echo >> ${CONFIG_MK}
echo "CFLAGS_DEBUG = $CFLAGS_DEBUG" >> ${CONFIG_MK}
echo "LDFLAGS_DEBUG = $LDFLAGS_DEBUG" >> ${CONFIG_MK}
@@ -108,10 +112,12 @@ for SRC in $SOURCES; do
ext_rule .asan.lo "$SRC" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_ASAN} -c $SRC -o $SRC_ASAN_LO" >> ${CONFIG_MK}
- echo >> ${CONFIG_MK}
- SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
- ext_rule .cov.lo "$SRC" >> ${CONFIG_MK}
- echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_COV} -c $SRC -o $SRC_COV_LO" >> ${CONFIG_MK}
+ if $HAVE_GCOV; then
+ echo >> ${CONFIG_MK}
+ SRC_COV_LO="$(c2ext .cov.lo "$SRC")"
+ ext_rule .cov.lo "$SRC" >> ${CONFIG_MK}
+ echo " ${LIBTOOL} --tag=CC --mode=compile \${CC} \${CPPFLAGS} \${CFLAGS_COV} -c $SRC -o $SRC_COV_LO" >> ${CONFIG_MK}
+ fi
echo >> ${CONFIG_MK}
SRC_DEBUG_LO="$(c2ext .debug.lo "$SRC")"
@@ -127,9 +133,11 @@ echo >> ${CONFIG_MK}
echo "$PROG_ASAN: $LIBC3_ASAN $OBJECTS_ASAN" >> ${CONFIG_MK}
echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_ASAN} \${LDFLAGS_ASAN} ${OBJECTS_ASAN} ${LIBS_ASAN} -o $PROG_ASAN" >> ${CONFIG_MK}
-echo >> ${CONFIG_MK}
-echo "$PROG_COV: $LIBC3_COV $OBJECTS_COV" >> ${CONFIG_MK}
-echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_COV} \${LDFLAGS_COV} ${OBJECTS_COV} ${LIBS_COV} -o $PROG_COV" >> ${CONFIG_MK}
+if $HAVE_GCOV; then
+ echo >> ${CONFIG_MK}
+ echo "$PROG_COV: $LIBC3_COV $OBJECTS_COV" >> ${CONFIG_MK}
+ echo " ${LIBTOOL} --tag=CC --mode=link \${CC} \${CFLAGS_COV} \${LDFLAGS_COV} ${OBJECTS_COV} ${LIBS_COV} -o $PROG_COV" >> ${CONFIG_MK}
+fi
echo >> ${CONFIG_MK}
echo "$PROG_DEBUG: $LIBC3_DEBUG $OBJECTS_DEBUG" >> ${CONFIG_MK}
diff --git a/test/skiplist__fact_test.c b/test/skiplist__fact_test.c
index 702be6b..a47568a 100644
--- a/test/skiplist__fact_test.c
+++ b/test/skiplist__fact_test.c
@@ -85,7 +85,7 @@ void skiplist__fact_test_find ()
{
s_fact fact[24];
const u8 *h;
- const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 64, 128, 255, 0};
+ const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 0};
sw i;
s8 *p[24] = {
"\"a\"",
@@ -141,7 +141,7 @@ void skiplist__fact_test_insert ()
{
sw i;
const u8 *h;
- const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 64, 128, 255, 0};
+ const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 0};
const double *s;
const double spacing[] = {2.0, 2.4, 3.0, 0.0};
s8 *p[24] = {
@@ -198,7 +198,7 @@ void skiplist__fact_test_insert ()
void skiplist__fact_test_init_clean ()
{
const u8 *h;
- const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 64, 128, 255, 0};
+ const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 0};
const double *s;
const double spacing[] = {2.0, 2.4, 3.0, 0.0};
for (h = height; *h; h++) {
@@ -211,7 +211,7 @@ void skiplist__fact_test_init_clean ()
void skiplist__fact_test_new_delete ()
{
const u8 *h;
- const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 64, 128, 255, 0};
+ const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 0};
const double *s;
const double spacing[] = {2.0, 2.4, 3.0, 0.0};
for (h = height; *h; h++) {
@@ -225,7 +225,7 @@ void skiplist__fact_test_remove ()
{
s_fact fact[24];
const u8 *h;
- const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 64, 128, 255, 0};
+ const u8 height[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 0};
sw i;
s8 *p[24] = {
"\"a\"",