Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/src/float_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub fn parse_str(literal: &str) -> Option<f64> {
}

pub fn is_integer(v: f64) -> bool {
(v - v.round()).abs() < std::f64::EPSILON
(v - v.round()).abs() < f64::EPSILON
}

#[derive(Debug)]
Expand Down
4 changes: 2 additions & 2 deletions vm/src/anystr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ fn saturate_to_isize(py_int: PyIntRef) -> isize {
let big = py_int.as_bigint();
big.to_isize().unwrap_or_else(|| {
if big.is_negative() {
std::isize::MIN
isize::MIN
} else {
std::isize::MAX
isize::MAX
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion vm/src/builtins/pystr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl PyStr {
ch if (ch as u32) < 0x10000 => 6, // \uHHHH
_ => 10, // \uHHHHHHHH
};
if out_len > (std::isize::MAX as usize) - incr {
if out_len > (isize::MAX as usize) - incr {
return Err(vm.new_overflow_error("string is too long to generate repr".to_owned()));
}
out_len += incr;
Expand Down
4 changes: 2 additions & 2 deletions vm/src/bytesinner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ impl PyBytesInner {
return self.elements.clone();
};

let mut count = maxcount.unwrap_or(std::usize::MAX) - 1;
let mut count = maxcount.unwrap_or(usize::MAX) - 1;
for offset in iter {
new[offset..offset + len].clone_from_slice(to.elements.as_slice());
count -= 1;
Expand Down Expand Up @@ -860,7 +860,7 @@ impl PyBytesInner {
// result_len = self_len + count * (to_len-from_len)
debug_assert!(count > 0);
if to.len() as isize - from.len() as isize
> (std::isize::MAX - self.elements.len() as isize) / count as isize
> (isize::MAX - self.elements.len() as isize) / count as isize
{
return Err(vm.new_overflow_error("replace bytes is too long".to_owned()));
}
Expand Down
4 changes: 2 additions & 2 deletions vm/src/stdlib/cmath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
"pi" => ctx.new_float(std::f64::consts::PI),
"e" => ctx.new_float(std::f64::consts::E),
"tau" => ctx.new_float(2.0 * std::f64::consts::PI),
"inf" => ctx.new_float(std::f64::INFINITY),
"inf" => ctx.new_float(f64::INFINITY),
"infj" => ctx.new_complex(num_complex::Complex64::new(0., std::f64::INFINITY)),
"nan" => ctx.new_float(std::f64::NAN),
"nan" => ctx.new_float(f64::NAN),
"nanj" => ctx.new_complex(num_complex::Complex64::new(0., std::f64::NAN)),
});

Expand Down
8 changes: 4 additions & 4 deletions vm/src/stdlib/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn math_gamma(x: IntoPyFloat) -> f64 {
} else if x.is_nan() || x.is_sign_positive() {
x
} else {
std::f64::NAN
f64::NAN
}
}

Expand All @@ -338,7 +338,7 @@ fn math_lgamma(x: IntoPyFloat) -> f64 {
} else if x.is_nan() {
x
} else {
std::f64::INFINITY
f64::INFINITY
}
}

Expand Down Expand Up @@ -822,7 +822,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
"pi" => ctx.new_float(std::f64::consts::PI), // 3.14159...
"e" => ctx.new_float(std::f64::consts::E), // 2.71..
"tau" => ctx.new_float(2.0 * std::f64::consts::PI),
"inf" => ctx.new_float(std::f64::INFINITY),
"nan" => ctx.new_float(std::f64::NAN)
"inf" => ctx.new_float(f64::INFINITY),
"nan" => ctx.new_float(f64::NAN)
})
}
68 changes: 31 additions & 37 deletions vm/src/stdlib/sre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ mod _sre {
string: PyObjectRef,
#[pyarg(any, default = "0")]
pos: usize,
#[pyarg(any, default = "std::isize::MAX as usize")]
#[pyarg(any, default = "isize::MAX as usize")]
endpos: usize,
}

Expand Down Expand Up @@ -340,48 +340,42 @@ mod _sre {
split_args: SplitArgs,
vm: &VirtualMachine,
) -> PyResult<PyListRef> {
zelf.with_state(
split_args.string.clone(),
0,
std::usize::MAX,
vm,
|mut state| {
let mut splitlist: Vec<PyObjectRef> = Vec::new();
zelf.with_state(split_args.string.clone(), 0, usize::MAX, vm, |mut state| {
let mut splitlist: Vec<PyObjectRef> = Vec::new();

let mut n = 0;
let mut last = 0;
while split_args.maxsplit == 0 || n < split_args.maxsplit {
state = state.search();
if !state.has_matched {
break;
}
let mut n = 0;
let mut last = 0;
while split_args.maxsplit == 0 || n < split_args.maxsplit {
state = state.search();
if !state.has_matched {
break;
}

/* get segment before this match */
splitlist.push(slice_drive(&state.string, last, state.start, vm));
/* get segment before this match */
splitlist.push(slice_drive(&state.string, last, state.start, vm));

let m = Match::new(&state, zelf.clone(), split_args.string.clone());
let m = Match::new(&state, zelf.clone(), split_args.string.clone());

// add groups (if any)
for i in 1..zelf.groups + 1 {
splitlist.push(
m.get_slice(i, state.string, vm)
.unwrap_or_else(|| vm.ctx.none()),
);
}

n += 1;
state.must_advance = state.string_position == state.start;
last = state.string_position;
state.start = state.string_position;
state.reset();
// add groups (if any)
for i in 1..zelf.groups + 1 {
splitlist.push(
m.get_slice(i, state.string, vm)
.unwrap_or_else(|| vm.ctx.none()),
);
}

// get segment following last match (even if empty)
splitlist.push(slice_drive(&state.string, last, state.string.count(), vm));
n += 1;
state.must_advance = state.string_position == state.start;
last = state.string_position;
state.start = state.string_position;
state.reset();
}

Ok(PyList::from(splitlist).into_ref(vm))
},
)
// get segment following last match (even if empty)
splitlist.push(slice_drive(&state.string, last, state.string.count(), vm));

Ok(PyList::from(splitlist).into_ref(vm))
})
}

#[pymethod(magic)]
Expand Down Expand Up @@ -477,7 +471,7 @@ mod _sre {
}
};

zelf.with_state(string.clone(), 0, std::usize::MAX, vm, |mut state| {
zelf.with_state(string.clone(), 0, usize::MAX, vm, |mut state| {
let mut sublist: Vec<PyObjectRef> = Vec::new();
let mut n = 0;
let mut last_pos = 0;
Expand Down
2 changes: 1 addition & 1 deletion vm/src/sysmodule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
/*
* The magic sys module.
*/
const MAXSIZE: usize = std::isize::MAX as usize;
const MAXSIZE: usize = isize::MAX as usize;
const MAXUNICODE: u32 = std::char::MAX as u32;

fn argv(vm: &VirtualMachine) -> PyObjectRef {
Expand Down