On Mon, Jun 03, 2019 at 10:12:05AM -0500, Eric Blake wrote:
On 6/3/19 4:59 AM, Richard W.M. Jones wrote:
> nbd_get_version returns the library version as a string.
>
> nbd_supports_uri returns whether or not the library was compiled with
> NBD URI support (ie. with libxml2).
>
> nbd_get_package_name is fairly useless as it always returns the string
> "libnbd", however it replaces a function that was written for the
> Python bindings.
>
> These take a handle parameter but don't need to use it. Changing the
> generator to support a whole new class of API calls which don't need a
> handle is a massive pain.
Should we permit and/or document that these functions may pass NULL (at
least in C bindings) for the nbd_handle? (It's harder in other
languages, where you would treat it as more of a static method rather
than an instance method - hence I agree with your comment that
refactoring the generator to support that is harder)
We'd have to be careful in case we made some change to the generator
which broke that contract. It would at the very least require a test.
It certainly wouldn't work right now in the two non-C languages we've
implemented so far (Python would hopefully fail the runtime type
check, OCaml wouldn't let you compile the code in the first place).
Looks good to me.
I agree that supports_uri should be a runtime question. Having the
version as a runtime answer is sane enough (even if being a string
requires a bit of parsing to interpret the version). There's still the
question if additionally exposing the version as a compile-time constant
can also make it easier to conditionally use other API (such as
nbd_supports_uri) based on version-number checks for whether it is known
to be present (not as nice as a configure-check for the actual function,
in case it was backported across version numbers, but having
compile-time constants allows skipping the development of the
configure-time check).
In libguestfs we automatically generate defines like
#define GUESTFS_HAVE_<function_name> 1
for all functions which are present in the API. Easy enough to do
with a generator.
I'd also like to get symbol versioning working at some point.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top