Skip to content

Commit 809a799

Browse files
committed
use the new uninit intrinsic
1 parent f1d5690 commit 809a799

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

gmp.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ use core::num::IntConvertible::from_int;
1717
use core::ptr::to_mut_unsafe_ptr;
1818
use core::str::as_c_str;
1919
use core::vec;
20-
21-
#[abi = "rust-intrinsic"]
22-
extern mod rusti {
23-
fn init<T>() -> T;
24-
}
20+
use core::unstable::intrinsics::uninit;
2521

2622
struct mpz_struct {
2723
_mp_alloc: c_int,
@@ -159,15 +155,15 @@ impl Drop for Mpz {
159155
impl Mpz {
160156
fn new() -> Mpz {
161157
unsafe {
162-
let mut mpz = rusti::init(); // TODO: switch to rusti::uninit when implemented
158+
let mut mpz = uninit();
163159
__gmpz_init(&mut mpz);
164160
Mpz { mpz: mpz }
165161
}
166162
}
167163

168164
fn new_reserve(n: c_ulong) -> Mpz {
169165
unsafe {
170-
let mut mpz = rusti::init(); // TODO: switch to rusti::uninit when implemented
166+
let mut mpz = uninit();
171167
__gmpz_init2(&mut mpz, n);
172168
Mpz { mpz: mpz }
173169
}
@@ -182,7 +178,7 @@ impl Mpz {
182178
fn from_str_radix(s: &str, base: uint) -> Option<Mpz> {
183179
unsafe {
184180
assert!(base == 0 || (base >= 2 && base <= 62));
185-
let mut mpz = rusti::init(); // TODO: switch to rusti::uninit when implemented
181+
let mut mpz = uninit();
186182
let mpz_ptr = to_mut_unsafe_ptr(&mut mpz);
187183
let r = as_c_str(s, { |s| __gmpz_init_set_str(mpz_ptr, s, base as c_int) });
188184
if r == 0 {
@@ -294,7 +290,7 @@ impl Mpz {
294290
impl Clone for Mpz {
295291
fn clone(&self) -> Mpz {
296292
unsafe {
297-
let mut mpz = rusti::init(); // TODO: switch to rusti::uninit when implemented
293+
let mut mpz = uninit();
298294
__gmpz_init_set(&mut mpz, &self.mpz);
299295
Mpz { mpz: mpz }
300296
}
@@ -415,7 +411,7 @@ impl IntConvertible for Mpz {
415411
impl One for Mpz {
416412
fn one() -> Mpz {
417413
unsafe {
418-
let mut mpz = rusti::init(); // TODO: switch to rusti::uninit when implemented
414+
let mut mpz = uninit();
419415
__gmpz_init_set_ui(&mut mpz, 1);
420416
Mpz { mpz: mpz }
421417
}
@@ -502,35 +498,31 @@ impl Drop for RandState {
502498
impl RandState {
503499
fn new() -> RandState {
504500
unsafe {
505-
// TODO: switch to rusti::uninit when implemented
506-
let mut state: gmp_randstate_struct = rusti::init();
501+
let mut state: gmp_randstate_struct = uninit();
507502
__gmp_randinit_default(&mut state);
508503
RandState { state: state }
509504
}
510505
}
511506
512507
fn new_mt() -> RandState {
513508
unsafe {
514-
// TODO: switch to rusti::uninit when implemented
515-
let mut state: gmp_randstate_struct = rusti::init();
509+
let mut state: gmp_randstate_struct = uninit();
516510
__gmp_randinit_mt(&mut state);
517511
RandState { state: state }
518512
}
519513
}
520514
521515
fn new_lc_2exp(a: Mpz, c: c_ulong, m2exp: c_ulong) -> RandState {
522516
unsafe {
523-
// TODO: switch to rusti::uninit when implemented
524-
let mut state: gmp_randstate_struct = rusti::init();
517+
let mut state: gmp_randstate_struct = uninit();
525518
__gmp_randinit_lc_2exp(&mut state, &a.mpz, c, m2exp);
526519
RandState { state: state }
527520
}
528521
}
529522
530523
fn new_lc_2exp_size(size: c_ulong) -> RandState {
531524
unsafe {
532-
// TODO: switch to rusti::uninit when implemented
533-
let mut state: gmp_randstate_struct = rusti::init();
525+
let mut state: gmp_randstate_struct = uninit();
534526
__gmp_randinit_lc_2exp_size(&mut state, size);
535527
RandState { state: state }
536528
}
@@ -566,8 +558,7 @@ impl RandState {
566558
impl Clone for RandState {
567559
fn clone(&self) -> RandState {
568560
unsafe {
569-
// TODO: switch to rusti::uninit when implemented
570-
let mut state: gmp_randstate_struct = rusti::init();
561+
let mut state: gmp_randstate_struct = uninit();
571562
__gmp_randinit_set(&mut state, &self.state);
572563
RandState { state: state }
573564
}
@@ -586,7 +577,7 @@ impl Drop for Mpq {
586577
impl Mpq {
587578
fn new() -> Mpq {
588579
unsafe {
589-
let mut mpq = rusti::init(); // TODO: switch to rusti::uninit when implemented
580+
let mut mpq = uninit();
590581
__gmpq_init(&mut mpq);
591582
Mpq { mpq: mpq }
592583
}
@@ -768,7 +759,7 @@ impl Drop for Mpf {
768759
impl Mpf {
769760
fn new(precision: c_ulong) -> Mpf {
770761
unsafe {
771-
let mut mpf = rusti::init(); // TODO: switch to rusti::uninit when implemented
762+
let mut mpf = uninit();
772763
__gmpf_init2(&mut mpf, precision);
773764
Mpf { mpf: mpf }
774765
}
@@ -831,7 +822,7 @@ impl Mpf {
831822
impl Clone for Mpf {
832823
fn clone(&self) -> Mpf {
833824
unsafe {
834-
let mut mpf = rusti::init(); // TODO: switch to rusti::uninit when implemented
825+
let mut mpf = uninit();
835826
__gmpf_init_set(&mut mpf, &self.mpf);
836827
Mpf { mpf: mpf }
837828
}

0 commit comments

Comments
 (0)