[pypy-commit] pypy default: Fix: this logic can result in an external call whose stderr is completely

arigo pypy.commits at gmail.com
Sun Apr 10 08:32:40 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r83596:418eb4be7f64
Date: 2016-04-10 15:32 +0300
http://bitbucket.org/pypy/pypy/changeset/418eb4be7f64/

Log:	Fix: this logic can result in an external call whose stderr is
	completely eaten. Now we print the stderr, at least, and avoid
	caching results in that case.

diff --git a/rpython/tool/gcc_cache.py b/rpython/tool/gcc_cache.py
--- a/rpython/tool/gcc_cache.py
+++ b/rpython/tool/gcc_cache.py
@@ -1,5 +1,5 @@
 from hashlib import md5
-import py, os
+import py, os, sys
 
 def cache_file_path(c_files, eci, cachename):
     "Builds a filename to cache compilation data"
@@ -26,6 +26,8 @@
             if ignore_errors:
                 platform.log_errors = False
             result = platform.execute(platform.compile(c_files, eci))
+            if result.err:
+                sys.stderr.write(result.err)
         finally:
             if ignore_errors:
                 del platform.log_errors
@@ -33,7 +35,8 @@
             # compare equal to another instance without it
             if platform.log_errors != _previous:
                 platform.log_errors = _previous
-        try_atomic_write(path, result.out)
+        if not result.err:
+            try_atomic_write(path, result.out)
         return result.out
 
 def try_atomic_write(path, data):
diff --git a/rpython/tool/test/test_gcc_cache.py b/rpython/tool/test/test_gcc_cache.py
--- a/rpython/tool/test/test_gcc_cache.py
+++ b/rpython/tool/test/test_gcc_cache.py
@@ -93,3 +93,24 @@
     finally:
         sys.stderr = oldstderr
     assert 'ERROR' not in capture.getvalue().upper()
+
+def test_execute_code_show_runtime_error():
+    f = localudir.join('z.c')
+    f.write("""
+    #include <stdio.h>
+    int main()
+    {
+       fprintf(stderr, "hello\\n");
+       return 0;
+    }
+    """)
+    for i in range(2):
+        eci = ExternalCompilationInfo()
+        oldstderr = sys.stderr
+        try:
+            sys.stderr = capture = cStringIO.StringIO()
+            output = build_executable_cache([f], eci, True)
+        finally:
+            sys.stderr = oldstderr
+        assert 'hello' in capture.getvalue()
+        assert output == ''


More information about the pypy-commit mailing list