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
54d0df69
Commit
54d0df69
authored
Mar 06, 2009
by
Hirokazu Yamamoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #5334: array.fromfile() failed to insert values when EOFError was raised.
Reviewed by Benjamin Peterson.
parent
3aed8d51
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
8 deletions
+14
-8
Lib/test/test_array.py
Lib/test/test_array.py
+1
-2
Misc/NEWS
Misc/NEWS
+2
-0
Modules/arraymodule.c
Modules/arraymodule.c
+11
-6
No files found.
Lib/test/test_array.py
View file @
54d0df69
...
...
@@ -174,9 +174,8 @@ class BaseTest(unittest.TestCase):
b
.
fromfile
(
f
,
len
(
self
.
example
))
self
.
assertEqual
(
b
,
array
.
array
(
self
.
typecode
,
self
.
example
))
self
.
assertNotEqual
(
a
,
b
)
b
.
fromfile
(
f
,
len
(
self
.
example
)
)
self
.
assertRaises
(
EOFError
,
b
.
fromfile
,
f
,
len
(
self
.
example
)
+
1
)
self
.
assertEqual
(
a
,
b
)
self
.
assertRaises
(
EOFError
,
b
.
fromfile
,
f
,
1
)
f
.
close
()
finally
:
if
not
f
.
closed
:
...
...
Misc/NEWS
View file @
54d0df69
...
...
@@ -183,6 +183,8 @@ Core and Builtins
Library
-------
- Issue #5334: array.fromfile() failed to insert values when EOFError was raised.
- Issue #5385: Fixed mmap crash after resize failure on windows.
- Issue #5179: Fixed subprocess handle leak on failure on windows.
...
...
Modules/arraymodule.c
View file @
54d0df69
...
...
@@ -1201,6 +1201,7 @@ array_fromfile(arrayobject *self, PyObject *args)
PyObject
*
f
,
*
b
,
*
res
;
Py_ssize_t
itemsize
=
self
->
ob_descr
->
itemsize
;
Py_ssize_t
n
,
nbytes
;
int
not_enough_bytes
;
if
(
!
PyArg_ParseTuple
(
args
,
"On:fromfile"
,
&
f
,
&
n
))
return
NULL
;
...
...
@@ -1222,12 +1223,7 @@ array_fromfile(arrayobject *self, PyObject *args)
return
NULL
;
}
if
(
PyBytes_GET_SIZE
(
b
)
!=
nbytes
)
{
PyErr_SetString
(
PyExc_EOFError
,
"read() didn't return enough bytes"
);
Py_DECREF
(
b
);
return
NULL
;
}
not_enough_bytes
=
(
PyBytes_GET_SIZE
(
b
)
!=
nbytes
);
args
=
Py_BuildValue
(
"(O)"
,
b
);
Py_DECREF
(
b
);
...
...
@@ -1236,6 +1232,15 @@ array_fromfile(arrayobject *self, PyObject *args)
res
=
array_fromstring
(
self
,
args
);
Py_DECREF
(
args
);
if
(
res
==
NULL
)
return
NULL
;
if
(
not_enough_bytes
)
{
PyErr_SetString
(
PyExc_EOFError
,
"read() didn't return enough bytes"
);
Py_DECREF
(
res
);
return
NULL
;
}
return
res
;
}
...
...
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