unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Steven Allen <steven@stebalien.com>
To: notmuch@notmuchmail.org
Cc: Steven Allen <steven@stebalien.com>
Subject: [PATCH] Add method to reparent of message to the database.
Date: Sun,  1 Nov 2015 15:07:08 -0500	[thread overview]
Message-ID: <1446408428-7703-1-git-send-email-steven@stebalien.com> (raw)

Currently, a message is owned by its iterator (messages object) and,
ultimately, its query. This unfortunately makes encapsulating query
logic difficult because there is no way to return a message after
disposing of the query used to find the message (other than looking it
up again in the database by id).

This patch adds a function `notmuch_message_own` that reparents a
message onto the database making it the user's job to destroy it.
---
 lib/message.cc |  6 ++++++
 lib/notmuch.h  | 12 ++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/lib/message.cc b/lib/message.cc
index 26b5e76..014363f 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1657,6 +1657,12 @@ notmuch_message_thaw (notmuch_message_t *message)
 }
 
 void
+notmuch_message_own (notmuch_message_t *message)
+{
+    talloc_steal(message->notmuch, message);
+}
+
+void
 notmuch_message_destroy (notmuch_message_t *message)
 {
     talloc_free (message);
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 310a8b8..c80d7aa 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1629,6 +1629,18 @@ notmuch_message_freeze (notmuch_message_t *message);
 notmuch_status_t
 notmuch_message_thaw (notmuch_message_t *message);
 
+
+/**
+ * Reparent a notmuch_message_t object onto the database.
+ *
+ * Calling this function allows a notmuch_message_t object to outlive its
+ * query. The message will automatically be reclaimed when the database is
+ * destroyed but if you want to free its memory before then, you should call
+ * notmuch_message_destroy.
+ */
+void
+notmuch_message_own (notmuch_message_t *message);
+
 /**
  * Destroy a notmuch_message_t object.
  *
-- 
2.6.2

             reply	other threads:[~2015-11-01 20:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-01 20:07 Steven Allen [this message]
2015-11-07 21:04 ` [PATCH] Add a method to reparent threads to the database Steven Allen
2015-11-08 17:37   ` Jani Nikula
2015-11-08 19:15     ` Steven Allen
2017-03-11 22:44       ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446408428-7703-1-git-send-email-steven@stebalien.com \
    --to=steven@stebalien.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).