Re: [PATCH v4 08/16] reorganize indexing of multipart/signed and multipart/encrypted
[notmuch-archives.git] / 74 / a64d66b61e3fc0e598609ad15aef91b3729b59
1 Return-Path: <tomi.ollila@iki.fi>\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 90CE4431FC9\r
6         for <notmuch@notmuchmail.org>; Tue, 20 Jan 2015 03:01:50 -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 NcPGmERsFl6g for <notmuch@notmuchmail.org>;\r
16         Tue, 20 Jan 2015 03:01:47 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 8CF0F431FC3\r
19         for <notmuch@notmuchmail.org>; Tue, 20 Jan 2015 03:01:32 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 1430F1000E0;\r
22         Tue, 20 Jan 2015 13:01:07 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH] lib: add new status reporting API\r
26         for     notmuch_query_search_{m, t}\r
27 In-Reply-To: <1421740421-10401-1-git-send-email-david@tethera.net>\r
28 References: <1421740421-10401-1-git-send-email-david@tethera.net>\r
29 User-Agent: Notmuch/0.19+29~g7367d27 (http://notmuchmail.org) Emacs/24.3.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Tue, 20 Jan 2015 13:01:06 +0200\r
35 Message-ID: <m2a91dbtsd.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Tue, 20 Jan 2015 11:01:50 -0000\r
51 \r
52 On Tue, Jan 20 2015, David Bremner <david@tethera.net> wrote:\r
53 \r
54 > This at least allows distinguishing between out of memory and Xapian\r
55 > exceptions. Adding finer grained status codes would allow different\r
56 > Xapian exceptions to be preserved.\r
57 >\r
58 > Adding wrappers allows people to transition gradually to the new API,\r
59 > at the cost of bloating the library API a bit.\r
60 > ---\r
61 >  lib/notmuch.h | 10 ++++++++++\r
62 >  lib/query.cc  | 50 ++++++++++++++++++++++++++++++++++++++++----------\r
63 >  2 files changed, 50 insertions(+), 10 deletions(-)\r
64 >\r
65 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
66 > index 220839b..58052f1 100644\r
67 > --- a/lib/notmuch.h\r
68 > +++ b/lib/notmuch.h\r
69 > @@ -780,10 +780,15 @@ notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);\r
70 >   * to call it if the query is about to be destroyed).\r
71 >   *\r
72 >   * If a Xapian exception occurs this function will return NULL.\r
73 > + * For better error reporting, use the _st variant.\r
74 >   */\r
75 >  notmuch_threads_t *\r
76 >  notmuch_query_search_threads (notmuch_query_t *query);\r
77 >  \r
78 > +notmuch_status_t\r
79 > +notmuch_query_search_threads_st (notmuch_query_t *query,\r
80 > +                              notmuch_threads_t **out);\r
81 > +\r
82 >  /**\r
83 >   * Execute a query for messages, returning a notmuch_messages_t object\r
84 >   * which can be used to iterate over the results. The returned\r
85 > @@ -822,10 +827,15 @@ notmuch_query_search_threads (notmuch_query_t *query);\r
86 >   * reason to call it if the query is about to be destroyed).\r
87 >   *\r
88 >   * If a Xapian exception occurs this function will return NULL.\r
89 > + * For better error reporting, use the _st variant.\r
90 >   */\r
91 >  notmuch_messages_t *\r
92 >  notmuch_query_search_messages (notmuch_query_t *query);\r
93 >  \r
94 > +notmuch_status_t\r
95 > +notmuch_query_search_messages_st (notmuch_query_t *query,\r
96 > +                               notmuch_messages_t **mesages);\r
97 \r
98 prototype has **mesages, definition **out ;D -- otherwise looks pretty good.\r
99 \r
100 Tomi\r
101 \r
102 > +\r
103 >  /**\r
104 >   * Destroy a notmuch_query_t along with any associated resources.\r
105 >   *\r
106 > diff --git a/lib/query.cc b/lib/query.cc\r
107 > index 60ff8bd..9279915 100644\r
108 > --- a/lib/query.cc\r
109 > +++ b/lib/query.cc\r
110 > @@ -174,13 +174,26 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
111 >  notmuch_messages_t *\r
112 >  notmuch_query_search_messages (notmuch_query_t *query)\r
113 >  {\r
114 > +    notmuch_status_t status;\r
115 > +    notmuch_messages_t *messages;\r
116 > +    status = notmuch_query_search_messages_st (query, &messages);\r
117 > +    if (status)\r
118 > +     return NULL;\r
119 > +    else\r
120 > +     return messages;\r
121 > +}\r
122 > +\r
123 > +notmuch_status_t\r
124 > +notmuch_query_search_messages_st (notmuch_query_t *query,\r
125 > +                               notmuch_messages_t **out)\r
126 > +{\r
127 >      notmuch_database_t *notmuch = query->notmuch;\r
128 >      const char *query_string = query->query_string;\r
129 >      notmuch_mset_messages_t *messages;\r
130 >  \r
131 >      messages = talloc (query, notmuch_mset_messages_t);\r
132 >      if (unlikely (messages == NULL))\r
133 > -     return NULL;\r
134 > +     return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
135 >  \r
136 >      try {\r
137 >  \r
138 > @@ -279,7 +292,8 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
139 >       messages->iterator = mset.begin ();\r
140 >       messages->iterator_end = mset.end ();\r
141 >  \r
142 > -     return &messages->base;\r
143 > +     *out = &messages->base;\r
144 > +     return NOTMUCH_STATUS_SUCCESS;\r
145 >  \r
146 >      } catch (const Xapian::Error &error) {\r
147 >       fprintf (stderr, "A Xapian exception occurred performing query: %s\n",\r
148 > @@ -287,7 +301,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
149 >       fprintf (stderr, "Query string was: %s\n", query->query_string);\r
150 >       notmuch->exception_reported = TRUE;\r
151 >       talloc_free (messages);\r
152 > -     return NULL;\r
153 > +     return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
154 >      }\r
155 >  }\r
156 >  \r
157 > @@ -412,24 +426,39 @@ _notmuch_threads_destructor (notmuch_threads_t *threads)\r
158 >      return 0;\r
159 >  }\r
160 >  \r
161 > +\r
162 >  notmuch_threads_t *\r
163 >  notmuch_query_search_threads (notmuch_query_t *query)\r
164 >  {\r
165 > +    notmuch_status_t status;\r
166 > +    notmuch_threads_t *threads;\r
167 > +    status = notmuch_query_search_threads_st (query, &threads);\r
168 > +    if (status)\r
169 > +     return NULL;\r
170 > +    else\r
171 > +     return threads;\r
172 > +}\r
173 > +\r
174 > +notmuch_status_t\r
175 > +notmuch_query_search_threads_st (notmuch_query_t *query,\r
176 > +                              notmuch_threads_t **out)\r
177 > +{\r
178 >      notmuch_threads_t *threads;\r
179 >      notmuch_messages_t *messages;\r
180 > +    notmuch_status_t status;\r
181 >  \r
182 >      threads = talloc (query, notmuch_threads_t);\r
183 >      if (threads == NULL)\r
184 > -     return NULL;\r
185 > +     return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
186 >      threads->doc_ids = NULL;\r
187 >      talloc_set_destructor (threads, _notmuch_threads_destructor);\r
188 >  \r
189 >      threads->query = query;\r
190 >  \r
191 > -    messages = notmuch_query_search_messages (query);\r
192 > -    if (messages == NULL) {\r
193 > -         talloc_free (threads);\r
194 > -         return NULL;\r
195 > +    status = notmuch_query_search_messages_st (query, &messages);\r
196 > +    if (status) {\r
197 > +     talloc_free (threads);\r
198 > +     return status;\r
199 >      }\r
200 >  \r
201 >      threads->doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
202 > @@ -445,10 +474,11 @@ notmuch_query_search_threads (notmuch_query_t *query)\r
203 >      if (! _notmuch_doc_id_set_init (threads, &threads->match_set,\r
204 >                                   threads->doc_ids)) {\r
205 >       talloc_free (threads);\r
206 > -     return NULL;\r
207 > +     return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
208 >      }\r
209 >  \r
210 > -    return threads;\r
211 > +    *out = threads;\r
212 > +    return NOTMUCH_STATUS_SUCCESS;\r
213 >  }\r
214 >  \r
215 >  void\r
216 > -- \r
217 > 2.1.4\r
218 >\r
219 > _______________________________________________\r
220 > notmuch mailing list\r
221 > notmuch@notmuchmail.org\r
222 > http://notmuchmail.org/mailman/listinfo/notmuch\r