mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-29878: Add global instances of int for 0 and 1. (#852)
This commit is contained in:
parent
e6911a44f6
commit
ba85d69a3e
18 changed files with 105 additions and 249 deletions
|
@ -53,7 +53,6 @@ PyObject *_PyIO_str_write;
|
|||
|
||||
PyObject *_PyIO_empty_str;
|
||||
PyObject *_PyIO_empty_bytes;
|
||||
PyObject *_PyIO_zero;
|
||||
|
||||
PyDoc_STRVAR(module_doc,
|
||||
"The io module provides the Python interfaces to stream handling. The\n"
|
||||
|
@ -790,9 +789,6 @@ PyInit__io(void)
|
|||
if (!_PyIO_empty_bytes &&
|
||||
!(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
|
||||
goto fail;
|
||||
if (!_PyIO_zero &&
|
||||
!(_PyIO_zero = PyLong_FromLong(0L)))
|
||||
goto fail;
|
||||
|
||||
state->initialized = 1;
|
||||
|
||||
|
|
|
@ -183,6 +183,5 @@ extern PyObject *_PyIO_str_write;
|
|||
|
||||
extern PyObject *_PyIO_empty_str;
|
||||
extern PyObject *_PyIO_empty_bytes;
|
||||
extern PyObject *_PyIO_zero;
|
||||
|
||||
extern PyTypeObject _PyBytesIOBuffer_Type;
|
||||
|
|
|
@ -1078,7 +1078,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
|
|||
if (cookieObj == NULL)
|
||||
goto error;
|
||||
|
||||
cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ);
|
||||
cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
|
||||
Py_DECREF(cookieObj);
|
||||
if (cmp < 0) {
|
||||
goto error;
|
||||
|
@ -1087,7 +1087,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
|
|||
if (cmp == 0) {
|
||||
self->encoding_start_of_stream = 0;
|
||||
res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate,
|
||||
_PyIO_zero, NULL);
|
||||
_PyLong_Zero, NULL);
|
||||
if (res == NULL)
|
||||
goto error;
|
||||
Py_DECREF(res);
|
||||
|
@ -2030,7 +2030,7 @@ _textiowrapper_encoder_reset(textio *self, int start_of_stream)
|
|||
}
|
||||
else {
|
||||
res = PyObject_CallMethodObjArgs(self->encoder, _PyIO_str_setstate,
|
||||
_PyIO_zero, NULL);
|
||||
_PyLong_Zero, NULL);
|
||||
self->encoding_start_of_stream = 0;
|
||||
}
|
||||
if (res == NULL)
|
||||
|
@ -2075,7 +2075,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
|
|||
|
||||
if (whence == 1) {
|
||||
/* seek relative to current position */
|
||||
cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ);
|
||||
cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
|
||||
if (cmp < 0)
|
||||
goto fail;
|
||||
|
||||
|
@ -2094,7 +2094,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
|
|||
}
|
||||
else if (whence == 2) {
|
||||
/* seek relative to end of file */
|
||||
cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_EQ);
|
||||
cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_EQ);
|
||||
if (cmp < 0)
|
||||
goto fail;
|
||||
|
||||
|
@ -2123,7 +2123,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
|
|||
goto fail;
|
||||
if (self->encoder) {
|
||||
/* If seek() == 0, we are at the start of stream, otherwise not */
|
||||
cmp = PyObject_RichCompareBool(res, _PyIO_zero, Py_EQ);
|
||||
cmp = PyObject_RichCompareBool(res, _PyLong_Zero, Py_EQ);
|
||||
if (cmp < 0 || _textiowrapper_encoder_reset(self, cmp)) {
|
||||
Py_DECREF(res);
|
||||
goto fail;
|
||||
|
@ -2137,7 +2137,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
|
|||
goto fail;
|
||||
}
|
||||
|
||||
cmp = PyObject_RichCompareBool(cookieObj, _PyIO_zero, Py_LT);
|
||||
cmp = PyObject_RichCompareBool(cookieObj, _PyLong_Zero, Py_LT);
|
||||
if (cmp < 0)
|
||||
goto fail;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue