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 CA0A3431FBC for ; Sat, 7 Mar 2015 05:56:53 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 1.738 X-Spam-Level: * X-Spam-Status: No, score=1.738 tagged_above=-999 required=5 tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7] 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 EMKrDKcGxhdA for ; Sat, 7 Mar 2015 05:56:50 -0800 (PST) Received: from mail-we0-f176.google.com (mail-we0-f176.google.com [74.125.82.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 3D9F9431FAE for ; Sat, 7 Mar 2015 05:56:50 -0800 (PST) Received: by wesw55 with SMTP id w55so1818361wes.2 for ; Sat, 07 Mar 2015 05:56:49 -0800 (PST) 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=C2OcpB5z8BzYAn05Cre1UZauYjX8OKLVmWif22t4t+8=; b=P12wS/D2R8i9LQWwytN6UXUTEN3xgVs3yIAM2A10gSgvh8ktXyVJdI+gH4hcjgyler LU2SH3WJLBWsF4iCw8N3iCNAvUSBpxCW/xtBvzIoqz4QIEqWTTKLVnGERQ40qXmvZLBF Nly4q6aKCyE/9plY8tsA3JVgqhqjAHShSKNTDDhlPEqAz2PLWn8UCDiBEjkvw6Me0HYd G6tErUfZcw3/ZTf341OqvWae71qj4g1c7hVSrJruoQzvPleQmalzCebttZfWm9H/Sj5q 7TyxmqQTIlXCTyUdvlABkfu0L/C8Fp/TZK5RrzIQPOrf/WV6o/u9DVe2m6OAW/RnP60o zOmw== X-Gm-Message-State: ALoCoQmCEFAa/NMX+xO//NG/cujMCrVrotrSdfngfmNm2MbA39qmif+mprXuEZFV6AV7ZxIkBqEG X-Received: by 10.195.11.73 with SMTP id eg9mr38904056wjd.62.1425736609241; Sat, 07 Mar 2015 05:56:49 -0800 (PST) Received: from localhost (mobile-internet-bcee3b-76.dhcp.inet.fi. [188.238.59.76]) by mx.google.com with ESMTPSA id md2sm10644777wic.19.2015.03.07.05.56.47 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 07 Mar 2015 05:56:48 -0800 (PST) From: Jani Nikula To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH 1/4] lib: add versions of notmuch_query_count_{message, threads} with status return In-Reply-To: <1425717797-19990-2-git-send-email-david@tethera.net> References: <1419971380-10307-6-git-send-email-david@tethera.net> <1425717797-19990-1-git-send-email-david@tethera.net> <1425717797-19990-2-git-send-email-david@tethera.net> User-Agent: Notmuch/0.19+74~g6aeef2e (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) Date: Sat, 07 Mar 2015 15:57:08 +0200 Message-ID: <87vbicj4gb.fsf@nikula.org> 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: Sat, 07 Mar 2015 13:56:54 -0000 On Sat, 07 Mar 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 We should probably bump LIBNOTMUCH_MINOR_VERSION for this. See nitpicks inline below, up to you if you decide if they're worthwhile changes, generally LGTM. > --- > lib/database.cc | 8 +++++++- > lib/notmuch.h | 34 ++++++++++++++++++++++++++++++---- > lib/query.cc | 36 +++++++++++++++++++++++++++++------- > 3 files changed, 66 insertions(+), 12 deletions(-) > > diff --git a/lib/database.cc b/lib/database.cc > index 3974e2e..d92eec0 100644 > --- a/lib/database.cc > +++ b/lib/database.cc > @@ -1275,7 +1275,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, > if (new_features & > (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) { > notmuch_query_t *query = notmuch_query_create (notmuch, ""); > - total += notmuch_query_count_messages (query); > + unsigned msg_count; Personal preference, I always want to specify "unsigned int" instead of just "unsigned". Same all around patches 1 and 2. > + > + status = notmuch_query_count_messages_st (query, &msg_count); > + if (status) > + goto DONE; > + > + total += msg_count; > notmuch_query_destroy (query); > } > if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) { > diff --git a/lib/notmuch.h b/lib/notmuch.h > index 3e326bf..a0fc276 100644 > --- a/lib/notmuch.h > +++ b/lib/notmuch.h > @@ -914,12 +914,23 @@ notmuch_threads_destroy (notmuch_threads_t *threads); > * This function performs a search and returns Xapian's best > * guess as to number of matching messages. > * > - * If a Xapian exception occurs, this function may return 0 (after > - * printing a message). > + * The version returning the count directly instead of a status value > + * is deprecated. > + * > + * Return value (of the _st) version: > + * > + * NOTMUCH_STATUS_SUCCESS: query complete successfully. > + * > + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The > + * value of *count is not defined. > */ I'd really like to have separate doc comments for both the functions. The original and now deprecated version can be be a brief one, with a reference to the _st version documentation. If you move the _st version declaration here, above the original declaration, the diff should remain small. Perhaps reference the library version number when this was added? > + > unsigned > notmuch_query_count_messages (notmuch_query_t *query); > > +notmuch_status_t > +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count); > + > /** > * Return the number of threads matching a search. > * > @@ -928,13 +939,28 @@ 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}(). > + * > + * The version returning the count directly instead of a status value > + * is deprecated. > * > - * If an error occurs, this function may return 0. > + * Return values (of the _st version): > + * > + * 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. > */ Same as above. > + > unsigned > notmuch_query_count_threads (notmuch_query_t *query); > > +notmuch_status_t > +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count); > + > /** > * Get the thread ID of 'thread'. > * > diff --git a/lib/query.cc b/lib/query.cc > index 9279915..883d128 100644 > --- a/lib/query.cc > +++ b/lib/query.cc > @@ -541,6 +541,16 @@ notmuch_threads_destroy (notmuch_threads_t *threads) > unsigned > notmuch_query_count_messages (notmuch_query_t *query) > { > + notmuch_status_t status; > + unsigned 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; > @@ -595,30 +605,42 @@ notmuch_query_count_messages (notmuch_query_t *query) > fprintf (stderr, "A Xapian exception occurred: %s\n", > error.get_msg().c_str()); > fprintf (stderr, "Query string was: %s\n", query->query_string); > + return NOTMUCH_STATUS_XAPIAN_EXCEPTION; > } > > - return count; > + *count_out=count; Spaces around "="? > + return NOTMUCH_STATUS_SUCCESS; > } > > unsigned > notmuch_query_count_threads (notmuch_query_t *query) > { > + notmuch_status_t status; > + unsigned 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 ret = NOTMUCH_STATUS_SUCCESS; > > sort = query->sort; > query->sort = NOTMUCH_SORT_UNSORTED; > messages = notmuch_query_search_messages (query); > 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)) { > @@ -627,7 +649,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); > @@ -635,11 +657,11 @@ 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; > } > -- > 2.1.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch