Coverage Report

Created: 2026-10-31 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/cpython/Modules/_io/clinic/bytesio.c.h
Line
Count
Source
1
/*[clinic input]
2
preserve
3
[clinic start generated code]*/
4
5
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6
#  include "pycore_gc.h"          // PyGC_Head
7
#  include "pycore_runtime.h"     // _Py_ID()
8
#endif
9
#include "pycore_abstract.h"      // _Py_convert_optional_to_ssize_t()
10
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
11
#include "pycore_modsupport.h"    // _PyArg_CheckPositional()
12
13
PyDoc_STRVAR(_io_BytesIO_closed__doc__,
14
"True if the file is closed.");
15
16
static int
17
_io_BytesIO_closed_get_impl(bytesio *self);
18
19
static PyObject *
20
_io_BytesIO_closed_get(PyObject *self, void *Py_UNUSED(context))
21
0
{
22
0
    PyObject *return_value = NULL;
23
0
    int _return_value;
24
25
0
    Py_BEGIN_CRITICAL_SECTION(self);
26
0
    _return_value = _io_BytesIO_closed_get_impl((bytesio *)self);
27
0
    Py_END_CRITICAL_SECTION();
28
0
    if ((_return_value == -1) && PyErr_Occurred()) {
29
0
        goto exit;
30
0
    }
31
0
    return_value = PyBool_FromLong((long)_return_value);
32
33
0
exit:
34
0
    return return_value;
35
0
}
36
37
PyDoc_STRVAR(_io_BytesIO_readable__doc__,
38
"readable($self, /)\n"
39
"--\n"
40
"\n"
41
"Returns True if the IO object can be read.");
42
43
#define _IO_BYTESIO_READABLE_METHODDEF    \
44
    {"readable", (PyCFunction)_io_BytesIO_readable, METH_NOARGS, _io_BytesIO_readable__doc__},
45
46
static PyObject *
47
_io_BytesIO_readable_impl(bytesio *self);
48
49
static PyObject *
50
_io_BytesIO_readable(PyObject *self, PyObject *Py_UNUSED(ignored))
51
0
{
52
0
    PyObject *return_value = NULL;
53
54
0
    Py_BEGIN_CRITICAL_SECTION(self);
55
0
    return_value = _io_BytesIO_readable_impl((bytesio *)self);
56
0
    Py_END_CRITICAL_SECTION();
57
58
0
    return return_value;
59
0
}
60
61
PyDoc_STRVAR(_io_BytesIO_writable__doc__,
62
"writable($self, /)\n"
63
"--\n"
64
"\n"
65
"Returns True if the IO object can be written.");
66
67
#define _IO_BYTESIO_WRITABLE_METHODDEF    \
68
    {"writable", (PyCFunction)_io_BytesIO_writable, METH_NOARGS, _io_BytesIO_writable__doc__},
69
70
static PyObject *
71
_io_BytesIO_writable_impl(bytesio *self);
72
73
static PyObject *
74
_io_BytesIO_writable(PyObject *self, PyObject *Py_UNUSED(ignored))
75
0
{
76
0
    PyObject *return_value = NULL;
77
78
0
    Py_BEGIN_CRITICAL_SECTION(self);
79
0
    return_value = _io_BytesIO_writable_impl((bytesio *)self);
80
0
    Py_END_CRITICAL_SECTION();
81
82
0
    return return_value;
83
0
}
84
85
PyDoc_STRVAR(_io_BytesIO_seekable__doc__,
86
"seekable($self, /)\n"
87
"--\n"
88
"\n"
89
"Returns True if the IO object can be seeked.");
90
91
#define _IO_BYTESIO_SEEKABLE_METHODDEF    \
92
    {"seekable", (PyCFunction)_io_BytesIO_seekable, METH_NOARGS, _io_BytesIO_seekable__doc__},
