From f449bd157d3ae0a097a5d557796505f1e9e79736 Mon Sep 17 00:00:00 2001 From: Vitaliy Mysak Date: Wed, 13 May 2020 11:01:56 +0200 Subject: [PATCH] fix compilation under std=c89 There were few things that prevented successful compilation using c89 standard. (and other c* standards in case of gcc). Fix them in this small patch. Changes in 27/rand.c: - Use __GNU_SOURCE__ instead of __GNU_LIBRARY__ or else any of -std=c* options don't work with gcc - Add a check before using rand_r() as suggested in rand_r(3) - Move _WIN_32 definitions to "else" branch because it uses the most portable version --- AUTHORS | 1 + bignum.c | 8 ++++---- lib/srfi/27/rand.c | 25 +++++++++++++------------ sexp.c | 2 +- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/AUTHORS b/AUTHORS index 51342cab..3ba2cb6f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -58,6 +58,7 @@ Thanks to the following people for patches and bug reports: * Stephen Lewis * Taylor Venable * Travis Cross + * Vitaliy Mysak * Yuki Okumura If you would prefer not to be listed, or are one of the users listed diff --git a/bignum.c b/bignum.c index f61a7b6a..9eac5b26 100644 --- a/bignum.c +++ b/bignum.c @@ -772,10 +772,10 @@ sexp sexp_double_to_ratio (sexp ctx, double f) { return res; } -// -// For conversion that does not introduce round-off error, -// no matter what FLT_RADIX is. -// +/* + * For conversion that does not introduce round-off error, + * no matter what FLT_RADIX is. + */ sexp sexp_double_to_ratio_2 (sexp ctx, double f) { int sign,i; sexp_gc_var3(res, whole, scale); diff --git a/lib/srfi/27/rand.c b/lib/srfi/27/rand.c index 812f7a67..8946f176 100644 --- a/lib/srfi/27/rand.c +++ b/lib/srfi/27/rand.c @@ -18,7 +18,7 @@ #define sexp_sizeof_random (sexp_sizeof_header + sizeof(sexp_random_t) + sizeof(sexp)) -#ifdef __GNU_LIBRARY__ +#ifdef __GNU_SOURCE__ typedef struct random_data sexp_random_t; @@ -31,17 +31,7 @@ typedef struct random_data sexp_random_t; #define sexp_call_random(rs, dst) random_r(sexp_random_data(rs), &dst) #define sexp_seed_random(n, rs) srandom_r(n, sexp_random_data(rs)) -#elif defined(_WIN32) - -typedef unsigned int sexp_random_t; - -/* FIXME: MSVC CRT has rand_s() for "cryptographically secure" random number - * for WinXP or later. */ -#define sexp_random_init(rs, seed) (void)0 -#define sexp_call_random(rs, dst) ((dst) = rand()) -#define sexp_seed_random(n, rs) srand(n) - -#else +#elif _POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE typedef unsigned int sexp_random_t; @@ -50,6 +40,17 @@ typedef unsigned int sexp_random_t; #define sexp_call_random(rs, dst) ((dst) = rand_r(sexp_random_data(rs))) #define sexp_seed_random(n, rs) *sexp_random_data(rs) = (n) +#else + +typedef unsigned int sexp_random_t; + +#define sexp_random_init(rs, seed) (void)0 + +/* FIXME: MSVC CRT has rand_s() for "cryptographically secure" random number + * for WinXP or later. */ +#define sexp_call_random(rs, dst) ((dst) = rand()) +#define sexp_seed_random(n, rs) srand(n) + #endif sexp sexp_rs_random_integer (sexp ctx, sexp self, sexp_sint_t n, sexp rs, sexp bound) { diff --git a/sexp.c b/sexp.c index a199b0c5..de3f95b2 100644 --- a/sexp.c +++ b/sexp.c @@ -583,7 +583,7 @@ void sexp_init_context_globals (sexp ctx) { for (i=0; ivalue), &(_sexp_type_specs[i]), sizeof(_sexp_type_specs[0])); vec[i] = type;