Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 4FCBE6DE02D6 for ; Mon, 5 Oct 2015 11:23:01 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.162 X-Spam-Level: X-Spam-Status: No, score=-0.162 tagged_above=-999 required=5 tests=[AWL=-0.186, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, URIBL_SBL=0.644, URIBL_SBL_A=0.1] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sF_TxiaM5s5x for ; Mon, 5 Oct 2015 11:22:58 -0700 (PDT) Received: from mail-wi0-f180.google.com (mail-wi0-f180.google.com [209.85.212.180]) by arlo.cworth.org (Postfix) with ESMTPS id 5C2066DE00CB for ; Mon, 5 Oct 2015 11:22:58 -0700 (PDT) Received: by wicfx3 with SMTP id fx3so126769327wic.0 for ; Mon, 05 Oct 2015 11:22:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:in-reply-to:references :user-agent:date:message-id:mime-version:content-type; bh=MaBSh5nkQWPsHTtGuigAQDXtO9MBh301FZzA3HaQUUU=; b=XfauJtNj6RsQLvVsq8075wxA5Q4i77QvoXIpIjnwd0q7ml587QawgBNN2/031lSl47 IEcDbhWzUKI8EJ5eWhie5a6hYHyUu92vMi1iRYMcPYqRZHb1cU64aaj9uLCP6kGggbJL PdloHA7M5HoJ4WP96g4FVTrbaoeGvdm+9XGErRaVsOzpuOu92GJRHUWu7DBrA618Qrxr cVW32ivUJ+2faPu0DBNn6VgYNjWKXyNjWkLf7S6ZWvxX/wduqzOYewNnZsid5e9o/yh9 pN+6YFsulMy6P2bUsfFTyTHF6DOMIh+GkjRdJCvoY5BONRiBptunG8GgXHB9uTjWXGRQ mSmQ== X-Gm-Message-State: ALoCoQktcH2I8FBoIeZzAUb+0TAqJuKHzty8RnldrquteSuABt9t5HR1jgBCBqKQwyQWIm+PXXFG X-Received: by 10.194.22.165 with SMTP id e5mr30364182wjf.50.1444069376002; Mon, 05 Oct 2015 11:22:56 -0700 (PDT) Received: from localhost (mobile-access-bcee9f-54.dhcp.inet.fi. [188.238.159.54]) by smtp.gmail.com with ESMTPSA id f17sm28158297wjn.38.2015.10.05.11.22.55 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Oct 2015 11:22:55 -0700 (PDT) From: Jani Nikula To: David Bremner , notmuch@notmuchmail.org Subject: Re: [Patch v4 3/9] lib: add versions of n_q_count_{message, threads} with status return In-Reply-To: <1443367923-11867-4-git-send-email-david@tethera.net> References: <1443367923-11867-1-git-send-email-david@tethera.net> <1443367923-11867-4-git-send-email-david@tethera.net> User-Agent: Notmuch/0.20.2+101~g7b7dadb (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) Date: Mon, 05 Oct 2015 21:22:29 +0300 Message-ID: <87h9m589ay.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.18 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: Mon, 05 Oct 2015 18:23:01 -0000 On Sun, 27 Sep 2015, David Bremner 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