Skip to content

Commit 611d858

Browse files
committed
{Type,Exception}Zoo holds static ref
1 parent c6a66be commit 611d858

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+657
-673
lines changed

src/shell.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
127127
};
128128

129129
if let Err(exc) = result {
130-
if exc.fast_isinstance(&vm.ctx.exceptions.system_exit) {
130+
if exc.fast_isinstance(vm.ctx.exceptions.system_exit) {
131131
repl.save_history(&repl_history_path).unwrap();
132132
return Err(exc);
133133
}

stdlib/src/json.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ mod _json {
3636
let object_hook = vm.option_if_none(ctx.get_attr("object_hook", vm)?);
3737
let object_pairs_hook = vm.option_if_none(ctx.get_attr("object_pairs_hook", vm)?);
3838
let parse_float = ctx.get_attr("parse_float", vm)?;
39-
let parse_float =
40-
if vm.is_none(&parse_float) || parse_float.is(&vm.ctx.types.float_type) {
41-
None
42-
} else {
43-
Some(parse_float)
44-
};
39+
let parse_float = if vm.is_none(&parse_float) || parse_float.is(vm.ctx.types.float_type)
40+
{
41+
None
42+
} else {
43+
Some(parse_float)
44+
};
4545
let parse_int = ctx.get_attr("parse_int", vm)?;
46-
let parse_int = if vm.is_none(&parse_int) || parse_int.is(&vm.ctx.types.int_type) {
46+
let parse_int = if vm.is_none(&parse_int) || parse_int.is(vm.ctx.types.int_type) {
4747
None
4848
} else {
4949
Some(parse_int)

stdlib/src/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ mod _socket {
153153
type CastFrom = libc::c_longlong;
154154

155155
// should really just be to_index() but test_socket tests the error messages explicitly
156-
if obj.fast_isinstance(&vm.ctx.types.float_type) {
156+
if obj.fast_isinstance(vm.ctx.types.float_type) {
157157
return Err(vm.new_type_error("integer argument expected, got float".to_owned()));
158158
}
159159
let int = vm

vm/src/builtins/asyncgenerator.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type PyAsyncGenRef = PyRef<PyAsyncGen>;
2222

2323
impl PyPayload for PyAsyncGen {
2424
fn class(vm: &VirtualMachine) -> &PyTypeRef {
25-
&vm.ctx.types.async_generator
25+
vm.ctx.types.async_generator
2626
}
2727
}
2828

@@ -136,7 +136,7 @@ impl Unconstructible for PyAsyncGen {}
136136
pub(crate) struct PyAsyncGenWrappedValue(pub PyObjectRef);
137137
impl PyPayload for PyAsyncGenWrappedValue {
138138
fn class(vm: &VirtualMachine) -> &PyTypeRef {
139-
&vm.ctx.types.async_generator_wrapped_value
139+
vm.ctx.types.async_generator_wrapped_value
140140
}
141141
}
142142

@@ -147,7 +147,7 @@ impl PyAsyncGenWrappedValue {
147147
fn unbox(ag: &PyAsyncGen, val: PyResult<PyIterReturn>, vm: &VirtualMachine) -> PyResult {
148148
let (closed, async_done) = match &val {
149149
Ok(PyIterReturn::StopIteration(_)) => (true, true),
150-
Err(e) if e.fast_isinstance(&vm.ctx.exceptions.generator_exit) => (true, true),
150+
Err(e) if e.fast_isinstance(vm.ctx.exceptions.generator_exit) => (true, true),
151151
Err(_) => (false, true),
152152
_ => (false, false),
153153
};
@@ -185,7 +185,7 @@ pub(crate) struct PyAsyncGenASend {
185185

186186
impl PyPayload for PyAsyncGenASend {
187187
fn class(vm: &VirtualMachine) -> &PyTypeRef {
188-
&vm.ctx.types.async_generator_asend
188+
vm.ctx.types.async_generator_asend
189189
}
190190
}
191191

@@ -280,7 +280,7 @@ pub(crate) struct PyAsyncGenAThrow {
280280

281281
impl PyPayload for PyAsyncGenAThrow {
282282
fn class(vm: &VirtualMachine) -> &PyTypeRef {
283-
&vm.ctx.types.async_generator_athrow
283+
vm.ctx.types.async_generator_athrow
284284
}
285285
}
286286

@@ -398,8 +398,8 @@ impl PyAsyncGenAThrow {
398398
self.ag.running_async.store(false);
399399
self.state.store(AwaitableState::Closed);
400400
if self.aclose
401-
&& (exc.fast_isinstance(&vm.ctx.exceptions.stop_async_iteration)
402-
|| exc.fast_isinstance(&vm.ctx.exceptions.generator_exit))
401+
&& (exc.fast_isinstance(vm.ctx.exceptions.stop_async_iteration)
402+
|| exc.fast_isinstance(vm.ctx.exceptions.generator_exit))
403403
{
404404
vm.new_stop_iteration(None)
405405
} else {
@@ -416,7 +416,7 @@ impl IterNext for PyAsyncGenAThrow {
416416
}
417417

418418
pub fn init(ctx: &Context) {
419-
PyAsyncGen::extend_class(ctx, &ctx.types.async_generator);
420-
PyAsyncGenASend::extend_class(ctx, &ctx.types.async_generator_asend);
421-
PyAsyncGenAThrow::extend_class(ctx, &ctx.types.async_generator_athrow);
419+
PyAsyncGen::extend_class(ctx, ctx.types.async_generator);
420+
PyAsyncGenASend::extend_class(ctx, ctx.types.async_generator_asend);
421+
PyAsyncGenAThrow::extend_class(ctx, ctx.types.async_generator_athrow);
422422
}

vm/src/builtins/bool.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl ToPyObject for bool {
1515

1616
impl TryFromBorrowedObject for bool {
1717
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObject) -> PyResult<bool> {
18-
if obj.fast_isinstance(&vm.ctx.types.int_type) {
18+
if obj.fast_isinstance(vm.ctx.types.int_type) {
1919
Ok(get_value(obj))
2020
} else {
2121
Err(vm.new_type_error(format!("Expected type bool, not {}", obj.class().name())))
@@ -37,7 +37,7 @@ impl PyObjectRef {
3737
// If descriptor returns Error, propagate it further
3838
let method = method_or_err?;
3939
let bool_obj = vm.invoke(&method, ())?;
40-
if !bool_obj.fast_isinstance(&vm.ctx.types.bool_type) {
40+
if !bool_obj.fast_isinstance(vm.ctx.types.bool_type) {
4141
return Err(vm.new_type_error(format!(
4242
"__bool__ should return bool, returned type {}",
4343
bool_obj.class().name()
@@ -80,7 +80,7 @@ pub struct PyBool;
8080

8181
impl PyPayload for PyBool {
8282
fn class(vm: &VirtualMachine) -> &PyTypeRef {
83-
&vm.ctx.types.bool_type
83+
vm.ctx.types.bool_type
8484
}
8585
}
8686

@@ -94,7 +94,7 @@ impl Constructor for PyBool {
9494
type Args = OptionalArg<PyObjectRef>;
9595

9696
fn py_new(zelf: PyTypeRef, x: Self::Args, vm: &VirtualMachine) -> PyResult {
97-
if !zelf.fast_isinstance(&vm.ctx.types.type_type) {
97+
if !zelf.fast_isinstance(vm.ctx.types.type_type) {
9898
let actual_class = zelf.class();
9999
let actual_type = &actual_class.name();
100100
return Err(vm.new_type_error(format!(
@@ -132,8 +132,8 @@ impl PyBool {
132132
#[pymethod(name = "__ror__")]
133133
#[pymethod(magic)]
134134
fn or(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
135-
if lhs.fast_isinstance(&vm.ctx.types.bool_type)
136-
&& rhs.fast_isinstance(&vm.ctx.types.bool_type)
135+
if lhs.fast_isinstance(vm.ctx.types.bool_type)
136+
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
137137
{
138138
let lhs = get_value(&lhs);
139139
let rhs = get_value(&rhs);
@@ -146,8 +146,8 @@ impl PyBool {
146146
#[pymethod(name = "__rand__")]
147147
#[pymethod(magic)]
148148
fn and(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
149-
if lhs.fast_isinstance(&vm.ctx.types.bool_type)
150-
&& rhs.fast_isinstance(&vm.ctx.types.bool_type)
149+
if lhs.fast_isinstance(vm.ctx.types.bool_type)
150+
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
151151
{
152152
let lhs = get_value(&lhs);
153153
let rhs = get_value(&rhs);
@@ -160,8 +160,8 @@ impl PyBool {
160160
#[pymethod(name = "__rxor__")]
161161
#[pymethod(magic)]
162162
fn xor(lhs: PyObjectRef, rhs: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
163-
if lhs.fast_isinstance(&vm.ctx.types.bool_type)
164-
&& rhs.fast_isinstance(&vm.ctx.types.bool_type)
163+
if lhs.fast_isinstance(vm.ctx.types.bool_type)
164+
&& rhs.fast_isinstance(vm.ctx.types.bool_type)
165165
{
166166
let lhs = get_value(&lhs);
167167
let rhs = get_value(&rhs);
@@ -173,11 +173,11 @@ impl PyBool {
173173
}
174174

175175
pub(crate) fn init(context: &Context) {
176-
PyBool::extend_class(context, &context.types.bool_type);
176+
PyBool::extend_class(context, context.types.bool_type);
177177
}
178178

179179
// pub fn not(vm: &VirtualMachine, obj: &PyObject) -> PyResult<bool> {
180-
// if obj.fast_isinstance(&vm.ctx.types.bool_type) {
180+
// if obj.fast_isinstance(vm.ctx.types.bool_type) {
181181
// let value = get_value(obj);
182182
// Ok(!value)
183183
// } else {

vm/src/builtins/builtinfunc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct PyBuiltinFunction {
6464

6565
impl PyPayload for PyBuiltinFunction {
6666
fn class(vm: &VirtualMachine) -> &PyTypeRef {
67-
&vm.ctx.types.builtin_function_or_method_type
67+
vm.ctx.types.builtin_function_or_method_type
6868
}
6969
}
7070

@@ -169,7 +169,7 @@ pub struct PyBuiltinMethod {
169169

170170
impl PyPayload for PyBuiltinMethod {
171171
fn class(vm: &VirtualMachine) -> &PyTypeRef {
172-
&vm.ctx.types.method_descriptor_type
172+
vm.ctx.types.method_descriptor_type
173173
}
174174
}
175175

@@ -254,6 +254,6 @@ impl PyBuiltinMethod {
254254
impl Unconstructible for PyBuiltinMethod {}
255255

256256
pub fn init(context: &Context) {
257-
PyBuiltinFunction::extend_class(context, &context.types.builtin_function_or_method_type);
258-
PyBuiltinMethod::extend_class(context, &context.types.method_descriptor_type);
257+
PyBuiltinFunction::extend_class(context, context.types.builtin_function_or_method_type);
258+
PyBuiltinMethod::extend_class(context, context.types.method_descriptor_type);
259259
}

vm/src/builtins/bytearray.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ impl From<Vec<u8>> for PyByteArray {
8383

8484
impl PyPayload for PyByteArray {
8585
fn class(vm: &VirtualMachine) -> &PyTypeRef {
86-
&vm.ctx.types.bytearray_type
86+
vm.ctx.types.bytearray_type
8787
}
8888
}
8989

9090
/// Fill bytearray class methods dictionary.
9191
pub(crate) fn init(context: &Context) {
92-
PyByteArray::extend_class(context, &context.types.bytearray_type);
93-
PyByteArrayIterator::extend_class(context, &context.types.bytearray_iterator_type);
92+
PyByteArray::extend_class(context, context.types.bytearray_type);
93+
PyByteArrayIterator::extend_class(context, context.types.bytearray_iterator_type);
9494
}
9595

9696
#[pyimpl(
@@ -863,7 +863,7 @@ pub struct PyByteArrayIterator {
863863

864864
impl PyPayload for PyByteArrayIterator {
865865
fn class(vm: &VirtualMachine) -> &PyTypeRef {
866-
&vm.ctx.types.bytearray_iterator_type
866+
vm.ctx.types.bytearray_iterator_type
867867
}
868868
}
869869

vm/src/builtins/bytes.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ impl AsRef<[u8]> for PyBytesRef {
7575

7676
impl PyPayload for PyBytes {
7777
fn class(vm: &VirtualMachine) -> &PyTypeRef {
78-
&vm.ctx.types.bytes_type
78+
vm.ctx.types.bytes_type
7979
}
8080
}
8181

8282
pub(crate) fn init(context: &Context) {
83-
PyBytes::extend_class(context, &context.types.bytes_type);
84-
PyBytesIterator::extend_class(context, &context.types.bytes_iterator_type);
83+
PyBytes::extend_class(context, context.types.bytes_type);
84+
PyBytesIterator::extend_class(context, context.types.bytes_iterator_type);
8585
}
8686

8787
impl Constructor for PyBytes {
@@ -134,7 +134,7 @@ impl PyBytes {
134134

135135
#[pymethod(magic)]
136136
fn bytes(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyRef<Self> {
137-
if zelf.is(&vm.ctx.types.bytes_type) {
137+
if zelf.is(vm.ctx.types.bytes_type) {
138138
zelf
139139
} else {
140140
PyBytes::from(zelf.inner.clone()).into_ref(vm)
@@ -480,7 +480,7 @@ impl PyBytes {
480480
#[pymethod(name = "__rmul__")]
481481
#[pymethod(magic)]
482482
fn mul(zelf: PyRef<Self>, value: isize, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
483-
if value == 1 && zelf.class().is(&vm.ctx.types.bytes_type) {
483+
if value == 1 && zelf.class().is(vm.ctx.types.bytes_type) {
484484
// Special case: when some `bytes` is multiplied by `1`,
485485
// nothing really happens, we need to return an object itself
486486
// with the same `id()` to be compatible with CPython.
@@ -633,7 +633,7 @@ impl Comparable for PyBytes {
633633
) -> PyResult<PyComparisonValue> {
634634
Ok(if let Some(res) = op.identical_optimization(zelf, other) {
635635
res.into()
636-
} else if other.fast_isinstance(&vm.ctx.types.memoryview_type)
636+
} else if other.fast_isinstance(vm.ctx.types.memoryview_type)
637637
&& op != PyComparisonOp::Eq
638638
&& op != PyComparisonOp::Ne
639639
{
@@ -666,7 +666,7 @@ pub struct PyBytesIterator {
666666

667667
impl PyPayload for PyBytesIterator {
668668
fn class(vm: &VirtualMachine) -> &PyTypeRef {
669-
&vm.ctx.types.bytes_iterator_type
669+
vm.ctx.types.bytes_iterator_type
670670
}
671671
}
672672

vm/src/builtins/classmethod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl From<PyObjectRef> for PyClassMethod {
4040

4141
impl PyPayload for PyClassMethod {
4242
fn class(vm: &VirtualMachine) -> &PyTypeRef {
43-
&vm.ctx.types.classmethod_type
43+
vm.ctx.types.classmethod_type
4444
}
4545
}
4646

@@ -96,5 +96,5 @@ impl PyClassMethod {
9696
}
9797

9898
pub(crate) fn init(context: &Context) {
99-
PyClassMethod::extend_class(context, &context.types.classmethod_type);
99+
PyClassMethod::extend_class(context, context.types.classmethod_type);
100100
}

vm/src/builtins/code.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl fmt::Debug for PyCode {
152152

153153
impl PyPayload for PyCode {
154154
fn class(vm: &VirtualMachine) -> &PyTypeRef {
155-
&vm.ctx.types.code_type
155+
vm.ctx.types.code_type
156156
}
157157
}
158158

@@ -250,5 +250,5 @@ impl ToPyObject for bytecode::CodeObject {
250250
}
251251

252252
pub fn init(ctx: &Context) {
253-
PyRef::<PyCode>::extend_class(ctx, &ctx.types.code_type);
253+
PyRef::<PyCode>::extend_class(ctx, ctx.types.code_type);
254254
}

vm/src/builtins/complex.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct PyComplex {
2525

2626
impl PyPayload for PyComplex {
2727
fn class(vm: &VirtualMachine) -> &PyTypeRef {
28-
&vm.ctx.types.complex_type
28+
vm.ctx.types.complex_type
2929
}
3030
}
3131

@@ -72,7 +72,7 @@ impl PyObjectRef {
7272
}
7373

7474
pub fn init(context: &Context) {
75-
PyComplex::extend_class(context, &context.types.complex_type);
75+
PyComplex::extend_class(context, context.types.complex_type);
7676
}
7777

7878
fn to_op_complex(value: &PyObject, vm: &VirtualMachine) -> PyResult<Option<Complex64>> {
@@ -120,7 +120,7 @@ impl Constructor for PyComplex {
120120
let (real, real_was_complex) = match args.real {
121121
OptionalArg::Missing => (Complex64::new(0.0, 0.0), false),
122122
OptionalArg::Present(val) => {
123-
let val = if cls.is(&vm.ctx.types.complex_type) && imag_missing {
123+
let val = if cls.is(vm.ctx.types.complex_type) && imag_missing {
124124
match val.downcast_exact::<PyComplex>(vm) {
125125
Ok(c) => {
126126
return Ok(c.into());
@@ -161,7 +161,7 @@ impl Constructor for PyComplex {
161161
OptionalArg::Present(obj) => {
162162
if let Some(c) = obj.try_complex(vm)? {
163163
c
164-
} else if obj.class().fast_issubclass(&vm.ctx.types.str_type) {
164+
} else if obj.class().fast_issubclass(vm.ctx.types.str_type) {
165165
return Err(
166166
vm.new_type_error("complex() second arg can't be a string".to_owned())
167167
);
@@ -206,7 +206,7 @@ impl PyComplex {
206206
impl PyComplex {
207207
#[pymethod(magic)]
208208
fn complex(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyRef<PyComplex> {
209-
if zelf.is(&vm.ctx.types.complex_type) {
209+
if zelf.is(vm.ctx.types.complex_type) {
210210
zelf
211211
} else {
212212
PyComplex::from(zelf.value).into_ref(vm)

0 commit comments

Comments
 (0)