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
480e2853
Commit
480e2853
authored
Jun 08, 2016
by
Barry Warsaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #27066: Fixed SystemError if a custom opener (for open()) returns
a negative number without setting an exception.
parent
fda4d678
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
1 deletion
+25
-1
Lib/test/test_io.py
Lib/test/test_io.py
+16
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_io/fileio.c
Modules/_io/fileio.c
+6
-1
No files found.
Lib/test/test_io.py
View file @
480e2853
...
...
@@ -805,6 +805,22 @@ class IOTest(unittest.TestCase):
with
self
.
open
(
"non-existent"
,
"r"
,
opener
=
opener
)
as
f
:
self
.
assertEqual
(
f
.
read
(),
"egg
\
n
"
)
def
test_bad_opener_negative_1
(
self
):
# Issue #27066.
def
badopener
(
fname
,
flags
):
return
-
1
with
self
.
assertRaises
(
ValueError
)
as
cm
:
open
(
'non-existent'
,
'r'
,
opener
=
badopener
)
self
.
assertEqual
(
str
(
cm
.
exception
),
'opener returned -1'
)
def
test_bad_opener_other_negative
(
self
):
# Issue #27066.
def
badopener
(
fname
,
flags
):
return
-
2
with
self
.
assertRaises
(
ValueError
)
as
cm
:
open
(
'non-existent'
,
'r'
,
opener
=
badopener
)
self
.
assertEqual
(
str
(
cm
.
exception
),
'opener returned -2'
)
def
test_fileio_closefd
(
self
):
# Issue #4841
with
self
.
open
(
__file__
,
'rb'
)
as
f1
,
\
...
...
Misc/NEWS
View file @
480e2853
...
...
@@ -10,6 +10,9 @@ Release date: tba
Core and Builtins
-----------------
- Issue #27066: Fixed SystemError if a custom opener (for open()) returns a
negative number without setting an exception.
- Issue #20041: Fixed TypeError when frame.f_trace is set to None.
Patch by Xavier de Gaye.
...
...
Modules/_io/fileio.c
View file @
480e2853
...
...
@@ -421,7 +421,12 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
self
->
fd
=
_PyLong_AsInt
(
fdobj
);
Py_DECREF
(
fdobj
);
if
(
self
->
fd
==
-
1
)
{
if
(
self
->
fd
<
0
)
{
if
(
!
PyErr_Occurred
())
{
/* The opener returned -1. See issue #27066 */
PyErr_Format
(
PyExc_ValueError
,
"opener returned %d"
,
self
->
fd
);
}
goto
error
;
}
}
...
...
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