Call __del__ if present, without triggering object deallocation. Used by GC to call finalizers before breaking cycles. This allows proper resurrection detection. PyObject_CallFinalizerFromDealloc
(&self)
| 1694 | /// This allows proper resurrection detection. |
| 1695 | /// PyObject_CallFinalizerFromDealloc |
| 1696 | pub fn try_call_finalizer(&self) { |
| 1697 | let del = self.class().slots.del.load(); |
| 1698 | if let Some(slot_del) = del |
| 1699 | && !self.gc_finalized() |
| 1700 | { |
| 1701 | // Mark as finalized BEFORE calling __del__ to prevent double-call |
| 1702 | // This ensures drop_slow_inner() won't call __del__ again |
| 1703 | self.set_gc_finalized(); |
| 1704 | let result = crate::vm::thread::with_vm(self, |vm| { |
| 1705 | if let Err(e) = slot_del(self, vm) |
| 1706 | && let Some(del_method) = self.get_class_attr(identifier!(vm, __del__)) |
| 1707 | { |
| 1708 | vm.run_unraisable(e, None, del_method); |
| 1709 | } |
| 1710 | }); |
| 1711 | let _ = result; |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | /// Clear weakrefs but collect callbacks instead of calling them. |
| 1716 | /// This is used by GC to ensure ALL weakrefs are cleared BEFORE any callbacks run. |
no test coverage detected