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
5 changes: 1 addition & 4 deletions crates/capi/src/pyerrors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ pub unsafe extern "C" fn PyErr_SetString(exception: *mut PyObject, message: *con
let exc_type = unsafe { &*exception }.try_downcast_ref::<PyType>(vm)?;
let message = unsafe { message.try_as_str(vm) }?;

let exc = vm.invoke_exception(
exc_type.to_owned(),
vec![vm.ctx.new_str(message).into_object()],
)?;
let exc = vm.invoke_exception(exc_type, vec![vm.ctx.new_str(message).into_object()])?;

Err(exc)
})
Expand Down
7 changes: 2 additions & 5 deletions crates/vm/src/exception_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,8 @@ pub(super) mod types {
vm: &VirtualMachine,
) -> PyResult {
let message = zelf.get_arg(0).unwrap_or_else(|| vm.ctx.new_str("").into());
vm.invoke_exception(
vm.ctx.exceptions.base_exception_group.to_owned(),
vec![message, excs],
)
.map(|e| e.into())
vm.invoke_exception(vm.ctx.exceptions.base_exception_group, vec![message, excs])
.map(|e| e.into())
}

#[pymethod]
Expand Down
10 changes: 5 additions & 5 deletions crates/vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ impl VirtualMachine {

pub fn invoke_exception(
&self,
cls: PyTypeRef,
cls: &Py<PyType>,
args: Vec<PyObjectRef>,
) -> PyResult<PyBaseExceptionRef> {
// TODO: fast-path built-in exceptions by directly instantiating them? Is that really worth it?
let res = PyType::call(&cls, args.into_args(self), self)?;
let res = PyType::call(cls, args.into_args(self), self)?;
res.downcast::<PyBaseException>().map_err(|obj| {
self.new_type_error(format!(
"calling {} should have returned an instance of BaseException, not {}",
Expand Down Expand Up @@ -444,7 +444,7 @@ impl TryFromObject for ExceptionCtor {
impl ExceptionCtor {
pub fn instantiate(self, vm: &VirtualMachine) -> PyResult<PyBaseExceptionRef> {
match self {
Self::Class(cls) => vm.invoke_exception(cls, vec![]),
Self::Class(cls) => vm.invoke_exception(&cls, vec![]),
Self::Instance(exc) => Ok(exc),
}
}
Expand Down Expand Up @@ -472,7 +472,7 @@ impl ExceptionCtor {
exc @ PyBaseException => exc.args().to_vec(),
obj => vec![obj],
});
vm.invoke_exception(cls, args)
vm.invoke_exception(&cls, args)
}
}
}
Expand Down Expand Up @@ -2101,7 +2101,7 @@ pub(super) mod types {
.downcast_ref::<PyInt>()
.and_then(|errno| errno.try_to_primitive::<i32>(vm).ok())
.and_then(|errno| super::errno_to_exc_type(errno, vm))
.and_then(|typ| vm.invoke_exception(typ.to_owned(), args_vec).ok())
.and_then(|typ| vm.invoke_exception(typ, args_vec).ok())
{
return error.to_pyresult(vm);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/stdlib/_ctypes/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ fn check_hresult(hresult: i32, zelf: &Py<PyCFuncPtr>, vm: &VirtualMachine) -> Py
.new_str(format!("HRESULT: 0x{:08X}", hresult as u32))
.into();
let details: PyObjectRef = vm.ctx.none();
let exc = vm.invoke_exception(com_error_type, vec![text.clone(), details.clone()])?;
let exc = vm.invoke_exception(&com_error_type, vec![text.clone(), details.clone()])?;
let _ = exc.as_object().set_attr("hresult", hresult_obj, vm);
let _ = exc.as_object().set_attr("text", text, vm);
let _ = exc.as_object().set_attr("details", details, vm);
Expand Down
6 changes: 3 additions & 3 deletions crates/vm/src/stdlib/_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ mod _io {
None => {
// BlockingIOError(errno, msg, characters_written=0)
return Err(vm.invoke_exception(
vm.ctx.exceptions.blocking_io_error.to_owned(),
vm.ctx.exceptions.blocking_io_error,
vec![
vm.new_pyobj(EAGAIN),
vm.new_pyobj("write could not complete without blocking"),
Expand Down Expand Up @@ -1154,7 +1154,7 @@ mod _io {
self.write_end += avail as Offset;
self.pos += avail as Offset;
return Err(vm.invoke_exception(
vm.ctx.exceptions.blocking_io_error.to_owned(),
vm.ctx.exceptions.blocking_io_error,
vec![
vm.new_pyobj(EAGAIN),
vm.new_pyobj("write could not complete without blocking"),
Expand Down Expand Up @@ -1200,7 +1200,7 @@ mod _io {
// BlockingIOError(errno, msg, characters_written)
let chars_written = written + buffer_len;
return Err(vm.invoke_exception(
vm.ctx.exceptions.blocking_io_error.to_owned(),
vm.ctx.exceptions.blocking_io_error,
vec![
vm.new_pyobj(EAGAIN),
vm.new_pyobj("write could not complete without blocking"),
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/stdlib/_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ pub(crate) mod _thread {

#[pyfunction]
fn exit(vm: &VirtualMachine) -> PyResult {
Err(vm.invoke_exception(vm.ctx.exceptions.system_exit.to_owned(), vec![])?)
Err(vm.invoke_exception(vm.ctx.exceptions.system_exit, vec![])?)
}

thread_local!(static SENTINELS: RefCell<Vec<PyRef<Lock>>> = const { RefCell::new(Vec::new()) });
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/stdlib/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ mod builtins {
#[pyfunction]
pub(super) fn exit(exit_code_arg: OptionalArg<PyObjectRef>, vm: &VirtualMachine) -> PyResult {
let code = exit_code_arg.unwrap_or_else(|| vm.ctx.new_int(0).into());
Err(vm.invoke_exception(vm.ctx.exceptions.system_exit.to_owned(), vec![code])?)
Err(vm.invoke_exception(vm.ctx.exceptions.system_exit, vec![code])?)
}

#[derive(Debug, Default, FromArgs)]
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/stdlib/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ pub mod sys {
} else {
vec![status]
};
let exc = vm.invoke_exception(vm.ctx.exceptions.system_exit.to_owned(), args)?;
let exc = vm.invoke_exception(vm.ctx.exceptions.system_exit, args)?;
Err(exc)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ impl VirtualMachine {
if self.state.finalizing.load(Ordering::Acquire) && !self.is_main_thread() {
// once finalization starts,
// non-main Python threads should stop running bytecode.
return Err(self.invoke_exception(self.ctx.exceptions.system_exit.to_owned(), vec![])?);
return Err(self.invoke_exception(self.ctx.exceptions.system_exit, vec![])?);
}

// Suspend this thread if stop-the-world is in progress
Expand Down
2 changes: 1 addition & 1 deletion crates/vm/src/vm/vm_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ impl VirtualMachine {
}

pub fn new_stop_iteration(&self, value: Option<PyObjectRef>) -> PyBaseExceptionRef {
let stop_iteration_error = self.ctx.exceptions.stop_iteration.to_owned();
let stop_iteration_error = self.ctx.exceptions.stop_iteration;
let args = if let Some(value) = value {
vec![value]
} else {
Expand Down
Loading