]> git.notmuchmail.org Git - notmuch/blobdiff - bindings/python/notmuch/database.py
python: fix NULL pointer tests
[notmuch] / bindings / python / notmuch / database.py
index 44d40fdb322acc4ac2af5686e01ea856212f97b2..525f7c9a0ca9d0b2a933faa26185e3671e736e8f 100644 (file)
@@ -14,7 +14,7 @@ for more details.
 You should have received a copy of the GNU General Public License
 along with notmuch.  If not, see <http://www.gnu.org/licenses/>.
 
-Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>'
+Copyright 2010 Sebastian Spaeth <Sebastian@SSpaeth.de>
 """
 
 import os
@@ -161,8 +161,13 @@ class Database(object):
         else:
             self.create(path)
 
+    _destroy = nmlib.notmuch_database_destroy
+    _destroy.argtypes = [NotmuchDatabaseP]
+    _destroy.restype = None
+
     def __del__(self):
-        self.close()
+        if self._db:
+            self._destroy(self._db)
 
     def _assert_db_is_initialized(self):
         """Raises :exc:`NotInitializedError` if self._db is `None`"""
@@ -184,7 +189,7 @@ class Database(object):
         :raises: :exc:`NotmuchError` in case of any failure
                     (possibly after printing an error message on stderr).
         """
-        if self._db is not None:
+        if self._db:
             raise NotmuchError(message="Cannot create db, this Database() "
                                        "already has an open one.")
 
@@ -218,10 +223,11 @@ class Database(object):
     _close.restype = None
 
     def close(self):
-        """Close and free the notmuch database if needed"""
-        if self._db is not None:
+        '''
+        Closes the notmuch database.
+        '''
+        if self._db:
             self._close(self._db)
-            self._db = None
 
     def __enter__(self):
         '''