From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id kLVzN2XhQGD/LgAA0tVLHw (envelope-from ) for ; Thu, 04 Mar 2021 13:32:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id EI4fM2XhQGBgBAAAbx9fmQ (envelope-from ) for ; Thu, 04 Mar 2021 13:32:21 +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)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 70DDB164F6 for ; Thu, 4 Mar 2021 14:32:21 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 8249027C3B; Thu, 4 Mar 2021 08:31:52 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 75D1827568 for ; Thu, 4 Mar 2021 08:31:37 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 702685FA96; Thu, 4 Mar 2021 08:31:37 -0500 (EST) Received: (nullmailer pid 4053561 invoked by uid 1000); Thu, 04 Mar 2021 13:31:28 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 09/22] lib/open: factor out library initialization Date: Thu, 4 Mar 2021 09:31:12 -0400 Message-Id: <20210304133125.4050229-10-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210304133125.4050229-1-david@tethera.net> References: <20210304133125.4050229-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: CVYS6KAJ46AMQS7BFEYA56WIBRQGYXAO X-Message-ID-Hash: CVYS6KAJ46AMQS7BFEYA56WIBRQGYXAO 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=1614864741; 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=k5WW9N0RTa5c7dMzzskvBhA5AZxXgdUwZoHcX0OKJao=; b=AFHjFrL7ObZJWEgiGMGnQh4ZPbAJ14bmj4OffptpHJHqcoaq0U+Ww+1jOc6ONAfNln2RRQ MofX4uERid5fniEDIZpKq65wtKG/JPYAp3m3+viR670b1cXCbzFXSKRTICb7PIpCkg4e83 3IL/QE4jKQdccByZVCQbWTdhNDCFb3yaeHW+p9Z6lpEOqOFi63wrB2BRgcMDYR9TTarmLt 9QM48k3MOu0LmzbIsKZkr+x5cIR+KAS/Xdd7zOou4qkfhEyua4rnF07OL94wJ2zF+GIElJ unSNaxzC7KtNNqoJihTQVE5J/RUv36lvYqf5bbQB4i8jXM+NkZ6y/k4ckBr4LQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614864741; a=rsa-sha256; cv=none; b=ll1od/t92U1D38GxMCMq7R39NQVMsdVMMERimlVKNMscHluBmxwZ6398vbS+3tOhajQ00A vcPZlA9LX/5MzmquebtPxbzJ1n3MLfcsZRkJyFxf0UBt3X0giVborbpZ4w+L851DvwHJQv mj1CbMDj3yvJH9HXpGn2jcq/ujgbS4nuRnM+gl7Y0f6G+LhfX/ETgiAcILDskrl5aa6TdU saJug06yAsSGVwqBXaJKpu0uDYyLLk0slwG1hUIkdlOGi+XXjSV2aLvYs3SAWOIK3tfd29 GCvNV1dhNe5YG66qLiQ1lRInL5ZXr4yFFuWxbi1a7wamYLHttw08AaqyLNOYuw== 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: 70DDB164F6 X-Spam-Score: -0.96 X-Migadu-Scanner: scn0.migadu.com X-TUID: 21W/61ritUr/ 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.1