summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2007-08-03 19:05:29 +0000
committerHavoc Pennington <hp@redhat.com>2007-08-03 19:05:29 +0000
commitd9f2438806d0b2584003a3c3a54234c5a1fac4c2 (patch)
tree89b25817effe91b19afb89db54cf2a999ec47b6d
parentae4a1586969aaca534508837830d7d3de4ade070 (diff)
2007-08-03 Havoc Pennington <hp@redhat.com>
* configure.in: add major/minor/micro version number AC_SUBST * dbus/dbus-arch-deps.h.in (DBUS_MAJOR_VERSION, DBUS_MINOR_VERSION, DBUS_MICRO_VERSION, DBUS_VERSION_STRING, DBUS_VERSION): collection of macros to get version of library we are compiled against. * dbus/dbus-misc.c (dbus_get_version): new function, to get version of library we are linked against at runtime.
-rw-r--r--ChangeLog12
-rw-r--r--configure.in16
-rw-r--r--dbus/dbus-arch-deps.h.in11
-rw-r--r--dbus/dbus-misc.c132
-rw-r--r--dbus/dbus-misc.h6
5 files changed, 175 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index e904ce04..37ab97f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2007-08-03 Havoc Pennington <hp@redhat.com>
+
+ * configure.in: add major/minor/micro version number AC_SUBST
+
+ * dbus/dbus-arch-deps.h.in (DBUS_MAJOR_VERSION,
+ DBUS_MINOR_VERSION, DBUS_MICRO_VERSION, DBUS_VERSION_STRING,
+ DBUS_VERSION): collection of macros to get version of library we
+ are compiled against.
+
+ * dbus/dbus-misc.c (dbus_get_version): new function, to get
+ version of library we are linked against at runtime.
+
2007-07-30 Havoc Pennington <hp@redhat.com>
* bus/activation-helper.c (check_bus_name): don't use
diff --git a/configure.in b/configure.in
index 61cb9363..3dcd8bc6 100644
--- a/configure.in
+++ b/configure.in
@@ -1,7 +1,12 @@
dnl -*- mode: m4 -*-
AC_PREREQ(2.52)
-AC_INIT(dbus, 1.1.3)
+m4_define([dbus_major_version], [1])
+m4_define([dbus_minor_version], [1])
+m4_define([dbus_micro_version], [3])
+m4_define([dbus_version],
+ [dbus_major_version.dbus_minor_version.dbus_micro_version])
+AC_INIT(dbus, [dbus_version])
AC_CANONICAL_TARGET
@@ -39,6 +44,15 @@ AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)
+DBUS_MAJOR_VERSION=dbus_major_version
+DBUS_MINOR_VERSION=dbus_minor_version
+DBUS_MICRO_VERSION=dbus_micro_version
+DBUS_VERSION=dbus_major_version.dbus_minor_version.dbus_micro_version
+
+AC_SUBST(DBUS_MAJOR_VERSION)
+AC_SUBST(DBUS_MINOR_VERSION)
+AC_SUBST(DBUS_MICRO_VERSION)
+AC_SUBST(DBUS_VERSION)
AC_PROG_CC
AM_PROG_CC_C_O
diff --git a/dbus/dbus-arch-deps.h.in b/dbus/dbus-arch-deps.h.in
index 6d19990e..2a02a7f5 100644
--- a/dbus/dbus-arch-deps.h.in
+++ b/dbus/dbus-arch-deps.h.in
@@ -51,6 +51,17 @@ typedef unsigned @DBUS_INT32_TYPE@ dbus_uint32_t;
typedef @DBUS_INT16_TYPE@ dbus_int16_t;
typedef unsigned @DBUS_INT16_TYPE@ dbus_uint16_t;
+/* This is not really arch-dependent, but it's not worth
+ * creating an additional generated header just for this
+ */
+#define DBUS_MAJOR_VERSION @DBUS_MAJOR_VERSION@
+#define DBUS_MINOR_VERSION @DBUS_MINOR_VERSION@
+#define DBUS_MICRO_VERSION @DBUS_MICRO_VERSION@
+
+#define DBUS_VERSION_STRING "@DBUS_VERSION@"
+
+#define DBUS_VERSION ((@DBUS_MAJOR_VERSION@ << 16) | (@DBUS_MINOR_VERSION@ << 8) | (@DBUS_MICRO_VERSION@))
+
DBUS_END_DECLS
#endif /* DBUS_ARCH_DEPS_H */
diff --git a/dbus/dbus-misc.c b/dbus/dbus-misc.c
index 683ea3c7..22b7333e 100644
--- a/dbus/dbus-misc.c
+++ b/dbus/dbus-misc.c
@@ -91,6 +91,83 @@ dbus_get_local_machine_id (void)
}
+/**
+ * @def DBUS_MAJOR_VERSION
+ *
+ * The COMPILE TIME major version of libdbus, that is, the "X" in "X.Y.Z",
+ * as an integer literal. Consider carefully whether to use this or the
+ * runtime version from dbus_get_version().
+ */
+
+/**
+ * @def DBUS_MINOR_VERSION
+ *
+ * The COMPILE TIME minor version of libdbus, that is, the "Y" in "X.Y.Z",
+ * as an integer literal. Consider carefully whether to use this or the
+ * runtime version from dbus_get_version().
+ */
+
+/**
+ * @def DBUS_MICRO_VERSION
+ *
+ * The COMPILE TIME micro version of libdbus, that is, the "Z" in "X.Y.Z",
+ * as an integer literal. Consider carefully whether to use this or the
+ * runtime version from dbus_get_version().
+ */
+
+/**
+ * @def DBUS_VERSION
+ *
+ * The COMPILE TIME version of libdbus, as a single integer that has 0 in the most
+ * significant byte, the major version in the next most significant byte,
+ * the minor version in the third most significant, and the micro version in the
+ * least significant byte. This means two DBUS_VERSION can be compared to see
+ * which is higher.
+ *
+ * Consider carefully whether to use this or the runtime version from
+ * dbus_get_version().
+ */
+
+/**
+ * @def DBUS_VERSION_STRING
+ *
+ * The COMPILE TIME version of libdbus, as a string "X.Y.Z".
+ *
+ * Consider carefully whether to use this or the runtime version from
+ * dbus_get_version().
+ */
+
+/**
+ * Gets the DYNAMICALLY LINKED version of libdbus. Alternatively, there
+ * are macros #DBUS_MAJOR_VERSION, #DBUS_MINOR_VERSION, #DBUS_MICRO_VERSION,
+ * and #DBUS_VERSION which allow you to test the VERSION YOU ARE COMPILED AGAINST.
+ * In other words, you can get either the runtime or the compile-time version.
+ * Think carefully about which of these you want in a given case.
+ *
+ * The libdbus full version number is "MAJOR.MINOR.MICRO" where the
+ * MINOR changes if API is added, and the MICRO changes with each
+ * release of a MAJOR.MINOR series. The MINOR is an odd number for
+ * development releases and an even number for stable releases.
+ *
+ * @param major_version_p pointer to return the major version, or #NULL
+ * @param minor_version_p pointer to return the minor version, or #NULL
+ * @param micro_version_p pointer to return the micro version, or #NULL
+ *
+ */
+void
+dbus_get_version (int *major_version_p,
+ int *minor_version_p,
+ int *micro_version_p)
+{
+ if (major_version_p)
+ *major_version_p = DBUS_MAJOR_VERSION;
+ if (minor_version_p)
+ *minor_version_p = DBUS_MINOR_VERSION;
+ if (micro_version_p)
+ *micro_version_p = DBUS_MICRO_VERSION;
+}
+
+
/** @} */ /* End of public API */
#ifdef DBUS_BUILD_TESTS
@@ -104,7 +181,62 @@ dbus_get_local_machine_id (void)
dbus_bool_t
_dbus_misc_test (void)
{
+ int major, minor, micro;
+ DBusString str;
+
+ /* make sure we don't crash on NULL */
+ dbus_get_version (NULL, NULL, NULL);
+
+ /* Now verify that all the compile-time version stuff
+ * is right and matches the runtime. These tests
+ * are mostly intended to catch various kinds of
+ * typo (mixing up major and minor, that sort of thing).
+ */
+ dbus_get_version (&major, &minor, &micro);
+
+ _dbus_assert (major == DBUS_MAJOR_VERSION);
+ _dbus_assert (minor == DBUS_MINOR_VERSION);
+ _dbus_assert (micro == DBUS_MICRO_VERSION);
+
+#define MAKE_VERSION(x, y, z) (((x) << 16) | ((y) << 8) | (z))
+
+ /* check that MAKE_VERSION works and produces the intended ordering */
+ _dbus_assert (MAKE_VERSION (1, 0, 0) > MAKE_VERSION (0, 0, 0));
+ _dbus_assert (MAKE_VERSION (1, 1, 0) > MAKE_VERSION (1, 0, 0));
+ _dbus_assert (MAKE_VERSION (1, 1, 1) > MAKE_VERSION (1, 1, 0));
+
+ _dbus_assert (MAKE_VERSION (2, 0, 0) > MAKE_VERSION (1, 1, 1));
+ _dbus_assert (MAKE_VERSION (2, 1, 0) > MAKE_VERSION (1, 1, 1));
+ _dbus_assert (MAKE_VERSION (2, 1, 1) > MAKE_VERSION (1, 1, 1));
+
+ /* check DBUS_VERSION */
+ _dbus_assert (MAKE_VERSION (major, minor, micro) == DBUS_VERSION);
+
+ /* check that ordering works with DBUS_VERSION */
+ _dbus_assert (MAKE_VERSION (major - 1, minor, micro) < DBUS_VERSION);
+ _dbus_assert (MAKE_VERSION (major, minor - 1, micro) < DBUS_VERSION);
+ _dbus_assert (MAKE_VERSION (major, minor, micro - 1) < DBUS_VERSION);
+ _dbus_assert (MAKE_VERSION (major + 1, minor, micro) > DBUS_VERSION);
+ _dbus_assert (MAKE_VERSION (major, minor + 1, micro) > DBUS_VERSION);
+ _dbus_assert (MAKE_VERSION (major, minor, micro + 1) > DBUS_VERSION);
+
+ /* Check DBUS_VERSION_STRING */
+
+ if (!_dbus_string_init (&str))
+ _dbus_assert_not_reached ("no memory");
+
+ if (!(_dbus_string_append_int (&str, major) &&
+ _dbus_string_append_byte (&str, '.') &&
+ _dbus_string_append_int (&str, minor) &&
+ _dbus_string_append_byte (&str, '.') &&
+ _dbus_string_append_int (&str, micro)))
+ _dbus_assert_not_reached ("no memory");
+
+ _dbus_assert (_dbus_string_equal_c_str (&str, DBUS_VERSION_STRING));
+
+ _dbus_string_free (&str);
+
return TRUE;
}
diff --git a/dbus/dbus-misc.h b/dbus/dbus-misc.h
index 6c2d77e9..c59ce709 100644
--- a/dbus/dbus-misc.h
+++ b/dbus/dbus-misc.h
@@ -37,7 +37,11 @@ DBUS_BEGIN_DECLS
* @{
*/
-char* dbus_get_local_machine_id (void);
+char* dbus_get_local_machine_id (void);
+
+void dbus_get_version (int *major_version_p,
+ int *minor_version_p,
+ int *micro_version_p);
/** @} */