1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-22 17:34:18 +03:00

random: link with -lm when needed

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 virRandomBits(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.
This commit is contained in:
Eric Blake 2012-08-14 11:36:38 -06:00
parent 6a3691b743
commit c606671aaa
4 changed files with 7 additions and 2 deletions

@ -1 +1 @@
Subproject commit dbd914496c99c52220e5f5ba4121d6cb55fb3beb
Subproject commit 271dd74fdf54ec2a03e73a5173b0b5697f6088f1

View File

@ -61,6 +61,7 @@ intprops
ioctl
isatty
largefile
ldexp
listen
localeconv
maintainer-makefile

View File

@ -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)

View File

@ -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) - 1);
double val = virRandom();
return val * max;
}