Re: [PATCH 1/7] Split notmuch_database_close into two functions
[notmuch-archives.git] / 43 / 736965b056cc3096ffa4251fc0a92ba099387d
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id C5C22431FAF\r
6         for <notmuch@notmuchmail.org>; Sun, 22 Apr 2012 11:02:03 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id QFfdyK8LYcYD for <notmuch@notmuchmail.org>;\r
16         Sun, 22 Apr 2012 11:02:03 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
18         [18.9.25.14])\r
19         by olra.theworths.org (Postfix) with ESMTP id D1BDD431FAE\r
20         for <notmuch@notmuchmail.org>; Sun, 22 Apr 2012 11:02:02 -0700 (PDT)\r
21 X-AuditID: 1209190e-b7f7c6d0000008c3-7d-4f94479a17a2\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 0C.D7.02243.A97449F4; Sun, 22 Apr 2012 14:02:02 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id q3MI21HZ001500; \r
27         Sun, 22 Apr 2012 14:02:01 -0400\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
29         (authenticated bits=0)\r
30         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
31         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q3MI20Lu018743\r
32         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
33         Sun, 22 Apr 2012 14:02:01 -0400 (EDT)\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
35         (envelope-from <amdragon@mit.edu>)\r
36         id 1SM16l-0007z8-Qy; Sun, 22 Apr 2012 14:01:59 -0400\r
37 Date: Sun, 22 Apr 2012 14:01:59 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: Justus Winter <4winter@informatik.uni-hamburg.de>\r
40 Subject: Re: [PATCH 1/7] Split notmuch_database_close into two functions\r
41 Message-ID: <20120422180159.GG17810@mit.edu>\r
42 References: <20120422120620.26225.40778@thinkbox.jade-hamburg.de>\r
43         <1335096477-27537-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
44 MIME-Version: 1.0\r
45 Content-Type: text/plain; charset=us-ascii\r
46 Content-Disposition: inline\r
47 In-Reply-To:\r
48  <1335096477-27537-1-git-send-email-4winter@informatik.uni-hamburg.de>\r
49 User-Agent: Mutt/1.5.21 (2010-09-15)\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFmphleLIzCtJLcpLzFFi42IRYrdT153lPsXf4P5jaYvZrT+YLK7fnMns\r
52         wOQx8fxpNo9nq24xBzBFcdmkpOZklqUW6dslcGVMXHiateCXasWk491MDYyT5boYOTkkBEwk\r
53         7jXOY4WwxSQu3FvP1sXIxSEksI9RonFeExNIQkhgA6PEp/lQiZNMEif75jJDOEsYJX79WsYO\r
54         UsUioCqx6OwERhCbTUBDYtv+5WC2iICpxIYHD8BqmAWkJb79bgabKizgIbHj2h6wGl4BHYkJ\r
55         h7qYIIZ2Mko8+L+TBSIhKHFy5hMWiGYtiRv/XgIVcYANWv6PAyTMKRAksXZ1I9gcUQEViSkn\r
56         t7FNYBSahaR7FpLuWQjdCxiZVzHKpuRW6eYmZuYUpybrFicn5uWlFuka6+VmluilppRuYgQF\r
57         Nqck3w7GrweVDjEKcDAq8fA6mU/2F2JNLCuuzD3EKMnBpCTK+9ptir8QX1J+SmVGYnFGfFFp\r
58         TmrxIUYJDmYlEd7PIkDlvCmJlVWpRfkwKWkOFiVxXjWtd35CAumJJanZqakFqUUwWRkODiUJ\r
59         XjNgBAsJFqWmp1akZeaUIKSZODhBhvMADf8Ospi3uCAxtzgzHSJ/ilFRSpxXA6RZACSRUZoH\r
60         1wtLPK8YxYFeEeYVB6niASYtuO5XQIOZgAYnxEwCGVySiJCSamAUe7loa9uv/LnnK6ZsPb7p\r
61         1YS5Jpt6kkR7OT5NdV0wYW3h3ICQi221WzY3Sf33Fpu6MvFhceadJVoycVwMbceFzWcG64u/\r
62         0bmQefzh/pnct4sCqxsPRSfI+C/NObnnxRl+KfU1p/P9ghW2Xfu35ZHaTMeWteymu6a6HhYN\r
63         Otq2fzaLS45v4xJbJZbijERDLeai4kQAPp2AphcDAAA=\r
64 Cc: notmuch@notmuchmail.org\r
65 X-BeenThere: notmuch@notmuchmail.org\r
66 X-Mailman-Version: 2.1.13\r
67 Precedence: list\r
68 List-Id: "Use and development of the notmuch mail system."\r
69         <notmuch.notmuchmail.org>\r
70 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
72 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
73 List-Post: <mailto:notmuch@notmuchmail.org>\r
74 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
75 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
76         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
77 X-List-Received-Date: Sun, 22 Apr 2012 18:02:03 -0000\r
78 \r
79 Quoth Justus Winter on Apr 22 at  2:07 pm:\r
80 > Formerly notmuch_database_close closed the xapian database and\r
81 > destroyed the talloc structure associated with the notmuch database\r
82 > object. Split notmuch_database_close into notmuch_database_close and\r
83 > notmuch_database_destroy.\r
84\r
85 > This makes it possible for long running programs to close the xapian\r
86 > database and thus release the lock associated with it without\r
87 > destroying the data structures obtained from it.\r
88\r
89 > This also makes the api more consistent since every other data\r
90 > structure has a destructor function.\r
91\r
92 > Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>\r
93 > ---\r
94 >  lib/database.cc |   14 ++++++++++++--\r
95 >  lib/notmuch.h   |   15 +++++++++++----\r
96 >  2 files changed, 23 insertions(+), 6 deletions(-)\r
97\r
98 > diff --git a/lib/database.cc b/lib/database.cc\r
99 > index 16c4354..2fefcad 100644\r
100 > --- a/lib/database.cc\r
101 > +++ b/lib/database.cc\r
102 > @@ -642,7 +642,7 @@ notmuch_database_open (const char *path,\r
103 >                        "       read-write mode.\n",\r
104 >                        notmuch_path, version, NOTMUCH_DATABASE_VERSION);\r
105 >               notmuch->mode = NOTMUCH_DATABASE_MODE_READ_ONLY;\r
106 > -             notmuch_database_close (notmuch);\r
107 > +             notmuch_database_destroy (notmuch);\r
108 >               notmuch = NULL;\r
109 >               goto DONE;\r
110 >           }\r
111 > @@ -702,7 +702,7 @@ notmuch_database_open (const char *path,\r
112 >      } catch (const Xapian::Error &error) {\r
113 >       fprintf (stderr, "A Xapian exception occurred opening database: %s\n",\r
114 >                error.get_msg().c_str());\r
115 > -     notmuch_database_close (notmuch);\r
116 > +     notmuch_database_destroy (notmuch);\r
117 >       notmuch = NULL;\r
118 >      }\r
119 >  \r
120 > @@ -738,9 +738,19 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
121 >      }\r
122 >  \r
123 >      delete notmuch->term_gen;\r
124 > +    notmuch->term_gen = NULL;\r
125 >      delete notmuch->query_parser;\r
126 > +    notmuch->query_parser = NULL;\r
127 >      delete notmuch->xapian_db;\r
128 > +    notmuch->xapian_db = NULL;\r
129 >      delete notmuch->value_range_processor;\r
130 > +    notmuch->value_range_processor = NULL;\r
131 > +}\r
132 > +\r
133 > +void\r
134 > +notmuch_database_destroy (notmuch_database_t *notmuch)\r
135 > +{\r
136 > +    notmuch_database_close (notmuch);\r
137 >      talloc_free (notmuch);\r
138 >  }\r
139 >  \r
140 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
141 > index 673c423..84c9265 100644\r
142 > --- a/lib/notmuch.h\r
143 > +++ b/lib/notmuch.h\r
144 > @@ -133,7 +133,7 @@ typedef struct _notmuch_filenames notmuch_filenames_t;\r
145 >   *\r
146 >   * After a successful call to notmuch_database_create, the returned\r
147 >   * database will be open so the caller should call\r
148 > - * notmuch_database_close when finished with it.\r
149 > + * notmuch_database_destroy when finished with it.\r
150 >   *\r
151 >   * The database will not yet have any data in it\r
152 >   * (notmuch_database_create itself is a very cheap function). Messages\r
153 > @@ -165,7 +165,7 @@ typedef enum {\r
154 >   * An existing notmuch database can be identified by the presence of a\r
155 >   * directory named ".notmuch" below 'path'.\r
156 >   *\r
157 > - * The caller should call notmuch_database_close when finished with\r
158 > + * The caller should call notmuch_database_destroy when finished with\r
159 >   * this database.\r
160 >   *\r
161 >   * In case of any failure, this function returns NULL, (after printing\r
162 > @@ -175,11 +175,18 @@ notmuch_database_t *\r
163 >  notmuch_database_open (const char *path,\r
164 >                      notmuch_database_mode_t mode);\r
165 >  \r
166 > -/* Close the given notmuch database, freeing all associated\r
167 > - * resources. See notmuch_database_open. */\r
168 > +/* Close the given notmuch database.\r
169 > + *\r
170 > + * This function is called by notmuch_database_destroy and can be\r
171 > + * called multiple times. */\r
172 \r
173 This needs a comment explaining the implications of closing the\r
174 database.  Perhaps something like this (modeled on\r
175 Xapian::Database::close's documentation)\r
176 \r
177 /* Close the given notmuch database.\r
178  *\r
179  * After notmuch_database_close has been called, calls to other\r
180  * functions on objects derived from this database may either behave\r
181  * as if the database had not been closed (e.g., if the required data\r
182  * has been cached) or may fail with a\r
183  * NOTMUCH_STATUS_XAPIAN_EXCEPTION.\r
184  *\r
185  * notmuch_database_close can be called multiple times.  Later calls\r
186  * have no affect. \r
187  */\r
188 \r
189 >  void\r
190 >  notmuch_database_close (notmuch_database_t *database);\r
191 >  \r
192 > +/* Destroy the notmuch database freeing all associated\r
193 > + * resources */\r
194 \r
195 This should mention that this also closes the database (currently you\r
196 mention this in the doc for notmuch_database_close, but it's a reverse\r
197 reference there; that could probably even be omitted).  Perhaps\r
198 \r
199 /* Destroy the notmuch database, closing it if necessary and freeing\r
200  * all associated resources. */\r
201 \r
202 > +void\r
203 > +notmuch_database_destroy (notmuch_database_t *database);\r
204 > +\r
205 >  /* Return the database path of the given database.\r
206 >   *\r
207 >   * The return value is a string owned by notmuch so should not be\r