unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* heads up from the python front
@ 2012-01-22  6:01 Justus Winter
  2012-01-22 12:30 ` David Bremner
  0 siblings, 1 reply; 7+ messages in thread
From: Justus Winter @ 2012-01-22  6:01 UTC (permalink / raw)
  To: notmuch mailing list

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@informatik.uni-hamburg.de
1: https://github.com/teythoon/afew
2: id:1318198374-926-1-git-send-email-4winter@informatik.uni-hamburg.de
3: 8015cbff263606f009b5750d23b28ee332c25db8

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

end of thread, other threads:[~2012-01-29 16:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-22  6:01 heads up from the python front Justus Winter
2012-01-22 12:30 ` David Bremner
2012-01-22 13:09   ` [PATCH] python: fix error handling Justus Winter
2012-01-23 10:24     ` Tomi Ollila
2012-01-23 11:47     ` David Bremner
2012-01-23 12:15       ` [PATCH] Add a NEWS section for 0.11.1 and document the python error handling bugfix Justus Winter
2012-01-29 16:53   ` bugfix release (was: heads up from the python front) Justus Winter

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).