unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* Start to eliminate printing from libnotmuch
@ 2014-12-26 17:42 David Bremner
  2014-12-26 17:42 ` [PATCH 1/4] lib: add passthrough logger function David Bremner
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: David Bremner @ 2014-12-26 17:42 UTC (permalink / raw)
  To: notmuch

This series only centralizes the printing to one function.  It assumes
that any future solution will use some configuration information or
state in the notmuch_database_t object. To make this available
everywhere only requires internal API changes (i.e. functions in
notmuch-private.h).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/4] lib: add passthrough logger function
  2014-12-26 17:42 Start to eliminate printing from libnotmuch David Bremner
@ 2014-12-26 17:42 ` David Bremner
  2014-12-26 17:42 ` [PATCH 2/4] lib: add private function to extract the database for a message David Bremner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2014-12-26 17:42 UTC (permalink / raw)
  To: notmuch

As a first step to eliminating all the fprintfs in the library, make a
logger function that just calls fprintf. This is a bit more complex
than needed, because we want to do something more interesting with the
formatted string in the future.
---
 lib/database.cc | 19 +++++++++++++++++++
 lib/notmuch.h   | 10 +++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/lib/database.cc b/lib/database.cc
index 3601f9d..f3c62ee 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -916,6 +916,25 @@ notmuch_database_open (const char *path,
     return status;
 }
 
+void
+notmuch_database_log (notmuch_database_t *notmuch,
+		      const char *format,
+		      ...)
+{
+    va_list va_args;
+    const char *message;
+    
+    va_start (va_args, format);
+
+    message = talloc_vasprintf (notmuch, format, va_args);
+
+    /* XXX do something more clever here */
+    fputs (message, stderr);
+
+    talloc_free ((char *)message);
+
+}
+
 notmuch_status_t
 notmuch_database_close (notmuch_database_t *notmuch)
 {
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 220839b..c8c8124 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -279,7 +279,15 @@ notmuch_status_t
 notmuch_database_open (const char *path,
 		       notmuch_database_mode_t mode,
 		       notmuch_database_t **database);
-
+/**
+ * Log a message to where the database is configured to log it
+ *
+ * Initially this does notmuch interesting, since the output is not
+ * yet configurable.
+ */
+void
+notmuch_database_log (notmuch_database_t *notmuch,
+		      const char *format, ...);
 /**
  * Commit changes and close the given notmuch database.
  *
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] lib: add private function to extract the database for a message.
  2014-12-26 17:42 Start to eliminate printing from libnotmuch David Bremner
  2014-12-26 17:42 ` [PATCH 1/4] lib: add passthrough logger function David Bremner
