Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 6DD38431FC0 for ; Wed, 25 Mar 2015 09:48:09 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 2.438 X-Spam-Level: ** X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oYmNPJBJ0VIb for ; Wed, 25 Mar 2015 09:48:06 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by olra.theworths.org (Postfix) with ESMTP id E8A15431FBC for ; Wed, 25 Mar 2015 09:48:05 -0700 (PDT) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 6AD48100086; Wed, 25 Mar 2015 18:47:44 +0200 (EET) From: Tomi Ollila To: David Bremner , David Bremner , notmuch@notmuchmail.org Subject: Re: [Patch v5 5/8] lib: add a log function with output to a string in notmuch_database_t In-Reply-To: <1427203451-1540-6-git-send-email-david@tethera.net> References: <1426352554-4383-10-git-send-email-david@tethera.net> <1427203451-1540-1-git-send-email-david@tethera.net> <1427203451-1540-6-git-send-email-david@tethera.net> User-Agent: Notmuch/0.19+92~g402df12 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Mar 2015 16:48:09 -0000 On Tue, Mar 24 2015, David Bremner wrote: > In principle in the future this could do something fancier than sprintf. It would be better talking of sNprintf -- it is more accurate and potentially more educational. Rest of the patches in this series OK > --- > lib/database-private.h | 4 ++++ > lib/database.cc | 24 ++++++++++++++++++++++++ > lib/notmuch-private.h | 4 ++++ > lib/notmuch.h | 7 +++++++ > 4 files changed, 39 insertions(+) > > diff --git a/lib/database-private.h b/lib/database-private.h > index 6d6fa2c..24243db 100644 > --- a/lib/database-private.h > +++ b/lib/database-private.h > @@ -154,6 +154,10 @@ struct _notmuch_database { > unsigned int last_doc_id; > uint64_t last_thread_id; > > + /* error reporting; this value persists only until the > + * next library call. May be NULL */ > + char *status_string; > + > Xapian::QueryParser *query_parser; > Xapian::TermGenerator *term_gen; > Xapian::ValueRangeProcessor *value_range_processor; > diff --git a/lib/database.cc b/lib/database.cc > index 36849d7..673561b 100644 > --- a/lib/database.cc > +++ b/lib/database.cc > @@ -348,6 +348,23 @@ notmuch_status_to_string (notmuch_status_t status) > } > } > > +void > +_notmuch_database_log (notmuch_database_t *notmuch, > + const char *format, > + ...) > +{ > + va_list va_args; > + > + va_start (va_args, format); > + > + if (notmuch->status_string) > + talloc_free (notmuch->status_string); > + > + notmuch->status_string = talloc_vasprintf (notmuch, format, va_args); > + > + va_end (va_args); > +} > + > static void > find_doc_ids_for_term (notmuch_database_t *notmuch, > const char *term, > @@ -845,6 +862,7 @@ notmuch_database_open_verbose (const char *path, > > notmuch = talloc_zero (NULL, notmuch_database_t); > notmuch->exception_reported = FALSE; > + notmuch->status_string = NULL; > notmuch->path = talloc_strdup (notmuch, path); > > if (notmuch->path[strlen (notmuch->path) - 1] == '/') > @@ -2530,3 +2548,9 @@ notmuch_database_get_all_tags (notmuch_database_t *db) > return NULL; > } > } > + > +const char * > +notmuch_database_status_string (notmuch_database_t *notmuch) > +{ > + return notmuch->status_string; > +} > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h > index 8a1f2fa..7cb6fd4 100644 > --- a/lib/notmuch-private.h > +++ b/lib/notmuch-private.h > @@ -190,6 +190,10 @@ _notmuch_message_id_compressed (void *ctx, const char *message_id); > notmuch_status_t > _notmuch_database_ensure_writable (notmuch_database_t *notmuch); > > +void > +_notmuch_database_log (notmuch_database_t *notmuch, > + const char *format, ...); > + > const char * > _notmuch_database_relative_path (notmuch_database_t *notmuch, > const char *path); > diff --git a/lib/notmuch.h b/lib/notmuch.h > index c671d82..20c4e01 100644 > --- a/lib/notmuch.h > +++ b/lib/notmuch.h > @@ -302,6 +302,13 @@ notmuch_database_open_verbose (const char *path, > char **error_message); > > /** > + * Retrieve last status string for given database. > + * > + */ > +const char * > +notmuch_database_status_string (notmuch_database_t *notmuch); > + > +/** > * Commit changes and close the given notmuch database. > * > * After notmuch_database_close has been called, calls to other > -- > 2.1.4 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch