From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id EETaCF94LWDRGgAA0tVLHw (envelope-from ) for ; Wed, 17 Feb 2021 20:11:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id MDCvBF94LWB7YgAAB5/wlQ (envelope-from ) for ; Wed, 17 Feb 2021 20:11:11 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id A804321321 for ; Wed, 17 Feb 2021 21:11:10 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id DE43C26A11; Wed, 17 Feb 2021 15:10:57 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 9BECB1FBB5 for ; Wed, 17 Feb 2021 15:10:54 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 309CD607F4; Wed, 17 Feb 2021 15:10:54 -0500 (EST) Received: (nullmailer pid 2021421 invoked by uid 1000); Wed, 17 Feb 2021 20:10:50 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 08/21] lib/open: factor out library initialization Date: Wed, 17 Feb 2021 16:10:32 -0400 Message-Id: <20210217201045.2021106-9-david@tethera.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210217201045.2021106-1-david@tethera.net> References: <20210217201045.2021106-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: ZSSA6JAKCWLXTMWCDGGOZKO3GBQZLRAU X-Message-ID-Hash: ZSSA6JAKCWLXTMWCDGGOZKO3GBQZLRAU X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 0.47 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A804321321 X-Spam-Score: 0.47 X-Migadu-Scanner: scn0.migadu.com X-TUID: j8Vzg/UbFs0n This is slightly more tidy, but more importantly it allows for re-use of this code in n_d_create_with_config. --- lib/open.cc | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index d599aeac..7f25bd36 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -210,6 +210,22 @@ _set_database_path (notmuch_database_t *notmuch, _notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path); } +static void _init_libs () { + + static int initialized = 0; + + /* Initialize the GLib type system and threads */ +#if ! GLIB_CHECK_VERSION (2, 35, 1) + g_type_init (); +#endif + + /* Initialize gmime */ + if (! initialized) { + g_mime_init (); + initialized = 1; + } +} + notmuch_status_t notmuch_database_open_with_config (const char *database_path, notmuch_database_mode_t mode, @@ -229,6 +245,8 @@ notmuch_database_open_with_config (const char *database_path, GKeyFile *key_file = NULL; static int initialized = 0; + _init_libs (); + notmuch = _alloc_notmuch (); if (!notmuch) { status = NOTMUCH_STATUS_OUT_OF_MEMORY; @@ -260,17 +278,6 @@ notmuch_database_open_with_config (const char *database_path, goto DONE; } - /* Initialize the GLib type system and threads */ -#if ! GLIB_CHECK_VERSION (2, 35, 1) - g_type_init (); -#endif - - /* Initialize gmime */ - if (! initialized) { - g_mime_init (); - initialized = 1; - } - try { std::string last_thread_id; std::string last_mod; -- 2.30.0