unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH 4/7] CLI: centralize initialization in notmuch_client_init
Date: Thu, 13 May 2021 07:07:07 -0300	[thread overview]
Message-ID: <20210513100710.1460566-5-david@tethera.net> (raw)
In-Reply-To: <20210513100710.1460566-1-david@tethera.net>

Initially make sure gmime_filter_reply initialization is
thread-safe (assuming notmuch_client_init is only called once).
For tidyness, also put talloc initialization in the new function.
---
 Makefile.local       |  1 +
 gmime-filter-reply.c | 42 +++++++++++++++++++++---------------------
 gmime-filter-reply.h |  2 ++
 notmuch-client.h     |  4 ++++
 notmuch.c            |  7 +------
 5 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/Makefile.local b/Makefile.local
index bbb8f0b6..e12b94cd 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -231,6 +231,7 @@ notmuch_client_srcs =		\
 	gmime-filter-reply.c	\
 	hooks.c			\
 	notmuch.c		\
+	notmuch-client-init.c	\
 	notmuch-compact.c	\
 	notmuch-config.c	\
 	notmuch-count.c		\
diff --git a/gmime-filter-reply.c b/gmime-filter-reply.c
index 2b067669..35349cc8 100644
--- a/gmime-filter-reply.c
+++ b/gmime-filter-reply.c
@@ -43,29 +43,31 @@ static void filter_reset (GMimeFilter *filter);
 
 
 static GMimeFilterClass *parent_class = NULL;
+static GType type = 0;
+static const GTypeInfo info = {
+    .class_size = sizeof (GMimeFilterReplyClass),
+    .base_init = NULL,
+    .base_finalize = NULL,
+    .class_init = (GClassInitFunc) g_mime_filter_reply_class_init,
+    .class_finalize = NULL,
+    .class_data = NULL,
+    .instance_size = sizeof (GMimeFilterReply),
+    .n_preallocs = 0,
+    .instance_init = (GInstanceInitFunc) g_mime_filter_reply_init,
+    .value_table = NULL,
+};
+
+
+void
+g_mime_filter_reply_module_init (void)
+{
+    type = g_type_register_static (GMIME_TYPE_FILTER, "GMimeFilterReply", &info, (GTypeFlags) 0);
+    parent_class = (GMimeFilterClass *) g_type_class_ref (GMIME_TYPE_FILTER);
+}
 
 GType
 g_mime_filter_reply_get_type (void)
 {
-    static GType type = 0;
-
-    if (! type) {
-	static const GTypeInfo info = {
-	    .class_size = sizeof (GMimeFilterReplyClass),
-	    .base_init = NULL,
-	    .base_finalize = NULL,
-	    .class_init = (GClassInitFunc) g_mime_filter_reply_class_init,
-	    .class_finalize = NULL,
-	    .class_data = NULL,
-	    .instance_size = sizeof (GMimeFilterReply),
-	    .n_preallocs = 0,
-	    .instance_init = (GInstanceInitFunc) g_mime_filter_reply_init,
-	    .value_table = NULL,
-	};
-
-	type = g_type_register_static (GMIME_TYPE_FILTER, "GMimeFilterReply", &info, (GTypeFlags) 0);
-    }
-
     return type;
 }
 
@@ -76,8 +78,6 @@ g_mime_filter_reply_class_init (GMimeFilterReplyClass *klass, unused (void *clas
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
     GMimeFilterClass *filter_class = GMIME_FILTER_CLASS (klass);
 
-    parent_class = (GMimeFilterClass *) g_type_class_ref (GMIME_TYPE_FILTER);
-
     object_class->finalize = g_mime_filter_reply_finalize;
 
     filter_class->copy = filter_copy;
diff --git a/gmime-filter-reply.h b/gmime-filter-reply.h
index 7cdefcd1..988fe2d6 100644
--- a/gmime-filter-reply.h
+++ b/gmime-filter-reply.h
@@ -21,6 +21,8 @@
 
 #include <gmime/gmime-filter.h>
 
+void g_mime_filter_reply_module_init (void);
+
 G_BEGIN_DECLS
 
 #define GMIME_TYPE_FILTER_REPLY            (g_mime_filter_reply_get_type ())
diff --git a/notmuch-client.h b/notmuch-client.h
index 270553ad..8227fea4 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -250,6 +250,10 @@ json_quote_chararray (const void *ctx, const char *str, const size_t len);
 char *
 json_quote_str (const void *ctx, const char *str);
 
+/* notmuch-client-init.c */
+
+void notmuch_client_init (void);
+
 /* notmuch-config.c */
 
 typedef enum {
diff --git a/notmuch.c b/notmuch.c
index 2429999c..9ca3a4be 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -464,15 +464,10 @@ main (int argc, char *argv[])
 	{ }
     };
 
-    talloc_enable_null_tracking ();
+    notmuch_client_init ();
 
     local = talloc_new (NULL);
 
-    g_mime_init ();
-#if ! GLIB_CHECK_VERSION (2, 35, 1)
-    g_type_init ();
-#endif
-
     /* Globally default to the current output format version. */
     notmuch_format_version = NOTMUCH_FORMAT_CUR;
 
-- 
2.30.2

  parent reply	other threads:[~2021-05-13 10:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-13 10:07 static variable cleanup David Bremner
2021-05-13 10:07 ` [PATCH 1/7] lib: make glib initialization thread-safe David Bremner
2021-05-13 10:07 ` [PATCH 2/7] lib/generate_thread_id: move static buffer to notmuch_database_t David Bremner
2021-05-13 10:07 ` [PATCH 3/7] lib/message: mark flag2tag as const David Bremner
2021-05-13 10:07 ` David Bremner [this message]
2021-05-13 10:07 ` [PATCH 5/7] CLI/config: make immutable tables const David Bremner
2021-05-13 10:07 ` [PATCH 6/7] CLI: make static message strings const David Bremner
2021-05-13 17:27   ` Tomi Ollila
2021-05-14 10:24     ` David Bremner
2021-05-14 14:39       ` Tomi Ollila
2021-05-13 10:07 ` [PATCH 7/7] CLI/notmuch: make immutable tables const David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210513100710.1460566-5-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).