From ec249526ef406db942067c274415d17fb923c2cc Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Wed, 25 Oct 2017 12:36:41 -0400 Subject: MqTree: Fix width of pointers in debugging output And modify configure.ac to search for logl() and add -lm to LIBS. --- diff --git a/configure.ac b/configure.ac index 9d82351..e6ff630 100644 --- a/configure.ac +++ b/configure.ac @@ -69,6 +69,8 @@ AC_ARG_ENABLE( [enable_debug=no]) if test "x${enable_debug}" = 'xyes'; then + AC_SEARCH_LIBS([logl], [m], [], + [AC_MSG_ERROR([unable to find the logl() function])]) AC_DEFINE([MQ_TREE_DEBUG], [1], [Define to 1 to enable tree debugging.]) else AC_DEFINE([MQ_TREE_DEBUG], [0], [Define to 1 to enable tree debugging.]) diff --git a/src/tree.c b/src/tree.c index 61db6f6..1363098 100644 --- a/src/tree.c +++ b/src/tree.c @@ -31,6 +31,10 @@ #if MQ_TREE_DEBUG +#include + +#define PRIWxPTR ((int) (logl(UINTPTR_MAX) / logl(16))) + static void debug_print_tree_recurse(MqTree *node, gsize indent) { @@ -40,15 +44,16 @@ debug_print_tree_recurse(MqTree *node, gsize indent) for (i = 0; i < indent; ++i) { g_print("\t"); } - g_print("\t0x%" PRIxPTR " (size %d, position %d, " - "parent 0x%" PRIxPTR ", " - "siblings 0x%" PRIxPTR " and 0x%" PRIxPTR ", " - "children 0x%" PRIxPTR " to 0x%" PRIxPTR ")\n", - (uintptr_t) node, node->size, node->position, - (uintptr_t) node->parent, - (uintptr_t) node->prev, (uintptr_t) node->next, - (uintptr_t) node->first_child, - (uintptr_t) node->last_child); + g_print("\t0x%0*" PRIxPTR " (size %d, position %d, " + "parent 0x%0*" PRIxPTR ", " + "siblings 0x%0*" PRIxPTR " and 0x%0*" PRIxPTR ", " + "children 0x%0*" PRIxPTR " to 0x%0*" PRIxPTR ")\n", + PRIWxPTR, (uintptr_t) node, node->size, node->position, + PRIWxPTR, (uintptr_t) node->parent, + PRIWxPTR, (uintptr_t) node->prev, + PRIWxPTR, (uintptr_t) node->next, + PRIWxPTR, (uintptr_t) node->first_child, + PRIWxPTR, (uintptr_t) node->last_child); if (node->first_child) { debug_print_tree_recurse(node->first_child, indent + 1); @@ -59,7 +64,7 @@ debug_print_tree_recurse(MqTree *node, gsize indent) static void debug_print_tree(const gchar *msg, MqTree *node) { - g_print("%s 0x%" PRIxPTR ", ", msg, (uintptr_t) node); + g_print("%s 0x%0*" PRIxPTR ", ", msg, PRIWxPTR, (uintptr_t) node); node = node->root; g_print("new tree (size %d):\n", node->size); debug_print_tree_recurse(node, 0); @@ -68,13 +73,14 @@ debug_print_tree(const gchar *msg, MqTree *node) static void debug_print_node(MqTree *node) { - g_print("\t0x%" PRIxPTR "\n", (uintptr_t) node); + g_print("\t0x%0*" PRIxPTR "\n", PRIWxPTR, (uintptr_t) node); } static void debug_print_head(const gchar *head, MqTree *node) { - g_print("%s, starting at 0x%" PRIxPTR "\n", head, (uintptr_t) node); + g_print("%s, starting at 0x%0*" PRIxPTR "\n", + head, PRIWxPTR, (uintptr_t) node); } #else /* MQ_TREE_DEBUG */ -- cgit v0.9.1