1 Return-Path: <bremner@tesseract.cs.unb.ca>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 8C032431FC9
\r
6 for <notmuch@notmuchmail.org>; Mon, 19 Jan 2015 23:56:18 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=2.438 tagged_above=-999 required=5
\r
12 tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id bbFZA8BtzfxY for <notmuch@notmuchmail.org>;
\r
16 Mon, 19 Jan 2015 23:56:15 -0800 (PST)
\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net
\r
19 (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))
\r
20 (No client certificate requested)
\r
21 by olra.theworths.org (Postfix) with ESMTPS id 42389431FC3
\r
22 for <notmuch@notmuchmail.org>; Mon, 19 Jan 2015 23:56:15 -0800 (PST)
\r
23 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim
\r
24 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
25 id 1YDTda-0006KX-2P; Tue, 20 Jan 2015 07:54:10 +0000
\r
26 Received: (nullmailer pid 10454 invoked by uid 1000); Tue, 20 Jan 2015
\r
28 From: David Bremner <david@tethera.net>
\r
29 To: notmuch@notmuchmail.org
\r
30 Subject: [PATCH] lib: add new status reporting API for
\r
31 notmuch_query_search_{m,t}
\r
32 Date: Tue, 20 Jan 2015 08:53:41 +0100
\r
33 Message-Id: <1421740421-10401-1-git-send-email-david@tethera.net>
\r
34 X-Mailer: git-send-email 2.1.4
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.13
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Tue, 20 Jan 2015 07:56:18 -0000
\r
49 This at least allows distinguishing between out of memory and Xapian
\r
50 exceptions. Adding finer grained status codes would allow different
\r
51 Xapian exceptions to be preserved.
\r
53 Adding wrappers allows people to transition gradually to the new API,
\r
54 at the cost of bloating the library API a bit.
\r
56 lib/notmuch.h | 10 ++++++++++
\r
57 lib/query.cc | 50 ++++++++++++++++++++++++++++++++++++++++----------
\r
58 2 files changed, 50 insertions(+), 10 deletions(-)
\r
60 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
61 index 220839b..58052f1 100644
\r
64 @@ -780,10 +780,15 @@ notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);
\r
65 * to call it if the query is about to be destroyed).
\r
67 * If a Xapian exception occurs this function will return NULL.
\r
68 + * For better error reporting, use the _st variant.
\r
71 notmuch_query_search_threads (notmuch_query_t *query);
\r
74 +notmuch_query_search_threads_st (notmuch_query_t *query,
\r
75 + notmuch_threads_t **out);
\r
78 * Execute a query for messages, returning a notmuch_messages_t object
\r
79 * which can be used to iterate over the results. The returned
\r
80 @@ -822,10 +827,15 @@ notmuch_query_search_threads (notmuch_query_t *query);
\r
81 * reason to call it if the query is about to be destroyed).
\r
83 * If a Xapian exception occurs this function will return NULL.
\r
84 + * For better error reporting, use the _st variant.
\r
86 notmuch_messages_t *
\r
87 notmuch_query_search_messages (notmuch_query_t *query);
\r
90 +notmuch_query_search_messages_st (notmuch_query_t *query,
\r
91 + notmuch_messages_t **mesages);
\r
94 * Destroy a notmuch_query_t along with any associated resources.
\r
96 diff --git a/lib/query.cc b/lib/query.cc
\r
97 index 60ff8bd..9279915 100644
\r
100 @@ -174,13 +174,26 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)
\r
101 notmuch_messages_t *
\r
102 notmuch_query_search_messages (notmuch_query_t *query)
\r
104 + notmuch_status_t status;
\r
105 + notmuch_messages_t *messages;
\r
106 + status = notmuch_query_search_messages_st (query, &messages);
\r
114 +notmuch_query_search_messages_st (notmuch_query_t *query,
\r
115 + notmuch_messages_t **out)
\r
117 notmuch_database_t *notmuch = query->notmuch;
\r
118 const char *query_string = query->query_string;
\r
119 notmuch_mset_messages_t *messages;
\r
121 messages = talloc (query, notmuch_mset_messages_t);
\r
122 if (unlikely (messages == NULL))
\r
124 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
128 @@ -279,7 +292,8 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
129 messages->iterator = mset.begin ();
\r
130 messages->iterator_end = mset.end ();
\r
132 - return &messages->base;
\r
133 + *out = &messages->base;
\r
134 + return NOTMUCH_STATUS_SUCCESS;
\r
136 } catch (const Xapian::Error &error) {
\r
137 fprintf (stderr, "A Xapian exception occurred performing query: %s\n",
\r
138 @@ -287,7 +301,7 @@ notmuch_query_search_messages (notmuch_query_t *query)
\r
139 fprintf (stderr, "Query string was: %s\n", query->query_string);
\r
140 notmuch->exception_reported = TRUE;
\r
141 talloc_free (messages);
\r
143 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
147 @@ -412,24 +426,39 @@ _notmuch_threads_destructor (notmuch_threads_t *threads)
\r
152 notmuch_threads_t *
\r
153 notmuch_query_search_threads (notmuch_query_t *query)
\r
155 + notmuch_status_t status;
\r
156 + notmuch_threads_t *threads;
\r
157 + status = notmuch_query_search_threads_st (query, &threads);
\r
165 +notmuch_query_search_threads_st (notmuch_query_t *query,
\r
166 + notmuch_threads_t **out)
\r
168 notmuch_threads_t *threads;
\r
169 notmuch_messages_t *messages;
\r
170 + notmuch_status_t status;
\r
172 threads = talloc (query, notmuch_threads_t);
\r
173 if (threads == NULL)
\r
175 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
176 threads->doc_ids = NULL;
\r
177 talloc_set_destructor (threads, _notmuch_threads_destructor);
\r
179 threads->query = query;
\r
181 - messages = notmuch_query_search_messages (query);
\r
182 - if (messages == NULL) {
\r
183 - talloc_free (threads);
\r
185 + status = notmuch_query_search_messages_st (query, &messages);
\r
187 + talloc_free (threads);
\r
191 threads->doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));
\r
192 @@ -445,10 +474,11 @@ notmuch_query_search_threads (notmuch_query_t *query)
\r
193 if (! _notmuch_doc_id_set_init (threads, &threads->match_set,
\r
194 threads->doc_ids)) {
\r
195 talloc_free (threads);
\r
197 + return NOTMUCH_STATUS_OUT_OF_MEMORY;
\r
202 + return NOTMUCH_STATUS_SUCCESS;
\r