[Python-3000-checkins] r66827 - in python/branches/py3k: Lib/test/test_cprofile.py Modules/_lsprof.c

benjamin.peterson python-3000-checkins at python.org
Tue Oct 7 04:33:00 CEST 2008


Author: benjamin.peterson
Date: Tue Oct  7 04:32:59 2008
New Revision: 66827

Log:
Merged revisions 66677,66700 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r66677 | brett.cannon | 2008-09-28 22:41:21 -0500 (Sun, 28 Sep 2008) | 7 lines
  
  The _lsprof module could crash the interpreter if it was given an external
  timer that did not return a float and a timer was still running when the
  Profiler object was garbage collected.
  
  Fixes issue 3895.
  Code review by Benjamin Peterson.
........
  r66700 | brett.cannon | 2008-09-30 12:46:03 -0500 (Tue, 30 Sep 2008) | 5 lines
  
  Fix a refleak introduced by r66677.
  
  Fix suggested by Amaury Forgeot d'Arc.
  Closes issue #4003.
........


Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/test/test_cprofile.py
   python/branches/py3k/Modules/_lsprof.c

Modified: python/branches/py3k/Lib/test/test_cprofile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_cprofile.py	(original)
+++ python/branches/py3k/Lib/test/test_cprofile.py	Tue Oct  7 04:32:59 2008
@@ -1,7 +1,7 @@
 """Test suite for the cProfile module."""
 
 import sys
-from test.support import run_unittest
+from test.support import run_unittest, TESTFN, unlink
 
 # rip off all interesting stuff from test_profile
 import cProfile
@@ -13,6 +13,20 @@
     def get_expected_output(self):
         return _ProfileOutput
 
+    # Issue 3895.
+    def test_bad_counter_during_dealloc(self):
+        import _lsprof
+        # Must use a file as StringIO doesn't trigger the bug.
+        sys.stderr = open(TESTFN, 'w')
+        try:
+            obj = _lsprof.Profiler(lambda: int)
+            obj.enable()
+            obj = _lsprof.Profiler(1)
+            obj.disable()
+        finally:
+            sys.stderr = sys.__stderr__
+            unlink(TESTFN)
+
 
 def test_main():
     run_unittest(CProfileTest)

Modified: python/branches/py3k/Modules/_lsprof.c
==============================================================================
--- python/branches/py3k/Modules/_lsprof.c	(original)
+++ python/branches/py3k/Modules/_lsprof.c	Tue Oct  7 04:32:59 2008
@@ -150,7 +150,7 @@
 	}
 	Py_DECREF(o);
 	if (PyErr_Occurred()) {
-		PyErr_WriteUnraisable((PyObject *) pObj);
+		PyErr_WriteUnraisable(pObj->externalTimer);
 		return 0;
 	}
 	return result;


More information about the Python-3000-checkins mailing list