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

Method _trace_event_inner

crates/vm/src/protocol/callable.rs:211–273  ·  view source on GitHub ↗
(
        &self,
        event: TraceEvent,
        arg: Option<PyObjectRef>,
    )

Source from the content-addressed store, hash-verified

209 }
210 }
211 fn _trace_event_inner(
212 &self,
213 event: TraceEvent,
214 arg: Option<PyObjectRef>,
215 ) -> PyResult<Option<PyObjectRef>> {
216 let trace_func = self.trace_func.borrow().to_owned();
217 let profile_func = self.profile_func.borrow().to_owned();
218 if self.is_none(&trace_func) && self.is_none(&profile_func) {
219 return Ok(None);
220 }
221
222 let is_trace_event = event.is_trace_event();
223 let is_profile_event = event.is_profile_event();
224 let is_opcode_event = event.is_opcode_event();
225
226 let Some(frame_ref) = self.current_frame() else {
227 return Ok(None);
228 };
229
230 // Opcode events are only dispatched when f_trace_opcodes is set.
231 if is_opcode_event && !*frame_ref.trace_opcodes.lock() {
232 return Ok(None);
233 }
234
235 let frame: PyObjectRef = frame_ref.into();
236 let event = self.ctx.new_str(event.to_string()).into();
237 let args = vec![frame, event, arg.unwrap_or_else(|| self.ctx.none())];
238
239 let mut trace_result = None;
240
241 // temporarily disable tracing, during the call to the
242 // tracing function itself.
243 if is_trace_event && !self.is_none(&trace_func) {
244 self.use_tracing.set(false);
245 let res = trace_func.call(args.clone(), self);
246 self.use_tracing.set(true);
247 match res {
248 Ok(result) => {
249 if !self.is_none(&result) {
250 trace_result = Some(result);
251 }
252 }
253 Err(e) => {
254 // trace_trampoline behavior: clear per-frame f_trace
255 // and propagate the error.
256 if let Some(frame_ref) = self.current_frame() {
257 *frame_ref.trace.lock() = self.ctx.none();
258 }
259 return Err(e);
260 }
261 }
262 }
263
264 if is_profile_event && !self.is_none(&profile_func) {
265 self.use_tracing.set(false);
266 let res = profile_func.call(args, self);
267 self.use_tracing.set(true);
268 if res.is_err() {

Callers 1

trace_eventMethod · 0.80

Calls 15

is_trace_eventMethod · 0.80
is_profile_eventMethod · 0.80
is_opcode_eventMethod · 0.80
current_frameMethod · 0.80
to_stringMethod · 0.80
noneMethod · 0.80
is_errMethod · 0.80
borrow_mutMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
to_ownedMethod · 0.45
borrowMethod · 0.45

Tested by

no test coverage detected