diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index aa597bc8281..2a42dc16ce1 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -35,17 +35,26 @@ struct _Py_global_strings { STRUCT_FOR_STR(anon_module, "") STRUCT_FOR_STR(anon_setcomp, "") STRUCT_FOR_STR(anon_string, "") + STRUCT_FOR_STR(anon_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, ".") 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) @@ -194,7 +203,9 @@ struct _Py_global_strings { 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) @@ -216,23 +227,31 @@ struct _Py_global_strings { 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) @@ -240,22 +259,30 @@ struct _Py_global_strings { 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) @@ -266,9 +293,11 @@ struct _Py_global_strings { 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) @@ -296,6 +325,7 @@ struct _Py_global_strings { 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) @@ -307,6 +337,8 @@ struct _Py_global_strings { 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) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 04c1e671235..8f623434433 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -651,16 +651,25 @@ extern "C" { INIT_STR(anon_module, ""), \ INIT_STR(anon_setcomp, ""), \ INIT_STR(anon_string, ""), \ + INIT_STR(anon_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, "."), \ 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), \ @@ -809,7 +818,9 @@ extern "C" { 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), \ @@ -831,23 +842,31 @@ extern "C" { 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), \ @@ -855,22 +874,30 @@ extern "C" { 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), \ @@ -881,9 +908,11 @@ extern "C" { 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), \ @@ -911,6 +940,7 @@ extern "C" { INIT_ID(seek), \ INIT_ID(seekable), \ INIT_ID(send), \ + INIT_ID(setcomp), \ INIT_ID(setstate), \ INIT_ID(sort), \ INIT_ID(stderr), \ @@ -922,6 +952,8 @@ extern "C" { INIT_ID(text), \ INIT_ID(threading), \ INIT_ID(throw), \ + INIT_ID(top), \ + INIT_ID(truncate), \ INIT_ID(unraisablehook), \ INIT_ID(values), \ INIT_ID(version), \ diff --git a/Include/internal/pycore_symtable.h b/Include/internal/pycore_symtable.h index 4ecfab55850..28935f4ed55 100644 --- a/Include/internal/pycore_symtable.h +++ b/Include/internal/pycore_symtable.h @@ -128,8 +128,6 @@ extern struct symtable* _Py_SymtableStringObjectFlags( int start, PyCompilerFlags *flags); -extern void _PySymtable_Fini(void); - #ifdef __cplusplus } #endif diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 9ecc6718cb1..7f029f26078 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -24,38 +24,6 @@ #include #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 638797fd357..c260080f0e3 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 bb93ae361f8..ac30d1d632b 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 @@ _buffered_readline(buffered *self, Py_ssize_t limit) 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 74663e007b1..b00b6b983ee 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 e76152e617b..3fe02d35924 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 d5ceec7981f..ca59a4ef271 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 14bad00e4c6..53e329989ab 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 @@ -15,6 +16,8 @@ module _tracemalloc [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=708a98302fc46e5f]*/ +_Py_DECLARE_STR(anon_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(""); - 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); } diff --git a/Objects/boolobject.c b/Objects/boolobject.c index 53f81926057..d86958aff9c 100644 --- a/Objects/boolobject.c +++ b/Objects/boolobject.c @@ -1,26 +1,15 @@ /* 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 */ diff --git a/Objects/classobject.c b/Objects/classobject.c index d7ccf31244e..3b1c25394f1 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -157,13 +157,7 @@ static PyMemberDef method_memberlist[] = { 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[] = { @@ -405,13 +399,8 @@ static PyMemberDef instancemethod_memberlist[] = { 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[] = { diff --git a/Objects/codeobject.c b/Objects/codeobject.c index 9a27f1295b1..f8ef1e6b40c 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -553,16 +553,11 @@ PyCode_New(int argcount, int kwonlyargcount, 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; @@ -576,6 +571,7 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) goto failed; } +#define emptystring (PyObject *)&_Py_SINGLETON(bytes_empty) struct _PyCodeConstructor con = { .filename = filename_ob, .name = funcname_ob, @@ -594,7 +590,6 @@ PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno) result = _PyCode_New(&con); failed: - Py_XDECREF(emptystring); Py_XDECREF(nulltuple); Py_XDECREF(funcname_ob); Py_XDECREF(filename_ob); diff --git a/Objects/listobject.c b/Objects/listobject.c index 1ba1c1b0531..783ae88a17f 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -15,7 +15,7 @@ class list "PyListObject *" "&PyList_Type" #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 * @@ -125,10 +125,6 @@ _PyList_Fini(PyInterpreterState *interp) 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 */ @@ -238,13 +234,8 @@ PyList_GetItem(PyObject *op, Py_ssize_t i) 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]; @@ -452,13 +443,7 @@ static PyObject * 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]); diff --git a/Python/_warnings.c b/Python/_warnings.c index 03e6ffcee0a..be962e76cd8 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -768,25 +768,6 @@ warn_explicit(PyThreadState *tstate, PyObject *category, PyObject *message, 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; } @@ -802,12 +783,12 @@ is_internal_frame(PyFrameObject *frame) 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; } diff --git a/Python/ast_unparse.c b/Python/ast_unparse.c index 126e9047d58..f148e998652 100644 --- a/Python/ast_unparse.c +++ b/Python/ast_unparse.c @@ -1,5 +1,6 @@ #include "Python.h" #include "pycore_ast.h" // expr_ty +#include "pycore_runtime.h" // _Py_ID() #include // DBL_MAX_10_EXP #include @@ -8,11 +9,10 @@ * 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. */ @@ -80,7 +80,7 @@ append_repr(_PyUnicodeWriter *writer, PyObject *obj) { PyObject *new_repr = PyUnicode_Replace( repr, - _str_inf, + &_Py_ID(inf), _str_replace_inf, -1 ); @@ -575,11 +575,11 @@ escape_braces(PyObject *orig) { 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; } @@ -673,7 +673,7 @@ append_formattedvalue(_PyUnicodeWriter *writer, expr_ty e) 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 = "{ "; @@ -927,26 +927,6 @@ append_ast_expr(_PyUnicodeWriter *writer, expr_ty e, int level) 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; diff --git a/Python/compile.c b/Python/compile.c index 7f0a6f096d7..cb6e5e3550f 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2522,7 +2522,6 @@ static int compiler_class(struct compiler *c, stmt_ty s) { PyCodeObject *co; - PyObject *str; int i, firstlineno; asdl_expr_seq *decos = s->v.ClassDef.decorator_list; @@ -2557,30 +2556,21 @@ compiler_class(struct compiler *c, stmt_ty s) 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); @@ -2591,13 +2581,7 @@ compiler_class(struct compiler *c, stmt_ty s) /* 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; @@ -2606,13 +2590,10 @@ compiler_class(struct compiler *c, stmt_ty s) 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 */ @@ -4741,13 +4722,8 @@ compiler_joined_str(struct compiler *c, expr_ty e) 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)); diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 4a3a1abb3a4..b6310c9aeb8 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -24,7 +24,6 @@ #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() @@ -1690,9 +1689,6 @@ finalize_interp_clear(PyThreadState *tstate) 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); diff --git a/Python/symtable.c b/Python/symtable.c index e9bdff3eba1..0b259b08b61 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -230,13 +230,6 @@ static int symtable_raise_if_annotation_block(struct symtable *st, const char *, 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" @@ -313,8 +306,7 @@ _PySymtable_Build(mod_ty mod, PyObject *filename, PyFutureFeatures *future) 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; } @@ -619,9 +611,7 @@ static int 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) @@ -834,9 +824,7 @@ analyze_block(PySTEntryObject *ste, PyObject *bound, PyObject *free, } 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; } @@ -1610,13 +1598,11 @@ symtable_visit_expr(struct symtable *st, expr_ty e) 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)) @@ -1730,8 +1716,7 @@ symtable_visit_expr(struct symtable *st, expr_ty e) 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; @@ -1832,7 +1817,7 @@ symtable_visit_annotation(struct symtable *st, expr_ty annotation) { 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)) { @@ -1867,7 +1852,7 @@ symtable_visit_annotations(struct symtable *st, stmt_ty o, arguments_ty a, expr_ { 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); @@ -2085,7 +2070,7 @@ symtable_handle_comprehension(struct symtable *st, expr_ty e, 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); } @@ -2093,7 +2078,7 @@ symtable_visit_genexp(struct symtable *st, expr_ty e) 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); } @@ -2101,7 +2086,7 @@ symtable_visit_listcomp(struct symtable *st, expr_ty e) 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); } @@ -2109,7 +2094,7 @@ symtable_visit_setcomp(struct symtable *st, expr_ty e) 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); @@ -2173,16 +2158,3 @@ _Py_SymtableStringObjectFlags(const char *str, PyObject *filename, _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); -} diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 57bf04dd306..e23b879c1ab 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -706,7 +706,6 @@ sys_displayhook(PyObject *module, PyObject *o) { PyObject *outf; PyObject *builtins; - static PyObject *newline = NULL; PyThreadState *tstate = _PyThreadState_GET(); builtins = PyImport_GetModule(&_Py_ID(builtins)); @@ -747,12 +746,8 @@ sys_displayhook(PyObject *module, PyObject *o) 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; @@ -946,30 +941,18 @@ sys_intern_impl(PyObject *module, PyObject *s) /* * 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 * @@ -1050,10 +1033,6 @@ trace_trampoline(PyObject *self, PyFrameObject *frame, 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) { @@ -1099,10 +1078,6 @@ sys_gettrace_impl(PyObject *module) 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) { diff --git a/Tools/c-analyzer/cpython/globals-to-fix.tsv b/Tools/c-analyzer/cpython/globals-to-fix.tsv index 4ef0a6c848b..7e939277f1e 100644 --- a/Tools/c-analyzer/cpython/globals-to-fix.tsv +++ b/Tools/c-analyzer/cpython/globals-to-fix.tsv @@ -280,66 +280,8 @@ Objects/sliceobject.c - _Py_EllipsisObject - # 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 - @@ -402,6 +344,7 @@ Objects/typeobject.c - slotdefs - # 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 - @@ -666,37 +609,6 @@ Modules/signalmodule.c - ItimerError - #----------------------- # 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 - diff --git a/Tools/c-analyzer/cpython/ignored.tsv b/Tools/c-analyzer/cpython/ignored.tsv index c945542e29a..63d0695bfb4 100644 --- a/Tools/c-analyzer/cpython/ignored.tsv +++ b/Tools/c-analyzer/cpython/ignored.tsv @@ -1517,3 +1517,4 @@ Python/pylifecycle.c - _TARGET_LOCALES - Python/specialize.c - adaptive_opcodes - Python/specialize.c - cache_requirements - Python/specialize.c - compare_masks - +Python/sysmodule.c - whatstrings -