Skip to content

Commit c268a50

Browse files
Update converting buffers.
1 parent 44a1686 commit c268a50

File tree

14 files changed

+105
-21
lines changed

14 files changed

+105
-21
lines changed

Modules/_io/clinic/bufferedio.c.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ _io__BufferedIOBase_readinto(PyObject *self, PyObject *arg)
2020
Py_buffer buffer = {NULL, NULL};
2121

2222
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
23-
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
2423
goto exit;
2524
}
2625
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -56,7 +55,6 @@ _io__BufferedIOBase_readinto1(PyObject *self, PyObject *arg)
5655
Py_buffer buffer = {NULL, NULL};
5756

5857
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
59-
_PyErr_BadArgument("readinto1", "read-write bytes-like object", arg);
6058
goto exit;
6159
}
6260
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -194,7 +192,6 @@ _io__Buffered_readinto(buffered *self, PyObject *arg)
194192
Py_buffer buffer = {NULL, NULL};
195193

196194
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
197-
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
198195
goto exit;
199196
}
200197
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -230,7 +227,6 @@ _io__Buffered_readinto1(buffered *self, PyObject *arg)
230227
Py_buffer buffer = {NULL, NULL};
231228

232229
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
233-
_PyErr_BadArgument("readinto1", "read-write bytes-like object", arg);
234230
goto exit;
235231
}
236232
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -413,6 +409,10 @@ _io_BufferedWriter_write(buffered *self, PyObject *arg)
413409
if (PyObject_GetBuffer(arg, &buffer, PyBUF_SIMPLE) != 0) {
414410
goto exit;
415411
}
412+
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
413+
_PyErr_BadArgument("write", "contiguous buffer", arg);
414+
goto exit;
415+
}
416416
return_value = _io_BufferedWriter_write_impl(self, &buffer);
417417

418418
exit:
@@ -496,4 +496,4 @@ _io_BufferedRandom___init__(PyObject *self, PyObject *args, PyObject *kwargs)
496496
exit:
497497
return return_value;
498498
}
499-
/*[clinic end generated code: output=2c378c413f3121ff input=a9049054013a1b77]*/
499+
/*[clinic end generated code: output=ecce6d4ca9143a15 input=a9049054013a1b77]*/

Modules/_io/clinic/bytesio.c.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ _io_BytesIO_readinto(bytesio *self, PyObject *arg)
297297
Py_buffer buffer = {NULL, NULL};
298298

299299
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
300-
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
301300
goto exit;
302301
}
303302
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -449,4 +448,4 @@ _io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
449448
exit:
450449
return return_value;
451450
}
452-
/*[clinic end generated code: output=c20712afca846fc0 input=a9049054013a1b77]*/
451+
/*[clinic end generated code: output=319d5f4852532292 input=a9049054013a1b77]*/

Modules/_io/clinic/fileio.c.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ _io_FileIO_readinto(fileio *self, PyObject *arg)
157157
Py_buffer buffer = {NULL, NULL};
158158

159159
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
160-
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
161160
goto exit;
162161
}
163162
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -253,6 +252,10 @@ _io_FileIO_write(fileio *self, PyObject *arg)
253252
if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) {
254253
goto exit;
255254
}
255+
if (!PyBuffer_IsContiguous(&b, 'C')) {
256+
_PyErr_BadArgument("write", "contiguous buffer", arg);
257+
goto exit;
258+
}
256259
return_value = _io_FileIO_write_impl(self, &b);
257260

258261
exit:
@@ -378,4 +381,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
378381
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
379382
#define _IO_FILEIO_TRUNCATE_METHODDEF
380383
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
381-
/*[clinic end generated code: output=5165002e37eaed24 input=a9049054013a1b77]*/
384+
/*[clinic end generated code: output=13ff9ef76ca044d0 input=a9049054013a1b77]*/

Modules/_io/clinic/winconsoleio.c.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ _io__WindowsConsoleIO_readinto(winconsoleio *self, PyObject *arg)
157157
Py_buffer buffer = {NULL, NULL};
158158

159159
if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
160-
_PyErr_BadArgument("readinto", "read-write bytes-like object", arg);
161160
goto exit;
162161
}
163162
if (!PyBuffer_IsContiguous(&buffer, 'C')) {
@@ -263,6 +262,10 @@ _io__WindowsConsoleIO_write(winconsoleio *self, PyObject *arg)
263262
if (PyObject_GetBuffer(arg, &b, PyBUF_SIMPLE) != 0) {
264263
goto exit;
265264
}
265+
if (!PyBuffer_IsContiguous(&b, 'C')) {
266+
_PyErr_BadArgument("write", "contiguous buffer", arg);
267+
goto exit;
268+
}
266269
return_value = _io__WindowsConsoleIO_write_impl(self, &b);
267270

268271
exit:
@@ -333,4 +336,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
333336
#ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
334337
#define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
335338
#endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
336-
/*[clinic end generated code: output=06e4655bbabff31c input=a9049054013a1b77]*/
339+
/*[clinic end generated code: output=21005cb3b728c616 input=a9049054013a1b77]*/

Modules/clinic/_bz2module.c.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/_lzmamodule.c.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/_ssl.c.h

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/_struct.c.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/arraymodule.c.h

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/binascii.c.h

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/zlibmodule.c.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/clinic/bytesobject.c.h

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/clinic/marshal.c.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/clinic/clinic.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3254,6 +3254,10 @@ def parse_arg(self, argname):
32543254
if (PyObject_GetBuffer({argname}, &{paramname}, PyBUF_SIMPLE) != 0) {{{{
32553255
goto exit;
32563256
}}}}
3257+
if (!PyBuffer_IsContiguous(&{paramname}, 'C')) {{{{
3258+
_PyErr_BadArgument("{{name}}", "contiguous buffer", {argname});
3259+
goto exit;
3260+
}}}}
32573261
""".format(argname=argname, paramname=self.name)
32583262
elif self.format_unit == 's*':
32593263
return """
@@ -3269,12 +3273,15 @@ def parse_arg(self, argname):
32693273
if (PyObject_GetBuffer({argname}, &{paramname}, PyBUF_SIMPLE) != 0) {{{{
32703274
goto exit;
32713275
}}}}
3276+
if (!PyBuffer_IsContiguous(&{paramname}, 'C')) {{{{
3277+
_PyErr_BadArgument("{{name}}", "contiguous buffer", {argname});
3278+
goto exit;
3279+
}}}}
32723280
}}}}
32733281
""".format(argname=argname, paramname=self.name)
32743282
elif self.format_unit == 'w*':
32753283
return """
32763284
if (PyObject_GetBuffer({argname}, &{paramname}, PyBUF_WRITABLE) < 0) {{{{
3277-
_PyErr_BadArgument("{{name}}", "read-write bytes-like object", {argname});
32783285
goto exit;
32793286
}}}}
32803287
if (!PyBuffer_IsContiguous(&{paramname}, 'C')) {{{{

0 commit comments

Comments
 (0)