93
94
static PyObject *
95
_io_BytesIO_seekable_impl(bytesio *self);
96
97
static PyObject *
98
_io_BytesIO_seekable(PyObject *self, PyObject *Py_UNUSED(ignored))
99
17.2k
{
100
17.2k
    PyObject *return_value = NULL;
101
102
17.2k
    Py_BEGIN_CRITICAL_SECTION(self);
103
17.2k
    return_value = _io_BytesIO_seekable_impl((bytesio *)self);
104
17.2k
    Py_END_CRITICAL_SECTION();
105
106
17.2k
    return return_value;
107
17.2k
}
108
109
PyDoc_STRVAR(_io_BytesIO_flush__doc__,
110
"flush($self, /)\n"
111
"--\n"
112
"\n"
113
"Does nothing.");
114
115
#define _IO_BYTESIO_FLUSH_METHODDEF    \
116
    {"flush", (PyCFunction)_io_BytesIO_flush, METH_NOARGS, _io_BytesIO_flush__doc__},
117
118
static PyObject *
119
_io_BytesIO_flush_impl(bytesio *self);
120
121
static PyObject *
122
_io_BytesIO_flush(PyObject *self, PyObject *Py_UNUSED(ignored))
123
12.3k
{
124
12.3k
    PyObject *return_value = NULL;
125
126
12.3k
    Py_BEGIN_CRITICAL_SECTION(self);
127
12.3k
    return_value = _io_BytesIO_flush_impl((bytesio *)self);
128
12.3k
    Py_END_CRITICAL_SECTION();
129
130
12.3k
    return return_value;
131
12.3k
}
132
133
PyDoc_STRVAR(_io_BytesIO_getbuffer__doc__,
134
"getbuffer($self, /)\n"
135
"--\n"
136
"\n"
137
"Get a read-write view over the contents of the BytesIO object.");
138
139
#define _IO_BYTESIO_GETBUFFER_METHODDEF    \
140
    {"getbuffer", _PyCFunction_CAST(_io_BytesIO_getbuffer), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, _io_BytesIO_getbuffer__doc__},
141
142
static PyObject *
143
_io_BytesIO_getbuffer_impl(bytesio *self, PyTypeObject *cls);
144
145
static PyObject *
146
_io_BytesIO_getbuffer(PyObject *self, PyTypeObject *cls, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
147
0
{
148
0
    PyObject *return_value = NULL;
149
150
0
    if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
151
0
        PyErr_SetString(PyExc_TypeError, "getbuffer() takes no arguments");
152
0
        goto exit;
153
0
    }
154
0
    Py_BEGIN_CRITICAL_SECTION(self);
155
0
    return_value = _io_BytesIO_getbuffer_impl((bytesio *)self, cls);
156
0
    Py_END_CRITICAL_SECTION();
157
158
0
exit:
159
0
    return return_value;
160
0
}
161
162
PyDoc_STRVAR(_io_BytesIO_getvalue__doc__,
163
"getvalue($self, /)\n"
164
"--\n"
165
"\n"
166
"Retrieve the entire contents of the BytesIO object.");
167
168
#define _IO_BYTESIO_GETVALUE_METHODDEF    \
169
    {"getvalue", (PyCFunction)_io_BytesIO_getvalue, METH_NOARGS, _io_BytesIO_getvalue__doc__},
170
171
static PyObject *
172
_io_BytesIO_getvalue_impl(bytesio *self);
173
174
static PyObject *
175
_io_BytesIO_getvalue(PyObject *self, PyObject *Py_UNUSED(ignored))
176
594
{
177
594
    PyObject *return_value = NULL;
178
179
594
    Py_BEGIN_CRITICAL_SECTION(self);
180
594
    return_value = _io_BytesIO_getvalue_impl((bytesio *)self);
181
594
    Py_END_CRITICAL_SECTION();
182
183
594
    return return_value;
184
594
}
185
186
PyDoc_STRVAR(_io_BytesIO_isatty__doc__,
187
"isatty($self, /)\n"
188
"--\n"
189
"\n"
190
"Always returns False.\n"
191
"\n"
192
"BytesIO objects are not connected to a TTY-like device.");
193
194
#define _IO_BYTESIO_ISATTY_METHODDEF    \
195
    {"isatty", (PyCFunction)_io_BytesIO_isatty, METH_NOARGS, _io_BytesIO_isatty__doc__},
