| 104 | /// false if the object was deferred (depth exceeded). |
| 105 | #[inline] |
| 106 | pub(super) unsafe fn begin( |
| 107 | obj: *mut super::PyObject, |
| 108 | dealloc: unsafe fn(*mut super::PyObject), |
| 109 | ) -> bool { |
| 110 | DEALLOC_DEPTH.with(|d| { |
| 111 | let depth = d.get(); |
| 112 | if depth >= TRASHCAN_LIMIT { |
| 113 | // Depth exceeded: defer this deallocation |
| 114 | DEALLOC_QUEUE.with(|q| { |
| 115 | let mut queue = q.take(); |
| 116 | queue.push((obj, dealloc)); |
| 117 | q.set(queue); |
| 118 | }); |
| 119 | false |
| 120 | } else { |
| 121 | d.set(depth + 1); |
| 122 | true |
| 123 | } |
| 124 | }) |
| 125 | } |
| 126 | |
| 127 | /// End deallocation and process any deferred objects if at outermost level. |
| 128 | #[inline] |