remove some unsafety from uint.rs
This commit is contained in:
parent
db869fcdd1
commit
5168a1c851
@ -92,8 +92,8 @@ macro_rules! uint_overflowing_add_reg {
|
|||||||
macro_rules! uint_overflowing_add {
|
macro_rules! uint_overflowing_add {
|
||||||
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
||||||
let self_t: &[u64; 4] = unsafe { &mem::transmute($self_expr) };
|
let self_t: &[u64; 4] = &self.0;
|
||||||
let other_t: &[u64; 4] = unsafe { &mem::transmute($other) };
|
let other_t: &[u64; 4] = &other.0;
|
||||||
|
|
||||||
let overflow: u8;
|
let overflow: u8;
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -115,8 +115,8 @@ macro_rules! uint_overflowing_add {
|
|||||||
});
|
});
|
||||||
(U512, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
(U512, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut result: [u64; 8] = unsafe { mem::uninitialized() };
|
let mut result: [u64; 8] = unsafe { mem::uninitialized() };
|
||||||
let self_t: &[u64; 8] = unsafe { &mem::transmute($self_expr) };
|
let self_t: &[u64; 8] = &self.0;
|
||||||
let other_t: &[u64; 8] = unsafe { &mem::transmute($other) };
|
let other_t: &[u64; 8] = &other.0;
|
||||||
|
|
||||||
let overflow: u8;
|
let overflow: u8;
|
||||||
|
|
||||||
@ -196,8 +196,8 @@ macro_rules! uint_overflowing_sub_reg {
|
|||||||
macro_rules! uint_overflowing_sub {
|
macro_rules! uint_overflowing_sub {
|
||||||
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
||||||
let self_t: &[u64; 4] = unsafe { &mem::transmute($self_expr) };
|
let self_t: &[u64; 4] = &self.0;
|
||||||
let other_t: &[u64; 4] = unsafe { &mem::transmute($other) };
|
let other_t: &[u64; 4] = &other.0;
|
||||||
|
|
||||||
let overflow: u8;
|
let overflow: u8;
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -218,8 +218,8 @@ macro_rules! uint_overflowing_sub {
|
|||||||
});
|
});
|
||||||
(U512, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
(U512, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut result: [u64; 8] = unsafe { mem::uninitialized() };
|
let mut result: [u64; 8] = unsafe { mem::uninitialized() };
|
||||||
let self_t: &[u64; 8] = unsafe { &mem::transmute($self_expr) };
|
let self_t: &[u64; 8] = &self.0;
|
||||||
let other_t: &[u64; 8] = unsafe { &mem::transmute($other) };
|
let other_t: &[u64; 8] = &other.0;
|
||||||
|
|
||||||
let overflow: u8;
|
let overflow: u8;
|
||||||
|
|
||||||
@ -270,8 +270,8 @@ macro_rules! uint_overflowing_sub {
|
|||||||
macro_rules! uint_overflowing_mul {
|
macro_rules! uint_overflowing_mul {
|
||||||
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
(U256, $n_words: expr, $self_expr: expr, $other: expr) => ({
|
||||||
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
let mut result: [u64; 4] = unsafe { mem::uninitialized() };
|
||||||
let self_t: &[u64; 4] = unsafe { &mem::transmute($self_expr) };
|
let self_t: &[u64; 4] = &self.0;
|
||||||
let other_t: &[u64; 4] = unsafe { &mem::transmute($other) };
|
let other_t: &[u64; 4] = &self.0;
|
||||||
|
|
||||||
let overflow: u64;
|
let overflow: u64;
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -548,6 +548,7 @@ pub trait Uint: Sized + Default + FromStr + From<u64> + fmt::Debug + fmt::Displa
|
|||||||
macro_rules! construct_uint {
|
macro_rules! construct_uint {
|
||||||
($name:ident, $n_words:expr) => (
|
($name:ident, $n_words:expr) => (
|
||||||
/// Little-endian large integer type
|
/// Little-endian large integer type
|
||||||
|
#[repr(C)]
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
pub struct $name(pub [u64; $n_words]);
|
pub struct $name(pub [u64; $n_words]);
|
||||||
|
|
||||||
@ -1132,8 +1133,8 @@ impl U256 {
|
|||||||
/// No overflow possible
|
/// No overflow possible
|
||||||
#[cfg(all(asm_available, target_arch="x86_64"))]
|
#[cfg(all(asm_available, target_arch="x86_64"))]
|
||||||
pub fn full_mul(self, other: U256) -> U512 {
|
pub fn full_mul(self, other: U256) -> U512 {
|
||||||
let self_t: &[u64; 4] = unsafe { &mem::transmute(self) };
|
let self_t: &[u64; 4] = &self.0;
|
||||||
let other_t: &[u64; 4] = unsafe { &mem::transmute(other) };
|
let other_t: &[u64; 4] = &other.0;
|
||||||
let mut result: [u64; 8] = unsafe { mem::uninitialized() };
|
let mut result: [u64; 8] = unsafe { mem::uninitialized() };
|
||||||
unsafe {
|
unsafe {
|
||||||
asm!("
|
asm!("
|
||||||
|
Loading…
Reference in New Issue
Block a user