Skip to content

Commit 78fe75a

Browse files
committed
rt: Fix iaac_init using wrong type and not seeding correctly
This was a result of changing the vector representation to contain a box header.
1 parent e04e948 commit 78fe75a

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/libcore/rand.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,17 @@ mod tests {
303303
assert ra.gen_str(100u) == rb.gen_str(100u);
304304
}
305305

306+
#[test]
307+
fn rng_seeded_custom_seed2() {
308+
let seed = [2u8, 32u8, 4u8, 32u8, 51u8];
309+
let ra = rand::seeded_rng(seed);
310+
// Regression test that isaac is actually using the above vector
311+
let r = ra.next();
312+
#error("%?", r);
313+
assert r == 890007737u32 // on x86_64
314+
|| r == 2935188040u32; // on x86
315+
}
316+
306317
#[test]
307318
fn gen_int_range() {
308319
let r = rand::rng();

src/rt/rust_builtin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ rand_new() {
204204
}
205205

206206
extern "C" CDECL void *
207-
rand_new_seeded(rust_vec* seed) {
207+
rand_new_seeded(rust_vec_box* seed) {
208208
rust_task *task = rust_get_current_task();
209209
rust_sched_loop *thread = task->sched_loop;
210210
randctx *rctx = (randctx *) task->malloc(sizeof(randctx),

src/rt/rust_util.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@ inline void isaac_seed(rust_kernel* kernel, uint8_t* dest)
128128
}
129129

130130
inline void
131-
isaac_init(rust_kernel *kernel, randctx *rctx, rust_vec* user_seed)
131+
isaac_init(rust_kernel *kernel, randctx *rctx, rust_vec_box* user_seed)
132132
{
133133
memset(rctx, 0, sizeof(randctx));
134134

135135
char *env_seed = kernel->env->rust_seed;
136136
if (user_seed != NULL) {
137137
// ignore bytes after the required length
138-
size_t seed_len = user_seed->fill < sizeof(rctx->randrsl)
139-
? user_seed->fill : sizeof(rctx->randrsl);
140-
memcpy(&rctx->randrsl, user_seed->data, seed_len);
138+
size_t seed_len = user_seed->body.fill < sizeof(rctx->randrsl)
139+
? user_seed->body.fill : sizeof(rctx->randrsl);
140+
memcpy(&rctx->randrsl, user_seed->body.data, seed_len);
141141
} else if (env_seed != NULL) {
142142
ub4 seed = (ub4) atoi(env_seed);
143143
for (size_t i = 0; i < RANDSIZ; i ++) {

0 commit comments

Comments
 (0)