Mercurial > pymonkey
changeset 127:4179d1e1a75c
Added a test for context cyclic gc support and fixed a bug revealed by it.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Sun, 23 Aug 2009 17:21:02 -0700 |
parents | 8371983fee63 |
children | 1e4d4d475e75 |
files | src/context.cpp tests/test_pymonkey.py |
diffstat | 2 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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; }
--- 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!")