--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 4FCBE6DE02D6\r
+ for <notmuch@notmuchmail.org>; Mon, 5 Oct 2015 11:23:01 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.162\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.162 tagged_above=-999 required=5\r
+ tests=[AWL=-0.186, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
+ RCVD_IN_MSPIKE_WL=-0.01, URIBL_SBL=0.644, URIBL_SBL_A=0.1]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id sF_TxiaM5s5x for <notmuch@notmuchmail.org>;\r
+ Mon, 5 Oct 2015 11:22:58 -0700 (PDT)\r
+Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com\r
+ [209.85.212.180])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 5C2066DE00CB\r
+ for <notmuch@notmuchmail.org>; Mon, 5 Oct 2015 11:22:58 -0700 (PDT)\r
+Received: by wicfx3 with SMTP id fx3so126769327wic.0\r
+ for <notmuch@notmuchmail.org>; Mon, 05 Oct 2015 11:22:56 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=MaBSh5nkQWPsHTtGuigAQDXtO9MBh301FZzA3HaQUUU=;\r
+ b=XfauJtNj6RsQLvVsq8075wxA5Q4i77QvoXIpIjnwd0q7ml587QawgBNN2/031lSl47\r
+ IEcDbhWzUKI8EJ5eWhie5a6hYHyUu92vMi1iRYMcPYqRZHb1cU64aaj9uLCP6kGggbJL\r
+ PdloHA7M5HoJ4WP96g4FVTrbaoeGvdm+9XGErRaVsOzpuOu92GJRHUWu7DBrA618Qrxr\r
+ cVW32ivUJ+2faPu0DBNn6VgYNjWKXyNjWkLf7S6ZWvxX/wduqzOYewNnZsid5e9o/yh9\r
+ pN+6YFsulMy6P2bUsfFTyTHF6DOMIh+GkjRdJCvoY5BONRiBptunG8GgXHB9uTjWXGRQ\r
+ mSmQ==\r
+X-Gm-Message-State:\r
+ ALoCoQktcH2I8FBoIeZzAUb+0TAqJuKHzty8RnldrquteSuABt9t5HR1jgBCBqKQwyQWIm+PXXFG\r
+X-Received: by 10.194.22.165 with SMTP id e5mr30364182wjf.50.1444069376002;\r
+ Mon, 05 Oct 2015 11:22:56 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee9f-54.dhcp.inet.fi.\r
+ [188.238.159.54])\r
+ by smtp.gmail.com with ESMTPSA id f17sm28158297wjn.38.2015.10.05.11.22.55\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Mon, 05 Oct 2015 11:22:55 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: [Patch v4 3/9] lib: add versions of n_q_count_{message,\r
+ threads} with status return\r
+In-Reply-To: <1443367923-11867-4-git-send-email-david@tethera.net>\r
+References: <1443367923-11867-1-git-send-email-david@tethera.net>\r
+ <1443367923-11867-4-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.20.2+101~g7b7dadb (http://notmuchmail.org) Emacs/24.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Mon, 05 Oct 2015 21:22:29 +0300\r
+Message-ID: <87h9m589ay.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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: Mon, 05 Oct 2015 18:23:01 -0000\r
+\r
+On Sun, 27 Sep 2015, David Bremner <david@tethera.net> wrote:\r
+> Although I think it's a pretty bad idea to continue using the old API,\r
+> this allows both a more gentle transition for clients of the library,\r
+> and allows us to break one monolithic change into a series\r
+\r
+Mostly looks as good as it gets (who would say C makes error handling\r
+like this look good?!), a few nitpicks inline below, up to your\r
+discretion.\r
+\r
+BR,\r
+Jani.\r
+\r
+\r
+> ---\r
+> lib/database.cc | 13 ++++++++++++-\r
+> lib/notmuch.h | 48 ++++++++++++++++++++++++++++++++++++++++++------\r
+> lib/query.cc | 47 +++++++++++++++++++++++++++++++++--------------\r
+> 3 files changed, 87 insertions(+), 21 deletions(-)\r
+>\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index dcfad8c..f39d448 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -1410,8 +1410,15 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+> (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER |\r
+> NOTMUCH_FEATURE_LAST_MOD)) {\r
+> query = notmuch_query_create (notmuch, "");\r
+> - total += notmuch_query_count_messages (query);\r
+> + unsigned msg_count;\r
+> +\r
+> + status = notmuch_query_count_messages_st (query, &msg_count);\r
+> + if (status)\r
+> + goto DONE;\r
+> +\r
+> + total += msg_count;\r
+> notmuch_query_destroy (query);\r
+> + query = NULL;\r
+> }\r
+> if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {\r
+> t_end = db->allterms_end ("XTIMESTAMP");\r
+> @@ -1492,6 +1499,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+> }\r
+> \r
+> notmuch_query_destroy (query);\r
+> + query = NULL;\r
+> }\r
+> \r
+> /* Perform per-directory upgrades. */\r
+> @@ -1612,6 +1620,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+> sigaction (SIGALRM, &action, NULL);\r
+> }\r
+> \r
+> + if (query)\r
+> + notmuch_query_destroy (query);\r
+> +\r
+> talloc_free (local);\r
+> return status;\r
+> }\r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index 8775683..2fb778b 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -984,10 +984,26 @@ notmuch_threads_destroy (notmuch_threads_t *threads);\r
+> * This function performs a search and returns the number of matching\r
+> * messages.\r
+> *\r
+> - * If a Xapian exception occurs, this function may return 0 (after\r
+> - * printing a message).\r
+> + * @returns\r
+> + *\r
+> + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
+\r
+complete_d_?\r
+\r
+> + *\r
+> + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
+> + * value of *count is not defined.\r
+> */\r
+> -unsigned\r
+> +notmuch_status_t\r
+> +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);\r
+\r
+I'd use "unsigned int", but matter of style.\r
+\r
+Do we care about documenting at which versions the new functions have\r
+been introduced? Doxygen supports @since.\r
+\r
+> +\r
+> +/**\r
+> + * like notmuch_query_count_messages_st, but without a status return\r
+\r
+Period at the end.\r
+\r
+> + *\r
+> + * May return 0 in the case of errors.\r
+> + *\r
+> + * @deprecated Deprecated since libnotmuch 4.3 (notmuch 0.21). Please\r
+> + * use notmuch_query_count_messages_st instead.\r
+> + */\r
+> +NOTMUCH_DEPRECATED(4,3)\r
+> +unsigned int\r
+> notmuch_query_count_messages (notmuch_query_t *query);\r
+> \r
+> /**\r
+> @@ -998,11 +1014,31 @@ notmuch_query_count_messages (notmuch_query_t *query);\r
+> * search.\r
+> *\r
+> * Note that this is a significantly heavier operation than\r
+> - * notmuch_query_count_messages().\r
+> + * notmuch_query_count_messages{_st}().\r
+\r
+I think doxygen can do some hyperlinking here if you use the proper\r
+function name(s). On output formats we don't use, but anyway...\r
+\r
+> + *\r
+> + * @returns\r
+> *\r
+> - * If an error occurs, this function may return 0.\r
+> + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value\r
+> + * of *count is not defined\r
+> +\r
+> + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
+\r
+complete_d_?\r
+\r
+> + *\r
+> + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
+> + * value of *count is not defined.\r
+> */\r
+> -unsigned\r
+> +notmuch_status_t\r
+> +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);\r
+> +\r
+> +/**\r
+> + * like notmuch_query_count_threads, but without a status return.\r
+> + *\r
+> + * May return 0 in case of errors.\r
+> + *\r
+> + * @deprecated Deprecated as of libnotmuch 4.3 (notmuch 0.21). Please\r
+> + * use notmuch_query_count_threads_st instead.\r
+> + */\r
+> +NOTMUCH_DEPRECATED(4,3)\r
+> +unsigned int\r
+> notmuch_query_count_threads (notmuch_query_t *query);\r
+> \r
+> /**\r
+> diff --git a/lib/query.cc b/lib/query.cc\r
+> index 8cf0a07..e627bfc 100644\r
+> --- a/lib/query.cc\r
+> +++ b/lib/query.cc\r
+> @@ -541,9 +541,19 @@ notmuch_threads_destroy (notmuch_threads_t *threads)\r
+> talloc_free (threads);\r
+> }\r
+> \r
+> -unsigned\r
+> +unsigned int\r
+> notmuch_query_count_messages (notmuch_query_t *query)\r
+> {\r
+> + notmuch_status_t status;\r
+> + unsigned int count;\r
+> +\r
+> + status = notmuch_query_count_messages_st (query, &count);\r
+> + return status ? 0 : count;\r
+> +}\r
+> +\r
+> +notmuch_status_t\r
+> +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
+> +{\r
+> notmuch_database_t *notmuch = query->notmuch;\r
+> const char *query_string = query->query_string;\r
+> Xapian::doccount count = 0;\r
+> @@ -605,35 +615,44 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+> "Query string was: %s\n",\r
+> error.get_msg().c_str(),\r
+> query->query_string);\r
+> -\r
+> + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+> }\r
+> \r
+> - return count;\r
+> + *count_out = count;\r
+> + return NOTMUCH_STATUS_SUCCESS;\r
+> }\r
+> \r
+> unsigned\r
+> notmuch_query_count_threads (notmuch_query_t *query)\r
+> {\r
+> + notmuch_status_t status;\r
+> + unsigned int count;\r
+> +\r
+> + status = notmuch_query_count_threads_st (query, &count);\r
+> + return status ? 0 : count;\r
+> +}\r
+> +\r
+> +notmuch_status_t\r
+> +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)\r
+> +{\r
+> notmuch_messages_t *messages;\r
+> GHashTable *hash;\r
+> - unsigned int count;\r
+> notmuch_sort_t sort;\r
+> - notmuch_status_t status;\r
+> + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
+> \r
+> sort = query->sort;\r
+> query->sort = NOTMUCH_SORT_UNSORTED;\r
+> - status = notmuch_query_search_messages_st (query, &messages);\r
+> - if (status)\r
+> - return 0;\r
+> -\r
+> + ret = notmuch_query_search_messages_st (query, &messages);\r
+> + if (ret)\r
+> + return ret;\r
+> query->sort = sort;\r
+> if (messages == NULL)\r
+> - return 0;\r
+> + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+> \r
+> hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);\r
+> if (hash == NULL) {\r
+> talloc_free (messages);\r
+> - return 0;\r
+> + return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+> }\r
+> \r
+> while (notmuch_messages_valid (messages)) {\r
+> @@ -642,7 +661,7 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
+> char *thread_id_copy = talloc_strdup (messages, thread_id);\r
+> if (unlikely (thread_id_copy == NULL)) {\r
+> notmuch_message_destroy (message);\r
+> - count = 0;\r
+> + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+> goto DONE;\r
+> }\r
+> g_hash_table_insert (hash, thread_id_copy, NULL);\r
+> @@ -650,13 +669,13 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
+> notmuch_messages_move_to_next (messages);\r
+> }\r
+> \r
+> - count = g_hash_table_size (hash);\r
+> + *count = g_hash_table_size (hash);\r
+> \r
+> DONE:\r
+> g_hash_table_unref (hash);\r
+> talloc_free (messages);\r
+> \r
+> - return count;\r
+> + return ret;\r
+> }\r
+> \r
+> notmuch_database_t *\r
+> -- \r
+> 2.5.3\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r