On 6/28/19 2:17 PM, Richard W.M. Jones wrote:
Looks good to me now! Thanks for figuring this out while I was struggling with reading lots of documentation on C bindings.
ACK
I pushed it, but there may be a few issues still:
- Still no error checking in raise_exception(). We're on an error path already here so it's hard to do anything useful, although perhaps we should not segfault.
Yeah, avoiding the segfault is still worthwhile - but our lack of PyFOO_BAR() error checking is more pervasive than just in raise_exception(), so a patch to audit all of our generated code will pick that up along with the rest.
- The .errno attribute returns a (Python module) errno value, not a number, so the number is effectively lost, should that really be an issue.
Maybe we want two fields, both .errno (string name, or None if Python errno.errorcode couldn't map it to a name), and .errnum (raw numeric value, accessible no matter what). Maybe as simple as this (or with one further tweak to __str__ to at least output .errnum when .errno is None): diff --git i/generator/generator w/generator/generator index 7c2fb59..9192988 100755 --- i/generator/generator +++ w/generator/generator @@ -3944,11 +3944,14 @@ from libnbdmod import Error Error.__doc__ = ''' Exception thrown when the underlying libnbd call fails. -This exception has two properties to query the error. Use +This exception has three properties to query the error. Use the .string property to return a printable string containing -the error message. Use the .errno property to return a -Python errno (which may be None in some cases if the error -did not correspond to a system call failure). +the error message. Use the .errnum property for the associated +numeric error value (which may be 0 if the error did not +correspond to a system call failure), or the .errno property to +return a string containing the Python errno name if one is known +(which may be None if the numeric value does not correspond to +a known errno name). ''' Error.string = property (lambda self: self.args[0]) @@ -3961,6 +3964,8 @@ def _errno (self): return None Error.errno = property (_errno) +Error.errnum = property (lambda self: self.args[1]) + def _str (self): if self.errno: return (\"%%s (%%s)\" %% (self.string, self.errno)) -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org