[libvirt] [PATCH] Macro for testing the version you are compiling with

Added a macro similar to the Linux kernel's KERNEL_VERSION so that you can simply do something like: #if LIBVIR_VERSION(1,1,3) <= LIBVIR_VERSION_NUMBER /* Call function here that appeared in 1.1.3 and newer */ virSomeNewFunction(); #endif --- include/libvirt/libvirt.h.in | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 80b2d78..41a8c69 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1466,6 +1466,16 @@ VIR_EXPORT_VAR virConnectAuthPtr virConnectAuthPtrDefault; #define LIBVIR_VERSION_NUMBER @LIBVIRT_VERSION_NUMBER@ +/** + * LIBVIR_VERSION: + * + * Macro for developers to easily check what version of the library + * their code is compiling against. Similar in behavior to KERNEL_VERSION + * e.g. + * #if LIBVIR_VERSION(1,1,3) < LIBVIR_VERSION_NUMBER + */ +#define LIBVIR_VERSION(a,b,c) (((a) * 1000000) + ((b) * 1000) + (c)) + int virGetVersion (unsigned long *libVer, const char *type, unsigned long *typeVer); -- 1.8.1.5

On Wed, Nov 13, 2013 at 10:59:14AM -0600, Doug Goldstein wrote:
Added a macro similar to the Linux kernel's KERNEL_VERSION so that you can simply do something like:
#if LIBVIR_VERSION(1,1,3) <= LIBVIR_VERSION_NUMBER /* Call function here that appeared in 1.1.3 and newer */ virSomeNewFunction(); #endif --- include/libvirt/libvirt.h.in | 10 ++++++++++ 1 file changed, 10 insertions(+)
I think it'd be better to have something like GLib's macro https://developer.gnome.org/glib/stable/glib-Version-Information.html#GLIB-C... eg #if LIBVIRT_CHECK_VERSION(1,1,3) ...some code... #endif Of course this won't help the python binding - we'll need to actually provide that macro in the python binding so it can work with all old historic versions of libvirt. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Nov 13, 2013 at 11:03 AM, Daniel P. Berrange <berrange@redhat.com> wrote:
On Wed, Nov 13, 2013 at 10:59:14AM -0600, Doug Goldstein wrote:
Added a macro similar to the Linux kernel's KERNEL_VERSION so that you can simply do something like:
#if LIBVIR_VERSION(1,1,3) <= LIBVIR_VERSION_NUMBER /* Call function here that appeared in 1.1.3 and newer */ virSomeNewFunction(); #endif --- include/libvirt/libvirt.h.in | 10 ++++++++++ 1 file changed, 10 insertions(+)
I think it'd be better to have something like GLib's macro
https://developer.gnome.org/glib/stable/glib-Version-Information.html#GLIB-C...
eg
#if LIBVIRT_CHECK_VERSION(1,1,3) ...some code... #endif
Of course this won't help the python binding - we'll need to actually provide that macro in the python binding so it can work with all old historic versions of libvirt.
Sounds good to me. I switched it and reposted. I'm suggesting adding it to libvirt simply so that other language bindings can take advantage of the macro as well. I'm sticking it into libvirt-python with an ifndef wrapper as well. That patch series to come later. -- Doug Goldstein
participants (2)
-
Daniel P. Berrange
-
Doug Goldstein