]> granicus.if.org Git - python/commitdiff
SF bug #762455: Python segfaults when sys.stdout is changed in getattr
authorRaymond Hettinger <python@rcn.com>
Sun, 29 Jun 2003 15:44:07 +0000 (15:44 +0000)
committerRaymond Hettinger <python@rcn.com>
Sun, 29 Jun 2003 15:44:07 +0000 (15:44 +0000)
* Added unittest that fails before, but not after Neil's fix to ceval.c.

Lib/test/test_descr.py

index 46e3c4837a43e18e1f2455e7f9ac84215d25f976..cb13ff2e065a926a8d24a11a9d796124bd9e7564 100644 (file)
@@ -3916,6 +3916,20 @@ def weakref_segfault():
     o.whatever = Provoker(o)
     del o
 
+# Fix SF #762455, segfault when sys.stdout is changed in getattr
+def filefault():
+    if verbose:
+        print "Testing sys.stdout is changed in getattr..."
+    import sys
+    class StdoutGuard:
+        def __getattr__(self, attr):
+            sys.stdout = sys.__stdout__
+            raise RuntimeError("Premature access to sys.stdout.%s" % attr)
+    sys.stdout = StdoutGuard()
+    try:
+        print "Oops!"
+    except RuntimeError:
+        pass
 
 def test_main():
     weakref_segfault() # Must be first, somehow
@@ -4007,6 +4021,7 @@ def test_main():
     isinst_isclass()
     proxysuper()
     carloverre()
+    filefault()
 
     if verbose: print "All OK"