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