CLI: centralize initialization in notmuch_client_init

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.
This commit is contained in:
David Bremner 2021-05-12 20:22:18 -03:00
parent b1b6798588
commit 5a8d174f67
5 changed files with 29 additions and 27 deletions

View file

@ -231,6 +231,7 @@ notmuch_client_srcs = \
gmime-filter-reply.c \ gmime-filter-reply.c \
hooks.c \ hooks.c \
notmuch.c \ notmuch.c \
notmuch-client-init.c \
notmuch-compact.c \ notmuch-compact.c \
notmuch-config.c \ notmuch-config.c \
notmuch-count.c \ notmuch-count.c \

View file

@ -43,13 +43,7 @@ static void filter_reset (GMimeFilter *filter);
static GMimeFilterClass *parent_class = NULL; static GMimeFilterClass *parent_class = NULL;
GType
g_mime_filter_reply_get_type (void)
{
static GType type = 0; static GType type = 0;
if (! type) {
static const GTypeInfo info = { static const GTypeInfo info = {
.class_size = sizeof (GMimeFilterReplyClass), .class_size = sizeof (GMimeFilterReplyClass),
.base_init = NULL, .base_init = NULL,
@ -63,9 +57,17 @@ g_mime_filter_reply_get_type (void)
.value_table = NULL, .value_table = NULL,
}; };
void
g_mime_filter_reply_module_init (void)
{
type = g_type_register_static (GMIME_TYPE_FILTER, "GMimeFilterReply", &info, (GTypeFlags) 0); 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)
{
return type; return type;
} }
@ -76,8 +78,6 @@ g_mime_filter_reply_class_init (GMimeFilterReplyClass *klass, unused (void *clas
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GMimeFilterClass *filter_class = GMIME_FILTER_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; object_class->finalize = g_mime_filter_reply_finalize;
filter_class->copy = filter_copy; filter_class->copy = filter_copy;

View file

@ -21,6 +21,8 @@
#include <gmime/gmime-filter.h> #include <gmime/gmime-filter.h>
void g_mime_filter_reply_module_init (void);
G_BEGIN_DECLS G_BEGIN_DECLS
#define GMIME_TYPE_FILTER_REPLY (g_mime_filter_reply_get_type ()) #define GMIME_TYPE_FILTER_REPLY (g_mime_filter_reply_get_type ())

View file

@ -250,6 +250,10 @@ json_quote_chararray (const void *ctx, const char *str, const size_t len);
char * char *
json_quote_str (const void *ctx, const char *str); json_quote_str (const void *ctx, const char *str);
/* notmuch-client-init.c */
void notmuch_client_init (void);
/* notmuch-config.c */ /* notmuch-config.c */
typedef enum { typedef enum {

View file

@ -464,15 +464,10 @@ main (int argc, char *argv[])
{ } { }
}; };
talloc_enable_null_tracking (); notmuch_client_init ();
local = talloc_new (NULL); 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. */ /* Globally default to the current output format version. */
notmuch_format_version = NOTMUCH_FORMAT_CUR; notmuch_format_version = NOTMUCH_FORMAT_CUR;