]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Treat NULL as a valid (and empty) notmuch_filenames_t iterator.
authorCarl Worth <cworth@cworth.org>
Wed, 6 Jan 2010 22:35:11 +0000 (14:35 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 6 Jan 2010 22:35:11 +0000 (14:35 -0800)
This will be convenient to avoid some special-casing in higher-level
code.

lib/directory.cc
lib/notmuch.h

index 196f78059ecbace2e347aeb48222c787bf7e4060..d5015e0ac6f351102b894d0e5efe96f437575408 100644 (file)
@@ -81,12 +81,18 @@ _notmuch_filenames_create (void *ctx,
 notmuch_bool_t
 notmuch_filenames_has_more (notmuch_filenames_t *filenames)
 {
 notmuch_bool_t
 notmuch_filenames_has_more (notmuch_filenames_t *filenames)
 {
+    if (filenames == NULL)
+       return NULL;
+
     return (filenames->iterator != filenames->end);
 }
 
 const char *
 notmuch_filenames_get (notmuch_filenames_t *filenames)
 {
     return (filenames->iterator != filenames->end);
 }
 
 const char *
 notmuch_filenames_get (notmuch_filenames_t *filenames)
 {
+    if (filenames == NULL || filenames->iterator == filenames->end)
+       return NULL;
+
     if (filenames->filename == NULL) {
        std::string term = *filenames->iterator;
 
     if (filenames->filename == NULL) {
        std::string term = *filenames->iterator;
 
@@ -101,6 +107,9 @@ notmuch_filenames_get (notmuch_filenames_t *filenames)
 void
 notmuch_filenames_advance (notmuch_filenames_t *filenames)
 {
 void
 notmuch_filenames_advance (notmuch_filenames_t *filenames)
 {
+    if (filenames == NULL)
+       return;
+
     if (filenames->filename) {
        talloc_free (filenames->filename);
        filenames->filename = NULL;
     if (filenames->filename) {
        talloc_free (filenames->filename);
        filenames->filename = NULL;
@@ -113,6 +122,9 @@ notmuch_filenames_advance (notmuch_filenames_t *filenames)
 void
 notmuch_filenames_destroy (notmuch_filenames_t *filenames)
 {
 void
 notmuch_filenames_destroy (notmuch_filenames_t *filenames)
 {
+    if (filenames == NULL)
+       return;
+
     talloc_free (filenames);
 }
 
     talloc_free (filenames);
 }
 
index 110061c29ae62d37e8df2b53038980d2e3a76cea..f3e1d28661414abaca44088dba4931c853027daa 100644 (file)
@@ -996,6 +996,9 @@ notmuch_directory_destroy (notmuch_directory_t *directory);
  * When this function returns TRUE, notmuch_filenames_get will return
  * a valid string. Whereas when this function returns FALSE,
  * notmuch_filenames_get will return NULL.
  * When this function returns TRUE, notmuch_filenames_get will return
  * a valid string. Whereas when this function returns FALSE,
  * notmuch_filenames_get will return NULL.
+ *
+ * It is acceptable to pass NULL for 'filenames', in which case this
+ * function will always return FALSE.
  */
 notmuch_bool_t
 notmuch_filenames_has_more (notmuch_filenames_t *filenames);
  */
 notmuch_bool_t
 notmuch_filenames_has_more (notmuch_filenames_t *filenames);
@@ -1004,11 +1007,17 @@ notmuch_filenames_has_more (notmuch_filenames_t *filenames);
  *
  * Note: The returned string belongs to 'filenames' and has a lifetime
  * identical to it (and the directory to which it ultimately belongs).
  *
  * Note: The returned string belongs to 'filenames' and has a lifetime
  * identical to it (and the directory to which it ultimately belongs).
+ *
+ * It is acceptable to pass NULL for 'filenames', in which case this
+ * function will always return NULL.
  */
 const char *
 notmuch_filenames_get (notmuch_filenames_t *filenames);
 
 /* Advance the 'filenames' iterator to the next filename.
  */
 const char *
 notmuch_filenames_get (notmuch_filenames_t *filenames);
 
 /* Advance the 'filenames' iterator to the next filename.
+ *
+ * It is acceptable to pass NULL for 'filenames', in which case this
+ * function will do nothing.
  */
 void
 notmuch_filenames_advance (notmuch_filenames_t *filenames);
  */
 void
 notmuch_filenames_advance (notmuch_filenames_t *filenames);
@@ -1018,6 +1027,9 @@ notmuch_filenames_advance (notmuch_filenames_t *filenames);
  * It's not strictly necessary to call this function. All memory from
  * the notmuch_filenames_t object will be reclaimed when the
  * containing directory object is destroyed.
  * It's not strictly necessary to call this function. All memory from
  * the notmuch_filenames_t object will be reclaimed when the
  * containing directory object is destroyed.
+ *
+ * It is acceptable to pass NULL for 'filenames', in which case this
+ * function will do nothing.
  */
 void
 notmuch_filenames_destroy (notmuch_filenames_t *filenames);
  */
 void
 notmuch_filenames_destroy (notmuch_filenames_t *filenames);