[Xapian-devel] Error handling in the bindings
Richard Boulton
richard at lemurconsulting.com
Thu Mar 8 17:11:17 GMT 2007
Coming back to this topic - as you may have seen, I've committed to
xapian-bindings some changes which reorganise the SWIG source files so
that we can add language specific exception handling just by adding an
"except.i" file to the source directory for the language in question - a
default except.i file is used if this isn't present. I've split the TCL
exception handling and PHP exception handling into except.i files,
because they were already significantly customised (with #ifdefs, and
similar), but haven't yet committed anything which changes behaviour (as
far as I can tell).
I've now got an uncommitted except.i file for Python which causes it to
throw Xapian errors instead of the limited SWIG errors. This seems to
work fine, but I haven't yet made it use the full Xapian exception
hierarchy (I've just wrapped Xapian::Error and a couple of the
subclasses for test purposes). So - the hard work is done.
I've just been looking at how to use generate-exceptions.in to generate
the exception hierarchy for use by SWIG. Sadly, my Perl is a bit rusty,
so I quickly converted it to Python, and split the definitions of the
exception heirarchy into a separate file. This leaves me with two
files, "generate-exceptions.in" which generates xapian/include/error.h
and xapian/include/errordispatch.h, and "exception_data.py" which just
initialises a load of python variables to represent the error hierarchy.
The point of this is that I can then write a separate
generate-binding-exceptions.in in the xapian-bindings module which
generates the exception hierarchy stuff for the bindings which need it,
and this script can include the same "exception_data.py" file to get the
definition of the hierarchy.
I have several questions:
1. Is it okay to require Python for maintainer mode builds of Xapian-core?
2. Is it okay to replace the Perl generate-exceptions.in with my Python one?
3. How best should I include exception_data.py from the xapian-bindings
module. My current thinking is to assume that the sources are laid out
as assumed by bootstrap.sh if a maintainer mode build is in progress,
and to look for exception_data.py in "$srcdir/../xapian-core/", but I'd
like a better plan. Perhaps I could add exception_data.py to the list
of installed files (going in $prefix/share/xapian/ perhaps), and add an
option to xapian-config.py which reported the directory it was installed in.
Once we've got such exception handling for Python sorted, it hopefully
won't be too hard to implement it for PHP5, Ruby and CSharp - but I
haven't looked at those at all yet.
--
Richard
More information about the Xapian-devel
mailing list