Skip to content

Commit 198e449

Browse files
committed
recursion_limit is actually thread-local
1 parent 5f93f83 commit 198e449

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

vm/src/sysmodule.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ fn update_use_tracing(vm: &VirtualMachine) {
155155
}
156156

157157
fn sys_getrecursionlimit(vm: &VirtualMachine) -> usize {
158-
vm.state.recursion_limit.load()
158+
vm.recursion_limit.get()
159159
}
160160

161161
fn sys_setrecursionlimit(recursion_limit: usize, vm: &VirtualMachine) -> PyResult {
162162
let recursion_depth = vm.frames.borrow().len();
163163

164164
if recursion_limit > recursion_depth + 1 {
165-
vm.state.recursion_limit.store(recursion_limit);
165+
vm.recursion_limit.set(recursion_limit);
166166
Ok(vm.ctx.none())
167167
} else {
168168
Err(vm.new_recursion_error(format!(

vm/src/vm.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use crate::pyobject::{
4646
use crate::scope::Scope;
4747
use crate::stdlib;
4848
use crate::sysmodule;
49-
use crossbeam_utils::atomic::AtomicCell;
5049

5150
// use objects::objects;
5251

@@ -65,14 +64,14 @@ pub struct VirtualMachine {
6564
pub profile_func: RefCell<PyObjectRef>,
6665
pub trace_func: RefCell<PyObjectRef>,
6766
pub use_tracing: Cell<bool>,
67+
pub recursion_limit: Cell<usize>,
6868
pub signal_handlers: Option<RefCell<[PyObjectRef; NSIG]>>,
6969
pub state: Arc<PyGlobalState>,
7070
pub initialized: bool,
7171
}
7272

7373
pub struct PyGlobalState {
7474
pub settings: PySettings,
75-
pub recursion_limit: AtomicCell<usize>,
7675
pub stdlib_inits: HashMap<String, stdlib::StdlibInitFunc>,
7776
pub frozen: HashMap<String, bytecode::FrozenModule>,
7877
}
@@ -199,10 +198,10 @@ impl VirtualMachine {
199198
profile_func,
200199
trace_func,
201200
use_tracing: Cell::new(false),
201+
recursion_limit: Cell::new(if cfg!(debug_assertions) { 256 } else { 512 }),
202202
signal_handlers: Some(signal_handlers),
203203
state: Arc::new(PyGlobalState {
204204
settings,
205-
recursion_limit: AtomicCell::new(if cfg!(debug_assertions) { 256 } else { 512 }),
206205
stdlib_inits,
207206
frozen,
208207
}),
@@ -310,7 +309,7 @@ impl VirtualMachine {
310309
}
311310

312311
fn check_recursive_call(&self, _where: &str) -> PyResult<()> {
313-
if self.frames.borrow().len() > self.state.recursion_limit.load() {
312+
if self.frames.borrow().len() > self.recursion_limit.get() {
314313
Err(self.new_recursion_error(format!("maximum recursion depth exceeded {}", _where)))
315314
} else {
316315
Ok(())

0 commit comments

Comments
 (0)