196
197
static PyObject *
198
_io_BytesIO_isatty_impl(bytesio *self);
199
200
static PyObject *
201
_io_BytesIO_isatty(PyObject *self, PyObject *Py_UNUSED(ignored))
202
0
{
203
0
    PyObject *return_value = NULL;
204
205
0
    Py_BEGIN_CRITICAL_SECTION(self);
206
0
    return_value = _io_BytesIO_isatty_impl((bytesio *)self);
207
0
    Py_END_CRITICAL_SECTION();
208
209
0
    return return_value;
210
0
}
211
212
PyDoc_STRVAR(_io_BytesIO_tell__doc__,
213
"tell($self, /)\n"
214
"--\n"
215
"\n"
216
"Current file position, an integer.");
217
218
#define _IO_BYTESIO_TELL_METHODDEF    \
219
    {"tell", (PyCFunction)_io_BytesIO_tell, METH_NOARGS, _io_BytesIO_tell__doc__},
220
221
static PyObject *
222
_io_BytesIO_tell_impl(bytesio *self);
223
224
static PyObject *
225
_io_BytesIO_tell(PyObject *self, PyObject *Py_UNUSED(ignored))
226
111k
{
227
111k
    PyObject *return_value = NULL;
228
229
111k
    Py_BEGIN_CRITICAL_SECTION(self);
230
111k
    return_value = _io_BytesIO_tell_impl((bytesio *)self);
231
111k
    Py_END_CRITICAL_SECTION();
232
233
111k
    return return_value;
234
111k
}
235
236
PyDoc_STRVAR(_io_BytesIO_read__doc__,
237
"read($self, size=-1, /)\n"
238
"--\n"
239
"\n"
240
"Read at most size bytes, returned as a bytes object.\n"
241
"\n"
242
"If the size argument is negative, read until EOF is reached.\n"
243
"Return an empty bytes object at EOF.");
244
245
#define _IO_BYTESIO_READ_METHODDEF    \
246
    {"read", _PyCFunction_CAST(_io_BytesIO_read), METH_FASTCALL, _io_BytesIO_read__doc__},
247
248
static PyObject *
249
_io_BytesIO_read_impl(bytesio *self, Py_ssize_t size);
250
251
static PyObject *
252
_io_BytesIO_read(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
253
16.6M
{
254
16.6M
    PyObject *return_value = NULL;
255
16.6M
    Py_ssize_t size = -1;
256
257
16.6M
    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
258
0
        goto exit;
259
0
    }
260
16.6M
    if (nargs < 1) {
261
0
        goto skip_optional;
262
0
    }
263
16.6M
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
264
0
        goto exit;
265
0
    }
266
16.6M
skip_optional:
267
16.6M
    Py_BEGIN_CRITICAL_SECTION(self);
268
16.6M
    return_value = _io_BytesIO_read_impl((bytesio *)self, size);
269
16.6M
    Py_END_CRITICAL_SECTION();
270
271
16.6M
exit:
272
16.6M
    return return_value;
273
16.6M
}
274
275
PyDoc_STRVAR(_io_BytesIO_read1__doc__,
276
"read1($self, size=-1, /)\n"
277
"--\n"
278
"\n"
279
"Read at most size bytes, returned as a bytes object.\n"
280
"\n"
281
"If the size argument is negative or omitted, read until EOF is\n"
282
"reached.  Return an empty bytes object at EOF.");
283
284
#define _IO_BYTESIO_READ1_METHODDEF    \
285
    {"read1", _PyCFunction_CAST(_io_BytesIO_read1), METH_FASTCALL, _io_BytesIO_read1__doc__},
