From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id CFgiD7wXTmB9HAAA0tVLHw (envelope-from ) for ; Sun, 14 Mar 2021 14:03:40 +0000 Received: from aspmx2.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id uIHUCrwXTmAJTgAAbx9fmQ (envelope-from ) for ; Sun, 14 Mar 2021 14:03:40 +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 D137110D89 for ; Sun, 14 Mar 2021 15:03:39 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 7750D27D50; Sun, 14 Mar 2021 10:02:48 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 5B56E27B37 for ; Sun, 14 Mar 2021 10:02:31 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 23A605FA96; Sun, 14 Mar 2021 10:02:31 -0400 (EDT) Received: (nullmailer pid 183646 invoked by uid 1000); Sun, 14 Mar 2021 14:02:19 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 07/22] lib/open: allocate notmuch_t struct early Date: Sun, 14 Mar 2021 11:02:02 -0300 Message-Id: <20210314140217.183425-8-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: 34CW6COCGDJ2CRWCBMXKZBTG6EAGBXYF X-Message-ID-Hash: 34CW6COCGDJ2CRWCBMXKZBTG6EAGBXYF 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=1615730619; 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=LRr0TCHlILn5emjAulldQEcvrmyL3smZosq58lNQWEw=; b=rpd+YuXBsnBgOnM9jgvix1oRNS6igPjbx0rYroIfaTKoyg53dx+8uYCBSMYtusIAwuXJQX ts8rw9LAvxLG2AKAmDW3zy21phYd/6U/vkVIy1kogxYWmhhyrmndplvj4qDYIubU/KOMFf ThcbMR4cCPJuIqSltpCyMjKC5zVYhNmTzkcaKKzilc/EjMqzqlVEQ5YsGOn6YPBfIf28cc H3vegyljclkLEhoA8x1fu/7//UuOQdncB/AEpv4ibV4ClxIWY+v3itwp9eerI2Rs2DOyKm H1NrVZJMF+5ulduHpS0D/BJgSvLTNxFZqzXrr3JD+DhUpVhB+iBpA/ExB7wwmQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615730619; a=rsa-sha256; cv=none; b=nMg09jpPAmCnwqSpTC7zdWGu1GuUlkfrAuF1KKas06R+fr88XdTFMaotcXuAFSRe9TxGxm ziGEgRMEH3DLpPBf+IpWNZedL3W6KOHfZena2dEYPfutmOFMLiJ/yp7Cwvm/fvyGJY1+ka ZNa0rkcObHqB17lYSo0xX8NTSPMlZwRPC4QNRAIIm7z5sHsfoE5FjsXXXognMkfyeKYWou XofYgixG+TE3uGJpUoAfKeVpecJUcGG1ey0NujUKx0mUDPrBAIuV0T7iO/+OtOacT4GmL7 DBOeXQTbrD+2Oqjw1jlONG8Gs0fZJDY+Wi8Uk1B5r2zGo2iP7fcm1LXHf9PuQQ== 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: -1.00 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: D137110D89 X-Spam-Score: -1.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: jF1O5BCk+CZy This gives more flexibility in restructuring the database opening code. --- lib/open.cc | 57 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 6e46168a..de5f3467 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; - if ((status = _choose_database_path (local, config_path, profile, &key_file, &database_path, - &message))) + 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; @@ -442,8 +457,8 @@ notmuch_database_create_with_config (const char *database_path, int err; void *local = talloc_new (NULL); - if ((status = _choose_database_path (local, config_path, profile, &key_file, &database_path, - &message))) + if ((status = _choose_database_path (local, config_path, profile, + &key_file, &database_path, &message))) goto DONE; err = stat (database_path, &st); -- 2.30.1