Merge Makefile rewrite into master
authorDavid Gibson <david@gibson.dropbear.id.au>
Mon, 21 Nov 2016 12:24:36 +0000 (23:24 +1100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Mon, 21 Nov 2016 12:24:36 +0000 (23:24 +1100)
# Conflicts:
# .travis.yml
# Makefile
# Makefile-ccan

255 files changed:
.travis.yml
Makefile
appveyor.yml [new file with mode: 0644]
ccan/aga/aga.h
ccan/aga/bellman_ford.c [new file with mode: 0644]
ccan/aga/dijkstra.c
ccan/aga/test/api-adjacency.c
ccan/aga/test/api-bellman_ford.c [new file with mode: 0644]
ccan/aga/test/api-bfs.c
ccan/aga/test/api-dfs.c
ccan/aga/test/api-dijkstra.c
ccan/aga/test/negacycle.c [new file with mode: 0644]
ccan/aga/test/simple-graph.h
ccan/agar/agar.c
ccan/agar/agar.h
ccan/agar/test/api-bellman_ford.c [new file with mode: 0644]
ccan/agar/test/api-bfs.c
ccan/agar/test/api-dfs.c
ccan/agar/test/api-dijkstra.c
ccan/agar/test/negacycle.c [new file with mode: 0644]
ccan/agar/test/simple-graphr.h
ccan/alignof/_info
ccan/alignof/test/run.c
ccan/array_size/test/compile_fail-function-param.c
ccan/array_size/test/compile_fail.c
ccan/array_size/test/run.c
ccan/asort/_info
ccan/asort/test/compile_fail-context-type.c
ccan/autodata/autodata.c
ccan/build_assert/test/compile_fail-expr.c
ccan/build_assert/test/compile_fail.c
ccan/build_assert/test/compile_ok.c
ccan/build_assert/test/run-BUILD_ASSERT_OR_ZERO.c
ccan/cast/_info
ccan/cast/test/compile_fail-cast_const.c
ccan/cast/test/compile_fail-cast_const2.c
ccan/cast/test/compile_fail-cast_const3.c
ccan/cast/test/compile_fail-cast_signed-const.c
ccan/cast/test/compile_fail-cast_signed-sizesame.c
ccan/cast/test/compile_fail-cast_signed.c
ccan/cast/test/compile_fail-cast_static-2.c
ccan/cast/test/compile_fail-cast_static-3.c
ccan/cast/test/compile_fail-cast_static.c
ccan/cast/test/compile_ok-static.c
ccan/cdump/_info
ccan/cdump/cdump.c
ccan/check_type/test/compile_fail-check_type.c
ccan/check_type/test/compile_fail-check_type_unsigned.c
ccan/check_type/test/compile_fail-check_types_match.c
ccan/check_type/test/run.c
ccan/compiler/_info
ccan/compiler/test/compile_fail-printf.c
ccan/compiler/test/run-is_compile_constant.c
ccan/container_of/_info
ccan/container_of/test/compile_fail-bad-type.c
ccan/container_of/test/compile_fail-types.c
ccan/container_of/test/compile_fail-var-types.c
ccan/container_of/test/run.c
ccan/cpuid/cpuid.c
ccan/crypto/siphash24/siphash24.c
ccan/endian/test/run.c
ccan/err/test/run.c
ccan/foreach/test/run-nested.c
ccan/htable/_info
ccan/htable/htable.h
ccan/htable/test/run-copy.c
ccan/htable/test/run-size.c
ccan/htable/test/run-type-int.c
ccan/htable/test/run-type.c
ccan/htable/test/run-zero-hash-first-entry.c
ccan/htable/test/run.c
ccan/ilog/test/run-out-of-line.c
ccan/ilog/test/run.c
ccan/io/io.h
ccan/io/poll.c
ccan/io/test/run-01-start-finish.c
ccan/io/test/run-02-read.c
ccan/io/test/run-15-timeout.c
ccan/io/test/run-20-io_time_override.c
ccan/isaac/test/run.c
ccan/isaac/test/run64.c
ccan/jmap/tools/Makefile
ccan/jmap/tools/speed.c
ccan/likely/test/run-debug.c
ccan/likely/test/run.c
ccan/list/_info
ccan/list/list.h
ccan/list/test/run-CCAN_LIST_DEBUG.c
ccan/list/test/run-check-corrupt.c
ccan/list/test/run-check-nonconst.c
ccan/list/test/run-list_del_from-assert.c
ccan/list/test/run-list_prev-list_next.c
ccan/list/test/run-prepend_list.c
ccan/list/test/run-single-eval.c
ccan/list/test/run.c
ccan/mem/mem.h
ccan/noerr/_info
ccan/noerr/test/run.c
ccan/opt/opt.h
ccan/opt/test/compile_ok-const-arg.c
ccan/opt/test/run-add_desc.c
ccan/opt/test/run-checkopt.c
ccan/opt/test/run-consume_words.c
ccan/opt/test/run-helpers.c
ccan/opt/test/run-iter.c
ccan/opt/test/run-set_alloc.c
ccan/opt/test/run-usage.c
ccan/opt/test/utils.c
ccan/order/order.c
ccan/order/test/compile_fail_1.c
ccan/order/test/compile_fail_2.c
ccan/order/test/compile_ok.c
ccan/order/test/run-fancy.c
ccan/pipecmd/_info
ccan/pipecmd/pipecmd.c
ccan/ptr_valid/ptr_valid.c
ccan/ptrint/_info
ccan/read_write_all/_info
ccan/read_write_all/test/run-read_all.c
ccan/read_write_all/test/run-write_all.c
ccan/str/_info
ccan/str/test/compile_fail-STR_MAX_CHARS.c
ccan/str/test/compile_fail-isalnum.c
ccan/str/test/compile_fail-isalpha.c
ccan/str/test/compile_fail-isascii.c
ccan/str/test/compile_fail-isblank.c
ccan/str/test/compile_fail-iscntrl.c
ccan/str/test/compile_fail-isdigit.c
ccan/str/test/compile_fail-islower.c
ccan/str/test/compile_fail-isprint.c
ccan/str/test/compile_fail-ispunct.c
ccan/str/test/compile_fail-isspace.c
ccan/str/test/compile_fail-isupper.c
ccan/str/test/compile_fail-isxdigit.c
ccan/str/test/compile_fail-strchr.c
ccan/str/test/compile_fail-strrchr.c
ccan/str/test/compile_fail-strstr.c
ccan/str/test/run-STR_MAX_CHARS.c
ccan/str/test/run.c
ccan/strmap/_info
ccan/strmap/test/run-iterate-const.c
ccan/strmap/test/run-prefix.c
ccan/take/_info
ccan/take/test/run.c
ccan/tal/_info
ccan/tal/grab_file/_info
ccan/tal/grab_file/test/run-grab.c
ccan/tal/link/_info
ccan/tal/link/link.c
ccan/tal/link/test/run.c
ccan/tal/stack/_info
ccan/tal/str/_info
ccan/tal/str/str.h
ccan/tal/str/test/run-fmt-terminate.c
ccan/tal/str/test/run-strndup.c
ccan/tal/str/test/run-strreg.c
ccan/tal/str/test/run.c
ccan/tal/tal.c
ccan/tal/test/run-allocfail.c
ccan/tal/test/run-destructor.c
ccan/tal/test/run-free.c
ccan/tal/test/run-notifier.c
ccan/tal/test/run-overflow.c
ccan/tal/test/run-test-backend.c
ccan/tcon/test/compile_fail-container1.c
ccan/tcon/test/compile_fail-container1w.c
ccan/tcon/test/compile_fail-container2.c
ccan/tcon/test/compile_fail-container2w.c
ccan/tcon/test/compile_fail-container3.c
ccan/tcon/test/compile_fail-container3w.c
ccan/tcon/test/compile_fail-container4.c
ccan/tcon/test/compile_fail-container4w.c
ccan/tcon/test/compile_fail-tcon_cast.c
ccan/tcon/test/compile_fail-tcon_cast_wrap.c
ccan/tcon/test/compile_fail-wrap.c
ccan/tcon/test/compile_fail.c
ccan/tcon/test/compile_ok-container.c
ccan/tcon/test/compile_ok-sizeof.c
ccan/tcon/test/compile_ok-value.c
ccan/tcon/test/compile_ok-void.c
ccan/tcon/test/compile_ok.c
ccan/tcon/test/run-container.c
ccan/tcon/test/run-wrap.c
ccan/time/test/run-check.c
ccan/time/test/run-monotonic.c
ccan/time/time.c
ccan/time/time.h
ccan/timer/_info
ccan/timer/test/run-add.c
ccan/timer/test/run-corrupt.c
ccan/timer/test/run-corrupt2.c
ccan/timer/test/run-expiry.c
ccan/timer/test/run-ff.c
ccan/timer/test/run-original-corrupt.c
ccan/timer/test/run.c
ccan/timer/timer.c
ccan/timer/timer.h
ccan/typesafe_cb/_info
ccan/typesafe_cb/test/compile_fail-cast_if_type-promotable.c
ccan/typesafe_cb/test/compile_fail-typesafe_cb-int.c
ccan/typesafe_cb/test/compile_fail-typesafe_cb.c
ccan/typesafe_cb/test/compile_fail-typesafe_cb_cast-multi.c
ccan/typesafe_cb/test/compile_fail-typesafe_cb_cast.c
ccan/typesafe_cb/test/compile_fail-typesafe_cb_postargs.c
ccan/typesafe_cb/test/compile_fail-typesafe_cb_preargs.c
ccan/typesafe_cb/test/compile_ok-typesafe_cb-NULL.c
ccan/typesafe_cb/test/compile_ok-typesafe_cb-undefined.c
ccan/typesafe_cb/test/compile_ok-typesafe_cb-vars.c
ccan/typesafe_cb/test/compile_ok-typesafe_cb_cast.c
ccan/typesafe_cb/test/run.c
ccan/wwviaudio/_info
ccan/wwviaudio/wwviaudio.c
tools/ccanlint/async.c
tools/ccanlint/ccanlint.c
tools/ccanlint/file_analysis.c
tools/ccanlint/tests/avoids_cpp_reserved.c
tools/ccanlint/tests/depends_accurate.c
tools/ccanlint/tests/depends_build.c
tools/ccanlint/tests/depends_build_without_features.c
tools/ccanlint/tests/depends_exist.c
tools/ccanlint/tests/examples_compile.c
tools/ccanlint/tests/examples_exist.c
tools/ccanlint/tests/examples_relevant.c
tools/ccanlint/tests/examples_run.c
tools/ccanlint/tests/hash_if.c
tools/ccanlint/tests/headers_idempotent.c
tools/ccanlint/tests/info_compiles.c
tools/ccanlint/tests/info_documentation_exists.c
tools/ccanlint/tests/info_exists.c
tools/ccanlint/tests/info_ported.c
tools/ccanlint/tests/info_summary_single_line.c
tools/ccanlint/tests/license_comment.c
tools/ccanlint/tests/license_depends_compat.c
tools/ccanlint/tests/license_exists.c
tools/ccanlint/tests/license_file_compat.c
tools/ccanlint/tests/main_header_compiles.c
tools/ccanlint/tests/main_header_exists.c
tools/ccanlint/tests/module_builds.c
tools/ccanlint/tests/module_links.c
tools/ccanlint/tests/no_trailing_whitespace.c
tools/ccanlint/tests/objects_build.c
tools/ccanlint/tests/objects_build_with_stringchecks.c
tools/ccanlint/tests/objects_build_without_features.c
tools/ccanlint/tests/reduce_features.c
tools/ccanlint/tests/tests_compile.c
tools/ccanlint/tests/tests_exist.c
tools/ccanlint/tests/tests_helpers_compile.c
tools/ccanlint/tests/tests_pass.c
tools/ccanlint/tests/tests_pass_valgrind.c
tools/ccanlint/tests/tests_pass_without_features.c
tools/compile.c
tools/configurator/configurator.c
tools/doc_extract-core.c
tools/manifest.c
tools/tools.h

index 5f2097fd8182a7a084b700571c6cce53bd8c515b..d7b4318ddcde7daabe4da6db7f888d08f79b82bd 100644 (file)
@@ -8,7 +8,11 @@ compiler:
 addons:
     apt:
         packages:
-            - libjudy-dev libvorbis-dev libportaudio-dev libtalloc-dev
+            - libjudy-dev
+            - libvorbis-dev
+            - libportaudio-dev
+            - libtalloc-dev
 
 script:
-        - make -j2 -k check quiet=1
+    - make -j2 -k quiet=1
+    - make -k check quiet=1
index ff0bad4e91acfd32d7a0e60366850b41b0c23ba8..6559c702a14c911ee024586dfa0f794abfd7b5b5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,7 @@ WARN_CFLAGS := -Wall -Wstrict-prototypes -Wold-style-definition -Wundef \
  -Wmissing-prototypes -Wmissing-declarations -Wpointer-arith -Wwrite-strings
 DEP_CFLAGS = -MMD -MP -MF$(@:%=%.d) -MT$@
 CCAN_CFLAGS := -g3 -ggdb $(WARN_CFLAGS) -DCCAN_STR_DEBUG=1 -I. $(CFLAGS)
+CFLAGS_FORCE_C_SOURCE := -x c
 
 # Anything with an _info file is a module ...
 INFO_SRCS := $(wildcard ccan/*/_info ccan/*/*/_info)
@@ -32,7 +33,7 @@ DEPS := $(OBJS:%=%.d)
 
 # _info files are compiled into executables and don't need dependencies
 %info : %_info config.h
-       $(PRE)$(CC) $(CCAN_CFLAGS) -I. -o $@ -x c $<
+       $(PRE)$(CC) $(CCAN_CFLAGS) -I. -o $@ $(CFLAGS_FORCE_C_SOURCE) $<
 
 # config.h is built by configurator which has no ccan dependencies
 CONFIGURATOR := tools/configurator/configurator
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644 (file)
index 0000000..76a7e4b
--- /dev/null
@@ -0,0 +1,37 @@
+# AppVeyor CI Configuration
+#
+# Current build status can be viewed at
+# https://ci.appveyor.com/project/dgibson/ccan
+#
+# To build test a fork of this repository using AppVeyor:
+# 1. Visit appveyor.com and create a free account.
+# 2. On the Projects tab, select "New Project" then the project hosting site.
+# 3. Grant OAuth permissions to your project git host.
+# 4. Select the repository for your project fork.
+# 5. Review build results and push updates until the desired result is reached.
+
+version: 0.0.{build}
+
+platform:
+- x86
+- amd64
+
+build_script:
+# Reset %PATH% to avoid msys/cygwin DLL conflicts which cause
+# *** fatal error - cygheap base mismatch detected
+- set PATH=C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\msys64\usr\bin
+# Set environment variables for chosen compiler
+- "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat\" %Platform%"
+# Ensure config.h can be generated.
+# Note: Dash options avoid POSIX path conversion by msys
+- "make config.h CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+# FIXME:  -j%NUMBER_OF_PROCESSORS% won't work without DEPGEN for config.h
+#         It may be possible to generate .d from cl using /showIncludes
+#         See https://stackoverflow.com/q/37685069
+#- "make tools CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+#- "make -k CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
+
+test_script:
+# FIXME:  Work in progress.  Disabled due to unfixed compile errors.
+#- "make -k check CC=cl CCAN_CFLAGS=\"-nologo -Zi -FS -W4 -wd4200 -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS\" CFLAGS_FORCE_C_SOURCE=-TC OUTPUT_OPTION=-Fo:$@ DEPGEN= LD=link SHELL=bash"
index d09d4c72ba7a2e8d5f98b50f57f275ebcc370cd6..239d36c339ee7bebc73d03ba1b1e4419fb1e0b76 100644 (file)
@@ -165,6 +165,12 @@ struct aga_node {
                        bool complete;
                        struct lpq_link pqlink;
                } dijkstra;
+               struct {
+                       aga_icost_t distance;
+                       struct aga_node *prev;
+                       const void *prevedge;
+                       struct aga_node *list;
+               } bellman_ford;
        } u;
 };
 
@@ -177,6 +183,11 @@ struct aga_graph {
        aga_edge_info_fn edge_info;
        union {
                LPQ(struct aga_node, u.dijkstra.pqlink) dijkstra;
+               struct {
+                       struct aga_node *nodelist;
+                       int nnodes;
+                       int npasses;
+               } bellman_ford;
        } state;
 };
 
@@ -347,7 +358,7 @@ struct aga_node *aga_bfs_explore(struct aga_graph *g, struct aga_node *n);
  *
  * Performs a breadth first search.  The block following this macro is
  * executed with @_n set first to @_start, then to each node reachable
- * from @_start in depth first search order.
+ * from @_start in breadth-first search order.
  *
  * aga_bfs_start() must be called before this macro is used.
  */
@@ -416,15 +427,74 @@ bool aga_dijkstra_path(struct aga_graph *g, struct aga_node *dest,
                       struct aga_node **prev, const void **prevedge);
 
 /**
- * aga_dijkstra_all_paths - Find shortest paths to all reachable nodes
+ * aga_dijkstra_complete - Find shortest paths to all reachable nodes
  * @g: graph
  *
  * Finds shortest paths from the source node (specified in
  * aga_dijkstra_start()) to all other reachable nodes in @g.  No
  * results are returned directly, but between calling
- * aga_dijkstra_all_paths() and aga_finish, aga_dijkstra_path() is
+ * aga_dijkstra_all_paths() and aga_finish(), aga_dijkstra_path() is
  * guaranteed to complete in O(1) time for all destinations.
  */
-void aga_dijkstra_all_paths(struct aga_graph *g);
+void aga_dijkstra_complete(struct aga_graph *g);
+
+/*
+ * Bellman-Ford algorithm
+ */
+
+/**
+ * aga_bellman_ford_start - Start Bellman-Ford algorithm
+ * @g: graph
+ * @source: source node
+ *
+ * Start's the Bellman-Ford algorithm on @g to find shortest paths
+ * from node @source, to other nodes in @g.
+ */
+int aga_bellman_ford_start(struct aga_graph *g, struct aga_node *source);
+
+/**
+ * aga_bellman_ford_path - Find the shortest path to a node
+ * @g: graph
+ * @dest: destination node
+ * @prev: Second last node in the path *output)
+ * @prevedge: Last edge in the path
+ *
+ * Finds the shortest path from the source node (specified in
+ * aga_bellman_ford_start() to @dest using Bellman_Ford's algorithm.
+ *
+ * If no path exists, return false.
+ *
+ * If a path does exist, returns true.  Additionally if @total_cost is
+ * non-NULL, store the total cost of the path in *@total_cost, if
+ * @prev is non-NULL, store the node in the path immediately before
+ * @dest in *@prev and if @prevedge is non-NULL stores the edge which
+ * leads from *@prev to @dest in *@prevedge.
+ *
+ * If @dest is the same as source, 0 will be stored in @cost, and NULL
+ * will be stored in *@prev and *@prevedge.
+ *
+ * The full path from source to @dest can be determined by repeatedly
+ * calling aga_bellman_ford_path() on *@prev.
+ *
+ * NOTE: Bellman_Ford's algorithm will not work correctly on a graph
+ * which contains a cycle with (total) negative cost.  If aga detects
+ * this case, it will set aga_error() to AGA_ERR_NEGATIVE_COST.
+ */
+bool aga_bellman_ford_path(struct aga_graph *g, struct aga_node *dest,
+                          aga_icost_t *total_cost,
+                          struct aga_node **prev, const void **prevedge);
+
+/**
+ * aga_bellman_ford_complete - Run Bellman-Ford algorithm to completion
+ * @g: graph
+ *
+ * Finds shortest paths from the source node (specified in
+ * aga_bellman_ford_start()) to all other reachable nodes in @g.  No
+ * results are returned directly, but between calling
+ * aga_bellman_ford_complete() and aga_finish(),
+ * aga_bellman_ford_path() is guaranteed to complete in O(1) time for
+ * all destinations.
+ */
+void aga_bellman_ford_complete(struct aga_graph *g);
 
 #endif /* CCAN_AGA_H */