286
287
static PyObject *
288
_io_BytesIO_read1_impl(bytesio *self, Py_ssize_t size);
289
290
static PyObject *
291
_io_BytesIO_read1(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
292
0
{
293
0
    PyObject *return_value = NULL;
294
0
    Py_ssize_t size = -1;
295
296
0
    if (!_PyArg_CheckPositional("read1", nargs, 0, 1)) {
297
0
        goto exit;
298
0
    }
299
0
    if (nargs < 1) {
300
0
        goto skip_optional;
301
0
    }
302
0
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
303
0
        goto exit;
304
0
    }
305
0
skip_optional:
306
0
    Py_BEGIN_CRITICAL_SECTION(self);
307
0
    return_value = _io_BytesIO_read1_impl((bytesio *)self, size);
308
0
    Py_END_CRITICAL_SECTION();
309
310
0
exit:
311
0
    return return_value;
312
0
}
313
314
PyDoc_STRVAR(_io_BytesIO_peek__doc__,
315
"peek($self, size=0, /)\n"
316
"--\n"
317
"\n"
318
"Return bytes from the stream without advancing the position.\n"
319
"\n"
320
"Return an empty bytes object at EOF.");
321
322
#define _IO_BYTESIO_PEEK_METHODDEF    \
323
    {"peek", _PyCFunction_CAST(_io_BytesIO_peek), METH_FASTCALL, _io_BytesIO_peek__doc__},
324
325
static PyObject *
326
_io_BytesIO_peek_impl(bytesio *self, Py_ssize_t size);
327
328
static PyObject *
329
_io_BytesIO_peek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
330
0
{
331
0
    PyObject *return_value = NULL;
332
0
    Py_ssize_t size = 0;
333
334
0
    if (!_PyArg_CheckPositional("peek", nargs, 0, 1)) {
335
0
        goto exit;
336
0
    }
337
0
    if (nargs < 1) {
338
0
        goto skip_optional;
339
0
    }
340
0
    {
341
0
        Py_ssize_t ival = -1;
342
0
        PyObject *iobj = _PyNumber_Index(args[0]);
343
0
        if (iobj != NULL) {
344
0
            ival = PyLong_AsSsize_t(iobj);
345
0
            Py_DECREF(iobj);
346
0
        }
347
0
        if (ival == -1 && PyErr_Occurred()) {
348
0
            goto exit;
349
0
        }
350
0
        size = ival;
351
0
    }
352
0
skip_optional:
353
0
    Py_BEGIN_CRITICAL_SECTION(self);
354
0
    return_value = _io_BytesIO_peek_impl((bytesio *)self, size);
355
0
    Py_END_CRITICAL_SECTION();
356
357
0
exit:
358
0
    return return_value;
359
0
}
360
361
PyDoc_STRVAR(_io_BytesIO_readline__doc__,
362
"readline($self, size=-1, /)\n"
363
"--\n"
364
"\n"
365
"Next line from the file, as a bytes object.\n"
366
"\n"
367
"Retain newline.  A non-negative size argument limits the maximum\n"
368
"number of bytes to return (an incomplete line may be returned then).\n"
369
"Return an empty bytes object at EOF.");
370
371
#define _IO_BYTESIO_READLINE_METHODDEF    \
372
    {"readline", _PyCFunction_CAST(_io_BytesIO_readline), METH_FASTCALL, _io_BytesIO_readline__doc__},
373
374
static PyObject *
375
_io_BytesIO_readline_impl(bytesio *self, Py_ssize_t size);
376
377
static PyObject *
378
_io_BytesIO_readline(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
379
133k
{
380
133k
    PyObject *return_value = NULL;
381
133k
    Py_ssize_t size = -1;
382
383
133k
    if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
384
0
        goto exit;
385
0
    }
386
133k
    if (nargs < 1) {
387
751
        goto skip_optional;
388
751
    }
389
133k
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
390
0
        goto exit;
391
0
    }
392
133k
skip_optional:
393
133k
    Py_BEGIN_CRITICAL_SECTION(self);
394
133k
    return_value = _io_BytesIO_readline_impl((bytesio *)self, size);
395
133k
    Py_END_CRITICAL_SECTION();
396
397
133k
exit:
398
133k
    return return_value;
