From 72339e5bf9349bd87af80bee256789c2301aec9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Niederb=C3=BChl?= Date: Sun, 14 Jul 2019 15:44:37 +0200 Subject: [PATCH] Implement PyGCProtocol in test class For the garbage collection to work the PyGCProtocol has to be implemented. Ideally it should not even get compiled if it doesn't since a missing tp_traverse can produce a segfault. --- tests/test_gc.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_gc.rs b/tests/test_gc.rs index b175c334..c6e6f6b5 100644 --- a/tests/test_gc.rs +++ b/tests/test_gc.rs @@ -180,15 +180,19 @@ fn gc_integration() { #[pyclass(gc)] struct GCIntegration2 {} +#[pyproto] +impl PyGCProtocol for GCIntegration2 { + fn __traverse__(&self, _visit: PyVisit) -> Result<(), PyTraverseError> { + Ok(()) + } +} + #[test] fn gc_integration2() { let gil = Python::acquire_gil(); let py = gil.python(); - // Temporarily disable pythons garbage collector to avoid a race condition - py.run("import gc; gc.disable()", None, None).unwrap(); let inst = PyRef::new(py, GCIntegration2 {}).unwrap(); - py_run!(py, inst, "assert inst in gc.get_objects()"); - py.run("gc.enable()", None, None).unwrap(); + py_run!(py, inst, "import gc; assert inst in gc.get_objects()"); } #[pyclass(weakref)]