From 9a0439a3b813613cb3e5b476c49426eba365c2a6 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Mon, 23 Oct 2017 07:10:55 -0400 Subject: mq_tree_foreach*(): Accept only one user data argument And update MqNotebook. The va_copy()s didn't seem to work. va_arg() in MqNotebook's find_node_compare() returned garbage, preventing the node from being found and causing the assertion in find_node() (as called by mq_notebook_insert_sibling() and mq_notebook_insert_child()) to fail. --- diff --git a/src/notebook.c b/src/notebook.c index 5124d7b..305a2da 100644 --- a/src/notebook.c +++ b/src/notebook.c @@ -41,6 +41,7 @@ struct _MqNotebook { GtkNotebook parent_instance; MqWindow *window; MqTabTree *tree; + MqTabPage *find_page; MqTabTree *found_node; MqTabPage *current_page; }; @@ -175,15 +176,13 @@ mq_notebook_new(MqWindow *window) } static gboolean -find_node_compare(MqTree *node, va_list ap) +find_node_compare(MqTree *node, gpointer user_data) { MqNotebook *notebook; - MqTabPage *page; - notebook = va_arg(ap, MqNotebook *); - page = va_arg(ap, MqTabPage *); + notebook = MQ_NOTEBOOK(user_data); - if (MQ_TAB_TREE(node)->page == page) { + if (MQ_TAB_TREE(node)->page == notebook->find_page) { notebook->found_node = MQ_TAB_TREE(node); return MQ_TREE_STOP; } else { @@ -194,9 +193,10 @@ find_node_compare(MqTree *node, va_list ap) static void find_node(MqNotebook *notebook, MqTabPage *page) { + notebook->find_page = page; notebook->found_node = NULL; - mq_tree_foreach(MQ_TREE(notebook->tree), find_node_compare, notebook, - page); + mq_tree_foreach(MQ_TREE(notebook->tree), find_node_compare, notebook); + notebook->find_page = NULL; g_assert(notebook->found_node); } diff --git a/src/tree.c b/src/tree.c index 4d989b2..9b2c22b 100644 --- a/src/tree.c +++ b/src/tree.c @@ -148,34 +148,28 @@ mq_tree_seek(MqTree *node, gint offset) } static gboolean -foreach(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), va_list ap) +foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data) { - va_list aq; gboolean ret; ret = MQ_TREE_CONTINUE; for (; node; node = node->next) { /* XXX: Warning: Does not skip root node */ - va_copy(ap, aq); - ret = cb(node, aq); - va_end(aq); + ret = cb(node, user_data); if (ret == MQ_TREE_STOP) { break; } if (node->first_child) { - va_copy(ap, aq); - ret = foreach(node->first_child, cb, aq); - va_end(aq); + ret = foreach(node->first_child, cb, user_data); if (ret == MQ_TREE_STOP) { break; } } if (node->parent && node->parent->next) { - va_copy(ap, aq); - ret = foreach(node->parent->next, cb, aq); - va_end(aq); + ret = foreach(node->parent->next, cb, user_data); if (ret == MQ_TREE_STOP) { break; } @@ -186,27 +180,21 @@ foreach(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), va_list ap) } void -mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), ...) +mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data) { - va_list ap; - - va_start(ap, cb); - foreach(node->root->first_child, cb, ap); - va_end(ap); + foreach(node->root->first_child, cb, user_data); } static gboolean -foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), - va_list ap) +foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data) { - va_list aq; gboolean ret; ret = MQ_TREE_CONTINUE; for (node = node->first_child; node; node = node->next) { - va_copy(ap, aq); - ret = cb(node, aq); - va_end(aq); + ret = cb(node, user_data); if (ret == MQ_TREE_STOP) { break; } @@ -216,12 +204,8 @@ foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), } void -mq_tree_foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), - ...) +mq_tree_foreach_child(MqTree *node, + gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) { - va_list ap; - - va_start(ap, cb); - foreach_child(node->root->first_child, cb, ap); - va_end(ap); + foreach_child(node->root->first_child, cb, user_data); } diff --git a/src/tree.h b/src/tree.h index 3d2c113..70e24d5 100644 --- a/src/tree.h +++ b/src/tree.h @@ -74,11 +74,12 @@ MqTree * mq_tree_seek(MqTree *node, gint offset); void -mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), ...); +mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data); void -mq_tree_foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), - ...); +mq_tree_foreach_child(MqTree *node, + gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data); G_END_DECLS -- cgit v0.9.1