diff --git a/ccan/aga/bellman_ford.c b/ccan/aga/bellman_ford.c
new file mode 100644 (file)
index 0000000..1820483
--- /dev/null
@@ -0,0 +1,141 @@
+/* Licensed under LGPLv2+ - see LICENSE file for details */
+#include "config.h"
+
+#include <stdbool.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <ccan/build_assert/build_assert.h>
+#include <ccan/check_type/check_type.h>
+#include <ccan/order/order.h>
+
+#include <ccan/aga/aga.h>
+#include "private.h"
+
+/*
+ * The Bellman-Ford algorithm
+ */
+
+static bool candidate_path(struct aga_graph *g, struct aga_node *node,
+                          aga_icost_t distance,
+                          struct aga_node *prev, const void *prevedge)
+{
+       if (aga_update_node(g, node)) {
+               /* New node, treat as having infinite distance */
+               node->u.bellman_ford.distance = distance;
+               node->u.bellman_ford.prev = prev;
+               node->u.bellman_ford.prevedge = prevedge;
+
+               node->u.bellman_ford.list = g->state.bellman_ford.nodelist;
+               g->state.bellman_ford.nodelist = node;
+               g->state.bellman_ford.nnodes++;
+
+               return true;
+       } else if (distance < node->u.bellman_ford.distance) {
+               node->u.bellman_ford.distance = distance;
+               node->u.bellman_ford.prev = prev;
+               node->u.bellman_ford.prevedge = prevedge;
+       }
+       return false;
+}
+
+int aga_bellman_ford_start(struct aga_graph *g, struct aga_node *source)
+{
+       int rc;
+
+       /* Make sure we're actually using the right ordering for
+        * aga_icost_t */
+       BUILD_ASSERT(check_types_match(long, aga_icost_t) == 0);
+
+       rc = aga_start(g);
+       if (rc < 0)
+               return rc;
+
+       g->state.bellman_ford.nodelist = NULL;
+       g->state.bellman_ford.nnodes = 0;
+       g->state.bellman_ford.npasses = 0;
+
+       candidate_path(g, source, 0, NULL, NULL);
+
+       return 0;
+}
+
+static bool aga_bellman_ford_step(struct aga_graph *g)
+{
+       struct aga_node *n;
+       const void *e;
+       struct aga_edge_info ei;
+       int err;
+       bool newnode = false;
+
+       if (!aga_check_state(g))
+               return false;
+
+       for (n = g->state.bellman_ford.nodelist;
+            n; n = n->u.bellman_ford.list) {
+               aga_for_each_edge_info(e, ei, err, g, n) {
+                       aga_icost_t dist = n->u.bellman_ford.distance
+                               + ei.icost;
+                       newnode = newnode || candidate_path(g, ei.to, dist, n, e);
+               }
+               if (err) {
+                       aga_fail(g, err);
+                       return false;
+               }
+       }
+       g->state.bellman_ford.npasses++;
+       return newnode || (g->state.bellman_ford.npasses
+                          < g->state.bellman_ford.nnodes);
+}
+
+void aga_bellman_ford_complete(struct aga_graph *g)
+{
+       struct aga_node *n;
+       const void *e;
+       struct aga_edge_info ei;
+       int err;
+
+       if (!aga_check_state(g))
+               return;
+
+       while (aga_bellman_ford_step(g))
+               ;
+
+       /* Check for negative cycles */
+       for (n = g->state.bellman_ford.nodelist;
+            n; n = n->u.bellman_ford.list) {
+               aga_for_each_edge_info(e, ei, err, g, n) {
+                       if ((n->u.bellman_ford.distance + ei.icost)
+                           < ei.to->u.bellman_ford.distance) {
+                               aga_fail(g, AGA_ERR_NEGATIVE_COST);
+                               return;
+                       }
+               }
+               if (err) {
+                       aga_fail(g, err);
+                       return;
+               }
+       }
+}
+
+bool aga_bellman_ford_path(struct aga_graph *g, struct aga_node *node,
+                          aga_icost_t *total_cost,
+                          struct aga_node **prev, const void **prevedge)
+{
+       aga_bellman_ford_complete(g);
+
+       if (!aga_check_state(g))
+               return false;
+
+       if (aga_node_needs_update(g, node))
+               return false;
+
+       if (total_cost)
+               *total_cost = node->u.bellman_ford.distance;
+       if (prev)
+               *prev = node->u.bellman_ford.prev;
+       if (prevedge)
+               *prevedge = node->u.bellman_ford.prevedge;
+
+       return true;
+}
index 02177fb8415a82cf1d3095792484c898d70558bb..cbb79b90779596c6f7c56e0cae18ebee107aeb7b 100644 (file)
@@ -114,7 +114,7 @@ bool aga_dijkstra_path(struct aga_graph *g, struct aga_node *node,
        return true;
 }
 
-void aga_dijkstra_all_paths(struct aga_graph *g)
+void aga_dijkstra_complete(struct aga_graph *g)
 {
        if (!aga_check_state(g))
                return;
index 6e5043017788272e6aa8f2b07163e49277d71c34..3168522401018b751eb5b2daa70792d863af2963 100644 (file)
@@ -63,8 +63,9 @@ int main(void)
        struct traversal1_graph t1g;
        struct shortcut1_graph s1g;
        struct shortcut2_graph s2g;
+       struct negacycle_graph ng;
 
-       plan_tests(2 + 7 + 35 + 30 + 30 + 42 + 9 + 30 + 9 + 9);
+       plan_tests(2 + 7 + 35 + 30 + 30 + 42 + 9 + 30 + 9 + 9 + 9);
 
        trivial_graph_init(&tg);
        test_adjacency("trivial", &tg.sg, trivial_adjacency);
@@ -99,5 +100,8 @@ int main(void)
        shortcut2_graph_init(&s2g);
        test_adjacency("shortcut2 graph", &s2g.sg, shortcut2_adjacency);
 
+       negacycle_graph_init(&ng);
+       test_adjacency("negacycle graph", &ng.sg, negacycle_adjacency);
+
        return exit_status();
 }
diff --git a/ccan/aga/test/api-bellman_ford.c b/ccan/aga/test/api-bellman_ford.c
new file mode 100644 (file)
index 0000000..5dc032a
--- /dev/null
@@ -0,0 +1,279 @@
+#include "config.h"
+
+#include <stddef.h>
+#include <assert.h>
+#include <stdlib.h>
+
+#include <ccan/tap/tap.h>
+#include <ccan/array_size/array_size.h>
+
+#include <ccan/aga/aga.h>
+
+#include "simple-graph.h"
+
+static void test_trivial(void)
+{
+       struct trivial_graph tg;
+       aga_icost_t cost;
+       struct aga_node *node;
+       const void *edge;
+
+       trivial_graph_init(&tg);
+
+       ok1(aga_bellman_ford_start(&tg.sg.g, &tg.sg.nodes[1]) == 0);
+       ok1(aga_bellman_ford_path(&tg.sg.g, &tg.sg.nodes[1], &cost, &node, &edge));
+       ok1(cost == 0);
+       ok1(node == NULL);
+       ok1(edge == NULL);
+       aga_finish(&tg.sg.g);
+}
+
+static void test_parallel(void)
+{
+       struct parallel_graph pg;
+       aga_icost_t cost;
+       struct aga_node *node;
+       const void *edge;
+
+       parallel_graph_init(&pg, 3, 0);
+
+       ok1(aga_bellman_ford_start(&pg.sg.g, &pg.sg.nodes[1]) == 0);
+       ok1(aga_bellman_ford_path(&pg.sg.g, &pg.sg.nodes[1], &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(aga_bellman_ford_path(&pg.sg.g, &pg.sg.nodes[2], &cost, &node, NULL));
+       ok1(cost == 2);
+       ok1(node == &pg.sg.nodes[1]);
+       aga_finish(&pg.sg.g);
+
+       ok1(aga_bellman_ford_start(&pg.sg.g, &pg.sg.nodes[2]) == 0);
+       ok1(aga_bellman_ford_path(&pg.sg.g, &pg.sg.nodes[2], &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(!aga_bellman_ford_path(&pg.sg.g, &pg.sg.nodes[1], NULL, NULL, NULL));
+       aga_finish(&pg.sg.g);
+
+
+       parallel_graph_init(&pg, 3, 2);
+       ok1(aga_bellman_ford_start(&pg.sg.g, &pg.sg.nodes[1]) == 0);
+       ok1(aga_bellman_ford_path(&pg.sg.g, &pg.sg.nodes[2], &cost, &node, &edge));
+       ok1(cost == 1);
+       ok1(node == &pg.sg.nodes[1]);
+       ok1(ptr2int(edge) == 2);
+       aga_finish(&pg.sg.g);
+}
+
+#define FULL_LEN       4
+
+static void test_full(void)
+{
+       struct full_graph fg;
+       int i, j;
+
+       full_graph_init(&fg, FULL_LEN);
+
+       for (i = 1; i <= FULL_LEN; i++) {
+               ok1(aga_bellman_ford_start(&fg.sg.g, &fg.sg.nodes[i]) == 0);
+
+               for (j = 1; j <= FULL_LEN; j++) {
+                       aga_icost_t cost;
+                       struct aga_node *node;
+                       const void *edge;
+
+                       ok1(aga_bellman_ford_path(&fg.sg.g, &fg.sg.nodes[j],
+                                             &cost, &node, &edge));
+                       if (i == j) {
+                               ok1(cost == 0);
+                               ok1(node == NULL);
+                               ok1(edge == NULL);
+                       } else {
+                               ok1(cost == 1);
+                               ok1(node == &fg.sg.nodes[i]);
+                               ok1(edge == &fg.sg.nodes[j]);
+                       }
+               }
+
+               aga_finish(&fg.sg.g);
+       }
+}
+
+#define CHAIN_LEN      8
+
+static void test_chain(void)
+{
+       struct chain_graph cg;
+       int i, j;
+
+       chain_graph_init(&cg, CHAIN_LEN);
+
+       for (i = 1; i <= CHAIN_LEN; i++) {
+               ok1(aga_bellman_ford_start(&cg.fg.sg.g, &cg.fg.sg.nodes[i]) == 0);
+
+               for (j = 1; j <= CHAIN_LEN; j++) {
+                       aga_icost_t cost;
+
+                       ok1(aga_bellman_ford_path(&cg.fg.sg.g, &cg.fg.sg.nodes[j],
+                                             &cost, NULL, NULL));
+                       ok1(cost == labs(i - j));
+               }
+
+               aga_finish(&cg.fg.sg.g);
+       }
+}
+
+static void test_error(void)
+{
+       struct error_graph eg;
+       aga_icost_t cost;
+
+       error_graph_init(&eg);
+
+       ok1(aga_bellman_ford_start(&eg.sg.g, &eg.sg.nodes[1]) == 0);
+       ok1(aga_bellman_ford_path(&eg.sg.g, &eg.sg.nodes[1], &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(aga_bellman_ford_path(&eg.sg.g, &eg.sg.nodes[2], &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(!aga_bellman_ford_path(&eg.sg.g, &eg.sg.nodes[3], &cost, NULL, NULL));
+       ok1(!aga_bellman_ford_path(&eg.sg.g, &eg.sg.nodes[4], &cost, NULL, NULL));
+       aga_finish(&eg.sg.g);
+
+       ok1(aga_bellman_ford_start(&eg.sg.g, &eg.sg.nodes[3]) == 0);
+       aga_bellman_ford_complete(&eg.sg.g);
+       ok1(!aga_bellman_ford_path(&eg.sg.g, &eg.sg.nodes[4], &cost, NULL, NULL));
+       ok1(aga_error(&eg.sg.g) == -1);
+       aga_finish(&eg.sg.g);
+}
+
+static void test_traversal1(void)
+{
+       struct traversal1_graph t1g;
+       aga_icost_t cost;
+
+       /* This is mostly about testing we correctly handle
+        * non-reachable nodes */
+       traversal1_graph_init(&t1g);
+
+       ok1(aga_bellman_ford_start(&t1g.sg.g, &t1g.sg.nodes[1]) == 0);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[1],
+                             &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[2],
+                             &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[3],
+                             &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[4],
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[5],
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[6],
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(!aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[7],
+                              NULL, NULL, NULL));
+       ok1(!aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[8],
+                              NULL, NULL, NULL));
+       ok1(!aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[9],
+                              NULL, NULL, NULL));
+       aga_finish(&t1g.sg.g);
+
+       ok1(aga_bellman_ford_start(&t1g.sg.g, &t1g.sg.nodes[9]) == 0);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[9],
+                             &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[8],
+                             &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[7],
+                             &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[6],
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[5],
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[4],
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(!aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[3],
+                              NULL, NULL, NULL));
+       ok1(!aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[2],
+                              NULL, NULL, NULL));
+       ok1(!aga_bellman_ford_path(&t1g.sg.g, &t1g.sg.nodes[1],
+                              NULL, NULL, NULL));
+       aga_finish(&t1g.sg.g);
+}
+
+static void test_shortcut1(void)
+{
+       struct shortcut1_graph s1g;
+       aga_icost_t cost;
+       struct aga_node *node;
+
+       shortcut1_graph_init(&s1g);
+
+       ok1(aga_bellman_ford_start(&s1g.sg.g, &s1g.sg.nodes[1]) == 0);
+       ok1(aga_bellman_ford_path(&s1g.sg.g, &s1g.sg.nodes[3],
+                             &cost, &node, NULL));
+       ok1(cost == 2);
+       ok1(node == &s1g.sg.nodes[2]);
+       ok1(aga_bellman_ford_path(&s1g.sg.g, &s1g.sg.nodes[2],
+                             &cost, &node, NULL));
+       ok1(cost == 1);
+       ok1(node == &s1g.sg.nodes[1]);
+       aga_finish(&s1g.sg.g);
+}
+
+static void test_shortcut2(void)
+{
+       struct shortcut2_graph s2g;
+       aga_icost_t cost;
+       struct aga_node *node;
+
+       shortcut2_graph_init(&s2g);
+
+       ok1(aga_bellman_ford_start(&s2g.sg.g, &s2g.sg.nodes[1]) == 0);
+       ok1(aga_bellman_ford_path(&s2g.sg.g, &s2g.sg.nodes[3],
+                                 &cost, &node, NULL));
+       ok1(cost == 1);
+       ok1(node == &s2g.sg.nodes[2]);
+       ok1(aga_bellman_ford_path(&s2g.sg.g, &s2g.sg.nodes[2],
+                             &cost, &node, NULL));
+       ok1(cost == 2);
+       ok1(node == &s2g.sg.nodes[1]);
+       aga_finish(&s2g.sg.g);
+}
+
+static void test_negacycle(void)
+{
+       struct negacycle_graph ng;
+
+       negacycle_graph_init(&ng);
+
+       ok1(aga_bellman_ford_start(&ng.sg.g, &ng.sg.nodes[1]) == 0);
+       aga_bellman_ford_complete(&ng.sg.g);
+       ok1(aga_error(&ng.sg.g) == AGA_ERR_NEGATIVE_COST);
+       aga_finish(&ng.sg.g);
+}
+
+int main(void)
+{
+       plan_tests(5 + 15
+                  + FULL_LEN * (1 + FULL_LEN * 4)
+                  + CHAIN_LEN * (1 + CHAIN_LEN * 2)
+                  + 10 + 32 + 7 + 7 + 2);
+
+       test_trivial();
+       test_parallel();
+       test_full();
+       test_chain();
+       test_error();
+       test_traversal1();
+       test_shortcut1();
+       test_shortcut2();
+       test_negacycle();
+       
+       return exit_status();
+}
index 90fcc62853887595093ce9fff22cc055124d2f23..1a3e1411a229f1ea2b90ba96cea568136b57e565 100644 (file)
@@ -42,9 +42,10 @@ int main(void)
        struct grid_graph gg1, gg2;
        struct error_graph eg;
        struct traversal1_graph t1g;
+       struct negacycle_graph ng;
        struct aga_node *node;
        
-       plan_tests(2 * 13 + 10 + 10);
+       plan_tests(2 * 13 + 10 + 10 + 6);
 
        trivial_graph_init(&tg);
        test_bfs(&tg.sg, 1, 1);
@@ -100,5 +101,10 @@ int main(void)
        test_bfs_partial(&t1g.sg, 1, 1, 2, 3);
        aga_finish(&t1g.sg.g);
 
+       negacycle_graph_init(&ng);
+       test_bfs(&ng.sg, 1, 1, 2, 3);
+       test_bfs(&ng.sg, 2, 2, 3, 1);
+       test_bfs(&ng.sg, 3, 3, 1, 2);
+       
        return exit_status();
 }
index 24d1a4f912078551fbb9faa0161e047fc88f2ef5..c28097a690dcc1687f9273837bd61e6591134527 100644 (file)
@@ -42,9 +42,10 @@ int main(void)
        struct grid_graph gg1, gg2;
        struct error_graph eg;
        struct traversal1_graph t1g;
+       struct negacycle_graph ng;
        struct aga_node *node;
        
-       plan_tests(2 * 13 + 10 + 10);
+       plan_tests(2 * 13 + 10 + 10 + 6);
 
        trivial_graph_init(&tg);
        test_dfs(&tg.sg, 1, 1);
@@ -100,5 +101,10 @@ int main(void)
        test_dfs_partial(&t1g.sg, 1, 1, 2, 3);
        aga_finish(&t1g.sg.g);
 
+       negacycle_graph_init(&ng);
+       test_dfs(&ng.sg, 1, 1, 2, 3);
+       test_dfs(&ng.sg, 2, 2, 3, 1);
+       test_dfs(&ng.sg, 3, 3, 1, 2);
+
        return exit_status();
 }
index f9b8d764a7d6e198d23797afa404882b0009e8d6..01bb5aa4d880f579ea4c60dd3f51a64a14a9657d 100644 (file)
@@ -241,17 +241,29 @@ static void test_shortcut2(void)
        shortcut2_graph_init(&s2g);
 
        ok1(aga_dijkstra_start(&s2g.sg.g, &s2g.sg.nodes[1]) == 0);
-       aga_dijkstra_all_paths(&s2g.sg.g);
+       aga_dijkstra_complete(&s2g.sg.g);
        ok1(aga_error(&s2g.sg.g) == AGA_ERR_NEGATIVE_COST);
        aga_finish(&s2g.sg.g);
 }
 
+static void test_negacycle(void)
+{
+       struct negacycle_graph ng;
+
+       negacycle_graph_init(&ng);
+
+       ok1(aga_dijkstra_start(&ng.sg.g, &ng.sg.nodes[1]) == 0);
+       aga_dijkstra_complete(&ng.sg.g);
+       ok1(aga_error(&ng.sg.g) == AGA_ERR_NEGATIVE_COST);
+       aga_finish(&ng.sg.g);
+}
+
 int main(void)
 {
        plan_tests(7 + 20
                   + FULL_LEN * (1 + FULL_LEN*4)
                   + CHAIN_LEN * (1 + CHAIN_LEN*2)
-                  + 12 + 32 + 7 + 2);
+                  + 12 + 32 + 7 + 2 + 2);
 
        test_trivial();
        test_parallel();
