Skip to content

Commit af5cc4e

Browse files
committed
Share binary formats and align memoryview with CPython 3.15
Reuse the shared Clinic binder, numeric converters and struct cache while preserving memoryview-specific scalar policies. Avoid per-scalar temporary allocations and redundant object clones. Match cast, indexing, comparison and half conversion behavior, preserve callback lifetimes, and fix multidimensional comparison and shared-buffer reads. Add focused Rust and Python regression coverage. AI assistance covered implementation, test preparation and source review. Assisted-by: OpenAI Codex:model version not exposed
1 parent a5d2485 commit af5cc4e

13 files changed

Lines changed: 1211 additions & 555 deletions

File tree

‎crates/vm/src/buffer.rs‎

Lines changed: 199 additions & 262 deletions
Large diffs are not rendered by default.

‎crates/vm/src/builtins/complex.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl From<Complex64> for PyComplex {
9292
}
9393
}
9494

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

@@ -122,7 +122,7 @@ impl PyObjectRef {
122122
&self,
123123
vm: &VirtualMachine,
124124
) -> PyResult<Option<PyRef<PyComplex>>> {
125-
let Some(method) = vm.get_method(self.clone(), identifier!(vm, __complex__)) else {
125+
let Some(method) = vm.get_method(self.to_owned(), identifier!(vm, __complex__)) else {
126126
return Ok(None);
127127
};
128128
let result = method?.call((), vm)?;

‎crates/vm/src/builtins/int.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,17 @@ impl Constructor for PyInt {
338338
}
339339

340340
impl PyInt {
341+
/// PyNumber_AsSsize_t with no overflow exception, as used by slice indices.
342+
pub(crate) fn as_saturated_index(&self) -> isize {
343+
self.value.to_isize().unwrap_or_else(|| {
344+
if self.value.is_negative() {
345+
isize::MIN
346+
} else {
347+
isize::MAX
348+
}
349+
})
350+
}
351+
341352
fn with_value<T>(cls: PyTypeRef, value: T, vm: &VirtualMachine) -> PyResult<PyRef<Self>>
342353
where
343354
T: Into<BigInt> + ToPrimitive,

0 commit comments

Comments
 (0)