From 034022189d4a9805c05f748578d203bd0105c656 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 23 Apr 2012 14:01:59 +2000 Subject: [PATCH] Re: [PATCH 1/7] Split notmuch_database_close into two functions --- 43/736965b056cc3096ffa4251fc0a92ba099387d | 207 ++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 43/736965b056cc3096ffa4251fc0a92ba099387d diff --git a/43/736965b056cc3096ffa4251fc0a92ba099387d b/43/736965b056cc3096ffa4251fc0a92ba099387d new file mode 100644 index 000000000..9aa2bf18a --- /dev/null +++ b/43/736965b056cc3096ffa4251fc0a92ba099387d @@ -0,0 +1,207 @@ +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 C5C22431FAF + for ; Sun, 22 Apr 2012 11:02:03 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[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 QFfdyK8LYcYD for ; + Sun, 22 Apr 2012 11:02:03 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU + [18.9.25.14]) + by olra.theworths.org (Postfix) with ESMTP id D1BDD431FAE + for ; Sun, 22 Apr 2012 11:02:02 -0700 (PDT) +X-AuditID: 1209190e-b7f7c6d0000008c3-7d-4f94479a17a2 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 0C.D7.02243.A97449F4; Sun, 22 Apr 2012 14:02:02 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q3MI21HZ001500; + Sun, 22 Apr 2012 14:02:01 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3MI20Lu018743 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sun, 22 Apr 2012 14:02:01 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1SM16l-0007z8-Qy; Sun, 22 Apr 2012 14:01:59 -0400 +Date: Sun, 22 Apr 2012 14:01:59 -0400 +From: Austin Clements +To: Justus Winter <4winter@informatik.uni-hamburg.de> +Subject: Re: [PATCH 1/7] Split notmuch_database_close into two functions +Message-ID: <20120422180159.GG17810@mit.edu> +References: <20120422120620.26225.40778@thinkbox.jade-hamburg.de> + <1335096477-27537-1-git-send-email-4winter@informatik.uni-hamburg.de> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: + <1335096477-27537-1-git-send-email-4winter@informatik.uni-hamburg.de> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT153lPsXf4P5jaYvZrT+YLK7fnMns + wOQx8fxpNo9nq24xBzBFcdmkpOZklqUW6dslcGVMXHiateCXasWk491MDYyT5boYOTkkBEwk + 7jXOY4WwxSQu3FvP1sXIxSEksI9RonFeExNIQkhgA6PEp/lQiZNMEif75jJDOEsYJX79WsYO + UsUioCqx6OwERhCbTUBDYtv+5WC2iICpxIYHD8BqmAWkJb79bgabKizgIbHj2h6wGl4BHYkJ + h7qYIIZ2Mko8+L+TBSIhKHFy5hMWiGYtiRv/XgIVcYANWv6PAyTMKRAksXZ1I9gcUQEViSkn + t7FNYBSahaR7FpLuWQjdCxiZVzHKpuRW6eYmZuYUpybrFicn5uWlFuka6+VmluilppRuYgQF + Nqck3w7GrweVDjEKcDAq8fA6mU/2F2JNLCuuzD3EKMnBpCTK+9ptir8QX1J+SmVGYnFGfFFp + TmrxIUYJDmYlEd7PIkDlvCmJlVWpRfkwKWkOFiVxXjWtd35CAumJJanZqakFqUUwWRkODiUJ + XjNgBAsJFqWmp1akZeaUIKSZODhBhvMADf8Ospi3uCAxtzgzHSJ/ilFRSpxXA6RZACSRUZoH + 1wtLPK8YxYFeEeYVB6niASYtuO5XQIOZgAYnxEwCGVySiJCSamAUe7loa9uv/LnnK6ZsPb7p + 1YS5Jpt6kkR7OT5NdV0wYW3h3ICQi221WzY3Sf33Fpu6MvFhceadJVoycVwMbceFzWcG64u/ + 0bmQefzh/pnct4sCqxsPRSfI+C/NObnnxRl+KfU1p/P9ghW2Xfu35ZHaTMeWteymu6a6HhYN + Otq2fzaLS45v4xJbJZbijERDLeai4kQAPp2AphcDAAA= +Cc: notmuch@notmuchmail.org +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: Sun, 22 Apr 2012 18:02:03 -0000 + +Quoth Justus Winter on Apr 22 at 2:07 pm: +> 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. +> +> 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 673c423..84c9265 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_destroy and can be +> + * called multiple times. */ + +This needs a comment explaining the implications of closing the +database. Perhaps something like this (modeled on +Xapian::Database::close's documentation) + +/* Close the given notmuch database. + * + * After notmuch_database_close has been called, calls to other + * functions on objects derived from this database may either behave + * as if the database had not been closed (e.g., if the required data + * has been cached) or may fail with a + * NOTMUCH_STATUS_XAPIAN_EXCEPTION. + * + * notmuch_database_close can be called multiple times. Later calls + * have no affect. + */ + +> void +> notmuch_database_close (notmuch_database_t *database); +> +> +/* Destroy the notmuch database freeing all associated +> + * resources */ + +This should mention that this also closes the database (currently you +mention this in the doc for notmuch_database_close, but it's a reverse +reference there; that could probably even be omitted). Perhaps + +/* Destroy the notmuch database, closing it if necessary and 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 -- 2.26.2