@@ -332,41 +332,49 @@ _enter_buffered_busy(buffered *self)
332
332
PyThread_release_lock(self->lock); \
333
333
} while(0);
334
334
335
- #define CHECK_INITIALIZED (self ) \
336
- if (self->ok <= 0) { \
337
- if (self->detached) { \
338
- PyErr_SetString(PyExc_ValueError, \
339
- "raw stream has been detached"); \
340
- } else { \
341
- PyErr_SetString(PyExc_ValueError, \
342
- "I/O operation on uninitialized object"); \
343
- } \
344
- return NULL; \
345
- }
346
-
347
- #define CHECK_INITIALIZED_INT (self ) \
348
- if (self->ok <= 0) { \
349
- if (self->detached) { \
350
- PyErr_SetString(PyExc_ValueError, \
351
- "raw stream has been detached"); \
352
- } else { \
353
- PyErr_SetString(PyExc_ValueError, \
354
- "I/O operation on uninitialized object"); \
355
- } \
356
- return -1; \
357
- }
335
+ #define CHECK_INITIALIZED (self ) \
336
+ do { \
337
+ if (self->ok <= 0) { \
338
+ if (self->detached) { \
339
+ PyErr_SetString(PyExc_ValueError, \
340
+ "raw stream has been detached"); \
341
+ } else { \
342
+ PyErr_SetString(PyExc_ValueError, \
343
+ "I/O operation on uninitialized object"); \
344
+ } \
345
+ return NULL; \
346
+ } \
347
+ } while (0)
348
+
349
+ #define CHECK_INITIALIZED_INT (self ) \
350
+ do { \
351
+ if (self->ok <= 0) { \
352
+ if (self->detached) { \
353
+ PyErr_SetString(PyExc_ValueError, \
354
+ "raw stream has been detached"); \
355
+ } else { \
356
+ PyErr_SetString(PyExc_ValueError, \
357
+ "I/O operation on uninitialized object"); \
358
+ } \
359
+ return -1; \
360
+ } \
361
+ } while (0)
358
362
359
363
#define IS_CLOSED (self ) \
360
364
(!self->buffer || \
361
365
(self->fast_closed_checks \
362
366
? _PyFileIO_closed(self->raw) \
363
367
: buffered_closed(self)))
364
368
365
- #define CHECK_CLOSED (self , error_msg ) \
366
- if (IS_CLOSED(self) && (Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t) == 0)) { \
367
- PyErr_SetString(PyExc_ValueError, error_msg); \
368
- return NULL; \
369
- } \
369
+ #define CHECK_CLOSED (self , error_msg ) \
370
+ do { \
371
+ if (IS_CLOSED(self) \
372
+ && (Py_SAFE_DOWNCAST(READAHEAD(self), Py_off_t, Py_ssize_t) == 0)) \
373
+ { \
374
+ PyErr_SetString(PyExc_ValueError, error_msg); \
375
+ return NULL; \
376
+ } \
377
+ } while (0)
370
378
371
379
#define VALID_READ_BUFFER (self ) \
372
380
(self->readable && self->read_end != -1)
@@ -498,7 +506,7 @@ static PyObject *
498
506
_io__Buffered_simple_flush_impl (buffered * self )
499
507
/*[clinic end generated code: output=29ebb3820db1bdfd input=5248cb84a65f80bd]*/
500
508
{
501
- CHECK_INITIALIZED (self )
509
+ CHECK_INITIALIZED (self );
502
510
return PyObject_CallMethodNoArgs (self -> raw , & _Py_ID (flush ));
503
511
}
504
512
@@ -507,7 +515,7 @@ buffered_closed(buffered *self)
507
515
{
508
516
int closed ;
509
517
PyObject * res ;
510
- CHECK_INITIALIZED_INT (self )
518
+ CHECK_INITIALIZED_INT (self );
511
519
res = PyObject_GetAttr (self -> raw , & _Py_ID (closed ));
512
520
if (res == NULL )
513
521
return -1 ;
@@ -526,7 +534,7 @@ static PyObject *
526
534
_io__Buffered_closed_get_impl (buffered * self )
527
535
/*[clinic end generated code: output=f08ce57290703a1a input=18eddefdfe4a3d2f]*/
528
536
{
529
- CHECK_INITIALIZED (self )
537
+ CHECK_INITIALIZED (self );
530
538
return PyObject_GetAttr (self -> raw , & _Py_ID (closed ));
531
539
}
532
540
@@ -542,7 +550,7 @@ _io__Buffered_close_impl(buffered *self)
542
550
PyObject * res = NULL ;
543
551
int r ;
544
552
545
- CHECK_INITIALIZED (self )
553
+ CHECK_INITIALIZED (self );
546
554
if (!ENTER_BUFFERED (self )) {
547
555
return NULL ;
548
556
}
@@ -603,7 +611,7 @@ _io__Buffered_detach_impl(buffered *self)
603
611
/*[clinic end generated code: output=dd0fc057b8b779f7 input=d4ef1828a678be37]*/
604
612
{
605
613
PyObject * raw ;
606
- CHECK_INITIALIZED (self )
614
+ CHECK_INITIALIZED (self );
607
615
if (_PyFile_Flush ((PyObject * )self ) < 0 ) {
608
616
return NULL ;
609
617
}
@@ -625,7 +633,7 @@ static PyObject *
625
633
_io__Buffered_seekable_impl (buffered * self )
626
634
/*[clinic end generated code: output=90172abb5ceb6e8f input=e3a4fc1d297b2fd3]*/
627
635
{
628
- CHECK_INITIALIZED (self )
636
+ CHECK_INITIALIZED (self );
629
637
return PyObject_CallMethodNoArgs (self -> raw , & _Py_ID (seekable ));
630
638
}
631
639
@@ -638,7 +646,7 @@ static PyObject *
638
646
_io__Buffered_readable_impl (buffered * self )
639
647
/*[clinic end generated code: output=92afa07661ecb698 input=abe54107d59bca9a]*/
640
648
{
641
- CHECK_INITIALIZED (self )
649
+ CHECK_INITIALIZED (self );
642
650
return PyObject_CallMethodNoArgs (self -> raw , & _Py_ID (readable ));
643
651
}
644
652
@@ -651,7 +659,7 @@ static PyObject *
651
659
_io__Buffered_writable_impl (buffered * self )
652
660
/*[clinic end generated code: output=4e3eee8d6f9d8552 input=45eb76bf6a10e6f7]*/
653
661
{
654
- CHECK_INITIALIZED (self )
662
+ CHECK_INITIALIZED (self );
655
663
return PyObject_CallMethodNoArgs (self -> raw , & _Py_ID (writable ));
656
664
}
657
665
@@ -666,7 +674,7 @@ static PyObject *
666
674
_io__Buffered_name_get_impl (buffered * self )
667
675
/*[clinic end generated code: output=d2adf384051d3d10 input=6b84a0e6126f545e]*/
668
676
{
669
- CHECK_INITIALIZED (self )
677
+ CHECK_INITIALIZED (self );
670
678
return PyObject_GetAttr (self -> raw , & _Py_ID (name ));
671
679
}
672
680
@@ -680,7 +688,7 @@ static PyObject *
680
688
_io__Buffered_mode_get_impl (buffered * self )
681
689
/*[clinic end generated code: output=0feb205748892fa4 input=0762d5e28542fd8c]*/
682
690
{
683
- CHECK_INITIALIZED (self )
691
+ CHECK_INITIALIZED (self );
684
692
return PyObject_GetAttr (self -> raw , & _Py_ID (mode ));
685
693
}
686
694
@@ -695,7 +703,7 @@ static PyObject *
695
703
_io__Buffered_fileno_impl (buffered * self )
696
704
/*[clinic end generated code: output=b717648d58a95ee3 input=1c4fead777bae20a]*/
697
705
{
698
- CHECK_INITIALIZED (self )
706
+ CHECK_INITIALIZED (self );
699
707
return PyObject_CallMethodNoArgs (self -> raw , & _Py_ID (fileno ));
700
708
}
701
709
@@ -708,7 +716,7 @@ static PyObject *
708
716
_io__Buffered_isatty_impl (buffered * self )
709
717
/*[clinic end generated code: output=c20e55caae67baea input=e53d182d7e490e3a]*/
710
718
{
711
- CHECK_INITIALIZED (self )
719
+ CHECK_INITIALIZED (self );
712
720
return PyObject_CallMethodNoArgs (self -> raw , & _Py_ID (isatty ));
713
721
}
714
722
@@ -922,8 +930,8 @@ _io__Buffered_flush_impl(buffered *self)
922
930
{
923
931
PyObject * res ;
924
932
925
- CHECK_INITIALIZED (self )
926
- CHECK_CLOSED (self , "flush of closed file" )
933
+ CHECK_INITIALIZED (self );
934
+ CHECK_CLOSED (self , "flush of closed file" );
927
935
928
936
if (!ENTER_BUFFERED (self ))
929
937
return NULL ;
@@ -947,8 +955,8 @@ _io__Buffered_peek_impl(buffered *self, Py_ssize_t size)
947
955
{
948
956
PyObject * res = NULL ;
949
957
950
- CHECK_INITIALIZED (self )
951
- CHECK_CLOSED (self , "peek of closed file" )
958
+ CHECK_INITIALIZED (self );
959
+ CHECK_CLOSED (self , "peek of closed file" );
952
960
953
961
if (!ENTER_BUFFERED (self ))
954
962
return NULL ;
@@ -979,14 +987,14 @@ _io__Buffered_read_impl(buffered *self, Py_ssize_t n)
979
987
{
980
988
PyObject * res ;
981
989
982
- CHECK_INITIALIZED (self )
990
+ CHECK_INITIALIZED (self );
983
991
if (n < -1 ) {
984
992
PyErr_SetString (PyExc_ValueError ,
985
993
"read length must be non-negative or -1" );
986
994
return NULL ;
987
995
}
988
996
989
- CHECK_CLOSED (self , "read of closed file" )
997
+ CHECK_CLOSED (self , "read of closed file" );
990
998
991
999
if (n == -1 ) {
992
1000
/* The number of bytes is unspecified, read until the end of stream */
@@ -1022,12 +1030,12 @@ _io__Buffered_read1_impl(buffered *self, Py_ssize_t n)
1022
1030
Py_ssize_t have , r ;
1023
1031
PyObject * res = NULL ;
1024
1032
1025
- CHECK_INITIALIZED (self )
1033
+ CHECK_INITIALIZED (self );
1026
1034
if (n < 0 ) {
1027
1035
n = self -> buffer_size ;
1028
1036
}
1029
1037
1030
- CHECK_CLOSED (self , "read of closed file" )
1038
+ CHECK_CLOSED (self , "read of closed file" );
1031
1039
1032
1040
if (n == 0 )
1033
1041
return PyBytes_FromStringAndSize (NULL , 0 );
@@ -1079,8 +1087,8 @@ _buffered_readinto_generic(buffered *self, Py_buffer *buffer, char readinto1)
1079
1087
Py_ssize_t n , written = 0 , remaining ;
1080
1088
PyObject * res = NULL ;
1081
1089
1082
- CHECK_INITIALIZED (self )
1083
- CHECK_CLOSED (self , "readinto of closed file" )
1090
+ CHECK_INITIALIZED (self );
1091
+ CHECK_CLOSED (self , "readinto of closed file" );
1084
1092
1085
1093
n = Py_SAFE_DOWNCAST (READAHEAD (self ), Py_off_t , Py_ssize_t );
1086
1094
if (n > 0 ) {
@@ -1192,7 +1200,7 @@ _buffered_readline(buffered *self, Py_ssize_t limit)
1192
1200
Py_ssize_t n ;
1193
1201
const char * start , * s , * end ;
1194
1202
1195
- CHECK_CLOSED (self , "readline of closed file" )
1203
+ CHECK_CLOSED (self , "readline of closed file" );
1196
1204
1197
1205
/* First, try to find a line in the buffer. This can run unlocked because
1198
1206
the calls to the C API are simple enough that they can't trigger
@@ -1303,7 +1311,7 @@ static PyObject *
1303
1311
_io__Buffered_readline_impl (buffered * self , Py_ssize_t size )
1304
1312
/*[clinic end generated code: output=24dd2aa6e33be83c input=e81ca5abd4280776]*/
1305
1313
{
1306
- CHECK_INITIALIZED (self )
1314
+ CHECK_INITIALIZED (self );
1307
1315
return _buffered_readline (self , size );
1308
1316
}
1309
1317
@@ -1319,7 +1327,7 @@ _io__Buffered_tell_impl(buffered *self)
1319
1327
{
1320
1328
Py_off_t pos ;
1321
1329
1322
- CHECK_INITIALIZED (self )
1330
+ CHECK_INITIALIZED (self );
1323
1331
pos = _buffered_raw_tell (self );
1324
1332
if (pos == -1 )
1325
1333
return NULL ;
@@ -1347,7 +1355,7 @@ _io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence)
1347
1355
Py_off_t target , n ;
1348
1356
PyObject * res = NULL ;
1349
1357
1350
- CHECK_INITIALIZED (self )
1358
+ CHECK_INITIALIZED (self );
1351
1359
1352
1360
/* Do some error checking instead of trusting OS 'seek()'
1353
1361
** error detection, just in case.
@@ -1365,7 +1373,7 @@ _io__Buffered_seek_impl(buffered *self, PyObject *targetobj, int whence)
1365
1373
return NULL ;
1366
1374
}
1367
1375
1368
- CHECK_CLOSED (self , "seek of closed file" )
1376
+ CHECK_CLOSED (self , "seek of closed file" );
1369
1377
1370
1378
_PyIO_State * state = find_io_state_by_def (Py_TYPE (self ));
1371
1379
if (_PyIOBase_check_seekable (state , self -> raw , Py_True ) == NULL ) {
@@ -1449,8 +1457,8 @@ _io__Buffered_truncate_impl(buffered *self, PyTypeObject *cls, PyObject *pos)
1449
1457
{
1450
1458
PyObject * res = NULL ;
1451
1459
1452
- CHECK_INITIALIZED (self )
1453
- CHECK_CLOSED (self , "truncate of closed file" )
1460
+ CHECK_INITIALIZED (self );
1461
+ CHECK_CLOSED (self , "truncate of closed file" );
1454
1462
if (!self -> writable ) {
1455
1463
_PyIO_State * state = get_io_state_by_cls (cls );
1456
1464
return bufferediobase_unsupported (state , "truncate" );
@@ -2073,7 +2081,7 @@ _io_BufferedWriter_write_impl(buffered *self, Py_buffer *buffer)
2073
2081
Py_ssize_t written , avail , remaining ;
2074
2082
Py_off_t offset ;
2075
2083
2076
- CHECK_INITIALIZED (self )
2084
+ CHECK_INITIALIZED (self );
2077
2085
2078
2086
if (!ENTER_BUFFERED (self ))
2079
2087
return NULL ;
0 commit comments