diff options
| author | Roy Frostig <rfrostig@mozilla.com> | 2010-07-25 21:45:09 -0700 |
|---|---|---|
| committer | Roy Frostig <rfrostig@mozilla.com> | 2010-07-25 21:45:09 -0700 |
| commit | 5b6e714d05a0c96ade618256a67a9cb7f337f196 (patch) | |
| tree | 45406973ea3c0ffb1a9e070588f4ca5fc8c7744c /src/rt/rust_builtin.cpp | |
| parent | 7ef9e82f51de73e89759910fd1b45ce5ccc363b3 (diff) | |
| download | rust-5b6e714d05a0c96ade618256a67a9cb7f337f196.tar.gz rust-5b6e714d05a0c96ade618256a67a9cb7f337f196.zip | |
Expose an RNG (the one used by our runtime) to Rust via std.
Diffstat (limited to 'src/rt/rust_builtin.cpp')
| -rw-r--r-- | src/rt/rust_builtin.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp index 99fa953580c..e8d2d67d3c7 100644 --- a/src/rt/rust_builtin.cpp +++ b/src/rt/rust_builtin.cpp @@ -127,6 +127,31 @@ vec_len(rust_task *task, type_desc *ty, rust_vec *v) return v->fill / ty->size; } +extern "C" CDECL void * +rand_new(rust_task *task) +{ + rust_dom *dom = task->dom; + randctx *rctx = (randctx *) task->malloc(sizeof(randctx)); + if (!rctx) { + task->fail(1); + return NULL; + } + isaac_init(dom, rctx); + return rctx; +} + +extern "C" CDECL size_t +rand_next(rust_task *task, randctx *rctx) +{ + return rand(rctx); +} + +extern "C" CDECL void +rand_free(rust_task *task, randctx *rctx) +{ + task->free(rctx); +} + // // Local Variables: // mode: C++ |
