aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/_io/bytesio.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Modules/_io/bytesio.c
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Modules/_io/bytesio.c')
-rw-r--r--contrib/tools/python3/src/Modules/_io/bytesio.c154
1 files changed, 77 insertions, 77 deletions
diff --git a/contrib/tools/python3/src/Modules/_io/bytesio.c b/contrib/tools/python3/src/Modules/_io/bytesio.c
index d17e18030d..2468f45f94 100644
--- a/contrib/tools/python3/src/Modules/_io/bytesio.c
+++ b/contrib/tools/python3/src/Modules/_io/bytesio.c
@@ -1,6 +1,6 @@
#include "Python.h"
-#include "pycore_object.h"
-#include <stddef.h> // offsetof()
+#include "pycore_object.h"
+#include <stddef.h> // offsetof()
#include "_iomodule.h"
/*[clinic input]
@@ -31,34 +31,34 @@ typedef struct {
* exports > 0. Py_REFCNT(buf) == 1, any modifications are forbidden.
*/
-static int
-check_closed(bytesio *self)
-{
- if (self->buf == NULL) {
- PyErr_SetString(PyExc_ValueError, "I/O operation on closed file.");
- return 1;
- }
- return 0;
-}
-
-static int
-check_exports(bytesio *self)
-{
- if (self->exports > 0) {
- PyErr_SetString(PyExc_BufferError,
- "Existing exports of data: object cannot be re-sized");
- return 1;
- }
- return 0;
-}
-
+static int
+check_closed(bytesio *self)
+{
+ if (self->buf == NULL) {
+ PyErr_SetString(PyExc_ValueError, "I/O operation on closed file.");
+ return 1;
+ }
+ return 0;
+}
+
+static int
+check_exports(bytesio *self)
+{
+ if (self->exports > 0) {
+ PyErr_SetString(PyExc_BufferError,
+ "Existing exports of data: object cannot be re-sized");
+ return 1;
+ }
+ return 0;
+}
+
#define CHECK_CLOSED(self) \
- if (check_closed(self)) { \
+ if (check_closed(self)) { \
return NULL; \
}
#define CHECK_EXPORTS(self) \
- if (check_exports(self)) { \
+ if (check_exports(self)) { \
return NULL; \
}
@@ -173,41 +173,41 @@ resize_buffer(bytesio *self, size_t size)
}
/* Internal routine for writing a string of bytes to the buffer of a BytesIO
- object. Returns the number of bytes written, or -1 on error.
- Inlining is disabled because it's significantly decreases performance
- of writelines() in PGO build. */
-_Py_NO_INLINE static Py_ssize_t
-write_bytes(bytesio *self, PyObject *b)
+ object. Returns the number of bytes written, or -1 on error.
+ Inlining is disabled because it's significantly decreases performance
+ of writelines() in PGO build. */
+_Py_NO_INLINE static Py_ssize_t
+write_bytes(bytesio *self, PyObject *b)
{
- if (check_closed(self)) {
- return -1;
- }
- if (check_exports(self)) {
- return -1;
- }
-
- Py_buffer buf;
- if (PyObject_GetBuffer(b, &buf, PyBUF_CONTIG_RO) < 0) {
- return -1;
- }
- Py_ssize_t len = buf.len;
- if (len == 0) {
- goto done;
- }
-
+ if (check_closed(self)) {
+ return -1;
+ }
+ if (check_exports(self)) {
+ return -1;
+ }
+
+ Py_buffer buf;
+ if (PyObject_GetBuffer(b, &buf, PyBUF_CONTIG_RO) < 0) {
+ return -1;
+ }
+ Py_ssize_t len = buf.len;
+ if (len == 0) {
+ goto done;
+ }
+
assert(self->pos >= 0);
- size_t endpos = (size_t)self->pos + len;
+ size_t endpos = (size_t)self->pos + len;
if (endpos > (size_t)PyBytes_GET_SIZE(self->buf)) {
- if (resize_buffer(self, endpos) < 0) {
- len = -1;
- goto done;
- }
+ if (resize_buffer(self, endpos) < 0) {
+ len = -1;
+ goto done;
+ }
}
else if (SHARED_BUF(self)) {
- if (unshare_buffer(self, Py_MAX(endpos, (size_t)self->string_size)) < 0) {
- len = -1;
- goto done;
- }
+ if (unshare_buffer(self, Py_MAX(endpos, (size_t)self->string_size)) < 0) {
+ len = -1;
+ goto done;
+ }
}
if (self->pos > self->string_size) {
@@ -225,7 +225,7 @@ write_bytes(bytesio *self, PyObject *b)
/* Copy the data to the internal buffer, overwriting some of the existing
data if self->pos < self->string_size. */
- memcpy(PyBytes_AS_STRING(self->buf) + self->pos, buf.buf, len);
+ memcpy(PyBytes_AS_STRING(self->buf) + self->pos, buf.buf, len);
self->pos = endpos;
/* Set the new length of the internal string if it has changed. */
@@ -233,8 +233,8 @@ write_bytes(bytesio *self, PyObject *b)
self->string_size = endpos;
}
- done:
- PyBuffer_Release(&buf);
+ done:
+ PyBuffer_Release(&buf);
return len;
}
@@ -393,7 +393,7 @@ _io_BytesIO_tell_impl(bytesio *self)
static PyObject *
read_bytes(bytesio *self, Py_ssize_t size)
{
- const char *output;
+ const char *output;
assert(self->buf != NULL);
assert(size <= self->string_size);
@@ -502,7 +502,7 @@ _io_BytesIO_readlines_impl(bytesio *self, PyObject *arg)
{
Py_ssize_t maxsize, size, n;
PyObject *result, *line;
- const char *output;
+ const char *output;
CHECK_CLOSED(self);
@@ -706,7 +706,7 @@ static PyObject *
_io_BytesIO_write(bytesio *self, PyObject *b)
/*[clinic end generated code: output=53316d99800a0b95 input=f5ec7c8c64ed720a]*/
{
- Py_ssize_t n = write_bytes(self, b);
+ Py_ssize_t n = write_bytes(self, b);
return n >= 0 ? PyLong_FromSsize_t(n) : NULL;
}
@@ -735,9 +735,9 @@ _io_BytesIO_writelines(bytesio *self, PyObject *lines)
return NULL;
while ((item = PyIter_Next(it)) != NULL) {
- Py_ssize_t ret = write_bytes(self, item);
+ Py_ssize_t ret = write_bytes(self, item);
Py_DECREF(item);
- if (ret < 0) {
+ if (ret < 0) {
Py_DECREF(it);
return NULL;
}
@@ -782,7 +782,7 @@ _io_BytesIO_close_impl(bytesio *self)
*/
static PyObject *
-bytesio_getstate(bytesio *self, PyObject *Py_UNUSED(ignored))
+bytesio_getstate(bytesio *self, PyObject *Py_UNUSED(ignored))
{
PyObject *initvalue = _io_BytesIO_getvalue_impl(self);
PyObject *dict;
@@ -841,7 +841,7 @@ bytesio_setstate(bytesio *self, PyObject *state)
/* Set carefully the position value. Alternatively, we could use the seek
method instead of modifying self->pos directly to better protect the
- object internal state against erroneous (or malicious) inputs. */
+ object internal state against erroneous (or malicious) inputs. */
position_obj = PyTuple_GET_ITEM(state, 1);
if (!PyLong_Check(position_obj)) {
PyErr_Format(PyExc_TypeError,
@@ -966,13 +966,13 @@ bytesio_sizeof(bytesio *self, void *unused)
Py_ssize_t res;
res = _PyObject_SIZE(Py_TYPE(self));
- if (self->buf && !SHARED_BUF(self)) {
- Py_ssize_t s = _PySys_GetSizeOf(self->buf);
- if (s == -1) {
- return NULL;
- }
- res += s;
- }
+ if (self->buf && !SHARED_BUF(self)) {
+ Py_ssize_t s = _PySys_GetSizeOf(self->buf);
+ if (s == -1) {
+ return NULL;
+ }
+ res += s;
+ }
return PyLong_FromSsize_t(res);
}
@@ -1030,10 +1030,10 @@ PyTypeObject PyBytesIO_Type = {
sizeof(bytesio), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)bytesio_dealloc, /*tp_dealloc*/
- 0, /*tp_vectorcall_offset*/
+ 0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_as_async*/
+ 0, /*tp_as_async*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
@@ -1124,16 +1124,16 @@ static PyBufferProcs bytesiobuf_as_buffer = {
(releasebufferproc) bytesiobuf_releasebuffer,
};
-Py_EXPORTED_SYMBOL PyTypeObject _PyBytesIOBuffer_Type = {
+Py_EXPORTED_SYMBOL PyTypeObject _PyBytesIOBuffer_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
"_io._BytesIOBuffer", /*tp_name*/
sizeof(bytesiobuf), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)bytesiobuf_dealloc, /*tp_dealloc*/
- 0, /*tp_vectorcall_offset*/
+ 0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_as_async*/
+ 0, /*tp_as_async*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/