99#define PY_SSIZE_T_CLEAN
1010#include "Python.h"
1111#include "pycore_interp.h" // PyInterpreterState.fs_codec
12+ #include "pycore_long.h" // _PyLong_GetZero()
1213#include "pycore_object.h"
1314#include "pycore_pystate.h" // _PyInterpreterState_GET()
1415#include "structmember.h" // PyMemberDef
@@ -971,7 +972,7 @@ _textiowrapper_fix_encoder_state(textio *self)
971972 return -1 ;
972973 }
973974
974- int cmp = PyObject_RichCompareBool (cookieObj , _PyLong_Zero , Py_EQ );
975+ int cmp = PyObject_RichCompareBool (cookieObj , _PyLong_GetZero () , Py_EQ );
975976 Py_DECREF (cookieObj );
976977 if (cmp < 0 ) {
977978 return -1 ;
@@ -980,7 +981,7 @@ _textiowrapper_fix_encoder_state(textio *self)
980981 if (cmp == 0 ) {
981982 self -> encoding_start_of_stream = 0 ;
982983 PyObject * res = PyObject_CallMethodOneArg (
983- self -> encoder , _PyIO_str_setstate , _PyLong_Zero );
984+ self -> encoder , _PyIO_str_setstate , _PyLong_GetZero () );
984985 if (res == NULL ) {
985986 return -1 ;
986987 }
@@ -2415,7 +2416,7 @@ _textiowrapper_encoder_reset(textio *self, int start_of_stream)
24152416 }
24162417 else {
24172418 res = PyObject_CallMethodOneArg (self -> encoder , _PyIO_str_setstate ,
2418- _PyLong_Zero );
2419+ _PyLong_GetZero () );
24192420 self -> encoding_start_of_stream = 0 ;
24202421 }
24212422 if (res == NULL )
@@ -2459,10 +2460,12 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
24592460 goto fail ;
24602461 }
24612462
2463+ PyObject * zero = _PyLong_GetZero (); // borrowed reference
2464+
24622465 switch (whence ) {
24632466 case SEEK_CUR :
24642467 /* seek relative to current position */
2465- cmp = PyObject_RichCompareBool (cookieObj , _PyLong_Zero , Py_EQ );
2468+ cmp = PyObject_RichCompareBool (cookieObj , zero , Py_EQ );
24662469 if (cmp < 0 )
24672470 goto fail ;
24682471
@@ -2482,7 +2485,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
24822485
24832486 case SEEK_END :
24842487 /* seek relative to end of file */
2485- cmp = PyObject_RichCompareBool (cookieObj , _PyLong_Zero , Py_EQ );
2488+ cmp = PyObject_RichCompareBool (cookieObj , zero , Py_EQ );
24862489 if (cmp < 0 )
24872490 goto fail ;
24882491
@@ -2511,7 +2514,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
25112514 goto fail ;
25122515 if (self -> encoder ) {
25132516 /* 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 );
25152518 if (cmp < 0 || _textiowrapper_encoder_reset (self , cmp )) {
25162519 Py_DECREF (res );
25172520 goto fail ;
@@ -2529,7 +2532,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
25292532 goto fail ;
25302533 }
25312534
2532- cmp = PyObject_RichCompareBool (cookieObj , _PyLong_Zero , Py_LT );
2535+ cmp = PyObject_RichCompareBool (cookieObj , zero , Py_LT );
25332536 if (cmp < 0 )
25342537 goto fail ;
25352538
0 commit comments