Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
28f07364
Commit
28f07364
authored
Jul 17, 2018
by
Zackery Spytz
Committed by
Serhiy Storchaka
Jul 17, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34068: _io__IOBase_close_impl could call _PyObject_SetAttrId with an exception set (GH-8282)
parent
56d8f57b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
5 deletions
+20
-5
Lib/test/test_io.py
Lib/test/test_io.py
+10
-0
Misc/NEWS.d/next/Core and Builtins/2018-07-14-08-58-46.bpo-34068.9xfM55.rst
...ore and Builtins/2018-07-14-08-58-46.bpo-34068.9xfM55.rst
+3
-0
Modules/_io/iobase.c
Modules/_io/iobase.c
+7
-5
No files found.
Lib/test/test_io.py
View file @
28f07364
...
@@ -968,6 +968,16 @@ class IOTest(unittest.TestCase):
...
@@ -968,6 +968,16 @@ class IOTest(unittest.TestCase):
self
.
assertSequenceEqual
(
buffer
[
result
:],
unused
)
self
.
assertSequenceEqual
(
buffer
[
result
:],
unused
)
self
.
assertEqual
(
len
(
reader
.
avail
),
avail
-
result
)
self
.
assertEqual
(
len
(
reader
.
avail
),
avail
-
result
)
def
test_close_assert
(
self
):
class
R
(
self
.
IOBase
):
def
__setattr__
(
self
,
name
,
value
):
pass
def
flush
(
self
):
raise
OSError
()
f
=
R
()
# This would cause an assertion failure.
self
.
assertRaises
(
OSError
,
f
.
close
)
class
CIOTest
(
IOTest
):
class
CIOTest
(
IOTest
):
...
...
Misc/NEWS.d/next/Core and Builtins/2018-07-14-08-58-46.bpo-34068.9xfM55.rst
0 → 100644
View file @
28f07364
In :meth:`io.IOBase.close`, ensure that the :attr:`~io.IOBase.closed`
attribute is not set with a live exception. Patch by Zackery Spytz and Serhiy
Storchaka.
Modules/_io/iobase.c
View file @
28f07364
...
@@ -224,8 +224,8 @@ static PyObject *
...
@@ -224,8 +224,8 @@ static PyObject *
_io__IOBase_close_impl
(
PyObject
*
self
)
_io__IOBase_close_impl
(
PyObject
*
self
)
/*[clinic end generated code: output=63c6a6f57d783d6d input=f4494d5c31dbc6b7]*/
/*[clinic end generated code: output=63c6a6f57d783d6d input=f4494d5c31dbc6b7]*/
{
{
PyObject
*
res
;
PyObject
*
res
,
*
exc
,
*
val
,
*
tb
;
int
closed
=
iobase_is_closed
(
self
);
int
rc
,
closed
=
iobase_is_closed
(
self
);
if
(
closed
<
0
)
{
if
(
closed
<
0
)
{
return
NULL
;
return
NULL
;
...
@@ -236,9 +236,11 @@ _io__IOBase_close_impl(PyObject *self)
...
@@ -236,9 +236,11 @@ _io__IOBase_close_impl(PyObject *self)
res
=
PyObject_CallMethodObjArgs
(
self
,
_PyIO_str_flush
,
NULL
);
res
=
PyObject_CallMethodObjArgs
(
self
,
_PyIO_str_flush
,
NULL
);
if
(
_PyObject_SetAttrId
(
self
,
&
PyId___IOBase_closed
,
Py_True
)
<
0
)
{
PyErr_Fetch
(
&
exc
,
&
val
,
&
tb
);
Py_XDECREF
(
res
);
rc
=
_PyObject_SetAttrId
(
self
,
&
PyId___IOBase_closed
,
Py_True
);
return
NULL
;
_PyErr_ChainExceptions
(
exc
,
val
,
tb
);
if
(
rc
<
0
)
{
Py_CLEAR
(
res
);
}
}
if
(
res
==
NULL
)
if
(
res
==
NULL
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment