heads up from the python front
Justus Winter
4winter at informatik.uni-hamburg.de
Sat Jan 21 22:01:41 PST 2012
Hey everyone :)
after getting to know nmbug a little better (it's actually very nice
to track bugs and patches this way...) I did some work on the python
bindings. tl;dr version: housekeeping, python3.2 support, fixed nasty
bug.
I familiarized myself with nmbug and went through all the threads
tagged with notmuch::python, added and updated few tags here and there
and started working on the open issues.
Python 3.2 support
------------------
I merged the last patch of a patchset[0] I wrote in december that makes
it possible to use the python bindings with both python2.x and
python3.2.
I do not now how complete the port is, most notably the notmuch.py
script does not work with 3.x. But it is complete enough to make
afew[1] work using python3.2 and the vanilla notmuch bindings.
If you want to help out and have a small script that uses the bindings
I'd like to invite you to try to port your script and report any
issues.
Fix random crashes when using the bindings
------------------------------------------
I found a nasty bug I introduced with a patchset[2] that was supposed
to make the bindings more robust. Annotating pointers returned from
libnotmuch functions called using ctypes allows the ctypes framework
to do typechecking. But I accidentally broke the error handling
code. Citing the commit message:
Before 3434d1940 the return values of libnotmuch functions were
declared as c_void_p and the code checking for errors compared the
returned value to None, which is the ctypes equivalent of a NULL
pointer.
But said commit wrapped all the data types in python classes and the
semantic changed in a subtle way. If a function returns NULL, the
wrapped python value is falsish, but no longer equal to None.
In fact the minimal test case triggering the bug is:
import os
import notmuch
db_path = os.path.expanduser('~/Maildir')
db_0 = notmuch.Database(db_path, mode=notmuch.Database.MODE.READ_WRITE)
db_1 = notmuch.Database(db_path, mode=notmuch.Database.MODE.READ_WRITE)
The problem was most apparent when opening the database fails because
it has been locked by someone else. The patch regarding the function
Database.open looks like this:
res = Database._open(_str(path), mode)
- if res is None:
+ if not res:
raise NotmuchError(message="Could not open the specified database")
self._db = res
The old code fails to notify the callee of the error who causes a
segfault later if he uses that database reference which is in fact
NULL.
I feel kind of bad since I severely broke the error handling for all
pythonic notmuch users out there, is there any chance of a bugfix
release? The patch[3] is really simple and I'd say it's trivial to
backport it to the last release. What do you think?
Justus
0: id:1323860305-15802-1-git-send-email-4winter at informatik.uni-hamburg.de
1: https://github.com/teythoon/afew
2: id:1318198374-926-1-git-send-email-4winter at informatik.uni-hamburg.de
3: 8015cbff263606f009b5750d23b28ee332c25db8
More information about the notmuch
mailing list