From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SPV9JoANRWDJaQAA0tVLHw (envelope-from ) for ; Sun, 07 Mar 2021 17:29:36 +0000 Received: from aspmx2.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id aMNXIoANRWDvZAAAB5/wlQ (envelope-from ) for ; Sun, 07 Mar 2021 17:29:36 +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 aspmx2.migadu.com (Postfix) with ESMTPS id 1AEBC1E9DF for ; Sun, 7 Mar 2021 18:29:36 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 20EAE28E2D; Sun, 7 Mar 2021 12:28:34 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id E551227D52 for ; Sun, 7 Mar 2021 12:28:00 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id DCFFB5FA96; Sun, 7 Mar 2021 12:28:00 -0500 (EST) Received: (nullmailer pid 1091647 invoked by uid 1000); Sun, 07 Mar 2021 17:27:38 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 07/22] lib/open: allocate notmuch_t struct early Date: Sun, 7 Mar 2021 13:27:19 -0400 Message-Id: <20210307172734.1091264-8-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: SGNCV7URR7G53IGIGLIEIFYBEAFSNAJL X-Message-ID-Hash: SGNCV7URR7G53IGIGLIEIFYBEAFSNAJL 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=1615138176; 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=kE1oh3o9yQKHJ3cnxuUqI5dNU5UHfkCZiHaTOElvTRI=; b=V20NKYyH2eyggq/XlcZtsLCjNFRDVRHll23ODgrWiO1ClpohoZvRYmWOlOUD+pTk1yLM4g gykG27iUiIeK/zpA2id0HUAKapLfKD5XZzfr9fgrfDCCUF1eOdcM3hmN8Y3bDOqFeBImuM ms7pdF7FovybvZ5Dji9oC6hmHkYFX7Fq+fCU89s7A4U3FK/yRWxHHY11n2gQez3O+tPBUy OmG8/qfjMWSEHDCxsS9TQfOdupRmzyjiXjzGO/bT+KYd4U0AIZ4KolKglW9H/enf5ReDlv orX/cfXkaMhCWSn3ltVYymG34nSlzVwGL7hZTy6z9EhqOnWhqhfaIN4LvY9+KA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615138176; a=rsa-sha256; cv=none; b=k992aoXftZo2ANiN1MT/B3Exy7/fU4xOdAsMf7eUkpwY6fVyxMPheYoZ0weVEt3sqhkDZw 0n30F48VF1fwY/244zT0jTlGW42jTTFGTZztW3w7vOfKJOos+d+aU942JGO0NMS4dc4PC2 FjBCqHN4rGiv6ytDRxI7hqaH6AO3GaFGVurtsimCHhw//gY9rnnnlyaHRT306Ig4KpTD4A Yh4tyiuPLOwvT5TDpE9Nt1D8w6yFRm1foWdRr/tB34q2tinK570Vn6piDnSo6Jk6/Y0AJn 2uzvx7vBBa52sJ5u9hiJjI7hjdYku9ZxIGdaqiObI9jklv3dC5naxMWdQbfVwQ== ARC-Authentication-Results: i=1; aspmx2.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx2.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: aspmx2.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx2.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: 1AEBC1E9DF X-Spam-Score: -0.96 X-Migadu-Scanner: scn1.migadu.com X-TUID: 8zg/wGEVQdXc This gives more flexibility in restructuring the database opening code. --- lib/open.cc | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index e1732d35..21a6b0f4 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -192,6 +192,23 @@ _choose_database_path (void *ctx, return NOTMUCH_STATUS_SUCCESS; } +notmuch_database_t * +_alloc_notmuch () +{ + notmuch_database_t *notmuch; + + notmuch = talloc_zero (NULL, notmuch_database_t); + if (! notmuch) + return NULL; + + notmuch->exception_reported = false; + notmuch->status_string = NULL; + notmuch->writable_xapian_db = NULL; + notmuch->atomic_nesting = 0; + notmuch->view = 1; + return notmuch; +} + notmuch_status_t notmuch_database_open_with_config (const char *database_path, notmuch_database_mode_t mode, @@ -211,10 +228,19 @@ notmuch_database_open_with_config (const char *database_path, GKeyFile *key_file = NULL; static int initialized = 0; + notmuch = _alloc_notmuch (); + if (! notmuch) { + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + if ((status = _choose_database_path (local, config_path, profile, &key_file, &database_path, &message))) goto DONE; + notmuch->path = talloc_strdup (notmuch, database_path); + strip_trailing (notmuch->path, '/'); + if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) { message = strdup ("Out of memory\n"); status = NOTMUCH_STATUS_OUT_OF_MEMORY; @@ -229,6 +255,12 @@ notmuch_database_open_with_config (const char *database_path, goto DONE; } + if (! (notmuch->xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) { + message = strdup ("Out of memory\n"); + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + /* Initialize the GLib type system and threads */ #if ! GLIB_CHECK_VERSION (2, 35, 1) g_type_init (); @@ -240,23 +272,6 @@ notmuch_database_open_with_config (const char *database_path, initialized = 1; } - notmuch = talloc_zero (NULL, notmuch_database_t); - notmuch->exception_reported = false; - notmuch->status_string = NULL; - notmuch->path = talloc_strdup (notmuch, database_path); - - strip_trailing (notmuch->path, '/'); - - notmuch->writable_xapian_db = NULL; - notmuch->atomic_nesting = 0; - notmuch->view = 1; - - if (! (notmuch->xapian_path = talloc_asprintf (notmuch, "%s/%s", notmuch_path, "xapian"))) { - message = strdup ("Out of memory\n"); - status = NOTMUCH_STATUS_OUT_OF_MEMORY; - goto DONE; - } - try { std::string last_thread_id; std::string last_mod; -- 2.30.1