From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id qHoIOXMNRWAiUwAA0tVLHw (envelope-from ) for ; Sun, 07 Mar 2021 17:29:23 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 2JPcNHMNRWDOVgAA1q6Kng (envelope-from ) for ; Sun, 07 Mar 2021 17:29:23 +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 63AFA23121 for ; Sun, 7 Mar 2021 18:29:23 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 6137C28E20; Sun, 7 Mar 2021 12:28:28 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2C76A27D48 for ; Sun, 7 Mar 2021 12:27:58 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 238115FA96; Sun, 7 Mar 2021 12:27:58 -0500 (EST) Received: (nullmailer pid 1091651 invoked by uid 1000); Sun, 07 Mar 2021 17:27:38 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 09/22] lib/open: factor out library initialization Date: Sun, 7 Mar 2021 13:27:21 -0400 Message-Id: <20210307172734.1091264-10-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210307172734.1091264-1-david@tethera.net> References: <20210307172734.1091264-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: ARLS2PHI7WDUJ2WKSRBTQGCUKQBR5RJH X-Message-ID-Hash: ARLS2PHI7WDUJ2WKSRBTQGCUKQBR5RJH 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=1615138163; 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=lbabv1K8RJMqrTntUbDnH2rvkL/DtwjLAB565JvCksU=; b=dNFnO0cXsbvICUVN9XZofuJAZTG2KE7G/vKSEHLvE6Fg+p8qyd6p1pejtz+7Cg7SQK467R 3Nmr9g7FMCXZE4OaBRYYgn5rTVs6V9GhwRN6hKu1lXz+j5I7MfIo0X5ntMrMD8AjZyfrWj +ITmoGqiu1/rnjTKczCT8cDPMJMK9yT8WkePfzmCpDWkuqr/ugQGHWzoJXk+rpqaWHsYDq UFKRoWDL0YmSIpkFdK0rz8aVFGR01Tok4T6i+KVeKS1KeOqOnKgSBdkqzOBH4BHSkpuWYX wIvoZjEkmPMxn9x51KRRKvF2NjNDotg/Y1rvYrcYPdKWVYzl8guPRxonG9JJYw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615138163; a=rsa-sha256; cv=none; b=YwwrBqDosAgEhqR/bO87vg/Ext61Qsfg8fdo7Cb5XW8bXJJUi9SkDJkA/zx7o1+s+7KBTY FvIJ9FXwhNSdMij48cbWUP+X/g2Jjy1lDaziNiGHKHqY/M+FJWfFXFGoSkPAdc0VyF74h4 OqymX2pnAeGOGDTMMwmLuybCN0QljRkkQyOzmpx5OFbwnNv6SesK/etUm4j4b887rJGnk0 ktDiliJ5ksMw7Oyz/oED9wOTbXd5CcbQg6vcnDFqeUOvZE5WukEv89jA+EvuPykPvhKs1+ qX8hT0X25mNkPatdzlcaxyh0u0UTRIIXnA8p0hFa3fmf7rzeWACqwFimw17b3A== 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: -0.96 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: 63AFA23121 X-Spam-Score: -0.96 X-Migadu-Scanner: scn0.migadu.com X-TUID: rE/Dm+JMtp9z 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 | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 7d295893..e700fa6a 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, @@ -239,6 +257,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; @@ -271,17 +291,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.1