From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id KOl3Ou0XTmAKdAAA0tVLHw (envelope-from ) for ; Sun, 14 Mar 2021 14:04:29 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id YJcsNu0XTmAuRAAAB5/wlQ (envelope-from ) for ; Sun, 14 Mar 2021 14:04:29 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 9E4FE12BBF for ; Sun, 14 Mar 2021 15:04:29 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 02A1B28CB8; Sun, 14 Mar 2021 10:03:03 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id AB33627C63 for ; Sun, 14 Mar 2021 10:02:38 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id A2E2A5FA96; Sun, 14 Mar 2021 10:02:38 -0400 (EDT) Received: (nullmailer pid 183650 invoked by uid 1000); Sun, 14 Mar 2021 14:02:19 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 09/22] lib/open: factor out library initialization Date: Sun, 14 Mar 2021 11:02:04 -0300 Message-Id: <20210314140217.183425-10-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210314140217.183425-1-david@tethera.net> References: <20210314140217.183425-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: MVX3H2YQ5PCWUYIZQBJ4LR3IPPAGJHX7 X-Message-ID-Hash: MVX3H2YQ5PCWUYIZQBJ4LR3IPPAGJHX7 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1615730669; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bP+g0jp0P10Fu7J0YkXfdAZVfZqK3IxMpVWrGUEpW6g=; b=W+j6RUsTQlNYEkeSNfEKwtYs1/JJx43Jz4apnBn02Qg81SZoY34aIIMR42EROsRxpCHIHQ Lz4QSBXYiXvnHslTwqiHG3N4/cGjVov85y0jrbu9/pZ0qiwyopBkFvFsRkGFHFYjyXiG1d /dE6cY01H1BrxWRdcTNJTPlyAQGPybfDNeDht2WkKNaco6L8nkITKCcZpmjoFS0BO9A+YU pZRbQX/YLLKcJiC1z87+1PGmWpIQGzEArhk67mjqrOkZOfcUnTRFwvxnuOPoaW0xE9H7bJ CDUwcjINCpRsZ3kqlz5rBBn/mgRmF2Gr45hR68MzTD3yB1gAV9zl1PgIBb8VHg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615730669; a=rsa-sha256; cv=none; b=utRlHhyJW2sHDbxb8aCm7StiL4DeaSevuh/AiTVZ59E17Mgor8tQARyPV4GOCky8Xvg7NG VPhtMB4XYXuQIn/uw8rAMNGq3gOE4t/Zdw7+l2Fo0r3ZGOjSzt5iiStHE+mxa0Cq+NJGEP q14WXEGzuhTaiAxaegnWbYQLK2EFAiZ2T0Czm4CvTBW0GIrTV+WXEgfM6g4v9SEOuYJQdY GoFSRof6UodaVMaYt8SApN2vluVe2Ozu6FqcrvK0HMJizADFx9yBJxLS7gIQzryMT3APeZ 75Az6oy7dAqP+X2HvVssL95Bt3Nm6sUJepR4jam8CtwaF+6bNY0aMff4/e+exg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.00 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 9E4FE12BBF X-Spam-Score: -1.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: Vg9OBV0RE/zU This is slightly more tidy, but more importantly it allows for re-use of this code in n_d_create_with_config. That re-use will be crucial when we no longer call n_d_open_with_config from n_d_create_with_config. --- lib/open.cc | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index a62d4dee..f48b97ae 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -220,6 +220,24 @@ _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, @@ -237,7 +255,8 @@ notmuch_database_open_with_config (const char *database_path, int err; unsigned int version; GKeyFile *key_file = NULL; - static int initialized = 0; + + _init_libs (); notmuch = _alloc_notmuch (); if (! notmuch) { @@ -271,17 +290,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; @@ -467,6 +475,8 @@ notmuch_database_create_with_config (const char *database_path, int err; void *local = talloc_new (NULL); + _init_libs (); + if ((status = _choose_database_path (local, config_path, profile, &key_file, &database_path, &message))) goto DONE; -- 2.30.1