Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
92dd958
remove redundant C-contiguity chec in getargs.c
furkanonder Jun 8, 2023
68a78dd
Merge branch 'main' into issue-67565
furkanonder Jun 8, 2023
8ab0fbd
📜🤖 Added by blurb_it.
blurb-it[bot] Jun 8, 2023
9453509
Merge branch 'main' into issue-67565
furkanonder Jun 8, 2023
6653612
Merge branch 'main' into issue-67565
furkanonder Aug 5, 2023
ce0fd8c
add whitespace between functions
furkanonder Aug 5, 2023
374f01a
remove redundant C-contiguity check in binascii
furkanonder Sep 6, 2023
36bee41
remove redundant C-contiguity check in ssl
furkanonder Sep 6, 2023
84b1a42
Merge branch 'main' into issue-67565
furkanonder Sep 7, 2023
8bbd6fa
mention binascii and ssl module
furkanonder Sep 10, 2023
657bc60
Remove PyBuffer_IsContiguous from Argument Clinic
furkanonder Sep 10, 2023
9c5215f
Merge branch 'issue-67565' of github.com:furkanonder/cpython into iss…
furkanonder Sep 10, 2023
9e6f9c3
remove trailing-whitespace in test_binascii
furkanonder Sep 10, 2023
4902c6a
Merge branch 'main' into issue-67565
furkanonder Sep 10, 2023
bcfd13b
update news entry
furkanonder Sep 11, 2023
1e953f3
Merge branch 'main' into issue-67565
furkanonder Sep 11, 2023
b86546f
Add assert for PyBuffer_IsContiguous in getargs.c
furkanonder Sep 25, 2023
7cb3b09
Add assert for PyBuffer_IsContiguous in binascii.c
furkanonder Sep 25, 2023
d2cbee5
Add assert for PyBuffer_IsContiguous _ssl.c
furkanonder Sep 25, 2023
dff0a4f
add comment that PyBUF_SIMPLE guarantees C-contiguous buffers
furkanonder Sep 25, 2023
d06be0a
Merge branch 'main' into issue-67565
furkanonder Sep 26, 2023
9ce050a
Merge branch 'main' into issue-67565
furkanonder Oct 16, 2023
9e17a07
add new test using NONCONTIG_WRITABLE
furkanonder Oct 16, 2023
9e99a83
add new test using NONCONTIG_READONLY
furkanonder Oct 16, 2023
64d9e8f
add new test using NONCONTIG_READONLY
furkanonder Oct 16, 2023
a90519e
remove whitespaces
furkanonder Oct 16, 2023
676dfa2
re-run argument clinic
furkanonder Oct 16, 2023
d4387b2
remove tests
furkanonder Oct 16, 2023
c4da7d5
Merge branch 'main' into issue-67565
furkanonder Oct 16, 2023
81ba023
resolve conflict
furkanonder Oct 17, 2023
ce031cb
Merge branch 'main' into issue-67565
furkanonder Oct 17, 2023
69ba12f
re-run argument clinic
furkanonder Oct 18, 2023
cbfc93a
Update Python/getargs.c
serhiy-storchaka Oct 20, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_binascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ def test_base64_roundtrip(self, binary, newline):
restored = binascii.a2b_base64(self.type2test(converted))
self.assertConversion(binary, converted, restored, newline=newline)

def test_c_contiguity(self):
m = memoryview(bytearray(b'noncontig'))
noncontig_writable = m[::-2]
with self.assertRaises(BufferError):
binascii.b2a_hex(noncontig_writable)


class ArrayBinASCIITest(BinASCIITest):
def type2test(self, s):
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_capi/test_getargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class TupleSubclass(tuple):
class DictSubclass(dict):
pass

m = memoryview(bytearray(b'noncontig'))
NONCONTIG_WRITABLE = m[::-2]

class Unsigned_TestCase(unittest.TestCase):
def test_b(self):
Expand Down Expand Up @@ -835,6 +837,7 @@ def test_y_star(self):
self.assertEqual(getargs_y_star(bytearray(b'bytearray')), b'bytearray')
self.assertEqual(getargs_y_star(memoryview(b'memoryview')), b'memoryview')
self.assertRaises(TypeError, getargs_y_star, None)
self.assertRaises(BufferError, getargs_y_star, NONCONTIG_WRITABLE)

def test_y_hash(self):
from _testcapi import getargs_y_hash
Expand All @@ -844,6 +847,8 @@ def test_y_hash(self):
self.assertRaises(TypeError, getargs_y_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_y_hash, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_y_hash, None)
# TypeError: must be read-only bytes-like object, not memoryview
self.assertRaises(TypeError, getargs_y_hash, NONCONTIG_WRITABLE)

