Use of ldexp() requires -lm on some platforms; use gnulib to determine
this for our makefile.  Also, optimize virRandomInt() for the case
of a power-of-two limit (actually rather common, given that Daniel
has a pending patch to replace virRandomBis(10) with code that will
default to virRandomInt(1024) on default SELinux settings).

* .gnulib: Update to latest, for ldexp.
* bootstrap.conf (gnulib_modules): Import ldexp.
* src/Makefile.am (libvirt_util_la_CFLAGS): Link with -lm when
needed.
* src/util/virrandom.c (virRandomInt): Optimize powers of 2.
---

Gnulib changes:
* .gnulib dbd9144...271dd74 (37):
  > ldexp: relax license
  > update from texinfo
  > gnulib-tool: Fix persistence of --witness-c-macro option.
  > count-leading-zeros: use a lookup table on non-gcc compilers
  > count-leading-zeros: new module
  > maintainer-makefile: Fix syntax error with dash.
  > extern-inline: also ignore -Wmissing-declarations
  > autoupdate
  > maint.mk: sc_prohibit_magic_number_exit: avoid new false positives
  > gnumakefile: better interaction with Automake-NG
  > base64: Use extern C scope in header file, for C++.
  > stat-time, timespec, u64: support naive out-of-dir builds
  > Fix typo: 'linline' -> 'inline' (thanks to Eric Blake).
  > Keep the extern-inline macros closer together.
  > Fix indenting.
  > utimens: use extern-inline
  > u64: use extern-inline
  > timespec: use extern-inline
  > stat-time: use extern-inline
  > extern-inline: new module
  > maint.mk: a "release-commit" wrapper to do-release-commit-and-tag
  > autoupdate
  > autoupdate
  > maint.mk: use silent-rules support from Automake
  > maint.mk: provide a web-manual-update target
  > README-release: shorten the circuit to post a news
  > gnu-web-doc-update: fix --help
  > passfd: fix comment on recvfd
  > maint.mk: avoid a sub-shell
  > maint.mk: absolute VPATH issue
  > update from texinfo
  > gitlog-to-changelog: fix previous change
  > gitlog-to-changelog: don't expect .git to be in $srcdir
  > maint.mk: absolute VPATH build fix
  > clean-temp: Fix memory leak.
  > maint: fix grammar in a ChangeLog entry
  > maint.mk: new rule: refresh-gnulib-patches

 .gnulib              | 2 +-
 bootstrap.conf       | 1 +
 src/Makefile.am      | 2 +-
 src/util/virrandom.c | 4 ++++
 4 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/.gnulib b/.gnulib
index dbd9144..271dd74 160000
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit dbd914496c99c52220e5f5ba4121d6cb55fb3beb
+Subproject commit 271dd74fdf54ec2a03e73a5173b0b5697f6088f1
diff --git a/bootstrap.conf b/bootstrap.conf
index a4e1c2f..a6cfe24 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -61,6 +61,7 @@ intprops
 ioctl
 isatty
 largefile
+ldexp
 listen
 localeconv
 maintainer-makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index e94f977..cec4789 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -654,7 +654,7 @@ libvirt_util_la_SOURCES =                                   
\
                $(UTIL_SOURCES)
 libvirt_util_la_CFLAGS = $(CAPNG_CFLAGS) $(YAJL_CFLAGS) $(LIBNL_CFLAGS) \
                $(AM_CFLAGS) $(AUDIT_CFLAGS) $(DEVMAPPER_CFLAGS) \
-               $(DBUS_CFLAGS)
+               $(DBUS_CFLAGS) $(LDEXP_LIBM)
 libvirt_util_la_LIBADD = $(CAPNG_LIBS) $(YAJL_LIBS) $(LIBNL_LIBS) \
                $(THREAD_LIBS) $(AUDIT_LIBS) $(DEVMAPPER_LIBS) \
                $(RT_LIBS) $(DBUS_LIBS) $(MSCOM_LIBS) $(LIBXML_LIBS)
diff --git a/src/util/virrandom.c b/src/util/virrandom.c
index 363fcab..8870865 100644
--- a/src/util/virrandom.c
+++ b/src/util/virrandom.c
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <inttypes.h>
 #include <math.h>
+#include <strings.h>

 #include "virrandom.h"
 #include "threads.h"
@@ -135,6 +136,9 @@ double virRandom(void)
  */
 uint32_t virRandomInt(uint32_t max)
 {
+    if ((max & (max - 1)) == 0)
+        return virRandomBits(ffs(max));
+
     double val = virRandom();
     return val * max;
 }
-- 
1.7.11.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to