mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-20 14:19:18 +02:00
initstate_r is a glibc extension
This commit is contained in:
parent
6dfc5e9cfd
commit
a54c49d48a
1 changed files with 25 additions and 17 deletions
|
@ -1,5 +1,5 @@
|
||||||
/* rand.c -- rand_r/random_r interface */
|
/* rand.c -- rand_r/random_r interface */
|
||||||
/* Copyright (c) 2009-2011 Alex Shinn. All rights reserved. */
|
/* Copyright (c) 2009-2014 Alex Shinn. All rights reserved. */
|
||||||
/* BSD-style license: http://synthcode.com/license.txt */
|
/* BSD-style license: http://synthcode.com/license.txt */
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
@ -13,22 +13,6 @@
|
||||||
|
|
||||||
#define sexp_random_source_p(x) sexp_check_tag(x, rs_type_id)
|
#define sexp_random_source_p(x) sexp_check_tag(x, rs_type_id)
|
||||||
|
|
||||||
#define sexp_random_init(x, seed) \
|
|
||||||
initstate_r(seed, \
|
|
||||||
sexp_bytes_data(sexp_random_state(x)), \
|
|
||||||
SEXP_RANDOM_STATE_SIZE, \
|
|
||||||
sexp_random_data(x))
|
|
||||||
|
|
||||||
#ifdef __GNU_LIBRARY__
|
|
||||||
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))
|
|
||||||
#else
|
|
||||||
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)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define sexp_random_state(x) (sexp_slot_ref((x), 0))
|
#define sexp_random_state(x) (sexp_slot_ref((x), 0))
|
||||||
#define sexp_random_data(x) ((sexp_random_t*)(&sexp_slot_ref((x), 1)))
|
#define sexp_random_data(x) ((sexp_random_t*)(&sexp_slot_ref((x), 1)))
|
||||||
|
|
||||||
|
@ -37,6 +21,30 @@ typedef unsigned int sexp_random_t;
|
||||||
static sexp_uint_t rs_type_id = 0;
|
static sexp_uint_t rs_type_id = 0;
|
||||||
static sexp default_random_source;
|
static sexp default_random_source;
|
||||||
|
|
||||||
|
#ifdef __GNU_LIBRARY__
|
||||||
|
|
||||||
|
typedef struct random_data sexp_random_t;
|
||||||
|
|
||||||
|
#define sexp_random_init(rs, seed) \
|
||||||
|
initstate_r(seed, \
|
||||||
|
sexp_bytes_data(sexp_random_state(rs)), \
|
||||||
|
SEXP_RANDOM_STATE_SIZE, \
|
||||||
|
sexp_random_data(rs))
|
||||||
|
|
||||||
|
#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))
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
typedef unsigned int sexp_random_t;
|
||||||
|
|
||||||
|
#define sexp_random_init(rs, seed) *sexp_random_data(rs) = (seed)
|
||||||
|
|
||||||
|
#define sexp_call_random(rs, dst) ((dst) = rand_r(sexp_random_data(rs)))
|
||||||
|
#define sexp_seed_random(n, rs) *sexp_random_data(rs) = (n)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static sexp sexp_rs_random_integer (sexp ctx, sexp self, sexp_sint_t n, sexp rs, sexp bound) {
|
static sexp sexp_rs_random_integer (sexp ctx, sexp self, sexp_sint_t n, sexp rs, sexp bound) {
|
||||||
sexp res;
|
sexp res;
|
||||||
int32_t m;
|
int32_t m;
|
||||||
|
|
Loading…
Add table
Reference in a new issue