Coverage Report

Created: 2026-12-01 06:09

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
#endif
8
#include "pycore_abstract.h"      // _Py_convert_optional_to_ssize_t()
9
#include "pycore_critical_section.h"// Py_BEGIN_CRITICAL_SECTION()
10
#include "pycore_modsupport.h"    // _PyArg_CheckPositional()
11
#include "pycore_runtime.h"       // _Py_SINGLETON()
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
19.9k
{
100
19.9k
    PyObject *return_value = NULL;
101
102
19.9k
    Py_BEGIN_CRITICAL_SECTION(self);
103
19.9k
    return_value = _io_BytesIO_seekable_impl((bytesio *)self);
104
19.9k
    Py_END_CRITICAL_SECTION();
105
106
19.9k
    return return_value;
107
19.9k
}
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
10.0k
{
124
10.0k
    PyObject *return_value = NULL;
125
126
10.0k
    Py_BEGIN_CRITICAL_SECTION(self);
127
10.0k
    return_value = _io_BytesIO_flush_impl((bytesio *)self);
128
10.0k
    Py_END_CRITICAL_SECTION();
129
130
10.0k
    return return_value;
131
10.0k
}
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
606
{
177
606
    PyObject *return_value = NULL;
178
179
606
    Py_BEGIN_CRITICAL_SECTION(self);
180
606
    return_value = _io_BytesIO_getvalue_impl((bytesio *)self);
181
606
    Py_END_CRITICAL_SECTION();
182
183
606
    return return_value;
184
606
}
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
105k
{
227
105k
    PyObject *return_value = NULL;
228
229
105k
    Py_BEGIN_CRITICAL_SECTION(self);
230
105k
    return_value = _io_BytesIO_tell_impl((bytesio *)self);
231
105k
    Py_END_CRITICAL_SECTION();
232
233
105k
    return return_value;
234
105k
}
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
18.9M
{
254
18.9M
    PyObject *return_value = NULL;
255
18.9M
    Py_ssize_t size = -1;
256
257
18.9M
    if (!_PyArg_CheckPositional("read", nargs, 0, 1)) {
258
0
        goto exit;
259
0
    }
260
18.9M
    if (nargs < 1) {
261
0
        goto skip_optional;
262
0
    }
263
18.9M
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
264
0
        goto exit;
265
0
    }
266
18.9M
skip_optional:
267
18.9M
    Py_BEGIN_CRITICAL_SECTION(self);
268
18.9M
    return_value = _io_BytesIO_read_impl((bytesio *)self, size);
269
18.9M
    Py_END_CRITICAL_SECTION();
270
271
18.9M
exit:
272
18.9M
    return return_value;
