Skip to content

Commit 6bfcd4c

Browse files
LeoTestardthestinger
authored andcommitted
Fix build for Rust master
1 parent 23f0e61 commit 6bfcd4c

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

gmp.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ extern mod std;
1212

1313
use std::from_str::FromStr;
1414
use std::libc::{c_char, c_double, c_int, c_long, c_ulong, c_void, size_t};
15-
use std::num::{IntConvertible, One, Zero};
15+
use std::num::{One, Zero};
1616
use std::unstable::intrinsics::uninit;
17+
use std::mem::size_of;
1718
use std::{cmp, int, str, to_str, uint, vec};
1819

1920
struct mpz_struct {
@@ -419,20 +420,34 @@ impl Neg<Mpz> for Mpz {
419420
}
420421
}
421422
422-
impl IntConvertible for Mpz {
423-
fn to_int(&self) -> int {
423+
impl ToPrimitive for Mpz {
424+
fn to_i64(&self) -> Option<i64> {
424425
fail!(~"not implemented")
425426
}
427+
fn to_u64(&self) -> Option<u64> {
428+
fail!(~"not implemented")
429+
}
430+
}
431+
432+
impl FromPrimitive for Mpz {
426433
#[fixed_stack_segment]
427-
fn from_int(other: int) -> Mpz {
434+
fn from_u64(other: u64) -> Option<Mpz> {
435+
unsafe {
436+
let mut res = Mpz::new();
437+
__gmpz_import(&mut res.mpz, 1, 1, size_of::<u64>() as size_t, 0, 0,
438+
std::util::id::<*u64>(&other) as *c_void);
439+
Some(res)
440+
}
441+
}
442+
fn from_i64(other: i64) -> Option<Mpz> {
428443
unsafe {
429444
let mut res = Mpz::new();
430-
__gmpz_import(&mut res.mpz, 1, 1, int::bytes as size_t, 0, 0,
431-
std::util::id::<*int>(&other.abs()) as *c_void);
445+
__gmpz_import(&mut res.mpz, 1, 1, size_of::<i64>() as size_t, 0, 0,
446+
std::util::id::<*i64>(&other.abs()) as *c_void);
432447
if other.is_negative() {
433448
__gmpz_neg(&mut res.mpz, &res.mpz)
434449
}
435-
res
450+
Some(res)
436451
}
437452
}
438453
}
@@ -794,14 +809,25 @@ impl Neg<Mpq> for Mpq {
794809
}
795810
}
796811
797-
impl IntConvertible for Mpq {
798-
fn to_int(&self) -> int {
812+
impl ToPrimitive for Mpq {
813+
fn to_i64(&self) -> Option<i64> {
814+
fail!(~"not implemented")
815+
}
816+
fn to_u64(&self) -> Option<u64> {
799817
fail!(~"not implemented")
800818
}
801-
fn from_int(other: int) -> Mpq {
819+
}
820+
821+
impl FromPrimitive for Mpq {
822+
fn from_i64(other: i64) -> Option<Mpq> {
823+
let mut res = Mpq::new();
824+
res.set_z(&FromPrimitive::from_i64(other).unwrap());
825+
Some(res)
826+
}
827+
fn from_u64(other: u64) -> Option<Mpq> {
802828
let mut res = Mpq::new();
803-
res.set_z(&IntConvertible::from_int(other));
804-
res
829+
res.set_z(&FromPrimitive::from_u64(other).unwrap());
830+
Some(res)
805831
}
806832
}
807833

0 commit comments

Comments
 (0)