Re: Hi all
[notmuch-archives.git] / d2 / bdf46eb9eaf3f47b140d18612b3339b1f914c6
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
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 2.438\r
10 X-Spam-Level: **\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
18         [87.98.215.224])\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
27         07:53:56 -0000\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
37 Precedence: list\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
48 \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
52 \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
55 ---\r
56  lib/notmuch.h | 10 ++++++++++\r
57  lib/query.cc  | 50 ++++++++++++++++++++++++++++++++++++++++----------\r
58  2 files changed, 50 insertions(+), 10 deletions(-)\r
59 \r
60 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
61 index 220839b..58052f1 100644\r
62 --- a/lib/notmuch.h\r
63 +++ b/lib/notmuch.h\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
66   *\r
67   * If a Xapian exception occurs this function will return NULL.\r
68 + * For better error reporting, use the _st variant.\r
69   */\r
70  notmuch_threads_t *\r
71  notmuch_query_search_threads (notmuch_query_t *query);\r
72  \r
73 +notmuch_status_t\r
74 +notmuch_query_search_threads_st (notmuch_query_t *query,\r
75 +                                notmuch_threads_t **out);\r
76 +\r
77  /**\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
82   *\r
83   * If a Xapian exception occurs this function will return NULL.\r
84 + * For better error reporting, use the _st variant.\r
85   */\r
86  notmuch_messages_t *\r
87  notmuch_query_search_messages (notmuch_query_t *query);\r
88  \r
89 +notmuch_status_t\r
90 +notmuch_query_search_messages_st (notmuch_query_t *query,\r
91 +                                 notmuch_messages_t **mesages);\r
92 +\r
93  /**\r
94   * Destroy a notmuch_query_t along with any associated resources.\r
95   *\r
96 diff --git a/lib/query.cc b/lib/query.cc\r
97 index 60ff8bd..9279915 100644\r
98 --- a/lib/query.cc\r
99 +++ b/lib/query.cc\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
103  {\r
104 +    notmuch_status_t status;\r
105 +    notmuch_messages_t *messages;\r
106 +    status = notmuch_query_search_messages_st (query, &messages);\r
107 +    if (status)\r
108 +       return NULL;\r
109 +    else\r
110 +       return messages;\r
111 +}\r
112 +\r
113 +notmuch_status_t\r
114 +notmuch_query_search_messages_st (notmuch_query_t *query,\r
115 +                                 notmuch_messages_t **out)\r
116 +{\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
120  \r
121      messages = talloc (query, notmuch_mset_messages_t);\r
122      if (unlikely (messages == NULL))\r
123 -       return NULL;\r
124 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
125  \r
126      try {\r
127  \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
131  \r
132 -       return &messages->base;\r
133 +       *out = &messages->base;\r
134 +       return NOTMUCH_STATUS_SUCCESS;\r
135  \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
142 -       return NULL;\r
143 +       return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
144      }\r
145  }\r
146  \r
147 @@ -412,24 +426,39 @@ _notmuch_threads_destructor (notmuch_threads_t *threads)\r
148      return 0;\r
149  }\r
150  \r
151 +\r
152  notmuch_threads_t *\r
153  notmuch_query_search_threads (notmuch_query_t *query)\r
154  {\r
155 +    notmuch_status_t status;\r
156 +    notmuch_threads_t *threads;\r
157 +    status = notmuch_query_search_threads_st (query, &threads);\r
158 +    if (status)\r
159 +       return NULL;\r
160 +    else\r
161 +       return threads;\r
162 +}\r
163 +\r
164 +notmuch_status_t\r
165 +notmuch_query_search_threads_st (notmuch_query_t *query,\r
166 +                                notmuch_threads_t **out)\r
167 +{\r
168      notmuch_threads_t *threads;\r
169      notmuch_messages_t *messages;\r
170 +    notmuch_status_t status;\r
171  \r
172      threads = talloc (query, notmuch_threads_t);\r
173      if (threads == NULL)\r
174 -       return 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
178  \r
179      threads->query = query;\r
180  \r
181 -    messages = notmuch_query_search_messages (query);\r
182 -    if (messages == NULL) {\r
183 -           talloc_free (threads);\r
184 -           return NULL;\r
185 +    status = notmuch_query_search_messages_st (query, &messages);\r
186 +    if (status) {\r
187 +       talloc_free (threads);\r
188 +       return status;\r
189      }\r
190  \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
196 -       return NULL;\r
197 +       return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
198      }\r
199  \r
200 -    return threads;\r
201 +    *out = threads;\r
202 +    return NOTMUCH_STATUS_SUCCESS;\r
203  }\r
204  \r
205  void\r
206 -- \r
207 2.1.4\r
208 \r