Skip to content

Commit f7cae1e

Browse files
committed
Change signature of isinstance to take a reference to a python reference
1 parent f8016dc commit f7cae1e

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

vm/src/builtins.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn builtin_issubclass(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
213213
panic!("issubclass expects exactly two parameters");
214214
}
215215

216-
let cls1 = args.args[0].clone();
216+
let cls1 = &args.args[0];
217217
let cls2 = args.args[1].clone();
218218

219219
Ok(vm.context().new_bool(objtype::issubclass(cls1, cls2)))

vm/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ macro_rules! arg_check {
6363
{
6464
match expected_type {
6565
Some(expected_type) => {
66-
if !objtype::isinstance(arg.clone(), expected_type.clone()) {
66+
if !objtype::isinstance(arg, expected_type.clone()) {
6767
let arg_typ = arg.typ().clone();
6868
let actual_type = arg_typ.borrow().str().clone();
6969
return Err($vm.new_type_error(format!(

vm/src/obj/objint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn str(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
1414

1515
fn int_new(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
1616
let ref cls = args.args[0];
17-
if !objtype::issubclass(cls.clone(), vm.ctx.int_type()) {
17+
if !objtype::issubclass(cls, vm.ctx.int_type()) {
1818
return Err(vm.new_type_error(format!("{:?} is not a subtype of int", cls)));
1919
}
2020
let val = to_int(vm, &args.args[1].clone())?;

vm/src/obj/objtype.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ fn _mro(cls: PyObjectRef) -> Option<Vec<PyObjectRef>> {
5454
}
5555
}
5656

57-
pub fn isinstance(obj: PyObjectRef, cls: PyObjectRef) -> bool {
57+
pub fn isinstance(obj: &PyObjectRef, cls: PyObjectRef) -> bool {
5858
let mro = _mro(obj.typ()).unwrap();
5959
mro.into_iter().any(|c| c.is(&cls))
6060
}
6161

62-
pub fn issubclass(typ: PyObjectRef, cls: PyObjectRef) -> bool {
63-
let mro = _mro(typ).unwrap();
62+
pub fn issubclass(typ: &PyObjectRef, cls: PyObjectRef) -> bool {
63+
let mro = _mro(typ.clone()).unwrap();
6464
mro.into_iter().any(|c| c.is(&cls))
6565
}
6666

vm/src/vm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl VirtualMachine {
259259
// unwind block stack on exception and find any handlers.
260260
// Add an entry in the traceback:
261261
assert!(objtype::isinstance(
262-
exception.clone(),
262+
&exception,
263263
self.ctx.exceptions.base_exception_type.clone()
264264
));
265265
let traceback = self
@@ -962,7 +962,7 @@ impl VirtualMachine {
962962
_ => panic!("Invalid paramter for RAISE_VARARGS, must be between 0 to 3"),
963963
};
964964
if objtype::isinstance(
965-
exception.clone(),
965+
&exception,
966966
self.context().exceptions.base_exception_type.clone(),
967967
) {
968968
info!("Exception raised: {:?}", exception);

0 commit comments

Comments
 (0)