@@ -206,15 +206,13 @@ def test_native_class(self):
206
206
207
207
if GRAALPY_NATIVE :
208
208
get_handle_table_id = __graalpython__ .get_handle_table_id
209
- is_strong_handle_table_ref = __graalpython__ .is_strong_handle_table_ref
209
+ def assert_is_strong (x ): assert __graalpython__ .is_strong_handle_table_ref (x )
210
+ def assert_is_weak (x ): assert not __graalpython__ .is_strong_handle_table_ref (x )
210
211
else :
211
212
# just that the test is compatible with CPython
212
- def get_handle_table_id (object ):
213
- return - 1
214
-
215
-
216
- def is_strong_handle_table_ref (id ):
217
- return False
213
+ def get_handle_table_id (object ): return - 1
214
+ def assert_is_strong (x ): pass
215
+ def assert_is_weak (x ): pass
218
216
219
217
class TestGCRefCycles :
220
218
def _trigger_gc (self ):
@@ -479,12 +477,12 @@ def assert_is_freed(id): pass
479
477
assert_is_alive (ID_OBJ10 )
480
478
assert_is_alive (ID_OBJ11 )
481
479
assert_is_alive (ID_OBJ14 )
482
- assert is_strong_handle_table_ref (htid_l )
483
- assert is_strong_handle_table_ref (htid_l1 )
484
- assert is_strong_handle_table_ref (htid_l2 )
485
- assert is_strong_handle_table_ref (htid_l3 )
486
- assert is_strong_handle_table_ref (htid_l4 )
487
- assert is_strong_handle_table_ref (htid_d0 )
480
+ assert_is_strong (htid_l )
481
+ assert_is_strong (htid_l1 )
482
+ assert_is_strong (htid_l2 )
483
+ assert_is_strong (htid_l3 )
484
+ assert_is_strong (htid_l4 )
485
+ assert_is_strong (htid_d0 )
488
486
489
487
del obj2 , l , obj3
490
488
del obj4 , obj5
@@ -510,12 +508,12 @@ def assert_is_freed(id): pass
510
508
assert_is_alive (ID_OBJ9 )
511
509
assert_is_alive (ID_OBJ10 )
512
510
assert_is_alive (ID_OBJ14 )
513
- assert is_strong_handle_table_ref (htid_l2 )
514
- assert is_strong_handle_table_ref (htid_l3 )
515
- assert not is_strong_handle_table_ref (htid_l )
516
- assert not is_strong_handle_table_ref (htid_l1 )
517
- assert not is_strong_handle_table_ref (htid_l4 )
518
- assert not is_strong_handle_table_ref (htid_d0 )
511
+ assert_is_strong (htid_l2 )
512
+ assert_is_strong (htid_l3 )
513
+ assert_is_weak (htid_l )
514
+ assert_is_weak (htid_l1 )
515
+ assert_is_weak (htid_l4 )
516
+ assert_is_weak (htid_d0 )
519
517
520
518
rescued_obj4 = l1 [0 ]
521
519
del l1
@@ -531,7 +529,7 @@ def assert_is_freed(id): pass
531
529
assert_is_alive (ID_OBJ5 )
532
530
assert_is_alive (ID_OBJ14 )
533
531
assert rescued_obj4 .get_obj ().get_obj ()[0 ] is rescued_obj4
534
- assert is_strong_handle_table_ref (htid_l4 )
532
+ assert_is_strong (htid_l4 )
535
533
536
534
del rescued_obj4
537
535
@@ -551,8 +549,8 @@ def assert_is_freed(id): pass
551
549
552
550
assert_is_alive (ID_OBJ12 )
553
551
assert_is_alive (ID_OBJ13 )
554
- assert is_strong_handle_table_ref (htid_l2 )
555
- assert is_strong_handle_table_ref (htid_l3 )
552
+ assert_is_strong (htid_l2 )
553
+ assert_is_strong (htid_l3 )
556
554
557
555
del obj12 , obj13 , l2 , l3
558
556
@@ -564,8 +562,8 @@ def assert_is_freed(id): pass
564
562
assert_is_freed (ID_OBJ5 )
565
563
assert_is_freed (ID_OBJ12 )
566
564
assert_is_freed (ID_OBJ13 )
567
- assert not is_strong_handle_table_ref (htid_l2 )
568
- assert not is_strong_handle_table_ref (htid_l3 )
565
+ assert_is_weak (htid_l2 )
566
+ assert_is_weak (htid_l3 )
569
567
570
568
571
569
@skipIf (GRAALPY and not GRAALPY_NATIVE , "Python GC only used in native mode" )
@@ -634,24 +632,36 @@ def test_cycle_with_lists(self):
634
632
tp_flags = 'Py_TPFLAGS_DEFAULT' ,
635
633
tp_dealloc = '(destructor)tc_dealloc' ,
636
634
)
635
+ if RELY_ON_GC :
636
+ def assert_is_alive (id ):
637
+ assert not TestCycle .is_freed (id )
638
+ def assert_is_freed (id ):
639
+ assert TestCycle .is_freed (id )
640
+ else :
641
+ def assert_is_alive (id ): pass
642
+ def assert_is_freed (id ): pass
643
+
637
644
l0 , l1 = TestCycle .set_list_item (0 )
645
+ htid_l0 = get_handle_table_id (l0 )
646
+ htid_l1 = get_handle_table_id (l1 )
638
647
639
648
ml0 , ml1 = list (), list ()
640
649
ml0 .append (ml1 )
641
650
ml0 .append (TestCycle (1 ))
642
651
ml1 .append (ml0 )
643
652
644
- assert not TestCycle .is_freed (0 )
645
- assert not TestCycle .is_freed (1 )
646
- assert l0 [0 ] == l1
647
- assert l1 [0 ] == l0
648
- assert ml0 [0 ] == ml1
649
- assert ml1 [0 ] == ml0
653
+ assert_is_alive (0 )
654
+ assert_is_alive (1 )
655
+ assert_is_strong (htid_l0 )
656
+ assert_is_strong (htid_l1 )
657
+ assert l0 [0 ] is l1
658
+ assert l1 [0 ] is l0
659
+ assert ml0 [0 ] is ml1
660
+ assert ml1 [0 ] is ml0
650
661
651
- del l0
652
- del l1
653
- del ml0
654
- del ml1
662
+ del l0 , l1 , ml0 , ml1
655
663
self ._trigger_gc ()
656
- assert TestCycle .is_freed (0 )
657
- assert TestCycle .is_freed (1 )
664
+ assert_is_freed (0 )
665
+ assert_is_freed (1 )
666
+ assert_is_weak (htid_l0 )
667
+ assert_is_weak (htid_l1 )
0 commit comments