# HG changeset patch # User Atul Varma # Date 1251073262 25200 # Node ID 4179d1e1a75c0ca11b7942ca9b752677142fe7d8 # Parent 8371983fee63bb6570f911f1a9e741a7410ffea9 Added a test for context cyclic gc support and fixed a bug revealed by it. diff -r 8371983fee63 -r 4179d1e1a75c src/context.cpp --- a/src/context.cpp Sun Aug 23 17:07:45 2009 -0700 +++ b/src/context.cpp Sun Aug 23 17:21:02 2009 -0700 @@ -570,5 +570,6 @@ JS_SetGCZeal(cx, 2); #endif + PyObject_GC_Track((PyObject *) context); return context; } diff -r 8371983fee63 -r 4179d1e1a75c tests/test_pymonkey.py --- a/tests/test_pymonkey.py Sun Aug 23 17:07:45 2009 -0700 +++ b/tests/test_pymonkey.py Sun Aug 23 17:21:02 2009 -0700 @@ -1,3 +1,4 @@ +import gc import sys import unittest import weakref @@ -72,6 +73,26 @@ del cx self.assertEqual(pyobj(), None) + def testContextSupportsCyclicGc(self): + def makecx(): + cx = pymonkey.Runtime().new_context() + + def opcb(othercx): + return cx + + cx.set_operation_callback(opcb) + return cx + + gc.disable() + cx = makecx() + wcx = weakref.ref(cx) + self.assertEqual(wcx(), cx) + del cx + self.assertTrue(wcx()) + gc.enable() + gc.collect() + self.assertEqual(wcx(), None) + def testOperationCallbackIsCalled(self): def opcb(cx): raise Exception("stop eet!")