--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 90CE4431FC9\r
+ for <notmuch@notmuchmail.org>; Tue, 20 Jan 2015 03:01:50 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.438\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.438 tagged_above=-999 required=5\r
+ tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id NcPGmERsFl6g for <notmuch@notmuchmail.org>;\r
+ Tue, 20 Jan 2015 03:01:47 -0800 (PST)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 8CF0F431FC3\r
+ for <notmuch@notmuchmail.org>; Tue, 20 Jan 2015 03:01:32 -0800 (PST)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 1430F1000E0;\r
+ Tue, 20 Jan 2015 13:01:07 +0200 (EET)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] lib: add new status reporting API\r
+ for notmuch_query_search_{m, t}\r
+In-Reply-To: <1421740421-10401-1-git-send-email-david@tethera.net>\r
+References: <1421740421-10401-1-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.19+29~g7367d27 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Tue, 20 Jan 2015 13:01:06 +0200\r
+Message-ID: <m2a91dbtsd.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 20 Jan 2015 11:01:50 -0000\r
+\r
+On Tue, Jan 20 2015, David Bremner <david@tethera.net> wrote:\r
+\r
+> This at least allows distinguishing between out of memory and Xapian\r
+> exceptions. Adding finer grained status codes would allow different\r
+> Xapian exceptions to be preserved.\r
+>\r
+> Adding wrappers allows people to transition gradually to the new API,\r
+> at the cost of bloating the library API a bit.\r
+> ---\r
+> lib/notmuch.h | 10 ++++++++++\r
+> lib/query.cc | 50 ++++++++++++++++++++++++++++++++++++++++----------\r
+> 2 files changed, 50 insertions(+), 10 deletions(-)\r
+>\r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index 220839b..58052f1 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -780,10 +780,15 @@ notmuch_query_add_tag_exclude (notmuch_query_t *query, const char *tag);\r
+> * to call it if the query is about to be destroyed).\r
+> *\r
+> * If a Xapian exception occurs this function will return NULL.\r
+> + * For better error reporting, use the _st variant.\r
+> */\r
+> notmuch_threads_t *\r
+> notmuch_query_search_threads (notmuch_query_t *query);\r
+> \r
+> +notmuch_status_t\r
+> +notmuch_query_search_threads_st (notmuch_query_t *query,\r
+> + notmuch_threads_t **out);\r
+> +\r
+> /**\r
+> * Execute a query for messages, returning a notmuch_messages_t object\r
+> * which can be used to iterate over the results. The returned\r
+> @@ -822,10 +827,15 @@ notmuch_query_search_threads (notmuch_query_t *query);\r
+> * reason to call it if the query is about to be destroyed).\r
+> *\r
+> * If a Xapian exception occurs this function will return NULL.\r
+> + * For better error reporting, use the _st variant.\r
+> */\r
+> notmuch_messages_t *\r
+> notmuch_query_search_messages (notmuch_query_t *query);\r
+> \r
+> +notmuch_status_t\r
+> +notmuch_query_search_messages_st (notmuch_query_t *query,\r
+> + notmuch_messages_t **mesages);\r
+\r
+prototype has **mesages, definition **out ;D -- otherwise looks pretty good.\r
+\r
+Tomi\r
+\r
+> +\r
+> /**\r
+> * Destroy a notmuch_query_t along with any associated resources.\r
+> *\r
+> diff --git a/lib/query.cc b/lib/query.cc\r
+> index 60ff8bd..9279915 100644\r
+> --- a/lib/query.cc\r
+> +++ b/lib/query.cc\r
+> @@ -174,13 +174,26 @@ _notmuch_exclude_tags (notmuch_query_t *query, Xapian::Query xquery)\r
+> notmuch_messages_t *\r
+> notmuch_query_search_messages (notmuch_query_t *query)\r
+> {\r
+> + notmuch_status_t status;\r
+> + notmuch_messages_t *messages;\r
+> + status = notmuch_query_search_messages_st (query, &messages);\r
+> + if (status)\r
+> + return NULL;\r
+> + else\r
+> + return messages;\r
+> +}\r
+> +\r
+> +notmuch_status_t\r
+> +notmuch_query_search_messages_st (notmuch_query_t *query,\r
+> + notmuch_messages_t **out)\r
+> +{\r
+> notmuch_database_t *notmuch = query->notmuch;\r
+> const char *query_string = query->query_string;\r
+> notmuch_mset_messages_t *messages;\r
+> \r
+> messages = talloc (query, notmuch_mset_messages_t);\r
+> if (unlikely (messages == NULL))\r
+> - return NULL;\r
+> + return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+> \r
+> try {\r
+> \r
+> @@ -279,7 +292,8 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+> messages->iterator = mset.begin ();\r
+> messages->iterator_end = mset.end ();\r
+> \r
+> - return &messages->base;\r
+> + *out = &messages->base;\r
+> + return NOTMUCH_STATUS_SUCCESS;\r
+> \r
+> } catch (const Xapian::Error &error) {\r
+> fprintf (stderr, "A Xapian exception occurred performing query: %s\n",\r
+> @@ -287,7 +301,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+> fprintf (stderr, "Query string was: %s\n", query->query_string);\r
+> notmuch->exception_reported = TRUE;\r
+> talloc_free (messages);\r
+> - return NULL;\r
+> + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+> }\r
+> }\r
+> \r
+> @@ -412,24 +426,39 @@ _notmuch_threads_destructor (notmuch_threads_t *threads)\r
+> return 0;\r
+> }\r
+> \r
+> +\r
+> notmuch_threads_t *\r
+> notmuch_query_search_threads (notmuch_query_t *query)\r
+> {\r
+> + notmuch_status_t status;\r
+> + notmuch_threads_t *threads;\r
+> + status = notmuch_query_search_threads_st (query, &threads);\r
+> + if (status)\r
+> + return NULL;\r
+> + else\r
+> + return threads;\r
+> +}\r
+> +\r
+> +notmuch_status_t\r
+> +notmuch_query_search_threads_st (notmuch_query_t *query,\r
+> + notmuch_threads_t **out)\r
+> +{\r
+> notmuch_threads_t *threads;\r
+> notmuch_messages_t *messages;\r
+> + notmuch_status_t status;\r
+> \r
+> threads = talloc (query, notmuch_threads_t);\r
+> if (threads == NULL)\r
+> - return NULL;\r
+> + return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+> threads->doc_ids = NULL;\r
+> talloc_set_destructor (threads, _notmuch_threads_destructor);\r
+> \r
+> threads->query = query;\r
+> \r
+> - messages = notmuch_query_search_messages (query);\r
+> - if (messages == NULL) {\r
+> - talloc_free (threads);\r
+> - return NULL;\r
+> + status = notmuch_query_search_messages_st (query, &messages);\r
+> + if (status) {\r
+> + talloc_free (threads);\r
+> + return status;\r
+> }\r
+> \r
+> threads->doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
+> @@ -445,10 +474,11 @@ notmuch_query_search_threads (notmuch_query_t *query)\r
+> if (! _notmuch_doc_id_set_init (threads, &threads->match_set,\r
+> threads->doc_ids)) {\r
+> talloc_free (threads);\r
+> - return NULL;\r
+> + return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+> }\r
+> \r
+> - return threads;\r
+> + *out = threads;\r
+> + return NOTMUCH_STATUS_SUCCESS;\r
+> }\r
+> \r
+> void\r
+> -- \r
+> 2.1.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r