@@ -261,6 +273,7 @@ int main(void)
        test_traversal1();
        test_shortcut1();
        test_shortcut2();
+       test_negacycle();
        
        return exit_status();
 }
diff --git a/ccan/aga/test/negacycle.c b/ccan/aga/test/negacycle.c
new file mode 100644 (file)
index 0000000..8eae4bf
--- /dev/null
@@ -0,0 +1,46 @@
+#include "config.h"
+
+#include <assert.h>
+
+#include <ccan/container_of/container_of.h>
+#include <ccan/ptrint/ptrint.h>
+
+#include <ccan/aga/aga.h>
+
+#include "simple-graph.h"
+
+static ptrint_t *negacycle_first_edge(const struct aga_graph *g,
+                                     const struct aga_node *n)
+{
+       return int2ptr(1);
+}
+
+static ptrint_t *negacycle_next_edge(const struct aga_graph *g,
+                                    const struct aga_node *n,
+                                    ptrint_t *e)
+{
+       assert(ptr2int(e) == 1);
+       return NULL;
+}
+
+static int negacycle_edge_info(const struct aga_graph *g,
+                              const struct aga_node *n,
+                              ptrint_t *e, struct aga_edge_info *ei)
+{
+       struct negacycle_graph *ng = container_of(g, struct negacycle_graph,
+                                                  sg.g);
+       int ni = n - ng->sg.nodes;
+
+       assert(ptr2int(e) == 1);
+       ei->to = &ng->sg.nodes[(ni % 3) + 1];
+       if (ni == 3)
+               ei->icost = -3;
+       return 0;
+}
+
+void negacycle_graph_init(struct negacycle_graph *ng)
+{
+       simple_graph_init(&ng->sg, negacycle_first_edge,
+                         negacycle_next_edge,
+                         negacycle_edge_info);
+}
index b8da3ad999045bc9207b59871a56fae691a13120..5808993ac2c203364c73b6ffdbbf8f09ebfc95fd 100644 (file)
@@ -256,4 +256,23 @@ static const struct adjacency_list shortcut2_adjacency[] = {
        {},
 };
 
+/* Negacycle graph
+ *
+ *  A <---- (-3) ----- C
+ *   \                 ^
+ *    (1)->  B -- (1)-/
+ *
+ * Graph with a negative length cycle, and so lacking well-defined shortest paths.
+ */
+struct negacycle_graph {
+       struct simple_graph sg;
+};
+void negacycle_graph_init(struct negacycle_graph *ng);
+static const struct adjacency_list negacycle_adjacency[] = {
+       {1, {2}},
+       {2, {3}},
+       {3, {1}},
+       {},
+};
+
 #endif /* _TEST_GRAPHS_H */
index e930d7aa6c7eeabde50110474502b087b78f05ae..aa4628404864affe29578122fb69f729f1a059c8 100644 (file)
@@ -286,8 +286,53 @@ bool agar_dijkstra_path(struct agar_state *sr, const void *destr,
        return true;
 }
 
-void agar_dijkstra_all_paths(struct agar_state *sr)
+void agar_dijkstra_complete(struct agar_state *sr)
 {
-       aga_dijkstra_all_paths(&sr->g);
+       aga_dijkstra_complete(&sr->g);
 }
 
+
+/*
+ * Bellman-Ford algorithm
+ */
+
+struct agar_state *agar_bellman_ford_new(void *ctx, struct agar_graph *gr,
+                                        const void *nr)
+{
+       struct agar_state *sr = agar_new(ctx, gr);
+
+       if (aga_bellman_ford_start(&sr->g, nr_to_n(sr, nr)) < 0) {
+               tal_free(sr);
+               return NULL;
+       }
+
+       return sr;
+}
+
+bool agar_bellman_ford_path(struct agar_state *sr, const void *destr,
+                           aga_icost_t *total_cost,
+                           const void **prevr, const void **prevedge)
+{
+       struct aga_node *dest = nr_to_n(sr, destr);
+       struct aga_node *prev;
+
+       if (!aga_bellman_ford_path(&sr->g, dest, total_cost, &prev, prevedge))
+               return false;
+
+       /*
+        * When destr is the same as the source node, there obviously
+        * isn't a previous node or edge.  In that case aga sets them
+        * to NULL.  But for agar, NULL could be a valid node
+        * references (particularly if using ptrint).  So we don't
+        * have much choice here but to leave *prevr as undefined when
+        * destr is the source node. */
+       if (prevr && prev)
+               *prevr = n_to_nr(sr, prev);
+
+       return true;
+}
+
+void agar_bellman_ford_complete(struct agar_state *sr)
+{
+       aga_bellman_ford_complete(&sr->g);
+}
index abd11301e6f86abafabfdd5563e5ae9f4b67ddb8..f65b4e371f456d7b6bca8208dd5e7f53260874c2 100644 (file)
@@ -84,6 +84,18 @@ bool agar_dijkstra_step(struct agar_state *sr, const void **nextr);
 bool agar_dijkstra_path(struct agar_state *sr, const void *destr,
                        aga_icost_t *total_cost,
                        const void **prevr, const void **prevedge);
-void agar_dijkstra_all_paths(struct agar_state *sr);
+void agar_dijkstra_complete(struct agar_state *sr);
+
+/*
+ * Bellman-Ford algorithm
+ */
+
+struct agar_state *agar_bellman_ford_new(void *ctx, struct agar_graph *gr,
+                                        const void *nr);
+
+bool agar_bellman_ford_path(struct agar_state *sr, const void *destr,
+                           aga_icost_t *total_cost,
+                           const void **prevr, const void **prevedge);
+void agar_bellman_ford_complete(struct agar_state *sr);
 
 #endif /* CCAN_AGAR_H */