399
133k
}
400
401
PyDoc_STRVAR(_io_BytesIO_readlines__doc__,
402
"readlines($self, size=None, /)\n"
403
"--\n"
404
"\n"
405
"List of bytes objects, each a line from the file.\n"
406
"\n"
407
"Call readline() repeatedly and return a list of the lines so read.\n"
408
"The optional size argument, if given, is an approximate bound on the\n"
409
"total number of bytes in the lines returned.");
410
411
#define _IO_BYTESIO_READLINES_METHODDEF    \
412
    {"readlines", _PyCFunction_CAST(_io_BytesIO_readlines), METH_FASTCALL, _io_BytesIO_readlines__doc__},
413
414
static PyObject *
415
_io_BytesIO_readlines_impl(bytesio *self, PyObject *arg);
416
417
static PyObject *
418
_io_BytesIO_readlines(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
419
0
{
420
0
    PyObject *return_value = NULL;
421
0
    PyObject *arg = Py_None;
422
423
0
    if (!_PyArg_CheckPositional("readlines", nargs, 0, 1)) {
424
0
        goto exit;
425
0
    }
426
0
    if (nargs < 1) {
427
0
        goto skip_optional;
428
0
    }
429
0
    arg = args[0];
430
0
skip_optional:
431
0
    Py_BEGIN_CRITICAL_SECTION(self);
432
0
    return_value = _io_BytesIO_readlines_impl((bytesio *)self, arg);
433
0
    Py_END_CRITICAL_SECTION();
434
435
0
exit:
436
0
    return return_value;
437
0
}
438
439
PyDoc_STRVAR(_io_BytesIO_readinto__doc__,
440
"readinto($self, buffer, /)\n"
441
"--\n"
442
"\n"
443
"Read bytes into buffer.\n"
444
"\n"
445
"Returns number of bytes read (0 for EOF), or None if the object\n"
446
"is set not to block and has no data to read.");
447
448
#define _IO_BYTESIO_READINTO_METHODDEF    \
449
    {"readinto", (PyCFunction)_io_BytesIO_readinto, METH_O, _io_BytesIO_readinto__doc__},
450
451
static PyObject *
452
_io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer);
453
454
static PyObject *
455
_io_BytesIO_readinto(PyObject *self, PyObject *arg)
456
0
{
457
0
    PyObject *return_value = NULL;
458
0
    Py_buffer buffer = {NULL, NULL};
459
460
0
    if (PyObject_GetBuffer(arg, &buffer, PyBUF_WRITABLE) < 0) {
461
0
        _PyArg_BadArgument("readinto", "argument", "read-write bytes-like object", arg);
462
0
        goto exit;
463
0
    }
464
0
    Py_BEGIN_CRITICAL_SECTION(self);
465
0
    return_value = _io_BytesIO_readinto_impl((bytesio *)self, &buffer);
466
0
    Py_END_CRITICAL_SECTION();
467
468
0
exit:
469
    /* Cleanup for buffer */
470
0
    if (buffer.obj) {
471
0
       PyBuffer_Release(&buffer);
472
0
    }
473
474
0
    return return_value;
475
0
}
476
477
PyDoc_STRVAR(_io_BytesIO_truncate__doc__,
478
"truncate($self, size=None, /)\n"
479
"--\n"
480
"\n"
481
"Truncate the file to at most size bytes.\n"
482
"\n"
483
"Size defaults to the current file position, as returned by tell().\n"
484
"The current file position is unchanged.  Returns the new size.");
485
486
#define _IO_BYTESIO_TRUNCATE_METHODDEF    \
487
    {"truncate", _PyCFunction_CAST(_io_BytesIO_truncate), METH_FASTCALL, _io_BytesIO_truncate__doc__},