@ 2014-12-26 17:42 ` David Bremner
  2014-12-26 17:42 ` [PATCH 3/4] lib: replace almost all fprintfs in library with n_d_log David Bremner
  2014-12-26 17:42 ` [PATCH 4/4] lib: eliminate fprintf from _notmuch_message_file_open David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2014-12-26 17:42 UTC (permalink / raw)
  To: notmuch

This is needed by logging in functions outside message.cc that take
only a notmuch_message_t object.
---
 lib/message.cc        | 6 ++++++
 lib/notmuch-private.h | 2 ++
 2 files changed, 8 insertions(+)

diff --git a/lib/message.cc b/lib/message.cc
index a7a13cc..43cc078 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1625,3 +1625,9 @@ notmuch_message_destroy (notmuch_message_t *message)
 {
     talloc_free (message);
 }
+
+notmuch_database_t *
+_notmuch_message_database (notmuch_message_t *message)
+{
+    return message->notmuch;
+}
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 012ad25..d4b4858 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -469,6 +469,8 @@ _notmuch_doc_id_set_remove (notmuch_doc_id_set_t *doc_ids,
 void
 _notmuch_message_add_reply (notmuch_message_t *message,
 			    notmuch_message_t *reply);
+notmuch_database_t *
+_notmuch_message_database (notmuch_message_t *message);
 
 /* sha1.c */
 
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] lib: replace almost all fprintfs in library with n_d_log
  2014-12-26 17:42 Start to eliminate printing from libnotmuch David Bremner
  2014-12-26 17:42 ` [PATCH 1/4] lib: add passthrough logger function David Bremner
  2014-12-26 17:42 ` [PATCH 2/4] lib: add private function to extract the database for a message David Bremner
@ 2014-12-26 17:42 ` David Bremner
  2014-12-26 17:42 ` [PATCH 4/4] lib: eliminate fprintf from _notmuch_message_file_open David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2014-12-26 17:42 UTC (permalink / raw)
  To: notmuch

This is not supposed to change any functionality from an end user
point of view. The remaining fprintf will need an internal API change.
---
 lib/database.cc  | 56 ++++++++++++++++++++++++++++----------------------------
 lib/directory.cc |  4 ++--
 lib/index.cc     | 11 +++++++----
 lib/message.cc   |  6 +++---
 lib/query.cc     | 18 +++++++++---------
 5 files changed, 49 insertions(+), 46 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index f3c62ee..8143758 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -450,7 +450,7 @@ notmuch_database_find_message (notmuch_database_t *notmuch,
 
 	return NOTMUCH_STATUS_SUCCESS;
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred finding message: %s.\n",
+	notmuch_database_log (notmuch, "A Xapian exception occurred finding message: %s.\n",
 		 error.get_msg().c_str());
 	notmuch->exception_reported = TRUE;
 	*message_ret = NULL;
@@ -609,21 +609,21 @@ notmuch_database_create (const char *path, notmuch_database_t **database)
     int err;
 
     if (path == NULL) {
-	fprintf (stderr, "Error: Cannot create a database for a NULL path.\n");
+	notmuch_database_log (notmuch, "Error: Cannot create a database for a NULL path.\n");
 	status = NOTMUCH_STATUS_NULL_POINTER;
 	goto DONE;
     }
 
     err = stat (path, &st);
     if (err) {
-	fprintf (stderr, "Error: Cannot create database at %s: %s.\n",
+	notmuch_database_log (notmuch, "Error: Cannot create database at %s: %s.\n",
 		 path, strerror (errno));
 	status = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
     }
 
     if (! S_ISDIR (st.st_mode)) {
-	fprintf (stderr, "Error: Cannot create database at %s: Not a directory.\n",
+	notmuch_database_log (notmuch, "Error: Cannot create database at %s: Not a directory.\n",
 		 path);
 	status = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
@@ -634,7 +634,7 @@ notmuch_database_create (const char *path, notmuch_database_t **database)
     err = mkdir (notmuch_path, 0755);
 
     if (err) {
-	fprintf (stderr, "Error: Cannot create directory %s: %s.\n",
+	notmuch_database_log (notmuch, "Error: Cannot create directory %s: %s.\n",
 		 notmuch_path, strerror (errno));
 	status = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
@@ -671,7 +671,7 @@ notmuch_status_t
 _notmuch_database_ensure_writable (notmuch_database_t *notmuch)
 {
     if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) {
-	fprintf (stderr, "Cannot write to a read-only database.\n");
+	notmuch_database_log (notmuch, "Cannot write to a read-only database.\n");
 	return NOTMUCH_STATUS_READ_ONLY_DATABASE;
     }
 
@@ -770,27 +770,27 @@ notmuch_database_open (const char *path,
     static int initialized = 0;
 
     if (path == NULL) {
-	fprintf (stderr, "Error: Cannot open a database for a NULL path.\n");
+	notmuch_database_log (notmuch, "Error: Cannot open a database for a NULL path.\n");
 	status = NOTMUCH_STATUS_NULL_POINTER;
 	goto DONE;
     }
 
     if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {
-	fprintf (stderr, "Out of memory\n");
+	notmuch_database_log (notmuch, "Out of memory\n");
 	status = NOTMUCH_STATUS_OUT_OF_MEMORY;
 	goto DONE;
     }
 
     err = stat (notmuch_path, &st);
     if (err) {
-	fprintf (stderr, "Error opening database at %s: %s\n",
+	notmuch_database_log (notmuch, "Error opening database at %s: %s\n",
 		 notmuch_path, strerror (errno));
 	status = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
     }
 
     if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {
-	fprintf (stderr, "Out of memory\n");
+	notmuch_database_log (notmuch, "Out of memory\n");
 	status = NOTMUCH_STATUS_OUT_OF_MEMORY;
 	goto DONE;
     }
@@ -830,7 +830,7 @@ notmuch_database_open (const char *path,
 	 * means a dramatically incompatible change. */
 	version = notmuch_database_get_version (notmuch);
 	if (version > NOTMUCH_DATABASE_VERSION) {
-	    fprintf (stderr,
+	    notmuch_database_log (notmuch,
 		     "Error: Notmuch database at %s\n"
 		     "       has a newer database format version (%u) than supported by this\n"
 		     "       version of notmuch (%u).\n",
@@ -849,7 +849,7 @@ notmuch_database_open (const char *path,
 	    version, mode == NOTMUCH_DATABASE_MODE_READ_WRITE ? 'w' : 'r',
 	    &incompat_features);
 	if (incompat_features) {
-	    fprintf (stderr,
+	    notmuch_database_log (notmuch,
 		     "Error: Notmuch database at %s\n"
 		     "       requires features (%s)\n"
 		     "       not supported by this version of notmuch.\n",
@@ -899,7 +899,7 @@ notmuch_database_open (const char *path,
 	    notmuch->query_parser->add_prefix (prefix->name, prefix->prefix);
 	}
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred opening database: %s\n",
+	notmuch_database_log (notmuch, "A Xapian exception occurred opening database: %s\n",
 		 error.get_msg().c_str());
 	notmuch_database_destroy (notmuch);
 	notmuch = NULL;
@@ -961,7 +961,7 @@ notmuch_database_close (notmuch_database_t *notmuch)
 	} catch (const Xapian::Error &error) {
 	    status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 	    if (! notmuch->exception_reported) {
-		fprintf (stderr, "Error: A Xapian exception occurred closing database: %s\n",
+		notmuch_database_log (notmuch, "Error: A Xapian exception occurred closing database: %s\n",
 			 error.get_msg().c_str());
 	    }
 	}
@@ -1088,12 +1088,12 @@ notmuch_database_compact (const char *path,
     }
 
     if (stat (backup_path, &statbuf) != -1) {
-	fprintf (stderr, "Path already exists: %s\n", backup_path);
+	notmuch_database_log (notmuch, "Path already exists: %s\n", backup_path);
 	ret = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
     }
     if (errno != ENOENT) {
-	fprintf (stderr, "Unknown error while stat()ing path: %s\n",
+	notmuch_database_log (notmuch, "Unknown error while stat()ing path: %s\n",
 		 strerror (errno));
 	ret = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
@@ -1113,20 +1113,20 @@ notmuch_database_compact (const char *path,
 	compactor.set_destdir (compact_xapian_path);
 	compactor.compact ();
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "Error while compacting: %s\n", error.get_msg().c_str());
+	notmuch_database_log (notmuch, "Error while compacting: %s\n", error.get_msg().c_str());
 	ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 	goto DONE;
     }
 
     if (rename (xapian_path, backup_path)) {
-	fprintf (stderr, "Error moving %s to %s: %s\n",
+	notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",
 		 xapian_path, backup_path, strerror (errno));
 	ret = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
     }
 
     if (rename (compact_xapian_path, xapian_path)) {
-	fprintf (stderr, "Error moving %s to %s: %s\n",
+	notmuch_database_log (notmuch, "Error moving %s to %s: %s\n",
 		 compact_xapian_path, xapian_path, strerror (errno));
 	ret = NOTMUCH_STATUS_FILE_ERROR;
 	goto DONE;
@@ -1134,7 +1134,7 @@ notmuch_database_compact (const char *path,
 
     if (! keep_backup) {
 	if (rmtree (backup_path)) {
-	    fprintf (stderr, "Error removing old database %s: %s\n",
+	    notmuch_database_log (notmuch, "Error removing old database %s: %s\n",
 		     backup_path, strerror (errno));
 	    ret = NOTMUCH_STATUS_FILE_ERROR;
 	    goto DONE;
@@ -1163,7 +1163,7 @@ notmuch_database_compact (unused (const char *path),
 			  unused (notmuch_compact_status_cb_t status_cb),
 			  unused (void *closure))
 {
-    fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n");
+    notmuch_database_log (notmuch, "notmuch was compiled against a xapian version lacking compaction support.\n");
     return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
 }
 #endif
@@ -1441,7 +1441,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
 	    }
 
 	    if (private_status) {
-		fprintf (stderr,
+		notmuch_database_log (notmuch,
 			 "Upgrade failed while creating ghost messages.\n");
 		status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost");
 		goto DONE;
@@ -1491,7 +1491,7 @@ notmuch_database_begin_atomic (notmuch_database_t *notmuch)
     try {
 	(static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred beginning transaction: %s.\n",
+	notmuch_database_log (notmuch, "A Xapian exception occurred beginning transaction: %s.\n",
 		 error.get_msg().c_str());
 	notmuch->exception_reported = TRUE;
 	return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
@@ -1525,7 +1525,7 @@ notmuch_database_end_atomic (notmuch_database_t *notmuch)
 	if (thresh && atoi (thresh) == 1)
 	    db->flush ();
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred committing transaction: %s.\n",
+	notmuch_database_log (notmuch, "A Xapian exception occurred committing transaction: %s.\n",
 		 error.get_msg().c_str());
 	notmuch->exception_reported = TRUE;
 	return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
@@ -1771,7 +1771,7 @@ notmuch_database_get_directory (notmuch_database_t *notmuch,
 	*directory = _notmuch_directory_create (notmuch, path,
 						NOTMUCH_FIND_LOOKUP, &status);
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred getting directory: %s.\n",
+	notmuch_database_log (notmuch, "A Xapian exception occurred getting directory: %s.\n",
 		 error.get_msg().c_str());
 	notmuch->exception_reported = TRUE;
 	status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
@@ -2353,7 +2353,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
 
 	_notmuch_message_sync (message);
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred adding message: %s.\n",
+	notmuch_database_log (notmuch, "A Xapian exception occurred adding message: %s.\n",
 		 error.get_msg().c_str());
 	notmuch->exception_reported = TRUE;
 	ret = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
@@ -2445,7 +2445,7 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
 		status = NOTMUCH_STATUS_OUT_OF_MEMORY;
 	}
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "Error: A Xapian exception occurred finding message by filename: %s\n",
+	notmuch_database_log (notmuch, "Error: A Xapian exception occurred finding message by filename: %s\n",
 		 error.get_msg().c_str());
 	notmuch->exception_reported = TRUE;
 	status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
@@ -2498,7 +2498,7 @@ notmuch_database_get_all_tags (notmuch_database_t *db)
 	_notmuch_string_list_sort (tags);
 	return _notmuch_tags_create (db, tags);
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred getting tags: %s.\n",
+	notmuch_database_log (db, "A Xapian exception occurred getting tags: %s.\n",
 		 error.get_msg().c_str());
 	db->exception_reported = TRUE;
 	return NULL;
diff --git a/lib/directory.cc b/lib/directory.cc
index 8daaec8..955ffac 100644
--- a/lib/directory.cc
+++ b/lib/directory.cc
@@ -186,7 +186,7 @@ _notmuch_directory_create (notmuch_database_t *notmuch,
 	directory->mtime = Xapian::sortable_unserialise (
 	    directory->doc.get_value (NOTMUCH_VALUE_TIMESTAMP));
     } catch (const Xapian::Error &error) {
-	fprintf (stderr,
+	notmuch_database_log (notmuch,
 		 "A Xapian exception occurred creating a directory: %s.\n",
 		 error.get_msg().c_str());
 	notmuch->exception_reported = TRUE;
@@ -228,7 +228,7 @@ notmuch_directory_set_mtime (notmuch_directory_t *directory,
 
 	db->replace_document (directory->document_id, directory->doc);
     } catch (const Xapian::Error &error) {
-	fprintf (stderr,
+	notmuch_database_log (notmuch,
 		 "A Xapian exception occurred setting directory mtime: %s.\n",
 		 error.get_msg().c_str());
 	notmuch->exception_reported = TRUE;
diff --git a/lib/index.cc b/lib/index.cc
index 1a2e63d..8fce9b8 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -314,7 +314,8 @@ _index_mime_part (notmuch_message_t *message,
     const char *charset;
 
     if (! part) {
-	fprintf (stderr, "Warning: Not indexing empty mime part.\n");
+	notmuch_database_log (_notmuch_message_database (message),
+			      "Warning: Not indexing empty mime part.\n");
 	return;
     }
 
@@ -334,7 +335,8 @@ _index_mime_part (notmuch_message_t *message,
 		if (i == 1)
 		    continue;
 		if (i > 1)
-		    fprintf (stderr, "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");
+		    notmuch_database_log (_notmuch_message_database (message),
+					  "Warning: Unexpected extra parts of multipart/signed. Indexing anyway.\n");
 	    }
 	    if (GMIME_IS_MULTIPART_ENCRYPTED (multipart)) {
 		/* Don't index encrypted parts. */
@@ -357,8 +359,9 @@ _index_mime_part (notmuch_message_t *message,
     }
 
     if (! (GMIME_IS_PART (part))) {
-	fprintf (stderr, "Warning: Not indexing unknown mime part: %s.\n",
-		 g_type_name (G_OBJECT_TYPE (part)));
+	notmuch_database_log (_notmuch_message_database (message),
+			      "Warning: Not indexing unknown mime part: %s.\n",
+			      g_type_name (G_OBJECT_TYPE (part)));
 	return;
     }
 
diff --git a/lib/message.cc b/lib/message.cc
index 43cc078..60601ef 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -252,7 +252,7 @@ _notmuch_message_create_for_message_id (notmuch_database_t *notmuch,
 
 	doc_id = _notmuch_database_generate_doc_id (notmuch);
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred creating message: %s\n",
+	notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred creating message: %s\n",
 		 error.get_msg().c_str());
 	notmuch->exception_reported = TRUE;
 	*status_ret = NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION;
@@ -467,7 +467,7 @@ notmuch_message_get_header (notmuch_message_t *message, const char *header)
 		return talloc_strdup (message, value.c_str ());
 
 	} catch (Xapian::Error &error) {
-	    fprintf (stderr, "A Xapian exception occurred when reading header: %s\n",
+	    notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading header: %s\n",
 		     error.get_msg().c_str());
 	    message->notmuch->exception_reported = TRUE;
 	    return NULL;
@@ -920,7 +920,7 @@ notmuch_message_get_date (notmuch_message_t *message)
     try {
 	value = message->doc.get_value (NOTMUCH_VALUE_TIMESTAMP);
     } catch (Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred when reading date: %s\n",
+	notmuch_database_log(_notmuch_message_database (message), "A Xapian exception occurred when reading date: %s\n",
 		 error.get_msg().c_str());
 	message->notmuch->exception_reported = TRUE;
 	return 0;
diff --git a/lib/query.cc b/lib/query.cc
index 60ff8bd..677b130 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -78,7 +78,7 @@ notmuch_query_create (notmuch_database_t *notmuch,
     notmuch_query_t *query;
 
     if (_debug_query ())
-	fprintf (stderr, "Query string is:\n%s\n", query_string);
+	notmuch_database_log (notmuch, "Query string is:\n%s\n", query_string);
 
     query = talloc (notmuch, notmuch_query_t);
     if (unlikely (query == NULL))
@@ -266,9 +266,9 @@ notmuch_query_search_messages (notmuch_query_t *query)
 	}
 
 	if (_debug_query ()) {
-	    fprintf (stderr, "Exclude query is:\n%s\n",
+	    notmuch_database_log (notmuch, "Exclude query is:\n%s\n",
 		     exclude_query.get_description ().c_str ());
-	    fprintf (stderr, "Final query is:\n%s\n",
+	    notmuch_database_log (notmuch, "Final query is:\n%s\n",
 		     final_query.get_description ().c_str ());
 	}
 
@@ -282,9 +282,9 @@ notmuch_query_search_messages (notmuch_query_t *query)
 	return &messages->base;
 
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred performing query: %s\n",
+	notmuch_database_log (notmuch, "A Xapian exception occurred performing query: %s\n",
 		 error.get_msg().c_str());
-	fprintf (stderr, "Query string was: %s\n", query->query_string);
+	notmuch_database_log (notmuch, "Query string was: %s\n", query->query_string);
 	notmuch->exception_reported = TRUE;
 	talloc_free (messages);
 	return NULL;
@@ -549,9 +549,9 @@ notmuch_query_count_messages (notmuch_query_t *query)
 	enquire.set_docid_order(Xapian::Enquire::ASCENDING);
 
 	if (_debug_query ()) {
-	    fprintf (stderr, "Exclude query is:\n%s\n",
+	    notmuch_database_log (notmuch, "Exclude query is:\n%s\n",
 		     exclude_query.get_description ().c_str ());
-	    fprintf (stderr, "Final query is:\n%s\n",
+	    notmuch_database_log (notmuch, "Final query is:\n%s\n",
 		     final_query.get_description ().c_str ());
 	}
 
@@ -562,9 +562,9 @@ notmuch_query_count_messages (notmuch_query_t *query)
 	count = mset.get_matches_estimated();
 
     } catch (const Xapian::Error &error) {
-	fprintf (stderr, "A Xapian exception occurred: %s\n",
+	notmuch_database_log (notmuch, "A Xapian exception occurred: %s\n",
 		 error.get_msg().c_str());
-	fprintf (stderr, "Query string was: %s\n", query->query_string);
+	notmuch_database_log (notmuch, "Query string was: %s\n", query->query_string);
     }
 
     return count;
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] lib: eliminate fprintf from _notmuch_message_file_open
  2014-12-26 17:42 Start to eliminate printing from libnotmuch David Bremner
                   ` (2 preceding siblings ...)
  2014-12-26 17:42 ` [PATCH 3/4] lib: replace almost all fprintfs in library with n_d_log David Bremner
@ 2014-12-26 17:42 ` David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2014-12-26 17:42 UTC (permalink / raw)
  To: notmuch

