diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-03-30 06:15:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-30 06:15:31 (GMT) |
commit | 762bf40438a572a398e500c74e38f9894ea20a45 (patch) | |
tree | e3cec204dd4f633631650bf10222344a2c605929 /Modules/_io/bytesio.c | |
parent | ea720fe7e99d68924deab38de955fe97f87e2b29 (diff) | |
download | cpython-762bf40438a572a398e500c74e38f9894ea20a45.zip cpython-762bf40438a572a398e500c74e38f9894ea20a45.tar.gz cpython-762bf40438a572a398e500c74e38f9894ea20a45.tar.bz2 |
bpo-29852: Argument Clinic Py_ssize_t converter now supports None (#716)
if pass `accept={int, NoneType}`.
Diffstat (limited to 'Modules/_io/bytesio.c')
-rw-r--r-- | Modules/_io/bytesio.c | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index f78b447..42c7f79 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -8,13 +8,6 @@ class _io.BytesIO "bytesio *" "&PyBytesIO_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=7f50ec034f5c0b26]*/ -/*[python input] -class io_ssize_t_converter(CConverter): - type = 'Py_ssize_t' - converter = '_PyIO_ConvertSsize_t' -[python start generated code]*/ -/*[python end generated code: output=da39a3ee5e6b4b0d input=d0a811d3cbfd1b33]*/ - typedef struct { PyObject_HEAD PyObject *buf; @@ -381,7 +374,7 @@ read_bytes(bytesio *self, Py_ssize_t size) /*[clinic input] _io.BytesIO.read - size: io_ssize_t = -1 + size: Py_ssize_t(accept={int, NoneType}) = -1 / Read at most size bytes, returned as a bytes object. @@ -392,7 +385,7 @@ Return an empty bytes object at EOF. static PyObject * _io_BytesIO_read_impl(bytesio *self, Py_ssize_t size) -/*[clinic end generated code: output=9cc025f21c75bdd2 input=c81ec53b8f2cc3cf]*/ +/*[clinic end generated code: output=9cc025f21c75bdd2 input=74344a39f431c3d7]*/ { Py_ssize_t n; @@ -412,7 +405,7 @@ _io_BytesIO_read_impl(bytesio *self, Py_ssize_t size) /*[clinic input] _io.BytesIO.read1 - size: io_ssize_t = -1 + size: Py_ssize_t(accept={int, NoneType}) = -1 / Read at most size bytes, returned as a bytes object. @@ -423,14 +416,14 @@ Return an empty bytes object at EOF. static PyObject * _io_BytesIO_read1_impl(bytesio *self, Py_ssize_t size) -/*[clinic end generated code: output=d0f843285aa95f1c input=67cf18b142111664]*/ +/*[clinic end generated code: output=d0f843285aa95f1c input=440a395bf9129ef5]*/ { return _io_BytesIO_read_impl(self, size); } /*[clinic input] _io.BytesIO.readline - size: io_ssize_t = -1 + size: Py_ssize_t(accept={int, NoneType}) = -1 / Next line from the file, as a bytes object. @@ -442,7 +435,7 @@ Return an empty bytes object at EOF. static PyObject * _io_BytesIO_readline_impl(bytesio *self, Py_ssize_t size) -/*[clinic end generated code: output=4bff3c251df8ffcd input=7c95bd3f9e9d1646]*/ +/*[clinic end generated code: output=4bff3c251df8ffcd input=e7c3fbd1744e2783]*/ { Py_ssize_t n; @@ -556,7 +549,7 @@ _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer) /*[clinic input] _io.BytesIO.truncate - size as arg: object = None + size: Py_ssize_t(accept={int, NoneType}, c_default="self->pos") = None / Truncate the file to at most size bytes. @@ -566,31 +559,12 @@ The current file position is unchanged. Returns the new size. [clinic start generated code]*/ static PyObject * -_io_BytesIO_truncate_impl(bytesio *self, PyObject *arg) -/*[clinic end generated code: output=81e6be60e67ddd66 input=11ed1966835462ba]*/ +_io_BytesIO_truncate_impl(bytesio *self, Py_ssize_t size) +/*[clinic end generated code: output=9ad17650c15fa09b input=423759dd42d2f7c1]*/ { - Py_ssize_t size; - CHECK_CLOSED(self); CHECK_EXPORTS(self); - if (arg == Py_None) { - /* Truncate to current position if no argument is passed. */ - size = self->pos; - } - else if (PyIndex_Check(arg)) { - size = PyNumber_AsSsize_t(arg, PyExc_OverflowError); - if (size == -1 && PyErr_Occurred()) { - return NULL; - } - } - else { - PyErr_Format(PyExc_TypeError, - "argument should be integer or None, not '%.200s'", - Py_TYPE(arg)->tp_name); - return NULL; - } - if (size < 0) { PyErr_Format(PyExc_ValueError, "negative size value %zd", size); |