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
7a3639f3
Commit
7a3639f3
authored
Nov 20, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #25659: Change assert to TypeError in from_buffer/_copy()
Based on suggestion by Eryk Sun.
parent
8305b833
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
3 deletions
+20
-3
Lib/ctypes/test/test_frombuffer.py
Lib/ctypes/test/test_frombuffer.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes.c
+9
-3
No files found.
Lib/ctypes/test/test_frombuffer.py
View file @
7a3639f3
...
...
@@ -120,5 +120,13 @@ class Test(unittest.TestCase):
with
self
.
assertRaises
(
ValueError
):
(
c_int
*
1
).
from_buffer_copy
(
a
,
16
*
sizeof
(
c_int
))
def
test_abstract
(
self
):
self
.
assertRaises
(
TypeError
,
Array
.
from_buffer
,
bytearray
(
10
))
self
.
assertRaises
(
TypeError
,
Structure
.
from_buffer
,
bytearray
(
10
))
self
.
assertRaises
(
TypeError
,
Union
.
from_buffer
,
bytearray
(
10
))
self
.
assertRaises
(
TypeError
,
Array
.
from_buffer_copy
,
b"123"
)
self
.
assertRaises
(
TypeError
,
Structure
.
from_buffer_copy
,
b"123"
)
self
.
assertRaises
(
TypeError
,
Union
.
from_buffer_copy
,
b"123"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS
View file @
7a3639f3
...
...
@@ -121,6 +121,9 @@ Core and Builtins
Library
-------
- Issue #25659: In ctypes, prevent a crash calling the from_buffer() and
from_buffer_copy() methods on abstract classes like Array.
- Issue #28732: Fix crash in os.spawnv() with no elements in args
- Issue #28485: Always raise ValueError for negative
...
...
Modules/_ctypes/_ctypes.c
View file @
7a3639f3
...
...
@@ -469,7 +469,10 @@ CDataType_from_buffer(PyObject *type, PyObject *args)
Py_ssize_t
offset
=
0
;
StgDictObject
*
dict
=
PyType_stgdict
(
type
);
assert
(
dict
);
if
(
!
dict
)
{
PyErr_SetString
(
PyExc_TypeError
,
"abstract class"
);
return
NULL
;
}
if
(
!
PyArg_ParseTuple
(
args
,
"O|n:from_buffer"
,
&
obj
,
&
offset
))
return
NULL
;
...
...
@@ -537,9 +540,12 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args)
Py_ssize_t
offset
=
0
;
PyObject
*
result
;
StgDictObject
*
dict
=
PyType_stgdict
(
type
);
assert
(
dict
);
if
(
!
dict
)
{
PyErr_SetString
(
PyExc_TypeError
,
"abstract class"
);
return
NULL
;
}
if
(
!
PyArg_ParseTuple
(
args
,
"y*|n:from_buffer"
,
&
buffer
,
&
offset
))
if
(
!
PyArg_ParseTuple
(
args
,
"y*|n:from_buffer
_copy
"
,
&
buffer
,
&
offset
))
return
NULL
;
if
(
offset
<
0
)
{
...
...
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