notmuch as a shared object aka library knigge
Justus Winter
4winter at informatik.uni-hamburg.de
Mon Feb 20 16:29:21 PST 2012
Hi fellow notmuchrs,
while going through the python bindings I recently came across the
following note in the documentation for the Database.get_directory
function [0]:
~~~ snip ~~~
Warning
This call needs a writable database in Database.MODE.READ_WRITE
mode. The underlying library will exit the program if this method is
used on a read-only database!
~~~ snap ~~~
and indeed, the following program exits with an error:
~~~ snip ~~~
import os
import notmuch
db_path = os.path.expanduser('~/Maildir')
with notmuch.Database(db_path, mode=notmuch.Database.MODE.READ_ONLY) as db:
db.get_directory('')
~~~ snap ~~~
% python temp/get_directory.py
Internal error: Failure to ensure database is writable (lib/directory.cc:100).
The line mentioned in the error message reads:
if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
INTERNAL_ERROR ("Failure to ensure database is writable");
with
/* There's no point in continuing when we've detected that we've done
* something wrong internally (as opposed to the user passing in a
* bogus value).
*
* Note that __location__ comes from talloc.h.
*/
#define INTERNAL_ERROR(format, ...) \
_internal_error (format " (%s).\n", \
##__VA_ARGS__, __location__)
and _internal_error calling exit(3).
If creating a shared library is the preferred way to increase the
startup time of the notmuch binary that's totally cool, but if
libnotmuch is to be used as a library for arbitrary programs it is not
acceptable to call exit(3).
(And as mentioned before, neither is writing to any file descriptor
unless it has been specifically requested by the caller.)
Cheers,
Justus
0: http://notmuch.readthedocs.org/en/latest/index.html#notmuch.Database.get_directory
More information about the notmuch
mailing list