9
9
#define PY_SSIZE_T_CLEAN
10
10
#include "Python.h"
11
11
#include "pycore_interp.h" // PyInterpreterState.fs_codec
12
+ #include "pycore_long.h" // _PyLong_GetZero()
12
13
#include "pycore_object.h"
13
14
#include "pycore_pystate.h" // _PyInterpreterState_GET()
14
15
#include "structmember.h" // PyMemberDef
@@ -971,7 +972,7 @@ _textiowrapper_fix_encoder_state(textio *self)
971
972
return -1 ;
972
973
}
973
974
974
- int cmp = PyObject_RichCompareBool (cookieObj , _PyLong_Zero , Py_EQ );
975
+ int cmp = PyObject_RichCompareBool (cookieObj , _PyLong_GetZero () , Py_EQ );
975
976
Py_DECREF (cookieObj );
976
977
if (cmp < 0 ) {
977
978
return -1 ;
@@ -980,7 +981,7 @@ _textiowrapper_fix_encoder_state(textio *self)
980
981
if (cmp == 0 ) {
981
982
self -> encoding_start_of_stream = 0 ;
982
983
PyObject * res = PyObject_CallMethodOneArg (
983
- self -> encoder , _PyIO_str_setstate , _PyLong_Zero );
984
+ self -> encoder , _PyIO_str_setstate , _PyLong_GetZero () );
984
985
if (res == NULL ) {
985
986
return -1 ;
986
987
}
@@ -2415,7 +2416,7 @@ _textiowrapper_encoder_reset(textio *self, int start_of_stream)
2415
2416
}
2416
2417
else {
2417
2418
res = PyObject_CallMethodOneArg (self -> encoder , _PyIO_str_setstate ,
2418
- _PyLong_Zero );
2419
+ _PyLong_GetZero () );
2419
2420
self -> encoding_start_of_stream = 0 ;
2420
2421
}
2421
2422
if (res == NULL )
@@ -2459,10 +2460,12 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
2459
2460
goto fail ;
2460
2461
}
2461
2462
2463
+ PyObject * zero = _PyLong_GetZero (); // borrowed reference
2464
+
2462
2465
switch (whence ) {
2463
2466
case SEEK_CUR :
2464
2467
/* seek relative to current position */
2465
- cmp = PyObject_RichCompareBool (cookieObj , _PyLong_Zero , Py_EQ );
2468
+ cmp = PyObject_RichCompareBool (cookieObj , zero , Py_EQ );
2466
2469
if (cmp < 0 )
2467
2470
goto fail ;
2468
2471
@@ -2482,7 +2485,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
2482
2485
2483
2486
case SEEK_END :
2484
2487
/* seek relative to end of file */
2485
- cmp = PyObject_RichCompareBool (cookieObj , _PyLong_Zero , Py_EQ );
2488
+ cmp = PyObject_RichCompareBool (cookieObj , zero , Py_EQ );
2486
2489
if (cmp < 0 )
2487
2490
goto fail ;
2488
2491
@@ -2511,7 +2514,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
2511
2514
goto fail ;
2512
2515
if (self -> encoder ) {
2513
2516
/* If seek() == 0, we are at the start of stream, otherwise not */
2514
- cmp = PyObject_RichCompareBool (res , _PyLong_Zero , Py_EQ );
2517
+ cmp = PyObject_RichCompareBool (res , zero , Py_EQ );
2515
2518
if (cmp < 0 || _textiowrapper_encoder_reset (self , cmp )) {
2516
2519
Py_DECREF (res );
2517
2520
goto fail ;
@@ -2529,7 +2532,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
2529
2532
goto fail ;
2530
2533
}
2531
2534
2532
- cmp = PyObject_RichCompareBool (cookieObj , _PyLong_Zero , Py_LT );
2535
+ cmp = PyObject_RichCompareBool (cookieObj , zero , Py_LT );
2533
2536
if (cmp < 0 )
2534
2537
goto fail ;
2535
2538
0 commit comments