Skip to content

Commit 3af0cf8

Browse files
committed
Address code review: checked arithmetic, threading feature deps, Send gate
- Use checked arithmetic for nlocalsplus in Frame::new - Add "std" to threading feature dependencies in rustpython-common - Gate GcState Send impl with #[cfg(feature = "threading")]
1 parent ceaa98d commit 3af0cf8

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

crates/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ license.workspace = true
1111
[features]
1212
default = ["std"]
1313
std = []
14-
threading = ["parking_lot"]
14+
threading = ["parking_lot", "std"]
1515
wasm_js = ["getrandom/wasm_js"]
1616

1717
[dependencies]

crates/vm/src/frame.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,10 @@ impl Frame {
672672
.collect();
673673

674674
// Create unified localsplus: varnames + cellvars + freevars + stack
675-
let nlocalsplus = nlocals + num_cells + nfrees;
675+
let nlocalsplus = nlocals
676+
.checked_add(num_cells)
677+
.and_then(|v| v.checked_add(nfrees))
678+
.expect("Frame::new: nlocalsplus overflow");
676679
let max_stackdepth = code.max_stackdepth as usize;
677680
let mut localsplus = if use_datastack {
678681
LocalsPlus::new_on_datastack(nlocalsplus, max_stackdepth, vm)

crates/vm/src/gc_state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ pub struct GcState {
136136

137137
// SAFETY: GcObjectPtr wraps NonNull which is !Send/!Sync, but we only use it as an opaque
138138
// hash key. PyObjectRef is Send. In threading mode, PyRwLock/PyMutex are parking_lot based
139-
// and genuinely Sync. In non-threading mode, gc_state() is thread-local so Sync is not needed.
139+
// and genuinely Sync. In non-threading mode, gc_state() is thread-local so neither Send
140+
// nor Sync is needed.
141+
#[cfg(feature = "threading")]
140142
unsafe impl Send for GcState {}
141143
#[cfg(feature = "threading")]
142144
unsafe impl Sync for GcState {}

0 commit comments

Comments
 (0)