[Python-checkins] python/dist/src/Lib/test test_isinstance.py, 1.7, 1.7.8.1

bcannon at users.sourceforge.net bcannon at users.sourceforge.net
Sat Mar 20 16:54:38 EST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5214/Lib/test

Modified Files:
      Tag: release23-maint
	test_isinstance.py 
Log Message:
Raise RuntimeError if the second argument to isinstance() or issubclass()
is a tuple nested to a depth beyond the interpreter's recursion limit to
prevent a segfault from blowing the C stack.
Fixes bug #858016 .


Index: test_isinstance.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_isinstance.py,v
retrieving revision 1.7
retrieving revision 1.7.8.1
diff -C2 -d -r1.7 -r1.7.8.1
*** test_isinstance.py	1 May 2003 17:45:37 -0000	1.7
--- test_isinstance.py	20 Mar 2004 21:54:35 -0000	1.7.8.1
***************
*** 5,8 ****
--- 5,9 ----
  import unittest
  from test import test_support
+ import sys
  
  
***************
*** 245,248 ****
--- 246,267 ----
          self.assertEqual(True, issubclass(str, (unicode, (Child, NewChild, basestring))))
  
+     def test_subclass_recursion_limit(self):
+         # make sure that issubclass raises RuntimeError before the C stack is
+         # blown
+         self.assertRaises(RuntimeError, blowstack, issubclass, str, str)
+ 
+     def test_isinstance_recursion_limit(self):
+         # make sure that issubclass raises RuntimeError before the C stack is
+         # blown
+         self.assertRaises(RuntimeError, blowstack, isinstance, '', str)
+ 
+ def blowstack(fxn, arg, compare_to):
+     # Make sure that calling isinstance with a deeply nested tuple for its
+     # argument will raise RuntimeError eventually.
+     tuple_arg = (compare_to,)
+     for cnt in xrange(sys.getrecursionlimit()+5):
+         tuple_arg = (tuple_arg,)
+         fxn(arg, tuple_arg)
+ 
  
  




More information about the Python-checkins mailing list