From c7a874b8d6375c6787afca1d68b16de5cd2c9ad4 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Wed, 4 Nov 2020 20:00:30 +0200 Subject: [PATCH] lib: convert threader/container to c++ Did change the code much, but it's now compiled as c++ --- lib/Makefile.am | 8 ++++---- lib/{mu-container.c => mu-container.cc} | 10 +++++++--- lib/{mu-container.h => mu-container.hh} | 25 ++++++++++--------------- lib/mu-msg-iter.cc | 2 +- lib/{mu-threader.c => mu-threader.cc} | 12 ++++++------ lib/{mu-threader.h => mu-threader.hh} | 15 ++++----------- lib/test-mu-container.cc | 7 +------ lib/test-mu-maildir.cc | 8 ++++---- lib/utils/test-command-parser.cc | 12 ++++++++---- mu/mu-cmd-find.cc | 2 +- 10 files changed, 46 insertions(+), 55 deletions(-) rename lib/{mu-container.c => mu-container.cc} (98%) rename lib/{mu-container.h => mu-container.hh} (94%) rename lib/{mu-threader.c => mu-threader.cc} (97%) rename lib/{mu-threader.h => mu-threader.hh} (87%) diff --git a/lib/Makefile.am b/lib/Makefile.am index 5e31e1c7..f7bc4ca2 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -63,8 +63,8 @@ libmu_la_SOURCES= \ mu-bookmarks.h \ mu-contacts.cc \ mu-contacts.hh \ - mu-container.c \ - mu-container.h \ + mu-container.cc \ + mu-container.hh \ mu-data.hh \ mu-flags.c \ mu-flags.h \ @@ -100,8 +100,8 @@ libmu_la_SOURCES= \ mu-server.hh \ mu-store.cc \ mu-store.hh \ - mu-threader.c \ - mu-threader.h \ + mu-threader.cc \ + mu-threader.hh \ mu-tokenizer.cc \ mu-tokenizer.hh \ mu-tree.hh \ diff --git a/lib/mu-container.c b/lib/mu-container.cc similarity index 98% rename from lib/mu-container.c rename to lib/mu-container.cc index a7e07e34..c31c9298 100644 --- a/lib/mu-container.c +++ b/lib/mu-container.cc @@ -1,5 +1,5 @@ /* -** Copyright (C) 2011-2013 Dirk-Jan C. Binnema +** Copyright (C) 2011-2020 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -16,11 +16,11 @@ ** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ** */ +#include "mu-container.hh" #include /* for memset */ #include /* for log, ceil */ -#include "mu-container.h" #include "mu-msg.h" #include "mu-msg-iter.h" @@ -323,7 +323,7 @@ mu_container_from_list (GSList *lst) if (!lst) return NULL; - tail = list_last_data (lst); + tail = (MuContainer*)list_last_data (lst); for (c = cur = (MuContainer*)lst->data; cur; lst = g_slist_next(lst)) { cur->next = lst ? (MuContainer*)lst->data : NULL; cur->last = tail; @@ -545,7 +545,11 @@ path_to_string (Path *p, const char* frmt) for (u = 0, str = NULL; p->_data[u] != 0; ++u) { char segm[16]; + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" g_snprintf (segm, sizeof(segm), frmt, p->_data[u] - 1); +#pragma GCC diagnostic pop if (!str) str = g_strdup (segm); diff --git a/lib/mu-container.h b/lib/mu-container.hh similarity index 94% rename from lib/mu-container.h rename to lib/mu-container.hh index 628e0ac4..ed17ed7c 100644 --- a/lib/mu-container.h +++ b/lib/mu-container.hh @@ -17,50 +17,47 @@ ** */ -#ifndef __MU_CONTAINER_H__ -#define __MU_CONTAINER_H__ +#ifndef MU_CONTAINER_HH__ +#define MU_CONTAINER_HH__ #include #include +#include -G_BEGIN_DECLS - -enum _MuContainerFlag { +enum MuContainerFlag { MU_CONTAINER_FLAG_NONE = 0, MU_CONTAINER_FLAG_DELETE = 1 << 0, MU_CONTAINER_FLAG_SPLICE = 1 << 1, MU_CONTAINER_FLAG_DUP = 1 << 2 }; -typedef enum _MuContainerFlag MuContainerFlag; +MU_ENABLE_BITOPS(MuContainerFlag); /* * MuContainer data structure, as seen in JWZs document: * http://www.jwz.org/doc/threading.html */ -struct _MuContainer { - struct _MuContainer *parent, *child, *next; +struct MuContainer { + struct MuContainer *parent, *child, *next; /* note: we cache the last of the string of next->next->... * `mu_container_append_siblings' shows up high in the * profiles since it needs to walk to the end, and this give * O(n*n) behavior. * */ - struct _MuContainer *last; + struct MuContainer *last; /* Node in the subtree rooted at this node which comes first * in the descending sort order, e.g. the latest message if * sorting by date. We compare the leaders when ordering * subtrees. */ - struct _MuContainer *leader; + struct MuContainer *leader; MuMsg *msg; const char *msgid; unsigned docid; MuContainerFlag flags; - }; -typedef struct _MuContainer MuContainer; /** @@ -223,6 +220,4 @@ MuContainer* mu_container_sort (MuContainer *c, MuMsgFieldId mfid, GHashTable* mu_container_thread_info_hash_new (MuContainer *root_set, size_t matchnum); -G_END_DECLS - -#endif /*__MU_CONTAINER_H__*/ +#endif /*MU_CONTAINER_HH__*/ diff --git a/lib/mu-msg-iter.cc b/lib/mu-msg-iter.cc index a401976f..34b88ec4 100644 --- a/lib/mu-msg-iter.cc +++ b/lib/mu-msg-iter.cc @@ -37,7 +37,7 @@ #include "mu-msg.h" #include "mu-msg-iter.h" -#include "mu-threader.h" +#include "mu-threader.hh" struct ltstr { bool operator () (const std::string &s1, diff --git a/lib/mu-threader.c b/lib/mu-threader.cc similarity index 97% rename from lib/mu-threader.c rename to lib/mu-threader.cc index 80857ef0..17b81fdf 100644 --- a/lib/mu-threader.c +++ b/lib/mu-threader.cc @@ -1,6 +1,5 @@ -/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ /* -** Copyright (C) 2012-2013 Dirk-Jan C. Binnema +** Copyright (C) 2012-2020 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -17,11 +16,12 @@ ** Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ** */ +#include "mu-threader.hh" + #include /* for log, ceil */ #include /* for memset */ -#include "mu-threader.h" -#include "mu-container.h" +#include "mu-container.hh" #include "utils/mu-str.h" /* msg threading implementation based on JWZ's algorithm, as described in: @@ -137,7 +137,7 @@ find_or_create_referred (GHashTable *id_table, const char *msgid, g_return_val_if_fail (msgid, NULL); - c = g_hash_table_lookup (id_table, msgid); + c = (MuContainer*)g_hash_table_lookup (id_table, msgid); *created = !c; if (!c) { c = mu_container_new (NULL, 0, msgid); @@ -172,7 +172,7 @@ find_or_create (GHashTable *id_table, MuMsg *msg, guint docid) /* XXX the '' works around a crash; find a better * solution */ - c = g_hash_table_lookup (id_table, msgid); + c = (MuContainer*)g_hash_table_lookup (id_table, msgid); /* If id_table contains an empty MuContainer for this ID: * * * Store this message in the MuContainer's message slot. */ diff --git a/lib/mu-threader.h b/lib/mu-threader.hh similarity index 87% rename from lib/mu-threader.h rename to lib/mu-threader.hh index dc8d4149..3603aeda 100644 --- a/lib/mu-threader.h +++ b/lib/mu-threader.hh @@ -1,7 +1,5 @@ -/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ - /* -** Copyright (C) 2012-2013 Dirk-Jan C. Binnema +** Copyright (C) 2012-2020 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -19,14 +17,12 @@ ** */ -#ifndef __MU_THREADER_H__ -#define __MU_THREADER_H__ +#ifndef MU_THREADER_HH__ +#define MU_THREADER_HH__ #include #include -G_BEGIN_DECLS - /** * takes an iter and the total number of matches, and from this * generates a hash-table with information about the thread structure @@ -50,7 +46,4 @@ G_BEGIN_DECLS GHashTable *mu_threader_calculate (MuMsgIter *iter, size_t matches, MuMsgFieldId sortfield, gboolean revert); - -G_END_DECLS - -#endif /*__MU_THREADER_H__*/ +#endif /*MU_THREADER_HH__*/ diff --git a/lib/test-mu-container.cc b/lib/test-mu-container.cc index 49e62deb..6f61f1de 100644 --- a/lib/test-mu-container.cc +++ b/lib/test-mu-container.cc @@ -1,5 +1,3 @@ -/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ - /* ** Copyright (C) 2014 Jakub Sitnicki ** @@ -19,14 +17,11 @@ ** */ -#if HAVE_CONFIG_H #include "config.h" -#endif /*HAVE_CONFIG_H*/ - #include #include "test-mu-common.hh" -#include "mu-container.h" +#include "mu-container.hh" static gboolean container_has_children (const MuContainer *c) diff --git a/lib/test-mu-maildir.cc b/lib/test-mu-maildir.cc index cfffa44c..8d7010da 100644 --- a/lib/test-mu-maildir.cc +++ b/lib/test-mu-maildir.cc @@ -197,15 +197,15 @@ copy_test_data (void) gchar *dir, *cmd; dir = test_mu_common_get_random_tmpdir(); - cmd = g_strdup_printf ("mkdir -m 0700 %s", dir); + cmd = g_strdup_printf ("mkdir -p -m 0700 %s", dir); if (g_test_verbose()) - g_print ("cmd: %s\n", cmd); + g_debug ("cmd: %s\n", cmd); g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL)); g_free (cmd); cmd = g_strdup_printf ("cp -R %s %s", MU_TESTMAILDIR, dir); if (g_test_verbose()) - g_print ("cmd: %s\n", cmd); + g_debug ("cmd: %s\n", cmd); g_assert (g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL)); g_free (cmd); @@ -228,7 +228,7 @@ dir_cb (const char *fullpath, gboolean enter, WalkData *data) ++data->_dir_left; if (g_test_verbose()) - g_print ("%s: %s: %s (%u)\n", __func__, enter ? "entering" : "leaving", + g_debug ("%s: %s: %s (%u)\n", __func__, enter ? "entering" : "leaving", fullpath, enter ? data->_dir_entered : data->_dir_left); return MU_OK; diff --git a/lib/utils/test-command-parser.cc b/lib/utils/test-command-parser.cc index 94709d1b..fc1b57c5 100644 --- a/lib/utils/test-command-parser.cc +++ b/lib/utils/test-command-parser.cc @@ -49,8 +49,6 @@ static bool call (const Command::CommandMap& cmap, const std::string& str) try { const auto sexp{Sexp::make_parse(str)}; - g_message ("invoking %s", to_string(sexp).c_str()); - invoke (cmap, sexp); return true; @@ -75,8 +73,6 @@ test_command() "My command,", {}}); - std::cout << "****** " << cmap << "\n"; - g_assert_true(call(cmap, "(my-command :param1 \"hello\")")); g_assert_true(call(cmap, "(my-command :param1 \"hello\" :param2 123)")); @@ -127,6 +123,8 @@ test_command_fail() } +static void black_hole() {} + int main (int argc, char *argv[]) try { @@ -137,6 +135,12 @@ main (int argc, char *argv[]) try g_test_add_func ("/utils/command-parser/command2", test_command2); g_test_add_func ("/utils/command-parser/command-fail", test_command_fail); + g_log_set_handler (NULL, + (GLogLevelFlags)(G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| + G_LOG_FLAG_RECURSION), + (GLogFunc)black_hole, NULL); + + return g_test_run (); diff --git a/mu/mu-cmd-find.cc b/mu/mu-cmd-find.cc index 97c0f72f..80950fa5 100644 --- a/mu/mu-cmd-find.cc +++ b/mu/mu-cmd-find.cc @@ -40,7 +40,7 @@ #include "utils/mu-date.h" #include "mu-cmd.hh" -#include "mu-threader.h" +#include "mu-threader.hh" using namespace Mu;