def test_w_star(self):
# getargs_w_star() modifies first and last byte
Expand All @@ -859,6 +864,7 @@ def test_w_star(self):
self.assertEqual(getargs_w_star(memoryview(buf)), b'[emoryvie]')
self.assertEqual(buf, bytearray(b'[emoryvie]'))
self.assertRaises(TypeError, getargs_w_star, None)
self.assertRaises(TypeError, getargs_w_star, NONCONTIG_WRITABLE)


class String_TestCase(unittest.TestCase):
Expand Down Expand Up @@ -891,6 +897,7 @@ def test_s_star(self):
self.assertEqual(getargs_s_star(bytearray(b'bytearray')), b'bytearray')
self.assertEqual(getargs_s_star(memoryview(b'memoryview')), b'memoryview')
self.assertRaises(TypeError, getargs_s_star, None)
self.assertRaises(BufferError, getargs_s_star, NONCONTIG_WRITABLE)

def test_s_hash(self):
from _testcapi import getargs_s_hash
Expand All @@ -900,6 +907,8 @@ def test_s_hash(self):
self.assertRaises(TypeError, getargs_s_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_s_hash, memoryview(b'memoryview'))
self.assertRaises(TypeError, getargs_s_hash, None)
# TypeError: must be read-only bytes-like object, not memoryview
self.assertRaises(TypeError, getargs_s_hash, NONCONTIG_WRITABLE)

def test_z(self):
from _testcapi import getargs_z
Expand All @@ -918,6 +927,7 @@ def test_z_star(self):
self.assertEqual(getargs_z_star(bytearray(b'bytearray')), b'bytearray')
self.assertEqual(getargs_z_star(memoryview(b'memoryview')), b'memoryview')
self.assertIsNone(getargs_z_star(None))
self.assertRaises(BufferError, getargs_z_star, NONCONTIG_WRITABLE)

def test_z_hash(self):
from _testcapi import getargs_z_hash
Expand All @@ -927,6 +937,8 @@ def test_z_hash(self):
self.assertRaises(TypeError, getargs_z_hash, bytearray(b'bytearray'))
self.assertRaises(TypeError, getargs_z_hash, memoryview(b'memoryview'))
self.assertIsNone(getargs_z_hash(None))
# TypeError: must be read-only bytes-like object, not memoryview
self.assertRaises(TypeError, getargs_z_hash, NONCONTIG_WRITABLE)

def test_es(self):
from _testcapi import getargs_es
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,10 @@ def test_buffer_types(self):
self.assertEqual(bio.read(), b'bar')
bio.write(memoryview(b'baz'))
self.assertEqual(bio.read(), b'baz')
m = memoryview(bytearray(b'noncontig'))
noncontig_writable = m[::-2]
with self.assertRaises(BufferError):
bio.write(memoryview(noncontig_writable))

def test_error_types(self):
bio = ssl.MemoryBIO()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove redundant C-contiguity check in :file:`getargs.c`, :mod:`binascii`, :mod:`ssl` and Argument Clinic. Patched by Stefan Krah and Furkan Onder
14 changes: 1 addition & 13 deletions Modules/_blake2/clinic/blake2b_impl.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 1 addition & 13 deletions Modules/_blake2/clinic/blake2s_impl.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 1 addition & 21 deletions Modules/_io/clinic/bufferedio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Modules/_io/clinic/bytesio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions Modules/_io/clinic/fileio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions Modules/_io/clinic/winconsoleio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Modules/_multiprocessing/clinic/multiprocessing.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Modules/_sqlite/clinic/blob.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Modules/_sqlite/clinic/connection.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Modules/_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4133,7 +4133,8 @@ _ssl__SSLContext_load_verify_locations_impl(PySSLContext *self,
if (PyObject_GetBuffer(cadata, &buf, PyBUF_SIMPLE)) {
goto error;
}
if (!PyBuffer_IsContiguous(&buf, 'C') || buf.ndim > 1) {
assert(PyBuffer_IsContiguous(&buf, 'C'));
if (buf.ndim > 1) {
PyBuffer_Release(&buf);
PyErr_SetString(PyExc_TypeError,
"cadata should be a contiguous buffer with "
Expand Down
8 changes: 1 addition & 7 deletions Modules/binascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,7 @@ ascii_buffer_converter(PyObject *arg, Py_buffer *buf)
"not '%.100s'", Py_TYPE(arg)->tp_name);
return 0;
}
if (!PyBuffer_IsContiguous(buf, 'C')) {
PyErr_Format(PyExc_TypeError,
"argument should be a contiguous buffer, "
"not '%.100s'", Py_TYPE(arg)->tp_name);
PyBuffer_Release(buf);
return 0;
}
assert(PyBuffer_IsContiguous(buf, 'C'));
return Py_CLEANUP_SUPPORTED;
}

Expand Down
Loading