From 9473b71a7964f08e1de9d55034371ee4a07fba45 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Wed, 24 Jul 2019 10:07:08 +0100 Subject: [PATCH] When compiling on OSX, do not inline the RNG glibc functions but use their official POSIX versions. --- src/random.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/random.h b/src/random.h index fb33bb2ef5..832c95a884 100644 --- a/src/random.h +++ b/src/random.h @@ -20,13 +20,10 @@ #ifndef SWIFT_RANDOM_H #define SWIFT_RANDOM_H -/* COde configuration */ +/* Code configuration */ #include "../config.h" /* Standard header */ -#include <errno.h> -#include <ieee754.h> -#include <limits.h> #include <stdint.h> #include <stdlib.h> #include <string.h> @@ -55,6 +52,12 @@ enum random_number_type { random_number_BH_swallow = 4947009007LL }; +#ifndef __APPLE__ + +#include <errno.h> +#include <ieee754.h> +#include <limits.h> + /* Inline the default RNG functions to avoid costly function calls. These functions are minor modifications, but functional equivalents, of their glibc counterparts. */ @@ -110,6 +113,17 @@ INLINE static double inl_erand48(uint16_t xsubi[3]) { return temp.d - 1.0; } +#else + +/* In the case of OSX, we default to the platform's + default implementation. */ + +INLINE static int inl_rand_r(uint32_t *seed) { return rand_r(seed); } + +INLINE static double inl_erand48(uint16_t xsubi[3]) { return erand48(xsubi); } + +#endif + /** * @brief Returns a pseudo-random number in the range [0, 1[. * -- GitLab