Skip to content

Commit 384cb3d

Browse files
committed
Make rust-gmp compile again
1 parent 195e5a6 commit 384cb3d

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

deps/rust-gmp/gmp.rs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::from_str::FromStr;
1818
struct mpz_struct {
1919
_mp_alloc: c_int,
2020
_mp_size: c_int,
21-
_mp_d: *c_void
21+
_mp_d: *mut c_void
2222
}
2323

2424
struct mpq_struct {
@@ -32,21 +32,21 @@ struct mpf_struct {
3232
_mp_prec: c_int,
3333
_mp_size: c_int,
3434
_mp_exp: mp_exp_t,
35-
_mp_d: *c_void
35+
_mp_d: *mut c_void
3636
}
3737

3838
struct gmp_randstate_struct {
3939
_mp_seed: mpz_struct,
4040
_mp_alg: c_int,
41-
_mp_algdata: *c_void
41+
_mp_algdata: *mut c_void
4242
}
4343

4444
type mp_bitcnt_t = c_ulong;
45-
type mpz_srcptr = *mpz_struct;
45+
type mpz_srcptr = *const mpz_struct;
4646
type mpz_ptr = *mut mpz_struct;
47-
type mpq_srcptr = *mpq_struct;
47+
type mpq_srcptr = *const mpq_struct;
4848
type mpq_ptr = *mut mpq_struct;
49-
type mpf_srcptr = *mpf_struct;
49+
type mpf_srcptr = *const mpf_struct;
5050
type mpf_ptr = *mut mpf_struct;
5151
type gmp_randstate_t = *mut gmp_randstate_struct;
5252

@@ -56,12 +56,12 @@ extern "C" {
5656
fn __gmpz_init2(x: mpz_ptr, n: mp_bitcnt_t);
5757
fn __gmpz_init_set(rop: mpz_ptr, op: mpz_srcptr);
5858
fn __gmpz_init_set_ui(rop: mpz_ptr, op: c_ulong);
59-
fn __gmpz_init_set_str(rop: mpz_ptr, str: *c_char, base: c_int) -> c_int;
59+
fn __gmpz_init_set_str(rop: mpz_ptr, str: *const c_char, base: c_int) -> c_int;
6060
fn __gmpz_clear(x: mpz_ptr);
6161
fn __gmpz_realloc2(x: mpz_ptr, n: mp_bitcnt_t);
6262
fn __gmpz_set(rop: mpz_ptr, op: mpz_srcptr);
63-
fn __gmpz_set_str(rop: mpz_ptr, str: *c_char, base: c_int) -> c_int;
64-
fn __gmpz_get_str(str: *mut c_char, base: c_int, op: mpz_srcptr) -> *c_char;
63+
fn __gmpz_set_str(rop: mpz_ptr, str: *const c_char, base: c_int) -> c_int;
64+
fn __gmpz_get_str(str: *mut c_char, base: c_int, op: mpz_srcptr) -> *mut c_char;
6565
fn __gmpz_sizeinbase(op: mpz_srcptr, base: c_int) -> size_t;
6666
fn __gmpz_cmp(op1: mpz_srcptr, op2: mpz_srcptr) -> c_int;
6767
fn __gmpz_cmp_ui(op1: mpz_srcptr, op2: c_ulong) -> c_int;
@@ -92,12 +92,12 @@ extern "C" {
9292
fn __gmpz_lcm(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr);
9393
fn __gmpz_invert(rop: mpz_ptr, op1: mpz_srcptr, op2: mpz_srcptr) -> c_int;
9494
fn __gmpz_import(rop: mpz_ptr, count: size_t, order: c_int, size: size_t,
95-
endian: c_int, nails: size_t, op: *c_void);
95+
endian: c_int, nails: size_t, op: *const c_void);
9696
fn __gmp_randinit_default(state: gmp_randstate_t);
9797
fn __gmp_randinit_mt(state: gmp_randstate_t);
9898
fn __gmp_randinit_lc_2exp(state: gmp_randstate_t, a: mpz_srcptr, c: c_ulong, m2exp: mp_bitcnt_t);
9999
fn __gmp_randinit_lc_2exp_size(state: gmp_randstate_t, size: mp_bitcnt_t);
100-
fn __gmp_randinit_set(state: gmp_randstate_t, op: *gmp_randstate_struct);
100+
fn __gmp_randinit_set(state: gmp_randstate_t, op: *const gmp_randstate_struct);
101101
fn __gmp_randclear(state: gmp_randstate_t);
102102
fn __gmp_randseed(state: gmp_randstate_t, seed: mpz_srcptr);
103103
fn __gmp_randseed_ui(state: gmp_randstate_t, seed: c_ulong);
@@ -337,8 +337,8 @@ impl Ord for Mpz {
337337
}
338338

339339
impl PartialOrd for Mpz {
340-
fn lt(&self, other: &Mpz) -> bool {
341-
self.cmp(other) == Less
340+
fn partial_cmp(&self, other: &Mpz) -> Option<Ordering> {
341+
Some(self.cmp(other))
342342
}
343343
}
344344

@@ -424,15 +424,15 @@ impl FromPrimitive for Mpz {
424424
unsafe {
425425
let mut res = Mpz::new();
426426
__gmpz_import(&mut res.mpz, 1, 1, size_of::<u64>() as size_t, 0, 0,
427-
&other as *u64 as *c_void);
427+
&other as *const u64 as *const c_void);
428428
Some(res)
429429
}
430430
}
431431
fn from_i64(other: i64) -> Option<Mpz> {
432432
unsafe {
433433
let mut res = Mpz::new();
434434
__gmpz_import(&mut res.mpz, 1, 1, size_of::<i64>() as size_t, 0, 0,
435-
&other.abs() as *i64 as *c_void);
435+
&other.abs() as *const i64 as *const c_void);
436436
if other.is_negative() {
437437
__gmpz_neg(&mut res.mpz, &res.mpz)
438438
}
@@ -713,17 +713,13 @@ impl cmp::PartialEq for Mpq {
713713
}
714714

715715
impl cmp::PartialOrd for Mpq {
716-
fn lt(&self, other: &Mpq) -> bool {
717-
unsafe { __gmpq_cmp(&self.mpq, &other.mpq) < 0 }
718-
}
719-
fn le(&self, other: &Mpq) -> bool {
720-
unsafe { __gmpq_cmp(&self.mpq, &other.mpq) <= 0 }
721-
}
722-
fn gt(&self, other: &Mpq) -> bool {
723-
unsafe { __gmpq_cmp(&self.mpq, &other.mpq) > 0 }
724-
}
725-
fn ge(&self, other: &Mpq) -> bool {
726-
unsafe { __gmpq_cmp(&self.mpq, &other.mpq) >= 0 }
716+
fn partial_cmp(&self, other: &Mpq) -> Option<Ordering> {
717+
match unsafe { __gmpq_cmp(&self.mpq, &other.mpq) } {
718+
0 => Some(Equal),
719+
x if x < 0 => Some(Less),
720+
x if x > 0 => Some(Greater),
721+
_ => None,
722+
}
727723
}
728724
}
729725

@@ -909,17 +905,13 @@ impl cmp::PartialEq for Mpf {
909905
}
910906

911907
impl cmp::PartialOrd for Mpf {
912-
fn lt(&self, other: &Mpf) -> bool {
913-
unsafe { __gmpf_cmp(&self.mpf, &other.mpf) < 0 }
914-
}
915-
fn le(&self, other: &Mpf) -> bool {
916-
unsafe { __gmpf_cmp(&self.mpf, &other.mpf) <= 0 }
917-
}
918-
fn gt(&self, other: &Mpf) -> bool {
919-
unsafe { __gmpf_cmp(&self.mpf, &other.mpf) > 0 }
920-
}
921-
fn ge(&self, other: &Mpf) -> bool {
922-
unsafe { __gmpf_cmp(&self.mpf, &other.mpf) >= 0 }
908+
fn partial_cmp(&self, other: &Mpf) -> Option<Ordering> {
909+
match unsafe { __gmpf_cmp(&self.mpf, &other.mpf) } {
910+
0 => Some(Equal),
911+
x if x < 0 => Some(Less),
912+
x if x > 0 => Some(Greater),
913+
_ => None,
914+
}
923915
}
924916
}
925917

0 commit comments

Comments
 (0)