Author: Antonio Cuni <[email protected]>
Branch: gc-disable
Changeset: r95223:69e61e0e2314
Date: 2018-10-19 18:43 +0200
http://bitbucket.org/pypy/pypy/changeset/69e61e0e2314/

Log:    implement the return value for collect_step in the real incminimark

diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py
--- a/rpython/memory/gc/incminimark.py
+++ b/rpython/memory/gc/incminimark.py
@@ -778,14 +778,11 @@
         This is meant to be used together with gc.disable(), to have a
         fine-grained control on when the GC runs.
         """
-        in_progress = self.gc_state != STATE_SCANNING
+        old_state = self.gc_state
         self._minor_collection()
         self.major_collection_step()
         self.rrc_invoke_callback()
-        # if we were in the middle of a collection and we are back to
-        # STATE_SCANNING, it means we have just finished one
-        done = in_progress and self.gc_state == STATE_SCANNING
-        return done
+        return rgc._encode_states(old_state, self.gc_state)
 
     def minor_collection_with_major_progress(self, extrasize=0,
                                              force_enabled=False):
diff --git a/rpython/memory/gc/test/test_direct.py 
b/rpython/memory/gc/test/test_direct.py
--- a/rpython/memory/gc/test/test_direct.py
+++ b/rpython/memory/gc/test/test_direct.py
@@ -823,14 +823,24 @@
         py.test.raises(RuntimeError, 's.x')
 
     def test_collect_step(self, debuglog):
+        from rpython.rlib import rgc
         n = 0
+        states = []
         while True:
             debuglog.reset()
-            done = self.gc.collect_step()
+            val = self.gc.collect_step()
+            states.append((rgc.old_state(val), rgc.new_state(val)))
             summary = debuglog.summary()
             assert summary == {'gc-minor': 1, 'gc-collect-step': 1}
-            if done:
+            if rgc.is_done(val):
                 break
             n += 1
             if n == 100:
                 assert False, 'this looks like an endless loop'
+        #
+        assert states == [
+            (incminimark.STATE_SCANNING, incminimark.STATE_MARKING),
+            (incminimark.STATE_MARKING, incminimark.STATE_SWEEPING),
+            (incminimark.STATE_SWEEPING, incminimark.STATE_FINALIZING),
+            (incminimark.STATE_FINALIZING, incminimark.STATE_SCANNING)
+            ]
diff --git a/rpython/memory/gctransform/framework.py 
b/rpython/memory/gctransform/framework.py
--- a/rpython/memory/gctransform/framework.py
+++ b/rpython/memory/gctransform/framework.py
@@ -310,7 +310,7 @@
         self.collect_ptr = getfn(GCClass.collect.im_func,
             [s_gc, annmodel.SomeInteger()], annmodel.s_None)
         self.collect_step_ptr = getfn(GCClass.collect_step.im_func, [s_gc],
-                                      annmodel.s_Bool)
+                                      annmodel.SomeInteger())
         self.enable_ptr = getfn(GCClass.enable.im_func, [s_gc], 
annmodel.s_None)
         self.disable_ptr = getfn(GCClass.disable.im_func, [s_gc], 
annmodel.s_None)
         self.isenabled_ptr = getfn(GCClass.isenabled.im_func, [s_gc],
diff --git a/rpython/translator/c/test/test_newgc.py 
b/rpython/translator/c/test/test_newgc.py
--- a/rpython/translator/c/test/test_newgc.py
+++ b/rpython/translator/c/test/test_newgc.py
@@ -1866,9 +1866,12 @@
             #
             gc.disable()
             n = 0
+            states = []
             while True:
                 n += 1
-                if rgc.collect_step():
+                val = rgc.collect_step()
+                states.append((rgc.old_state(val), rgc.new_state(val)))
+                if rgc.is_done(val):
                     break
                 if n == 100:
                     print 'Endless loop!'
@@ -1877,6 +1880,17 @@
             if n < 4: # we expect at least 4 steps
                 print 'Too few steps! n =', n
                 assert False
+
+            # check that the state transitions are reasonable
+            first_state, _ = states[0]
+            for i, (old_state, new_state) in enumerate(states):
+                is_last = (i == len(states) - 1)
+                is_valid = False
+                if is_last:
+                    assert old_state != new_state == first_state
+                else:
+                    assert new_state == old_state or new_state == old_state+1
+
             return counter.val
         return f
 
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to