273
18.9M
}
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
136k
{
380
136k
    PyObject *return_value = NULL;
381
136k
    Py_ssize_t size = -1;
382
383
136k
    if (!_PyArg_CheckPositional("readline", nargs, 0, 1)) {
384
0
        goto exit;
385
0
    }
386
136k
    if (nargs < 1) {
387
736
        goto skip_optional;
388
736
    }
389
136k
    if (!_Py_convert_optional_to_ssize_t(args[0], &size)) {
390
0
        goto exit;
391
0
    }
392
136k
skip_optional:
393
136k
    Py_BEGIN_CRITICAL_SECTION(self);
394
136k
    return_value = _io_BytesIO_readline_impl((bytesio *)self, size);
395
136k
    Py_END_CRITICAL_SECTION();
396
397
136k
exit:
398
136k
    return return_value;
399
136k
}
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
157k
{
550
157k
    PyObject *return_value = NULL;
551
157k
    Py_ssize_t pos;
552
157k
    int whence = 0;
553
554
157k
    if (!_PyArg_CheckPositional("seek", nargs, 1, 2)) {
555
0
        goto exit;
556
0
    }
557
157k
    {
558
157k
        Py_ssize_t ival = -1;
559
157k
        PyObject *iobj = _PyNumber_Index(args[0]);
560
157k
        if (iobj != NULL) {
561
157k
            ival = PyLong_AsSsize_t(iobj);
562
157k
            Py_DECREF(iobj);
563
157k
        }
564
157k
        if (ival == -1 && PyErr_Occurred()) {
565
115
            goto exit;
566
115
        }
567
157k
        pos = ival;
568
157k
    }
569
157k
    if (nargs < 2) {
570
116k
        goto skip_optional;
571
116k
    }
572
41.2k
    whence = PyLong_AsInt(args[1]);
573
41.2k
    if (whence == -1 && PyErr_Occurred()) {
574
0
        goto exit;
575
0
    }
576
157k
skip_optional:
577
157k
    Py_BEGIN_CRITICAL_SECTION(self);
578
157k
    return_value = _io_BytesIO_seek_impl((bytesio *)self, pos, whence);
579
157k
    Py_END_CRITICAL_SECTION();
580
581
157k
exit:
582
157k
    return return_value;
583
157k
}
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
15.9k
{
602
15.9k
    PyObject *return_value = NULL;
603
604
15.9k
    Py_BEGIN_CRITICAL_SECTION(self);
605
15.9k
    return_value = _io_BytesIO_write_impl((bytesio *)self, b);
606
15.9k
    Py_END_CRITICAL_SECTION();
607
608
15.9k
    return return_value;
609
15.9k
}
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
10.1k
{
654
10.1k
    PyObject *return_value = NULL;
655
656
10.1k
    Py_BEGIN_CRITICAL_SECTION(self);
657
10.1k
    return_value = _io_BytesIO_close_impl((bytesio *)self);
658
10.1k
    Py_END_CRITICAL_SECTION();
659
660
10.1k
    return return_value;
661
10.1k
}
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___helper(PyObject *self, PyObject *const *args,
720
    Py_ssize_t nargs, Py_ssize_t nkw, PyObject *kwargs, PyObject *kwnames)
721
0
{
722
0
    int return_value = -1;
723
0
    #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
724
725
0
    #define NUM_KEYWORDS 1
726
0
    static struct {
727
0
        PyGC_Head _this_is_not_used;
728
0
        PyObject_VAR_HEAD
729
0
        Py_hash_t ob_hash;
730
0
        PyObject *ob_item[NUM_KEYWORDS];
731
0
    } _kwtuple = {
732
0
        .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
733
0
        .ob_hash = -1,
734
0
        .ob_item = { &_Py_ID(initial_bytes), },
735
0
    };
736
0
    #undef NUM_KEYWORDS
737
0
    #define KWTUPLE (&_kwtuple.ob_base.ob_base)
738
739
    #else  // !Py_BUILD_CORE
740
    #  define KWTUPLE NULL
741
    #endif  // !Py_BUILD_CORE
742
743
0
    static const char * const _keywords[] = {"initial_bytes", NULL};
744
0
    static _PyArg_Parser _parser = {
745
0
        .keywords = _keywords,
746
0
        .fname = "BytesIO",
747
0
        .kwtuple = KWTUPLE,
748
0
    };
749
0
    #undef KWTUPLE
750
0
    PyObject *argsbuf[1];
751
0
    PyObject * const *fastargs;
752
0
    Py_ssize_t noptargs = nargs + nkw - 0;
753
0
    PyObject *initvalue = NULL;
754
755
0
    fastargs = _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, &_parser,
756
0
            /*minpos*/ 0, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
757
0
    if (!fastargs) {
758
0
        goto exit;
759
0
    }
760
0
    if (!noptargs) {
761
0
        goto skip_optional_pos;
762
0
    }
763
0
    initvalue = fastargs[0];
764
0
skip_optional_pos:
765
0
    Py_BEGIN_CRITICAL_SECTION(self);
766
0
    return_value = _io_BytesIO___init___impl((bytesio *)self, initvalue);
767
0
    Py_END_CRITICAL_SECTION();
768
769
0
exit:
770
0
    return return_value;
771
0
}
772
773
static int
774
_io_BytesIO___init__(PyObject *self, PyObject *args, PyObject *kwargs)
775
0
{
776
0
    return _io_BytesIO___init___helper(self, _PyTuple_CAST(args)->ob_item,
777
0
        PyTuple_GET_SIZE(args),
778
0
        kwargs ? PyDict_GET_SIZE(kwargs) : 0,
779
0
        kwargs, NULL);
780
0
}
781
782
static PyObject *
783
_io_BytesIO_vectorcall(PyObject *type, PyObject *const *args,
784
    size_t nargsf, PyObject *kwnames)
