* [Patch v4 1/9] lib: move query variable to function scope
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
@ 2015-09-27 15:31 ` David Bremner
2015-09-27 15:31 ` [Patch v4 2/9] cli/count: simplify and document return value of print_count David Bremner
` (8 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: David Bremner @ 2015-09-27 15:31 UTC (permalink / raw)
To: notmuch
This is a prelude to deallocating it (if necessary) on the error path.
---
lib/database.cc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/database.cc b/lib/database.cc
index 6d0e5a6..dcfad8c 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1372,6 +1372,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
enum _notmuch_features target_features, new_features;
notmuch_status_t status;
notmuch_private_status_t private_status;
+ notmuch_query_t *query = NULL;
unsigned int count = 0, total = 0;
status = _notmuch_database_ensure_writable (notmuch);
@@ -1408,7 +1409,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
if (new_features &
(NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
NOTMUCH_FEATURE_LAST_MOD)) {
- notmuch_query_t *query = notmuch_query_create (notmuch, "");
+ query = notmuch_query_create (notmuch, "");
total += notmuch_query_count_messages (query);
notmuch_query_destroy (query);
}
@@ -1436,11 +1437,12 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
if (new_features &
(NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
NOTMUCH_FEATURE_LAST_MOD)) {
- notmuch_query_t *query = notmuch_query_create (notmuch, "");
notmuch_messages_t *messages;
notmuch_message_t *message;
char *filename;
+ query = notmuch_query_create (notmuch, "");
+
/* XXX: this should use the _st version, but needs an error
path */
for (messages = notmuch_query_search_messages (query);
--
2.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Patch v4 2/9] cli/count: simplify and document return value of print_count
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
2015-09-27 15:31 ` [Patch v4 1/9] lib: move query variable to function scope David Bremner
@ 2015-09-27 15:31 ` David Bremner
2015-09-27 15:31 ` [Patch v4 3/9] lib: add versions of n_q_count_{message, threads} with status return David Bremner
` (7 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: David Bremner @ 2015-09-27 15:31 UTC (permalink / raw)
To: notmuch
Essentially a cosmetic change.
---
notmuch-count.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/notmuch-count.c b/notmuch-count.c
index 09613e6..be3e236 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -67,6 +67,7 @@ count_files (notmuch_query_t *query)
return count;
}
+/* return 0 on success, -1 on failure */
static int
print_count (notmuch_database_t *notmuch, const char *query_str,
const char **exclude_tags, size_t exclude_tags_length, int output, int print_lastmod)
@@ -81,7 +82,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
query = notmuch_query_create (notmuch, query_str);
if (query == NULL) {
fprintf (stderr, "Out of memory\n");
- return 1;
+ return -1;
}
for (i = 0; i < exclude_tags_length; i++)
--
2.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Patch v4 3/9] lib: add versions of n_q_count_{message, threads} with status return
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
2015-09-27 15:31 ` [Patch v4 1/9] lib: move query variable to function scope David Bremner
2015-09-27 15:31 ` [Patch v4 2/9] cli/count: simplify and document return value of print_count David Bremner
@ 2015-09-27 15:31 ` David Bremner
2015-10-05 18:22 ` Jani Nikula
2015-09-27 15:31 ` [Patch v4 4/9] cli: update to use new count API David Bremner
` (6 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: David Bremner @ 2015-09-27 15:31 UTC (permalink / raw)
To: notmuch
Although I think it's a pretty bad idea to continue using the old API,
this allows both a more gentle transition for clients of the library,
and allows us to break one monolithic change into a series
---
lib/database.cc | 13 ++++++++++++-
lib/notmuch.h | 48 ++++++++++++++++++++++++++++++++++++++++++------
lib/query.cc | 47 +++++++++++++++++++++++++++++++++--------------
3 files changed, 87 insertions(+), 21 deletions(-)
diff --git a/lib/database.cc b/lib/database.cc
index dcfad8c..f39d448 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1410,8 +1410,15 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
(NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
NOTMUCH_FEATURE_LAST_MOD)) {
query = notmuch_query_create (notmuch, "");
- total += notmuch_query_count_messages (query);
+ unsigned msg_count;
+
+ status = notmuch_query_count_messages_st (query, &msg_count);
+ if (status)
+ goto DONE;
+
+ total += msg_count;
notmuch_query_destroy (query);
+ query = NULL;
}
if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
t_end = db->allterms_end ("XTIMESTAMP");
@@ -1492,6 +1499,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
}
notmuch_query_destroy (query);
+ query = NULL;
}
/* Perform per-directory upgrades. */
@@ -1612,6 +1620,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
sigaction (SIGALRM, &action, NULL);
}
+ if (query)
+ notmuch_query_destroy (query);
+
talloc_free (local);
return status;
}
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 8775683..2fb778b 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -984,10 +984,26 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
* This function performs a search and returns the number of matching
* messages.
*
- * If a Xapian exception occurs, this function may return 0 (after
- * printing a message).
+ * @returns
+ *
+ * NOTMUCH_STATUS_SUCCESS: query complete successfully.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
+ * value of *count is not defined.
*/
-unsigned
+notmuch_status_t
+notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);
+
+/**
+ * like notmuch_query_count_messages_st, but without a status return
+ *
+ * May return 0 in the case of errors.
+ *
+ * @deprecated Deprecated since libnotmuch 4.3 (notmuch 0.21). Please
+ * use notmuch_query_count_messages_st instead.
+ */
+NOTMUCH_DEPRECATED(4,3)
+unsigned int
notmuch_query_count_messages (notmuch_query_t *query);
/**
@@ -998,11 +1014,31 @@ notmuch_query_count_messages (notmuch_query_t *query);
* search.
*
* Note that this is a significantly heavier operation than
- * notmuch_query_count_messages().
+ * notmuch_query_count_messages{_st}().
+ *
+ * @returns
*
- * If an error occurs, this function may return 0.
+ * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
+ * of *count is not defined
+
+ * NOTMUCH_STATUS_SUCCESS: query complete successfully.
+ *
+ * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
+ * value of *count is not defined.
*/
-unsigned
+notmuch_status_t
+notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);
+
+/**
+ * like notmuch_query_count_threads, but without a status return.
+ *
+ * May return 0 in case of errors.
+ *
+ * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please
+ * use notmuch_query_count_threads_st instead.
+ */
+NOTMUCH_DEPRECATED(4,3)
+unsigned int
notmuch_query_count_threads (notmuch_query_t *query);
/**
diff --git a/lib/query.cc b/lib/query.cc
index 8cf0a07..e627bfc 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -541,9 +541,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)
talloc_free (threads);
}
-unsigned
+unsigned int
notmuch_query_count_messages (notmuch_query_t *query)
{
+ notmuch_status_t status;
+ unsigned int count;
+
+ status = notmuch_query_count_messages_st (query, &count);
+ return status ? 0 : count;
+}
+
+notmuch_status_t
+notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)
+{
notmuch_database_t *notmuch = query->notmuch;
const char *query_string = query->query_string;
Xapian::doccount count = 0;
@@ -605,35 +615,44 @@ notmuch_query_count_messages (notmuch_query_t *query)
"Query string was: %s\n",
error.get_msg().c_str(),
query->query_string);
-
+ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
- return count;
+ *count_out = count;
+ return NOTMUCH_STATUS_SUCCESS;
}
unsigned
notmuch_query_count_threads (notmuch_query_t *query)
{
+ notmuch_status_t status;
+ unsigned int count;
+
+ status = notmuch_query_count_threads_st (query, &count);
+ return status ? 0 : count;
+}
+
+notmuch_status_t
+notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)
+{
notmuch_messages_t *messages;
GHashTable *hash;
- unsigned int count;
notmuch_sort_t sort;
- notmuch_status_t status;
+ notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
sort = query->sort;
query->sort = NOTMUCH_SORT_UNSORTED;
- status = notmuch_query_search_messages_st (query, &messages);
- if (status)
- return 0;
-
+ ret = notmuch_query_search_messages_st (query, &messages);
+ if (ret)
+ return ret;
query->sort = sort;
if (messages == NULL)
- return 0;
+ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
if (hash == NULL) {
talloc_free (messages);
- return 0;
+ return NOTMUCH_STATUS_OUT_OF_MEMORY;
}
while (notmuch_messages_valid (messages)) {
@@ -642,7 +661,7 @@ notmuch_query_count_threads (notmuch_query_t *query)
char *thread_id_copy = talloc_strdup (messages, thread_id);
if (unlikely (thread_id_copy == NULL)) {
notmuch_message_destroy (message);
- count = 0;
+ ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;
}
g_hash_table_insert (hash, thread_id_copy, NULL);
@@ -650,13 +669,13 @@ notmuch_query_count_threads (notmuch_query_t *query)
notmuch_messages_move_to_next (messages);
}
- count = g_hash_table_size (hash);
+ *count = g_hash_table_size (hash);
DONE:
g_hash_table_unref (hash);
talloc_free (messages);
- return count;
+ return ret;
}
notmuch_database_t *
--
2.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Patch v4 3/9] lib: add versions of n_q_count_{message, threads} with status return
2015-09-27 15:31 ` [Patch v4 3/9] lib: add versions of n_q_count_{message, threads} with status return David Bremner
@ 2015-10-05 18:22 ` Jani Nikula
0 siblings, 0 replies; 15+ messages in thread
From: Jani Nikula @ 2015-10-05 18:22 UTC (permalink / raw)
To: David Bremner, notmuch
On Sun, 27 Sep 2015, David Bremner <david@tethera.net> wrote:
> Although I think it's a pretty bad idea to continue using the old API,
> this allows both a more gentle transition for clients of the library,
> and allows us to break one monolithic change into a series
Mostly looks as good as it gets (who would say C makes error handling
like this look good?!), a few nitpicks inline below, up to your
discretion.
BR,
Jani.
> ---
> lib/database.cc | 13 ++++++++++++-
> lib/notmuch.h | 48 ++++++++++++++++++++++++++++++++++++++++++------
> lib/query.cc | 47 +++++++++++++++++++++++++++++++++--------------
> 3 files changed, 87 insertions(+), 21 deletions(-)
>
> diff --git a/lib/database.cc b/lib/database.cc
> index dcfad8c..f39d448 100644
> --- a/lib/database.cc
> +++ b/lib/database.cc
> @@ -1410,8 +1410,15 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
> (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |
> NOTMUCH_FEATURE_LAST_MOD)) {
> query = notmuch_query_create (notmuch, "");
> - total += notmuch_query_count_messages (query);
> + unsigned msg_count;
> +
> + status = notmuch_query_count_messages_st (query, &msg_count);
> + if (status)
> + goto DONE;
> +
> + total += msg_count;
> notmuch_query_destroy (query);
> + query = NULL;
> }
> if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {
> t_end = db->allterms_end ("XTIMESTAMP");
> @@ -1492,6 +1499,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
> }
>
> notmuch_query_destroy (query);
> + query = NULL;
> }
>
> /* Perform per-directory upgrades. */
> @@ -1612,6 +1620,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
> sigaction (SIGALRM, &action, NULL);
> }
>
> + if (query)
> + notmuch_query_destroy (query);
> +
> talloc_free (local);
> return status;
> }
> diff --git a/lib/notmuch.h b/lib/notmuch.h
> index 8775683..2fb778b 100644
> --- a/lib/notmuch.h
> +++ b/lib/notmuch.h
> @@ -984,10 +984,26 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
> * This function performs a search and returns the number of matching
> * messages.
> *
> - * If a Xapian exception occurs, this function may return 0 (after
> - * printing a message).
> + * @returns
> + *
> + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
complete_d_?
> + *
> + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
> + * value of *count is not defined.
> */
> -unsigned
> +notmuch_status_t
> +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);
I'd use "unsigned int", but matter of style.
Do we care about documenting at which versions the new functions have
been introduced? Doxygen supports @since.
> +
> +/**
> + * like notmuch_query_count_messages_st, but without a status return
Period at the end.
> + *
> + * May return 0 in the case of errors.
> + *
> + * @deprecated Deprecated since libnotmuch 4.3 (notmuch 0.21). Please
> + * use notmuch_query_count_messages_st instead.
> + */
> +NOTMUCH_DEPRECATED(4,3)
> +unsigned int
> notmuch_query_count_messages (notmuch_query_t *query);
>
> /**
> @@ -998,11 +1014,31 @@ notmuch_query_count_messages (notmuch_query_t *query);
> * search.
> *
> * Note that this is a significantly heavier operation than
> - * notmuch_query_count_messages().
> + * notmuch_query_count_messages{_st}().
I think doxygen can do some hyperlinking here if you use the proper
function name(s). On output formats we don't use, but anyway...
> + *
> + * @returns
> *
> - * If an error occurs, this function may return 0.
> + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value
> + * of *count is not defined
> +
> + * NOTMUCH_STATUS_SUCCESS: query complete successfully.
complete_d_?
> + *
> + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The
> + * value of *count is not defined.
> */
> -unsigned
> +notmuch_status_t
> +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);
> +
> +/**
> + * like notmuch_query_count_threads, but without a status return.
> + *
> + * May return 0 in case of errors.
> + *
> + * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please
> + * use notmuch_query_count_threads_st instead.
> + */
> +NOTMUCH_DEPRECATED(4,3)
> +unsigned int
> notmuch_query_count_threads (notmuch_query_t *query);
>
> /**
> diff --git a/lib/query.cc b/lib/query.cc
> index 8cf0a07..e627bfc 100644
> --- a/lib/query.cc
> +++ b/lib/query.cc
> @@ -541,9 +541,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)
> talloc_free (threads);
> }
>
> -unsigned
> +unsigned int
> notmuch_query_count_messages (notmuch_query_t *query)
> {
> + notmuch_status_t status;
> + unsigned int count;
> +
> + status = notmuch_query_count_messages_st (query, &count);
> + return status ? 0 : count;
> +}
> +
> +notmuch_status_t
> +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)
> +{
> notmuch_database_t *notmuch = query->notmuch;
> const char *query_string = query->query_string;
> Xapian::doccount count = 0;
> @@ -605,35 +615,44 @@ notmuch_query_count_messages (notmuch_query_t *query)
> "Query string was: %s\n",
> error.get_msg().c_str(),
> query->query_string);
> -
> + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
> }
>
> - return count;
> + *count_out = count;
> + return NOTMUCH_STATUS_SUCCESS;
> }
>
> unsigned
> notmuch_query_count_threads (notmuch_query_t *query)
> {
> + notmuch_status_t status;
> + unsigned int count;
> +
> + status = notmuch_query_count_threads_st (query, &count);
> + return status ? 0 : count;
> +}
> +
> +notmuch_status_t
> +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)
> +{
> notmuch_messages_t *messages;
> GHashTable *hash;
> - unsigned int count;
> notmuch_sort_t sort;
> - notmuch_status_t status;
> + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
>
> sort = query->sort;
> query->sort = NOTMUCH_SORT_UNSORTED;
> - status = notmuch_query_search_messages_st (query, &messages);
> - if (status)
> - return 0;
> -
> + ret = notmuch_query_search_messages_st (query, &messages);
> + if (ret)
> + return ret;
> query->sort = sort;
> if (messages == NULL)
> - return 0;
> + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
>
> hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
> if (hash == NULL) {
> talloc_free (messages);
> - return 0;
> + return NOTMUCH_STATUS_OUT_OF_MEMORY;
> }
>
> while (notmuch_messages_valid (messages)) {
> @@ -642,7 +661,7 @@ notmuch_query_count_threads (notmuch_query_t *query)
> char *thread_id_copy = talloc_strdup (messages, thread_id);
> if (unlikely (thread_id_copy == NULL)) {
> notmuch_message_destroy (message);
> - count = 0;
> + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;
> goto DONE;
> }
> g_hash_table_insert (hash, thread_id_copy, NULL);
> @@ -650,13 +669,13 @@ notmuch_query_count_threads (notmuch_query_t *query)
> notmuch_messages_move_to_next (messages);
> }
>
> - count = g_hash_table_size (hash);
> + *count = g_hash_table_size (hash);
>
> DONE:
> g_hash_table_unref (hash);
> talloc_free (messages);
>
> - return count;
> + return ret;
> }
>
> notmuch_database_t *
> --
> 2.5.3
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Patch v4 4/9] cli: update to use new count API
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
` (2 preceding siblings ...)
2015-09-27 15:31 ` [Patch v4 3/9] lib: add versions of n_q_count_{message, threads} with status return David Bremner
@ 2015-09-27 15:31 ` David Bremner
2015-10-05 18:25 ` Jani Nikula
2015-09-27 15:31 ` [Patch v4 5/9] ruby: " David Bremner
` (5 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: David Bremner @ 2015-09-27 15:31 UTC (permalink / raw)
To: notmuch
Essentially replace each call to notmuch_count_* with the corresponding
_st call, followed by print_status_query.
---
notmuch-count.c | 12 ++++++++++--
notmuch-reply.c | 7 ++++++-
notmuch-search.c | 16 ++++++++++++++--
notmuch-show.c | 7 ++++++-
4 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/notmuch-count.c b/notmuch-count.c
index be3e236..0b6e6f5 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -75,9 +75,11 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
notmuch_query_t *query;
size_t i;
int count;
+ unsigned int ucount;
unsigned long revision;
const char *uuid;
int ret = 0;
+ notmuch_status_t status;
query = notmuch_query_create (notmuch, query_str);
if (query == NULL) {
@@ -90,10 +92,16 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
switch (output) {
case OUTPUT_MESSAGES:
- printf ("%u", notmuch_query_count_messages (query));
+ status = notmuch_query_count_messages_st (query, &ucount);
+ if (print_status_query ("notmuch count", query, status))
+ return -1;
+ printf ("%u", ucount);
break;
case OUTPUT_THREADS:
- printf ("%u", notmuch_query_count_threads (query));
+ status = notmuch_query_count_threads_st (query, &ucount);
+ if (print_status_query ("notmuch count", query, status))
+ return -1;
+ printf ("%u", ucount);
break;
case OUTPUT_FILES:
count = count_files (query);
diff --git a/notmuch-reply.c b/notmuch-reply.c
index fd6a1ec..1357142 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -655,9 +655,14 @@ notmuch_reply_format_sprinter(void *ctx,
notmuch_messages_t *messages;
notmuch_message_t *message;
mime_node_t *node;
+ unsigned count;
notmuch_status_t status;
- if (notmuch_query_count_messages (query) != 1) {
+ status = notmuch_query_count_messages_st (query, &count);
+ if (print_status_query ("notmuch reply", query, status))
+ return 1;
+
+ if (count != 1) {
fprintf (stderr, "Error: search term did not match precisely one message.\n");
return 1;
}
diff --git a/notmuch-search.c b/notmuch-search.c
index 44e582c..6d08c25 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -121,7 +121,13 @@ do_search_threads (search_context_t *ctx)
notmuch_status_t status;
if (ctx->offset < 0) {
- ctx->offset += notmuch_query_count_threads (ctx->query);
+ unsigned count;
+ notmuch_status_t status;
+ status = notmuch_query_count_threads_st (ctx->query, &count);
+ if (print_status_query ("notmuch search", ctx->query, status))
+ return 1;
+
+ ctx->offset += count;
if (ctx->offset < 0)
ctx->offset = 0;
}
@@ -521,7 +527,13 @@ do_search_messages (search_context_t *ctx)
notmuch_status_t status;
if (ctx->offset < 0) {
- ctx->offset += notmuch_query_count_messages (ctx->query);
+ unsigned count;
+ notmuch_status_t status;
+ status = notmuch_query_count_messages_st (ctx->query, &count);
+ if (print_status_query ("notmuch search", ctx->query, status))
+ return 1;
+
+ ctx->offset += count;
if (ctx->offset < 0)
ctx->offset = 0;
}
diff --git a/notmuch-show.c b/notmuch-show.c
index e054808..5a83c60 100644
--- a/notmuch-show.c
+++ b/notmuch-show.c
@@ -896,8 +896,13 @@ do_show_single (void *ctx,
notmuch_messages_t *messages;
notmuch_message_t *message;
notmuch_status_t status;
+ unsigned int count;
- if (notmuch_query_count_messages (query) != 1) {
+ status = notmuch_query_count_messages_st (query, &count);
+ if (print_status_query ("notmuch show", query, status))
+ return 1;
+
+ if (count != 1) {
fprintf (stderr, "Error: search term did not match precisely one message.\n");
return 1;
}
--
2.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Patch v4 4/9] cli: update to use new count API
2015-09-27 15:31 ` [Patch v4 4/9] cli: update to use new count API David Bremner
@ 2015-10-05 18:25 ` Jani Nikula
0 siblings, 0 replies; 15+ messages in thread
From: Jani Nikula @ 2015-10-05 18:25 UTC (permalink / raw)
To: David Bremner, notmuch
On Sun, 27 Sep 2015, David Bremner <david@tethera.net> wrote:
> Essentially replace each call to notmuch_count_* with the corresponding
> _st call, followed by print_status_query.
LGTM.
> ---
> notmuch-count.c | 12 ++++++++++--
> notmuch-reply.c | 7 ++++++-
> notmuch-search.c | 16 ++++++++++++++--
> notmuch-show.c | 7 ++++++-
> 4 files changed, 36 insertions(+), 6 deletions(-)
>
> diff --git a/notmuch-count.c b/notmuch-count.c
> index be3e236..0b6e6f5 100644
> --- a/notmuch-count.c
> +++ b/notmuch-count.c
> @@ -75,9 +75,11 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
> notmuch_query_t *query;
> size_t i;
> int count;
> + unsigned int ucount;
> unsigned long revision;
> const char *uuid;
> int ret = 0;
> + notmuch_status_t status;
>
> query = notmuch_query_create (notmuch, query_str);
> if (query == NULL) {
> @@ -90,10 +92,16 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
>
> switch (output) {
> case OUTPUT_MESSAGES:
> - printf ("%u", notmuch_query_count_messages (query));
> + status = notmuch_query_count_messages_st (query, &ucount);
> + if (print_status_query ("notmuch count", query, status))
> + return -1;
> + printf ("%u", ucount);
> break;
> case OUTPUT_THREADS:
> - printf ("%u", notmuch_query_count_threads (query));
> + status = notmuch_query_count_threads_st (query, &ucount);
> + if (print_status_query ("notmuch count", query, status))
> + return -1;
> + printf ("%u", ucount);
> break;
> case OUTPUT_FILES:
> count = count_files (query);
> diff --git a/notmuch-reply.c b/notmuch-reply.c
> index fd6a1ec..1357142 100644
> --- a/notmuch-reply.c
> +++ b/notmuch-reply.c
> @@ -655,9 +655,14 @@ notmuch_reply_format_sprinter(void *ctx,
> notmuch_messages_t *messages;
> notmuch_message_t *message;
> mime_node_t *node;
> + unsigned count;
> notmuch_status_t status;
>
> - if (notmuch_query_count_messages (query) != 1) {
> + status = notmuch_query_count_messages_st (query, &count);
> + if (print_status_query ("notmuch reply", query, status))
> + return 1;
> +
> + if (count != 1) {
> fprintf (stderr, "Error: search term did not match precisely one message.\n");
> return 1;
> }
> diff --git a/notmuch-search.c b/notmuch-search.c
> index 44e582c..6d08c25 100644
> --- a/notmuch-search.c
> +++ b/notmuch-search.c
> @@ -121,7 +121,13 @@ do_search_threads (search_context_t *ctx)
> notmuch_status_t status;
>
> if (ctx->offset < 0) {
> - ctx->offset += notmuch_query_count_threads (ctx->query);
> + unsigned count;
> + notmuch_status_t status;
> + status = notmuch_query_count_threads_st (ctx->query, &count);
> + if (print_status_query ("notmuch search", ctx->query, status))
> + return 1;
> +
> + ctx->offset += count;
> if (ctx->offset < 0)
> ctx->offset = 0;
> }
> @@ -521,7 +527,13 @@ do_search_messages (search_context_t *ctx)
> notmuch_status_t status;
>
> if (ctx->offset < 0) {
> - ctx->offset += notmuch_query_count_messages (ctx->query);
> + unsigned count;
> + notmuch_status_t status;
> + status = notmuch_query_count_messages_st (ctx->query, &count);
> + if (print_status_query ("notmuch search", ctx->query, status))
> + return 1;
> +
> + ctx->offset += count;
> if (ctx->offset < 0)
> ctx->offset = 0;
> }
> diff --git a/notmuch-show.c b/notmuch-show.c
> index e054808..5a83c60 100644
> --- a/notmuch-show.c
> +++ b/notmuch-show.c
> @@ -896,8 +896,13 @@ do_show_single (void *ctx,
> notmuch_messages_t *messages;
> notmuch_message_t *message;
> notmuch_status_t status;
> + unsigned int count;
>
> - if (notmuch_query_count_messages (query) != 1) {
> + status = notmuch_query_count_messages_st (query, &count);
> + if (print_status_query ("notmuch show", query, status))
> + return 1;
> +
> + if (count != 1) {
> fprintf (stderr, "Error: search term did not match precisely one message.\n");
> return 1;
> }
> --
> 2.5.3
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Patch v4 5/9] ruby: use new count API
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
` (3 preceding siblings ...)
2015-09-27 15:31 ` [Patch v4 4/9] cli: update to use new count API David Bremner
@ 2015-09-27 15:31 ` David Bremner
2015-09-27 15:32 ` [Patch v4 6/9] python: update bindings for " David Bremner
` (4 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: David Bremner @ 2015-09-27 15:31 UTC (permalink / raw)
To: notmuch
This change of replacing ignoring errors with exceptions is intended,
and indeed one of the main motivations for the libnotmuch API changes.
---
bindings/ruby/query.c | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index a7dacba..f87700a 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -173,14 +173,16 @@ VALUE
notmuch_rb_query_count_messages (VALUE self)
{
notmuch_query_t *query;
+ notmuch_status_t status;
+ unsigned int count;
Data_Get_Notmuch_Query (self, query);
- /* Xapian exceptions are not handled properly.
- * (function may return 0 after printing a message)
- * Thus there is nothing we can do here...
- */
- return UINT2NUM(notmuch_query_count_messages(query));
+ status = notmuch_query_count_messages_st (query, &count);
+ if (status)
+ notmuch_rb_status_raise (status);
+
+ return UINT2NUM(count);
}
/*
@@ -192,12 +194,14 @@ VALUE
notmuch_rb_query_count_threads (VALUE self)
{
notmuch_query_t *query;
+ notmuch_status_t status;
+ unsigned int count;
Data_Get_Notmuch_Query (self, query);
- /* Xapian exceptions are not handled properly.
- * (function may return 0 after printing a message)
- * Thus there is nothing we can do here...
- */
- return UINT2NUM(notmuch_query_count_threads(query));
+ status = notmuch_query_count_threads_st (query, &count);
+ if (status)
+ notmuch_rb_status_raise (status);
+
+ return UINT2NUM(count);
}
--
2.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Patch v4 6/9] python: update bindings for new count API
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
` (4 preceding siblings ...)
2015-09-27 15:31 ` [Patch v4 5/9] ruby: " David Bremner
@ 2015-09-27 15:32 ` David Bremner
2015-09-27 15:32 ` [Patch v4 7/9] lib: migrate notmuch_database_upgrade to new query_search API David Bremner
` (3 subsequent siblings)
9 siblings, 0 replies; 15+ messages in thread
From: David Bremner @ 2015-09-27 15:32 UTC (permalink / raw)
To: notmuch
Note that any mismatches are not detected until runtime (if at all)
with the python bindings, so tests are crucial
---
bindings/python/notmuch/query.py | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/bindings/python/notmuch/query.py b/bindings/python/notmuch/query.py
index 94773ac..378aa47 100644
--- a/bindings/python/notmuch/query.py
+++ b/bindings/python/notmuch/query.py
@@ -17,7 +17,7 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>.
Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
"""
-from ctypes import c_char_p, c_uint
+from ctypes import c_char_p, c_uint, POINTER, byref
from .globals import (
nmlib,
Enum,
@@ -178,8 +178,8 @@ class Query(object):
raise NullPointerError
return Messages(msgs_p, self)
- _count_messages = nmlib.notmuch_query_count_messages
- _count_messages.argtypes = [NotmuchQueryP]
+ _count_messages = nmlib.notmuch_query_count_messages_st
+ _count_messages.argtypes = [NotmuchQueryP, POINTER(c_uint)]
_count_messages.restype = c_uint
def count_messages(self):
@@ -191,10 +191,14 @@ class Query(object):
:rtype: int
'''
self._assert_query_is_initialized()
- return Query._count_messages(self._query)
-
- _count_threads = nmlib.notmuch_query_count_threads
- _count_threads.argtypes = [NotmuchQueryP]
+ count = c_uint(0)
+ status = Query._count_messages(self._query, byref(count))
+ if status != 0:
+ raise NotmuchError(status)
+ return count.value
+
+ _count_threads = nmlib.notmuch_query_count_threads_st
+ _count_threads.argtypes = [NotmuchQueryP, POINTER(c_uint)]
_count_threads.restype = c_uint
def count_threads(self):
@@ -210,7 +214,11 @@ class Query(object):
:rtype: int
'''
self._assert_query_is_initialized()
- return Query._count_threads(self._query)
+ count = c_uint(0)
+ status = Query._count_threads(self._query, byref(count))
+ if status != 0:
+ raise NotmuchError(status)
+ return count.value
_destroy = nmlib.notmuch_query_destroy
_destroy.argtypes = [NotmuchQueryP]
--
2.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [Patch v4 7/9] lib: migrate notmuch_database_upgrade to new query_search API
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
` (5 preceding siblings ...)
2015-09-27 15:32 ` [Patch v4 6/9] python: update bindings for " David Bremner
@ 2015-09-27 15:32 ` David Bremner
2015-10-05 18:27 ` Jani Nikula
2015-09-27 15:32 ` [Patch v4 8/9] lib: migrate thread.cc " David Bremner
` (2 subsequent siblings)
9 siblings, 1 reply; 15+ messages in thread
From: David Bremner @ 2015-09-27 15:32 UTC (permalink / raw)
To: notmuch
Here we depend on the error path cleaning up query
---
lib/database.cc | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/database.cc b/lib/database.cc
index f39d448..5e86955 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1450,9 +1450,10 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
query = notmuch_query_create (notmuch, "");
- /* XXX: this should use the _st version, but needs an error
- path */
- for (messages = notmuch_query_search_messages (query);
+ status = notmuch_query_search_messages_st (query, &messages);
+ if (status)
+ goto DONE;
+ for (;
notmuch_messages_valid (messages);
notmuch_messages_move_to_next (messages))
{
--
2.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Patch v4 7/9] lib: migrate notmuch_database_upgrade to new query_search API
2015-09-27 15:32 ` [Patch v4 7/9] lib: migrate notmuch_database_upgrade to new query_search API David Bremner
@ 2015-10-05 18:27 ` Jani Nikula
0 siblings, 0 replies; 15+ messages in thread
From: Jani Nikula @ 2015-10-05 18:27 UTC (permalink / raw)
To: David Bremner, notmuch
On Sun, 27 Sep 2015, David Bremner <david@tethera.net> wrote:
> Here we depend on the error path cleaning up query
LGTM
> ---
> lib/database.cc | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/lib/database.cc b/lib/database.cc
> index f39d448..5e86955 100644
> --- a/lib/database.cc
> +++ b/lib/database.cc
> @@ -1450,9 +1450,10 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
>
> query = notmuch_query_create (notmuch, "");
>
> - /* XXX: this should use the _st version, but needs an error
> - path */
> - for (messages = notmuch_query_search_messages (query);
> + status = notmuch_query_search_messages_st (query, &messages);
> + if (status)
> + goto DONE;
> + for (;
> notmuch_messages_valid (messages);
> notmuch_messages_move_to_next (messages))
> {
> --
> 2.5.3
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Patch v4 8/9] lib: migrate thread.cc to new query_search API
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
` (6 preceding siblings ...)
2015-09-27 15:32 ` [Patch v4 7/9] lib: migrate notmuch_database_upgrade to new query_search API David Bremner
@ 2015-09-27 15:32 ` David Bremner
2015-10-05 18:27 ` Jani Nikula
2015-09-27 15:32 ` [Patch v4 9/9] ruby: use " David Bremner
2015-10-05 23:30 ` v4 of count patches, plus convert remaining deprecated APIs David Bremner
9 siblings, 1 reply; 15+ messages in thread
From: David Bremner @ 2015-09-27 15:32 UTC (permalink / raw)
To: notmuch
here we rely on thread_id_query being attached to the local talloc
context, so no new cleanup code is needed.
---
lib/thread.cc | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/lib/thread.cc b/lib/thread.cc
index c8e58c3..0c937d7 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -447,6 +447,7 @@ _notmuch_thread_create (void *ctx,
notmuch_messages_t *messages;
notmuch_message_t *message;
+ notmuch_status_t status;
seed_message = _notmuch_message_create (local, notmuch, seed_doc_id, NULL);
if (! seed_message)
@@ -504,9 +505,11 @@ _notmuch_thread_create (void *ctx,
* oldest or newest subject is desired. */
notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_OLDEST_FIRST);
- /* XXX: this should use the _st version, but it needs an error path
- */
- for (messages = notmuch_query_search_messages (thread_id_query);
+ status = notmuch_query_search_messages_st (thread_id_query, &messages);
+ if (status)
+ goto DONE;
+
+ for (;
notmuch_messages_valid (messages);
notmuch_messages_move_to_next (messages))
{
--
2.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [Patch v4 8/9] lib: migrate thread.cc to new query_search API
2015-09-27 15:32 ` [Patch v4 8/9] lib: migrate thread.cc " David Bremner
@ 2015-10-05 18:27 ` Jani Nikula
0 siblings, 0 replies; 15+ messages in thread
From: Jani Nikula @ 2015-10-05 18:27 UTC (permalink / raw)
To: David Bremner, notmuch
On Sun, 27 Sep 2015, David Bremner <david@tethera.net> wrote:
> here we rely on thread_id_query being attached to the local talloc
> context, so no new cleanup code is needed.
LGTM
> ---
> lib/thread.cc | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/lib/thread.cc b/lib/thread.cc
> index c8e58c3..0c937d7 100644
> --- a/lib/thread.cc
> +++ b/lib/thread.cc
> @@ -447,6 +447,7 @@ _notmuch_thread_create (void *ctx,
>
> notmuch_messages_t *messages;
> notmuch_message_t *message;
> + notmuch_status_t status;
>
> seed_message = _notmuch_message_create (local, notmuch, seed_doc_id, NULL);
> if (! seed_message)
> @@ -504,9 +505,11 @@ _notmuch_thread_create (void *ctx,
> * oldest or newest subject is desired. */
> notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_OLDEST_FIRST);
>
> - /* XXX: this should use the _st version, but it needs an error path
> - */
> - for (messages = notmuch_query_search_messages (thread_id_query);
> + status = notmuch_query_search_messages_st (thread_id_query, &messages);
> + if (status)
> + goto DONE;
> +
> + for (;
> notmuch_messages_valid (messages);
> notmuch_messages_move_to_next (messages))
> {
> --
> 2.5.3
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Patch v4 9/9] ruby: use new query_search API
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
` (7 preceding siblings ...)
2015-09-27 15:32 ` [Patch v4 8/9] lib: migrate thread.cc " David Bremner
@ 2015-09-27 15:32 ` David Bremner
2015-10-05 23:30 ` v4 of count patches, plus convert remaining deprecated APIs David Bremner
9 siblings, 0 replies; 15+ messages in thread
From: David Bremner @ 2015-09-27 15:32 UTC (permalink / raw)
To: notmuch
These changes should not be too surprising for users because the
routines were already potentially throwing exceptions.
---
bindings/ruby/query.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/bindings/ruby/query.c b/bindings/ruby/query.c
index f87700a..8cbc73f 100644
--- a/bindings/ruby/query.c
+++ b/bindings/ruby/query.c
@@ -134,12 +134,13 @@ notmuch_rb_query_search_threads (VALUE self)
{
notmuch_query_t *query;
notmuch_threads_t *threads;
+ notmuch_status_t status;
Data_Get_Notmuch_Query (self, query);
- threads = notmuch_query_search_threads (query);
- if (!threads)
- rb_raise (notmuch_rb_eMemoryError, "Out of memory");
+ status = notmuch_query_search_threads_st (query, &threads);
+ if (status)
+ notmuch_rb_status_raise (status);
return Data_Wrap_Struct (notmuch_rb_cThreads, NULL, NULL, threads);
}
@@ -154,12 +155,13 @@ notmuch_rb_query_search_messages (VALUE self)
{
notmuch_query_t *query;
notmuch_messages_t *messages;
+ notmuch_status_t status;
Data_Get_Notmuch_Query (self, query);
- messages = notmuch_query_search_messages (query);
- if (!messages)
- rb_raise (notmuch_rb_eMemoryError, "Out of memory");
+ status = notmuch_query_search_messages_st (query, &messages);
+ if (status)
+ notmuch_rb_status_raise (status);
return Data_Wrap_Struct (notmuch_rb_cMessages, NULL, NULL, messages);
}
--
2.5.3
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: v4 of count patches, plus convert remaining deprecated APIs
2015-09-27 15:31 v4 of count patches, plus convert remaining deprecated APIs David Bremner
` (8 preceding siblings ...)
2015-09-27 15:32 ` [Patch v4 9/9] ruby: use " David Bremner
@ 2015-10-05 23:30 ` David Bremner
9 siblings, 0 replies; 15+ messages in thread
From: David Bremner @ 2015-10-05 23:30 UTC (permalink / raw)
To: notmuch
David Bremner <david@tethera.net> writes:
> Apologies for the confusion last night/this-morning with the count
> patches. I'm resending the whole series with at least one important
> bug fix.
I have pushed this series, with doc changes as suggested by Jani.
d
^ permalink raw reply [flat|nested] 15+ messages in thread