Kaydet (Commit) 5de1594e authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Merged revisions 81275 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81275 | antoine.pitrou | 2010-05-17 21:56:59 +0200 (lun., 17 mai 2010) | 4 lines

  Issue #7079: Fix a possible crash when closing a file object while using
  it from another thread.  Patch by Daniel Stutzbach.
........
üst 83175569
...@@ -417,6 +417,7 @@ class FileThreadingTests(unittest.TestCase): ...@@ -417,6 +417,7 @@ class FileThreadingTests(unittest.TestCase):
self._count_lock = threading.Lock() self._count_lock = threading.Lock()
self.close_count = 0 self.close_count = 0
self.close_success_count = 0 self.close_success_count = 0
self.use_buffering = False
def tearDown(self): def tearDown(self):
if self.f: if self.f:
...@@ -430,7 +431,10 @@ class FileThreadingTests(unittest.TestCase): ...@@ -430,7 +431,10 @@ class FileThreadingTests(unittest.TestCase):
pass pass
def _create_file(self): def _create_file(self):
self.f = open(self.filename, "w+") if self.use_buffering:
self.f = open(self.filename, "w+", buffering=1024*16)
else:
self.f = open(self.filename, "w+")
def _close_file(self): def _close_file(self):
with self._count_lock: with self._count_lock:
...@@ -517,6 +521,12 @@ class FileThreadingTests(unittest.TestCase): ...@@ -517,6 +521,12 @@ class FileThreadingTests(unittest.TestCase):
print >> self.f, '' print >> self.f, ''
self._test_close_open_io(io_func) self._test_close_open_io(io_func)
def test_close_open_print_buffered(self):
self.use_buffering = True
def io_func():
print >> self.f, ''
self._test_close_open_io(io_func)
def test_close_open_read(self): def test_close_open_read(self):
def io_func(): def io_func():
self.f.read(0) self.f.read(0)
......
...@@ -12,6 +12,9 @@ What's New in Python 2.6.6 alpha 1? ...@@ -12,6 +12,9 @@ What's New in Python 2.6.6 alpha 1?
Core and Builtins Core and Builtins
----------------- -----------------
- Issue #7079: Fix a possible crash when closing a file object while using
it from another thread. Patch by Daniel Stutzbach.
- Issue #1533: fix inconsistency in range function argument - Issue #1533: fix inconsistency in range function argument
processing: any non-float non-integer argument is now converted to processing: any non-float non-integer argument is now converted to
an integer (if possible) using its __int__ method. Previously, only an integer (if possible) using its __int__ method. Previously, only
......
...@@ -568,8 +568,10 @@ static PyObject * ...@@ -568,8 +568,10 @@ static PyObject *
file_close(PyFileObject *f) file_close(PyFileObject *f)
{ {
PyObject *sts = close_the_file(f); PyObject *sts = close_the_file(f);
PyMem_Free(f->f_setbuf); if (sts) {
f->f_setbuf = NULL; PyMem_Free(f->f_setbuf);
f->f_setbuf = NULL;
}
return sts; return sts;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment