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

Function invoke_callbacks

crates/vm/src/stdlib/gc.rs:277–304  ·  view source on GitHub ↗

Helper function to invoke GC callbacks

(
        vm: &VirtualMachine,
        phase: &str,
        generation: usize,
        result: &gc_state::CollectResult,
    )

Source from the content-addressed store, hash-verified

275
276 /// Helper function to invoke GC callbacks
277 fn invoke_callbacks(
278 vm: &VirtualMachine,
279 phase: &str,
280 generation: usize,
281 result: &gc_state::CollectResult,
282 ) {
283 let callbacks_list = &vm.ctx.gc_callbacks;
284 let callbacks: Vec<PyObjectRef> = callbacks_list.borrow_vec().to_vec();
285 if callbacks.is_empty() {
286 return;
287 }
288
289 let phase_str: PyObjectRef = vm.ctx.new_str(phase).into();
290 let info = vm.ctx.new_dict();
291 let _ = info.set_item("generation", vm.ctx.new_int(generation).into(), vm);
292 let _ = info.set_item("collected", vm.ctx.new_int(result.collected).into(), vm);
293 let _ = info.set_item(
294 "uncollectable",
295 vm.ctx.new_int(result.uncollectable).into(),
296 vm,
297 );
298 let _ = info.set_item("candidates", vm.ctx.new_int(result.candidates).into(), vm);
299 let _ = info.set_item("duration", vm.ctx.new_float(result.duration).into(), vm);
300
301 for callback in callbacks {
302 let _ = callback.call((phase_str.clone(), info.clone()), vm);
303 }
304 }
305}

Callers 1

collectFunction · 0.85

Calls 10

to_vecMethod · 0.80
borrow_vecMethod · 0.80
new_dictMethod · 0.80
is_emptyMethod · 0.45
new_strMethod · 0.45
set_itemMethod · 0.45
new_intMethod · 0.45
new_floatMethod · 0.45
callMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected