[pypy-svn] r74669 - in pypy/trunk/pypy/module/cpyext: . test

afa at codespeak.net afa at codespeak.net
Sat May 22 11:25:57 CEST 2010


Author: afa
Date: Sat May 22 11:25:54 2010
New Revision: 74669

Modified:
   pypy/trunk/pypy/module/cpyext/api.py
   pypy/trunk/pypy/module/cpyext/test/test_eval.py
Log:
Fix segfault in test: don't close the file with fclose(), this frees the FILE* structure.
Use os.close() instead.


Modified: pypy/trunk/pypy/module/cpyext/api.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/api.py	(original)
+++ pypy/trunk/pypy/module/cpyext/api.py	Sat May 22 11:25:54 2010
@@ -67,6 +67,7 @@
 assert CONST_STRING is not rffi.CCHARP
 assert CONST_WSTRING is not rffi.CWCHARP
 
+# FILE* interface
 FILEP = rffi.COpaquePtr('FILE')
 fopen = rffi.llexternal('fopen', [CONST_STRING, CONST_STRING], FILEP)
 fclose = rffi.llexternal('fclose', [FILEP], rffi.INT)
@@ -77,6 +78,11 @@
                         [rffi.VOIDP, rffi.SIZE_T, rffi.SIZE_T, FILEP],
                         rffi.SIZE_T)
 feof = rffi.llexternal('feof', [FILEP], rffi.INT)
+if sys.platform == 'win32':
+    fileno = rffi.llexternal('_fileno', [FILEP], rffi.INT)
+else:
+    fileno = rffi.llexternal('fileno', [FILEP], rffi.INT)
+
 
 constant_names = """
 Py_TPFLAGS_READY Py_TPFLAGS_READYING

Modified: pypy/trunk/pypy/module/cpyext/test/test_eval.py
==============================================================================
--- pypy/trunk/pypy/module/cpyext/test/test_eval.py	(original)
+++ pypy/trunk/pypy/module/cpyext/test/test_eval.py	Sat May 22 11:25:54 2010
@@ -3,10 +3,10 @@
 from pypy.module.cpyext.test.test_api import BaseApiTest
 from pypy.module.cpyext.eval import (
     Py_single_input, Py_file_input, Py_eval_input)
-from pypy.module.cpyext.api import fopen, fclose, Py_ssize_tP
+from pypy.module.cpyext.api import fopen, fclose, fileno, Py_ssize_tP
 from pypy.interpreter.gateway import interp2app
 from pypy.tool.udir import udir
-import sys
+import sys, os
 
 class TestEval(BaseApiTest):
     def test_eval(self, space, api):
@@ -92,8 +92,11 @@
         assert api.PyErr_Occurred() is space.w_ZeroDivisionError
         api.PyErr_Clear()
 
-        # retry on closed file
+        # try again, but with a closed file
+        fp = fopen(str(filepath), "rb")
+        os.close(fileno(fp))
         api.PyRun_File(fp, filename, Py_file_input, w_globals, w_locals)
+        fclose(fp)
         assert api.PyErr_Occurred() is space.w_IOError
         api.PyErr_Clear()
 



More information about the Pypy-commit mailing list