785
58.8k
{
786
58.8k
    PyObject *return_value = NULL;
787
58.8k
    Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
788
58.8k
    PyObject *self;
789
58.8k
    int _result;
790
58.8k
    PyObject *initvalue = NULL;
791
792
58.8k
    assert(_PyType_CAST(type)->tp_init == _io_BytesIO___init__);
793
    /* Make sure the type object is immutable: the generated
794
     * vectorcall doesn't deal e.g. with users reassigning __init__. */
795
58.8k
    assert(PyType_HasFeature(_PyType_CAST(type), Py_TPFLAGS_IMMUTABLETYPE));
796
58.8k
    if (kwnames != NULL || nargs > 1) {
797
0
        self = _PyType_CAST(type)->tp_new(_PyType_CAST(type),
798
0
            (PyObject *)&_Py_SINGLETON(tuple_empty), NULL);
799
0
        if (self == NULL) {
800
0
            return NULL;
801
0
        }
802
0
        _result = _io_BytesIO___init___helper(self, args, nargs,
803
0
            kwnames ? PyTuple_GET_SIZE(kwnames) : 0,
804
0
            NULL, kwnames);
805
0
        if (_result != 0) {
806
0
            Py_DECREF(self);
807
0
            return NULL;
808
0
        }
809
0
        return self;
810
0
    }
811
58.8k
    if (nargs < 1) {
812
4.01k
        goto skip_optional;
813
4.01k
    }
814
54.7k
    initvalue = args[0];
815
58.8k
skip_optional:
816
58.8k
    self = _PyType_CAST(type)->tp_new(_PyType_CAST(type),
817
58.8k
        (PyObject *)&_Py_SINGLETON(tuple_empty), NULL);
818
58.8k
    if (self == NULL) {
819
0
        goto exit;
820
0
    }
821
58.8k
    Py_BEGIN_CRITICAL_SECTION(self);
822
58.8k
    _result = _io_BytesIO___init___impl((bytesio *)self, initvalue);
823
58.8k
    Py_END_CRITICAL_SECTION();
824
58.8k
    if (_result != 0) {
825
0
        Py_DECREF(self);
826
0
        goto exit;
827
0
    }
828
58.8k
    return_value = self;
829
830
58.8k
exit:
831
58.8k
    return return_value;
832
58.8k
}
833
834
PyDoc_STRVAR(_io_BytesIO___sizeof____doc__,
835
"__sizeof__($self, /)\n"
836
"--\n"
837
"\n"
838
"Size of object in memory, in bytes.");
839
840
#define _IO_BYTESIO___SIZEOF___METHODDEF    \
841
    {"__sizeof__", (PyCFunction)_io_BytesIO___sizeof__, METH_NOARGS, _io_BytesIO___sizeof____doc__},
842
843
static PyObject *
844
_io_BytesIO___sizeof___impl(bytesio *self);
845
846
static PyObject *
847
_io_BytesIO___sizeof__(PyObject *self, PyObject *Py_UNUSED(ignored))
848
0
{
849
0
    PyObject *return_value = NULL;
850
851
0
    Py_BEGIN_CRITICAL_SECTION(self);
852
0
    return_value = _io_BytesIO___sizeof___impl((bytesio *)self);
853
0
    Py_END_CRITICAL_SECTION();
854
855
0
    return return_value;
856
0
}
857
#define _IO_BYTESIO_CLOSED_GETSETDEF {"closed", (getter)_io_BytesIO_closed_get, (setter)NULL, _io_BytesIO_closed__doc__},
858
859
/*[clinic end generated code: output=b9d367ad8e0b44d2 input=a9049054013a1b77]*/