From df1aa5add726ca8895544856bb935afcfb23fd16 Mon Sep 17 00:00:00 2001 From: Jeong Yunwon Date: Thu, 14 Apr 2022 03:57:36 +0900 Subject: [PATCH] PyContext::new don't create a new context --- vm/src/builtins/pytype.rs | 2 +- vm/src/pyobject.rs | 17 ++++++----------- vm/src/pyobjectrc.rs | 2 +- vm/src/vm.rs | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/vm/src/builtins/pytype.rs b/vm/src/builtins/pytype.rs index 1fe52c8e2..052826493 100644 --- a/vm/src/builtins/pytype.rs +++ b/vm/src/builtins/pytype.rs @@ -953,7 +953,7 @@ mod tests { #[test] fn test_linearise() { - let context = PyContext::new(); + let context = PyContext::default(); let object = &context.types.object_type; let type_type = &context.types.type_type; diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 19dbc1495..03c3ae775 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -24,10 +24,8 @@ use crate::{ }; use num_bigint::BigInt; use num_traits::ToPrimitive; -use std::any::Any; -use std::collections::HashMap; -use std::fmt; -use std::ops::Deref; +use std::{any::Any, collections::HashMap, fmt, ops::Deref}; + /* Python objects and references. Okay, so each python object itself is an class itself (PyObject). Each @@ -143,12 +141,6 @@ impl PyContext { exceptions::ExceptionZoo::extend(&context); context } - pub fn new() -> Self { - rustpython_common::static_cell! { - static CONTEXT: PyContext; - } - CONTEXT.get_or_init(Self::init).clone() - } pub fn none(&self) -> PyObjectRef { self.none.clone().into() @@ -338,7 +330,10 @@ impl PyContext { impl Default for PyContext { fn default() -> Self { - PyContext::new() + rustpython_common::static_cell! { + static CONTEXT: PyContext; + } + CONTEXT.get_or_init(Self::init).clone() } } diff --git a/vm/src/pyobjectrc.rs b/vm/src/pyobjectrc.rs index 5cbbf60da..259cfa4d7 100644 --- a/vm/src/pyobjectrc.rs +++ b/vm/src/pyobjectrc.rs @@ -1177,7 +1177,7 @@ mod tests { #[test] fn miri_test_drop() { - let ctx = crate::PyContext::new(); + let ctx = crate::PyContext::default(); let obj = ctx.new_bytes(b"dfghjkl".to_vec()); drop(obj); } diff --git a/vm/src/vm.rs b/vm/src/vm.rs index 8d3fac70b..3812cdede 100644 --- a/vm/src/vm.rs +++ b/vm/src/vm.rs @@ -243,7 +243,7 @@ impl VirtualMachine { /// Create a new `VirtualMachine` structure. fn new(settings: PySettings) -> VirtualMachine { flame_guard!("new VirtualMachine"); - let ctx = PyContext::new(); + let ctx = PyContext::default(); // make a new module without access to the vm; doesn't // set __spec__, __loader__, etc. attributes