summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/_iomodule.c114
-rw-r--r--Modules/_io/_iomodule.h29
-rw-r--r--Modules/_io/bufferedio.c44
-rw-r--r--Modules/_io/iobase.c26
-rw-r--r--Modules/_io/stringio.c6
-rw-r--r--Modules/_io/textio.c61
-rw-r--r--Modules/_tracemalloc.c15
7 files changed, 74 insertions, 221 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 9ecc671..7f029f2 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -24,38 +24,6 @@
#include <windows.h>
#endif
-/* Various interned strings */
-
-PyObject *_PyIO_str_close = NULL;
-PyObject *_PyIO_str_closed = NULL;
-PyObject *_PyIO_str_decode = NULL;
-PyObject *_PyIO_str_encode = NULL;
-PyObject *_PyIO_str_fileno = NULL;
-PyObject *_PyIO_str_flush = NULL;
-PyObject *_PyIO_str_getstate = NULL;
-PyObject *_PyIO_str_isatty = NULL;
-PyObject *_PyIO_str_locale = NULL;
-PyObject *_PyIO_str_newlines = NULL;
-PyObject *_PyIO_str_nl = NULL;
-PyObject *_PyIO_str_peek = NULL;
-PyObject *_PyIO_str_read = NULL;
-PyObject *_PyIO_str_read1 = NULL;
-PyObject *_PyIO_str_readable = NULL;
-PyObject *_PyIO_str_readall = NULL;
-PyObject *_PyIO_str_readinto = NULL;
-PyObject *_PyIO_str_readline = NULL;
-PyObject *_PyIO_str_reset = NULL;
-PyObject *_PyIO_str_seek = NULL;
-PyObject *_PyIO_str_seekable = NULL;
-PyObject *_PyIO_str_setstate = NULL;
-PyObject *_PyIO_str_tell = NULL;
-PyObject *_PyIO_str_truncate = NULL;
-PyObject *_PyIO_str_writable = NULL;
-PyObject *_PyIO_str_write = NULL;
-
-PyObject *_PyIO_empty_str = NULL;
-PyObject *_PyIO_empty_bytes = NULL;
-
PyDoc_STRVAR(module_doc,
"The io module provides the Python interfaces to stream handling. The\n"
"builtin open function is defined in this module.\n"
@@ -511,8 +479,7 @@ _io_text_encoding_impl(PyObject *module, PyObject *encoding, int stacklevel)
return NULL;
}
}
- Py_INCREF(_PyIO_str_locale);
- return _PyIO_str_locale;
+ return &_Py_ID(locale);
}
Py_INCREF(encoding);
return encoding;
@@ -699,41 +666,6 @@ _PyIO_Fini(void)
PyTypeObject *exc = static_types[i];
_PyStaticType_Dealloc(exc);
}
-
- /* Interned strings */
-#define CLEAR_INTERNED(name) \
- Py_CLEAR(_PyIO_str_ ## name)
-
- CLEAR_INTERNED(close);
- CLEAR_INTERNED(closed);
- CLEAR_INTERNED(decode);
- CLEAR_INTERNED(encode);
- CLEAR_INTERNED(fileno);
- CLEAR_INTERNED(flush);
- CLEAR_INTERNED(getstate);
- CLEAR_INTERNED(isatty);
- CLEAR_INTERNED(locale);
- CLEAR_INTERNED(newlines);
- CLEAR_INTERNED(peek);
- CLEAR_INTERNED(read);
- CLEAR_INTERNED(read1);
- CLEAR_INTERNED(readable);
- CLEAR_INTERNED(readall);
- CLEAR_INTERNED(readinto);
- CLEAR_INTERNED(readline);
- CLEAR_INTERNED(reset);
- CLEAR_INTERNED(seek);
- CLEAR_INTERNED(seekable);
- CLEAR_INTERNED(setstate);
- CLEAR_INTERNED(tell);
- CLEAR_INTERNED(truncate);
- CLEAR_INTERNED(write);
- CLEAR_INTERNED(writable);
-#undef CLEAR_INTERNED
-
- Py_CLEAR(_PyIO_str_nl);
- Py_CLEAR(_PyIO_empty_str);
- Py_CLEAR(_PyIO_empty_bytes);
}
@@ -797,50 +729,6 @@ PyInit__io(void)
}
}
- /* Interned strings */
-#define ADD_INTERNED(name) \
- if (!_PyIO_str_ ## name && \
- !(_PyIO_str_ ## name = PyUnicode_InternFromString(# name))) \
- goto fail;
-
- ADD_INTERNED(close)
- ADD_INTERNED(closed)
- ADD_INTERNED(decode)
- ADD_INTERNED(encode)
- ADD_INTERNED(fileno)
- ADD_INTERNED(flush)
- ADD_INTERNED(getstate)
- ADD_INTERNED(isatty)
- ADD_INTERNED(locale)
- ADD_INTERNED(newlines)
- ADD_INTERNED(peek)
- ADD_INTERNED(read)
- ADD_INTERNED(read1)
- ADD_INTERNED(readable)
- ADD_INTERNED(readall)
- ADD_INTERNED(readinto)
- ADD_INTERNED(readline)
- ADD_INTERNED(reset)
- ADD_INTERNED(seek)
- ADD_INTERNED(seekable)
- ADD_INTERNED(setstate)
- ADD_INTERNED(tell)
- ADD_INTERNED(truncate)
- ADD_INTERNED(write)
- ADD_INTERNED(writable)
-#undef ADD_INTERNED
-
- if (!_PyIO_str_nl &&
- !(_PyIO_str_nl = PyUnicode_InternFromString("\n")))
- goto fail;
-
- if (!_PyIO_empty_str &&
- !(_PyIO_empty_str = PyUnicode_FromStringAndSize(NULL, 0)))
- goto fail;
- if (!_PyIO_empty_bytes &&
- !(_PyIO_empty_bytes = PyBytes_FromStringAndSize(NULL, 0)))
- goto fail;
-
state->initialized = 1;
return m;
diff --git a/Modules/_io/_iomodule.h b/Modules/_io/_iomodule.h
index 638797f..c260080 100644
--- a/Modules/_io/_iomodule.h
+++ b/Modules/_io/_iomodule.h
@@ -155,33 +155,4 @@ extern _PyIO_State *_PyIO_get_module_state(void);
extern char _PyIO_get_console_type(PyObject *);
#endif
-extern PyObject *_PyIO_str_close;
-extern PyObject *_PyIO_str_closed;
-extern PyObject *_PyIO_str_decode;
-extern PyObject *_PyIO_str_encode;
-extern PyObject *_PyIO_str_fileno;
-extern PyObject *_PyIO_str_flush;
-extern PyObject *_PyIO_str_getstate;
-extern PyObject *_PyIO_str_isatty;
-extern PyObject *_PyIO_str_newlines;
-extern PyObject *_PyIO_str_nl;
-extern PyObject *_PyIO_str_peek;
-extern PyObject *_PyIO_str_read;
-extern PyObject *_PyIO_str_read1;
-extern PyObject *_PyIO_str_readable;
-extern PyObject *_PyIO_str_readall;
-extern PyObject *_PyIO_str_readinto;
-extern PyObject *_PyIO_str_readline;
-extern PyObject *_PyIO_str_reset;
-extern PyObject *_PyIO_str_seek;
-extern PyObject *_PyIO_str_seekable;
-extern PyObject *_PyIO_str_setstate;
-extern PyObject *_PyIO_str_tell;
-extern PyObject *_PyIO_str_truncate;
-extern PyObject *_PyIO_str_writable;
-extern PyObject *_PyIO_str_write;
-
-extern PyObject *_PyIO_empty_str;
-extern PyObject *_PyIO_empty_bytes;
-
extern Py_EXPORTED_SYMBOL PyTypeObject _PyBytesIOBuffer_Type;
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index bb93ae3..ac30d1d 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -443,7 +443,7 @@ static PyObject *
buffered_simple_flush(buffered *self, PyObject *args)
{
CHECK_INITIALIZED(self)
- return PyObject_CallMethodNoArgs(self->raw, _PyIO_str_flush);
+ return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(flush));
}
static int
@@ -452,7 +452,7 @@ buffered_closed(buffered *self)
int closed;
PyObject *res;
CHECK_INITIALIZED_INT(self)
- res = PyObject_GetAttr(self->raw, _PyIO_str_closed);
+ res = PyObject_GetAttr(self->raw, &_Py_ID(closed));
if (res == NULL)
return -1;
closed = PyObject_IsTrue(res);
@@ -464,7 +464,7 @@ static PyObject *
buffered_closed_get(buffered *self, void *context)
{
CHECK_INITIALIZED(self)
- return PyObject_GetAttr(self->raw, _PyIO_str_closed);
+ return PyObject_GetAttr(self->raw, &_Py_ID(closed));
}
static PyObject *
@@ -495,7 +495,7 @@ buffered_close(buffered *self, PyObject *args)
}
/* flush() will most probably re-take the lock, so drop it first */
LEAVE_BUFFERED(self)
- res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_flush);
+ res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (!ENTER_BUFFERED(self))
return NULL;
if (res == NULL)
@@ -503,7 +503,7 @@ buffered_close(buffered *self, PyObject *args)
else
Py_DECREF(res);
- res = PyObject_CallMethodNoArgs(self->raw, _PyIO_str_close);
+ res = PyObject_CallMethodNoArgs(self->raw, &_Py_ID(close));
if (self->buffer) {
PyMem_Free(self->buffer);
@@ -530,7 +530,7 @@ buffered_detach(buffered *self, PyObject *Py_UNUSED(ignored))
{
PyObject *raw, *res;
CHECK_INITIALIZED(self)
- res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_flush);
+ res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (res == NULL)
return NULL;
Py_DECREF(res);
@@ -547,21 +547,21 @@ static PyObject *
buffered_seekable(buffered *self, PyObject *Py_UNUSED(ignored))
{
CHECK_INITIALIZED(self)
- return PyObject_CallMethodNoArgs(self->raw, _PyIO_str_seekable);
+ return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(seekable));
}
static PyObject *
buffered_readable(buffered *self, PyObject *Py_UNUSED(ignored))
{
CHECK_INITIALIZED(self)
- return PyObject_CallMethodNoArgs(self->raw, _PyIO_str_readable);
+ return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(readable));
}
static PyObject *
buffered_writable(buffered *self, PyObject *Py_UNUSED(ignored))
{
CHECK_INITIALIZED(self)
- return PyObject_CallMethodNoArgs(self->raw, _PyIO_str_writable);
+ return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(writable));
}
static PyObject *
@@ -584,14 +584,14 @@ static PyObject *
buffered_fileno(buffered *self, PyObject *Py_UNUSED(ignored))
{
CHECK_INITIALIZED(self)
- return PyObject_CallMethodNoArgs(self->raw, _PyIO_str_fileno);
+ return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(fileno));
}
static PyObject *
buffered_isatty(buffered *self, PyObject *Py_UNUSED(ignored))
{
CHECK_INITIALIZED(self)
- return PyObject_CallMethodNoArgs(self->raw, _PyIO_str_isatty);
+ return PyObject_CallMethodNoArgs(self->raw, &_Py_ID(isatty));
}
/* Forward decls */
@@ -655,7 +655,7 @@ _buffered_raw_tell(buffered *self)
{
Py_off_t n;
PyObject *res;
- res = PyObject_CallMethodNoArgs(self->raw, _PyIO_str_tell);
+ res = PyObject_CallMethodNoArgs(self->raw, &_Py_ID(tell));
if (res == NULL)
return -1;
n = PyNumber_AsOff_t(res, PyExc_ValueError);
@@ -685,7 +685,7 @@ _buffered_raw_seek(buffered *self, Py_off_t target, int whence)
Py_DECREF(posobj);
return -1;
}
- res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_seek,
+ res = PyObject_CallMethodObjArgs(self->raw, &_Py_ID(seek),
posobj, whenceobj, NULL);
Py_DECREF(posobj);
Py_DECREF(whenceobj);
@@ -1152,7 +1152,7 @@ found:
Py_CLEAR(res);
goto end;
}
- Py_XSETREF(res, _PyBytes_Join(_PyIO_empty_bytes, chunks));
+ Py_XSETREF(res, _PyBytes_Join((PyObject *)&_Py_SINGLETON(bytes_empty), chunks));
end:
LEAVE_BUFFERED(self)
@@ -1311,7 +1311,7 @@ _io__Buffered_truncate_impl(buffered *self, PyObject *pos)
}
Py_CLEAR(res);
- res = PyObject_CallMethodOneArg(self->raw, _PyIO_str_truncate, pos);
+ res = PyObject_CallMethodOneArg(self->raw, &_Py_ID(truncate), pos);
if (res == NULL)
goto end;
/* Reset cached position */
@@ -1339,7 +1339,7 @@ buffered_iternext(buffered *self)
}
else {
line = PyObject_CallMethodNoArgs((PyObject *)self,
- _PyIO_str_readline);
+ &_Py_ID(readline));
if (line && !PyBytes_Check(line)) {
PyErr_Format(PyExc_OSError,
"readline() should have returned a bytes object, "
@@ -1457,7 +1457,7 @@ _bufferedreader_raw_read(buffered *self, char *start, Py_ssize_t len)
raised (see issue #10956).
*/
do {
- res = PyObject_CallMethodOneArg(self->raw, _PyIO_str_readinto, memobj);
+ res = PyObject_CallMethodOneArg(self->raw, &_Py_ID(readinto), memobj);
} while (res == NULL && _PyIO_trap_eintr());
Py_DECREF(memobj);
if (res == NULL)
@@ -1530,7 +1530,7 @@ _bufferedreader_read_all(buffered *self)
}
_bufferedreader_reset_buf(self);
- if (_PyObject_LookupAttr(self->raw, _PyIO_str_readall, &readall) < 0) {
+ if (_PyObject_LookupAttr(self->raw, &_Py_ID(readall), &readall) < 0) {
goto cleanup;
}
if (readall) {
@@ -1565,7 +1565,7 @@ _bufferedreader_read_all(buffered *self)
}
/* Read until EOF or until read() would block. */
- data = PyObject_CallMethodNoArgs(self->raw, _PyIO_str_read);
+ data = PyObject_CallMethodNoArgs(self->raw, &_Py_ID(read));
if (data == NULL)
goto cleanup;
if (data != Py_None && !PyBytes_Check(data)) {
@@ -1578,7 +1578,7 @@ _bufferedreader_read_all(buffered *self)
goto cleanup;
}
else {
- tmp = _PyBytes_Join(_PyIO_empty_bytes, chunks);
+ tmp = _PyBytes_Join((PyObject *)&_Py_SINGLETON(bytes_empty), chunks);
res = tmp;
goto cleanup;
}
@@ -1814,7 +1814,7 @@ _bufferedwriter_raw_write(buffered *self, char *start, Py_ssize_t len)
*/
do {
errno = 0;
- res = PyObject_CallMethodOneArg(self->raw, _PyIO_str_write, memobj);
+ res = PyObject_CallMethodOneArg(self->raw, &_Py_ID(write), memobj);
errnum = errno;
} while (res == NULL && _PyIO_trap_eintr());
Py_DECREF(memobj);
@@ -2251,7 +2251,7 @@ bufferedrwpair_closed_get(rwpair *self, void *context)
"the BufferedRWPair object is being garbage-collected");
return NULL;
}
- return PyObject_GetAttr((PyObject *) self->writer, _PyIO_str_closed);
+ return PyObject_GetAttr((PyObject *) self->writer, &_Py_ID(closed));
}
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index 74663e0..b00b6b9 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -181,7 +181,7 @@ iobase_check_closed(PyObject *self)
int closed;
/* This gets the derived attribute, which is *not* __IOBase_closed
in most cases! */
- closed = _PyObject_LookupAttr(self, _PyIO_str_closed, &res);
+ closed = _PyObject_LookupAttr(self, &_Py_ID(closed), &res);
if (closed > 0) {
closed = PyObject_IsTrue(res);
Py_DECREF(res);
@@ -231,7 +231,7 @@ _io__IOBase_close_impl(PyObject *self)
Py_RETURN_NONE;
}
- res = PyObject_CallMethodNoArgs(self, _PyIO_str_flush);
+ res = PyObject_CallMethodNoArgs(self, &_Py_ID(flush));
PyErr_Fetch(&exc, &val, &tb);
rc = PyObject_SetAttr(self, &_Py_ID(__IOBase_closed), Py_True);
@@ -261,7 +261,7 @@ iobase_finalize(PyObject *self)
/* If `closed` doesn't exist or can't be evaluated as bool, then the
object is probably in an unusable state, so ignore. */
- if (_PyObject_LookupAttr(self, _PyIO_str_closed, &res) <= 0) {
+ if (_PyObject_LookupAttr(self, &_Py_ID(closed), &res) <= 0) {
PyErr_Clear();
closed = -1;
}
@@ -276,7 +276,7 @@ iobase_finalize(PyObject *self)
finalization process. */
if (PyObject_SetAttr(self, &_Py_ID(_finalizing), Py_True))
PyErr_Clear();
- res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_close);
+ res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(close));
/* Silencing I/O errors is bad, but printing spurious tracebacks is
equally as bad, and potentially more frequent (because of
shutdown issues). */
@@ -377,7 +377,7 @@ _io__IOBase_seekable_impl(PyObject *self)
PyObject *
_PyIOBase_check_seekable(PyObject *self, PyObject *args)
{
- PyObject *res = PyObject_CallMethodNoArgs(self, _PyIO_str_seekable);
+ PyObject *res = PyObject_CallMethodNoArgs(self, &_Py_ID(seekable));
if (res == NULL)
return NULL;
if (res != Py_True) {
@@ -410,7 +410,7 @@ _io__IOBase_readable_impl(PyObject *self)
PyObject *
_PyIOBase_check_readable(PyObject *self, PyObject *args)
{
- PyObject *res = PyObject_CallMethodNoArgs(self, _PyIO_str_readable);
+ PyObject *res = PyObject_CallMethodNoArgs(self, &_Py_ID(readable));
if (res == NULL)
return NULL;
if (res != Py_True) {
@@ -443,7 +443,7 @@ _io__IOBase_writable_impl(PyObject *self)
PyObject *
_PyIOBase_check_writable(PyObject *self, PyObject *args)
{
- PyObject *res = PyObject_CallMethodNoArgs(self, _PyIO_str_writable);
+ PyObject *res = PyObject_CallMethodNoArgs(self, &_Py_ID(writable));
if (res == NULL)
return NULL;
if (res != Py_True) {
@@ -472,7 +472,7 @@ iobase_enter(PyObject *self, PyObject *args)
static PyObject *
iobase_exit(PyObject *self, PyObject *args)
{
- return PyObject_CallMethodNoArgs(self, _PyIO_str_close);
+ return PyObject_CallMethodNoArgs(self, &_Py_ID(close));
}
/* Lower-level APIs */
@@ -536,7 +536,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit)
PyObject *peek, *buffer, *result;
Py_ssize_t old_size = -1;
- if (_PyObject_LookupAttr(self, _PyIO_str_peek, &peek) < 0) {
+ if (_PyObject_LookupAttr(self, &_Py_ID(peek), &peek) < 0) {
return NULL;
}
@@ -650,7 +650,7 @@ iobase_iter(PyObject *self)
static PyObject *
iobase_iternext(PyObject *self)
{
- PyObject *line = PyObject_CallMethodNoArgs(self, _PyIO_str_readline);
+ PyObject *line = PyObject_CallMethodNoArgs(self, &_Py_ID(readline));
if (line == NULL)
return NULL;
@@ -776,7 +776,7 @@ _io__IOBase_writelines(PyObject *self, PyObject *lines)
res = NULL;
do {
- res = PyObject_CallMethodObjArgs(self, _PyIO_str_write, line, NULL);
+ res = PyObject_CallMethodObjArgs(self, &_Py_ID(write), line, NULL);
} while (res == NULL && _PyIO_trap_eintr());
Py_DECREF(line);
if (res == NULL) {
@@ -920,7 +920,7 @@ _io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n)
if (b == NULL)
return NULL;
- res = PyObject_CallMethodObjArgs(self, _PyIO_str_readinto, b, NULL);
+ res = PyObject_CallMethodObjArgs(self, &_Py_ID(readinto), b, NULL);
if (res == NULL || res == Py_None) {
Py_DECREF(b);
return res;
@@ -994,7 +994,7 @@ _io__RawIOBase_readall_impl(PyObject *self)
return NULL;
}
}
- result = _PyBytes_Join(_PyIO_empty_bytes, chunks);
+ result = _PyBytes_Join((PyObject *)&_Py_SINGLETON(bytes_empty), chunks);
Py_DECREF(chunks);
return result;
}
diff --git a/Modules/_io/stringio.c b/Modules/_io/stringio.c
index e76152e..3fe02d3 100644
--- a/Modules/_io/stringio.c
+++ b/Modules/_io/stringio.c
@@ -192,7 +192,7 @@ write_str(stringio *self, PyObject *obj)
}
if (self->writenl) {
PyObject *translated = PyUnicode_Replace(
- decoded, _PyIO_str_nl, self->writenl, -1);
+ decoded, &_Py_STR(newline), self->writenl, -1);
Py_DECREF(decoded);
decoded = translated;
}
@@ -409,7 +409,7 @@ stringio_iternext(stringio *self)
else {
/* XXX is subclassing StringIO really supported? */
line = PyObject_CallMethodNoArgs((PyObject *)self,
- _PyIO_str_readline);
+ &_Py_ID(readline));
if (line && !PyUnicode_Check(line)) {
PyErr_Format(PyExc_OSError,
"readline() should have returned a str object, "
@@ -964,7 +964,7 @@ stringio_newlines(stringio *self, void *context)
CHECK_CLOSED(self);
if (self->decoder == NULL)
Py_RETURN_NONE;
- return PyObject_GetAttr(self->decoder, _PyIO_str_newlines);
+ return PyObject_GetAttr(self->decoder, &_Py_ID(newlines));
}
#include "clinic/stringio.c.h"
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index d5ceec7..ca59a4e 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -298,7 +298,7 @@ _PyIncrementalNewlineDecoder_decode(PyObject *myself,
/* decode input (with the eventual \r from a previous pass) */
if (self->decoder != Py_None) {
output = PyObject_CallMethodObjArgs(self->decoder,
- _PyIO_str_decode, input, final ? Py_True : Py_False, NULL);
+ &_Py_ID(decode), input, final ? Py_True : Py_False, NULL);
}
else {
output = input;
@@ -509,7 +509,7 @@ _io_IncrementalNewlineDecoder_getstate_impl(nldecoder_object *self)
if (self->decoder != Py_None) {
PyObject *state = PyObject_CallMethodNoArgs(self->decoder,
- _PyIO_str_getstate);
+ &_Py_ID(getstate));
if (state == NULL)
return NULL;
if (!PyTuple_Check(state)) {
@@ -584,7 +584,7 @@ _io_IncrementalNewlineDecoder_reset_impl(nldecoder_object *self)
self->seennl = 0;
self->pendingcr = 0;
if (self->decoder != Py_None)
- return PyObject_CallMethodNoArgs(self->decoder, _PyIO_str_reset);
+ return PyObject_CallMethodNoArgs(self->decoder, &_Py_ID(reset));
else
Py_RETURN_NONE;
}
@@ -883,7 +883,7 @@ _textiowrapper_decode(PyObject *decoder, PyObject *bytes, int eof)
if (Py_IS_TYPE(decoder, &PyIncrementalNewlineDecoder_Type))
chars = _PyIncrementalNewlineDecoder_decode(decoder, bytes, eof);
else
- chars = PyObject_CallMethodObjArgs(decoder, _PyIO_str_decode, bytes,
+ chars = PyObject_CallMethodObjArgs(decoder, &_Py_ID(decode), bytes,
eof ? Py_True : Py_False, NULL);
if (check_decoded(chars) < 0)
@@ -947,7 +947,7 @@ _textiowrapper_fix_encoder_state(textio *self)
self->encoding_start_of_stream = 1;
PyObject *cookieObj = PyObject_CallMethodNoArgs(
- self->buffer, _PyIO_str_tell);
+ self->buffer, &_Py_ID(tell));
if (cookieObj == NULL) {
return -1;
}
@@ -961,7 +961,7 @@ _textiowrapper_fix_encoder_state(textio *self)
if (cmp == 0) {
self->encoding_start_of_stream = 0;
PyObject *res = PyObject_CallMethodOneArg(
- self->encoder, _PyIO_str_setstate, _PyLong_GetZero());
+ self->encoder, &_Py_ID(setstate), _PyLong_GetZero());
if (res == NULL) {
return -1;
}
@@ -1225,7 +1225,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
goto error;
self->seekable = self->telling = r;
- r = _PyObject_LookupAttr(buffer, _PyIO_str_read1, &res);
+ r = _PyObject_LookupAttr(buffer, &_Py_ID(read1), &res);
if (r < 0) {
goto error;
}
@@ -1358,7 +1358,7 @@ _io_TextIOWrapper_reconfigure_impl(textio *self, PyObject *encoding,
return NULL;
}
- PyObject *res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_flush);
+ PyObject *res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (res == NULL) {
return NULL;
}
@@ -1497,7 +1497,7 @@ _io_TextIOWrapper_detach_impl(textio *self)
{
PyObject *buffer, *res;
CHECK_ATTACHED(self);
- res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_flush);
+ res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (res == NULL)
return NULL;
Py_DECREF(res);
@@ -1569,7 +1569,7 @@ _textiowrapper_writeflush(textio *self)
PyObject *ret;
do {
- ret = PyObject_CallMethodOneArg(self->buffer, _PyIO_str_write, b);
+ ret = PyObject_CallMethodOneArg(self->buffer, &_Py_ID(write), b);
} while (ret == NULL && _PyIO_trap_eintr());
Py_DECREF(b);
// NOTE: We cleared buffer but we don't know how many bytes are actually written
@@ -1644,7 +1644,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
self->encoding_start_of_stream = 0;
}
else {
- b = PyObject_CallMethodOneArg(self->encoder, _PyIO_str_encode, text);
+ b = PyObject_CallMethodOneArg(self->encoder, &_Py_ID(encode), text);
}
Py_DECREF(text);
@@ -1704,7 +1704,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
}
if (needflush) {
- ret = PyObject_CallMethodNoArgs(self->buffer, _PyIO_str_flush);
+ ret = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(flush));
if (ret == NULL)
return NULL;
Py_DECREF(ret);
@@ -1795,7 +1795,7 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
* where the decoder's input buffer is empty.
*/
PyObject *state = PyObject_CallMethodNoArgs(self->decoder,
- _PyIO_str_getstate);
+ &_Py_ID(getstate));
if (state == NULL)
return -1;
/* Given this, we know there was a valid snapshot point
@@ -1836,7 +1836,7 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
goto fail;
input_chunk = PyObject_CallMethodOneArg(self->buffer,
- (self->has_read1 ? _PyIO_str_read1: _PyIO_str_read),
+ (self->has_read1 ? &_Py_ID(read1): &_Py_ID(read)),
chunk_size);
Py_DECREF(chunk_size);
if (input_chunk == NULL)
@@ -1928,7 +1928,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
bytes, 1);
else
decoded = PyObject_CallMethodObjArgs(
- self->decoder, _PyIO_str_decode, bytes, Py_True, NULL);
+ self->decoder, &_Py_ID(decode), bytes, Py_True, NULL);
Py_DECREF(bytes);
if (check_decoded(decoded) < 0)
goto fail;
@@ -1989,7 +1989,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
if (chunks != NULL) {
if (result != NULL && PyList_Append(chunks, result) < 0)
goto fail;
- Py_XSETREF(result, PyUnicode_Join(_PyIO_empty_str, chunks));
+ Py_XSETREF(result, PyUnicode_Join(&_Py_STR(empty), chunks));
if (result == NULL)
goto fail;
Py_CLEAR(chunks);
@@ -2254,14 +2254,13 @@ _textiowrapper_readline(textio *self, Py_ssize_t limit)
goto error;
Py_DECREF(line);
}
- line = PyUnicode_Join(_PyIO_empty_str, chunks);
+ line = PyUnicode_Join(&_Py_STR(empty), chunks);
if (line == NULL)
goto error;
Py_CLEAR(chunks);
}
if (line == NULL) {
- Py_INCREF(_PyIO_empty_str);
- line = _PyIO_empty_str;
+ line = &_Py_STR(empty);
}
return line;
@@ -2379,7 +2378,7 @@ _textiowrapper_decoder_setstate(textio *self, cookie_type *cookie)
utf-16, that we are expecting a BOM).
*/
if (cookie->start_pos == 0 && cookie->dec_flags == 0) {
- res = PyObject_CallMethodNoArgs(self->decoder, _PyIO_str_reset);
+ res = PyObject_CallMethodNoArgs(self->decoder, &_Py_ID(reset));
}
else {
res = _PyObject_CallMethod(self->decoder, &_Py_ID(setstate),
@@ -2397,11 +2396,11 @@ _textiowrapper_encoder_reset(textio *self, int start_of_stream)
{
PyObject *res;
if (start_of_stream) {
- res = PyObject_CallMethodNoArgs(self->encoder, _PyIO_str_reset);
+ res = PyObject_CallMethodNoArgs(self->encoder, &_Py_ID(reset));
self->encoding_start_of_stream = 1;
}
else {
- res = PyObject_CallMethodOneArg(self->encoder, _PyIO_str_setstate,
+ res = PyObject_CallMethodOneArg(self->encoder, &_Py_ID(setstate),
_PyLong_GetZero());
self->encoding_start_of_stream = 0;
}
@@ -2528,7 +2527,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
goto fail;
}
- res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_flush);
+ res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (res == NULL)
goto fail;
Py_DECREF(res);
@@ -2543,7 +2542,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
posobj = PyLong_FromOff_t(cookie.start_pos);
if (posobj == NULL)
goto fail;
- res = PyObject_CallMethodOneArg(self->buffer, _PyIO_str_seek, posobj);
+ res = PyObject_CallMethodOneArg(self->buffer, &_Py_ID(seek), posobj);
Py_DECREF(posobj);
if (res == NULL)
goto fail;
@@ -2692,14 +2691,14 @@ _io_TextIOWrapper_tell_impl(textio *self)
/* Decoder state will be restored at the end */
saved_state = PyObject_CallMethodNoArgs(self->decoder,
- _PyIO_str_getstate);
+ &_Py_ID(getstate));
if (saved_state == NULL)
goto fail;
#define DECODER_GETSTATE() do { \
PyObject *dec_buffer; \
PyObject *_state = PyObject_CallMethodNoArgs(self->decoder, \
- _PyIO_str_getstate); \
+ &_Py_ID(getstate)); \
if (_state == NULL) \
goto fail; \
if (!PyTuple_Check(_state)) { \
@@ -2863,12 +2862,12 @@ _io_TextIOWrapper_truncate_impl(textio *self, PyObject *pos)
CHECK_ATTACHED(self)
- res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_flush);
+ res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (res == NULL)
return NULL;
Py_DECREF(res);
- return PyObject_CallMethodOneArg(self->buffer, _PyIO_str_truncate, pos);
+ return PyObject_CallMethodOneArg(self->buffer, &_Py_ID(truncate), pos);
}
static PyObject *
@@ -3077,7 +3076,7 @@ textiowrapper_iternext(textio *self)
}
else {
line = PyObject_CallMethodNoArgs((PyObject *)self,
- _PyIO_str_readline);
+ &_Py_ID(readline));
if (line && !PyUnicode_Check(line)) {
PyErr_Format(PyExc_OSError,
"readline() should have returned a str object, "
@@ -3112,7 +3111,7 @@ static PyObject *
textiowrapper_closed_get(textio *self, void *context)
{
CHECK_ATTACHED(self);
- return PyObject_GetAttr(self->buffer, _PyIO_str_closed);
+ return PyObject_GetAttr(self->buffer, &_Py_ID(closed));
}
static PyObject *
@@ -3121,7 +3120,7 @@ textiowrapper_newlines_get(textio *self, void *context)
PyObject *res;
CHECK_ATTACHED(self);
if (self->decoder == NULL ||
- _PyObject_LookupAttr(self->decoder, _PyIO_str_newlines, &res) == 0)
+ _PyObject_LookupAttr(self->decoder, &_Py_ID(newlines), &res) == 0)
{
Py_RETURN_NONE;
}
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c
index 14bad00..53e3299 100644
--- a/Modules/_tracemalloc.c
+++ b/Modules/_tracemalloc.c
@@ -3,6 +3,7 @@
#include "pycore_gc.h" // PyGC_Head
#include "pycore_hashtable.h" // _Py_hashtable_t
#include "pycore_pymem.h" // _Py_tracemalloc_config
+#include "pycore_runtime.h" // _Py_ID()
#include "pycore_traceback.h"
#include <pycore_frame.h>
@@ -15,6 +16,8 @@ module _tracemalloc
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=708a98302fc46e5f]*/
+_Py_DECLARE_STR(anon_unknown, "<unknown>");
+
/* Trace memory blocks allocated by PyMem_RawMalloc() */
#define TRACE_RAW_MALLOC
@@ -91,7 +94,6 @@ typedef struct {
static const unsigned long MAX_NFRAME = Py_MIN(UINT16_MAX, ((SIZE_MAX - sizeof(traceback_t)) / sizeof(frame_t) + 1));
-static PyObject *unknown_filename = NULL;
static traceback_t tracemalloc_empty_traceback;
/* Trace of a memory block */
@@ -305,7 +307,7 @@ hashtable_compare_traceback(const void *key1, const void *key2)
static void
tracemalloc_get_frame(InterpreterFrame *pyframe, frame_t *frame)
{
- frame->filename = unknown_filename;
+ frame->filename = &_Py_STR(anon_unknown);
int lineno = PyCode_Addr2Line(pyframe->f_code, pyframe->f_lasti*sizeof(_Py_CODEUNIT));
if (lineno < 0) {
lineno = 0;
@@ -905,15 +907,10 @@ tracemalloc_init(void)
return -1;
}
- unknown_filename = PyUnicode_FromString("<unknown>");
- if (unknown_filename == NULL)
- return -1;
- PyUnicode_InternInPlace(&unknown_filename);
-
tracemalloc_empty_traceback.nframe = 1;
tracemalloc_empty_traceback.total_nframe = 1;
/* borrowed reference */
- tracemalloc_empty_traceback.frames[0].filename = unknown_filename;
+ tracemalloc_empty_traceback.frames[0].filename = &_Py_STR(anon_unknown);
tracemalloc_empty_traceback.frames[0].lineno = 0;
tracemalloc_empty_traceback.hash = traceback_hash(&tracemalloc_empty_traceback);
@@ -947,8 +944,6 @@ tracemalloc_deinit(void)
#ifdef REENTRANT_THREADLOCAL
PyThread_tss_delete(&tracemalloc_reentrant_key);
#endif
-
- Py_XDECREF(unknown_filename);
}