unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] lib: add new status reporting API for notmuch_query_search_{m,t}
@ 2015-01-20  7:53 David Bremner
  2015-01-20 11:01 ` [PATCH] lib: add new status reporting API for notmuch_query_search_{m, t} Tomi Ollila
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Bremner @ 2015-01-20  7:53 UTC (permalink / raw)
  To: notmuch

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);
+
 /**
  * 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib: add new status reporting API for notmuch_query_search_{m, t}
  2015-01-20  7:53 [PATCH] lib: add new status reporting API for notmuch_query_search_{m,t} David Bremner
@ 2015-01-20 11:01 ` Tomi Ollila
  2015-02-28  8:41 ` [PATCH] lib: bump SONAME minor version David Bremner
  2015-03-01  8:04 ` [PATCH] lib: add new status reporting API for notmuch_query_search_{m,t} David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: Tomi Ollila @ 2015-01-20 11:01 UTC (permalink / raw)
  To: David Bremner, notmuch

On Tue, Jan 20 2015, David Bremner <david@tethera.net> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] lib: bump SONAME minor version
  2015-01-20  7:53 [PATCH] lib: add new status reporting API for notmuch_query_search_{m,t} David Bremner
  2015-01-20 11:01 ` [PATCH] lib: add new status reporting API for notmuch_query_search_{m, t} Tomi Ollila
@ 2015-02-28  8:41 ` David Bremner
  2015-03-01  8:04 ` [PATCH] lib: add new status reporting API for notmuch_query_search_{m,t} David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2015-02-28  8:41 UTC (permalink / raw)
  To: David Bremner, notmuch

This indicates upwardly compatible changes, namely adding new symbols.

Although we don't formally need to do this until the next release,
there is no hard in doing it now, as long as we don't bump the minor
version for every addition between now and the release.
---
 lib/Makefile.local | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/Makefile.local b/lib/Makefile.local
index 4120390..7278f46 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -11,7 +11,7 @@ LIBNOTMUCH_VERSION_MAJOR = 4
 # the time of release for any additions to the library interface,
 # (and when it is incremented, the release version of the library should
 #  be reset to 0).
-LIBNOTMUCH_VERSION_MINOR = 1
+LIBNOTMUCH_VERSION_MINOR = 2
 
 # The release version the library interface. This should be incremented at
 # the time of release if there have been no changes to the interface, (but
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] lib: add new status reporting API for notmuch_query_search_{m,t}
  2015-01-20  7:53 [PATCH] lib: add new status reporting API for notmuch_query_search_{m,t} David Bremner
  2015-01-20 11:01 ` [PATCH] lib: add new status reporting API for notmuch_query_search_{m, t} Tomi Ollila
  2015-02-28  8:41 ` [PATCH] lib: bump SONAME minor version David Bremner
@ 2015-03-01  8:04 ` David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2015-03-01  8:04 UTC (permalink / raw)
  To: notmuch

David Bremner <david@tethera.net> writes:

> 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.

Merged to master. Please send any complaints about the name ASAP, rather
than after people start using it.

d

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-03-02 18:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-20  7:53 [PATCH] lib: add new status reporting API for notmuch_query_search_{m,t} David Bremner
2015-01-20 11:01 ` [PATCH] lib: add new status reporting API for notmuch_query_search_{m, t} Tomi Ollila
2015-02-28  8:41 ` [PATCH] lib: bump SONAME minor version David Bremner
2015-03-01  8:04 ` [PATCH] lib: add new status reporting API for notmuch_query_search_{m,t} David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).