I considered fancier solutions but memory management is already a bit
delicate here, and I didn't want to mess it up. The remaining fprintf
is removed by Jani's series un-deprecating single message mboxes.
---
 lib/database.cc       |  2 +-
 lib/message-file.c    | 11 +++++++----
 lib/message.cc        |  3 ++-
 lib/notmuch-private.h |  7 ++++---
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 8143758..b22a0e6 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -2244,7 +2244,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
     if (ret)
 	return ret;
 
-    message_file = _notmuch_message_file_open (filename);
+    message_file = _notmuch_message_file_open (notmuch, filename);
     if (message_file == NULL)
 	return NOTMUCH_STATUS_FILE_ERROR;
 
diff --git a/lib/message-file.c b/lib/message-file.c
index eda1b74..ce435dd 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -76,7 +76,8 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message)
 /* Create a new notmuch_message_file_t for 'filename' with 'ctx' as
  * the talloc owner. */
 notmuch_message_file_t *
-_notmuch_message_file_open_ctx (void *ctx, const char *filename)
+_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,
+				void *ctx, const char *filename)
 {
     notmuch_message_file_t *message;
 
@@ -98,16 +99,18 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename)
     return message;
 
   FAIL:
-    fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno));
+    notmuch_database_log (notmuch, "Error opening %s: %s\n",
+			  filename, strerror (errno));
     _notmuch_message_file_close (message);
 
     return NULL;
 }
 
 notmuch_message_file_t *
