MCPcopy Index your code
hub / github.com/RustPython/RustPython / normalize_event_set

Function normalize_event_set

crates/vm/src/stdlib/sys/monitoring.rs:196–227  ·  view source on GitHub ↗
(event_set: i32, local: bool, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

194}
195
196fn normalize_event_set(event_set: i32, local: bool, vm: &VirtualMachine) -> PyResult<u32> {
197 let kind = if local {
198 "local event set"
199 } else {
200 "event set"
201 };
202 if event_set < 0 {
203 return Err(vm.new_value_error(format!("invalid {kind} 0x{event_set:x}")));
204 }
205
206 let mut event_set = event_set as u32;
207 if event_set >= (1 << EVENTS_COUNT) {
208 return Err(vm.new_value_error(format!("invalid {kind} 0x{event_set:x}")));
209 }
210
211 if (event_set & EVENT_C_RETURN_MASK) != 0 && (event_set & EVENT_CALL) != EVENT_CALL {
212 return Err(vm.new_value_error("cannot set C_RETURN or C_RAISE events independently"));
213 }
214
215 event_set &= !EVENT_C_RETURN_MASK;
216
217 if (event_set & EVENT_BRANCH) != 0 {
218 event_set &= !EVENT_BRANCH;
219 event_set |= EVENT_BRANCH_LEFT | EVENT_BRANCH_RIGHT;
220 }
221
222 if local && event_set >= (1 << LOCAL_EVENTS_COUNT) {
223 return Err(vm.new_value_error(format!("invalid local event set 0x{event_set:x}")));
224 }
225
226 Ok(event_set)
227}
228
229/// Rewrite a code object's bytecode in-place with layered instrumentation.
230///

Callers 2

set_eventsFunction · 0.85
set_local_eventsFunction · 0.85

Calls 1

ErrClass · 0.50

Tested by

no test coverage detected