Add obj to the weak set
(
set_lock: &PyRwLock<Option<PyRef<PySet>>>,
obj: &PyObject,
vm: &VirtualMachine,
)
| 113 | |
| 114 | /// Add obj to the weak set |
| 115 | fn add_to_weak_set( |
| 116 | set_lock: &PyRwLock<Option<PyRef<PySet>>>, |
| 117 | obj: &PyObject, |
| 118 | vm: &VirtualMachine, |
| 119 | ) -> PyResult<()> { |
| 120 | let mut set_opt = set_lock.write(); |
| 121 | let set = match &*set_opt { |
| 122 | Some(s) => s.clone(), |
| 123 | None => { |
| 124 | let new_set = PySet::default().into_ref(&vm.ctx); |
| 125 | *set_opt = Some(new_set.clone()); |
| 126 | new_set |
| 127 | } |
| 128 | }; |
| 129 | drop(set_opt); |
| 130 | |
| 131 | // Create a weak reference to the object |
| 132 | let weak_ref = obj.downgrade(None, vm)?; |
| 133 | set.add(weak_ref.into(), vm)?; |
| 134 | Ok(()) |
| 135 | } |
| 136 | |
| 137 | /// Returns the current ABC cache token. |
| 138 | #[pyfunction] |
no test coverage detected