]> git.notmuchmail.org Git - notmuch/commitdiff
Split notmuch_database_close into two functions
authorJustus Winter <4winter@informatik.uni-hamburg.de>
Wed, 25 Apr 2012 13:20:16 +0000 (15:20 +0200)
committerDavid Bremner <bremner@debian.org>
Sat, 28 Apr 2012 12:21:13 +0000 (09:21 -0300)
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.

The comments in notmuch.h are a courtesy of Austin Clements.

Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
lib/database.cc
lib/notmuch.h

index 16c4354f2448bbc39bff3a1c3f630b4775575cd4..2fefcad7d163b5e9e40f9805a3d58b46a5704e37 100644 (file)
@@ -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;
                         "       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;
            }
                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());
     } 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;
     }
 
        notmuch = NULL;
     }
 
@@ -738,9 +738,19 @@ notmuch_database_close (notmuch_database_t *notmuch)
     }
 
     delete notmuch->term_gen;
     }
 
     delete notmuch->term_gen;
+    notmuch->term_gen = NULL;
     delete notmuch->query_parser;
     delete notmuch->query_parser;
+    notmuch->query_parser = NULL;
     delete notmuch->xapian_db;
     delete notmuch->xapian_db;
+    notmuch->xapian_db = NULL;
     delete notmuch->value_range_processor;
     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);
 }
 
     talloc_free (notmuch);
 }
 
index 673c4237ca4f98ba18183cf2c62ee4f0cd785f0d..7d9e0921f0c17e9f442f46e57dcc33e152c13329 100644 (file)
@@ -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
  *
  * 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
  *
  * 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'.
  *
  * 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
  * this database.
  *
  * In case of any failure, this function returns NULL, (after printing
@@ -175,11 +175,25 @@ notmuch_database_t *
 notmuch_database_open (const char *path,
                       notmuch_database_mode_t mode);
 
 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.
+ *
+ * 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 effect.
+ */
 void
 notmuch_database_close (notmuch_database_t *database);
 
 void
 notmuch_database_close (notmuch_database_t *database);
 
+/* 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
 /* Return the database path of the given database.
  *
  * The return value is a string owned by notmuch so should not be