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
461 changes: 199 additions & 262 deletions crates/vm/src/buffer.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions crates/vm/src/builtins/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl From<Complex64> for PyComplex {
}
}

impl PyObjectRef {
impl PyObject {
/// Convert a constructor argument, preferring an overridden `__complex__`.
/// The flag records whether the result came from a complex value or method,
/// rather than a real-number conversion.
Expand All @@ -111,7 +111,7 @@ impl PyObjectRef {
// Unlike the two-component constructor, the single-argument form uses
// PyFloat_AsDouble: read float subclasses without invoking __float__.
if self.downcastable::<PyFloat>() || has_real_number_conversion(self) {
let real = ArgIntoFloat::try_from_object(vm, self.clone())?.into_float();
let real = self.try_to_value::<ArgIntoFloat>(vm)?.into_float();
return Ok(Some((Complex64::new(real, 0.0), false)));
}

Expand All @@ -122,7 +122,7 @@ impl PyObjectRef {
&self,
vm: &VirtualMachine,
) -> PyResult<Option<PyRef<PyComplex>>> {
let Some(method) = vm.get_method(self.clone(), identifier!(vm, __complex__)) else {
let Some(method) = vm.get_method(self.to_owned(), identifier!(vm, __complex__)) else {
return Ok(None);
};
let result = method?.call((), vm)?;
Expand Down
11 changes: 11 additions & 0 deletions crates/vm/src/builtins/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,17 @@ impl Constructor for PyInt {
}

impl PyInt {
/// PyNumber_AsSsize_t with no overflow exception, as used by slice indices.
pub(crate) fn as_saturated_index(&self) -> isize {
self.value.to_isize().unwrap_or_else(|| {
if self.value.is_negative() {
isize::MIN
} else {
isize::MAX
}
})
}

fn with_value<T>(cls: PyTypeRef, value: T, vm: &VirtualMachine) -> PyResult<PyRef<Self>>
where
T: Into<BigInt> + ToPrimitive,
Expand Down
Loading
Loading