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

Method get_objects

crates/vm/src/gc_state.rs:330–353  ·  view source on GitHub ↗

Get tracked objects (for gc.get_objects) If generation is None, returns all tracked objects. If generation is Some(n), returns objects in generation n only.

(&self, generation: Option<i32>)

Source from the content-addressed store, hash-verified

328 /// If generation is None, returns all tracked objects.
329 /// If generation is Some(n), returns objects in generation n only.
330 pub fn get_objects(&self, generation: Option<i32>) -> Vec<PyObjectRef> {
331 fn collect_from_list(
332 list: &LinkedList<GcLink, PyObject>,
333 ) -> impl Iterator<Item = PyObjectRef> + '_ {
334 list.iter().filter_map(|obj| obj.try_to_owned())
335 }
336
337 match generation {
338 None => {
339 // Return all tracked objects from all generations + permanent
340 let mut result = Vec::new();
341 for gen_list in &self.generation_lists {
342 result.extend(collect_from_list(&gen_list.read()));
343 }
344 result.extend(collect_from_list(&self.permanent_list.read()));
345 result
346 }
347 Some(g) if (0..=2).contains(&g) => {
348 let guard = self.generation_lists[g as usize].read();
349 collect_from_list(&guard).collect()
350 }
351 _ => Vec::new(),
352 }
353 }
354
355 /// Check if automatic GC should run and run it if needed.
356 /// Called after object allocation.

Callers 10

test_get_objectsMethod · 0.80
__del__Method · 0.80
test_slotsMethod · 0.80
test_issue_7959Method · 0.80
__reduce__Method · 0.80
get_objectsFunction · 0.80
get_referrersFunction · 0.80

Calls 5

newFunction · 0.85
collectMethod · 0.80
extendMethod · 0.45
readMethod · 0.45
containsMethod · 0.45

Tested by 7

test_get_objectsMethod · 0.64
__del__Method · 0.64
test_slotsMethod · 0.64
test_issue_7959Method · 0.64