STRUCT_FOR_STR(anon_module, "<module>")
STRUCT_FOR_STR(anon_setcomp, "<setcomp>")
STRUCT_FOR_STR(anon_string, "<string>")
+ STRUCT_FOR_STR(anon_unknown, "<unknown>")
+ STRUCT_FOR_STR(close_br, "}")
STRUCT_FOR_STR(comma_sep, ", ")
+ STRUCT_FOR_STR(dbl_close_br, "}}")
+ STRUCT_FOR_STR(dbl_open_br, "{{")
STRUCT_FOR_STR(dbl_percent, "%%")
STRUCT_FOR_STR(dot, ".")
STRUCT_FOR_STR(dot_locals, ".<locals>")
STRUCT_FOR_STR(empty, "")
+ STRUCT_FOR_STR(list_err, "list index out of range")
+ STRUCT_FOR_STR(newline, "\n")
+ STRUCT_FOR_STR(open_br, "{")
STRUCT_FOR_STR(percent, "%")
} literals;
struct {
+ STRUCT_FOR_ID(False)
STRUCT_FOR_ID(Py_Repr)
STRUCT_FOR_ID(TextIOWrapper)
+ STRUCT_FOR_ID(True)
STRUCT_FOR_ID(WarningMessage)
STRUCT_FOR_ID(_)
STRUCT_FOR_ID(__IOBase_closed)
STRUCT_FOR_ID(__weakref__)
STRUCT_FOR_ID(__xor__)
STRUCT_FOR_ID(_abc_impl)
+ STRUCT_FOR_ID(_annotation)
STRUCT_FOR_ID(_blksize)
+ STRUCT_FOR_ID(_bootstrap)
STRUCT_FOR_ID(_dealloc_warn)
STRUCT_FOR_ID(_finalizing)
STRUCT_FOR_ID(_find_and_load)
STRUCT_FOR_ID(big)
STRUCT_FOR_ID(buffer)
STRUCT_FOR_ID(builtins)
+ STRUCT_FOR_ID(c_call)
+ STRUCT_FOR_ID(c_exception)
+ STRUCT_FOR_ID(c_return)
+ STRUCT_FOR_ID(call)
STRUCT_FOR_ID(clear)
STRUCT_FOR_ID(close)
+ STRUCT_FOR_ID(closed)
STRUCT_FOR_ID(code)
STRUCT_FOR_ID(copy)
STRUCT_FOR_ID(copyreg)
STRUCT_FOR_ID(decode)
STRUCT_FOR_ID(default)
STRUCT_FOR_ID(defaultaction)
+ STRUCT_FOR_ID(dictcomp)
STRUCT_FOR_ID(difference_update)
STRUCT_FOR_ID(dispatch_table)
STRUCT_FOR_ID(displayhook)
STRUCT_FOR_ID(enable)
+ STRUCT_FOR_ID(encode)
STRUCT_FOR_ID(encoding)
STRUCT_FOR_ID(end_lineno)
STRUCT_FOR_ID(end_offset)
STRUCT_FOR_ID(errors)
STRUCT_FOR_ID(excepthook)
+ STRUCT_FOR_ID(exception)
STRUCT_FOR_ID(extend)
STRUCT_FOR_ID(filename)
STRUCT_FOR_ID(fileno)
STRUCT_FOR_ID(filters)
STRUCT_FOR_ID(find_class)
STRUCT_FOR_ID(flush)
+ STRUCT_FOR_ID(genexpr)
STRUCT_FOR_ID(get)
STRUCT_FOR_ID(get_source)
STRUCT_FOR_ID(getattr)
+ STRUCT_FOR_ID(getstate)
STRUCT_FOR_ID(ignore)
STRUCT_FOR_ID(importlib)
+ STRUCT_FOR_ID(inf)
STRUCT_FOR_ID(intersection)
STRUCT_FOR_ID(isatty)
STRUCT_FOR_ID(items)
STRUCT_FOR_ID(iter)
+ STRUCT_FOR_ID(join)
STRUCT_FOR_ID(keys)
+ STRUCT_FOR_ID(lambda)
STRUCT_FOR_ID(last_traceback)
STRUCT_FOR_ID(last_type)
STRUCT_FOR_ID(last_value)
STRUCT_FOR_ID(latin1)
+ STRUCT_FOR_ID(line)
STRUCT_FOR_ID(lineno)
+ STRUCT_FOR_ID(listcomp)
STRUCT_FOR_ID(little)
+ STRUCT_FOR_ID(locale)
STRUCT_FOR_ID(match)
STRUCT_FOR_ID(metaclass)
STRUCT_FOR_ID(mode)
STRUCT_FOR_ID(n_sequence_fields)
STRUCT_FOR_ID(n_unnamed_fields)
STRUCT_FOR_ID(name)
+ STRUCT_FOR_ID(newlines)
STRUCT_FOR_ID(obj)
STRUCT_FOR_ID(offset)
STRUCT_FOR_ID(onceregistry)
+ STRUCT_FOR_ID(opcode)
STRUCT_FOR_ID(open)
STRUCT_FOR_ID(parent)
STRUCT_FOR_ID(partial)
STRUCT_FOR_ID(seek)
STRUCT_FOR_ID(seekable)
STRUCT_FOR_ID(send)
+ STRUCT_FOR_ID(setcomp)
STRUCT_FOR_ID(setstate)
STRUCT_FOR_ID(sort)
STRUCT_FOR_ID(stderr)
STRUCT_FOR_ID(text)
STRUCT_FOR_ID(threading)
STRUCT_FOR_ID(throw)
+ STRUCT_FOR_ID(top)
+ STRUCT_FOR_ID(truncate)
STRUCT_FOR_ID(unraisablehook)
STRUCT_FOR_ID(values)
STRUCT_FOR_ID(version)
INIT_STR(anon_module, "<module>"), \
INIT_STR(anon_setcomp, "<setcomp>"), \
INIT_STR(anon_string, "<string>"), \
+ INIT_STR(anon_unknown, "<unknown>"), \
+ INIT_STR(close_br, "}"), \
INIT_STR(comma_sep, ", "), \
+ INIT_STR(dbl_close_br, "}}"), \
+ INIT_STR(dbl_open_br, "{{"), \
INIT_STR(dbl_percent, "%%"), \
INIT_STR(dot, "."), \
INIT_STR(dot_locals, ".<locals>"), \
INIT_STR(empty, ""), \
+ INIT_STR(list_err, "list index out of range"), \
+ INIT_STR(newline, "\n"), \
+ INIT_STR(open_br, "{"), \
INIT_STR(percent, "%"), \
}, \
.identifiers = { \
+ INIT_ID(False), \
INIT_ID(Py_Repr), \
INIT_ID(TextIOWrapper), \
+ INIT_ID(True), \
INIT_ID(WarningMessage), \
INIT_ID(_), \
INIT_ID(__IOBase_closed), \
INIT_ID(__weakref__), \
INIT_ID(__xor__), \
INIT_ID(_abc_impl), \
+ INIT_ID(_annotation), \
INIT_ID(_blksize), \
+ INIT_ID(_bootstrap), \
INIT_ID(_dealloc_warn), \
INIT_ID(_finalizing), \
INIT_ID(_find_and_load), \
INIT_ID(big), \
INIT_ID(buffer), \
INIT_ID(builtins), \
+ INIT_ID(c_call), \
+ INIT_ID(c_exception), \
+ INIT_ID(c_return), \
+ INIT_ID(call), \
INIT_ID(clear), \
INIT_ID(close), \
+ INIT_ID(closed), \
INIT_ID(code), \
INIT_ID(copy), \
INIT_ID(copyreg), \
INIT_ID(decode), \
INIT_ID(default), \
INIT_ID(defaultaction), \
+ INIT_ID(dictcomp), \
INIT_ID(difference_update), \
INIT_ID(dispatch_table), \
INIT_ID(displayhook), \
INIT_ID(enable), \
+ INIT_ID(encode), \
INIT_ID(encoding), \
INIT_ID(end_lineno), \
INIT_ID(end_offset), \
INIT_ID(errors), \
INIT_ID(excepthook), \
+ INIT_ID(exception), \
INIT_ID(extend), \
INIT_ID(filename), \
INIT_ID(fileno), \
INIT_ID(filters), \
INIT_ID(find_class), \
INIT_ID(flush), \
+ INIT_ID(genexpr), \
INIT_ID(get), \
INIT_ID(get_source), \
INIT_ID(getattr), \
+ INIT_ID(getstate), \
INIT_ID(ignore), \
INIT_ID(importlib), \
+ INIT_ID(inf), \
INIT_ID(intersection), \
INIT_ID(isatty), \
INIT_ID(items), \
INIT_ID(iter), \
+ INIT_ID(join), \
INIT_ID(keys), \
+ INIT_ID(lambda), \
INIT_ID(last_traceback), \
INIT_ID(last_type), \
INIT_ID(last_value), \
INIT_ID(latin1), \
+ INIT_ID(line), \
INIT_ID(lineno), \
+ INIT_ID(listcomp), \
INIT_ID(little), \
+ INIT_ID(locale), \
INIT_ID(match), \
INIT_ID(metaclass), \
INIT_ID(mode), \
INIT_ID(n_sequence_fields), \
INIT_ID(n_unnamed_fields), \
INIT_ID(name), \
+ INIT_ID(newlines), \
INIT_ID(obj), \
INIT_ID(offset), \
INIT_ID(onceregistry), \
+ INIT_ID(opcode), \
INIT_ID(open), \
INIT_ID(parent), \
INIT_ID(partial), \
INIT_ID(seek), \
INIT_ID(seekable), \
INIT_ID(send), \
+ INIT_ID(setcomp), \
INIT_ID(setstate), \
INIT_ID(sort), \
INIT_ID(stderr), \
INIT_ID(text), \
INIT_ID(threading), \
INIT_ID(throw), \
+ INIT_ID(top), \
+ INIT_ID(truncate), \
INIT_ID(unraisablehook), \
INIT_ID(values), \
INIT_ID(version), \
int start,
PyCompilerFlags *flags);
-extern void _PySymtable_Fini(void);
-
#ifdef __cplusplus
}
#endif
#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"
return NULL;
}
}
- Py_INCREF(_PyIO_str_locale);
- return _PyIO_str_locale;
+ return &_Py_ID(locale);
}
Py_INCREF(encoding);
return encoding;
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);
}
}
}
- /* 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;
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;
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
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);
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 *
}
/* 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)
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);
{
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);
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 *
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 */
{
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);
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);
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)
}
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 */
}
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, "
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)
}
_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) {
}
/* 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)) {
goto cleanup;
}
else {
- tmp = _PyBytes_Join(_PyIO_empty_bytes, chunks);
+ tmp = _PyBytes_Join((PyObject *)&_Py_SINGLETON(bytes_empty), chunks);
res = tmp;
goto cleanup;
}
*/
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);
"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));
}
\f
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);
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);
/* 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;
}
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). */
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) {
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) {
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) {
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 */
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;
}
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;
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) {
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;
return NULL;
}
}
- result = _PyBytes_Join(_PyIO_empty_bytes, chunks);
+ result = _PyBytes_Join((PyObject *)&_Py_SINGLETON(bytes_empty), chunks);
Py_DECREF(chunks);
return result;
}
}
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;
}
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, "
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"
/* 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;
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)) {
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;
}
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)
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;
}
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;
}
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;
}
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;
}
{
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);
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
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);
}
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);
* 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
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)
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;
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);
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;
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),
{
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;
}
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);
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;
/* 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)) { \
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 *
}
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, "
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 *
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;
}
#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>
[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
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 */
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;
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);
#ifdef REENTRANT_THREADLOCAL
PyThread_tss_delete(&tracemalloc_reentrant_key);
#endif
-
- Py_XDECREF(unknown_filename);
}
/* Boolean type, a subtype of int */
#include "Python.h"
+#include "pycore_runtime.h" // _Py_ID()
#include "pycore_pyerrors.h" // _Py_FatalRefcountError()
/* We define bool_repr to return "False" or "True" */
-static PyObject *false_str = NULL;
-static PyObject *true_str = NULL;
-
static PyObject *
bool_repr(PyObject *self)
{
- PyObject *s;
-
- if (self == Py_True)
- s = true_str ? true_str :
- (true_str = PyUnicode_InternFromString("True"));
- else
- s = false_str ? false_str :
- (false_str = PyUnicode_InternFromString("False"));
- Py_XINCREF(s);
- return s;
+ return self == Py_True ? &_Py_ID(True) : &_Py_ID(False);
}
/* Function to return a bool from a C long */
static PyObject *
method_get_doc(PyMethodObject *im, void *context)
{
- static PyObject *docstr;
- if (docstr == NULL) {
- docstr= PyUnicode_InternFromString("__doc__");
- if (docstr == NULL)
- return NULL;
- }
- return PyObject_GetAttr(im->im_func, docstr);
+ return PyObject_GetAttr(im->im_func, &_Py_ID(__doc__));
}
static PyGetSetDef method_getset[] = {
static PyObject *
instancemethod_get_doc(PyObject *self, void *context)
{
- static PyObject *docstr;
- if (docstr == NULL) {
- docstr = PyUnicode_InternFromString("__doc__");
- if (docstr == NULL)
- return NULL;
- }
- return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), docstr);
+ return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self),
+ &_Py_ID(__doc__));
}
static PyGetSetDef instancemethod_getset[] = {
PyCodeObject *
PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno)
{
- PyObject *emptystring = NULL;
PyObject *nulltuple = NULL;
PyObject *filename_ob = NULL;
PyObject *funcname_ob = NULL;
PyCodeObject *result = NULL;
- emptystring = PyBytes_FromString("");
- if (emptystring == NULL) {
- goto failed;
- }
nulltuple = PyTuple_New(0);
if (nulltuple == NULL) {
goto failed;
goto failed;
}
+#define emptystring (PyObject *)&_Py_SINGLETON(bytes_empty)
struct _PyCodeConstructor con = {
.filename = filename_ob,
.name = funcname_ob,
result = _PyCode_New(&con);
failed:
- Py_XDECREF(emptystring);
Py_XDECREF(nulltuple);
Py_XDECREF(funcname_ob);
Py_XDECREF(filename_ob);
#include "clinic/listobject.c.h"
-static PyObject *indexerr = NULL;
+_Py_DECLARE_STR(list_err, "list index out of range");
#if PyList_MAXFREELIST > 0
static struct _Py_list_state *
struct _Py_list_state *state = &interp->list;
state->numfree = -1;
#endif
-
- if (_Py_IsMainInterpreter(interp)) {
- Py_CLEAR(indexerr);
- }
}
/* Print summary info about the state of the optimized allocator */
return NULL;
}
if (!valid_index(i, Py_SIZE(op))) {
- if (indexerr == NULL) {
- indexerr = PyUnicode_FromString(
- "list index out of range");
- if (indexerr == NULL)
- return NULL;
- }
- PyErr_SetObject(PyExc_IndexError, indexerr);
+ _Py_DECLARE_STR(list_err, "list index out of range");
+ PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err));
return NULL;
}
return ((PyListObject *)op) -> ob_item[i];
list_item(PyListObject *a, Py_ssize_t i)
{
if (!valid_index(i, Py_SIZE(a))) {
- if (indexerr == NULL) {
- indexerr = PyUnicode_FromString(
- "list index out of range");
- if (indexerr == NULL)
- return NULL;
- }
- PyErr_SetObject(PyExc_IndexError, indexerr);
+ PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err));
return NULL;
}
Py_INCREF(a->ob_item[i]);
static int
is_internal_frame(PyFrameObject *frame)
{
- static PyObject *importlib_string = NULL;
- static PyObject *bootstrap_string = NULL;
- int contains;
-
- if (importlib_string == NULL) {
- importlib_string = PyUnicode_FromString("importlib");
- if (importlib_string == NULL) {
- return 0;
- }
-
- bootstrap_string = PyUnicode_FromString("_bootstrap");
- if (bootstrap_string == NULL) {
- Py_DECREF(importlib_string);
- return 0;
- }
- Py_INCREF(importlib_string);
- Py_INCREF(bootstrap_string);
- }
-
if (frame == NULL) {
return 0;
}
return 0;
}
- contains = PyUnicode_Contains(filename, importlib_string);
+ int contains = PyUnicode_Contains(filename, &_Py_ID(importlib));
if (contains < 0) {
return 0;
}
else if (contains > 0) {
- contains = PyUnicode_Contains(filename, bootstrap_string);
+ contains = PyUnicode_Contains(filename, &_Py_ID(_bootstrap));
if (contains < 0) {
return 0;
}
#include "Python.h"
#include "pycore_ast.h" // expr_ty
+#include "pycore_runtime.h" // _Py_ID()
#include <float.h> // DBL_MAX_10_EXP
#include <stdbool.h>
* See ast.unparse for a full unparser (written in Python)
*/
-static PyObject *_str_open_br;
-static PyObject *_str_dbl_open_br;
-static PyObject *_str_close_br;
-static PyObject *_str_dbl_close_br;
-static PyObject *_str_inf;
+_Py_DECLARE_STR(open_br, "{");
+_Py_DECLARE_STR(dbl_open_br, "{{");
+_Py_DECLARE_STR(close_br, "}");
+_Py_DECLARE_STR(dbl_close_br, "}}");
static PyObject *_str_replace_inf;
/* Forward declarations for recursion via helper functions. */
{
PyObject *new_repr = PyUnicode_Replace(
repr,
- _str_inf,
+ &_Py_ID(inf),
_str_replace_inf,
-1
);
{
PyObject *temp;
PyObject *result;
- temp = PyUnicode_Replace(orig, _str_open_br, _str_dbl_open_br, -1);
+ temp = PyUnicode_Replace(orig, &_Py_STR(open_br), &_Py_STR(dbl_open_br), -1);
if (!temp) {
return NULL;
}
- result = PyUnicode_Replace(temp, _str_close_br, _str_dbl_close_br, -1);
+ result = PyUnicode_Replace(temp, &_Py_STR(close_br), &_Py_STR(dbl_close_br), -1);
Py_DECREF(temp);
return result;
}
if (!temp_fv_str) {
return -1;
}
- if (PyUnicode_Find(temp_fv_str, _str_open_br, 0, 1, 1) == 0) {
+ if (PyUnicode_Find(temp_fv_str, &_Py_STR(open_br), 0, 1, 1) == 0) {
/* Expression starts with a brace, split it with a space from the outer
one. */
outer_brace = "{ ";
static int
maybe_init_static_strings(void)
{
- if (!_str_open_br &&
- !(_str_open_br = PyUnicode_InternFromString("{"))) {
- return -1;
- }
- if (!_str_dbl_open_br &&
- !(_str_dbl_open_br = PyUnicode_InternFromString("{{"))) {
- return -1;
- }
- if (!_str_close_br &&
- !(_str_close_br = PyUnicode_InternFromString("}"))) {
- return -1;
- }
- if (!_str_dbl_close_br &&
- !(_str_dbl_close_br = PyUnicode_InternFromString("}}"))) {
- return -1;
- }
- if (!_str_inf &&
- !(_str_inf = PyUnicode_FromString("inf"))) {
- return -1;
- }
if (!_str_replace_inf &&
!(_str_replace_inf = PyUnicode_FromFormat("1e%d", 1 + DBL_MAX_10_EXP))) {
return -1;
compiler_class(struct compiler *c, stmt_ty s)
{
PyCodeObject *co;
- PyObject *str;
int i, firstlineno;
asdl_expr_seq *decos = s->v.ClassDef.decorator_list;
Py_INCREF(s->v.ClassDef.name);
Py_XSETREF(c->u->u_private, s->v.ClassDef.name);
/* load (global) __name__ ... */
- str = PyUnicode_InternFromString("__name__");
- if (!str || !compiler_nameop(c, str, Load)) {
- Py_XDECREF(str);
+ if (!compiler_nameop(c, &_Py_ID(__name__), Load)) {
compiler_exit_scope(c);
return 0;
}
- Py_DECREF(str);
/* ... and store it as __module__ */
- str = PyUnicode_InternFromString("__module__");
- if (!str || !compiler_nameop(c, str, Store)) {
- Py_XDECREF(str);
+ if (!compiler_nameop(c, &_Py_ID(__module__), Store)) {
compiler_exit_scope(c);
return 0;
}
- Py_DECREF(str);
assert(c->u->u_qualname);
ADDOP_LOAD_CONST(c, c->u->u_qualname);
- str = PyUnicode_InternFromString("__qualname__");
- if (!str || !compiler_nameop(c, str, Store)) {
- Py_XDECREF(str);
+ if (!compiler_nameop(c, &_Py_ID(__qualname__), Store)) {
compiler_exit_scope(c);
return 0;
}
- Py_DECREF(str);
/* compile the body proper */
if (!compiler_body(c, s->v.ClassDef.body)) {
compiler_exit_scope(c);
/* Return __classcell__ if it is referenced, otherwise return None */
if (c->u->u_ste->ste_needs_class_closure) {
/* Store __classcell__ into class namespace & return it */
- str = PyUnicode_InternFromString("__class__");
- if (str == NULL) {
- compiler_exit_scope(c);
- return 0;
- }
- i = compiler_lookup_arg(c->u->u_cellvars, str);
- Py_DECREF(str);
+ i = compiler_lookup_arg(c->u->u_cellvars, &_Py_ID(__class__));
if (i < 0) {
compiler_exit_scope(c);
return 0;
ADDOP_I(c, LOAD_CLOSURE, i);
ADDOP_I(c, COPY, 1);
- str = PyUnicode_InternFromString("__classcell__");
- if (!str || !compiler_nameop(c, str, Store)) {
- Py_XDECREF(str);
+ if (!compiler_nameop(c, &_Py_ID(__classcell__), Store)) {
compiler_exit_scope(c);
return 0;
}
- Py_DECREF(str);
}
else {
/* No methods referenced __class__, so just return None */
Py_ssize_t value_count = asdl_seq_LEN(e->v.JoinedStr.values);
if (value_count > STACK_USE_GUIDELINE) {
- ADDOP_LOAD_CONST_NEW(c, _PyUnicode_FromASCII("", 0));
- PyObject *join = _PyUnicode_FromASCII("join", 4);
- if (join == NULL) {
- return 0;
- }
- ADDOP_NAME(c, LOAD_METHOD, join, names);
- Py_DECREF(join);
+ ADDOP_LOAD_CONST_NEW(c, &_Py_STR(empty));
+ ADDOP_NAME(c, LOAD_METHOD, &_Py_ID(join), names);
ADDOP_I(c, BUILD_LIST, 0);
for (Py_ssize_t i = 0; i < asdl_seq_LEN(e->v.JoinedStr.values); i++) {
VISIT(c, expr, asdl_seq_GET(e->v.JoinedStr.values, i));
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_runtime_init.h" // _PyRuntimeState_INIT
#include "pycore_sliceobject.h" // _PySlice_Fini()
-#include "pycore_symtable.h" // _PySymtable_Fini()
#include "pycore_sysmodule.h" // _PySys_ClearAuditHooks()
#include "pycore_traceback.h" // _Py_DumpTracebackThreads()
#include "pycore_tuple.h" // _PyTuple_InitTypes()
int is_main_interp = _Py_IsMainInterpreter(tstate->interp);
_PyExc_ClearExceptionGroupType(tstate->interp);
- if (is_main_interp) {
- _PySymtable_Fini();
- }
/* Clear interpreter state and all thread states */
_PyInterpreterState_Clear(tstate);
static int symtable_raise_if_comprehension_block(struct symtable *st, expr_ty);
-static identifier top = NULL, lambda = NULL, genexpr = NULL,
- listcomp = NULL, setcomp = NULL, dictcomp = NULL,
- __class__ = NULL, _annotation = NULL;
-
-#define GET_IDENTIFIER(VAR) \
- ((VAR) ? (VAR) : ((VAR) = PyUnicode_InternFromString(# VAR)))
-
#define DUPLICATE_ARGUMENT \
"duplicate argument '%U' in function definition"
recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit;
/* Make the initial symbol information gathering pass */
- if (!GET_IDENTIFIER(top) ||
- !symtable_enter_block(st, top, ModuleBlock, (void *)mod, 0, 0, 0, 0)) {
+ if (!symtable_enter_block(st, &_Py_ID(top), ModuleBlock, (void *)mod, 0, 0, 0, 0)) {
_PySymtable_Free(st);
return NULL;
}
drop_class_free(PySTEntryObject *ste, PyObject *free)
{
int res;
- if (!GET_IDENTIFIER(__class__))
- return 0;
- res = PySet_Discard(free, __class__);
+ res = PySet_Discard(free, &_Py_ID(__class__));
if (res < 0)
return 0;
if (res)
}
else {
/* Special-case __class__ */
- if (!GET_IDENTIFIER(__class__))
- goto error;
- if (PySet_Add(newbound, __class__) < 0)
+ if (PySet_Add(newbound, &_Py_ID(__class__)) < 0)
goto error;
}
VISIT(st, expr, e->v.UnaryOp.operand);
break;
case Lambda_kind: {
- if (!GET_IDENTIFIER(lambda))
- VISIT_QUIT(st, 0);
if (e->v.Lambda.args->defaults)
VISIT_SEQ(st, expr, e->v.Lambda.args->defaults);
if (e->v.Lambda.args->kw_defaults)
VISIT_SEQ_WITH_NULL(st, expr, e->v.Lambda.args->kw_defaults);
- if (!symtable_enter_block(st, lambda,
+ if (!symtable_enter_block(st, &_Py_ID(lambda),
FunctionBlock, (void *)e,
e->lineno, e->col_offset,
e->end_lineno, e->end_col_offset))
if (e->v.Name.ctx == Load &&
st->st_cur->ste_type == FunctionBlock &&
_PyUnicode_EqualToASCIIString(e->v.Name.id, "super")) {
- if (!GET_IDENTIFIER(__class__) ||
- !symtable_add_def(st, __class__, USE, LOCATION(e)))
+ if (!symtable_add_def(st, &_Py_ID(__class__), USE, LOCATION(e)))
VISIT_QUIT(st, 0);
}
break;
{
int future_annotations = st->st_future->ff_features & CO_FUTURE_ANNOTATIONS;
if (future_annotations &&
- !symtable_enter_block(st, GET_IDENTIFIER(_annotation), AnnotationBlock,
+ !symtable_enter_block(st, &_Py_ID(_annotation), AnnotationBlock,
(void *)annotation, annotation->lineno,
annotation->col_offset, annotation->end_lineno,
annotation->end_col_offset)) {
{
int future_annotations = st->st_future->ff_features & CO_FUTURE_ANNOTATIONS;
if (future_annotations &&
- !symtable_enter_block(st, GET_IDENTIFIER(_annotation), AnnotationBlock,
+ !symtable_enter_block(st, &_Py_ID(_annotation), AnnotationBlock,
(void *)o, o->lineno, o->col_offset, o->end_lineno,
o->end_col_offset)) {
VISIT_QUIT(st, 0);
static int
symtable_visit_genexp(struct symtable *st, expr_ty e)
{
- return symtable_handle_comprehension(st, e, GET_IDENTIFIER(genexpr),
+ return symtable_handle_comprehension(st, e, &_Py_ID(genexpr),
e->v.GeneratorExp.generators,
e->v.GeneratorExp.elt, NULL);
}
static int
symtable_visit_listcomp(struct symtable *st, expr_ty e)
{
- return symtable_handle_comprehension(st, e, GET_IDENTIFIER(listcomp),
+ return symtable_handle_comprehension(st, e, &_Py_ID(listcomp),
e->v.ListComp.generators,
e->v.ListComp.elt, NULL);
}
static int
symtable_visit_setcomp(struct symtable *st, expr_ty e)
{
- return symtable_handle_comprehension(st, e, GET_IDENTIFIER(setcomp),
+ return symtable_handle_comprehension(st, e, &_Py_ID(setcomp),
e->v.SetComp.generators,
e->v.SetComp.elt, NULL);
}
static int
symtable_visit_dictcomp(struct symtable *st, expr_ty e)
{
- return symtable_handle_comprehension(st, e, GET_IDENTIFIER(dictcomp),
+ return symtable_handle_comprehension(st, e, &_Py_ID(dictcomp),
e->v.DictComp.generators,
e->v.DictComp.key,
e->v.DictComp.value);
_PyArena_Free(arena);
return st;
}
-
-void
-_PySymtable_Fini(void)
-{
- Py_CLEAR(top);
- Py_CLEAR(lambda);
- Py_CLEAR(genexpr);
- Py_CLEAR(listcomp);
- Py_CLEAR(setcomp);
- Py_CLEAR(dictcomp);
- Py_CLEAR(__class__);
- Py_CLEAR(_annotation);
-}
{
PyObject *outf;
PyObject *builtins;
- static PyObject *newline = NULL;
PyThreadState *tstate = _PyThreadState_GET();
builtins = PyImport_GetModule(&_Py_ID(builtins));
return NULL;
}
}
- if (newline == NULL) {
- newline = PyUnicode_FromString("\n");
- if (newline == NULL)
- return NULL;
- }
- if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0)
+ _Py_DECLARE_STR(newline, "\n");
+ if (PyFile_WriteObject(&_Py_STR(newline), outf, Py_PRINT_RAW) != 0)
return NULL;
if (PyObject_SetAttr(builtins, &_Py_ID(_), o) != 0)
return NULL;
/*
* Cached interned string objects used for calling the profile and
- * trace functions. Initialized by trace_init().
+ * trace functions.
*/
-static PyObject *whatstrings[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
-
-static int
-trace_init(void)
-{
- static const char * const whatnames[8] = {
- "call", "exception", "line", "return",
- "c_call", "c_exception", "c_return",
- "opcode"
- };
- PyObject *name;
- int i;
- for (i = 0; i < 8; ++i) {
- if (whatstrings[i] == NULL) {
- name = PyUnicode_InternFromString(whatnames[i]);
- if (name == NULL)
- return -1;
- whatstrings[i] = name;
- }
- }
- return 0;
-}
+static PyObject *whatstrings[8] = {
+ &_Py_ID(call),
+ &_Py_ID(exception),
+ &_Py_ID(line),
+ &_Py_ID(return),
+ &_Py_ID(c_call),
+ &_Py_ID(c_exception),
+ &_Py_ID(c_return),
+ &_Py_ID(opcode),
+};
static PyObject *
static PyObject *
sys_settrace(PyObject *self, PyObject *args)
{
- if (trace_init() == -1) {
- return NULL;
- }
-
PyThreadState *tstate = _PyThreadState_GET();
if (args == Py_None) {
if (_PyEval_SetTrace(tstate, NULL, NULL) < 0) {
static PyObject *
sys_setprofile(PyObject *self, PyObject *args)
{
- if (trace_init() == -1) {
- return NULL;
- }
-
PyThreadState *tstate = _PyThreadState_GET();
if (args == Py_None) {
if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) {
# cached - initialized once
# manually cached PyUnicodeObject
-Objects/boolobject.c - false_str -
-Objects/boolobject.c - true_str -
-Objects/classobject.c method_get_doc docstr -
-Objects/classobject.c instancemethod_get_doc docstr -
-Objects/codeobject.c PyCode_NewEmpty emptystring -
-Objects/exceptions.c _check_for_legacy_statements print_prefix -
-Objects/exceptions.c _check_for_legacy_statements exec_prefix -
-Objects/funcobject.c PyFunction_NewWithQualName __name__ -
-Objects/listobject.c - indexerr -
-Objects/typeobject.c object___reduce_ex___impl objreduce -
-# XXX This should have been found by the analyzer but wasn't:
-Python/_warnings.c is_internal_frame bootstrap_string -
-# XXX This should have been found by the analyzer but wasn't:
-Python/_warnings.c is_internal_frame importlib_string -
-# XXX This should have been found by the analyzer but wasn't:
-Python/ast_unparse.c - _str_close_br -
-# XXX This should have been found by the analyzer but wasn't:
-Python/ast_unparse.c - _str_dbl_close_br -
-# XXX This should have been found by the analyzer but wasn't:
-Python/ast_unparse.c - _str_dbl_open_br -
-# XXX This should have been found by the analyzer but wasn't:
-Python/ast_unparse.c - _str_inf -
-# XXX This should have been found by the analyzer but wasn't:
-Python/ast_unparse.c - _str_open_br -
# XXX This should have been found by the analyzer but wasn't:
Python/ast_unparse.c - _str_replace_inf -
-# XXX This should have been found by the analyzer but wasn't:
-Python/compile.c - __annotations__ -
-# XXX This should have been found by the analyzer but wasn't:
-Python/compile.c - __doc__ -
-# XXX This should have been found by the analyzer but wasn't:
-Python/compile.c compiler_dictcomp name -
-# XXX This should have been found by the analyzer but wasn't:
-Python/compile.c compiler_from_import empty_string -
-# XXX This should have been found by the analyzer but wasn't:
-Python/compile.c compiler_genexp name -
-# XXX This should have been found by the analyzer but wasn't:
-Python/compile.c compiler_lambda name -
-# XXX This should have been found by the analyzer but wasn't:
-Python/compile.c compiler_listcomp name -
-# XXX This should have been found by the analyzer but wasn't:
-Python/compile.c compiler_setcomp name -
-# XXX This should have been found by the analyzer but wasn't:
-Python/compile.c compiler_visit_annotations return_str -
-# XXX This should have been found by the analyzer but wasn't:
-Python/import.c PyImport_Import builtins_str -
-# XXX This should have been found by the analyzer but wasn't:
-Python/import.c PyImport_Import import_str -
-Python/symtable.c - __class__ -
-Python/symtable.c - _annotation -
-Python/symtable.c - dictcomp -
-Python/symtable.c - genexpr -
-Python/symtable.c - lambda -
-Python/symtable.c - listcomp -
-Python/symtable.c - setcomp -
-Python/symtable.c - top -
-# XXX This should have been found by the analyzer but wasn't:
-Python/sysmodule.c - whatstrings -
-# XXX This should have been found by the analyzer but wasn't:
-Python/sysmodule.c sys_displayhook newline -
# _PyArg_Parser (holds tuple of strings)
Objects/clinic/bytearrayobject.c.h bytearray___init__ _parser -
# other
Objects/typeobject.c - method_cache -
+Objects/typeobject.c object___reduce_ex___impl objreduce -
Objects/unicodeobject.c - _string_module -
Objects/unicodeobject.c - interned -
Objects/unicodeobject.c - static_strings -
#-----------------------
# cached - initialized once
-# manually cached PyUnicodeOjbect
-Modules/_io/_iomodule.c - _PyIO_str_close -
-Modules/_io/_iomodule.c - _PyIO_str_closed -
-Modules/_io/_iomodule.c - _PyIO_str_decode -
-Modules/_io/_iomodule.c - _PyIO_str_encode -
-Modules/_io/_iomodule.c - _PyIO_str_fileno -
-Modules/_io/_iomodule.c - _PyIO_str_flush -
-Modules/_io/_iomodule.c - _PyIO_str_getstate -
-Modules/_io/_iomodule.c - _PyIO_str_isatty -
-Modules/_io/_iomodule.c - _PyIO_str_locale -
-Modules/_io/_iomodule.c - _PyIO_str_newlines -
-Modules/_io/_iomodule.c - _PyIO_str_nl -
-Modules/_io/_iomodule.c - _PyIO_str_peek -
-Modules/_io/_iomodule.c - _PyIO_str_read -
-Modules/_io/_iomodule.c - _PyIO_str_read1 -
-Modules/_io/_iomodule.c - _PyIO_str_readable -
-Modules/_io/_iomodule.c - _PyIO_str_readall -
-Modules/_io/_iomodule.c - _PyIO_str_readinto -
-Modules/_io/_iomodule.c - _PyIO_str_readline -
-Modules/_io/_iomodule.c - _PyIO_str_reset -
-Modules/_io/_iomodule.c - _PyIO_str_seek -
-Modules/_io/_iomodule.c - _PyIO_str_seekable -
-Modules/_io/_iomodule.c - _PyIO_str_setstate -
-Modules/_io/_iomodule.c - _PyIO_str_tell -
-Modules/_io/_iomodule.c - _PyIO_str_truncate -
-Modules/_io/_iomodule.c - _PyIO_str_writable -
-Modules/_io/_iomodule.c - _PyIO_str_write -
-Modules/_io/_iomodule.c - _PyIO_empty_str -
-Modules/_threadmodule.c - str_dict -
-Modules/_tracemalloc.c - unknown_filename -
-
# _PyArg_Parser
Modules/clinic/_codecsmodule.c.h _codecs_decode _parser -
Modules/clinic/_codecsmodule.c.h _codecs_encode _parser -
Python/specialize.c - adaptive_opcodes -
Python/specialize.c - cache_requirements -
Python/specialize.c - compare_masks -
+Python/sysmodule.c - whatstrings -