diff --git a/ccan/agar/test/api-bellman_ford.c b/ccan/agar/test/api-bellman_ford.c
new file mode 100644 (file)
index 0000000..a161b0c
--- /dev/null
@@ -0,0 +1,260 @@
+#include "config.h"
+
+#include <stddef.h>
+#include <assert.h>
+#include <stdlib.h>
+
+#include <ccan/tap/tap.h>
+#include <ccan/tal/tal.h>
+#include <ccan/array_size/array_size.h>
+
+#include <ccan/agar/agar.h>
+
+#include "simple-graphr.h"
+
+static void test_trivial(void)
+{
+       struct agar_state *sr;
+       aga_icost_t cost;
+
+       ok1(sr = agar_bellman_ford_new(NULL, &trivial_graphr.gr, int2ptr(1)));
+       ok1(agar_bellman_ford_path(sr, int2ptr(1), &cost, NULL, NULL));
+       ok1(cost == 0);
+       tal_free(sr);
+}
+
+static void test_parallel(void)
+{
+       struct parallel_graphr pgr;
+       struct agar_state *sr;
+       aga_icost_t cost;
+       const void *node, *edge;
+
+       parallel_graphr_init(&pgr, 3, 0);
+
+       ok1(sr = agar_bellman_ford_new(NULL, &pgr.gr, int2ptr(1)));
+       ok1(agar_bellman_ford_path(sr, int2ptr(1), &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(agar_bellman_ford_path(sr, int2ptr(2), &cost, &node, NULL));
+       ok1(cost == 2);
+       ok1(node == int2ptr(1));
+       tal_free(sr);
+
+       ok1(sr = agar_bellman_ford_new(NULL, &pgr.gr, int2ptr(2)));
+       ok1(agar_bellman_ford_path(sr, int2ptr(2), &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(!agar_bellman_ford_path(sr, int2ptr(1), NULL, NULL, NULL));
+       tal_free(sr);
+
+       parallel_graphr_init(&pgr, 3, 2);
+       ok1(sr = agar_bellman_ford_new(NULL, &pgr.gr, int2ptr(1)));
+       ok1(agar_bellman_ford_path(sr, int2ptr(2), &cost, &node, &edge));
+       ok1(cost == 1);
+       ok1(ptr2int(node) == 1);
+       ok1(ptr2int(edge) == 2);
+       tal_free(sr);
+}
+
+#define FULL_LEN       4
+
+static void test_full(void)
+{
+       struct full_graphr fgr;
+       int i, j;
+
+       full_graphr_init(&fgr, FULL_LEN);
+
+       for (i = 1; i <= FULL_LEN; i++) {
+               struct agar_state *sr;
+
+               ok1(sr = agar_bellman_ford_new(NULL, &fgr.gr, int2ptr(i)));
+
+               for (j = 1; j <= FULL_LEN; j++) {
+                       aga_icost_t cost;
+                       const void *node, *edge;
+
+                       ok1(agar_bellman_ford_path(sr, int2ptr(j),
+                                             &cost, &node, &edge));
+                       if (i == j) {
+                               ok1(cost == 0);
+                       } else {
+                               ok1(cost == 1);
+                               ok1(node == int2ptr(i));
+                               ok1(edge == int2ptr(j));
+                       }
+               }
+
+               tal_free(sr);
+       }
+}
+
+#define CHAIN_LEN      8
+
+static void test_chain(void)
+{
+       struct chain_graphr cgr;
+       int i, j;
+
+       chain_graphr_init(&cgr, CHAIN_LEN);
+
+       for (i = 1; i <= CHAIN_LEN; i++) {
+               struct agar_state *sr;
+
+               ok1(sr = agar_bellman_ford_new(NULL, &cgr.fgr.gr, int2ptr(i)));
+
+               for (j = 1; j <= CHAIN_LEN; j++) {
+                       aga_icost_t cost;
+
+                       ok1(agar_bellman_ford_path(sr, int2ptr(j),
+                                             &cost, NULL, NULL));
+                       ok1(cost == labs(i - j));
+               }
+
+               tal_free(sr);
+       }
+}
+
+static void test_error(void)
+{
+       struct agar_state *sr;
+       aga_icost_t cost;
+
+       ok1(sr = agar_bellman_ford_new(NULL, &error_graphr.gr, int2ptr(1)));
+       ok1(agar_bellman_ford_path(sr, int2ptr(1), &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(agar_bellman_ford_path(sr, int2ptr(2), &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(!agar_bellman_ford_path(sr, int2ptr(3), &cost, NULL, NULL));
+       ok1(!agar_bellman_ford_path(sr, int2ptr(4), &cost, NULL, NULL));
+       tal_free(sr);
+
+       ok1(sr = agar_bellman_ford_new(NULL, &error_graphr.gr, int2ptr(3)));
+       agar_bellman_ford_complete(sr);
+       ok1(!agar_bellman_ford_path(sr, int2ptr(4), &cost, NULL, NULL));
+       ok1(agar_error(sr) == -1);
+       tal_free(sr);
+}
+
+static void test_traversal1(void)
+{
+       struct agar_state *sr;
+       aga_icost_t cost;
+
+       /* This is mostly about testing we correctly handle
+        * non-reachable nodes */
+       ok1(sr = agar_bellman_ford_new(NULL, &traversal1_graphr.gr, int2ptr(1)));
+       ok1(agar_bellman_ford_path(sr, int2ptr(1),
+                             &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(agar_bellman_ford_path(sr, int2ptr(2),
+                             &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(agar_bellman_ford_path(sr, int2ptr(3),
+                             &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(agar_bellman_ford_path(sr, int2ptr(4),
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(agar_bellman_ford_path(sr, int2ptr(5),
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(agar_bellman_ford_path(sr, int2ptr(6),
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(!agar_bellman_ford_path(sr, int2ptr(7),
+                              NULL, NULL, NULL));
+       ok1(!agar_bellman_ford_path(sr, int2ptr(8),
+                              NULL, NULL, NULL));
+       ok1(!agar_bellman_ford_path(sr, int2ptr(9),
+                              NULL, NULL, NULL));
+       tal_free(sr);
+
+       ok1(sr = agar_bellman_ford_new(NULL, &traversal1_graphr.gr, int2ptr(9)));
+       ok1(agar_bellman_ford_path(sr, int2ptr(9),
+                             &cost, NULL, NULL));
+       ok1(cost == 0);
+       ok1(agar_bellman_ford_path(sr, int2ptr(8),
+                             &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(agar_bellman_ford_path(sr, int2ptr(7),
+                             &cost, NULL, NULL));
+       ok1(cost == 1);
+       ok1(agar_bellman_ford_path(sr, int2ptr(6),
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(agar_bellman_ford_path(sr, int2ptr(5),
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(agar_bellman_ford_path(sr, int2ptr(4),
+                             &cost, NULL, NULL));
+       ok1(cost == 2);
+       ok1(!agar_bellman_ford_path(sr, int2ptr(3),
+                              NULL, NULL, NULL));
+       ok1(!agar_bellman_ford_path(sr, int2ptr(2),
+                              NULL, NULL, NULL));
+       ok1(!agar_bellman_ford_path(sr, int2ptr(1),
+                              NULL, NULL, NULL));
+       tal_free(sr);
+}
+
+static void test_shortcut1(void)
+{
+       struct agar_state *sr;
+       aga_icost_t cost;
+       const void *node;
+
+       ok1(sr = agar_bellman_ford_new(NULL, &shortcut1_graphr.gr, int2ptr(1)));
+       ok1(agar_bellman_ford_path(sr, int2ptr(3), &cost, &node, NULL));
+       ok1(cost == 2);
+       ok1(node == int2ptr(2));
+       ok1(agar_bellman_ford_path(sr, int2ptr(2), &cost, &node, NULL));
+       ok1(cost == 1);
+       ok1(node == int2ptr(1));
+       tal_free(sr);
+}
+
+static void test_shortcut2(void)
+{
+       struct agar_state *sr;
+       aga_icost_t cost;
+       const void *node;
+
+       ok1(sr = agar_bellman_ford_new(NULL, &shortcut2_graphr.gr, int2ptr(1)));
+       ok1(agar_bellman_ford_path(sr, int2ptr(3), &cost, &node, NULL));
+       ok1(cost == 1);
+       ok1(node == int2ptr(2));
+       ok1(agar_bellman_ford_path(sr, int2ptr(2), &cost, &node, NULL));
+       ok1(cost == 2);
+       ok1(node == int2ptr(1));
+       tal_free(sr);   
+}
+
+static void test_negacycle(void)
+{
+       struct agar_state *sr;
+
+       ok1(sr = agar_bellman_ford_new(NULL, &negacycle_graphr.gr, int2ptr(1)));
+       agar_bellman_ford_complete(sr);
+       ok1(agar_error(sr) == AGA_ERR_NEGATIVE_COST);
+       tal_free(sr);
+}
+
+int main(void)
+{
+       plan_tests(3 + 15
+                  + FULL_LEN * (FULL_LEN*4 - 1)
+                  + CHAIN_LEN * (1 + CHAIN_LEN*2)
+                  + 10 + 32 + 7 + 7 + 2);
+
+       test_trivial();
+       test_parallel();
+       test_full();
+       test_chain();
+       test_error();
+       test_traversal1();
+       test_shortcut1();
+       test_shortcut2();
+       test_negacycle();
+       
+       return exit_status();
+}
index 27369b6e76f19b73e83ac1ec681beec53935b28e..79ea21ad71ee041a5a31ea0fab3729d52a7997f8 100644 (file)
@@ -45,7 +45,7 @@ int main(void)
        struct agar_state *sr;
        const void *nr;
        
-       plan_tests(2 * 13 + 12 + 10);
+       plan_tests(2 * 13 + 12 + 10 + 6);
 
        test_bfs(&trivial_graphr.gr, 1, 1);
 
@@ -97,5 +97,9 @@ int main(void)
        test_bfs_partial(sr, 1, 1, 2, 3);
        tal_free(sr);
 
+       test_bfs(&negacycle_graphr.gr, 1, 1, 2, 3);
+       test_bfs(&negacycle_graphr.gr, 2, 2, 3, 1);
+       test_bfs(&negacycle_graphr.gr, 3, 3, 1, 2);
+
        return exit_status();
 }
index 625e825c3fac07f63c75001f9795a186b531a6d2..65be2e18353f4ee39eb31442da9a1f202d2b0007 100644 (file)
@@ -45,7 +45,7 @@ int main(void)
        struct agar_state *sr;
        const void *nr;
        
-       plan_tests(2 * 13 + 12 + 10);
+       plan_tests(2 * 13 + 12 + 10 + 6);
 
        test_dfs(&trivial_graphr.gr, 1, 1);
 
@@ -97,5 +97,9 @@ int main(void)
        test_dfs_partial(sr, 1, 1, 2, 3);
        tal_free(sr);
 
+       test_dfs(&negacycle_graphr.gr, 1, 1, 2, 3);
+       test_dfs(&negacycle_graphr.gr, 2, 2, 3, 1);
+       test_dfs(&negacycle_graphr.gr, 3, 3, 1, 2);
+
        return exit_status();
 }
index ebdbf42d1a72d1a180c1441205e448d349943f7d..19980919bd7ca059db2a4287ac8aaf318f407148 100644 (file)
@@ -231,7 +231,17 @@ static void test_shortcut2(void)
        struct agar_state *sr;
 
        ok1(sr = agar_dijkstra_new(NULL, &shortcut2_graphr.gr, int2ptr(1)));
-       agar_dijkstra_all_paths(sr);
+       agar_dijkstra_complete(sr);
+       ok1(agar_error(sr) == AGA_ERR_NEGATIVE_COST);
+       tal_free(sr);
+}
+
+static void test_negacycle(void)
+{
+       struct agar_state *sr;
+
+       ok1(sr = agar_dijkstra_new(NULL, &negacycle_graphr.gr, int2ptr(1)));
+       agar_dijkstra_complete(sr);
        ok1(agar_error(sr) == AGA_ERR_NEGATIVE_COST);
        tal_free(sr);
 }
@@ -241,7 +251,7 @@ int main(void)
        plan_tests(6 + 23
                   + FULL_LEN * (FULL_LEN*4 - 1)
                   + CHAIN_LEN * (1 + CHAIN_LEN*2)
-                  + 12 + 32 + 7 + 2);
+                  + 12 + 32 + 7 + 2 + 2);
 
        test_trivial();
        test_parallel();
@@ -251,6 +261,7 @@ int main(void)
        test_traversal1();
        test_shortcut1();
        test_shortcut2();
+       test_negacycle();
        
        return exit_status();
 }
diff --git a/ccan/agar/test/negacycle.c b/ccan/agar/test/negacycle.c
new file mode 100644 (file)
index 0000000..7d3daa9
--- /dev/null
@@ -0,0 +1,42 @@
+#include "config.h"
+
+#include <assert.h>
+
+#include <ccan/container_of/container_of.h>
+#include <ccan/ptrint/ptrint.h>
+
+#include <ccan/agar/agar.h>
+
+#include "simple-graphr.h"
+
+static const void *negacycle_first_edge_r(const struct agar_graph *gr,
+                                         const void *nr)
+{
+       return int2ptr(1);
+}
+
+static const void *negacycle_next_edge_r(const struct agar_graph *gr,
+                                        const void *nr, const void *e)
+{
+       assert(ptr2int(e) == 1);
+       return NULL;
+}
+
+static int negacycle_edge_info_r(const struct agar_graph *gr,
+                                const void *nr, const void *e,
+                                struct agar_edge_info *eir)
+{
+       int ni = ptr2int(nr);
+
+       assert(ptr2int(e) == 1);
+       eir->to = int2ptr((ni % 3) + 1);
+       if (ni == 3)
+               eir->icost = -3;
+       return 0;
+}
+
+struct negacycle_graphr negacycle_graphr = {
+       AGAR_INIT_GRAPH(negacycle_first_edge_r,
+                       negacycle_next_edge_r,
+                       negacycle_edge_info_r),
+};
index ddb1edbcbd58a5603d9858d36a62671d2f4fcc6a..21cae6a3497c9900ba010dd445f4acdd6203f649 100644 (file)
@@ -240,4 +240,23 @@ static const struct adjacency_listr shortcut2_adjacencyr[] = {
        {},
 };
 
+/* Negacycle graph
+ *
+ *  A <---- (-3) ----- C
+ *   \                 ^
+ *    (1)->  B -- (1)-/
+ *
+ * Graph with a negative length cycle, and so lacking well-defined shortest paths.
+ */
+struct negacycle_graphr {
+       struct agar_graph gr;
+};
+extern struct negacycle_graphr negacycle_graphr;
+static const struct adjacency_listr negacycle_adjacencyr[] = {
+       {1, {2}},
+       {2, {3}},
+       {3, {1}},
+       {},
+};
+
 #endif /* _SIMPLE_GRAPHR_H */
index e0952c652810b5a3cdadd0597d2e9aa74ec003ef..ee2b7ad0f28057a73c464b5f59b25c3eb78b3073 100644 (file)
@@ -21,7 +21,7 @@
  *
  *     // Output contains "ALIGNOF(char) == 1"
  *     // Will also print out whether an onstack char array can hold a long.
- *     int main(int argc, char *argv[])
+ *     int main(void)
  *     {
  *             char arr[sizeof(int)];
  *
index f36113d18fded305b364f98f5ddd94701be5b660..5e3216f1708e61000c76f135aaa759749f6452d3 100644 (file)
@@ -24,7 +24,7 @@ struct lots_of_types
        char c5;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct lots_of_types lots_of_types, *lp = malloc(sizeof(*lp));
        char c;
index 48697e044ec797ada4e6c77cddc91159363975db..164c826f551681549232867b259a5ac16ce5a56e 100644 (file)
@@ -18,7 +18,7 @@ int check_parameter(const struct foo *array)
 #endif
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        return check_parameter(NULL);
 }
index 37d315f2198c59c083cdc81c3c1e057538a123bd..9bd656826dc72d38eaeaff82f5887737df30b2bb 100644 (file)
@@ -2,6 +2,8 @@
 
 int main(int argc, char *argv[8])
 {
+       (void)argc;
+       (void)argv;
        char array[100];
 #ifdef FAIL
        return ARRAY_SIZE(argv) + ARRAY_SIZE(array);
index 37b4200b44f363340616da82e20ce2df44388d25..3c4ae1893cca09f384ed634897c09f535881e017 100644 (file)
@@ -16,7 +16,7 @@ static int array2_size = ARRAY_SIZE(array2);
 static int array3_size = ARRAY_SIZE(array3);
 static int array4_size = ARRAY_SIZE(array4);
 
-int main(int argc, char *argv[])
+int main(void)
 {
        plan_tests(8);
        ok1(array1_size == 1);
index 28e2faebecb3edfcc8e3eff487b99c59cc219401..4d59bec1a7a58d05af0fe4ca8c28f018207a2615 100644 (file)
@@ -31,7 +31,7 @@
  *     int main(int argc, char *argv[])
  *     {
  *             bool casefold = false;
- *             unsigned int i;
+ *             int i;
  *     
  *             if (argc < 2) {
  *                     fprintf(stderr, "Usage: %s [-i] <list>...\n"
index 473d10264140e04710be1a98f02e353a726a9d77..aa2340f4e22b8bf8c8e133f854889c8ef1dffc5b 100644 (file)
@@ -1,7 +1,7 @@
 #include <ccan/asort/asort.h>
 #include <ccan/asort/asort.c>
 
-static int cmp(char *const *a, char *const *b, int *flag)
+static int cmp(char *const *a UNNEEDED, char *const *b UNNEEDED, int *flag UNNEEDED)
 {
        return 0;
 }
index d8ea88feae962e28fb4735bbc823824052f8c197..e8086e3abceaa661ecbcf67cb6353d75f8249b32 100644 (file)
@@ -11,7 +11,7 @@ void *autodata_get_section(void *start, void *stop, size_t *nump)
        return start;
 }
 
-void autodata_free(void *table)
+void autodata_free(void *table UNNEEDED)
 {
 }
 #else
index 109215b8aa7eab11de86a00b2c174ba9a5cfb721..6322eb3523a2e951c0835d6223773002b50f82df 100644 (file)
@@ -1,6 +1,6 @@
 #include <ccan/build_assert/build_assert.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
 #ifdef FAIL
        return BUILD_ASSERT_OR_ZERO(1 == 0);
index 37d95eddc9b8d979476a3a921e86e793c7a1dfa7..9fd827d6aef87b7bcec2e234d5cbb9ccb8b8bdfb 100644 (file)
@@ -1,6 +1,6 @@
 #include <ccan/build_assert/build_assert.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
 #ifdef FAIL
        BUILD_ASSERT(1 == 0);
index 4105484d1fe35f113a83e32474ad1a57db50c8c8..b4de8b41402d6938fd7cf83b782c8de84904d2b1 100644 (file)
@@ -1,6 +1,6 @@
 #include <ccan/build_assert/build_assert.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        BUILD_ASSERT(1 == 1);
        return 0;
index 418582133179268f0d70ca6ab8fbd8715d72f5d9..72f9ad1ba478fe246775d4327c4c57d24cc2f309 100644 (file)
@@ -1,7 +1,7 @@
 #include <ccan/build_assert/build_assert.h>
 #include <ccan/tap/tap.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        plan_tests(1);
        ok1(BUILD_ASSERT_OR_ZERO(1 == 1) == 0);
index b09e0344e49d6ee570e9b70dbbe98e75393d8847..29128b8d5cf7cff915b07fa01783c2c44727073f 100644 (file)
@@ -24,6 +24,7 @@
  *     #include <ccan/cast/cast.h>
  *     #include <stdint.h>
  *     #include <stdio.h>
+ *     #include <stdlib.h>
  *
  *     // Find char @orig in @str, if @repl, replace them.  Return number.
  *     static size_t find_chars(char *str, char orig, char repl)
@@ -53,6 +54,9 @@
  *     {
  *             uint64_t hash;
  *
+ *             if (argc != 2) {
+ *                     fprintf(stderr, "Needs argument\n"); exit(1);
+ *             }
  *             // find_chars wants a non-const string, but doesn't
  *             // need it if repl == 0.
  *             printf("%zu %c's in 'test string'\n",
index 277f3de1c442b21fd9a8953b560a97d5bbb80e58..24ee4b1f00140ac662c8026e37b3adf1b5996b7b 100644 (file)
@@ -6,7 +6,7 @@ struct char_struct {
        char c;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char *uc;
        const
index e671e88eda56ca3dfdfab58bf3cd299fe4627e86..b780f5282f15f1da9ca6c2c03e09826cbccab199 100644 (file)
@@ -6,7 +6,7 @@ struct char_struct {
        char c;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char **uc;
        const
index e958e2dde5b61c485f63be5008c3ac5137733ecc..ac7462c58e2cd7f244225980733b40df3a03f375 100644 (file)
@@ -6,7 +6,7 @@ struct char_struct {
        char c;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char ***uc;
        const
index 9971dc8eb320cbdc1fc3cfcde2c71b34ea51f6ad..26bf8974ea48d6e82e6dda4de0f71f6f0878bd9e 100644 (file)
@@ -1,7 +1,7 @@
 #include <ccan/cast/cast.h>
 #include <stdlib.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        unsigned char *uc;
 #ifdef FAIL
index 2bc40b2f462b0ece7254eb671ed8c80f6167816a..b6bbd28386361a6130bb0a0fe8999d2f95530376 100644 (file)
@@ -6,7 +6,7 @@ struct char_struct {
        char c;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        unsigned char *uc;
 #ifdef FAIL
index 66bcc0a1b5ef6f6bed57d9870d81ce00cebb5b50..7661bac46e9afe8031ea6a485cf68d91222690e0 100644 (file)
@@ -1,7 +1,7 @@
 #include <ccan/cast/cast.h>
 #include <stdlib.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        unsigned char *uc;
 #ifdef FAIL
index 8a1202538455ecc4a30b96bd352f843e1d6c07d3..dae0231e81b2efdee5fb02ed5a33f64a47dafd1c 100644 (file)
@@ -1,7 +1,7 @@
 #include <ccan/cast/cast.h>
 #include <stdlib.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char *c;
 #ifdef FAIL
index 6296b752769822d1880e72d5bf3570f82170bed4..7cd52fc7a39cb478a80fd728e7342b01d48232c4 100644 (file)
@@ -1,7 +1,7 @@
 #include <ccan/cast/cast.h>
 #include <stdlib.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char *c;
 #ifdef FAIL
index a4ebf61b1ae66549a792771ca1085701b9efce0b..91d0940bfea470e1c24007c1ea3c9cd378d9b48d 100644 (file)
@@ -1,7 +1,7 @@
 #include <ccan/cast/cast.h>
 #include <stdlib.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        long c;
 #ifdef FAIL
index 98b667e83440f36020856fdcb89a00c171a29549..a7c65725ba0924553d586a2eac5f990c1aa78b9d 100644 (file)
@@ -6,5 +6,6 @@ static char *p = cast_const(char *, (const char *)"hello");
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
        return p[0] == argv[0][0];
 }
index 02ba19b5b3fb0d0b9d4ebe8a009195c6895e930e..c79d013b2c8a08ebb7bb826bd8c40ad2f64e4591 100644 (file)
@@ -29,7 +29,8 @@
  * {
  *     char *code, *problems;
  *     struct cdump_definitions *defs;
- *     int i, j;
+ *     int i;
+ *     size_t j;
  *
  *     // Read code from stdin.
  *     code = grab_file(NULL, NULL);
index 85c818a6df7508db2365efaa952366daa11f8af5..7e42dbd74dc6d328186680598a6b364b2c957bb9 100644 (file)
@@ -213,7 +213,7 @@ static struct cdump_type *get_type(struct cdump_definitions *defs,
                                   enum cdump_type_kind kind,
                                   const char *name)
 {
-       cdump_map_t *m;
+       cdump_map_t *m = (void *)0x1L; /* Shouldn't be used */
        struct cdump_type *t;
 
        switch (kind) {
index fe7d6a235c33011040bfe9648e98916c69418ce4..4c22c65a499c5df7252444549fb3efe56d70a51b 100644 (file)
@@ -2,6 +2,8 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
+       (void)argv;
 #ifdef FAIL
        check_type(argc, char);
 #endif
index 574d4aeb2402cf3f5ac6d0e7c3a1fe11a3e3de79..795e7606701955440ebd81e816946f36abecbcc8 100644 (file)
@@ -2,6 +2,8 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
+       (void)argv;
 #ifdef FAIL
 #if HAVE_TYPEOF
        check_type(argc, unsigned int);
index cbd6e9bc5b45fd79739b8bdebd9b3a68c5b3dca3..fb83738b90aba585aedb6c749709b93054c7b9a1 100644 (file)
@@ -3,6 +3,7 @@
 int main(int argc, char *argv[])
 {
        unsigned char x = argc;
+       (void)argv;
 #ifdef FAIL
        check_types_match(argc, x);
 #endif
index 83b903c0b1b33314b3cefae512299de9f59986bb..09fd3634376fc078d3d62df5b465e54f0a2db4cd 100644 (file)
@@ -5,6 +5,7 @@ int main(int argc, char *argv[])
 {
        int x = 0, y = 0;
 
+       (void)argv;
        plan_tests(9);
 
        ok1(check_type(argc, int) == 0);
index d60dff4d17bb0a50b691bb83097debdc94f38cf5..12cb24757829b55d339ed6f9e540834d84eac9d3 100644 (file)
@@ -41,7 +41,7 @@
  *             va_end(ap);
  *     }
  *
- *     int main(int argc, char *argv[])
+ *     int main(int argc, char *argv[] UNNEEDED)
  *     {
  *             if (argc != 1) {
  *                     logger(3, "Don't want %i arguments!\n", argc-1);
index 8f34ae5a1255b25f89aa0ae3424c9c47ef750cee..7664f65d4803a6426781e84493476ce72773c049 100644 (file)
@@ -2,9 +2,11 @@
 
 static void PRINTF_FMT(2,3) my_printf(int x, const char *fmt, ...)
 {
+       (void)x;
+       (void)fmt;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        unsigned int i = 0;
 
index a66f2e13e6c9c3749ae9357cb800517377d5863c..c914c68300868e79ee3c0b2862487740e76d6a1d 100644 (file)
@@ -3,6 +3,8 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
+       (void)argv;
        plan_tests(2);
 
        ok1(!IS_COMPILE_CONSTANT(argc));
index d50094bc68ec1ef077182028c0d045923160562f..b1160522edd4fcfd52935d39227d3d19653149ec 100644 (file)
  *             struct timer timer;
  *     };
  *
- *     static void register_timer(struct timer *timer)
- *     {
- *             //...
- *     }
- *
  *     static void my_timer_callback(struct timer *timer)
  *     {
  *             struct info *info = container_of(timer, struct info, timer);
  *             printf("my_stuff is %u\n", info->my_stuff);
  *     }
  *
+ *     static void register_timer(struct timer *timer)
+ *     {
+ *             (void)timer;
+ *             (void)my_timer_callback;
+ *             //...
+ *     }
+ *
  *     int main(void)
  *     {
  *             struct info info = { .my_stuff = 1 };
index b7a1459386b2d53c8f650388073f7e40f1934897..55a911a1b006c770ab703483e6b53775a851a4cb 100644 (file)
@@ -6,7 +6,7 @@ struct foo {
        char b;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct foo foo = { .a = 1, .b = 2 };
        int *intp = &foo.a;
index cae1c7abd20a1ed36ae6072faa8b50d9aea2644e..fbb97a9ee4f9db1df8f39b063086e18df3eb3994 100644 (file)
@@ -6,7 +6,7 @@ struct foo {
        char b;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct foo foo = { .a = 1, .b = 2 }, *foop;
        int *intp = &foo.a;
index f254d9210207fabfd3eedc69062516b0ccafc64e..ecdd90916fa64a49ddd899b67f3c5b222186d9a8 100644 (file)
@@ -6,7 +6,7 @@ struct foo {
        char b;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct foo foo = { .a = 1, .b = 2 }, *foop;
        int *intp = &foo.a;
index 18207f60521f418d75df8cee15293c062acc1a21..32557295ddec1d471e89873b1534bc4b5d2232b7 100644 (file)
@@ -6,7 +6,7 @@ struct foo {
        char b;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct foo foo = { .a = 1, .b = 2 };
        int *intp = &foo.a;
index 9a42d83e948d715232a1440f7f20271ca18a5ae7..4510def85b2dc0cb87fb0c780615a70da87fdd60 100644 (file)
@@ -237,7 +237,7 @@ cputype_t cpuid_get_cpu_type(void)
                uint32_t i;
 
                get_cpuid(CPUID_VENDORID, &i, &u.bufu32[0], &u.bufu32[2], &u.bufu32[1]);
-               for (i = 0; i < sizeof(c_cpunames) / sizeof(c_cpunames); ++i) {
+               for (i = 0; i < sizeof(c_cpunames) / sizeof(c_cpunames[0]); ++i) {
                        if (strncmp(c_cpunames[i], u.buf, 12) == 0) {
                                cputype = (cputype_t)i;
                                break;
index d250de3295418f6f5e127167d0fad0421d13bc87..20daa74d32b71fd8c296295a8ed9fba69d4c7d5e 100644 (file)
@@ -45,6 +45,7 @@ static void check_siphash24(struct siphash24_ctx *ctx)
 static bool alignment_ok(const void *p, size_t n)
 {
 #if HAVE_UNALIGNED_ACCESS
+       (void)p; (void)n;
        return true;
 #else
        return ((size_t)p % n == 0);
index a00fce74e456c42ce8ad9120418ad807967a4020..9bf47f13a6d6348937fc17f3103702c8a31c9802 100644 (file)
@@ -3,7 +3,7 @@
 #include <stddef.h>
 #include <ccan/tap/tap.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        union {
                uint64_t u64;
index 242e93f8061c246e344a26079f0b0fd2808bb813..aeaa3750b3d40ac7cc0223f24e4ae7fb4b0da42a 100644 (file)
@@ -15,6 +15,7 @@ int main(int argc, char *argv[])
        int pfd[2];
        const char *base;
 
+       (void)argc;
        plan_tests(24);
 
        err_set_progname(argv[0]);
@@ -27,7 +28,8 @@ int main(int argc, char *argv[])
                base = argv[0];
 
        /* Test err() in child */
-       pipe(pfd);
+       if (pipe(pfd))
+               abort();
        fflush(stdout);
        if (fork()) {
                char buffer[BUFFER_MAX+1];
@@ -59,7 +61,8 @@ int main(int argc, char *argv[])
        }
 
        /* Test errx() in child */
-       pipe(pfd);
+       if (pipe(pfd))
+               abort();
        fflush(stdout);
        if (fork()) {
                char buffer[BUFFER_MAX+1];
@@ -89,7 +92,8 @@ int main(int argc, char *argv[])
 
 
        /* Test warn() in child */
-       pipe(pfd);
+       if (pipe(pfd))
+               abort();
        fflush(stdout);
        if (fork()) {
                char buffer[BUFFER_MAX+1];
@@ -121,7 +125,8 @@ int main(int argc, char *argv[])
        }
 
        /* Test warnx() in child */
-       pipe(pfd);
+       if (pipe(pfd))
+               abort();
        fflush(stdout);
        if (fork()) {
                char buffer[BUFFER_MAX+1];
index aa20437ec443e643f275502e31d70d544ffeec20..0bb21c980057d29af5ac34680a15ca1cbf39f83d 100644 (file)
@@ -44,7 +44,7 @@ static int count_iters(void)
 
 int main(void)
 {
-       int i, j, sum, max_iters;
+       int i, j, sum, max_iters = 0 /* keep gcc happy */;
        const char *istr, *jstr;
 
        plan_tests(13);
index 7e06c3867a3f977797720e54368f25cb3084d6c6..a3bb76db6bf0395562bfbc96c02e0f9e98e04391 100644 (file)
@@ -36,6 +36,7 @@
  *     // Wrapper for rehash function pointer.
  *     static size_t rehash(const void *e, void *unused)
  *     {
+ *             (void)unused;
  *             return hash_string(((struct name_to_digit *)e)->name);
  *     }
  *
@@ -64,7 +65,7 @@
  *     int main(int argc, char *argv[])
  *     {
  *             struct htable ht;
- *             unsigned int i;
+ *             int i;
  *             unsigned long val;
  *
  *             if (argc < 2)
@@ -73,7 +74,7 @@
  *
  *             // Create and populate hash table.
  *             htable_init(&ht, rehash, NULL);
- *             for (i = 0; i < sizeof(map)/sizeof(map[0]); i++)
+ *             for (i = 0; i < (int)(sizeof(map)/sizeof(map[0])); i++)
  *                     htable_add(&ht, hash_string(map[i].name), &map[i]);
  *
  *             // Add any aliases to the hash table.
index 61ed9170fda461779840f63db55295757a9bce8a..9845388e1b9f47b7938e765a4682c7b4aee689fe 100644 (file)
@@ -35,6 +35,7 @@ struct htable {
  *     // For simplicity's sake, say hash value is contents of elem.
  *     static size_t rehash(const void *elem, void *unused)
  *     {
+ *             (void)unused;
  *             return *(size_t *)elem;
  *     }
  *     static struct htable ht = HTABLE_INITIALIZER(ht, rehash, NULL);
index 02d5bbe46856daef1689c784152bee6c218ea806..d111495ad4c775c20a6875e141aef19c12f942da 100644 (file)
@@ -6,7 +6,7 @@
 
 #define NUM_VALS 512
 
-static size_t hash(const void *elem, void *unused)
+static size_t hash(const void *elem, void *unused UNNEEDED)
 {
        size_t h = *(uint64_t *)elem / 2;
        return h;
@@ -17,7 +17,7 @@ static bool cmp(const void *candidate, void *ptr)
        return *(const uint64_t *)candidate == *(const uint64_t *)ptr;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct htable ht, ht2;
        uint64_t val[NUM_VALS], i;
index c92401c3c67d0d1d525c33f33f58d055512ee35f..1a2f5cdd1ef8cbbfc1ab84f8221b5bb61b9734ab 100644 (file)
@@ -8,13 +8,13 @@
 
 /* We use the number divided by two as the hash (for lots of
    collisions). */
-static size_t hash(const void *elem, void *unused)
+static size_t hash(const void *elem, void *unused UNNEEDED)
 {
        size_t h = *(uint64_t *)elem / 2;
        return h;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct htable ht;
        uint64_t val[NUM_VALS];
index 66346d0c70ab24eebcccb13af6f84587ca2c4399..7b71815f3c38fef390a63ad4e420040939338c0e 100644 (file)
@@ -88,7 +88,7 @@ static void del_vals(struct htable_obj *ht,
 }
 
 static void del_vals_bykey(struct htable_obj *ht,
-                          const struct obj val[], unsigned int num)
+                          const struct obj val[] UNNEEDED, unsigned int num)
 {
        unsigned int i;
 
@@ -112,7 +112,7 @@ static bool check_mask(struct htable *ht, const struct obj val[], unsigned num)
        return true;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        unsigned int i;
        struct htable_obj ht, ht2;
index e1a78f49616eee40d421994253b30b1c07a5aba7..a3616a5a37b8fb1f2588d9d8e369136c6436665e 100644 (file)
@@ -83,7 +83,7 @@ static void del_vals(struct htable_obj *ht,
 }
 
 static void del_vals_bykey(struct htable_obj *ht,
-                          const struct obj val[], unsigned int num)
+                          const struct obj val[] UNNEEDED, unsigned int num)
 {
        unsigned int i;
 
@@ -107,7 +107,7 @@ static bool check_mask(struct htable *ht, const struct obj val[], unsigned num)
        return true;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        unsigned int i;
        struct htable_obj ht, ht2;
index fdd18569e7cc516f2d5b7fb5bbc25a7d0a35bacf..3a1a939e8ab390b921c02a3a1607ca98a6c38389 100644 (file)
@@ -8,7 +8,7 @@ struct data {
 };
 
 /* Hash is simply key itself. */
-static size_t hash(const void *e, void *unused)
+static size_t hash(const void *e, void *unused UNNEEDED)
 {
        struct data *d = (struct data *)e;
 
index 09cde890f7ea34af2e8be9c080ebd472c2b8f21c..46514c7202f2438b54b15aca2f9c0800ca5f5dd4 100644 (file)
@@ -10,7 +10,7 @@
 /* We use the number divided by two as the hash (for lots of
    collisions), plus set all the higher bits so we can detect if they
    don't get masked out. */
-static size_t hash(const void *elem, void *unused)
+static size_t hash(const void *elem, void *unused UNNEEDED)
 {
        size_t h = *(uint64_t *)elem / 2;
        h |= -1UL << NUM_BITS;
@@ -95,7 +95,7 @@ static bool check_mask(struct htable *ht, uint64_t val[], unsigned num)
        return true;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        unsigned int i, weight;
        uintptr_t perfect_bit;
index 48205d380edd72c7e7ffbd67c8ef8cc0591f51fc..a0918d751c0ba4998f0873d1d3dffb3cdc7252d6 100644 (file)
@@ -19,7 +19,7 @@ static int test_ilog64(uint64_t _v){
 
 #define NTRIALS (64)
 
-int main(int _argc,const char *_argv[]){
+int main(void){
   int i;
   int j;
   int (*il32)(uint32_t) = ilog32;
index bda59f920a33e115958eeff8b91a6a6a8d2eb966..00824ac3a7b6d29f0a2e5c87442c31f145318905 100644 (file)
@@ -19,7 +19,7 @@ static int test_ilog64(uint64_t _v){
 
 #define NTRIALS (64)
 
-int main(int _argc,const char *_argv[]){
+int main(void){
   int i;
   int j;
   /*This is how many tests you plan to run.*/
index 9316dd180a9895adc2f60fdb6cdaeff6d77deb4a..e24beec4666a37284b72f545c735989119381ce5 100644 (file)
@@ -47,7 +47,8 @@ struct io_conn;
  *     int fd[2];
  *     struct io_conn *conn;
  *
- *     pipe(fd);
+ *     if (pipe(fd) != 0)
+ *             exit(1);
  *     conn = io_new_conn(NULL, fd[0], conn_init, (const char *)"hi!");
  *     if (!conn)
  *             exit(1);
@@ -653,11 +654,11 @@ int io_conn_fd(const struct io_conn *conn);
  * io_time_override - override the normal call for time.
  * @nowfn: the function to call.
  *
- * io usually uses time_now() internally, but this forces it
+ * io usually uses time_mono() internally, but this forces it
  * to use your function (eg. for debugging).  Returns the old
  * one.
  */
-struct timeabs (*io_time_override(struct timeabs (*now)(void)))(void);
+struct timemono (*io_time_override(struct timemono (*now)(void)))(void);
 
 /**
  * io_set_debug - set synchronous mode on a connection.
index cddc3cacd266e5b80392d91af367d689da093bd6..36af33ef0854de3323c8f29c4dc522c976091764 100644 (file)
@@ -16,11 +16,11 @@ static struct pollfd *pollfds = NULL;
 static struct fd **fds = NULL;
 static LIST_HEAD(closing);
 static LIST_HEAD(always);
-static struct timeabs (*nowfn)(void) = time_now;
+static struct timemono (*nowfn)(void) = time_mono;
 
-struct timeabs (*io_time_override(struct timeabs (*now)(void)))(void)
+struct timemono (*io_time_override(struct timemono (*now)(void)))(void)
 {
-       struct timeabs (*old)(void) = nowfn;
+       struct timemono (*old)(void) = nowfn;
        nowfn = now;
        return old;
 }
@@ -262,7 +262,7 @@ void *io_loop(struct timers *timers, struct timer **expired)
                assert(num_waiting);
 
                if (timers) {
-                       struct timeabs now, first;
+                       struct timemono now, first;
 
                        now = nowfn();
 
@@ -274,7 +274,7 @@ void *io_loop(struct timers *timers, struct timer **expired)
                        /* Now figure out how long to wait for the next one. */
                        if (timer_earliest(timers, &first)) {
                                uint64_t next;
-                               next = time_to_msec(time_between(first, now));
+                               next = time_to_msec(timemono_between(first, now));
                                if (next < INT_MAX)
                                        ms_timeout = next;
                                else
index eb12e9488aea2eaca1dc445fb1cff6c46bddbbfc..04952db88e5ce9e3d65c9cadb57fee5e4730e001 100644 (file)
@@ -69,7 +69,7 @@ static int make_listen_fd(const char *port, struct addrinfo **info)
 int main(void)
 {
        int state = 0;
-       struct addrinfo *addrinfo;
+       struct addrinfo *addrinfo = NULL;
        struct io_listener *l;
        int fd;
 
index e25bbbb49cc5ee8e4ad4af8856e36e62608a751e..74cb2f021d87393c1dd0110a10a110ad1d52f09a 100644 (file)
@@ -71,7 +71,7 @@ static int make_listen_fd(const char *port, struct addrinfo **info)
 int main(void)
 {
        struct data *d = malloc(sizeof(*d));
-       struct addrinfo *addrinfo;
+       struct addrinfo *addrinfo = NULL;
        struct io_listener *l;
        int fd, status;
 
index 5709ddaa8a25416d6bb56c2a7d21ce81688e0e52..a4ab23add0abed3b0a3bcc5d536983db458ce8b5 100644 (file)
@@ -47,8 +47,7 @@ static struct io_plan *init_conn(struct io_conn *conn, struct data *d)
        d->conn = conn;
        io_set_finish(conn, finish_ok, d);
 
-       timer_add(&d->timers, &d->timer,
-                 timeabs_add(time_now(), time_from_usec(d->timeout_usec)));
+       timer_addrel(&d->timers, &d->timer, time_from_usec(d->timeout_usec));
 
        return io_read(conn, d->buf, sizeof(d->buf), no_timeout, d);
 }
@@ -97,7 +96,7 @@ int main(void)
        plan_tests(21);
        d->state = 0;
        d->timeout_usec = 100000;
-       timers_init(&d->timers, time_now());
+       timers_init(&d->timers, time_mono());
        timer_init(&d->timer);
        fd = make_listen_fd(PORT, &addrinfo);
        ok1(fd >= 0);
@@ -131,7 +130,7 @@ int main(void)
 
        /* One element, d->timer. */
        ok1(expired == &d->timer);
-       ok1(!timers_expire(&d->timers, time_now()));
+       ok1(!timers_expire(&d->timers, time_mono()));
        ok1(d->state == 1);
 
        io_close(d->conn);
index bf493c9912cf3ff2dd00033b3adfd8d09f434e34..c0b607a74cfdf09cb6a6c703da40b0ae794fc3bd 100644 (file)
@@ -45,9 +45,9 @@ static int make_listen_fd(const char *port, struct addrinfo **info)
        return fd;
 }
 
-static struct timeabs fake_time;
+static struct timemono fake_time;
 
-static struct timeabs get_fake_time(void)
+static struct timemono get_fake_time(void)
 {
        return fake_time;
 }
@@ -63,12 +63,12 @@ int main(void)
        /* This is how many tests you plan to run */
        plan_tests(7);
 
-       fake_time = time_now();
+       fake_time = time_mono();
 
        timers_init(&timers, fake_time);
        timer_init(&timer);
-       timer_add(&timers, &timer,
-                 timeabs_add(fake_time, time_from_sec(1000)));
+       timer_addmono(&timers, &timer,
+                     timemono_add(fake_time, time_from_sec(1000)));
 
        fd = make_listen_fd(PORT, &addrinfo);
        freeaddrinfo(addrinfo);
@@ -77,12 +77,12 @@ int main(void)
        ok1(l);
 
        fake_time.ts.tv_sec += 1000;
-       ok1(io_time_override(get_fake_time) == time_now);
+       ok1(io_time_override(get_fake_time) == time_mono);
        ok1(io_loop(&timers, &expired) == NULL);
 
        ok1(expired == &timer);
        ok1(!timers_expire(&timers, fake_time));
-       ok1(io_time_override(time_now) == get_fake_time);
+       ok1(io_time_override(time_mono) == get_fake_time);
        io_close_listener(l);
 
        timers_cleanup(&timers);
index 81a46bc2ce8fc245469b8ba90ef897052b852b53..c7ea4f97a38c6d7068b979156fce0d6f8fd2455b 100644 (file)
@@ -134,7 +134,7 @@ static const uint32_t STATEVEC[ISAAC_SZ<<1]={
   0x46D95CA5, 0xC54CD95B, 0x9D855E89, 0x4BB5AF29
 };
 
-int main(int _argc,const char *_argv[]){
+int main(void){
   isaac_ctx   isaac;
   int         i;
   int         j;
index db2b4d350e5b5d61eb5fed8e95615f0eaf416ee3..de9bef492bbc80c656caa36c888861c965f99094 100644 (file)
@@ -262,7 +262,7 @@ static const uint64_t STATEVEC64[ISAAC64_SZ<<1]={
   0x1877B51E57A764D5ULL, 0x001F837CC7350524ULL
 };
 
-int main(int _argc,const char *_argv[]){
+int main(void){
   isaac64_ctx isaac64;
   int         i;
   int         j;
index b9f07b9803a9b596bbbc9710504ceb976e9adf3f..efb46698a96c7f2d1c1a51fed48af0ab948bd079 100644 (file)
@@ -1,6 +1,6 @@
 CFLAGS=-Wall -Werror -O3 -I../../..
-LDFLAGS=-lJudy
+LDLIBS=-lJudy
 
 speed: speed.o
 
-speed.o: speed.c ../jmap.h ../jmap_type.h ../jmap.c
+speed.o: speed.c ../jmap.h
index d2ecd6f67694d84674d148c667b69a637d655c6b..6cd6d4799c14516ba539155bb5b81958560f2e7e 100644 (file)
@@ -1,38 +1,33 @@
 /* Simple speed tests for jmap. */
-#include <ccan/jmap/jmap_type.h>
 #include <ccan/jmap/jmap.c>
+#include <ccan/time/time.c>
 #include <stdio.h>
 #include <stdlib.h>
-#include <time.h>
 #include <unistd.h>
-#include <sys/time.h>
 
 struct object {
        /* Some contents. Doubles as consistency check. */
        struct object *self;
 };
 
+struct jmap_obj {
+       JMAP_MEMBERS(unsigned int, struct object *);
+};
+
 /* Nanoseconds per operation */
-static size_t normalize(const struct timeval *start,
-                       const struct timeval *stop,
+static size_t normalize(const struct timeabs *start,
+                       const struct timeabs *stop,
                        unsigned int num)
 {
-       struct timeval diff;
-
-       timersub(stop, start, &diff);
-
-       /* Floating point is more accurate here. */
-       return (double)(diff.tv_sec * 1000000 + diff.tv_usec)
-               / num * 1000;
+       return time_to_nsec(time_divide(time_between(*stop, *start), num));
 }
 
-JMAP_DEFINE_UINTIDX_TYPE(struct object, obj);
-
 int main(int argc, char *argv[])
 {
        struct object *objs;
-       size_t i, j, num;
-       struct timeval start, stop;
+       unsigned int i, j;
+       size_t num;
+       struct timeabs start, stop;
        struct jmap_obj *jmap;
 
        num = argv[1] ? atoi(argv[1]) : 1000000;
@@ -42,110 +37,110 @@ int main(int argc, char *argv[])
                objs[i].self = &objs[i];
        }
 
-       jmap = jmap_obj_new();
+       jmap = jmap_new(struct jmap_obj);
 
        printf("Initial insert: ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i++)
-               jmap_obj_add(jmap, i, objs[i].self);
-       gettimeofday(&stop, NULL);
+               jmap_add(jmap, i, objs[i].self);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Initial lookup (match): ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i++)
-               if (jmap_obj_get(jmap, i)->self != objs[i].self)
+               if (jmap_get(jmap, i)->self != objs[i].self)
                        abort();
-       gettimeofday(&stop, NULL);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Initial lookup (miss): ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i++)
-               if (jmap_obj_get(jmap, i+num))
+               if (jmap_get(jmap, i+num))
                        abort();
-       gettimeofday(&stop, NULL);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        /* Lookups in order are very cache-friendly for judy; try random */
        printf("Initial lookup (random): ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0, j = 0; i < num; i++, j = (j + 10007) % num)
-               if (jmap_obj_get(jmap, j)->self != &objs[j])
+               if (jmap_get(jmap, j)->self != &objs[j])
                        abort();
-       gettimeofday(&stop, NULL);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Initial delete all: ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i++)
-               jmap_obj_del(jmap, i);
-       gettimeofday(&stop, NULL);
+               jmap_del(jmap, i);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Initial re-inserting: ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i++)
-               jmap_obj_add(jmap, i, objs[i].self);
-       gettimeofday(&stop, NULL);
+               jmap_add(jmap, i, objs[i].self);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Deleting first half: ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i+=2)
-               jmap_obj_del(jmap, i);
-       gettimeofday(&stop, NULL);
+               jmap_del(jmap, i);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Adding (a different) half: ");
        fflush(stdout);
 
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i+=2)
-               jmap_obj_add(jmap, num+i, objs[i].self);
-       gettimeofday(&stop, NULL);
+               jmap_add(jmap, num+i, objs[i].self);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Lookup after half-change (match): ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 1; i < num; i+=2)
-               if (jmap_obj_get(jmap, i)->self != objs[i].self)
+               if (jmap_get(jmap, i)->self != objs[i].self)
                        abort();
        for (i = 0; i < num; i+=2)
-               if (jmap_obj_get(jmap, i+num)->self != objs[i].self)
+               if (jmap_get(jmap, i+num)->self != objs[i].self)
                        abort();
-       gettimeofday(&stop, NULL);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Lookup after half-change(miss): ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i++)
-               if (jmap_obj_get(jmap, i+num*2))
+               if (jmap_get(jmap, i+num*2))
                        abort();
-       gettimeofday(&stop, NULL);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        /* Hashtables with delete markers can fill with markers over time.
         * so do some changes to see how it operates in long-term. */
        printf("Details: churning first time\n");
        for (i = 1; i < num; i+=2) {
-               if (!jmap_obj_del(jmap, i))
+               if (!jmap_del(jmap, i))
                        abort();
-               jmap_obj_add(jmap, i, objs[i].self);
+               jmap_add(jmap, i, objs[i].self);
        }
        for (i = 0; i < num; i+=2) {
-               if (!jmap_obj_del(jmap, i+num))
+               if (!jmap_del(jmap, i+num))
                        abort();
-               jmap_obj_add(jmap, i, objs[i].self);
+               jmap_add(jmap, i, objs[i].self);
        }
        for (i = 1; i < 5; i++) {
                printf("Churning %s time: ",
@@ -154,84 +149,88 @@ int main(int argc, char *argv[])
                       : i == 3 ? "fourth"
                       : "fifth");
                fflush(stdout);
-               gettimeofday(&start, NULL);
+
+               start = time_now();
                for (j = 0; j < num; j++) {
-                       if (!jmap_obj_del(jmap, num*(i-1)+j))
+                       if (!jmap_del(jmap, num*(i-1)+j))
                                abort();
-                       jmap_obj_add(jmap, num*i+j, &objs[j]);
+                       jmap_add(jmap, num*i+j, &objs[j]);
                }
-               gettimeofday(&stop, NULL);
+               stop = time_now();
                printf(" %zu ns\n", normalize(&start, &stop, num));
        }
 
        /* Spread out the keys more to try to make it harder. */
        printf("Details: reinserting with spread\n");
        for (i = 0; i < num; i++) {
-               if (!jmap_obj_del(jmap, num*4 + i))
+               if (!jmap_del(jmap, num*4 + i))
                        abort();
-               jmap_obj_add(jmap, num * 5 + i * 9, objs[i].self);
+               jmap_add(jmap, num * 5 + i * 9, objs[i].self);
        }
 
-       if (jmap_obj_popcount(jmap, 0, -1) != num)
+       if (jmap_popcount(jmap, 0, -1) != num)
                abort();
 
        printf("Lookup after churn & spread (match): ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i++)
-               if (jmap_obj_get(jmap, num * 5 + i * 9)->self != objs[i].self) {
+               if (jmap_get(jmap, num * 5 + i * 9)->self != objs[i].self) {
                        printf("i  =%u\n", i);
                        abort();
                }
-       gettimeofday(&stop, NULL);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Lookup after churn & spread (miss): ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i++)
-               if (jmap_obj_get(jmap, num * 6 + i * 9))
+               if (jmap_get(jmap, num * 6 + i * 9))
                        abort();
-       gettimeofday(&stop, NULL);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Lookup after churn & spread (random): ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0, j = 0; i < num; i++, j = (j + 10007) % num)
-               if (jmap_obj_get(jmap, num * 5 + j * 9)->self != &objs[j])
+               if (jmap_get(jmap, num * 5 + j * 9)->self != &objs[j])
                        abort();
-       gettimeofday(&stop, NULL);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Lookup after churn & spread (half-random): ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0, j = 0; i < num/2; i++, j = (j + 10007) % num) {
-               if (jmap_obj_get(jmap, num * 5 + j * 9)->self != &objs[j])
+               if (jmap_get(jmap, num * 5 + j * 9)->self != &objs[j])
                        abort();
-               if (jmap_obj_get(jmap, num * 5 + (j + 1) * 9)->self != &objs[j+1])
+               if (jmap_get(jmap, num * 5 + (j + 1) * 9)->self != &objs[j+1])
                        abort();
        }
-       gettimeofday(&stop, NULL);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Deleting half after churn & spread: ");
        fflush(stdout);
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i+=2)
-               jmap_obj_del(jmap, num * 5 + i * 9);
-       gettimeofday(&stop, NULL);
+               jmap_del(jmap, num * 5 + i * 9);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
        printf("Adding (a different) half after churn & spread: ");
        fflush(stdout);
 
-       gettimeofday(&start, NULL);
+       start = time_now();
        for (i = 0; i < num; i+=2)
-               jmap_obj_add(jmap, num * 6 + i * 9, objs[i].self);
-       gettimeofday(&stop, NULL);
+               jmap_add(jmap, num * 6 + i * 9, objs[i].self);
+       stop = time_now();
        printf(" %zu ns\n", normalize(&start, &stop, num));
 
+       jmap_free(jmap);
+       free (objs);
+
        return 0;
 }
index 83f22afab2bf622141ebb4330af9c88e9de96c4f..72015ee42858301bd343572fead21ae9cce81a2b 100644 (file)
@@ -26,7 +26,7 @@ static bool likely_one_unlikely_two(unsigned int val1, unsigned int val2)
        return false;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char *bad;
 
index fa1dc9f6eade527431deae6b2d1b1ec470630357..28ea798578e7f4558acbe1aeafaccdc3fafc1ea5 100644 (file)
@@ -17,7 +17,7 @@ static bool one_seems_unlikely(unsigned int val)
        return false;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        plan_tests(4);
 
index 60790a9903f084eb0492436a95dd097eefe67416..c4f3e2a0acf21b32097cf5b3a9194361831d0a4b 100644 (file)
@@ -31,7 +31,7 @@
  *     {
  *             struct parent p;
  *             struct child *c;
- *             unsigned int i;
+ *             int i;
  *
  *             if (argc < 2)
  *                     errx(1, "Usage: %s parent children...", argv[0]);
index 0800a0fa144f20f1ab0985b5b3dd369fe9f39eef..a6b00385984c52ce9ab3a614e351437616f69b8e 100644 (file)
@@ -291,6 +291,21 @@ static inline bool list_empty_nodebug(const struct list_head *h)
 }
 #endif
 
+/**
+ * list_empty_nocheck - is a list empty?
+ * @h: the list_head
+ *
+ * If the list is empty, returns true. This doesn't perform any
+ * debug check for list consistency, so it can be called without
+ * locks, racing with the list being modified. This is ok for
+ * checks where an incorrect result is not an issue (optimized
+ * bail out path for example).
+ */
+static inline bool list_empty_nocheck(const struct list_head *h)
+{
+       return h->n.next == &h->n;
+}
+
 /**
  * list_del - delete an entry from an (unknown) linked list.
  * @n: the list_node to delete from the list.
@@ -701,12 +716,12 @@ static inline void list_prepend_list_(struct list_head *to,
  * so you can break and continue as normal.
  *
  * WARNING! Being the low-level macro that it is, this wrapper doesn't know
- * nor care about the type of @i. The only assumtion made is that @i points
+ * nor care about the type of @i. The only assumption made is that @i points
  * to a chunk of memory that at some @offset, relative to @i, contains a
- * properly filled `struct node_list' which in turn contains pointers to
- * memory chunks and it's turtles all the way down. Whith all that in mind
+ * properly filled `struct list_node' which in turn contains pointers to
+ * memory chunks and it's turtles all the way down. With all that in mind
  * remember that given the wrong pointer/offset couple this macro will
- * happilly churn all you memory untill SEGFAULT stops it, in other words
+ * happily churn all you memory until SEGFAULT stops it, in other words
  * caveat emptor.
  *
  * It is worth mentioning that one of legitimate use-cases for that wrapper
index 9fcb1d7456a699720f6e9d141039a411aa092a19..b8e5165a6441c841ef77d85798ef5547d49ef65b 100644 (file)
@@ -17,6 +17,7 @@ static int my_fprintf(FILE *stream, const char *format, ...)
 {
        va_list ap;
        int ret;
+       (void)stream;
        va_start(ap, format);
        ret = vsprintf(printf_buffer, format, ap);
        va_end(ap);
@@ -28,7 +29,7 @@ static int my_fprintf(FILE *stream, const char *format, ...)
 #include <ccan/tap/tap.h>
 #include <ccan/list/list.c>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct list_head list;
        struct list_node n1;
@@ -44,7 +45,7 @@ int main(int argc, char *argv[])
        list.n.prev = &n1;
 
        /* Aborting version. */
-       sprintf(expect, "run-CCAN_LIST_DEBUG.c:50: prev corrupt in node %p (0) of %p\n",
+       sprintf(expect, "run-CCAN_LIST_DEBUG.c:51: prev corrupt in node %p (0) of %p\n",
                &list, &list);
        if (setjmp(aborted) == 0) {
                assert(list_empty(&list));
index 5dd9f9cc835a91a7fc3f9448a3dad80fe407ec88..94c2e67e7bed36ddf3f19f511de8327c296ac1fa 100644 (file)
@@ -16,6 +16,7 @@ static int my_fprintf(FILE *stream, const char *format, ...)
 {
        va_list ap;
        int ret;
+       (void)stream;
        va_start(ap, format);
        ret = vsprintf(printf_buffer, format, ap);
        va_end(ap);
@@ -26,7 +27,7 @@ static int my_fprintf(FILE *stream, const char *format, ...)
 #include <ccan/tap/tap.h>
 #include <ccan/list/list.c>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct list_head list;
        struct list_node n1;
index b006a8a2e260963f63983ce51075dcb7ab642880..d3cb652a34a5be0469571af9c7ed0d667fb7549c 100644 (file)
@@ -8,7 +8,7 @@ struct child {
        struct list_node list;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct child c1, c2;
        struct list_head list = LIST_HEAD_INIT(list);
index 05d6cad62c4b54517ab068043f9fe30fd0f9bae5..9404b7120ee9d4e3cbe587fe6ed456cbf1db3f87 100644 (file)
@@ -7,7 +7,7 @@
 #include <unistd.h>
 #include <signal.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct list_head list1, list2;
        struct list_node n1, n2, n3;
index b496f11f84d8bea54191be4ff4069882be5aa3f9..cc61e03a01f3f160f2c94bb91b12bca23d60ba85 100644 (file)
@@ -14,7 +14,7 @@ struct child {
        struct list_node list;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct parent parent;
        struct child c1, c2, c3;
index d382f5a83a4ea60add31ed834285b7e51a3b2b29..fecd4196fd702d2ff42dd17f2bc188595c9e56a2 100644 (file)
@@ -17,7 +17,7 @@ static bool list_expect(struct list_head *h, ...)
        return (n->next == &h->n);
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct list_head h1, h2;
        struct list_node n[4];
index f90eed357ac9875d2cca6bc031612aca4d307160..db0bffdda5aa30092fb4ef2bc6a8601a34695042 100644 (file)
@@ -19,7 +19,7 @@ static LIST_HEAD(static_list);
 
 #define ref(obj, counter) ((counter)++, (obj))
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct parent parent;
        struct child c1, c2, c3, *c, *n;
index 7616af6c6095e8ca0978d35608ba56a2846e7b73..5787e4563e08f8de08c095a992f257df75d98c64 100644 (file)
@@ -16,7 +16,7 @@ struct child {
 
 static LIST_HEAD(static_list);
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct parent parent;
        struct child c1, c2, c3, x1, *c, *n;
index f2c3d5c7a6f795e2e091df8a545992c6533b50ec..19f69c038c67efe1e11ac8ab5cec036123aa3b95 100644 (file)
@@ -250,6 +250,7 @@ static inline void *memcheck_(const void *data, size_t len)
 #else
 static inline void *memcheck_(const void *data, size_t len)
 {
+       (void)len;
        return (void *)data;
 }
 #endif
index 082c71e601e451cf77ef022555d25d102f054de2..85f1f6f9c3906496969eba2b234fe11146b92749 100644 (file)
@@ -37,7 +37,7 @@
  *                     return false;
  *             }
  *             // A short write means out of space.
- *             if (ret < strlen(string)) {
+ *             if (ret < (int)strlen(string)) {
  *                     unlink(file);
  *                     errno = ENOSPC;
  *                     return false;
index 48086a24d542e98dccaa33548748850f5d464b83..31fb67400572d43aca0abf7b36f003ecf225346f 100644 (file)
@@ -7,7 +7,7 @@
 #include <stdio.h>
 #include <assert.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        const char *name = "noerr.file";
        int fd;
index 690907e595eff6922690204eb4c76a6be3e59d8c..0d508cf6fd173d1578bf26d1a703c3b12bbf3643 100644 (file)
@@ -185,7 +185,7 @@ void opt_register_table(const struct opt_table *table, const char *desc);
  * string (or see opt_set_alloc) and return false.
  *
  * Example:
- * static char *explode(const char *optarg, void *unused)
+ * static char *explode(const char *optarg, void *unused UNNEEDED)
  * {
  *     errx(1, "BOOM! %s", optarg);
  * }
index f1d10da10601d43e6dc07990d8db68920e8d892f..a73443473bf8707cbb71f190f2e66feec7fd0431 100644 (file)
@@ -4,7 +4,7 @@
 #include <ccan/opt/parse.c>
 #include <ccan/opt/usage.c>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        opt_register_noarg("-v", opt_version_and_exit,
                           (const char *)"1.2.3",
index ded3f88061deddcaa5d1a8378a659631f9af614f..b559c7f747689bae70d34589ee9794f4cf710ac0 100644 (file)
@@ -4,19 +4,19 @@
 #include <ccan/opt/helpers.c>
 #include <ccan/opt/parse.c>
 
-static void show_10(char buf[OPT_SHOW_LEN], const void *arg)
+static void show_10(char buf[OPT_SHOW_LEN], const void *arg UNNEEDED)
 {
        memset(buf, 'X', 10);
        buf[10] = '\0';
 }
 
-static void show_max(char buf[OPT_SHOW_LEN], const void *arg)
+static void show_max(char buf[OPT_SHOW_LEN], const void *arg UNNEEDED)
 {
        memset(buf, 'X', OPT_SHOW_LEN);
 }
 
 /* Test add_desc helper. */
-int main(int argc, char *argv[])
+int main(void)
 {
        struct opt_table opt;
        char *ret;
index d54a75205e9c675c9adc9312372809cbefa00964..8447f98d1a829254f01a4417688545238f1d6f8b 100644 (file)
@@ -53,7 +53,7 @@ static void reset(void)
        opt_count = opt_num_short = opt_num_short_arg = opt_num_long = 0;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        int exitval;
 
index 9f164656abd602d0b4fe414664bb51c498a62553..c1eaf56aa2678fc972671861a100f233c665a22f 100644 (file)
@@ -5,7 +5,7 @@
 #include <ccan/opt/parse.c>
 
 /* Test consume_words helper. */
-int main(int argc, char *argv[])
+int main(void)
 {
        size_t prefix, len;
        bool start = true;
index 6ec17f589fdb76d8c1fc7f0f78d39619d18c6294..0a08a85f7aa3930011cba5600186f3a21d5c5f09 100644 (file)
@@ -52,7 +52,7 @@ static int saved_printf(const char *fmt, ...)
        return ret;
 }
 
-static int saved_fprintf(FILE *ignored, const char *fmt, ...)
+static int saved_fprintf(FILE *ignored UNNEEDED, const char *fmt, ...)
 {
        va_list ap;
        int ret;
index e6b13dadea8d33b38d02e55ca99c20e0d956d1d8..d34fd6dc176a844f166d0fb32f9450f7bcd0a9f7 100644 (file)
@@ -10,7 +10,7 @@
 #include <ccan/opt/parse.c>
 
 /* Test iterators. */
-int main(int argc, char *argv[])
+int main(void)
 {
        unsigned j, i, len = 0;
        const char *p;
index 6a10d5979fca77d9e024fca95e962108ad66dbe4..1dbb351bedf41b0022a8abd26b3c0fbbc07ad445 100644 (file)
@@ -2,15 +2,15 @@
 #include <stdlib.h>
 
 /* Make sure we override these! */
-static void *no_malloc(size_t size)
+static void *no_malloc(size_t size UNNEEDED)
 {
        abort();
 }
-static void *no_realloc(void *p, size_t size)
+static void *no_realloc(void *p UNNEEDED, size_t size UNNEEDED)
 {
        abort();
 }
-static void no_free(void *p)
+static void no_free(void *p UNNEEDED)
 {
        abort();
 }
index aec8324474f2b2a547574d870968c92b476e3e3e..cea678f3806ded21d7636bf3f3380ebe67e3ca02 100644 (file)
@@ -6,7 +6,7 @@
 #include "utils.h"
 
 /* Ensure width is sane. */
-static const char *getenv_override(const char *name)
+static const char *getenv_override(const char *name UNNEEDED)
 {
        return "100";
 }
@@ -18,13 +18,13 @@ static const char *getenv_override(const char *name)
 #include <ccan/opt/helpers.c>
 #include <ccan/opt/parse.c>
 
-static char *my_cb(void *p)
+static char *my_cb(void *p UNNEEDED)
 {
        return NULL;
 }
 
 /* Test helpers. */
-int main(int argc, char *argv[])
+int main(void)
 {
        char *output;
        char *longname = strdup("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
index c2967fca173d51010b810fcaa626eb6ebff420df..a9bedf2e0063333060a597a3bd591ff76744ab00 100644 (file)
@@ -8,7 +8,7 @@
 #include "utils.h"
 
 unsigned int test_cb_called;
-char *test_noarg(void *arg)
+char *test_noarg(void *arg UNNEEDED)
 {
        test_cb_called++;
        return NULL;
index 863a8e16e1425803621ee0bc68e37ee376693f20..5ff85a987fec66fd5c55aa89d3a18ba5bcd9020c 100644 (file)
@@ -24,7 +24,7 @@
                           const _type *b,                              \
                           void *ctx)                                   \
        {                                                               \
-               return _order_##_oname(a, b, int2ptr(0));               \
+               (void)ctx; return _order_##_oname(a, b, int2ptr(0));    \
        }                                                               \
        int _order_##_oname##_reverse(const void *a,                    \
                                      const void *b,                    \
@@ -36,6 +36,7 @@
                                     const _type *b,                    \
                                     void *ctx)                         \
        {                                                               \
+               (void)ctx;                                              \
                return _order_##_oname##_reverse(a, b, int2ptr(0));     \
        }                                                               \
        int order_##_oname##_noctx(const void *a,                       \
index ba63ca1ef605fd315f81948b6c5cdf7e95c18a55..3eed7aa6484b0cd372e728f3f868f80b878bc4c9 100644 (file)
@@ -12,7 +12,7 @@ typedef int item_t;
 typedef struct item item_t;
 #endif
 
-int main(int argc, char *argv[])
+int main(void)
 {
        total_order_cb(cb0, struct item, struct cmp_info *) = fancy_cmp;
        _total_order_cb cb1 = total_order_cast(fancy_cmp,
index 5a7126d87703c9291e885cf20562f7d766c7b5ff..595ffcbbab62c466239bb35e077a06a2fa9a3637 100644 (file)
@@ -12,7 +12,7 @@ typedef int ctx_t;
 typedef struct cmp_info ctx_t;
 #endif
 
-int main(int argc, char *argv[])
+int main(void)
 {
        total_order_cb(cb0, struct item, struct cmp_info *) = fancy_cmp;
        _total_order_cb cb1 = total_order_cast(fancy_cmp, struct item,
index 33a420422d14a77a48c42062541ec45afe548393..37cc4e4ea0cea49ec25641fc99c34f0528ba7d5b 100644 (file)
@@ -6,7 +6,7 @@
 
 #include "fancy_cmp.h"
 
-int main(int argc, char *argv[])
+int main(void)
 {
        total_order_cb(cb0, struct item, struct cmp_info *) = fancy_cmp;
        _total_order_cb cb1 = total_order_cast(fancy_cmp,
index be5ff3f2d53d8a303247dee7a087d3be8d2c6861..5a287c4cbcfc76013d7be533afab547b521c7132 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "fancy_cmp.h"
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct item item1 = {
                .value = 0,
index 4621d72fc3b94d78192a8eb33fb9bec60309a600..a560bfea05ccc4e53807dde67d0546c48b6f0246 100644 (file)
@@ -28,7 +28,8 @@
  *     char input[12];
  *
  *     if (argc == 2) {
- *             write(STDOUT_FILENO, "hello world\n", 12);
+ *             if (write(STDOUT_FILENO, "hello world\n", 12) != 12)
+ *                     exit(1);
  *             exit(0);
  *     }
  *     child = pipecmd(&outputfd, NULL, NULL, argv[0], "ignoredarg", NULL);
index e8aec15b4e7f62993489de618a445439ac06c8c7..32772a83bc7b69c96cff57747aa779771f2e7604 100644 (file)
@@ -122,7 +122,10 @@ pid_t pipecmdarr(int *fd_fromchild, int *fd_tochild, int *fd_errfromchild,
 
        child_errno_fail:
                err = errno;
-               write(execfail[1], &err, sizeof(err));
+               /* Gcc's warn-unused-result fail. */
+               if (write(execfail[1], &err, sizeof(err))) {
+                       ;
+               }
                exit(127);
        }
 
index ef95d34f39c7a145a2b0c3621c8c764ea65d140b..dc61dd27cbc1fbd46a06e73ad25d4c1bb6fb9848 100644 (file)
@@ -246,9 +246,14 @@ static bool check_with_child(struct ptr_valid_batch *batch,
                        return false;
        }
 
-       write(batch->to_child, &p, sizeof(p));
-       write(batch->to_child, &size, sizeof(size));
-       write(batch->to_child, &is_write, sizeof(is_write));
+       if (write(batch->to_child, &p, sizeof(p))
+           + write(batch->to_child, &size, sizeof(size))
+           + write(batch->to_child, &is_write, sizeof(is_write))
+           != sizeof(p) + sizeof(size) + sizeof(is_write)) {
+               finish_child(batch);
+               errno = EFAULT;
+               return false;
+       }
 
        if (read(batch->from_child, &ret, sizeof(ret)) != sizeof(ret)) {
                finish_child(batch);
index 6300a9bca9e5ed04c7f96c396654db257bd8e096..30170da92bf2f23b888e4e74b1aaf25d4d4dfdf0 100644 (file)
@@ -29,7 +29,7 @@
  *
  *     void (*cb)(void *opaque) = callback;
  *
- *     int main(int argc, char *argv[])
+ *     int main(void)
  *     {
  *             int val = 17;
  *
index 20c5e8454fd3b00be4a84acb5714dc178ba927a3..0210dff9bf51cc98e84f9f29e7ddadd80f6d95cb 100644 (file)
@@ -17,7 +17,7 @@
  *     #include <ccan/read_write_all/read_write_all.h>
  *
  *     #define BUFFER_SIZE 10
- *     int main(int argc, char *argv[])
+ *     int main(void)
  *     {
  *             char buffer[BUFFER_SIZE+1];
  *
index 29f81fc703e05f0b930a2a4136b7981dfc7aaa06..6e6588d4149a79351f04993bbc37470ab8d36626 100644 (file)
@@ -17,6 +17,7 @@ static int p2c[2], c2p[2];
 static void got_signal(int sig)
 {
        char c = 0;
+       (void)sig;
        if (write(p2c[1], &c, 1) == 1)
                sigcount++;
 }
@@ -24,7 +25,7 @@ static void got_signal(int sig)
 /* < PIPE_BUF *will* be atomic.  But > PIPE_BUF only *might* be non-atomic. */
 #define BUFSZ (1024*1024)
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char *buffer;
        char c = 0;
index e2baf48dfe79893a9729b749516ebcdd3704c61e..c789d6b7829b3b05243ce7ae9d6bd679cfc8735f 100644 (file)
@@ -19,6 +19,9 @@ static ssize_t write_return;
 
 static ssize_t test_write(int fd, const void *buf, size_t count)
 {
+       (void)fd;
+       (void)buf;
+
        if (write_return == 0) {
                errno = ENOSPC;
                return 0;
@@ -39,7 +42,7 @@ static ssize_t test_write(int fd, const void *buf, size_t count)
 
 #define BUFSZ 1024
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char *buffer;
 
index 251d999a83f47328ead2ca8720d9859f59f43d03..b579525faac18e1fa52096b2e9b6eff34a70b404 100644 (file)
  *
  *     int main(int argc, char *argv[])
  *     {
- *             if (argv[1] && streq(argv[1], "--verbose"))
+ *             if (argc > 1 && streq(argv[1], "--verbose"))
  *                     printf("verbose set\n");
- *             if (argv[1] && strstarts(argv[1], "--"))
+ *             if (argc > 1 && strstarts(argv[1], "--"))
  *                     printf("Some option set\n");
- *             if (argv[1] && strends(argv[1], "cow-powers"))
+ *             if (argc > 1 && strends(argv[1], "cow-powers"))
  *                     printf("Magic option set\n");
  *             return 0;
  *     }
index 74448c1b81af19024612331de56e3c4ff30b220a..8e0fd2e2f65216ffa750bdecc9d9f9e87894df7c 100644 (file)
@@ -4,7 +4,7 @@ struct s {
        int val;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct s
 #ifdef FAIL
index 930defffa0c231862679e42ddb851655cf5a93a1..5d9895822ccd96442a7b1391d87d558856f13cca 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check isalnum.
index 2005109829be36e1ea558e287b770d9fbb1cc663..33d365538aff0a28c6f5b7f36119363ab6d7ae71 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check isalpha.
index ee55e4997434c5cd4c11c01a0bd45d28af67d37d..3946e0b3b88a288606903756c53eaaf6d267d0e8 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check isascii.
index f4cb961d740d9dd0bc9b99825a3af51d3d50d848..e14b0d7e66ac1a8e0018233c709b7274e182a468 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF || !HAVE_ISBLANK
 #error We need typeof to check isblank.
index bc74146542f1b36ecefe1fb394bfb84254d4b571..f9abf1dc56e4d4464dd417b2c2586769a22ccf15 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check iscntrl.
index 71d1c714330f2cf9f363e46a3161a4e0f5c9e93c..a3ee439c631eb867a876c955169cb4be2119c03f 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check isdigit.
index ca3f9907e52087eefb75d6f40831f11c50b12e8e..8f5c456197ff33cb2e4fdeef9704702b2aefa43c 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check islower.
index 6432e41d2b7db9db5ddc0ecd35611fcc169e49d3..85ed028f60f1e99a4da8983e3f3df4800e5e88ad 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check isprint.
index 5d941fcba687a23863780acc6076479ba05bfcd8..09d4279a9344d4770d93eb9b689ea2639c344ab1 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check ispunct.
index bfee1f89f166614b603b9aec5c2315ad430a3af0..798cfcd470f82db076a0b37ff79375baad194344 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check isspace.
index 4cf9fd35785c37e40e1ea16529845886896381f8..56f5dee11b9512268bdc782d85069b8f10331fcd 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check isupper.
index 65e6006a885b029ae7cec620a44aebd652567e22..ea4d5269add225115a436092fc8184e3a45151a0 100644 (file)
@@ -3,6 +3,7 @@
 
 int main(int argc, char *argv[])
 {
+       (void)argc;
 #ifdef FAIL
 #if !HAVE_BUILTIN_TYPES_COMPATIBLE_P || !HAVE_TYPEOF
 #error We need typeof to check isxdigit.
index 74a7314d06b7807eb22c1f3865ac9586c7b83d0d..bdaf034abd1f3e0403ecc55a96458672908a5cc7 100644 (file)
@@ -1,7 +1,7 @@
 #define CCAN_STR_DEBUG 1
 #include <ccan/str/str.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
 #ifdef FAIL
 #if !HAVE_TYPEOF
index ba7d17e031985df303e0f23a85f1421bf4024578..57fba0ed58d152e640f27d2c40e912c765572271 100644 (file)
@@ -1,7 +1,7 @@
 #define CCAN_STR_DEBUG 1
 #include <ccan/str/str.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
 #ifdef FAIL
 #if !HAVE_TYPEOF
index deefef6542bd3bef6bee74b0bd5ba7309288f03c..7bd8ac22f13b83911971f747661fd08e40cdcfdf 100644 (file)
@@ -1,7 +1,7 @@
 #define CCAN_STR_DEBUG 1
 #include <ccan/str/str.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
 #ifdef FAIL
 #if !HAVE_TYPEOF
index ae6969c7b07c63bcfd7c7c4c83972398f25f8680..fa45bad8a6414bd7df108823e3b2adeecbb864dd 100644 (file)
@@ -4,7 +4,7 @@
 #include <ccan/tap/tap.h>
 #include <stdint.h>
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char str[1000];
        struct {
index 0f00ea320d2a67fbc8c65448f14017abbdb1a165..9917fe7111c5bac1ff34ba52b61854e4f7862a66 100644 (file)
@@ -21,7 +21,7 @@ static char *strdup_rev(const char *s)
        return ret;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        unsigned int i, j, n;
        char *strings[NUM_SUBSTRINGS * NUM_SUBSTRINGS];
index c128cc27b5c3cbe941cd5e72a4bef2ae2c043f91..eba8fe444ae78e1119e03644ab0f55d29d1d4d23 100644 (file)
  *     license_depends_compat FAIL
  *
  * Example:
+ * #include <ccan/compiler/compiler.h>
  * #include <ccan/strmap/strmap.h>
  * #include <stdio.h>
  *
- * static bool dump(const char *member, size_t value, void *unused)
+ * static bool dump(const char *member, size_t value, void *unused UNNEEDED)
  * {
  *     printf("%s at %zu. ", member, value);
  *     // true means keep going with iteration.
@@ -32,7 +33,7 @@
  *     STRMAP(size_t) map;
  *
  *     strmap_init(&map);
- *     for (i = 1; i < argc; i++)
+ *     for (i = 1; i < (size_t)argc; i++)
  *             // This only adds the first time for this arg.
  *             strmap_add(&map, argv[i], i);
  *
index 63bea95236af32ba1372c460151243bf3f5d7d66..dfd9dca73847db6e100dc2716d80b9b5b191469e 100644 (file)
@@ -5,7 +5,7 @@
 static bool found = false;
 
 /* Make sure const args work. */
-static bool find_string(const char *str, char *member, const char *cmp)
+static bool find_string(const char *str UNNEEDED, char *member, const char *cmp)
 {
        if (strcmp(member, cmp) == 0)
                found = true;
index d88eb55655c2bfe3737ca3fc510f8d3b43658bc9..6232d71b26135106016d22a01f84feee45c988ca 100644 (file)
@@ -15,7 +15,7 @@ static bool in_order(const char *index, char *value, unsigned int *count)
        return true;
 }
 
-static bool find_empty(const char *index, char *value, char *empty)
+static bool find_empty(const char *index, char *value UNNEEDED, char *empty)
 {
        if (index == empty)
                pass("Found empty entry!");
index 693824664802aebdeef970c4de29f23fb4fc0efb..fcb4f318a36ad77fdf1e7e8440de463b4f2d51cf 100644 (file)
@@ -37,7 +37,7 @@
  *     {
  *             char *b;
  *
- *             if (argv[1]) // Mangle in place.
+ *             if (argc > 1) // Mangle in place.
  *                     b = base(take(argv[1]));
  *             else
  *                     b = base("test/string");
index 0c8ca2a1d6ae5207e76fabb249f2737327c5595b..ba170fb3aad71261f59bc7cd71a7b6feb65b69b6 100644 (file)
@@ -15,7 +15,7 @@ static void *my_realloc(void *p, size_t len)
 #include <ccan/tap/tap.h>
 
 static int my_allocfail_called;
-static void my_allocfail(const void *p)
+static void my_allocfail(const void *p UNNEEDED)
 {
        my_allocfail_called++;
 }      
index 890cb2e767a638b346f90e8f5b6be76bd6db3b2c..5285c1632b403121a5e499efae30ab7eb7d561ef 100644 (file)
@@ -29,7 +29,7 @@
  * Example:
  *     #include <stdio.h>
  *     #include <err.h>
- *     #include <ccan/talloc/talloc.h>
+ *     #include <ccan/tal/tal.h>
  *
  *     // A structure containing a popened command.
  *     struct command {
index 68ad089b06f23d59e4ef318f0f107c76a9e50e87..056f10990b08111ce1ebdc6c66541c445d87c7d0 100644 (file)
@@ -18,6 +18,8 @@
  *     {
  *             char *file;
  *
+ *             if (argc > 2)
+ *                     err(1, "Takes 0 or 1 arguments");
  *             file = grab_file(NULL, argv[1]);
  *             if (!file)
  *                     err(1, "Could not read file %s", argv[1]);
index b258230e84b270b65b9669e58d5ff884a181a9a9..ddb5ca307a48e899fab560df273874ceab7e97b0 100644 (file)
@@ -10,7 +10,7 @@
 #include <ccan/tal/str/str.h>
 
 int
-main(int argc, char *argv[])
+main(void)
 {
        unsigned int    i;
        char            **split, *str;
index db2ad61454687f4f9ba3a4b885df4ff2e77f75cc..8e39e781d8569978517854646c21d87cdf2fa68a 100644 (file)
@@ -87,7 +87,7 @@
  *
  *     int main(int argc, char *argv[])
  *     {
- *             unsigned int i;
+ *             int i;
  *             const char **values;
  *
  *             // Initialize cache.
index c25d97e581c9ab7b2a5580835a682532a1401f24..7c8892d2b59fc882167d3b0b8a0a5a80f7d0c5c2 100644 (file)
@@ -15,7 +15,7 @@ struct link {
 
 static void linkable_notifier(tal_t *linkable,
                              enum tal_notify_type type,
-                             void *info)
+                             void *info UNNEEDED)
 {
        struct linkable *l = tal_parent(linkable);
        assert(type == TAL_NOTIFY_STEAL || type == TAL_NOTIFY_FREE);
index fdbb4f02e56dfa86f21b3e11020675a3718af8d6..e031fef2806d1d92faff4891b3b765b69880a3fc 100644 (file)
@@ -4,12 +4,12 @@
 #include <err.h>
 
 static unsigned int destroy_count = 0;
-static void destroy_obj(void *obj)
+static void destroy_obj(void *obj UNNEEDED)
 {
        destroy_count++;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char *linkable, *p1, *p2, *p3;
        void **voidpp;
index 803a0058dc1358534731da56eae68bc82ffac240..b7de3dd065e77528bc8f2f37079efbb7bc47720e 100644 (file)
@@ -38,7 +38,7 @@
  *             return retval;
  *     }
  *
- *     int main(int argc, char *argv[])
+ *     int main(void)
  *     {
  *             tal_t *tmp_ctx = tal_newframe();
  *             int *val = do_work();
index cb81c9e19df33a64eb0e6323810d3d3129d9ff7e..3037cfde2fba99fcf1e817c0117ed8b89909fee3 100644 (file)
@@ -20,6 +20,8 @@
  *             char *textfile;
  *             char **lines;
  *
+ *             if (argc > 2)
+ *                     errx(1, "Takes 0 or 1 arguments");
  *             // Grab lines in file.
  *             textfile = grab_file(NULL, argv[1]);
  *             if (!textfile)
index 0c1821331e6a733b7a43fe3491e19b9065947eb8..5147ca2d4667fc7cc6997c34c9e6fdc5fc113c85 100644 (file)
@@ -171,6 +171,7 @@ char *tal_strjoin(const void *ctx, char *strings[], const char *delim,
  *     {
  *             char *person, *input;
  *
+ *             (void)argc;
  *             // Join args and trim trailing space.
  *             input = tal_strjoin(NULL, argv+1, " ", STR_NO_TRAIL);
  *             if (tal_strreg(NULL, input,
index 9dfd00155a536873da4a1c7b4ea93f6b67070309..374ca03a1fed893f017cc89c632c13d41a2507ed 100644 (file)
@@ -6,7 +6,7 @@
 #include "helper.h"
 
 /* Empty format string: should still terminate! */
-int main(int argc, char *argv[])
+int main(void)
 {
        char *str;
        const char *fmt = "";
index d967354842c2ef083543061612e5143ed7701c8a..55e35fd4be8c6fb1a8033a311d1ff4d8c17ff001 100644 (file)
@@ -5,7 +5,7 @@
 #include <ccan/tap/tap.h>
 #include "helper.h"
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char *str, *copy;
 
index fa8a86c66e6127872b1313644e343dc1d05860c2..93b8602a3c1f8ab067c4406ece439db949ae6b5b 100644 (file)
@@ -14,7 +14,7 @@ static bool find_parent(tal_t *child, tal_t *parent)
        return false;
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
        void *ctx = tal_strdup(NULL, "toplevel");
        char *a, *b;
index 4b9cf1fb5581e2a1596733f098f1bbc33e3540b0..a59d940087cfc81e5a39566a51cfb8790934cb03 100644 (file)
@@ -10,7 +10,7 @@
 static const char *substrings[]
 = { "far", "bar", "baz", "b", "ba", "z", "ar", NULL };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        char **split, *str;
        void *ctx;
index 79476772c585564b7e0840f215b59d09844723f1..842059d031b76977d665b31f1aedd3259a86ff0f 100644 (file)
@@ -323,7 +323,7 @@ static struct name *add_name_property(struct tal_hdr *t, const char *name)
 }
 
 static struct children *add_child_property(struct tal_hdr *parent,
-                                          struct tal_hdr *child)
+                                          struct tal_hdr *child UNNEEDED)
 {
        struct children *prop = allocate(sizeof(*prop));
        if (prop) {
index a166be3f6520a8795ea2c7bd916f0bfdf2a9cada..97cba9f6848d37d54594f666292bb82f21dbbce3 100644 (file)
@@ -30,7 +30,7 @@ static void nofail_on_error(const char *msg)
        err_count++;
 }
 
-static void destroy_p(void *p)
+static void destroy_p(void *p UNNEEDED)
 {
 }
 
index 873548889e91472013c3901b92bae8f01ae4e25c..7183f7c5b5a3daaff2e543d35e9f25c6d33366a2 100644 (file)
@@ -24,7 +24,7 @@ static void destroy_child(char *p)
        destroy_count++;
 }
 
-static void destroy_inc(char *p)
+static void destroy_inc(char *p UNNEEDED)
 {
        destroy_count++;
 }
index 29aa8c6f49dacf462300f41eda207b414c29ea95..f21264748d40a056a7e1ae5ed1d0976190d86e5a 100644 (file)
@@ -2,7 +2,7 @@
 #include <ccan/tal/tal.c>
 #include <ccan/tap/tap.h>
 
-static void destroy_errno(char *p)
+static void destroy_errno(char *p UNNEEDED)
 {
        errno = ENOENT;
 }
index b57c902e80ba9c3b7ec6a9ea285b4c0be0b40419..3820444f86f8245c38ffb9817f8d6cb38de506d1 100644 (file)
@@ -20,7 +20,7 @@ static void *my_realloc(void *old, size_t size)
        return new;
 }
 
-static void notify1(char *p, enum tal_notify_type notify, void *info)
+static void notify1(char *p UNNEEDED, enum tal_notify_type notify, void *info)
 {
        ok1(ctx == ctx);
        ok1(notify == expect);
@@ -31,7 +31,9 @@ static void notify1(char *p, enum tal_notify_type notify, void *info)
        notified1++;
 }
 
-static void notify2(char *ctx, enum tal_notify_type notify, void *info)
+static void notify2(char *ctx UNNEEDED,
+                   enum tal_notify_type notify UNNEEDED,
+                   void *info UNNEEDED)
 {
        notified2++;
 }
index d975398b4ba39b9e55ef35a57b18537aa514bbc8..d1919c1cceefcc65702fd5bf65a2ef015c30f7d7 100644 (file)
@@ -4,7 +4,7 @@
 
 static int error_count;
 
-static void my_error(const char *msg)
+static void my_error(const char *msg UNNEEDED)
 {
        error_count++;
 }
index 8fdfc064abb7eca68d06a18d0f4b00f7b9927df3..ebcd811192cfc9e2c39f09e9aff914ce25767ed0 100644 (file)
@@ -31,7 +31,7 @@ static void *my_realloc(void *old, size_t new_size)
 
 #define NUM_ALLOCS 1000
 
-static void destroy_p(void *p)
+static void destroy_p(void *p UNNEEDED)
 {
 }
 
index a67e2090766d3217d0665f815314bb6ccfcdb143..44645a7ec6d417875ceed8910915efea3a0d2193 100644 (file)
@@ -22,7 +22,7 @@ struct info_tcon {
        TCON(TCON_CONTAINER(concan, struct outer, inner));
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct info_tcon info;
        struct outer ovar;
index 0226b68e9f01b9095ce01a50dec0092360407c62..19ba5bdcc915d22851009a630b4bda32dd85f242 100644 (file)
@@ -17,7 +17,7 @@ struct info_base {
        char *infop;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        TCON_WRAP(struct info_base,
                  TCON_CONTAINER(concan, struct outer, inner)) info;
index 6cad734c5f57647568ff652e3e6b87488b6c7989..e41984d9f082e85b00ea60a6684ce25bd481f085 100644 (file)
@@ -22,7 +22,7 @@ struct info_tcon {
        TCON(TCON_CONTAINER(concan, struct outer, inner));
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct info_tcon info;
        struct outer ovar;
index c73123cacd2c8639e88cfda48591c515fb0f3276..3564ab0c480320c51bb810c36dedff76a8cf32b9 100644 (file)
@@ -17,7 +17,7 @@ struct info_base {
        char *infop;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        TCON_WRAP(struct info_base,
                  TCON_CONTAINER(concan, struct outer, inner)) info;
index 97473c8caeb89e2e7455aadabac0482b56eea4d3..9185225a9361903e25e86ce616e31da0e502e577 100644 (file)
@@ -22,7 +22,7 @@ struct info_tcon {
        TCON(TCON_CONTAINER(concan, struct outer, inner));
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct info_tcon info;
        struct outer ovar;
index 6930b436d984c5fe8e833b9cb81efd26304a0df9..958e5c8b3dca47c67c1f23aa25fe9fc29e759e90 100644 (file)
@@ -17,7 +17,7 @@ struct info_base {
        char *infop;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        TCON_WRAP(struct info_base,
                  TCON_CONTAINER(concan, struct outer, inner)) info;
index 838ce9b17696210669b5441e780c5244d597c07a..b11e8efcd8bc6eac7eda019b0881e24f17fddacc 100644 (file)
@@ -22,7 +22,7 @@ struct info_tcon {
        TCON(TCON_CONTAINER(concan, struct outer, inner));
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct info_tcon info;
        struct outer ovar;
index 0d7b367b99305700569e22a583ffb012078c5613..d33ce1e5216a2e6cac2c9856b2d158800862320f 100644 (file)
@@ -17,7 +17,7 @@ struct info_base {
        char *infop;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        TCON_WRAP(struct info_base,
                  TCON_CONTAINER(concan, struct outer, inner)) info;
index 3df0333ca047422eef3d83de1ea3b68063ab3df5..0d83ba3fa185cde98b4a83fed0ec2494dfe7136b 100644 (file)
@@ -10,7 +10,7 @@ struct int_and_charp_container {
        TCON(int *tc1; char *tc2);
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct int_and_charp_container icon;
 #ifdef FAIL
index f24cb01b8d791067a25b5f208a347172f4bf8b16..c9255791a1a5981bca55fc521468827a3d2d24c9 100644 (file)
@@ -5,7 +5,7 @@ struct container {
        void *p;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        TCON_WRAP(struct container,
                  int *tc1; char *tc2) icon;
index 26da13c3e0b9fe256a46acc21461d3f5e7b27dcf..96010e6cc51277038610d49ea8f6097e1fb35b60 100644 (file)
@@ -5,7 +5,7 @@ struct container {
        void *p;
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        TCON_WRAP(struct container, int *canary) icon;
 #ifdef FAIL
index 683bbd62ffdefb85434b04c3fa716dbd78d30a16..b17d9d2e556f5224f077bc5309db5843d71435af 100644 (file)
@@ -10,7 +10,7 @@ struct int_container {
        TCON(int *canary);
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct int_container icon;
 #ifdef FAIL
index a8347f7aa8f5c302483800b671b8050cd8e12642..8afacabccc9594e8483cf9db4e4debe6f385fea8 100644 (file)
@@ -22,7 +22,7 @@ struct info_tcon {
        TCON(TCON_CONTAINER(fi, struct outer, inner));
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        /* Const should work! */
        const struct outer *ovar = NULL;
index 64ccc136ea53ed86a2fc55ba839862bdbb6da72c..9c4bf9ac87d603d74b64448d043e4ff80330a6e2 100644 (file)
@@ -16,7 +16,7 @@ struct charp_and_int_container {
        TCON(int tc1; char *tc2);
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct int_container icon;
        struct charp_and_int_container cicon;
index d9c911e6d0dba5d0c2e6af802bcc322aa0a2c0ae..9620bcbd3d13a65ac9090b8813241582ee1dd1f3 100644 (file)
@@ -26,7 +26,7 @@ struct offs_container {
             TCON_VALUE(off2, offsetof(struct other_struct, x2)));
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct val_container valcon;
        struct offs_container offscon;
index 694a53b533d87db6478dda4557d77c2b206e1ad6..442ca6599938b2877b5615fc0bf036b26c2e1c6f 100644 (file)
@@ -15,6 +15,7 @@ int main(int argc, char *argv[])
        struct void_container vcon;
        TCON_WRAP(struct container, void *canary) vconw;
 
+       (void)argc;
        tcon_check(&vcon, canary, NULL)->raw.p = NULL;
        tcon_check(&vcon, canary, argv[0])->raw.p = NULL;
        tcon_check(&vcon, canary, main)->raw.p = NULL;
index f3fe2c6f8a1a09b4f7d3b2b9f6aee5f285e1d56f..6ba5f4c1458a793879e9a76cffa2448235f06bae 100644 (file)
@@ -23,6 +23,7 @@ int main(int argc, char *argv[])
        TCON_WRAP(struct container, int tc) iconw;
        TCON_WRAP(struct container, int tc1; char *tc2) ciconw;
 
+       (void)argc;
        tcon_check(&icon, tc, 7)->raw.p = NULL;
        tcon_check(&cicon, tc1, 7)->raw.p = argv[0];
        tcon_check(&cicon, tc2, argv[0])->raw.p = argv[0];
index 88bb2a1c53cb0d185e859d9b51f5dcb326d30388..c08bad5c840aa21642e71a1f46af2fa7e011ff38 100644 (file)
@@ -28,7 +28,7 @@ struct info_tcon {
             TCON_CONTAINER(fi2, struct outer0, inner));
 };
 
-int main(int argc, char *argv[])
+int main(void)
 {
        struct info_tcon info;
        TCON_WRAP(struct info_base,
index 0d5cfef61fc018aa4001cb125cfa585bac9d1515..3493e5ac77ccbce792e436fe3b6546d24b73b2f7 100644 (file)
@@ -4,7 +4,7 @@
 
 typedef TCON_WRAP(int, char *canary) canaried_int;
 
-int main(int argc, char *argv[])
+int main(void)
 {
        canaried_int ci = TCON_WRAP_INIT(0);
 
index 3c2e282fd4b4b40e47962066b6c45d6ef018ffc7..c134afc3ec1ac655e8913d361815cebbffd9597c 100644 (file)
@@ -17,10 +17,11 @@ void abort(void)
 int main(void)
 {
        struct timeabs t1, t2, epoch = { { 0, 0 } };
+       struct timemono t1m, t2m;
        struct timerel t3, t4, zero = { { 0, 0 } };
        int fds[2];
 
-       plan_tests(64);
+       plan_tests(69);
 
        /* Test time_now */
        t1 = time_now();
@@ -43,6 +44,21 @@ int main(void)
        ok1(timerel_eq(t3, t3));
        ok1(!timerel_eq(t3, zero));
 
+       /* Test time_mono */
+       t1m = time_mono();
+       t2m = time_mono();
+
+       ok1(!time_less_(t2m.ts, t1m.ts));
+
+       t3.ts.tv_sec = 1;
+       t3.ts.tv_nsec = 0;
+
+       ok1(time_less(timemono_between(t2m, t1m), t3));
+       ok1(time_less(timemono_since(t1m), t3));
+
+       ok1(timemono_add(t1m, t3).ts.tv_sec == t1m.ts.tv_sec + 1);
+       ok1(timemono_add(t2m, t3).ts.tv_nsec == t2m.ts.tv_nsec);
+
        /* Make sure t2 > t1. */
        t3.ts.tv_sec = 0;
        t3.ts.tv_nsec = 1;
@@ -156,7 +172,8 @@ int main(void)
        ok1(t3.ts.tv_sec == 2);
        ok1(t3.ts.tv_nsec == 147483648);
 
-       pipe(fds);
+       if (pipe(fds) != 0)
+               exit(1);
 
        fflush(stdout);
        switch (fork()) {
index ed70f3dbb5bddc19e15ed460c250f43fac236456..2da492d441b0160731ce4f431d31031c9b7e67a3 100644 (file)
@@ -7,7 +7,7 @@ int main(void)
        struct timemono t1, t2;
        struct timerel t3;
 
-       plan_tests(2);
+       plan_tests(5);
 
        /* Test time_mono */
        t1 = time_mono();
@@ -18,7 +18,11 @@ int main(void)
        t3.ts.tv_sec = 1;
        t3.ts.tv_nsec = 0;
 
-       ok1(time_less(timemono_between(t1, t2), t3));
+       ok1(time_less(timemono_between(t2, t1), t3));
+       ok1(time_less(timemono_since(t1), t3));
+
+       ok1(timemono_add(t1, t3).ts.tv_sec == t1.ts.tv_sec + 1);
+       ok1(timemono_add(t2, t3).ts.tv_nsec == t2.ts.tv_nsec);
 
        return exit_status();
 }
index d0542f5654e86f06e69bc40c530ce0c989643e92..27f0d52a30987df194ea710e8f4af6a4cd74dfc4 100644 (file)
@@ -33,7 +33,7 @@ struct timemono time_mono(void)
 #else /* Best we can do */
        ret.ts = time_now().ts;
 #endif /* !HAVE_TIME_MONOTONIC */
-       return ret;
+       return TIMEMONO_CHECK(ret);
 }
 
 struct timerel time_divide(struct timerel t, unsigned long div)
@@ -128,3 +128,11 @@ struct timeabs timeabs_check(struct timeabs t, const char *abortstr)
        ret.ts = time_check_(t.ts, abortstr);
        return ret;
 }
+
+struct timemono timemono_check(struct timemono t, const char *abortstr)
+{
+       struct timemono ret;
+
+       ret.ts = time_check_(t.ts, abortstr);
+       return ret;
+}
index 5c916f4c4c2ef04b9648791d862bb3eea731a6cd..70ebdc9a7751ca5be434329421618c58f177c9c7 100644 (file)
@@ -22,10 +22,13 @@ struct timespec {
        timerel_check((t), __FILE__ ":" stringify(__LINE__) " (" stringify(t) ") ")
 #define TIMEABS_CHECK(t) \
        timeabs_check((t), __FILE__ ":" stringify(__LINE__) " (" stringify(t) ") ")
+#define TIMEMONO_CHECK(t) \
+       timemono_check((t), __FILE__ ":" stringify(__LINE__) " (" stringify(t) ") ")
 #else
 #define TIME_CHECK(t) (t)
 #define TIMEREL_CHECK(t) (t)
 #define TIMEABS_CHECK(t) (t)
+#define TIMEMONO_CHECK(t) (t)
 #endif
 
 /**
@@ -95,7 +98,7 @@ struct timerel timerel_check(struct timerel in, const char *abortstr);
 
 /**
  * timeabs_check - check if an absolute time is malformed.
- * @in: the relative time to check (returned)
+ * @in: the absolute time to check (returned)
  * @abortstr: the string to print to stderr before aborting (if set).
  *
  * This can be used to make sure a time isn't negative and doesn't
@@ -113,6 +116,26 @@ struct timerel timerel_check(struct timerel in, const char *abortstr);
  */
 struct timeabs timeabs_check(struct timeabs in, const char *abortstr);
 
+/**
+ * timemono_check - check if a monotonic time is malformed.
+ * @in: the monotonic time to check (returned)
+ * @abortstr: the string to print to stderr before aborting (if set).
+ *
+ * This can be used to make sure a time isn't negative and doesn't
+ * have a tv_nsec >= 1000000000.  If it is, and @abortstr is non-NULL,
+ * that will be printed and abort() is called.  Otherwise, if
+ * @abortstr is NULL then the returned timemono will be normalized and
+ * tv_sec set to 0 if it was negative.
+ *
+ * Note that if ccan/time is compiled with DEBUG, then it will call this
+ * for all passed and returned times.
+ *
+ * Example:
+ *     printf("Now is %lu seconds since mono start\n",
+ *             (long)timemono_check(time_mono(), "time_mono failed?").ts.tv_sec);
+ */
+struct timemono timemono_check(struct timemono in, const char *abortstr);
+
 /**
  * time_now - return the current time
  *
@@ -127,7 +150,7 @@ struct timeabs time_now(void);
  * This value is only really useful for measuring time intervals.
  *
  * See also:
- *     time_since()
+ *     timemono_since()
  */
 struct timemono time_mono(void);
 
@@ -231,6 +254,32 @@ static inline bool timeabs_eq(struct timeabs a, struct timeabs b)
                && a.ts.tv_nsec == b.ts.tv_nsec;
 }
 
+/**
+ * timemono_eq - is a equal to b?
+ * @a: one monotonic time.
+ * @b: another monotonic time.
+ *
+ * Example:
+ *     #include <sys/types.h>
+ *     #include <sys/wait.h>
+ *
+ *     // Can we fork in under a nanosecond?
+ *     static bool fast_fork(void)
+ *     {
+ *             struct timemono start = time_mono();
+ *             if (fork() != 0) {
+ *                     exit(0);
+ *             }
+ *             wait(NULL);
+ *             return timemono_eq(start, time_mono());
+ *     }
+ */
+static inline bool timemono_eq(struct timemono a, struct timemono b)
+{
+       return TIMEMONO_CHECK(a).ts.tv_sec == TIMEMONO_CHECK(b).ts.tv_sec
+               && a.ts.tv_nsec == b.ts.tv_nsec;
+}
+
 /**
  * timerel_eq - is a equal to b?
  * @a: one relative time.
@@ -320,6 +369,17 @@ static inline struct timerel timemono_between(struct timemono recent,
        return t;
 }
 
+/**
+ * timemono_since - elapsed monotonic time since @old
+ * @old: a monotonic time from the past.
+ */
+static inline struct timerel timemono_since(struct timemono old)
+{
+       struct timemono now = time_mono();
+
+       return timemono_between(now, TIMEMONO_CHECK(old));
+}
+
 /**
  * timeabs_sub - subtract a relative time from an absolute time
  * @abs: the absolute time.
@@ -377,6 +437,28 @@ static inline struct timeabs timeabs_add(struct timeabs a, struct timerel b)
        return t;
 }
 
+/**
+ * timemono_add - add a relative to a monotonic time
+ * @a: the monotonic time.
+ * @b: a relative time.
+ *
+ * The times must not overflow, or the results are undefined.
+ *
+ * Example:
+ *     // We do one every second.
+ *     static struct timemono next_timem(void)
+ *     {
+ *             return timemono_add(time_mono(), time_from_msec(1000));
+ *     }
+ */
+static inline struct timemono timemono_add(struct timemono a, struct timerel b)
+{
+       struct timemono t;
+
+       t.ts = time_add_(a.ts, b.ts);
+       return t;
+}
+
 /**
  * timerel_add - add two relative times
  * @a: one relative time.
index 420aba1145ad46372d6a34172c5a837d32800a2b..9f5ec7a22809efa6de4d3806820f1b1ed78b2485 100644 (file)
  *             struct timer *t;
  *             struct timed_string *s;
  *
- *             timers_init(&timers, time_now());
+ *             (void)argc;
+ *             timers_init(&timers, time_mono());
  *             list_head_init(&strings);
  *
  *             while (argv[1]) {
  *                     s = malloc(sizeof(*s));
  *                     s->string = argv[1];
- *                     timer_add(&timers, &s->timer,
- *                               timeabs_add(time_now(),
- *                                           time_from_msec(atol(argv[2]))));
+ *                     timer_addrel(&timers, &s->timer,
+ *                                  time_from_msec(atol(argv[2])));
  *                     list_add_tail(&strings, &s->node);
  *                     argv += 2;
  *             }
  *
  *             while (!list_empty(&strings)) {
- *                     struct timeabs now = time_now();
+ *                     struct timemono now = time_mono();
  *                     list_for_each(&strings, s, node)
  *                             printf("%s", s->string);
  *                     while ((t = timers_expire(&timers, now)) != NULL) {
index e97bf781ddcc82e644d82165b9d7d373deee351c..9ad44b7e347608f9040310a40292271669b76a80 100644 (file)
@@ -20,7 +20,7 @@ int main(void)
        struct timer t;
        uint64_t diff;
        unsigned int i;
-       struct timeabs epoch = { { 0, 0 } };
+       struct timemono epoch = { { 0, 0 } };
 
        /* This is how many tests you plan to run */
        plan_tests(2 + (18 + (MAX_ORD - 4) * 3) * (18 + (MAX_ORD - 4) * 3));
@@ -38,7 +38,7 @@ int main(void)
                for (timers.base = 0;
                     timers.base < (1ULL << MAX_ORD)+2;
                     timers.base = next(timers.base)) {
-                       timer_add(&timers, &t, grains_to_time(timers.base + diff));
+                       timer_addmono(&timers, &t, grains_to_time(timers.base + diff));
                        ok1(timers_check(&timers, NULL));
                        timer_del(&timers, &t);
                }
index ee9660481ea92655618f30eeb7f0b7fd6328e6d5..9fd735b9edfaf420e1da7769d3fc26fb20b36d94 100644 (file)
@@ -7,25 +7,25 @@
 static void new_timer(struct timers *timers, unsigned long nsec)
 {
        struct timer *timer;
-       struct timeabs when;
+       struct timemono when;
 
        timer = malloc(sizeof(*timer));
        timer_init(timer);
        when.ts.tv_sec = 0; when.ts.tv_nsec = nsec;
-       timer_add(timers, timer, when);
+       timer_addmono(timers, timer, when);
 }
 
 static void update_and_expire(struct timers *timers)
 {
-       struct timeabs when;
+       struct timemono when;
 
        timer_earliest(timers, &when);
        free(timers_expire(timers, when));
 }
 
-int main(int argc, char *argv[])
+int main(void)
 {
-       struct timeabs when;
+       struct timemono when;
        struct timers timers;
 
        plan_tests(7);
index c2f32976165f456fe665b41be4ecbc47116ca4df..02e98ff9288dfa9f6d295c1a56b153e865a31db4 100644 (file)
@@ -5,9 +5,9 @@
 #include <ccan/tap/tap.h>
 
 /* This is the original pre-cut-down dump. */
-int main(int argc, char *argv[])
+int main(void)
 {
-       struct timeabs when;
+       struct timemono when;
        struct timers timers;
        struct timer *timer;
 
@@ -19,1611 +19,1611 @@ int main(int argc, char *argv[])
        when.ts.tv_sec = 0; when.ts.tv_nsec = 138000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 199000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 82000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 118000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 168000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 108000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 46000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 18000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 163000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 58000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 113000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 143000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 143000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 58000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 100000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 164000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 177000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 156000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 178000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 139000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 110000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 56000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 198000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 207000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 59000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 200000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 113000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 43000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 173000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 107000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 63000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 102000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 96000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 135000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 162000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 206000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 185000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 198000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 167000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 139000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 46000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 70000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 24000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 131000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 70000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 114000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 38000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 37000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 60000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 158000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 166000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 112000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 204000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 107000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 109000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 53000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 49000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 12000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 38000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 13000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 110000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 91000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 57000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 148000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 169000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 161000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 145000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 144000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 149000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 102000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 25000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 137000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 114000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 39000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 59000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 174000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 95000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 39000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 153000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 145000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 187000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 110000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 48000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 181000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 159000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 99000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 177000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 198000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 102000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 205000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 153000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 154000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 39000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 200000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 92000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 150000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 151000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 179000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 36000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 42000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 71000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 52000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 170000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 127000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 33000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 171000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 91000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 119000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 200000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 35000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 206000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 177000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 87000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 44000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 100000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 36000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 134000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 67000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 24000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 178000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 15000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 168000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 122000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 196000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 110000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 156000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 136000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 204000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 126000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 162000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 188000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 139000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 156000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 100000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 57000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 180000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 61000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 90000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 41000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 203000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 67000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 37000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 122000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 96000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 24000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 165000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 122000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 100000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 22000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 89000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 20000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 179000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 199000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 84000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 165000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 51000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 30000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 43000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 197000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 98000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 148000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 176000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 180000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 94000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 66000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 27000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 16000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 70000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 59000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 47000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 15000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 69000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 27000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 128000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 155000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 193000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 83000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 68000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 83000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 47000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 99000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 93000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 17000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 88000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 167000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 124000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 81000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 139000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 110000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 69000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 28000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 48000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 35000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 198000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 84000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 43000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 167000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 91000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 103000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 168000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 80000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 109000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 27000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 49000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 179000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 173000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 32000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 204000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 183000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 57000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 41000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 72000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 92000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 200000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 102000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 201000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 67000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 125000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 131000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 167000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 184000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 101000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 157000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 161000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 41000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 31000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 147000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 150000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 64000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 40000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 108000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 135000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 91000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 126000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 126000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 12000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 41000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 149000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 206000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 14000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 148000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 190000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 28000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 31000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 180000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 72000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 22000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 189000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 187000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add");
        when.ts.tv_sec = 0; when.ts.tv_nsec = 95000000;
        timer = malloc(sizeof(*timer));
        timer_init(timer);
-       timer_add(&timers, timer, when); timers_check(&timers, "add");
+       timer_addmono(&timers, timer, when); timers_check(&timers, "add&quo