@@ -518,7 +518,6 @@ def assert_is_freed(id): pass
518
518
rescued_obj4 = l1 [0 ]
519
519
del l1
520
520
521
- __graalpython__ .tdebug ("uff" )
522
521
TestCycle0 .set_global_obj (2 , obj14 )
523
522
del obj14
524
523
####################################### GC #######################################
@@ -665,3 +664,236 @@ def assert_is_freed(id): pass
665
664
assert_is_freed (1 )
666
665
assert_is_weak (htid_l0 )
667
666
assert_is_weak (htid_l1 )
667
+
668
+ def test_module_globals (self ):
669
+ self ._trigger_gc ()
670
+ GCTestModuleGlobal = CPyExtType ("GCTestModuleGlobal" ,
671
+ '''
672
+ struct struct_GC_Test_C
673
+ {
674
+ PyObject_HEAD
675
+ PyObject *_test_list_c;
676
+ };
677
+
678
+ struct struct_GC_Test_B
679
+ {
680
+ struct struct_GC_Test_C base;
681
+ };
682
+
683
+ struct struct_GC_Test_A
684
+ {
685
+ PyObject_HEAD
686
+ struct struct_GC_Test_B *_test_b;
687
+ };
688
+
689
+ struct struct_GC_Test_G
690
+ {
691
+ PyObject_HEAD
692
+ struct struct_GC_Test_A *_test_a;
693
+ };
694
+
695
+ static struct struct_GC_Test_G *__GC_Test_Global__ = 0;
696
+ static PyTypeObject *pytype_GC_Test_G = 0;
697
+ static PyTypeObject *pytype_GC_Test_A = 0;
698
+ static PyTypeObject *pytype_GC_Test_B = 0;
699
+ static PyTypeObject *pytype_GC_Test_C = 0;
700
+
701
+ static PyObject *tp_new_GC_Test_G(PyTypeObject *t, PyObject *a, PyObject *k) {
702
+ struct struct_GC_Test_G *p;
703
+ PyObject *o = (*t->tp_alloc)(t, 0);
704
+ p = ((struct struct_GC_Test_G *)o);
705
+ p->_test_a = ((struct struct_GC_Test_A *)Py_None);
706
+ Py_INCREF(Py_None);
707
+ return o;
708
+ }
709
+
710
+ static int tp_traverse_GC_Test_G(PyObject *o, visitproc v, void *a) {
711
+ struct struct_GC_Test_G *p = (struct struct_GC_Test_G *)o;
712
+ if (p->_test_a)
713
+ return (*v)(((PyObject *)p->_test_a), a);
714
+ return 0;
715
+ }
716
+
717
+ static PyObject *tp_new_GC_Test_A(PyTypeObject *t, PyObject *a, PyObject *k) {
718
+ PyObject *o = (*t->tp_alloc)(t, 0);
719
+ PyObject *t1 = PyObject_CallNoArgs(((PyObject *)pytype_GC_Test_B));
720
+ ((struct struct_GC_Test_A *)o)->_test_b = ((struct struct_GC_Test_B *)t1);
721
+ return o;
722
+ }
723
+
724
+ static int tp_traverse_GC_Test_A(PyObject *o, visitproc v, void *a) {
725
+ struct struct_GC_Test_A *p = (struct struct_GC_Test_A *)o;
726
+ if (p->_test_b)
727
+ return (*v)(((PyObject *)p->_test_b), a);
728
+ return 0;
729
+ }
730
+
731
+ static PyObject *tp_new_GC_Test_C(PyTypeObject *t, PyObject *a, PyObject *k) {
732
+ struct struct_GC_Test_C *p;
733
+ PyObject *o = (*t->tp_alloc)(t, 0);
734
+ p = ((struct struct_GC_Test_C *)o);
735
+ p->_test_list_c = ((PyObject *)Py_None);
736
+ Py_INCREF(Py_None);
737
+ return o;
738
+ }
739
+
740
+ static int tp_traverse_GC_Test_C(PyObject *o, visitproc v, void *a) {
741
+ struct struct_GC_Test_C *p = (struct struct_GC_Test_C *)o;
742
+ if (p->_test_list_c)
743
+ return (*v)(p->_test_list_c, a);
744
+ return 0;
745
+ }
746
+
747
+ static PyObject *tp_new_GC_Test_B(PyTypeObject *t, PyObject *a, PyObject *k) {
748
+ struct struct_GC_Test_B *p;
749
+ PyObject *o = tp_new_GC_Test_C(t, a, k);
750
+ p = ((struct struct_GC_Test_B *)o);
751
+ return o;
752
+ }
753
+
754
+ static struct struct_GC_Test_A *GC_Test_G_getGCTestA(struct struct_GC_Test_G *self) {
755
+ PyObject *t3 = NULL;
756
+ if (((PyObject *)self->_test_a) == Py_None)
757
+ {
758
+ t3 = PyObject_CallNoArgs(((PyObject *)pytype_GC_Test_A));
759
+ Py_DECREF(((PyObject *)self->_test_a));
760
+ self->_test_a = ((struct struct_GC_Test_A *)t3);
761
+ }
762
+
763
+ Py_INCREF(((PyObject *)self->_test_a));
764
+ return self->_test_a;
765
+ }
766
+
767
+ static PyObject *GC_Test_B_clear(struct struct_GC_Test_B *self) {
768
+ PyObject *py_slice = PySlice_New(Py_None, Py_None, Py_None);
769
+ PyObject_DelItem(self->base._test_list_c, py_slice);
770
+ Py_INCREF(Py_None);
771
+ return Py_None;
772
+ }
773
+
774
+ static int GC_Test_A_prepare(struct struct_GC_Test_A *self) {
775
+ PyObject *t1 = GC_Test_B_clear(self->_test_b);
776
+ Py_DECREF(t1);
777
+ return 0;
778
+ }
779
+
780
+ static int GC_Test_A_cleanup(struct struct_GC_Test_A *self) {
781
+ PyObject *t1 = GC_Test_B_clear(self->_test_b);
782
+ Py_DECREF(t1);
783
+ return 0;
784
+ }
785
+
786
+ static int GC_Test_C__init__(PyObject *self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
787
+ PyObject *list_c = PyTuple_GET_ITEM(__pyx_args, 0);
788
+ Py_INCREF(list_c);
789
+ Py_DECREF(((struct struct_GC_Test_C *)self)->_test_list_c);
790
+ printf("list_c: %p\\ n", list_c);
791
+ ((struct struct_GC_Test_C *)self)->_test_list_c = list_c;
792
+ return 0;
793
+ }
794
+
795
+ static int GC_Test_B__init__(PyObject *self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
796
+ PyObject *t1 = NULL;
797
+ PyObject *t2 = PyObject_GetAttrString((PyObject *)pytype_GC_Test_C, "__init__");
798
+ PyObject *t3 = PyList_New(0);
799
+ PyObject *t6 = PyTuple_New(2);
800
+ Py_INCREF(self);
801
+ PyTuple_SET_ITEM(t6, 0, self);
802
+ PyTuple_SET_ITEM(t6, 1, t3);
803
+ t1 = PyObject_Call(t2, t6, NULL);
804
+ Py_DECREF(t6);
805
+ Py_DECREF(t2);
806
+ Py_DECREF(t1);
807
+ return 0;
808
+ }
809
+
810
+
811
+ static PyObject *GC_Test_Global(PyObject *self, PyObject *unused) {
812
+ struct struct_GC_Test_A *__pyx_v_A = 0;
813
+ __pyx_v_A = GC_Test_G_getGCTestA(__GC_Test_Global__);
814
+ GC_Test_A_prepare(__pyx_v_A);
815
+ GC_Test_A_cleanup(__pyx_v_A);
816
+ Py_INCREF(Py_None);
817
+ Py_XDECREF((PyObject *)__pyx_v_A);
818
+ return Py_None;
819
+ }
820
+
821
+ PyTypeObject spec_GC_Test_C = {
822
+ PyVarObject_HEAD_INIT(NULL, 0)
823
+ .tp_name = "GC_Test_C",
824
+ .tp_basicsize = sizeof(struct struct_GC_Test_C),
825
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
826
+ .tp_traverse = tp_traverse_GC_Test_C,
827
+ .tp_init = GC_Test_C__init__,
828
+ .tp_new = tp_new_GC_Test_C,
829
+ };
830
+
831
+ PyTypeObject spec_GC_Test_B = {
832
+ PyVarObject_HEAD_INIT(NULL, 0)
833
+ .tp_name = "GC_Test_B",
834
+ .tp_basicsize = sizeof(struct struct_GC_Test_B),
835
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
836
+ .tp_traverse = tp_traverse_GC_Test_C,
837
+ .tp_init = GC_Test_B__init__,
838
+ .tp_new = tp_new_GC_Test_B,
839
+ .tp_base = &spec_GC_Test_C,
840
+ };
841
+
842
+ PyTypeObject spec_GC_Test_A = {
843
+ PyVarObject_HEAD_INIT(NULL, 0)
844
+ .tp_name = "GC_Test_A",
845
+ .tp_basicsize = sizeof(struct struct_GC_Test_A),
846
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
847
+ .tp_traverse = tp_traverse_GC_Test_A,
848
+ .tp_new = tp_new_GC_Test_A,
849
+ };
850
+
851
+ PyTypeObject spec_GC_Test_G = {
852
+ PyVarObject_HEAD_INIT(NULL, 0)
853
+ .tp_name = "GC_Test_G",
854
+ .tp_basicsize = sizeof(struct struct_GC_Test_G),
855
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
856
+ .tp_traverse = tp_traverse_GC_Test_G,
857
+ .tp_new = tp_new_GC_Test_G,
858
+ };
859
+
860
+ ''' ,
861
+ tp_methods = '''{"GC_Test_Global", (PyCFunction)GC_Test_Global, METH_NOARGS | METH_CLASS, ""}''' ,
862
+ ready_code = '''
863
+
864
+ if (PyType_Ready(&spec_GC_Test_G) < 0)
865
+ return NULL;
866
+ pytype_GC_Test_G = &spec_GC_Test_G;
867
+
868
+ if (PyType_Ready(&spec_GC_Test_A) < 0)
869
+ return NULL;
870
+ pytype_GC_Test_A = &spec_GC_Test_A;
871
+
872
+ if (PyType_Ready(&spec_GC_Test_C) < 0)
873
+ return NULL;
874
+ pytype_GC_Test_C = &spec_GC_Test_C;
875
+
876
+ if (PyType_Ready(&spec_GC_Test_B) < 0)
877
+ return NULL;
878
+ pytype_GC_Test_B = &spec_GC_Test_B;
879
+
880
+ __GC_Test_Global__ = (struct struct_GC_Test_G *)PyObject_CallNoArgs(((PyObject *)pytype_GC_Test_G));
881
+ ''' ,
882
+ )
883
+
884
+ GCTestModuleGlobal .GC_Test_Global ()
885
+ ####################################### GC #######################################
886
+ self ._trigger_gc ()
887
+ ##################################################################################
888
+ GCTestModuleGlobal .GC_Test_Global ()
889
+ ####################################### GC #######################################
890
+ self ._trigger_gc ()
891
+ ##################################################################################
892
+ GCTestModuleGlobal .GC_Test_Global ()
893
+ ####################################### GC #######################################
894
+ self ._trigger_gc ()
895
+ ##################################################################################
896
+ GCTestModuleGlobal .GC_Test_Global ()
897
+ ####################################### GC #######################################
898
+ self ._trigger_gc ()
899
+ ##################################################################################
0 commit comments