On Fri, May 19, 2006 at 01:53:11AM -0500, Anthony Liguori wrote:
> Ewan Mellor wrote:
> >>Did I miss something? If not, could the xen.lowlevel.xc.error class be
> >>publically exposed?
> >They are exceptions of the built-in type RuntimeError -- that's what you
> >when you use PyErr_SetFromErrno in the C layer. I don't know why it shows
> >as xc.error -- presumably that's a Python internal thing.
> Actually, these exceptions are rather weird. This is pretty much
> pushing my Python understanding to the limit but I looked into this a
> while back and came to this conclusion.
> These are not RuntimeError exceptions but rather of the type xc.error.
> This type is created in initxc() with PyErr_NewException().
> The weird thing is, this type is not exposed through the modules export
> list so you cannot ever directly reference the type. However, type() of
> the exception will return xc.error.
> The PyErr_SetFromErrno is just a helper that instantiates an exception
> of a given type and sets the value of the exception to a tuple
> containing the errno and message.
Yes, you're right, my mistake. The ones in xs.c do
PyErr_SetFromErrno(PyExc_RuntimeError), that's where I got that from.
> As a hack, I changed xc_error to be initialized to PyExc_OSError which
> allowed errors to be caught appropriately. I don't know if this is the
> Right Thing to do from a Python perspective (if libxc were in Python,
> the failures would get propagated as OSErrors so it sort of makes sense).
> In the very least, we probably have to somehow expose the exception type
> within the module. It's quite unfortunately that everywhere in Xend
> just catches any exception.
> Any Python gurus out there that can shed some light on the proper thing
> we should be doing? It's an easy patch once we know what the right
> thing to do is.
If we're going to make a change at all, we ought to do it properly. We should
have an exception for each of the xc and the xs modules, exposed through the
module interface correctly. I don't have a problem with the exception being
derived directly from Exception, though if we're going to change xs.c as well
as xc.c, then we ought to inherit from RuntimeError, for compatibility with
the Python layer.
Can one of you two submit a patch?
Xen-devel mailing list