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
650c1e81
Commit
650c1e81
authored
Feb 03, 2015
by
Stefan Krah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #14203: Remove obsolete support for view==NULL in bytesiobuf_getbuffer()
and array_buffer_getbuf().
parent
38c30e6c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
17 deletions
+48
-17
Lib/test/test_array.py
Lib/test/test_array.py
+5
-0
Lib/test/test_bytes.py
Lib/test/test_bytes.py
+4
-0
Misc/NEWS
Misc/NEWS
+3
-3
Modules/_io/bytesio.c
Modules/_io/bytesio.c
+11
-10
Modules/_testcapimodule.c
Modules/_testcapimodule.c
+20
-2
Modules/arraymodule.c
Modules/arraymodule.c
+5
-2
No files found.
Lib/test/test_array.py
View file @
650c1e81
...
...
@@ -1041,6 +1041,11 @@ class BaseTest:
a
=
array
.
array
(
self
.
typecode
,
"foo"
)
a
=
array
.
array
(
self
.
typecode
,
array
.
array
(
'u'
,
'foo'
))
@
support
.
cpython_only
def
test_obsolete_write_lock
(
self
):
from
_testcapi
import
getbuffer_with_null_view
a
=
array
.
array
(
'B'
,
b""
)
self
.
assertRaises
(
BufferError
,
getbuffer_with_null_view
,
a
)
class
StringTest
(
BaseTest
):
...
...
Lib/test/test_bytes.py
View file @
650c1e81
...
...
@@ -1224,6 +1224,10 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
self.assertRaises(BufferError, delslice)
self.assertEqual(b, orig)
@test.support.cpython_only
def test_obsolete_write_lock(self):
from _testcapi import getbuffer_with_null_view
self.assertRaises(BufferError, getbuffer_with_null_view, bytearray())
class AssortedBytesTest(unittest.TestCase):
#
...
...
Misc/NEWS
View file @
650c1e81
...
...
@@ -1560,9 +1560,9 @@ Build
C
API
-----
-
Issue
#
14203
:
Remove
obsolete
support
for
view
==
NULL
in
PyBuffer_FillInfo
()
and
bytearray_getbuffer
().
Both
functions
now
raise
BufferError
in
that
case
.
-
Issue
#
14203
:
Remove
obsolete
support
for
view
==
NULL
in
PyBuffer_FillInfo
()
,
bytearray_getbuffer
(),
bytesiobuf_getbuffer
()
and
array_buffer_getbuf
().
All
functions
now
raise
BufferError
in
that
case
.
-
Issue
#
22445
:
PyBuffer_IsContiguous
()
now
implements
precise
contiguity
tests
,
compatible
with
NumPy
's NPY_RELAXED_STRIDES_CHECKING compilation
...
...
Modules/_io/bytesio.c
View file @
650c1e81
...
...
@@ -1028,23 +1028,24 @@ PyTypeObject PyBytesIO_Type = {
static
int
bytesiobuf_getbuffer
(
bytesiobuf
*
obj
,
Py_buffer
*
view
,
int
flags
)
{
int
ret
;
bytesio
*
b
=
(
bytesio
*
)
obj
->
source
;
if
(
view
==
NULL
)
{
PyErr_SetString
(
PyExc_BufferError
,
"bytesiobuf_getbuffer: view==NULL argument is obsolete"
);
return
-
1
;
}
if
(
SHARED_BUF
(
b
))
{
if
(
unshare_buffer
(
b
,
b
->
string_size
)
<
0
)
return
-
1
;
}
if
(
view
==
NULL
)
{
b
->
exports
++
;
return
0
;
}
ret
=
PyBuffer_FillInfo
(
view
,
(
PyObject
*
)
obj
,
/* cannot fail if view != NULL and readonly == 0 */
(
void
)
PyBuffer_FillInfo
(
view
,
(
PyObject
*
)
obj
,
PyBytes_AS_STRING
(
b
->
buf
),
b
->
string_size
,
0
,
flags
);
if
(
ret
>=
0
)
{
b
->
exports
++
;
}
return
ret
;
b
->
exports
++
;
return
0
;
}
static
void
...
...
Modules/_testcapimodule.c
View file @
650c1e81
...
...
@@ -2518,21 +2518,26 @@ test_from_contiguous(PyObject* self, PyObject *noargs)
Py_RETURN_NONE
;
}
extern
PyTypeObject
_PyBytesIOBuffer_Type
;
static
PyObject
*
test_pep3118_obsolete_write_locks
(
PyObject
*
self
,
PyObject
*
noargs
)
{
PyTypeObject
*
type
=
&
_PyBytesIOBuffer_Type
;
PyObject
*
b
;
char
*
dummy
[
1
];
int
ret
,
match
;
/* PyBuffer_FillInfo() */
ret
=
PyBuffer_FillInfo
(
NULL
,
NULL
,
dummy
,
1
,
0
,
PyBUF_SIMPLE
);
match
=
PyErr_Occurred
()
&&
PyErr_ExceptionMatches
(
PyExc_BufferError
);
PyErr_Clear
();
if
(
ret
!=
-
1
||
match
==
0
)
goto
error
;
b
=
PyByteArray_FromStringAndSize
(
""
,
0
);
/* bytesiobuf_getbuffer() */
b
=
type
->
tp_alloc
(
type
,
0
);
if
(
b
==
NULL
)
{
return
NULL
;
}
...
...
@@ -2552,6 +2557,18 @@ error:
return
NULL
;
}
/* This tests functions that historically supported write locks. It is
wrong to call getbuffer() with view==NULL and a compliant getbufferproc
is entitled to segfault in that case. */
static
PyObject
*
getbuffer_with_null_view
(
PyObject
*
self
,
PyObject
*
obj
)
{
if
(
PyObject_GetBuffer
(
obj
,
NULL
,
PyBUF_SIMPLE
)
<
0
)
return
NULL
;
Py_RETURN_NONE
;
}
/* Test that the fatal error from not having a current thread doesn't
cause an infinite loop. Run via Lib/test/test_capi.py */
static
PyObject
*
...
...
@@ -3213,6 +3230,7 @@ static PyMethodDef TestMethods[] = {
{
"test_capsule"
,
(
PyCFunction
)
test_capsule
,
METH_NOARGS
},
{
"test_from_contiguous"
,
(
PyCFunction
)
test_from_contiguous
,
METH_NOARGS
},
{
"test_pep3118_obsolete_write_locks"
,
(
PyCFunction
)
test_pep3118_obsolete_write_locks
,
METH_NOARGS
},
{
"getbuffer_with_null_view"
,
getbuffer_with_null_view
,
METH_O
},
{
"getargs_tuple"
,
getargs_tuple
,
METH_VARARGS
},
{
"getargs_keywords"
,
(
PyCFunction
)
getargs_keywords
,
METH_VARARGS
|
METH_KEYWORDS
},
...
...
Modules/arraymodule.c
View file @
650c1e81
...
...
@@ -2530,7 +2530,11 @@ static const void *emptybuf = "";
static
int
array_buffer_getbuf
(
arrayobject
*
self
,
Py_buffer
*
view
,
int
flags
)
{
if
(
view
==
NULL
)
goto
finish
;
if
(
view
==
NULL
)
{
PyErr_SetString
(
PyExc_BufferError
,
"array_buffer_getbuf: view==NULL argument is obsolete"
);
return
-
1
;
}
view
->
buf
=
(
void
*
)
self
->
ob_item
;
view
->
obj
=
(
PyObject
*
)
self
;
...
...
@@ -2560,7 +2564,6 @@ array_buffer_getbuf(arrayobject *self, Py_buffer *view, int flags)
#endif
}
finish:
self
->
ob_exports
++
;
return
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