[Jython-checkins] jython: Fixed issue 2337.

stefan.richthofer jython-checkins at python.org
Mon May 11 14:45:08 CEST 2015


https://hg.python.org/jython/rev/376c6130d9e8
changeset:   7705:376c6130d9e8
user:        Stefan Richthofer <stefan.richthofer at gmx.de>
date:        Mon May 11 14:44:59 2015 +0200
summary:
  Fixed issue 2337.

files:
  Lib/test/test_gc_jy.py                           |  13 +++
  src/org/python/modules/_collections/PyDeque.java |  39 ++++++---
  2 files changed, 37 insertions(+), 15 deletions(-)


diff --git a/Lib/test/test_gc_jy.py b/Lib/test/test_gc_jy.py
--- a/Lib/test/test_gc_jy.py
+++ b/Lib/test/test_gc_jy.py
@@ -11,6 +11,8 @@
 import time
 import gc
 import weakref
+from Queue import Queue
+
 try:
     from java.lang import System, Runnable
     from javatests import GCTestHelper
@@ -744,6 +746,17 @@
         del prt
         self.assertEqual(gc.collect(), 0)
 
+class GCTests_Misc(unittest.TestCase):
+
+    #Test for issue 2337
+    def test_queue(self):
+        class X(object):
+            def __init__(self, q):
+                self.q = q
+        x = X(Queue())
+        gc.monitorObject(x)
+        gc.collect()
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/src/org/python/modules/_collections/PyDeque.java b/src/org/python/modules/_collections/PyDeque.java
--- a/src/org/python/modules/_collections/PyDeque.java
+++ b/src/org/python/modules/_collections/PyDeque.java
@@ -685,7 +685,13 @@
             if (retVal != 0) {
                 return retVal;
             }
-            return lastReturned == null ? 0 : traverseNode(lastReturned, visit, arg);
+            /* On first thought one would traverse the circular list
+             * starting with lastReturned. However due to synchronization
+             * it is guaranteed that this would traverse the same objects
+             * as starting with header would do. So we can simply call the
+             * traverse-method of PyDeque.this.
+             */
+            return PyDeque.this.traverse(visit, arg);
         }
 
         @Override
@@ -702,26 +708,29 @@
 
 
     /* Traverseproc implementation */
-    private static int traverseNode(Node node, Visitproc visit, Object arg) {
-        int retVal;
-        if (node.data != null) {
-            retVal = visit.visit(node.data, arg);
+    @Override
+    public synchronized int traverse(Visitproc visit, Object arg) {
+    	if (header == null) {
+            return 0;
+        }
+        int retVal = 0;
+        if (header.data != null) {
+            retVal = visit.visit(header.data, arg);
             if (retVal != 0) {
                 return retVal;
             }
         }
-        if (node.left != null) {
-            retVal = traverseNode(node.left, visit, arg);
-            if (retVal != 0) {
-                return retVal;
+        Node tmp = header.right;
+        while (tmp != header) {
+            if (tmp.data != null) {
+                retVal = visit.visit(tmp.data, arg);
+                if (retVal != 0) {
+                    return retVal;
+                }
             }
+            tmp = tmp.right;
         }
-        return node.right == null ? 0 : traverseNode(node.right, visit, arg);
-    }
-
-    @Override
-    public int traverse(Visitproc visit, Object arg) {
-        return header == null ? 0 : traverseNode(header, visit, arg);
+        return retVal;
     }
 
     @Override

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list