| 174 | |
| 175 | @pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") |
| 176 | def test_shared_ptr_and_references(): |
| 177 | s = m.SharedPtrRef() |
| 178 | stats = ConstructorStats.get(m.A) |
| 179 | assert stats.alive() == 2 |
| 180 | |
| 181 | ref = s.ref # init_holder_helper(holder_ptr=false, owned=false) |
| 182 | assert stats.alive() == 2 |
| 183 | assert s.set_ref(ref) |
| 184 | with pytest.raises(RuntimeError) as excinfo: |
| 185 | assert s.set_holder(ref) |
| 186 | assert "Unable to cast from non-held to held instance" in str(excinfo.value) |
| 187 | |
| 188 | copy = s.copy # init_holder_helper(holder_ptr=false, owned=true) |
| 189 | assert stats.alive() == 3 |
| 190 | assert s.set_ref(copy) |
| 191 | assert s.set_holder(copy) |
| 192 | |
| 193 | holder_ref = s.holder_ref # init_holder_helper(holder_ptr=true, owned=false) |
| 194 | assert stats.alive() == 3 |
| 195 | assert s.set_ref(holder_ref) |
| 196 | assert s.set_holder(holder_ref) |
| 197 | |
| 198 | holder_copy = s.holder_copy # init_holder_helper(holder_ptr=true, owned=true) |
| 199 | assert stats.alive() == 3 |
| 200 | assert s.set_ref(holder_copy) |
| 201 | assert s.set_holder(holder_copy) |
| 202 | |
| 203 | del ref, copy, holder_ref, holder_copy, s |
| 204 | assert stats.alive() == 0 |
| 205 | |
| 206 | |
| 207 | @pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") |