488
489
static PyObject *
490
_io_BytesIO_truncate_impl(bytesio *self, PyObject *size);
491
492
static PyObject *
493
_io_BytesIO_truncate(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
494
0
{
495
0
    PyObject *return_value = NULL;
496
0
    PyObject *size = Py_None;
497
498
0
    if (!_PyArg_CheckPositional("truncate", nargs, 0, 1)) {
499
0
        goto exit;
500
0
    }
501
0
    if (nargs < 1) {
502
0
        goto skip_optional;
503
0
    }
504
0
    size = args[0];
505
0
skip_optional:
506
0
    Py_BEGIN_CRITICAL_SECTION(self);
507
0
    return_value = _io_BytesIO_truncate_impl((bytesio *)self, size);
508
0
    Py_END_CRITICAL_SECTION();
509
510
0
exit:
511
0
    return return_value;
512
0
}
513
514
static PyObject *
515
bytesio_iternext_impl(bytesio *self);
516
517
static PyObject *
518
bytesio_iternext(PyObject *self)
519
0
{
520
0
    PyObject *return_value = NULL;
521
522
0
    Py_BEGIN_CRITICAL_SECTION(self);
523
0
    return_value = bytesio_iternext_impl((bytesio *)self);
524
0
    Py_END_CRITICAL_SECTION();
525
526
0
    return return_value;
527
0
}
528
529
PyDoc_STRVAR(_io_BytesIO_seek__doc__,
530
"seek($self, pos, whence=0, /)\n"
531
"--\n"
532
"\n"
533
"Change stream position.\n"
534
"\n"
535
"Seek to byte offset pos relative to position indicated by whence:\n"
536
"     0  Start of stream (the default).  pos should be >= 0;\n"
537
"     1  Current position - pos may be negative;\n"
538
"     2  End of stream - pos usually negative.\n"
539
"Returns the new absolute position.");
540
541
#define _IO_BYTESIO_SEEK_METHODDEF    \
542
    {"seek", _PyCFunction_CAST(_io_BytesIO_seek), METH_FASTCALL, _io_BytesIO_seek__doc__},
543
544
static PyObject *
545
_io_BytesIO_seek_impl(bytesio *self, Py_ssize_t pos, int whence);
546
547
static PyObject *
548
_io_BytesIO_seek(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
549
164k
{
550
164k
    PyObject *return_value = NULL;
551
164k
    Py_ssize_t pos;
552
164k
    int whence = 0;
553
554
164k
    if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
555
0
        goto exit;
556
0
    }
557
164k
    {
558
164k
        Py_ssize_t ival = -1;
559
164k
        PyObject *iobj = _PyNumber_Index(args[0]);
560
164k
        if (iobj != NULL) {
561
164k
            ival = PyLong_AsSsize_t(iobj);
562
164k
            Py_DECREF(iobj);
563
164k
        }
564
164k
        if (ival == -1 && PyErr_Occurred()) {
565
130
            goto exit;
566
130
        }
567
164k
        pos = ival;
568
164k
    }
569
164k
    if (nargs < 2) {
570
126k
        goto skip_optional;
571
126k
    }
572
37.7k
    whence = PyLong_AsInt(args[1]);
573
37.7k
    if (whence == -1 && PyErr_Occurred()) {
574
0
        goto exit;
575
0
    }
576
164k
skip_optional:
577
164k
    Py_BEGIN_CRITICAL_SECTION(self);
578
164k
    return_value = _io_BytesIO_seek_impl((bytesio *)self, pos, whence);
579
164k
    Py_END_CRITICAL_SECTION();
580
581
164k
exit:
582
164k
    return return_value;
583
164k
}
584
585
PyDoc_STRVAR(_io_BytesIO_write__doc__,
586
"write($self, b, /)\n"
587
"--\n"
588
"\n"
589
"Write bytes to file.\n"
590
"\n"
591
"Return the number of bytes written.");
592
593
#define _IO_BYTESIO_WRITE_METHODDEF    \
594
    {"write", (PyCFunction)_io_BytesIO_write, METH_O, _io_BytesIO_write__doc__},
595
596
static PyObject *
597
_io_BytesIO_write_impl(bytesio *self, PyObject *b);
598
599
static PyObject *
600
_io_BytesIO_write(PyObject *self, PyObject *b)
601
75.4k
{
602
75.4k
    PyObject *return_value = NULL;
603
604
75.4k
    Py_BEGIN_CRITICAL_SECTION(self);
605
75.4k
    return_value = _io_BytesIO_write_impl((bytesio *)self, b);
606
75.4k
    Py_END_CRITICAL_SECTION();
607
608
75.4k
    return return_value;
609
75.4k
}
610
611
PyDoc_STRVAR(_io_BytesIO_writelines__doc__,
612
"writelines($self, lines, /)\n"
613
"--\n"
614
"\n"
615
"Write lines to the file.\n"
616
"\n"
617
"Note that newlines are not added.  lines can be any iterable object\n"
618
"producing bytes-like objects.  This is equivalent to calling write()\n"
619
"for each element.");
620
621
#define _IO_BYTESIO_WRITELINES_METHODDEF    \
622
    {"writelines", (PyCFunction)_io_BytesIO_writelines, METH_O, _io_BytesIO_writelines__doc__},
623
624
static PyObject *
625
_io_BytesIO_writelines_impl(bytesio *self, PyObject *lines);
626
627
static PyObject *
628
_io_BytesIO_writelines(PyObject *self, PyObject *lines)
629
0
{
630
0
    PyObject *return_value = NULL;
631
632
0
    Py_BEGIN_CRITICAL_SECTION(self);
633
0
    return_value = _io_BytesIO_writelines_impl((bytesio *)self, lines);
634
0
    Py_END_CRITICAL_SECTION();
635
636
0
    return return_value;
637
0
}
638
639
PyDoc_STRVAR(_io_BytesIO_close__doc__,
640
"close($self, /)\n"
641
"--\n"
642
"\n"
643
"Disable all I/O operations.");
644
645
#define _IO_BYTESIO_CLOSE_METHODDEF    \
646
    {"close", (PyCFunction)_io_BytesIO_close, METH_NOARGS, _io_BytesIO_close__doc__},
647
648
static PyObject *
649
_io_BytesIO_close_impl(bytesio *self);
650
651
static PyObject *
652
_io_BytesIO_close(PyObject *self, PyObject *Py_UNUSED(ignored))
653
9.92k
{
654
9.92k
    PyObject *return_value = NULL;
655
656
9.92k
    Py_BEGIN_CRITICAL_SECTION(self);
657
9.92k
    return_value = _io_BytesIO_close_impl((bytesio *)self);
658
9.92k
    Py_END_CRITICAL_SECTION();
659
660
9.92k
    return return_value;
661
9.92k
}
662
663
PyDoc_STRVAR(_io_BytesIO___getstate____doc__,
664
"__getstate__($self, /)\n"
665
"--\n"
666
"\n");
667
668
#define _IO_BYTESIO___GETSTATE___METHODDEF    \
669
    {"__getstate__", (PyCFunction)_io_BytesIO___getstate__, METH_NOARGS, _io_BytesIO___getstate____doc__},
670
671
static PyObject *
672
_io_BytesIO___getstate___impl(bytesio *self);
673
674
static PyObject *
675
_io_BytesIO___getstate__(PyObject *self, PyObject *Py_UNUSED(ignored))
676
0
{
677
0
    PyObject *return_value = NULL;
678
679
0
    Py_BEGIN_CRITICAL_SECTION(self);
680
0
    return_value = _io_BytesIO___getstate___impl((bytesio *)self);
681
0
    Py_END_CRITICAL_SECTION();
682
683
0
    return return_value;
684
0
}
685
686
PyDoc_STRVAR(_io_BytesIO___setstate____doc__,
687
"__setstate__($self, state, /)\n"
688
"--\n"
689
"\n");
690
691
#define _IO_BYTESIO___SETSTATE___METHODDEF    \
692
    {"__setstate__", (PyCFunction)_io_BytesIO___setstate__, METH_O, _io_BytesIO___setstate____doc__},
693
694
static PyObject *
695
_io_BytesIO___setstate___impl(bytesio *self, PyObject *state);
696
697
static PyObject *
698
_io_BytesIO___setstate__(PyObject *self, PyObject *state)
699
0
{
700
0
    PyObject *return_value = NULL;
701
702
0
    Py_BEGIN_CRITICAL_SECTION(self);
703
0
    return_value = _io_BytesIO___setstate___impl((bytesio *)self, state);
704
0
    Py_END_CRITICAL_SECTION();
705
706
0
    return return_value;
707
0
}
708
709
PyDoc_STRVAR(_io_BytesIO___init____doc__,
710
"BytesIO(initial_bytes=b\'\')\n"
711
"--\n"
712
"\n"
713
"Buffered I/O implementation using an in-memory bytes buffer.");
714
715
static int
716
_io_BytesIO___init___impl(bytesio *self, PyObject *initvalue);
717
718
static int
719
_io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
720
55.0k
{
721
55.0k
    int return_value = -1;
722
55.0k
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
723
724
55.0k
    #define NUM_KEYWORDS 1
725
55.0k
    static struct {
726
55.0k
        PyGC_Head _this_is_not_used;
727
55.0k
        PyObject_VAR_HEAD
728
55.0k
        Py_hash_t ob_hash;
729
55.0k
        PyObject *ob_item[NUM_KEYWORDS];
730
55.0k
    } _kwtuple = {
731
55.0k
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
732
55.0k
        .ob_hash = -1,
733
55.0k
        .ob_item = { &_Py_ID(initial_bytes), },
734
55.0k
    };
735
55.0k
    #undef NUM_KEYWORDS
736
55.0k
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
737
738
    #else  // !Py_BUILD_CORE
739
    #  define KWTUPLE NULL
740
    #endif  // !Py_BUILD_CORE
741
742
55.0k
    static const char * const _keywords[] = {"initial_bytes", NULL};
743
55.0k
    static _PyArg_Parser _parser = {
744
55.0k
        .keywords = _keywords,
745
55.0k
        .fname = "BytesIO",
746
55.0k
        .kwtuple = KWTUPLE,
747
55.0k
    };
748
55.0k
    #undef KWTUPLE
749
55.0k
    PyObject *argsbuf[1];
750
55.0k
    PyObject * const *fastargs;
751
55.0k
    Py_ssize_t nargs = PyTuple_GET_SIZE(args);
752
55.0k
    Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
753
55.0k
    PyObject *initvalue = NULL;
754
755
55.0k
    fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
756
55.0k
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
757
55.0k
    if (!fastargs) {
758
0
        goto exit;
759
0
    }
760
55.0k
    if (!noptargs) {
761
6.12k
        goto skip_optional_pos;
762
6.12k
    }
763
48.9k
    initvalue = fastargs[0];
764
55.0k
skip_optional_pos:
765
55.0k
    Py_BEGIN_CRITICAL_SECTION(self);
766
55.0k
    return_value = _io_BytesIO___init___impl((bytesio *)self, initvalue);
767
55.0k
    Py_END_CRITICAL_SECTION();
768
769
55.0k
exit:
770
55.0k
    return return_value;
771
55.0k
}
772
773
PyDoc_STRVAR(_io_BytesIO___sizeof____doc__,
774
"__sizeof__($self, /)\n"
775
"--\n"
776
"\n"
777
"Size of object in memory, in bytes.");
778
779
#define _IO_BYTESIO___SIZEOF___METHODDEF    \
780
    {"__sizeof__", (PyCFunction)_io_BytesIO___sizeof__, METH_NOARGS, _io_BytesIO___sizeof____doc__},
781
782
static PyObject *
783
_io_BytesIO___sizeof___impl(bytesio *self);
784
785
static PyObject *
786
_io_BytesIO___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
787
0
{
788
0
    PyObject *return_value = NULL;
789
790
0
    Py_BEGIN_CRITICAL_SECTION(self);
791
0
    return_value = _io_BytesIO___sizeof___impl((bytesio *)self);
792
0
    Py_END_CRITICAL_SECTION();
793
794
0
    return return_value;
795
0
}
796
#define _IO_BYTESIO_CLOSED_GETSETDEF {"closed", (getter)_io_BytesIO_closed_get, (setter)NULL, _io_BytesIO_closed__doc__},
797
798
/*[clinic end generated code: output=a2bc96c358d6e240 input=a9049054013a1b77]*/