From: Mark Walters Date: Sat, 31 Mar 2012 17:17:15 +0000 (+0100) Subject: Re: [PATCH 1/7] Split notmuch_database_close into two functions X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=16d3317fb04b3f0e75e0891f445c6fa4572d42ac;p=notmuch-archives.git Re: [PATCH 1/7] Split notmuch_database_close into two functions --- diff --git a/49/2d7b1ac0337d2ddbc46f8e779ec2e5bc429d66 b/49/2d7b1ac0337d2ddbc46f8e779ec2e5bc429d66 new file mode 100644 index 000000000..7462e1d57 --- /dev/null +++ b/49/2d7b1ac0337d2ddbc46f8e779ec2e5bc429d66 @@ -0,0 +1,225 @@ +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 82114431FAF + for ; Sat, 31 Mar 2012 10:17:14 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -1.098 +X-Spam-Level: +X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5 + tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001, + NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 Y0UdHVOkPrGa for ; + Sat, 31 Mar 2012 10:17:13 -0700 (PDT) +Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 54593431FAE + for ; Sat, 31 Mar 2012 10:17:13 -0700 (PDT) +Received: from smtp.qmul.ac.uk ([138.37.6.40]) + by mail2.qmul.ac.uk with esmtp (Exim 4.71) + (envelope-from ) + id 1SE1vG-0003RQ-ID; Sat, 31 Mar 2012 18:17:09 +0100 +Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223] + helo=localhost) + by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69) + (envelope-from ) + id 1SE1vG-0000RL-3i; Sat, 31 Mar 2012 18:17:06 +0100 +From: Mark Walters +To: Justus Winter <4winter@informatik.uni-hamburg.de>, notmuch@notmuchmail.org +Subject: Re: [PATCH 1/7] Split notmuch_database_close into two functions +In-Reply-To: + <1332291311-28954-2-git-send-email-4winter@informatik.uni-hamburg.de> +References: + <1332291311-28954-1-git-send-email-4winter@informatik.uni-hamburg.de> + <1332291311-28954-2-git-send-email-4winter@informatik.uni-hamburg.de> +User-Agent: Notmuch/0.12+88~gb9fb613 (http://notmuchmail.org) Emacs/23.3.1 + (x86_64-pc-linux-gnu) +Date: Sat, 31 Mar 2012 18:17:15 +0100 +Message-ID: <87fwcopu5g.fsf@qmul.ac.uk> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +X-Sender-Host-Address: 94.192.233.223 +X-QM-SPAM-Info: Sender has good ham record. :) +X-QM-Body-MD5: afb81fd1a941e6f44213228b1e25b7d9 (of first 20000 bytes) +X-SpamAssassin-Score: -1.8 +X-SpamAssassin-SpamBar: - +X-SpamAssassin-Report: The QM spam filters have analysed this message to + determine if it is + spam. We require at least 5.0 points to mark a message as spam. + This message scored -1.8 points. + Summary of the scoring: + * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, + * medium trust + * [138.37.6.40 listed in list.dnswl.org] + * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail + provider * (markwalters1009[at]gmail.com) + * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay + * domain + * 0.5 AWL AWL: From: address is in the auto white-list +X-QM-Scan-Virus: ClamAV says the message is clean +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, 31 Mar 2012 17:17:14 -0000 + +Justus Winter <4winter@informatik.uni-hamburg.de> writes: + +> Formerly notmuch_database_close closed the xapian database and +> destroyed the talloc structure associated with the notmuch database +> object. Split notmuch_database_close into notmuch_database_close and +> notmuch_database_destroy. +> +> This makes it possible for long running programs to close the xapian +> database and thus release the lock associated with it without +> destroying the data structures obtained from it. +> +> This also makes the api more consistent since every other data +> structure has a destructor function. + +I like the idea of this series but have two queries before reviewing it. + +The first is a concern that if we change the library functions we should +update the library version otherwise out of tree users won't know which +to call. (I don't actually know how versioning is done but I think we +should at least be able to make new out-of-tree code cope with the old +or new version). It might be worth keeping notmuch_database_close as it +is for now and adding something like notmuch_database_weak_close with +the new functionality. Then whenever the library version is next going +to get bumped we could move to the destroy/close nomenclature. + +Secondly, I think the patch series could be made clearer and easier to +review. If you do it in three steps + +1) change of notmuch_database_close to notmuch_database_destroy (just + the function name change) +2) split the new notmuch_database_destroy into two as in the current + first patch +3) Make any changes (if there are any) of notmuch_database_destroy to + notmuch_database_close. + +The advantage is that the first change is easy to test (essentially does +it build) and then changes from notmuch_database_destroy to +notmuch_database_close in step 3 are explicit rather than the current +situation where we need to grep the code to see if some instances of +notmuch_database_close were not changed to notmuch_database_destroy. + +Of course if the decision is to go via the weak_close version then you +just need to do the analogues of 2 and 3. + +Best wishes + +Mark + +> +> Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de> +> --- +> lib/database.cc | 14 ++++++++++++-- +> lib/notmuch.h | 15 +++++++++++---- +> 2 files changed, 23 insertions(+), 6 deletions(-) +> +> diff --git a/lib/database.cc b/lib/database.cc +> index 16c4354..2fefcad 100644 +> --- a/lib/database.cc +> +++ b/lib/database.cc +> @@ -642,7 +642,7 @@ notmuch_database_open (const char *path, +> " read-write mode.\n", +> notmuch_path, version, NOTMUCH_DATABASE_VERSION); +> notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY; +> - notmuch_database_close (notmuch); +> + notmuch_database_destroy (notmuch); +> notmuch = NULL; +> goto DONE; +> } +> @@ -702,7 +702,7 @@ notmuch_database_open (const char *path, +> } catch (const Xapian::Error &error) { +> fprintf (stderr, "A Xapian exception occurred opening database: %s\n", +> error.get_msg().c_str()); +> - notmuch_database_close (notmuch); +> + notmuch_database_destroy (notmuch); +> notmuch = NULL; +> } +> +> @@ -738,9 +738,19 @@ notmuch_database_close (notmuch_database_t *notmuch) +> } +> +> delete notmuch->term_gen; +> + notmuch->term_gen = NULL; +> delete notmuch->query_parser; +> + notmuch->query_parser = NULL; +> delete notmuch->xapian_db; +> + notmuch->xapian_db = NULL; +> delete notmuch->value_range_processor; +> + notmuch->value_range_processor = NULL; +> +} +> + +> +void +> +notmuch_database_destroy (notmuch_database_t *notmuch) +> +{ +> + notmuch_database_close (notmuch); +> talloc_free (notmuch); +> } +> +> diff --git a/lib/notmuch.h b/lib/notmuch.h +> index babd208..6114f36 100644 +> --- a/lib/notmuch.h +> +++ b/lib/notmuch.h +> @@ -133,7 +133,7 @@ typedef struct _notmuch_filenames notmuch_filenames_t; +> * +> * After a successful call to notmuch_database_create, the returned +> * database will be open so the caller should call +> - * notmuch_database_close when finished with it. +> + * notmuch_database_destroy when finished with it. +> * +> * The database will not yet have any data in it +> * (notmuch_database_create itself is a very cheap function). Messages +> @@ -165,7 +165,7 @@ typedef enum { +> * An existing notmuch database can be identified by the presence of a +> * directory named ".notmuch" below 'path'. +> * +> - * The caller should call notmuch_database_close when finished with +> + * The caller should call notmuch_database_destroy when finished with +> * this database. +> * +> * In case of any failure, this function returns NULL, (after printing +> @@ -175,11 +175,18 @@ notmuch_database_t * +> notmuch_database_open (const char *path, +> notmuch_database_mode_t mode); +> +> -/* Close the given notmuch database, freeing all associated +> - * resources. See notmuch_database_open. */ +> +/* Close the given notmuch database. +> + * +> + * This function is called by notmuch_database_destroyed and can be +> + * called multiple times. */ +> void +> notmuch_database_close (notmuch_database_t *database); +> +> +/* Destroy the notmuch database freeing all associated +> + * resources */ +> +void +> +notmuch_database_destroy (notmuch_database_t *database); +> + +> /* Return the database path of the given database. +> * +> * The return value is a string owned by notmuch so should not be +> -- +> 1.7.9.1 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch