From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id iCX2FUPhQGBlMQAA0tVLHw (envelope-from ) for ; Thu, 04 Mar 2021 13:31:47 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id gJvDEUPhQGCjfQAAbx9fmQ (envelope-from ) for ; Thu, 04 Mar 2021 13:31:47 +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 D44F422BA9 for ; Thu, 4 Mar 2021 14:31:46 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 30DC72706D; Thu, 4 Mar 2021 08:31:35 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 19C1C1FBBC for ; Thu, 4 Mar 2021 08:31:31 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 0F8475FA96; Thu, 4 Mar 2021 08:31:31 -0500 (EST) Received: (nullmailer pid 4053555 invoked by uid 1000); Thu, 04 Mar 2021 13:31:28 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 07/22] lib/open: allocate notmuch_t struct early Date: Thu, 4 Mar 2021 09:31:10 -0400 Message-Id: <20210304133125.4050229-8-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: L77V6CZ6NKNQCVDL3ESURKW6EH3X6NUZ X-Message-ID-Hash: L77V6CZ6NKNQCVDL3ESURKW6EH3X6NUZ 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=1614864707; 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=vD8jWMpHN2CrpCJv3vGpreGVjcBaRcG7NzMKzEFzq7E=; b=WlxO5R+90RqD7MQJmGupr7FDyBQv4Xr3Fq6uQ3t1GlEA/FpQZsw6LdcjT7kYCGKP8KYNi4 eLZN5/TtetbCPUIDeelZizTc8WKUxcDg1cqYQBi5pP3WJMopxxCAQ7T6YGehus42j0Ewqs DDwyJlXxfcatYcRXEIecqWo1i6mQm6rK1HEokSBajDGPklHi/7XmvF6wf8UOW6voESw67e D5zrzDfhyPRvPGtEizc/hi0P5t0XXtVJUHmHGoVVXzN6zS6+f1JwLReyiKdiIQTvdt7aEA NXnR4U56hJPJllSYpazX4kZy17SNQwAKuOQCKt96VG6eMAvvVcejUgc2cOrkSg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614864707; a=rsa-sha256; cv=none; b=h4FZKCdUGMCa1yGSAiHZzZPOykd92jUCQIB1Pa9GYd5aNuEUfVaTcPTV0UnYFWX6+RqZ3k b7YrREGvaeuRaTML5zxKcbw8yGxASDt2eKsNDgw1YMeX50bmZEVEjpgJNeqIPmWWQP8Hq1 p92R+s8N5gVFiw+dn0jyPT44ac49cpsvb1uD/IpBzVeOf5YxR9X0n1mo/x0ADLWZ3q8JnJ T49dwXBGuwen3uvLHGzCHJtgloJB4qfyHo942LPocFY09bZDRTn2PJWDIOBBRG6JMMB0GN ngze0oPkxtihNgb81t3NnKJxvK4WA3s6b7c+SoPcCmITCAuRIMB8AzWgB0+Pmw== 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.80 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: D44F422BA9 X-Spam-Score: -0.80 X-Migadu-Scanner: scn1.migadu.com X-TUID: 3aP3dqjCRavQ This gives more flexibility in restructuring the database opening code. --- lib/open.cc | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index f08b5de5..c7fb6f81 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -186,6 +186,20 @@ _choose_database_path (const char *config_path, 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, @@ -205,9 +219,18 @@ 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 (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; @@ -222,6 +245,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 (); @@ -233,23 +262,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