-_notmuch_message_file_open (const char *filename)
+_notmuch_message_file_open (notmuch_database_t *notmuch,
+			    const char *filename)
 {
-    return _notmuch_message_file_open_ctx (NULL, filename);
+    return _notmuch_message_file_open_ctx (notmuch, NULL, filename);
 }
 
 void
diff --git a/lib/message.cc b/lib/message.cc
index 60601ef..3abe7ba 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -437,7 +437,8 @@ _notmuch_message_ensure_message_file (notmuch_message_t *message)
     if (unlikely (filename == NULL))
 	return;
 
-    message->message_file = _notmuch_message_file_open_ctx (message, filename);
+    message->message_file = _notmuch_message_file_open_ctx (
+	_notmuch_message_database (message), message, filename);
 }
 
 const char *
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index d4b4858..b7fa09b 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -351,15 +351,16 @@ typedef struct _notmuch_message_file notmuch_message_file_t;
 /* Open a file containing a single email message.
  *
  * The caller should call notmuch_message_close when done with this.
- *
+ * 
  * Returns NULL if any error occurs.
  */
 notmuch_message_file_t *
-_notmuch_message_file_open (const char *filename);
+_notmuch_message_file_open (notmuch_database_t *notmuch, const char *filename);
 
 /* Like notmuch_message_file_open but with 'ctx' as the talloc owner. */
 notmuch_message_file_t *
-_notmuch_message_file_open_ctx (void *ctx, const char *filename);
+_notmuch_message_file_open_ctx (notmuch_database_t *notmuch,
+				void *ctx, const char *filename);
 
 /* Close a notmuch message previously opened with notmuch_message_open. */
 void
-- 
2.1.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-12-26 17:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-26 17:42 Start to eliminate printing from libnotmuch David Bremner
2014-12-26 17:42 ` [PATCH 1/4] lib: add passthrough logger function David Bremner
2014-12-26 17:42 ` [PATCH 2/4] lib: add private function to extract the database for a message David Bremner
2014-12-26 17:42 ` [PATCH 3/4] lib: replace almost all fprintfs in library with n_d_log David Bremner
2014-12-26 17:42 ` [PATCH 4/4] lib: eliminate fprintf from _notmuch_message_file_open David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).