From ec0c931905edb704c469d70c6e0d2dc0a8a4e219 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 2 Dec 2021 11:39:01 -0700 Subject: [PATCH 001/115] Add _Py_STRING_LENGTH(). --- Include/pymacro.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Include/pymacro.h b/Include/pymacro.h index 2728496976de7e5..b83df5d399fcc07 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -65,6 +65,9 @@ (sizeof(array) / sizeof((array)[0])) #endif +#define _Py_STRING_LENGTH(str) \ + (sizeof(str) / sizeof(char)) + /* Define macros for inline documentation. */ #define PyDoc_VAR(name) static const char name[] From cea13355e95f6d19f9f9cd054c91093e51cf4d62 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 2 Dec 2021 10:04:36 -0700 Subject: [PATCH 002/115] Add PyInterpreterState._preallocated.strings (identifiers-only for now). --- Include/internal/pycore_global_strings.h | 307 +++++++++++++++++++++++ Include/internal/pycore_interp.h | 3 + Tools/c-analyzer/TODO | 2 - 3 files changed, 310 insertions(+), 2 deletions(-) create mode 100644 Include/internal/pycore_global_strings.h diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h new file mode 100644 index 000000000000000..ce0ef12a76558ca --- /dev/null +++ b/Include/internal/pycore_global_strings.h @@ -0,0 +1,307 @@ +#ifndef Py_INTERNAL_GLOBAL_STRINGS_H +#define Py_INTERNAL_GLOBAL_STRINGS_H +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef Py_BUILD_CORE +# error "this header requires Py_BUILD_CORE define" +#endif + +// The data structure & init here are inspired by Tools/scripts/deepfreeze.py. + +// All field names generated by STR() have an extra leading dollar sign. +// This helps avoid collisions with keywords, etc. + +#define STR(NAME, LITERAL) \ + struct { \ + PyASCIIObject _ascii; \ + uint8_t _data[_Py_STRING_LENGTH(LITERAL)]; \ + } $ ## NAME; +#define ID(NAME) \ + STR(NAME, #NAME) + +struct _Py_global_strings { + struct { + ID(Py_Repr) + ID(TextIOWrapper) + ID(WarningMessage) + ID(_) + ID(__IOBase_closed) + ID(__abs__) + ID(__abstractmethods__) + ID(__add__) + ID(__aenter__) + ID(__aexit__) + ID(__aiter__) + ID(__all__) + ID(__and__) + ID(__anext__) + ID(__annotations__) + ID(__await__) + ID(__bases__) + ID(__bool__) + ID(__build_class__) + ID(__builtins__) + ID(__bytes__) + ID(__call__) + ID(__class__) + ID(__class_getitem__) + ID(__classcell__) + ID(__complex__) + ID(__contains__) + ID(__copy__) + ID(__del__) + ID(__delattr__) + ID(__delete__) + ID(__delitem__) + ID(__dict__) + ID(__dir__) + ID(__divmod__) + ID(__doc__) // docstr + ID(__enter__) + ID(__eq__) + ID(__exit__) + ID(__file__) + ID(__float__) + ID(__floordiv__) + ID(__format__) + ID(__fspath__) + ID(__ge__) + ID(__get__) + ID(__getattr__) + ID(__getattribute__) + ID(__getitem__) + ID(__getnewargs__) + ID(__getnewargs_ex__) + ID(__getstate__) + ID(__gt__) + ID(__hash__) + ID(__iadd__) + ID(__iand__) + ID(__ifloordiv__) + ID(__ilshift__) + ID(__imatmul__) + ID(__imod__) + ID(__import__) + ID(__imul__) + ID(__index__) + ID(__init__) + ID(__init_subclass__) + ID(__instancecheck__) + ID(__int__) + ID(__invert__) + ID(__ior__) + ID(__ipow__) + ID(__irshift__) + ID(__isabstractmethod__) + ID(__isub__) + ID(__iter__) + ID(__itruediv__) + ID(__ixor__) + ID(__le__) + ID(__len__) + ID(__length_hint__) + ID(__loader__) + ID(__lshift__) + ID(__lt__) + ID(__ltrace__) + ID(__main__) + ID(__matmul__) + ID(__missing__) + ID(__mod__) + ID(__module__) + ID(__mro_entries__) + ID(__mul__) + ID(__name__) + ID(__ne__) + ID(__neg__) + ID(__new__) + ID(__newobj__) + ID(__newobj_ex__) + ID(__next__) + ID(__or__) + ID(__package__) + ID(__path__) + ID(__pos__) + ID(__pow__) + ID(__prepare__) + ID(__qualname__) + ID(__radd__) + ID(__rand__) + ID(__rdivmod__) + ID(__reduce__) + ID(__repr__) + ID(__reversed__) + ID(__rfloordiv__) + ID(__rlshift__) + ID(__rmatmul__) + ID(__rmod__) + ID(__rmul__) + ID(__ror__) + ID(__round__) + ID(__rpow__) + ID(__rrshift__) + ID(__rshift__) + ID(__rsub__) + ID(__rtruediv__) + ID(__rxor__) + ID(__set__) + ID(__set_name__) + ID(__setattr__) + ID(__setitem__) + ID(__setstate__) + ID(__sizeof__) + ID(__slotnames__) + ID(__slots__) + ID(__spec__) + ID(__str__) + ID(__sub__) + ID(__subclasscheck__) + ID(__subclasshook__) + ID(__truediv__) + ID(__trunc__) + ID(__warningregistry__) + ID(__xor__) + ID(_abc_impl) + ID(_blksize) + ID(_bootstrap) + ID(_dealloc_warn) + ID(_finalizing) + ID(_find_and_load) + ID(_fix_up_module) + ID(_get_sourcefile) + ID(_handle_fromlist) + ID(_initializing) + ID(_is_text_encoding) + ID(_lock_unlock_module) + ID(_showwarnmsg) + ID(_shutdown) + ID(_slotnames) + ID(_strptime_time) + ID(_warn_unawaited_coroutine) + ID(_xoptions) + ID(big) + ID(buffer) + ID(builtins) + ID(c_call) + ID(c_exception) + ID(c_return) + ID(call) + ID(clear) + ID(close) + ID(closed) + ID(code) + ID(copy) + ID(copyreg) + ID(decode) + ID(defaultaction) + ID(difference_update) + ID(displayhook) + ID(enable) + ID(encode) + ID(encoding) + ID(errors) + ID(excepthook) + ID(exception) + ID(extend) + ID(filename) + ID(fileno) + ID(fillvalue) + ID(filters) + ID(flush) + ID(get) + ID(get_source) + ID(getattr) + ID(getpreferredencoding) + ID(getstate) + ID(imp) + ID(importlib) + ID(inf) + ID(intersection_update) + ID(isatty) + ID(items) + ID(iter) + ID(keys) + ID(last_traceback) + ID(last_type) + ID(last_value) + ID(line) + ID(lineno) + ID(little) + ID(locale) + ID(match) + ID(metaclass) + ID(mode) + ID(mro) + ID(msg) + ID(n_fields) + ID(n_sequence_fields) + ID(n_unnamed_fields) + ID(name) + ID(newlines) + ID(offset) + ID(onceregistry) + ID(opcode) + ID(open) + ID(parent) + ID(partial) + ID(path) + ID(peek) + ID(print_file_and_line) + ID(ps1) + ID(ps2) + ID(raw) + ID(read) + ID(read1) + ID(readable) + ID(readall) + ID(readinto) + ID(readinto1) + ID(readline) + ID(reload) + ID(replace) + ID(reset) + ID(return) + ID(reversed) + ID(seek) + ID(seekable) + ID(send) + ID(setstate) + ID(sort) + ID(st_mode) + ID(stderr) + ID(stdin) + ID(stdout) + ID(strict) + ID(struct_rusage) + ID(symmetric_difference_update) + ID(tell) + ID(text) + ID(threading) + ID(throw) + ID(truncate) + ID(unraisablehook) + ID(update) + ID(values) + ID(version) + ID(warnings) + ID(warnoptions) + ID(writable) + ID(write) + ID(zipimporter) + } identifiers; +}; + +#undef ID +#undef STR + + +#define _PyInterpreterState_GET_IDENTIFIER(interp, NAME) \ + (&interp->strings.identifiers.$ ## NAME._ascii.ob_base) + + +#ifdef __cplusplus +} +#endif +#endif /* !Py_INTERNAL_GLOBAL_STRINGS_H */ diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index 77e42b65f5d3cdd..4f2692b29f3b385 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -19,6 +19,7 @@ extern "C" { #include "pycore_genobject.h" // struct _Py_async_gen_state #include "pycore_gil.h" // struct _gil_runtime_state #include "pycore_gc.h" // struct _gc_runtime_state +#include "pycore_global_strings.h" // struct _Py_global_strings #include "pycore_list.h" // struct _Py_list_state #include "pycore_tuple.h" // struct _Py_tuple_state #include "pycore_typeobject.h" // struct type_cache @@ -177,6 +178,8 @@ struct _is { struct ast_state ast; struct type_cache type_cache; + struct _Py_global_strings strings; + /* The following fields are here to avoid allocation during init. The data is exposed through PyInterpreterState pointer fields. These fields should not be accessed directly outside of init. diff --git a/Tools/c-analyzer/TODO b/Tools/c-analyzer/TODO index 4b9b2857e1d1e77..55338ebc855d096 100644 --- a/Tools/c-analyzer/TODO +++ b/Tools/c-analyzer/TODO @@ -156,8 +156,6 @@ Objects/codeobject.c:PyCode_NewEmpty():emptystring static PyObject Objects/exceptions.c:_check_for_legacy_statements():exec_prefix static PyObject *exec_prefix Objects/exceptions.c:_check_for_legacy_statements():print_prefix static PyObject *print_prefix Objects/funcobject.c:PyFunction_NewWithQualName():__name__ static PyObject *__name__ -Objects/typeobject.c:object___reduce_ex___impl():objreduce static PyObject *objreduce -Objects/typeobject.c:resolve_slotdups():pname static PyObject *pname Objects/unicodeobject.c:unicode_empty static PyObject *unicode_empty Objects/unicodeobject.c:unicode_latin1 static PyObject *unicode_latin1[256] Python/_warnings.c:is_internal_frame():bootstrap_string static PyObject *bootstrap_string From a5513fced951da08d8e7ebc7e428b049f903aaf1 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 19 Jan 2022 14:27:58 -0700 Subject: [PATCH 003/115] Move the strings to _PyRuntimeState. --- Include/internal/pycore_global_objects.h | 4 ++++ Include/internal/pycore_global_strings.h | 4 ++-- Include/internal/pycore_interp.h | 3 --- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Include/internal/pycore_global_objects.h b/Include/internal/pycore_global_objects.h index acf0b2aed5ae4c3..2135fa3b5d79add 100644 --- a/Include/internal/pycore_global_objects.h +++ b/Include/internal/pycore_global_objects.h @@ -8,6 +8,8 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif +#include "pycore_global_strings.h" // struct _Py_global_strings + // These would be in pycore_long.h if it weren't for an include cycle. #define _PY_NSMALLPOSINTS 257 @@ -36,6 +38,8 @@ struct _Py_global_objects { PyBytesObject ob; char eos; } bytes_characters[256]; + + struct _Py_global_strings strings; } singletons; }; diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index ce0ef12a76558ca..ec87de6f21525bb 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -297,8 +297,8 @@ struct _Py_global_strings { #undef STR -#define _PyInterpreterState_GET_IDENTIFIER(interp, NAME) \ - (&interp->strings.identifiers.$ ## NAME._ascii.ob_base) +#define _Py_GET_GLOBAL_IDENTIFIER(NAME) \ + (&_Py_SINGLETON(strings.identifiers.$ ## NAME._ascii.ob_base)) #ifdef __cplusplus diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index 4f2692b29f3b385..77e42b65f5d3cdd 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -19,7 +19,6 @@ extern "C" { #include "pycore_genobject.h" // struct _Py_async_gen_state #include "pycore_gil.h" // struct _gil_runtime_state #include "pycore_gc.h" // struct _gc_runtime_state -#include "pycore_global_strings.h" // struct _Py_global_strings #include "pycore_list.h" // struct _Py_list_state #include "pycore_tuple.h" // struct _Py_tuple_state #include "pycore_typeobject.h" // struct type_cache @@ -178,8 +177,6 @@ struct _is { struct ast_state ast; struct type_cache type_cache; - struct _Py_global_strings strings; - /* The following fields are here to avoid allocation during init. The data is exposed through PyInterpreterState pointer fields. These fields should not be accessed directly outside of init. From dd084ee9b38c29390800a37efa40db0e7bc1ae5e Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 2 Dec 2021 11:41:26 -0700 Subject: [PATCH 004/115] Initialize the global singleton strings (identifiers-only for now). --- Include/internal/pycore_runtime_init.h | 296 ++++++++++++++++++++++++- 1 file changed, 295 insertions(+), 1 deletion(-) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 3b7f2629033bf69..b037a3c7ed10b3f 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -82,7 +82,6 @@ extern "C" { .ob_digit = { ((val) >= 0 ? (val) : -(val)) }, \ } - #define _PyBytes_SIMPLE_INIT(CH, LEN) \ { \ _PyVarObject_IMMORTAL_INIT(&PyBytes_Type, LEN), \ @@ -94,6 +93,29 @@ extern "C" { _PyBytes_SIMPLE_INIT(CH, 1) \ } +#define _PyASCIIObject_INIT(LITERAL) \ + { \ + ._ascii = { \ + .ob_base = { \ + .ob_refcnt = 999999999, \ + .ob_type = &PyUnicode_Type, \ + }, \ + .length = _Py_STRING_LENGTH(LITERAL) - 1, \ + .hash = -1, \ + .state = { \ + .kind = 1, \ + .compact = 1, \ + .ascii = 1, \ + .ready = 1, \ + }, \ + }, \ + ._data = LITERAL, \ + } +#define INIT_STR(NAME, LITERAL) \ + .$ ## NAME = _PyASCIIObject_INIT(LITERAL) +#define INIT_ID(NAME) \ + INIT_STR(NAME, #NAME) + /* The following is auto-generated by Tools/scripts/generate_global_objects.py. */ #define _Py_global_objects_INIT { \ @@ -622,6 +644,278 @@ extern "C" { _PyBytes_CHAR_INIT(254), \ _PyBytes_CHAR_INIT(255), \ }, \ + \ + .strings = { \ + .identifiers = { \ + INIT_ID(Py_Repr), \ + INIT_ID(TextIOWrapper), \ + INIT_ID(WarningMessage), \ + INIT_ID(_), \ + INIT_ID(__IOBase_closed), \ + INIT_ID(__abs__), \ + INIT_ID(__abstractmethods__), \ + INIT_ID(__add__), \ + INIT_ID(__aenter__), \ + INIT_ID(__aexit__), \ + INIT_ID(__aiter__), \ + INIT_ID(__all__), \ + INIT_ID(__and__), \ + INIT_ID(__anext__), \ + INIT_ID(__annotations__), \ + INIT_ID(__await__), \ + INIT_ID(__bases__), \ + INIT_ID(__bool__), \ + INIT_ID(__build_class__), \ + INIT_ID(__builtins__), \ + INIT_ID(__bytes__), \ + INIT_ID(__call__), \ + INIT_ID(__class__), \ + INIT_ID(__class_getitem__), \ + INIT_ID(__classcell__), \ + INIT_ID(__complex__), \ + INIT_ID(__contains__), \ + INIT_ID(__copy__), \ + INIT_ID(__del__), \ + INIT_ID(__delattr__), \ + INIT_ID(__delete__), \ + INIT_ID(__delitem__), \ + INIT_ID(__dict__), \ + INIT_ID(__dir__), \ + INIT_ID(__divmod__), \ + INIT_ID(__doc__), \ + INIT_ID(__enter__), \ + INIT_ID(__eq__), \ + INIT_ID(__exit__), \ + INIT_ID(__file__), \ + INIT_ID(__float__), \ + INIT_ID(__floordiv__), \ + INIT_ID(__format__), \ + INIT_ID(__fspath__), \ + INIT_ID(__ge__), \ + INIT_ID(__get__), \ + INIT_ID(__getattr__), \ + INIT_ID(__getattribute__), \ + INIT_ID(__getitem__), \ + INIT_ID(__getnewargs__), \ + INIT_ID(__getnewargs_ex__), \ + INIT_ID(__getstate__), \ + INIT_ID(__gt__), \ + INIT_ID(__hash__), \ + INIT_ID(__iadd__), \ + INIT_ID(__iand__), \ + INIT_ID(__ifloordiv__), \ + INIT_ID(__ilshift__), \ + INIT_ID(__imatmul__), \ + INIT_ID(__imod__), \ + INIT_ID(__import__), \ + INIT_ID(__imul__), \ + INIT_ID(__index__), \ + INIT_ID(__init__), \ + INIT_ID(__init_subclass__), \ + INIT_ID(__instancecheck__), \ + INIT_ID(__int__), \ + INIT_ID(__invert__), \ + INIT_ID(__ior__), \ + INIT_ID(__ipow__), \ + INIT_ID(__irshift__), \ + INIT_ID(__isabstractmethod__), \ + INIT_ID(__isub__), \ + INIT_ID(__iter__), \ + INIT_ID(__itruediv__), \ + INIT_ID(__ixor__), \ + INIT_ID(__le__), \ + INIT_ID(__len__), \ + INIT_ID(__length_hint__), \ + INIT_ID(__loader__), \ + INIT_ID(__lshift__), \ + INIT_ID(__lt__), \ + INIT_ID(__ltrace__), \ + INIT_ID(__main__), \ + INIT_ID(__matmul__), \ + INIT_ID(__missing__), \ + INIT_ID(__mod__), \ + INIT_ID(__module__), \ + INIT_ID(__mro_entries__), \ + INIT_ID(__mul__), \ + INIT_ID(__name__), \ + INIT_ID(__ne__), \ + INIT_ID(__neg__), \ + INIT_ID(__new__), \ + INIT_ID(__newobj__), \ + INIT_ID(__newobj_ex__), \ + INIT_ID(__next__), \ + INIT_ID(__or__), \ + INIT_ID(__package__), \ + INIT_ID(__path__), \ + INIT_ID(__pos__), \ + INIT_ID(__pow__), \ + INIT_ID(__prepare__), \ + INIT_ID(__qualname__), \ + INIT_ID(__radd__), \ + INIT_ID(__rand__), \ + INIT_ID(__rdivmod__), \ + INIT_ID(__reduce__), \ + INIT_ID(__repr__), \ + INIT_ID(__reversed__), \ + INIT_ID(__rfloordiv__), \ + INIT_ID(__rlshift__), \ + INIT_ID(__rmatmul__), \ + INIT_ID(__rmod__), \ + INIT_ID(__rmul__), \ + INIT_ID(__ror__), \ + INIT_ID(__round__), \ + INIT_ID(__rpow__), \ + INIT_ID(__rrshift__), \ + INIT_ID(__rshift__), \ + INIT_ID(__rsub__), \ + INIT_ID(__rtruediv__), \ + INIT_ID(__rxor__), \ + INIT_ID(__set__), \ + INIT_ID(__set_name__), \ + INIT_ID(__setattr__), \ + INIT_ID(__setitem__), \ + INIT_ID(__setstate__), \ + INIT_ID(__sizeof__), \ + INIT_ID(__slotnames__), \ + INIT_ID(__slots__), \ + INIT_ID(__spec__), \ + INIT_ID(__str__), \ + INIT_ID(__sub__), \ + INIT_ID(__subclasscheck__), \ + INIT_ID(__subclasshook__), \ + INIT_ID(__truediv__), \ + INIT_ID(__trunc__), \ + INIT_ID(__warningregistry__), \ + INIT_ID(__xor__), \ + INIT_ID(_abc_impl), \ + INIT_ID(_blksize), \ + INIT_ID(_bootstrap), \ + INIT_ID(_dealloc_warn), \ + INIT_ID(_finalizing), \ + INIT_ID(_find_and_load), \ + INIT_ID(_fix_up_module), \ + INIT_ID(_get_sourcefile), \ + INIT_ID(_handle_fromlist), \ + INIT_ID(_initializing), \ + INIT_ID(_is_text_encoding), \ + INIT_ID(_lock_unlock_module), \ + INIT_ID(_showwarnmsg), \ + INIT_ID(_shutdown), \ + INIT_ID(_slotnames), \ + INIT_ID(_strptime_time), \ + INIT_ID(_warn_unawaited_coroutine), \ + INIT_ID(_xoptions), \ + 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(defaultaction), \ + INIT_ID(difference_update), \ + INIT_ID(displayhook), \ + INIT_ID(enable), \ + INIT_ID(encode), \ + INIT_ID(encoding), \ + INIT_ID(errors), \ + INIT_ID(excepthook), \ + INIT_ID(exception), \ + INIT_ID(extend), \ + INIT_ID(filename), \ + INIT_ID(fileno), \ + INIT_ID(fillvalue), \ + INIT_ID(filters), \ + INIT_ID(flush), \ + INIT_ID(get), \ + INIT_ID(get_source), \ + INIT_ID(getattr), \ + INIT_ID(getpreferredencoding), \ + INIT_ID(getstate), \ + INIT_ID(imp), \ + INIT_ID(importlib), \ + INIT_ID(inf), \ + INIT_ID(intersection_update), \ + INIT_ID(isatty), \ + INIT_ID(items), \ + INIT_ID(iter), \ + INIT_ID(keys), \ + INIT_ID(last_traceback), \ + INIT_ID(last_type), \ + INIT_ID(last_value), \ + INIT_ID(line), \ + INIT_ID(lineno), \ + INIT_ID(little), \ + INIT_ID(locale), \ + INIT_ID(match), \ + INIT_ID(metaclass), \ + INIT_ID(mode), \ + INIT_ID(mro), \ + INIT_ID(msg), \ + INIT_ID(n_fields), \ + INIT_ID(n_sequence_fields), \ + INIT_ID(n_unnamed_fields), \ + INIT_ID(name), \ + INIT_ID(newlines), \ + INIT_ID(offset), \ + INIT_ID(onceregistry), \ + INIT_ID(opcode), \ + INIT_ID(open), \ + INIT_ID(parent), \ + INIT_ID(partial), \ + INIT_ID(path), \ + INIT_ID(peek), \ + INIT_ID(print_file_and_line), \ + INIT_ID(ps1), \ + INIT_ID(ps2), \ + INIT_ID(raw), \ + INIT_ID(read), \ + INIT_ID(read1), \ + INIT_ID(readable), \ + INIT_ID(readall), \ + INIT_ID(readinto), \ + INIT_ID(readinto1), \ + INIT_ID(readline), \ + INIT_ID(reload), \ + INIT_ID(replace), \ + INIT_ID(reset), \ + INIT_ID(return), \ + INIT_ID(reversed), \ + INIT_ID(seek), \ + INIT_ID(seekable), \ + INIT_ID(send), \ + INIT_ID(setstate), \ + INIT_ID(sort), \ + INIT_ID(st_mode), \ + INIT_ID(stderr), \ + INIT_ID(stdin), \ + INIT_ID(stdout), \ + INIT_ID(strict), \ + INIT_ID(struct_rusage), \ + INIT_ID(symmetric_difference_update), \ + INIT_ID(tell), \ + INIT_ID(text), \ + INIT_ID(threading), \ + INIT_ID(throw), \ + INIT_ID(truncate), \ + INIT_ID(unraisablehook), \ + INIT_ID(update), \ + INIT_ID(values), \ + INIT_ID(version), \ + INIT_ID(warnings), \ + INIT_ID(warnoptions), \ + INIT_ID(writable), \ + INIT_ID(write), \ + INIT_ID(zipimporter), \ + }, \ + }, \ }, \ } /* End auto-generated code */ From 472b0a62a6925594d5eae16035f3b7eae63a1a65 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 2 Dec 2021 10:08:17 -0700 Subject: [PATCH 005/115] Add the global (non-identifier) string literals. --- Include/internal/pycore_global_strings.h | 284 +++++++++++++++++++++++ Include/internal/pycore_runtime_init.h | 279 ++++++++++++++++++++++ 2 files changed, 563 insertions(+) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index ec87de6f21525bb..216f7c80a0817bb 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -22,6 +22,287 @@ extern "C" { STR(NAME, #NAME) struct _Py_global_strings { + struct { + STR(empty, "") + STR(newline, "\n") // nl + STR(dot, ".") + + STR(comma_sep, ", ") // comma_id + + STR(br_open, "{") + STR(br_close, "}") + STR(br_dbl_open, "{{") + STR(br_dbl_close, "}}") + + STR(anon_dictcomp, "") + STR(anon_genexpr, "") + STR(anon_lambda, "") + STR(anon_listcomp, "") + STR(anon_setcomp, "") + STR(anon_string, "") + STR(dot_locals, ".") + + STR(replace_inf, "1eNN") + //STR(replace_inf, ['1', 'e', 1 + DBL_MAX_10_EXP]) + + STR(latin1_0, "\x00") + STR(latin1_1, "\x01") + STR(latin1_2, "\x02") + STR(latin1_3, "\x03") + STR(latin1_4, "\x04") + STR(latin1_5, "\x05") + STR(latin1_6, "\x06") + STR(latin1_7, "\x07") + STR(latin1_8, "\x08") + STR(latin1_9, "\x09") + STR(latin1_10, "\x0A") + STR(latin1_11, "\x0B") + STR(latin1_12, "\x0C") + STR(latin1_13, "\x0D") + STR(latin1_14, "\x0E") + STR(latin1_15, "\x0F") + STR(latin1_16, "\x10") + STR(latin1_17, "\x11") + STR(latin1_18, "\x12") + STR(latin1_19, "\x13") + STR(latin1_20, "\x14") + STR(latin1_21, "\x15") + STR(latin1_22, "\x16") + STR(latin1_23, "\x17") + STR(latin1_24, "\x18") + STR(latin1_25, "\x19") + STR(latin1_26, "\x1A") + STR(latin1_27, "\x1B") + STR(latin1_28, "\x1C") + STR(latin1_29, "\x1D") + STR(latin1_30, "\x1E") + STR(latin1_31, "\x1F") + STR(latin1_32, "\x20") + STR(latin1_33, "\x21") + STR(latin1_34, "\x22") + STR(latin1_35, "\x23") + STR(latin1_36, "\x24") + STR(latin1_37, "\x25") + STR(latin1_38, "\x26") + STR(latin1_39, "\x27") + STR(latin1_40, "\x28") + STR(latin1_41, "\x29") + STR(latin1_42, "\x2A") + STR(latin1_43, "\x2B") + STR(latin1_44, "\x2C") + STR(latin1_45, "\x2D") + STR(latin1_46, "\x2E") + STR(latin1_47, "\x2F") + STR(latin1_48, "\x30") + STR(latin1_49, "\x31") + STR(latin1_50, "\x32") + STR(latin1_51, "\x33") + STR(latin1_52, "\x34") + STR(latin1_53, "\x35") + STR(latin1_54, "\x36") + STR(latin1_55, "\x37") + STR(latin1_56, "\x38") + STR(latin1_57, "\x39") + STR(latin1_58, "\x3A") + STR(latin1_59, "\x3B") + STR(latin1_60, "\x3C") + STR(latin1_61, "\x3D") + STR(latin1_62, "\x3E") + STR(latin1_63, "\x3F") + STR(latin1_64, "\x40") + STR(latin1_65, "\x41") + STR(latin1_66, "\x42") + STR(latin1_67, "\x43") + STR(latin1_68, "\x44") + STR(latin1_69, "\x45") + STR(latin1_70, "\x46") + STR(latin1_71, "\x47") + STR(latin1_72, "\x48") + STR(latin1_73, "\x49") + STR(latin1_74, "\x4A") + STR(latin1_75, "\x4B") + STR(latin1_76, "\x4C") + STR(latin1_77, "\x4D") + STR(latin1_78, "\x4E") + STR(latin1_79, "\x4F") + STR(latin1_80, "\x50") + STR(latin1_81, "\x51") + STR(latin1_82, "\x52") + STR(latin1_83, "\x53") + STR(latin1_84, "\x54") + STR(latin1_85, "\x55") + STR(latin1_86, "\x56") + STR(latin1_87, "\x57") + STR(latin1_88, "\x58") + STR(latin1_89, "\x59") + STR(latin1_90, "\x5A") + STR(latin1_91, "\x5B") + STR(latin1_92, "\x5C") + STR(latin1_93, "\x5D") + STR(latin1_94, "\x5E") + STR(latin1_95, "\x5F") + STR(latin1_96, "\x60") + STR(latin1_97, "\x61") + STR(latin1_98, "\x62") + STR(latin1_99, "\x63") + STR(latin1_100, "\x64") + STR(latin1_101, "\x65") + STR(latin1_102, "\x66") + STR(latin1_103, "\x67") + STR(latin1_104, "\x68") + STR(latin1_105, "\x69") + STR(latin1_106, "\x6A") + STR(latin1_107, "\x6B") + STR(latin1_108, "\x6C") + STR(latin1_109, "\x6D") + STR(latin1_110, "\x6E") + STR(latin1_111, "\x6F") + STR(latin1_112, "\x70") + STR(latin1_113, "\x71") + STR(latin1_114, "\x72") + STR(latin1_115, "\x73") + STR(latin1_116, "\x74") + STR(latin1_117, "\x75") + STR(latin1_118, "\x76") + STR(latin1_119, "\x77") + STR(latin1_120, "\x78") + STR(latin1_121, "\x79") + STR(latin1_122, "\x7A") + STR(latin1_123, "\x7B") + STR(latin1_124, "\x7C") + STR(latin1_125, "\x7D") + STR(latin1_126, "\x7E") + STR(latin1_127, "\x7F") + STR(latin1_128, "\x80") + STR(latin1_129, "\x81") + STR(latin1_130, "\x82") + STR(latin1_131, "\x83") + STR(latin1_132, "\x84") + STR(latin1_133, "\x85") + STR(latin1_134, "\x86") + STR(latin1_135, "\x87") + STR(latin1_136, "\x88") + STR(latin1_137, "\x89") + STR(latin1_138, "\x8A") + STR(latin1_139, "\x8B") + STR(latin1_140, "\x8C") + STR(latin1_141, "\x8D") + STR(latin1_142, "\x8E") + STR(latin1_143, "\x8F") + STR(latin1_144, "\x90") + STR(latin1_145, "\x91") + STR(latin1_146, "\x92") + STR(latin1_147, "\x93") + STR(latin1_148, "\x94") + STR(latin1_149, "\x95") + STR(latin1_150, "\x96") + STR(latin1_151, "\x97") + STR(latin1_152, "\x98") + STR(latin1_153, "\x99") + STR(latin1_154, "\x9A") + STR(latin1_155, "\x9B") + STR(latin1_156, "\x9C") + STR(latin1_157, "\x9D") + STR(latin1_158, "\x9E") + STR(latin1_159, "\x9F") + STR(latin1_160, "\xA0") + STR(latin1_161, "\xA1") + STR(latin1_162, "\xA2") + STR(latin1_163, "\xA3") + STR(latin1_164, "\xA4") + STR(latin1_165, "\xA5") + STR(latin1_166, "\xA6") + STR(latin1_167, "\xA7") + STR(latin1_168, "\xA8") + STR(latin1_169, "\xA9") + STR(latin1_170, "\xAA") + STR(latin1_171, "\xAB") + STR(latin1_172, "\xAC") + STR(latin1_173, "\xAD") + STR(latin1_174, "\xAE") + STR(latin1_175, "\xAF") + STR(latin1_176, "\xB0") + STR(latin1_177, "\xB1") + STR(latin1_178, "\xB2") + STR(latin1_179, "\xB3") + STR(latin1_180, "\xB4") + STR(latin1_181, "\xB5") + STR(latin1_182, "\xB6") + STR(latin1_183, "\xB7") + STR(latin1_184, "\xB8") + STR(latin1_185, "\xB9") + STR(latin1_186, "\xBA") + STR(latin1_187, "\xBB") + STR(latin1_188, "\xBC") + STR(latin1_189, "\xBD") + STR(latin1_190, "\xBE") + STR(latin1_191, "\xBF") + STR(latin1_192, "\xC0") + STR(latin1_193, "\xC1") + STR(latin1_194, "\xC2") + STR(latin1_195, "\xC3") + STR(latin1_196, "\xC4") + STR(latin1_197, "\xC5") + STR(latin1_198, "\xC6") + STR(latin1_199, "\xC7") + STR(latin1_200, "\xC8") + STR(latin1_201, "\xC9") + STR(latin1_202, "\xCA") + STR(latin1_203, "\xCB") + STR(latin1_204, "\xCC") + STR(latin1_205, "\xCD") + STR(latin1_206, "\xCE") + STR(latin1_207, "\xCF") + STR(latin1_208, "\xD0") + STR(latin1_209, "\xD1") + STR(latin1_210, "\xD2") + STR(latin1_211, "\xD3") + STR(latin1_212, "\xD4") + STR(latin1_213, "\xD5") + STR(latin1_214, "\xD6") + STR(latin1_215, "\xD7") + STR(latin1_216, "\xD8") + STR(latin1_217, "\xD9") + STR(latin1_218, "\xDA") + STR(latin1_219, "\xDB") + STR(latin1_220, "\xDC") + STR(latin1_221, "\xDD") + STR(latin1_222, "\xDE") + STR(latin1_223, "\xDF") + STR(latin1_224, "\xE0") + STR(latin1_225, "\xE1") + STR(latin1_226, "\xE2") + STR(latin1_227, "\xE3") + STR(latin1_228, "\xE4") + STR(latin1_229, "\xE5") + STR(latin1_230, "\xE6") + STR(latin1_231, "\xE7") + STR(latin1_232, "\xE8") + STR(latin1_233, "\xE9") + STR(latin1_234, "\xEA") + STR(latin1_235, "\xEB") + STR(latin1_236, "\xEC") + STR(latin1_237, "\xED") + STR(latin1_238, "\xEE") + STR(latin1_239, "\xEF") + STR(latin1_240, "\xF0") + STR(latin1_241, "\xF1") + STR(latin1_242, "\xF2") + STR(latin1_243, "\xF3") + STR(latin1_244, "\xF4") + STR(latin1_245, "\xF5") + STR(latin1_246, "\xF6") + STR(latin1_247, "\xF7") + STR(latin1_248, "\xF8") + STR(latin1_249, "\xF9") + STR(latin1_250, "\xFA") + STR(latin1_251, "\xFB") + STR(latin1_252, "\xFC") + STR(latin1_253, "\xFD") + STR(latin1_254, "\xFE") + STR(latin1_255, "\xFF") + } literals; + struct { ID(Py_Repr) ID(TextIOWrapper) @@ -300,6 +581,9 @@ struct _Py_global_strings { #define _Py_GET_GLOBAL_IDENTIFIER(NAME) \ (&_Py_SINGLETON(strings.identifiers.$ ## NAME._ascii.ob_base)) +#define _Py_GET_GLOBAL_STRING(NAME) \ + (&_Py_SINGLETON(strings.literals.$ ## NAME._ascii.ob_base)) + #ifdef __cplusplus } diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index b037a3c7ed10b3f..4714e4f07d9067f 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -646,6 +646,285 @@ extern "C" { }, \ \ .strings = { \ + .literals = { \ + INIT_STR(empty, ""), \ + INIT_STR(newline, "\n"), \ + INIT_STR(dot, "."), \ + \ + INIT_STR(comma_sep, ", "), \ + \ + INIT_STR(br_open, "{"), \ + INIT_STR(br_close, "}"), \ + INIT_STR(br_dbl_open, "{{"), \ + INIT_STR(br_dbl_close, "}}"), \ + \ + INIT_STR(anon_dictcomp, ""), \ + INIT_STR(anon_genexpr, ""), \ + INIT_STR(anon_lambda, ""), \ + INIT_STR(anon_listcomp, ""), \ + INIT_STR(anon_setcomp, ""), \ + INIT_STR(anon_string, ""), \ + INIT_STR(dot_locals, "."), \ + \ + INIT_STR(replace_inf, "1eNN"), \ + \ + INIT_STR(latin1_0, "\x00"), \ + INIT_STR(latin1_1, "\x01"), \ + INIT_STR(latin1_2, "\x02"), \ + INIT_STR(latin1_3, "\x03"), \ + INIT_STR(latin1_4, "\x04"), \ + INIT_STR(latin1_5, "\x05"), \ + INIT_STR(latin1_6, "\x06"), \ + INIT_STR(latin1_7, "\x07"), \ + INIT_STR(latin1_8, "\x08"), \ + INIT_STR(latin1_9, "\x09"), \ + INIT_STR(latin1_10, "\x0A"), \ + INIT_STR(latin1_11, "\x0B"), \ + INIT_STR(latin1_12, "\x0C"), \ + INIT_STR(latin1_13, "\x0D"), \ + INIT_STR(latin1_14, "\x0E"), \ + INIT_STR(latin1_15, "\x0F"), \ + INIT_STR(latin1_16, "\x10"), \ + INIT_STR(latin1_17, "\x11"), \ + INIT_STR(latin1_18, "\x12"), \ + INIT_STR(latin1_19, "\x13"), \ + INIT_STR(latin1_20, "\x14"), \ + INIT_STR(latin1_21, "\x15"), \ + INIT_STR(latin1_22, "\x16"), \ + INIT_STR(latin1_23, "\x17"), \ + INIT_STR(latin1_24, "\x18"), \ + INIT_STR(latin1_25, "\x19"), \ + INIT_STR(latin1_26, "\x1A"), \ + INIT_STR(latin1_27, "\x1B"), \ + INIT_STR(latin1_28, "\x1C"), \ + INIT_STR(latin1_29, "\x1D"), \ + INIT_STR(latin1_30, "\x1E"), \ + INIT_STR(latin1_31, "\x1F"), \ + INIT_STR(latin1_32, "\x20"), \ + INIT_STR(latin1_33, "\x21"), \ + INIT_STR(latin1_34, "\x22"), \ + INIT_STR(latin1_35, "\x23"), \ + INIT_STR(latin1_36, "\x24"), \ + INIT_STR(latin1_37, "\x25"), \ + INIT_STR(latin1_38, "\x26"), \ + INIT_STR(latin1_39, "\x27"), \ + INIT_STR(latin1_40, "\x28"), \ + INIT_STR(latin1_41, "\x29"), \ + INIT_STR(latin1_42, "\x2A"), \ + INIT_STR(latin1_43, "\x2B"), \ + INIT_STR(latin1_44, "\x2C"), \ + INIT_STR(latin1_45, "\x2D"), \ + INIT_STR(latin1_46, "\x2E"), \ + INIT_STR(latin1_47, "\x2F"), \ + INIT_STR(latin1_48, "\x30"), \ + INIT_STR(latin1_49, "\x31"), \ + INIT_STR(latin1_50, "\x32"), \ + INIT_STR(latin1_51, "\x33"), \ + INIT_STR(latin1_52, "\x34"), \ + INIT_STR(latin1_53, "\x35"), \ + INIT_STR(latin1_54, "\x36"), \ + INIT_STR(latin1_55, "\x37"), \ + INIT_STR(latin1_56, "\x38"), \ + INIT_STR(latin1_57, "\x39"), \ + INIT_STR(latin1_58, "\x3A"), \ + INIT_STR(latin1_59, "\x3B"), \ + INIT_STR(latin1_60, "\x3C"), \ + INIT_STR(latin1_61, "\x3D"), \ + INIT_STR(latin1_62, "\x3E"), \ + INIT_STR(latin1_63, "\x3F"), \ + INIT_STR(latin1_64, "\x40"), \ + INIT_STR(latin1_65, "\x41"), \ + INIT_STR(latin1_66, "\x42"), \ + INIT_STR(latin1_67, "\x43"), \ + INIT_STR(latin1_68, "\x44"), \ + INIT_STR(latin1_69, "\x45"), \ + INIT_STR(latin1_70, "\x46"), \ + INIT_STR(latin1_71, "\x47"), \ + INIT_STR(latin1_72, "\x48"), \ + INIT_STR(latin1_73, "\x49"), \ + INIT_STR(latin1_74, "\x4A"), \ + INIT_STR(latin1_75, "\x4B"), \ + INIT_STR(latin1_76, "\x4C"), \ + INIT_STR(latin1_77, "\x4D"), \ + INIT_STR(latin1_78, "\x4E"), \ + INIT_STR(latin1_79, "\x4F"), \ + INIT_STR(latin1_80, "\x50"), \ + INIT_STR(latin1_81, "\x51"), \ + INIT_STR(latin1_82, "\x52"), \ + INIT_STR(latin1_83, "\x53"), \ + INIT_STR(latin1_84, "\x54"), \ + INIT_STR(latin1_85, "\x55"), \ + INIT_STR(latin1_86, "\x56"), \ + INIT_STR(latin1_87, "\x57"), \ + INIT_STR(latin1_88, "\x58"), \ + INIT_STR(latin1_89, "\x59"), \ + INIT_STR(latin1_90, "\x5A"), \ + INIT_STR(latin1_91, "\x5B"), \ + INIT_STR(latin1_92, "\x5C"), \ + INIT_STR(latin1_93, "\x5D"), \ + INIT_STR(latin1_94, "\x5E"), \ + INIT_STR(latin1_95, "\x5F"), \ + INIT_STR(latin1_96, "\x60"), \ + INIT_STR(latin1_97, "\x61"), \ + INIT_STR(latin1_98, "\x62"), \ + INIT_STR(latin1_99, "\x63"), \ + INIT_STR(latin1_100, "\x64"), \ + INIT_STR(latin1_101, "\x65"), \ + INIT_STR(latin1_102, "\x66"), \ + INIT_STR(latin1_103, "\x67"), \ + INIT_STR(latin1_104, "\x68"), \ + INIT_STR(latin1_105, "\x69"), \ + INIT_STR(latin1_106, "\x6A"), \ + INIT_STR(latin1_107, "\x6B"), \ + INIT_STR(latin1_108, "\x6C"), \ + INIT_STR(latin1_109, "\x6D"), \ + INIT_STR(latin1_110, "\x6E"), \ + INIT_STR(latin1_111, "\x6F"), \ + INIT_STR(latin1_112, "\x70"), \ + INIT_STR(latin1_113, "\x71"), \ + INIT_STR(latin1_114, "\x72"), \ + INIT_STR(latin1_115, "\x73"), \ + INIT_STR(latin1_116, "\x74"), \ + INIT_STR(latin1_117, "\x75"), \ + INIT_STR(latin1_118, "\x76"), \ + INIT_STR(latin1_119, "\x77"), \ + INIT_STR(latin1_120, "\x78"), \ + INIT_STR(latin1_121, "\x79"), \ + INIT_STR(latin1_122, "\x7A"), \ + INIT_STR(latin1_123, "\x7B"), \ + INIT_STR(latin1_124, "\x7C"), \ + INIT_STR(latin1_125, "\x7D"), \ + INIT_STR(latin1_126, "\x7E"), \ + INIT_STR(latin1_127, "\x7F"), \ + INIT_STR(latin1_128, "\x80"), \ + INIT_STR(latin1_129, "\x81"), \ + INIT_STR(latin1_130, "\x82"), \ + INIT_STR(latin1_131, "\x83"), \ + INIT_STR(latin1_132, "\x84"), \ + INIT_STR(latin1_133, "\x85"), \ + INIT_STR(latin1_134, "\x86"), \ + INIT_STR(latin1_135, "\x87"), \ + INIT_STR(latin1_136, "\x88"), \ + INIT_STR(latin1_137, "\x89"), \ + INIT_STR(latin1_138, "\x8A"), \ + INIT_STR(latin1_139, "\x8B"), \ + INIT_STR(latin1_140, "\x8C"), \ + INIT_STR(latin1_141, "\x8D"), \ + INIT_STR(latin1_142, "\x8E"), \ + INIT_STR(latin1_143, "\x8F"), \ + INIT_STR(latin1_144, "\x90"), \ + INIT_STR(latin1_145, "\x91"), \ + INIT_STR(latin1_146, "\x92"), \ + INIT_STR(latin1_147, "\x93"), \ + INIT_STR(latin1_148, "\x94"), \ + INIT_STR(latin1_149, "\x95"), \ + INIT_STR(latin1_150, "\x96"), \ + INIT_STR(latin1_151, "\x97"), \ + INIT_STR(latin1_152, "\x98"), \ + INIT_STR(latin1_153, "\x99"), \ + INIT_STR(latin1_154, "\x9A"), \ + INIT_STR(latin1_155, "\x9B"), \ + INIT_STR(latin1_156, "\x9C"), \ + INIT_STR(latin1_157, "\x9D"), \ + INIT_STR(latin1_158, "\x9E"), \ + INIT_STR(latin1_159, "\x9F"), \ + INIT_STR(latin1_160, "\xA0"), \ + INIT_STR(latin1_161, "\xA1"), \ + INIT_STR(latin1_162, "\xA2"), \ + INIT_STR(latin1_163, "\xA3"), \ + INIT_STR(latin1_164, "\xA4"), \ + INIT_STR(latin1_165, "\xA5"), \ + INIT_STR(latin1_166, "\xA6"), \ + INIT_STR(latin1_167, "\xA7"), \ + INIT_STR(latin1_168, "\xA8"), \ + INIT_STR(latin1_169, "\xA9"), \ + INIT_STR(latin1_170, "\xAA"), \ + INIT_STR(latin1_171, "\xAB"), \ + INIT_STR(latin1_172, "\xAC"), \ + INIT_STR(latin1_173, "\xAD"), \ + INIT_STR(latin1_174, "\xAE"), \ + INIT_STR(latin1_175, "\xAF"), \ + INIT_STR(latin1_176, "\xB0"), \ + INIT_STR(latin1_177, "\xB1"), \ + INIT_STR(latin1_178, "\xB2"), \ + INIT_STR(latin1_179, "\xB3"), \ + INIT_STR(latin1_180, "\xB4"), \ + INIT_STR(latin1_181, "\xB5"), \ + INIT_STR(latin1_182, "\xB6"), \ + INIT_STR(latin1_183, "\xB7"), \ + INIT_STR(latin1_184, "\xB8"), \ + INIT_STR(latin1_185, "\xB9"), \ + INIT_STR(latin1_186, "\xBA"), \ + INIT_STR(latin1_187, "\xBB"), \ + INIT_STR(latin1_188, "\xBC"), \ + INIT_STR(latin1_189, "\xBD"), \ + INIT_STR(latin1_190, "\xBE"), \ + INIT_STR(latin1_191, "\xBF"), \ + INIT_STR(latin1_192, "\xC0"), \ + INIT_STR(latin1_193, "\xC1"), \ + INIT_STR(latin1_194, "\xC2"), \ + INIT_STR(latin1_195, "\xC3"), \ + INIT_STR(latin1_196, "\xC4"), \ + INIT_STR(latin1_197, "\xC5"), \ + INIT_STR(latin1_198, "\xC6"), \ + INIT_STR(latin1_199, "\xC7"), \ + INIT_STR(latin1_200, "\xC8"), \ + INIT_STR(latin1_201, "\xC9"), \ + INIT_STR(latin1_202, "\xCA"), \ + INIT_STR(latin1_203, "\xCB"), \ + INIT_STR(latin1_204, "\xCC"), \ + INIT_STR(latin1_205, "\xCD"), \ + INIT_STR(latin1_206, "\xCE"), \ + INIT_STR(latin1_207, "\xCF"), \ + INIT_STR(latin1_208, "\xD0"), \ + INIT_STR(latin1_209, "\xD1"), \ + INIT_STR(latin1_210, "\xD2"), \ + INIT_STR(latin1_211, "\xD3"), \ + INIT_STR(latin1_212, "\xD4"), \ + INIT_STR(latin1_213, "\xD5"), \ + INIT_STR(latin1_214, "\xD6"), \ + INIT_STR(latin1_215, "\xD7"), \ + INIT_STR(latin1_216, "\xD8"), \ + INIT_STR(latin1_217, "\xD9"), \ + INIT_STR(latin1_218, "\xDA"), \ + INIT_STR(latin1_219, "\xDB"), \ + INIT_STR(latin1_220, "\xDC"), \ + INIT_STR(latin1_221, "\xDD"), \ + INIT_STR(latin1_222, "\xDE"), \ + INIT_STR(latin1_223, "\xDF"), \ + INIT_STR(latin1_224, "\xE0"), \ + INIT_STR(latin1_225, "\xE1"), \ + INIT_STR(latin1_226, "\xE2"), \ + INIT_STR(latin1_227, "\xE3"), \ + INIT_STR(latin1_228, "\xE4"), \ + INIT_STR(latin1_229, "\xE5"), \ + INIT_STR(latin1_230, "\xE6"), \ + INIT_STR(latin1_231, "\xE7"), \ + INIT_STR(latin1_232, "\xE8"), \ + INIT_STR(latin1_233, "\xE9"), \ + INIT_STR(latin1_234, "\xEA"), \ + INIT_STR(latin1_235, "\xEB"), \ + INIT_STR(latin1_236, "\xEC"), \ + INIT_STR(latin1_237, "\xED"), \ + INIT_STR(latin1_238, "\xEE"), \ + INIT_STR(latin1_239, "\xEF"), \ + INIT_STR(latin1_240, "\xF0"), \ + INIT_STR(latin1_241, "\xF1"), \ + INIT_STR(latin1_242, "\xF2"), \ + INIT_STR(latin1_243, "\xF3"), \ + INIT_STR(latin1_244, "\xF4"), \ + INIT_STR(latin1_245, "\xF5"), \ + INIT_STR(latin1_246, "\xF6"), \ + INIT_STR(latin1_247, "\xF7"), \ + INIT_STR(latin1_248, "\xF8"), \ + INIT_STR(latin1_249, "\xF9"), \ + INIT_STR(latin1_250, "\xFA"), \ + INIT_STR(latin1_251, "\xFB"), \ + INIT_STR(latin1_252, "\xFC"), \ + INIT_STR(latin1_253, "\xFD"), \ + INIT_STR(latin1_254, "\xFE"), \ + INIT_STR(latin1_255, "\xFF"), \ + }, \ .identifiers = { \ INIT_ID(Py_Repr), \ INIT_ID(TextIOWrapper), \ From 8a3096bf233d3be742335e886dd27455390fe18e Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 2 Dec 2021 11:42:04 -0700 Subject: [PATCH 006/115] Add _PyObject_CallMethod(). --- Include/internal/pycore_call.h | 3 +++ Objects/call.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Include/internal/pycore_call.h b/Include/internal/pycore_call.h index f2cfd2fd53ed9c4..ae657c86d9e05c2 100644 --- a/Include/internal/pycore_call.h +++ b/Include/internal/pycore_call.h @@ -30,6 +30,9 @@ PyAPI_FUNC(PyObject *) _PyObject_Call( PyObject *args, PyObject *kwargs); +extern PyObject * _PyObject_CallMethod( + PyThreadState *tstate, PyObject *callable, const char *format, ...); + // Static inline variant of public PyVectorcall_Function(). static inline vectorcallfunc diff --git a/Objects/call.c b/Objects/call.c index 310a2d732d17050..304acf7060c9c04 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -607,7 +607,6 @@ callmethod(PyThreadState *tstate, PyObject* callable, const char *format, va_lis return _PyObject_CallFunctionVa(tstate, callable, format, va, is_size_t); } - PyObject * PyObject_CallMethod(PyObject *obj, const char *name, const char *format, ...) { @@ -682,6 +681,17 @@ _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name, } +PyObject * _PyObject_CallMethod(PyThreadState *tstate, PyObject *callable, + const char *format, ...) +{ + va_list va; + va_start(va, format); + PyObject *retval = callmethod(tstate, callable, format, va, 0); + va_end(va); + return retval; +} + + PyObject * _PyObject_CallMethod_SizeT(PyObject *obj, const char *name, const char *format, ...) From 38300b315e0fec435b63453f7c99eb2f6c564707 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 2 Dec 2021 11:42:41 -0700 Subject: [PATCH 007/115] Get rid of _Py_IDENTIFIER() in tokenizer.c. --- Parser/tokenizer.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index cd4254f8b9077e5..2b5fc9edf46c069 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -443,8 +443,6 @@ static int fp_setreadl(struct tok_state *tok, const char* enc) { PyObject *readline, *io, *stream; - _Py_IDENTIFIER(open); - _Py_IDENTIFIER(readline); int fd; long pos; @@ -461,26 +459,38 @@ fp_setreadl(struct tok_state *tok, const char* enc) return 0; } + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *str_open = _Py_GET_GLOBAL_IDENTIFIER(open); + PyObject *str_readline = _Py_GET_GLOBAL_IDENTIFIER(readline); + io = PyImport_ImportModule("io"); - if (io == NULL) + if (io == NULL) { return 0; - - stream = _PyObject_CallMethodId(io, &PyId_open, "isisOOO", - fd, "r", -1, enc, Py_None, Py_None, Py_False); + } + PyObject *open = PyObject_GetAttr(io, str_open); Py_DECREF(io); - if (stream == NULL) + if (open == NULL) { + return 0; + } + stream = _PyObject_CallMethod(tstate, open, "isisOOO", + fd, "r", -1, enc, Py_None, Py_None, Py_False); + Py_DECREF(open); + if (stream == NULL) { return 0; + } - readline = _PyObject_GetAttrId(stream, &PyId_readline); + readline = PyObject_GetAttr(stream, str_readline); Py_DECREF(stream); - if (readline == NULL) + if (readline == NULL) { return 0; + } Py_XSETREF(tok->decoding_readline, readline); if (pos > 0) { PyObject *bufobj = _PyObject_CallNoArgs(readline); - if (bufobj == NULL) + if (bufobj == NULL) { return 0; + } Py_DECREF(bufobj); } From fb9fe24d87db7bd14e0160463579bd561d5e9267 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 2 Dec 2021 17:50:11 -0700 Subject: [PATCH 008/115] Add _PyDict_GetItemWithError(). --- Include/cpython/dictobject.h | 1 + Objects/dictobject.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Include/cpython/dictobject.h b/Include/cpython/dictobject.h index e97969be4de0cc7..d5119644c521254 100644 --- a/Include/cpython/dictobject.h +++ b/Include/cpython/dictobject.h @@ -30,6 +30,7 @@ typedef struct { PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, Py_hash_t hash); +PyAPI_FUNC(PyObject *) _PyDict_GetItemWithError(PyObject *dp, PyObject *key); PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key); PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *); diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 39be189e12000f1..ac956f7ab985c46 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1466,6 +1466,14 @@ PyDict_GetItemWithError(PyObject *op, PyObject *key) return value; } +PyObject * +_PyDict_GetItemWithError(PyObject *dp, PyObject *kv) +{ + Py_hash_t hash = ((PyASCIIObject *) kv)->hash; + assert (hash != -1); /* interned strings have their hash value initialised */ + return _PyDict_GetItem_KnownHash(dp, kv, hash); +} + PyObject * _PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key) { From 7fa8e839a301d665c090113dd8acbc67cb664064 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 3 Dec 2021 17:09:24 -0700 Subject: [PATCH 009/115] Set the hash if not set yet. --- Objects/dictobject.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Objects/dictobject.c b/Objects/dictobject.c index ac956f7ab985c46..0479edc0724d65b 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -1469,8 +1469,11 @@ PyDict_GetItemWithError(PyObject *op, PyObject *key) PyObject * _PyDict_GetItemWithError(PyObject *dp, PyObject *kv) { - Py_hash_t hash = ((PyASCIIObject *) kv)->hash; - assert (hash != -1); /* interned strings have their hash value initialised */ + assert(PyUnicode_CheckExact(kv)); + Py_hash_t hash = kv->ob_type->tp_hash(kv); + if (hash == -1) { + return NULL; + } return _PyDict_GetItem_KnownHash(dp, kv, hash); } From 9563c27e340a8be52a70996199cb8216906160b9 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 2 Dec 2021 18:07:23 -0700 Subject: [PATCH 010/115] Add _PySys_GetAttr(). --- Include/cpython/sysmodule.h | 2 ++ Python/sysmodule.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/Include/cpython/sysmodule.h b/Include/cpython/sysmodule.h index fc4c899b3fe3dc3..27dff7b2e3d9308 100644 --- a/Include/cpython/sysmodule.h +++ b/Include/cpython/sysmodule.h @@ -2,6 +2,8 @@ # error "this header file must not be included directly" #endif +PyAPI_FUNC(PyObject *) _PySys_GetAttr(PyThreadState *tstate, + PyObject *name); PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key); PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 7597ea2ea9e495a..e1a2a030e8e7542 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -67,6 +67,22 @@ _Py_IDENTIFIER(stderr); _Py_IDENTIFIER(warnoptions); _Py_IDENTIFIER(write); +PyObject * +_PySys_GetAttr(PyThreadState *tstate, PyObject *name) +{ + PyObject *sd = tstate->interp->sysdict; + if (sd == NULL) { + return NULL; + } + PyObject *exc_type, *exc_value, *exc_tb; + _PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb); + /* XXX Suppress a new exception if it was raised and restore + * the old one. */ + PyObject *value = _PyDict_GetItemWithError(sd, name); + _PyErr_Restore(tstate, exc_type, exc_value, exc_tb); + return value; +} + static PyObject * sys_get_object_id(PyThreadState *tstate, _Py_Identifier *key) { From 674e40b694b6d37076407db069c916a416d7e7eb Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 2 Dec 2021 18:11:41 -0700 Subject: [PATCH 011/115] Get rid of _Py_IDENTIFIER() in _warnings.c. --- Include/internal/pycore_global_strings.h | 2 + Include/internal/pycore_runtime_init.h | 2 + Python/_warnings.c | 273 ++++++++++++++--------- 3 files changed, 168 insertions(+), 109 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 216f7c80a0817bb..5c22043a93740b6 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -476,6 +476,7 @@ struct _Py_global_strings { ID(copy) ID(copyreg) ID(decode) + ID(default) ID(defaultaction) ID(difference_update) ID(displayhook) @@ -496,6 +497,7 @@ struct _Py_global_strings { ID(getattr) ID(getpreferredencoding) ID(getstate) + ID(ignore) ID(imp) ID(importlib) ID(inf) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 4714e4f07d9067f..a91bc8360bf5fdb 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -1098,6 +1098,7 @@ extern "C" { INIT_ID(copy), \ INIT_ID(copyreg), \ INIT_ID(decode), \ + INIT_ID(default), \ INIT_ID(defaultaction), \ INIT_ID(difference_update), \ INIT_ID(displayhook), \ @@ -1118,6 +1119,7 @@ extern "C" { INIT_ID(getattr), \ INIT_ID(getpreferredencoding), \ INIT_ID(getstate), \ + INIT_ID(ignore), \ INIT_ID(imp), \ INIT_ID(importlib), \ INIT_ID(inf), \ diff --git a/Python/_warnings.c b/Python/_warnings.c index cf2110d31c3b5e3..9d37cdf4072df23 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -14,30 +14,45 @@ PyDoc_STRVAR(warnings__doc__, MODULE_NAME " provides basic warning filtering support.\n" "It is a helper module to speed up interpreter start-up."); -_Py_IDENTIFIER(stderr); -#ifndef Py_DEBUG -_Py_IDENTIFIER(default); -_Py_IDENTIFIER(ignore); -#endif - /*************************************************************************/ typedef struct _warnings_runtime_state WarningsState; -_Py_IDENTIFIER(__name__); - -/* Given a module object, get its per-module state. */ -static WarningsState * -warnings_get_state(void) +static inline int +check_interp(PyInterpreterState *interp) { - PyInterpreterState *interp = _PyInterpreterState_GET(); if (interp == NULL) { PyErr_SetString(PyExc_RuntimeError, "warnings_get_state: could not identify " "current interpreter"); + return 0; + } + return 1; +} + +static inline PyInterpreterState * +get_current_interp(void) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return check_interp(interp) ? interp : NULL; +} + +static inline PyThreadState * +get_current_tstate(void) +{ + PyThreadState *tstate = _PyThreadState_GET(); + if (tstate == NULL) { + (void)check_interp(NULL); return NULL; } + return check_interp(tstate->interp) ? tstate : NULL; +} + +/* Given a module object, get its per-module state. */ +static WarningsState * +warnings_get_state(PyInterpreterState *interp) +{ return &interp->warnings; } @@ -52,13 +67,9 @@ warnings_clear_state(WarningsState *st) #ifndef Py_DEBUG static PyObject * -create_filter(PyObject *category, _Py_Identifier *id, const char *modname) +create_filter(PyObject *category, PyObject *action_str, const char *modname) { PyObject *modname_obj = NULL; - PyObject *action_str = _PyUnicode_FromId(id); - if (action_str == NULL) { - return NULL; - } /* Default to "no module name" for initial filter set */ if (modname != NULL) { @@ -79,7 +90,7 @@ create_filter(PyObject *category, _Py_Identifier *id, const char *modname) #endif static PyObject * -init_filters(void) +init_filters(PyInterpreterState *interp) { #ifdef Py_DEBUG /* Py_DEBUG builds show all warnings by default */ @@ -92,16 +103,17 @@ init_filters(void) } size_t pos = 0; /* Post-incremented in each use. */ - PyList_SET_ITEM(filters, pos++, - create_filter(PyExc_DeprecationWarning, &PyId_default, "__main__")); - PyList_SET_ITEM(filters, pos++, - create_filter(PyExc_DeprecationWarning, &PyId_ignore, NULL)); - PyList_SET_ITEM(filters, pos++, - create_filter(PyExc_PendingDeprecationWarning, &PyId_ignore, NULL)); - PyList_SET_ITEM(filters, pos++, - create_filter(PyExc_ImportWarning, &PyId_ignore, NULL)); - PyList_SET_ITEM(filters, pos++, - create_filter(PyExc_ResourceWarning, &PyId_ignore, NULL)); +#define ADD(TYPE, ACTION, MODNAME) \ + do { \ + PyObject *action = _Py_GET_GLOBAL_IDENTIFIER(ACTION); \ + PyList_SET_ITEM(filters, pos++, create_filter(TYPE, action, MODNAME)); \ + } while (0) + ADD(PyExc_DeprecationWarning, default, "__main__"); + ADD(PyExc_DeprecationWarning, ignore, NULL); + ADD(PyExc_PendingDeprecationWarning, ignore, NULL); + ADD(PyExc_ImportWarning, ignore, NULL); + ADD(PyExc_ResourceWarning, ignore, NULL); +#undef ADD for (size_t x = 0; x < pos; x++) { if (PyList_GET_ITEM(filters, x) == NULL) { @@ -120,7 +132,7 @@ _PyWarnings_InitState(PyInterpreterState *interp) WarningsState *st = &interp->warnings; if (st->filters == NULL) { - st->filters = init_filters(); + st->filters = init_filters(interp); if (st->filters == NULL) { return -1; } @@ -148,10 +160,9 @@ _PyWarnings_InitState(PyInterpreterState *interp) /*************************************************************************/ static int -check_matched(PyObject *obj, PyObject *arg) +check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg) { PyObject *result; - _Py_IDENTIFIER(match); int rc; /* A 'None' filter always matches */ @@ -168,7 +179,8 @@ check_matched(PyObject *obj, PyObject *arg) } /* Otherwise assume a regex filter and call its match() method */ - result = _PyObject_CallMethodIdOneArg(obj, &PyId_match, arg); + PyObject *str_match = _Py_GET_GLOBAL_IDENTIFIER(match); + result = PyObject_CallMethodOneArg(obj, str_match, arg); if (result == NULL) return -1; @@ -177,21 +189,22 @@ check_matched(PyObject *obj, PyObject *arg) return rc; } +#define GET_WARNINGS_ATTR(interp, attr, try_import) \ + get_warnings_attr(interp, \ + _Py_GET_GLOBAL_IDENTIFIER(attr), \ + try_import) + /* Returns a new reference. A NULL return value can mean false or an error. */ static PyObject * -get_warnings_attr(_Py_Identifier *attr_id, int try_import) +get_warnings_attr(PyInterpreterState *interp, PyObject *attr, int try_import) { PyObject *warnings_str; PyObject *warnings_module, *obj; - _Py_IDENTIFIER(warnings); - warnings_str = _PyUnicode_FromId(&PyId_warnings); - if (warnings_str == NULL) { - return NULL; - } + warnings_str = _Py_GET_GLOBAL_IDENTIFIER(warnings); /* don't try to import after the start of the Python finallization */ if (try_import && !_Py_IsFinalizing()) { @@ -210,7 +223,7 @@ get_warnings_attr(_Py_Identifier *attr_id, int try_import) gone, then we can't even use PyImport_GetModule without triggering an interpreter abort. */ - if (!_PyInterpreterState_GET()->modules) { + if (!interp->modules) { return NULL; } warnings_module = PyImport_GetModule(warnings_str); @@ -218,19 +231,23 @@ get_warnings_attr(_Py_Identifier *attr_id, int try_import) return NULL; } - (void)_PyObject_LookupAttrId(warnings_module, attr_id, &obj); + (void)_PyObject_LookupAttr(warnings_module, attr, &obj); Py_DECREF(warnings_module); return obj; } static PyObject * -get_once_registry(WarningsState *st) +get_once_registry(PyInterpreterState *interp) { PyObject *registry; - _Py_IDENTIFIER(onceregistry); - registry = get_warnings_attr(&PyId_onceregistry, 0); + WarningsState *st = warnings_get_state(interp); + if (st == NULL) { + return NULL; + } + + registry = GET_WARNINGS_ATTR(interp, onceregistry, 0); if (registry == NULL) { if (PyErr_Occurred()) return NULL; @@ -251,12 +268,16 @@ get_once_registry(WarningsState *st) static PyObject * -get_default_action(WarningsState *st) +get_default_action(PyInterpreterState *interp) { PyObject *default_action; - _Py_IDENTIFIER(defaultaction); - default_action = get_warnings_attr(&PyId_defaultaction, 0); + WarningsState *st = warnings_get_state(interp); + if (st == NULL) { + return NULL; + } + + default_action = GET_WARNINGS_ATTR(interp, defaultaction, 0); if (default_action == NULL) { if (PyErr_Occurred()) { return NULL; @@ -279,19 +300,19 @@ get_default_action(WarningsState *st) /* The item is a new reference. */ static PyObject* -get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno, +get_filter(PyInterpreterState *interp, PyObject *category, + PyObject *text, Py_ssize_t lineno, PyObject *module, PyObject **item) { PyObject *action; Py_ssize_t i; PyObject *warnings_filters; - _Py_IDENTIFIER(filters); - WarningsState *st = warnings_get_state(); + WarningsState *st = warnings_get_state(interp); if (st == NULL) { return NULL; } - warnings_filters = get_warnings_attr(&PyId_filters, 0); + warnings_filters = GET_WARNINGS_ATTR(interp, filters, 0); if (warnings_filters == NULL) { if (PyErr_Occurred()) return NULL; @@ -336,13 +357,13 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno, return NULL; } - good_msg = check_matched(msg, text); + good_msg = check_matched(interp, msg, text); if (good_msg == -1) { Py_DECREF(tmp_item); return NULL; } - good_mod = check_matched(mod, module); + good_mod = check_matched(interp, mod, module); if (good_mod == -1) { Py_DECREF(tmp_item); return NULL; @@ -368,7 +389,7 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno, Py_DECREF(tmp_item); } - action = get_default_action(st); + action = get_default_action(interp); if (action != NULL) { Py_INCREF(Py_None); *item = Py_None; @@ -380,19 +401,20 @@ get_filter(PyObject *category, PyObject *text, Py_ssize_t lineno, static int -already_warned(PyObject *registry, PyObject *key, int should_set) +already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key, + int should_set) { PyObject *version_obj, *already_warned; - _Py_IDENTIFIER(version); if (key == NULL) return -1; - WarningsState *st = warnings_get_state(); + WarningsState *st = warnings_get_state(interp); if (st == NULL) { return -1; } - version_obj = _PyDict_GetItemIdWithError(registry, &PyId_version); + PyObject *str_version = _Py_GET_GLOBAL_IDENTIFIER(version); + version_obj = _PyDict_GetItemWithError(registry, str_version); if (version_obj == NULL || !PyLong_CheckExact(version_obj) || PyLong_AsLong(version_obj) != st->filters_version) @@ -404,7 +426,7 @@ already_warned(PyObject *registry, PyObject *key, int should_set) version_obj = PyLong_FromLong(st->filters_version); if (version_obj == NULL) return -1; - if (_PyDict_SetItemId(registry, &PyId_version, version_obj) < 0) { + if (PyDict_SetItem(registry, str_version, version_obj) < 0) { Py_DECREF(version_obj); return -1; } @@ -463,8 +485,8 @@ normalize_module(PyObject *filename) } static int -update_registry(PyObject *registry, PyObject *text, PyObject *category, - int add_zero) +update_registry(PyInterpreterState *interp, PyObject *registry, PyObject *text, + PyObject *category, int add_zero) { PyObject *altkey; int rc; @@ -474,27 +496,30 @@ update_registry(PyObject *registry, PyObject *text, PyObject *category, else altkey = PyTuple_Pack(2, text, category); - rc = already_warned(registry, altkey, 1); + rc = already_warned(interp, registry, altkey, 1); Py_XDECREF(altkey); return rc; } static void -show_warning(PyObject *filename, int lineno, PyObject *text, - PyObject *category, PyObject *sourceline) +show_warning(PyThreadState *tstate, PyObject *filename, int lineno, + PyObject *text, PyObject *category, PyObject *sourceline) { PyObject *f_stderr; + PyObject *attr; PyObject *name; char lineno_str[128]; PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno); - name = _PyObject_GetAttrId(category, &PyId___name__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + name = PyObject_GetAttr(category, attr); if (name == NULL) { goto error; } - f_stderr = _PySys_GetObjectId(&PyId_stderr); + attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + f_stderr = _PySys_GetAttr(tstate, attr); if (f_stderr == NULL) { fprintf(stderr, "lost sys.stderr\n"); goto error; @@ -553,22 +578,22 @@ show_warning(PyObject *filename, int lineno, PyObject *text, } static int -call_show_warning(PyObject *category, PyObject *text, PyObject *message, +call_show_warning(PyThreadState *tstate, PyObject *category, + PyObject *text, PyObject *message, PyObject *filename, int lineno, PyObject *lineno_obj, PyObject *sourceline, PyObject *source) { PyObject *show_fn, *msg, *res, *warnmsg_cls = NULL; - _Py_IDENTIFIER(_showwarnmsg); - _Py_IDENTIFIER(WarningMessage); + PyInterpreterState *interp = tstate->interp; /* If the source parameter is set, try to get the Python implementation. The Python implementation is able to log the traceback where the source was allocated, whereas the C implementation doesn't. */ - show_fn = get_warnings_attr(&PyId__showwarnmsg, source != NULL); + show_fn = GET_WARNINGS_ATTR(interp, _showwarnmsg, source != NULL); if (show_fn == NULL) { if (PyErr_Occurred()) return -1; - show_warning(filename, lineno, text, category, sourceline); + show_warning(tstate, filename, lineno, text, category, sourceline); return 0; } @@ -578,7 +603,7 @@ call_show_warning(PyObject *category, PyObject *text, PyObject *message, goto error; } - warnmsg_cls = get_warnings_attr(&PyId_WarningMessage, 0); + warnmsg_cls = GET_WARNINGS_ATTR(interp, WarningMessage, 0); if (warnmsg_cls == NULL) { if (!PyErr_Occurred()) { PyErr_SetString(PyExc_RuntimeError, @@ -610,7 +635,7 @@ call_show_warning(PyObject *category, PyObject *text, PyObject *message, } static PyObject * -warn_explicit(PyObject *category, PyObject *message, +warn_explicit(PyThreadState *tstate, PyObject *category, PyObject *message, PyObject *filename, int lineno, PyObject *module, PyObject *registry, PyObject *sourceline, PyObject *source) @@ -619,6 +644,7 @@ warn_explicit(PyObject *category, PyObject *message, PyObject *item = NULL; PyObject *action; int rc; + PyInterpreterState *interp = tstate->interp; /* module can be None if a warning is emitted late during Python shutdown. In this case, the Python warnings module was probably unloaded, filters @@ -674,7 +700,7 @@ warn_explicit(PyObject *category, PyObject *message, goto cleanup; if ((registry != NULL) && (registry != Py_None)) { - rc = already_warned(registry, key, 0); + rc = already_warned(interp, registry, key, 0); if (rc == -1) goto cleanup; else if (rc == 1) @@ -682,7 +708,7 @@ warn_explicit(PyObject *category, PyObject *message, /* Else this warning hasn't been generated before. */ } - action = get_filter(category, text, lineno, module, &item); + action = get_filter(interp, category, text, lineno, module, &item); if (action == NULL) goto cleanup; @@ -707,21 +733,17 @@ warn_explicit(PyObject *category, PyObject *message, if (_PyUnicode_EqualToASCIIString(action, "once")) { if (registry == NULL || registry == Py_None) { - WarningsState *st = warnings_get_state(); - if (st == NULL) { - goto cleanup; - } - registry = get_once_registry(st); + registry = get_once_registry(interp); if (registry == NULL) goto cleanup; } /* WarningsState.once_registry[(text, category)] = 1 */ - rc = update_registry(registry, text, category, 0); + rc = update_registry(interp, registry, text, category, 0); } else if (_PyUnicode_EqualToASCIIString(action, "module")) { /* registry[(text, category, 0)] = 1 */ if (registry != NULL && registry != Py_None) - rc = update_registry(registry, text, category, 0); + rc = update_registry(interp, registry, text, category, 0); } else if (!_PyUnicode_EqualToASCIIString(action, "default")) { PyErr_Format(PyExc_RuntimeError, @@ -734,8 +756,8 @@ warn_explicit(PyObject *category, PyObject *message, if (rc == 1) /* Already warned for this module. */ goto return_none; if (rc == 0) { - if (call_show_warning(category, text, message, filename, lineno, - lineno_obj, sourceline, source) < 0) + if (call_show_warning(tstate, category, text, message, filename, + lineno, lineno_obj, sourceline, source) < 0) goto cleanup; } else /* if (rc == -1) */ @@ -827,11 +849,14 @@ static int setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, PyObject **module, PyObject **registry) { - _Py_IDENTIFIER(__warningregistry__); PyObject *globals; /* Setup globals, filename and lineno. */ - PyThreadState *tstate = _PyThreadState_GET(); + PyThreadState *tstate = get_current_tstate(); + if (tstate == NULL) { + return 0; + } + PyInterpreterState *interp = tstate->interp; PyFrameObject *f = PyThreadState_GetFrame(tstate); // Stack level comparisons to Python code is off by one as there is no // warnings-related stack level to avoid. @@ -849,7 +874,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, } if (f == NULL) { - globals = tstate->interp->sysdict; + globals = interp->sysdict; *filename = PyUnicode_FromString("sys"); *lineno = 1; } @@ -866,7 +891,8 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, /* Setup registry. */ assert(globals != NULL); assert(PyDict_Check(globals)); - *registry = _PyDict_GetItemIdWithError(globals, &PyId___warningregistry__); + PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__warningregistry__); + *registry = _PyDict_GetItemWithError(globals, key); if (*registry == NULL) { int rc; @@ -877,7 +903,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, if (*registry == NULL) goto handle_error; - rc = _PyDict_SetItemId(globals, &PyId___warningregistry__, *registry); + rc = PyDict_SetItem(globals, key, *registry); if (rc < 0) goto handle_error; } @@ -885,7 +911,8 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, Py_INCREF(*registry); /* Setup module. */ - *module = _PyDict_GetItemIdWithError(globals, &PyId___name__); + key = _Py_GET_GLOBAL_IDENTIFIER(__name__); + *module = _PyDict_GetItemWithError(globals, key); if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) { Py_INCREF(*module); } @@ -943,10 +970,15 @@ do_warn(PyObject *message, PyObject *category, Py_ssize_t stack_level, PyObject *filename, *module, *registry, *res; int lineno; + PyThreadState *tstate = get_current_tstate(); + if (tstate == NULL) { + return NULL; + } + if (!setup_context(stack_level, &filename, &lineno, &module, ®istry)) return NULL; - res = warn_explicit(category, message, filename, lineno, module, registry, + res = warn_explicit(tstate, category, message, filename, lineno, module, registry, NULL, source); Py_DECREF(filename); Py_DECREF(registry); @@ -977,10 +1009,9 @@ warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category, } static PyObject * -get_source_line(PyObject *module_globals, int lineno) +get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno) { - _Py_IDENTIFIER(get_source); - _Py_IDENTIFIER(__loader__); + PyObject *key; PyObject *loader; PyObject *module_name; PyObject *get_source; @@ -989,12 +1020,14 @@ get_source_line(PyObject *module_globals, int lineno) PyObject *source_line; /* Check/get the requisite pieces needed for the loader. */ - loader = _PyDict_GetItemIdWithError(module_globals, &PyId___loader__); + key = _Py_GET_GLOBAL_IDENTIFIER(__loader__); + loader = _PyDict_GetItemWithError(module_globals, key); if (loader == NULL) { return NULL; } Py_INCREF(loader); - module_name = _PyDict_GetItemIdWithError(module_globals, &PyId___name__); + key = _Py_GET_GLOBAL_IDENTIFIER(__name__); + module_name = _PyDict_GetItemWithError(module_globals, key); if (!module_name) { Py_DECREF(loader); return NULL; @@ -1002,7 +1035,8 @@ get_source_line(PyObject *module_globals, int lineno) Py_INCREF(module_name); /* Make sure the loader implements the optional get_source() method. */ - (void)_PyObject_LookupAttrId(loader, &PyId_get_source, &get_source); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(get_source); + (void)_PyObject_LookupAttr(loader, attr, &get_source); Py_DECREF(loader); if (!get_source) { Py_DECREF(module_name); @@ -1056,6 +1090,11 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds) ®istry, &module_globals, &sourceobj)) return NULL; + PyThreadState *tstate = get_current_tstate(); + if (tstate == NULL) { + return NULL; + } + if (module_globals && module_globals != Py_None) { if (!PyDict_Check(module_globals)) { PyErr_Format(PyExc_TypeError, @@ -1064,12 +1103,12 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds) return NULL; } - source_line = get_source_line(module_globals, lineno); + source_line = get_source_line(tstate->interp, module_globals, lineno); if (source_line == NULL && PyErr_Occurred()) { return NULL; } } - returned = warn_explicit(category, message, filename, lineno, module, + returned = warn_explicit(tstate, category, message, filename, lineno, module, registry, source_line, sourceobj); Py_XDECREF(source_line); return returned; @@ -1078,7 +1117,11 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds) static PyObject * warnings_filters_mutated(PyObject *self, PyObject *args) { - WarningsState *st = warnings_get_state(); + PyInterpreterState *interp = get_current_interp(); + if (interp == NULL) { + return NULL; + } + WarningsState *st = warnings_get_state(interp); if (st == NULL) { return NULL; } @@ -1208,7 +1251,11 @@ PyErr_WarnExplicitObject(PyObject *category, PyObject *message, PyObject *res; if (category == NULL) category = PyExc_RuntimeWarning; - res = warn_explicit(category, message, filename, lineno, + PyThreadState *tstate = get_current_tstate(); + if (tstate == NULL) { + return -1; + } + res = warn_explicit(tstate, category, message, filename, lineno, module, registry, NULL, NULL); if (res == NULL) return -1; @@ -1272,12 +1319,15 @@ PyErr_WarnExplicitFormat(PyObject *category, message = PyUnicode_FromFormatV(format, vargs); if (message != NULL) { PyObject *res; - res = warn_explicit(category, message, filename, lineno, - module, registry, NULL, NULL); - Py_DECREF(message); - if (res != NULL) { - Py_DECREF(res); - ret = 0; + PyThreadState *tstate = get_current_tstate(); + if (tstate != NULL) { + res = warn_explicit(tstate, category, message, filename, lineno, + module, registry, NULL, NULL); + Py_DECREF(message); + if (res != NULL) { + Py_DECREF(res); + ret = 0; + } } } va_end(vargs); @@ -1309,9 +1359,10 @@ _PyErr_WarnUnawaitedCoroutine(PyObject *coro) Since this is called from __del__ context, it's careful to never raise an exception. */ - _Py_IDENTIFIER(_warn_unawaited_coroutine); int warned = 0; - PyObject *fn = get_warnings_attr(&PyId__warn_unawaited_coroutine, 1); + PyInterpreterState *interp = _PyInterpreterState_GET(); + assert(interp != NULL); + PyObject *fn = GET_WARNINGS_ATTR(interp, _warn_unawaited_coroutine, 1); if (fn) { PyObject *res = PyObject_CallOneArg(fn, coro); Py_DECREF(fn); @@ -1352,7 +1403,11 @@ static PyMethodDef warnings_functions[] = { static int warnings_module_exec(PyObject *module) { - WarningsState *st = warnings_get_state(); + PyInterpreterState *interp = get_current_interp(); + if (interp == NULL) { + return -1; + } + WarningsState *st = warnings_get_state(interp); if (st == NULL) { return -1; } From e5e748356b8bae7bb922c6f3bedde51214700aa8 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 3 Dec 2021 17:45:58 -0700 Subject: [PATCH 012/115] _PyObject_LookupSpecial() -> _PyObject_LookupSpecialId(). --- Include/cpython/object.h | 2 +- Modules/_testcapimodule.c | 2 +- Modules/mathmodule.c | 6 +++--- Modules/posixmodule.c | 4 ++-- Objects/abstract.c | 10 +++++----- Objects/bytesobject.c | 4 ++-- Objects/complexobject.c | 2 +- Objects/dictobject.c | 2 +- Objects/enumobject.c | 2 +- Objects/object.c | 4 ++-- Objects/typeobject.c | 8 ++++---- Python/ceval.c | 8 ++++---- Python/sysmodule.c | 2 +- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 7b9f3acbc439d69..1dee99f29df927f 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -296,7 +296,7 @@ typedef struct _heaptypeobject { PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *); PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *); -PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, _Py_Identifier *); +PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *); PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *); PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *); diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 7369f094faeddec..5582890be268f91 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -3865,7 +3865,7 @@ slot_tp_del(PyObject *self) PyErr_Fetch(&error_type, &error_value, &error_traceback); /* Execute __del__ method, if any. */ - del = _PyObject_LookupSpecial(self, &PyId___tp_del__); + del = _PyObject_LookupSpecialId(self, &PyId___tp_del__); if (del != NULL) { res = PyObject_CallNoArgs(del); if (res == NULL) diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 0c7d4de0686213a..9b5c0619f7a6f16 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -1216,7 +1216,7 @@ math_ceil(PyObject *module, PyObject *number) _Py_IDENTIFIER(__ceil__); if (!PyFloat_CheckExact(number)) { - PyObject *method = _PyObject_LookupSpecial(number, &PyId___ceil__); + PyObject *method = _PyObject_LookupSpecialId(number, &PyId___ceil__); if (method != NULL) { PyObject *result = _PyObject_CallNoArgs(method); Py_DECREF(method); @@ -1288,7 +1288,7 @@ math_floor(PyObject *module, PyObject *number) } else { - PyObject *method = _PyObject_LookupSpecial(number, &PyId___floor__); + PyObject *method = _PyObject_LookupSpecialId(number, &PyId___floor__); if (method != NULL) { PyObject *result = _PyObject_CallNoArgs(method); Py_DECREF(method); @@ -2166,7 +2166,7 @@ math_trunc(PyObject *module, PyObject *x) return NULL; } - trunc = _PyObject_LookupSpecial(x, &PyId___trunc__); + trunc = _PyObject_LookupSpecialId(x, &PyId___trunc__); if (trunc == NULL) { if (!PyErr_Occurred()) PyErr_Format(PyExc_TypeError, diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 7b5c3ef575565c2..0efe5ffdbad05fe 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1159,7 +1159,7 @@ path_converter(PyObject *o, void *p) /* Inline PyOS_FSPath() for better error messages. */ PyObject *func, *res; - func = _PyObject_LookupSpecial(o, &PyId___fspath__); + func = _PyObject_LookupSpecialId(o, &PyId___fspath__); if (NULL == func) { goto error_format; } @@ -14437,7 +14437,7 @@ PyOS_FSPath(PyObject *path) return path; } - func = _PyObject_LookupSpecial(path, &PyId___fspath__); + func = _PyObject_LookupSpecialId(path, &PyId___fspath__); if (NULL == func) { return PyErr_Format(PyExc_TypeError, "expected str, bytes or os.PathLike object, " diff --git a/Objects/abstract.c b/Objects/abstract.c index 6a2d5eda14079bc..627bbadb25ac227 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -107,7 +107,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) return res; } } - hint = _PyObject_LookupSpecial(o, &PyId___length_hint__); + hint = _PyObject_LookupSpecialId(o, &PyId___length_hint__); if (hint == NULL) { if (PyErr_Occurred()) { return -1; @@ -797,7 +797,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) } /* Find the (unbound!) __format__ method */ - meth = _PyObject_LookupSpecial(obj, &PyId___format__); + meth = _PyObject_LookupSpecialId(obj, &PyId___format__); if (meth == NULL) { PyThreadState *tstate = _PyThreadState_GET(); if (!_PyErr_Occurred(tstate)) { @@ -1562,7 +1562,7 @@ PyNumber_Long(PyObject *o) if (m && m->nb_index) { return PyNumber_Index(o); } - trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__); + trunc_func = _PyObject_LookupSpecialId(o, &PyId___trunc__); if (trunc_func) { result = _PyObject_CallNoArgs(trunc_func); Py_DECREF(trunc_func); @@ -2651,7 +2651,7 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls return r; } - PyObject *checker = _PyObject_LookupSpecial(cls, &PyId___instancecheck__); + PyObject *checker = _PyObject_LookupSpecialId(cls, &PyId___instancecheck__); if (checker != NULL) { if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) { Py_DECREF(checker); @@ -2739,7 +2739,7 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) return r; } - checker = _PyObject_LookupSpecial(cls, &PyId___subclasscheck__); + checker = _PyObject_LookupSpecialId(cls, &PyId___subclasscheck__); if (checker != NULL) { int ok = -1; if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) { diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index b6edfb9acb2dbb5..9f8383fdbe17276 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -530,7 +530,7 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen) return v; } /* does it support __bytes__? */ - func = _PyObject_LookupSpecial(v, &PyId___bytes__); + func = _PyObject_LookupSpecialId(v, &PyId___bytes__); if (func != NULL) { result = _PyObject_CallNoArgs(func); Py_DECREF(func); @@ -2581,7 +2581,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding, /* We'd like to call PyObject_Bytes here, but we need to check for an integer argument before deferring to PyBytes_FromObject, something PyObject_Bytes doesn't do. */ - else if ((func = _PyObject_LookupSpecial(x, &PyId___bytes__)) != NULL) { + else if ((func = _PyObject_LookupSpecialId(x, &PyId___bytes__)) != NULL) { bytes = _PyObject_CallNoArgs(func); Py_DECREF(func); if (bytes == NULL) diff --git a/Objects/complexobject.c b/Objects/complexobject.c index e0766de258805fd..c82445b230c0705 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -283,7 +283,7 @@ try_complex_special_method(PyObject *op) PyObject *f; _Py_IDENTIFIER(__complex__); - f = _PyObject_LookupSpecial(op, &PyId___complex__); + f = _PyObject_LookupSpecialId(op, &PyId___complex__); if (f) { PyObject *res = _PyObject_CallNoArgs(f); Py_DECREF(f); diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 0479edc0724d65b..ed08ff1d581e8bc 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2160,7 +2160,7 @@ dict_subscript(PyDictObject *mp, PyObject *key) /* Look up __missing__ method if we're a subclass. */ PyObject *missing, *res; _Py_IDENTIFIER(__missing__); - missing = _PyObject_LookupSpecial((PyObject *)mp, &PyId___missing__); + missing = _PyObject_LookupSpecialId((PyObject *)mp, &PyId___missing__); if (missing != NULL) { res = PyObject_CallOneArg(missing, key); Py_DECREF(missing); diff --git a/Objects/enumobject.c b/Objects/enumobject.c index 828f1f925a0a1d9..4c941d676e78bb2 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -358,7 +358,7 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq) reversedobject *ro; _Py_IDENTIFIER(__reversed__); - reversed_meth = _PyObject_LookupSpecial(seq, &PyId___reversed__); + reversed_meth = _PyObject_LookupSpecialId(seq, &PyId___reversed__); if (reversed_meth == Py_None) { Py_DECREF(reversed_meth); PyErr_Format(PyExc_TypeError, diff --git a/Objects/object.c b/Objects/object.c index 3082e70e7e230b6..2d4180d292458df 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -562,7 +562,7 @@ PyObject_Bytes(PyObject *v) return v; } - func = _PyObject_LookupSpecial(v, &PyId___bytes__); + func = _PyObject_LookupSpecialId(v, &PyId___bytes__); if (func != NULL) { result = _PyObject_CallNoArgs(func); Py_DECREF(func); @@ -1569,7 +1569,7 @@ static PyObject * _dir_object(PyObject *obj) { PyObject *result, *sorted; - PyObject *dirfunc = _PyObject_LookupSpecial(obj, &PyId___dir__); + PyObject *dirfunc = _PyObject_LookupSpecialId(obj, &PyId___dir__); assert(obj != NULL); if (dirfunc == NULL) { diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 621ad9745d8448c..0c8111ead49de11 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1604,7 +1604,7 @@ PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) */ PyObject * -_PyObject_LookupSpecial(PyObject *self, _Py_Identifier *attrid) +_PyObject_LookupSpecialId(PyObject *self, _Py_Identifier *attrid) { PyObject *res; @@ -5155,7 +5155,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* We first attempt to fetch the arguments for __new__ by calling __getnewargs_ex__ on the object. */ - getnewargs_ex = _PyObject_LookupSpecial(obj, &PyId___getnewargs_ex__); + getnewargs_ex = _PyObject_LookupSpecialId(obj, &PyId___getnewargs_ex__); if (getnewargs_ex != NULL) { PyObject *newargs = _PyObject_CallNoArgs(getnewargs_ex); Py_DECREF(getnewargs_ex); @@ -5208,7 +5208,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* The object does not have __getnewargs_ex__ so we fallback on using __getnewargs__ instead. */ - getnewargs = _PyObject_LookupSpecial(obj, &PyId___getnewargs__); + getnewargs = _PyObject_LookupSpecialId(obj, &PyId___getnewargs__); if (getnewargs != NULL) { *args = _PyObject_CallNoArgs(getnewargs); Py_DECREF(getnewargs); @@ -8613,7 +8613,7 @@ type_new_set_names(PyTypeObject *type) Py_ssize_t i = 0; PyObject *key, *value; while (PyDict_Next(names_to_set, &i, &key, &value)) { - PyObject *set_name = _PyObject_LookupSpecial(value, &PyId___set_name__); + PyObject *set_name = _PyObject_LookupSpecialId(value, &PyId___set_name__); if (set_name == NULL) { if (PyErr_Occurred()) { goto error; diff --git a/Python/ceval.c b/Python/ceval.c index b69d5aa9d32069f..03083a1aca84f14 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4239,7 +4239,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr _Py_IDENTIFIER(__aexit__); PyObject *mgr = TOP(); PyObject *res; - PyObject *enter = _PyObject_LookupSpecial(mgr, &PyId___aenter__); + PyObject *enter = _PyObject_LookupSpecialId(mgr, &PyId___aenter__); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4249,7 +4249,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *exit = _PyObject_LookupSpecial(mgr, &PyId___aexit__); + PyObject *exit = _PyObject_LookupSpecialId(mgr, &PyId___aexit__); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4277,7 +4277,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr _Py_IDENTIFIER(__exit__); PyObject *mgr = TOP(); PyObject *res; - PyObject *enter = _PyObject_LookupSpecial(mgr, &PyId___enter__); + PyObject *enter = _PyObject_LookupSpecialId(mgr, &PyId___enter__); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4287,7 +4287,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *exit = _PyObject_LookupSpecial(mgr, &PyId___exit__); + PyObject *exit = _PyObject_LookupSpecialId(mgr, &PyId___exit__); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, diff --git a/Python/sysmodule.c b/Python/sysmodule.c index e1a2a030e8e7542..ce06e4ae275e2cb 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1692,7 +1692,7 @@ _PySys_GetSizeOf(PyObject *o) return (size_t)-1; } - method = _PyObject_LookupSpecial(o, &PyId___sizeof__); + method = _PyObject_LookupSpecialId(o, &PyId___sizeof__); if (method == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, From 07ac6baf24ef4e48e85f84fca48f08c45c7c533e Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 3 Dec 2021 17:51:18 -0700 Subject: [PATCH 013/115] Add _PyObject_LookupSpecial(). --- Include/cpython/object.h | 1 + Objects/typeobject.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 1dee99f29df927f..0acf90bb58e6bf1 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -296,6 +296,7 @@ typedef struct _heaptypeobject { PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *); PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *); +PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *); PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 0c8111ead49de11..dfe42cec92cd030 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1604,11 +1604,11 @@ PyType_IsSubtype(PyTypeObject *a, PyTypeObject *b) */ PyObject * -_PyObject_LookupSpecialId(PyObject *self, _Py_Identifier *attrid) +_PyObject_LookupSpecial(PyObject *self, PyObject *attr) { PyObject *res; - res = _PyType_LookupId(Py_TYPE(self), attrid); + res = _PyType_Lookup(Py_TYPE(self), attr); if (res != NULL) { descrgetfunc f; if ((f = Py_TYPE(res)->tp_descr_get) == NULL) @@ -1619,6 +1619,15 @@ _PyObject_LookupSpecialId(PyObject *self, _Py_Identifier *attrid) return res; } +PyObject * +_PyObject_LookupSpecialId(PyObject *self, _Py_Identifier *attrid) +{ + PyObject *attr = _PyUnicode_FromId(attrid); /* borrowed */ + if (attr == NULL) + return NULL; + return _PyObject_LookupSpecial(self, attr); +} + static PyObject * lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound) { From 249e8307c36f9e5c72e258a01c2d791e92da2dc4 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 3 Dec 2021 17:52:15 -0700 Subject: [PATCH 014/115] Get rid of _Py_IDENTIFIER() in bltinmodule.c. --- Python/bltinmodule.c | 86 ++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index ed612091d839416..ea54eba8de03ac2 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -11,21 +11,6 @@ #include "pycore_tuple.h" // _PyTuple_FromArray() #include "pycore_ceval.h" // _PyEval_Vector() -_Py_IDENTIFIER(__builtins__); -_Py_IDENTIFIER(__dict__); -_Py_IDENTIFIER(__prepare__); -_Py_IDENTIFIER(__round__); -_Py_IDENTIFIER(__mro_entries__); -_Py_IDENTIFIER(encoding); -_Py_IDENTIFIER(errors); -_Py_IDENTIFIER(fileno); -_Py_IDENTIFIER(flush); -_Py_IDENTIFIER(metaclass); -_Py_IDENTIFIER(sort); -_Py_IDENTIFIER(stdin); -_Py_IDENTIFIER(stdout); -_Py_IDENTIFIER(stderr); - #include "clinic/bltinmodule.c.h" static PyObject* @@ -47,7 +32,8 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs) } continue; } - if (_PyObject_LookupAttrId(base, &PyId___mro_entries__, &meth) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__mro_entries__); + if (_PyObject_LookupAttr(base, attr, &meth) < 0) { goto error; } if (!meth) { @@ -148,10 +134,11 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, goto error; } - meta = _PyDict_GetItemIdWithError(mkw, &PyId_metaclass); + PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(metaclass); + meta = _PyDict_GetItemWithError(mkw, key); if (meta != NULL) { Py_INCREF(meta); - if (_PyDict_DelItemId(mkw, &PyId_metaclass) < 0) { + if (PyDict_DelItem(mkw, key) < 0) { goto error; } /* metaclass is explicitly given, check if it's indeed a class */ @@ -191,7 +178,8 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, } /* else: meta is not a class, so we cannot do the metaclass calculation, so we will use the explicitly given object as it is */ - if (_PyObject_LookupAttrId(meta, &PyId___prepare__, &prep) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__prepare__); + if (_PyObject_LookupAttr(meta, attr, &prep) < 0) { ns = NULL; } else if (prep == NULL) { @@ -946,10 +934,10 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, return NULL; } - int r = _PyDict_ContainsId(globals, &PyId___builtins__); + PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); + int r = PyDict_Contains(globals, key); if (r == 0) { - r = _PyDict_SetItemId(globals, &PyId___builtins__, - PyEval_GetBuiltins()); + r = PyDict_SetItem(globals, key, PyEval_GetBuiltins()); } if (r < 0) { return NULL; @@ -1034,10 +1022,10 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, Py_TYPE(locals)->tp_name); return NULL; } - int r = _PyDict_ContainsId(globals, &PyId___builtins__); + PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); + int r = PyDict_Contains(globals, key); if (r == 0) { - r = _PyDict_SetItemId(globals, &PyId___builtins__, - PyEval_GetBuiltins()); + r = PyDict_SetItem(globals, key, PyEval_GetBuiltins()); } if (r < 0) { return NULL; @@ -1960,7 +1948,9 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, int i, err; if (file == Py_None) { - file = _PySys_GetObjectId(&PyId_stdout); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stdout); + file = _PySys_GetAttr(tstate, attr); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -2020,7 +2010,8 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, } if (flush) { - PyObject *tmp = _PyObject_CallMethodIdNoArgs(file, &PyId_flush); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *tmp = PyObject_CallMethodNoArgs(file, attr); if (tmp == NULL) { return NULL; } @@ -2050,9 +2041,13 @@ static PyObject * builtin_input_impl(PyObject *module, PyObject *prompt) /*[clinic end generated code: output=83db5a191e7a0d60 input=5e8bb70c2908fe3c]*/ { - PyObject *fin = _PySys_GetObjectId(&PyId_stdin); - PyObject *fout = _PySys_GetObjectId(&PyId_stdout); - PyObject *ferr = _PySys_GetObjectId(&PyId_stderr); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *fin = _PySys_GetAttr( + tstate, _Py_GET_GLOBAL_IDENTIFIER(stdin)); + PyObject *fout = _PySys_GetAttr( + tstate, _Py_GET_GLOBAL_IDENTIFIER(stdout)); + PyObject *ferr = _PySys_GetAttr( + tstate, _Py_GET_GLOBAL_IDENTIFIER(stderr)); PyObject *tmp; long fd; int tty; @@ -2079,7 +2074,8 @@ builtin_input_impl(PyObject *module, PyObject *prompt) } /* First of all, flush stderr */ - tmp = _PyObject_CallMethodIdNoArgs(ferr, &PyId_flush); + PyObject *str_flush = _Py_GET_GLOBAL_IDENTIFIER(flush); + tmp = PyObject_CallMethodNoArgs(ferr, str_flush); if (tmp == NULL) PyErr_Clear(); else @@ -2088,7 +2084,8 @@ builtin_input_impl(PyObject *module, PyObject *prompt) /* We should only use (GNU) readline if Python's sys.stdin and sys.stdout are the same as C's stdin and stdout, because we need to pass it those. */ - tmp = _PyObject_CallMethodIdNoArgs(fin, &PyId_fileno); + PyObject *str_fileno = _Py_GET_GLOBAL_IDENTIFIER(fileno); + tmp = PyObject_CallMethodNoArgs(fin, str_fileno); if (tmp == NULL) { PyErr_Clear(); tty = 0; @@ -2101,7 +2098,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) tty = fd == fileno(stdin) && isatty(fd); } if (tty) { - tmp = _PyObject_CallMethodIdNoArgs(fout, &PyId_fileno); + tmp = PyObject_CallMethodNoArgs(fout, str_fileno); if (tmp == NULL) { PyErr_Clear(); tty = 0; @@ -2125,10 +2122,12 @@ builtin_input_impl(PyObject *module, PyObject *prompt) const char *stdin_encoding_str, *stdin_errors_str; PyObject *result; size_t len; + PyObject *str_encoding = _Py_GET_GLOBAL_IDENTIFIER(encoding); + PyObject *str_errors = _Py_GET_GLOBAL_IDENTIFIER(errors); /* stdin is a text stream, so it must have an encoding. */ - stdin_encoding = _PyObject_GetAttrId(fin, &PyId_encoding); - stdin_errors = _PyObject_GetAttrId(fin, &PyId_errors); + stdin_encoding = PyObject_GetAttr(fin, str_encoding); + stdin_errors = PyObject_GetAttr(fin, str_errors); if (!stdin_encoding || !stdin_errors || !PyUnicode_Check(stdin_encoding) || !PyUnicode_Check(stdin_errors)) { @@ -2139,7 +2138,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) stdin_errors_str = PyUnicode_AsUTF8(stdin_errors); if (!stdin_encoding_str || !stdin_errors_str) goto _readline_errors; - tmp = _PyObject_CallMethodIdNoArgs(fout, &PyId_flush); + tmp = PyObject_CallMethodNoArgs(fout, str_flush); if (tmp == NULL) PyErr_Clear(); else @@ -2148,8 +2147,8 @@ builtin_input_impl(PyObject *module, PyObject *prompt) /* We have a prompt, encode it as stdout would */ const char *stdout_encoding_str, *stdout_errors_str; PyObject *stringpo; - stdout_encoding = _PyObject_GetAttrId(fout, &PyId_encoding); - stdout_errors = _PyObject_GetAttrId(fout, &PyId_errors); + stdout_encoding = PyObject_GetAttr(fout, str_encoding); + stdout_errors = PyObject_GetAttr(fout, str_errors); if (!stdout_encoding || !stdout_errors || !PyUnicode_Check(stdout_encoding) || !PyUnicode_Check(stdout_errors)) { @@ -2234,7 +2233,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0) return NULL; } - tmp = _PyObject_CallMethodIdNoArgs(fout, &PyId_flush); + tmp = PyObject_CallMethodNoArgs(fout, str_flush); if (tmp == NULL) PyErr_Clear(); else @@ -2285,7 +2284,8 @@ builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits) return NULL; } - round = _PyObject_LookupSpecial(number, &PyId___round__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__round__); + round = _PyObject_LookupSpecial(number, attr); if (round == NULL) { if (!PyErr_Occurred()) PyErr_Format(PyExc_TypeError, @@ -2346,7 +2346,8 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject if (newlist == NULL) return NULL; - callable = _PyObject_GetAttrId(newlist, &PyId_sort); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(sort); + callable = PyObject_GetAttr(newlist, attr); if (callable == NULL) { Py_DECREF(newlist); return NULL; @@ -2378,7 +2379,8 @@ builtin_vars(PyObject *self, PyObject *args) Py_XINCREF(d); } else { - if (_PyObject_LookupAttrId(v, &PyId___dict__, &d) == 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + if (_PyObject_LookupAttr(v, attr, &d) == 0) { PyErr_SetString(PyExc_TypeError, "vars() argument must have __dict__ attribute"); } From 3ea3c09b560757f7237a16702ff5d2bd736d1fbc Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 3 Dec 2021 18:13:21 -0700 Subject: [PATCH 015/115] Get rid of _Py_IDENTIFIER() in ceval.c. --- Python/ceval.c | 84 ++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 48 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index 03083a1aca84f14..ff1d539f7912643 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -49,8 +49,6 @@ # error "ceval.c must be build with Py_BUILD_CORE define for best performance" #endif -_Py_IDENTIFIER(__name__); - /* Forward declarations */ static PyObject *trace_call_function( PyThreadState *tstate, PyObject *callable, PyObject **stack, @@ -881,11 +879,7 @@ match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys) // - Atomically check for a key and get its value without error handling. // - Don't cause key creation or resizing in dict subclasses like // collections.defaultdict that define __missing__ (or similar). - _Py_IDENTIFIER(get); - get_name = _PyUnicode_FromId(&PyId_get); // borrowed - if (get_name == NULL) { - return NULL; - } + get_name = _Py_GET_GLOBAL_IDENTIFIER(get); int meth_found = _PyObject_GetMethod(map, get_name, &get); if (get == NULL) { goto fail; @@ -1736,9 +1730,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr SET_LOCALS_FROM_FRAME(); #ifdef LLTRACE - _Py_IDENTIFIER(__ltrace__); { - int r = _PyDict_ContainsId(GLOBALS(), &PyId___ltrace__); + PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__ltrace__); + int r = PyDict_Contains(GLOBALS(), key); if (r < 0) { goto exit_unwind; } @@ -2372,9 +2366,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } TARGET(PRINT_EXPR) { - _Py_IDENTIFIER(displayhook); PyObject *value = POP(); - PyObject *hook = _PySys_GetObjectId(&PyId_displayhook); + PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(displayhook); + PyObject *hook = _PySys_GetAttr(tstate, key); PyObject *res; if (hook == NULL) { _PyErr_SetString(tstate, PyExc_RuntimeError, @@ -2579,12 +2573,12 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr if (tstate->c_tracefunc == NULL) { gen_status = PyIter_Send(receiver, v, &retval); } else { - _Py_IDENTIFIER(send); if (Py_IsNone(v) && PyIter_Check(receiver)) { retval = Py_TYPE(receiver)->tp_iternext(receiver); } else { - retval = _PyObject_CallMethodIdOneArg(receiver, &PyId_send, v); + PyObject *name = _Py_GET_GLOBAL_IDENTIFIER(send); + retval = PyObject_CallMethodOneArg(receiver, name, v); } if (retval == NULL) { if (tstate->c_tracefunc != NULL @@ -2717,11 +2711,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } TARGET(LOAD_BUILD_CLASS) { - _Py_IDENTIFIER(__build_class__); - PyObject *bc; if (PyDict_CheckExact(BUILTINS())) { - bc = _PyDict_GetItemIdWithError(BUILTINS(), &PyId___build_class__); + PyObject *name = _Py_GET_GLOBAL_IDENTIFIER(__build_class__); + bc = _PyDict_GetItemWithError(BUILTINS(), name); if (bc == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_NameError, @@ -2732,9 +2725,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr Py_INCREF(bc); } else { - PyObject *build_class_str = _PyUnicode_FromId(&PyId___build_class__); - if (build_class_str == NULL) - goto error; + PyObject *build_class_str = _Py_GET_GLOBAL_IDENTIFIER(__build_class__); bc = PyObject_GetItem(BUILTINS(), build_class_str); if (bc == NULL) { if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) @@ -3288,7 +3279,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } TARGET(SETUP_ANNOTATIONS) { - _Py_IDENTIFIER(__annotations__); int err; PyObject *ann_dict; if (LOCALS() == NULL) { @@ -3298,8 +3288,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } /* check if __annotations__ in locals()... */ if (PyDict_CheckExact(LOCALS())) { - ann_dict = _PyDict_GetItemIdWithError(LOCALS(), - &PyId___annotations__); + PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); + ann_dict = _PyDict_GetItemWithError(LOCALS(), key); if (ann_dict == NULL) { if (_PyErr_Occurred(tstate)) { goto error; @@ -3309,8 +3299,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr if (ann_dict == NULL) { goto error; } - err = _PyDict_SetItemId(LOCALS(), - &PyId___annotations__, ann_dict); + err = PyDict_SetItem(LOCALS(), key, ann_dict); Py_DECREF(ann_dict); if (err != 0) { goto error; @@ -3319,10 +3308,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } else { /* do the same if locals() is not a dict */ - PyObject *ann_str = _PyUnicode_FromId(&PyId___annotations__); - if (ann_str == NULL) { - goto error; - } + PyObject *ann_str = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); ann_dict = PyObject_GetItem(LOCALS(), ann_str); if (ann_dict == NULL) { if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) { @@ -4235,11 +4221,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } TARGET(BEFORE_ASYNC_WITH) { - _Py_IDENTIFIER(__aenter__); - _Py_IDENTIFIER(__aexit__); PyObject *mgr = TOP(); PyObject *res; - PyObject *enter = _PyObject_LookupSpecialId(mgr, &PyId___aenter__); + PyObject *str_aenter = _Py_GET_GLOBAL_IDENTIFIER(__aenter__); + PyObject *enter = _PyObject_LookupSpecial(mgr, str_aenter); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4249,7 +4234,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *exit = _PyObject_LookupSpecialId(mgr, &PyId___aexit__); + PyObject *str_aexit = _Py_GET_GLOBAL_IDENTIFIER(__aexit__); + PyObject *exit = _PyObject_LookupSpecial(mgr, str_aexit); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4273,11 +4259,10 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } TARGET(BEFORE_WITH) { - _Py_IDENTIFIER(__enter__); - _Py_IDENTIFIER(__exit__); PyObject *mgr = TOP(); PyObject *res; - PyObject *enter = _PyObject_LookupSpecialId(mgr, &PyId___enter__); + PyObject *str_enter = _Py_GET_GLOBAL_IDENTIFIER(__enter__); + PyObject *enter = _PyObject_LookupSpecial(mgr, str_enter); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4287,7 +4272,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *exit = _PyObject_LookupSpecialId(mgr, &PyId___exit__); + PyObject *str_exit = _Py_GET_GLOBAL_IDENTIFIER(__exit__); + PyObject *exit = _PyObject_LookupSpecial(mgr, str_exit); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -7077,11 +7063,11 @@ static PyObject * import_name(PyThreadState *tstate, InterpreterFrame *frame, PyObject *name, PyObject *fromlist, PyObject *level) { - _Py_IDENTIFIER(__import__); PyObject *import_func, *res; PyObject* stack[5]; - import_func = _PyDict_GetItemIdWithError(frame->f_builtins, &PyId___import__); + PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__import__); + import_func = _PyDict_GetItemWithError(frame->f_builtins, key); if (import_func == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found"); @@ -7128,7 +7114,8 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name) /* Issue #17636: in case this failed because of a circular relative import, try to fallback on reading the module directly from sys.modules. */ - pkgname = _PyObject_GetAttrId(v, &PyId___name__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + pkgname = PyObject_GetAttr(v, attr); if (pkgname == NULL) { goto error; } @@ -7170,8 +7157,8 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name) PyErr_SetImportError(errmsg, pkgname, NULL); } else { - _Py_IDENTIFIER(__spec__); - PyObject *spec = _PyObject_GetAttrId(v, &PyId___spec__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + PyObject *spec = PyObject_GetAttr(v, attr); const char *fmt = _PyModuleSpec_IsInitializing(spec) ? "cannot import name %R from partially initialized module %R " @@ -7193,17 +7180,17 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name) static int import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v) { - _Py_IDENTIFIER(__all__); - _Py_IDENTIFIER(__dict__); PyObject *all, *dict, *name, *value; int skip_leading_underscores = 0; int pos, err; - if (_PyObject_LookupAttrId(v, &PyId___all__, &all) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__all__); + if (_PyObject_LookupAttr(v, attr, &all) < 0) { return -1; /* Unexpected error */ } if (all == NULL) { - if (_PyObject_LookupAttrId(v, &PyId___dict__, &dict) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + if (_PyObject_LookupAttr(v, attr, &dict) < 0) { return -1; } if (dict == NULL) { @@ -7230,7 +7217,8 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v) break; } if (!PyUnicode_Check(name)) { - PyObject *modname = _PyObject_GetAttrId(v, &PyId___name__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *modname = PyObject_GetAttr(v, attr); if (modname == NULL) { Py_DECREF(name); err = -1; @@ -7430,14 +7418,14 @@ format_exc_check_arg(PyThreadState *tstate, PyObject *exc, if (exc == PyExc_NameError) { // Include the name in the NameError exceptions to offer suggestions later. - _Py_IDENTIFIER(name); PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); PyErr_NormalizeException(&type, &value, &traceback); if (PyErr_GivenExceptionMatches(value, PyExc_NameError)) { // We do not care if this fails because we are going to restore the // NameError anyway. - (void)_PyObject_SetAttrId(value, &PyId_name, obj); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + (void)PyObject_SetAttr(value, attr, obj); } PyErr_Restore(type, value, traceback); } From 5713dab10e3a1a6d6037fc77d25f6ff820de9e0a Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 19 Jan 2022 13:59:06 -0700 Subject: [PATCH 016/115] Add a TODO. --- Include/internal/pycore_global_strings.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 5c22043a93740b6..bd93bb4864c085e 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -21,6 +21,8 @@ extern "C" { #define ID(NAME) \ STR(NAME, #NAME) +// XXX Order by frequency of use? + struct _Py_global_strings { struct { STR(empty, "") From 77a21d66d840bff65adfa679c2fae37ff4892f8b Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 19 Jan 2022 15:03:14 -0700 Subject: [PATCH 017/115] Get rid of _Py_IDENTIFIER() in specialize.c. --- Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init.h | 1 + Python/specialize.c | 22 ++++++++-------------- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index bd93bb4864c085e..88a0972e6e20b49 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -464,6 +464,7 @@ struct _Py_global_strings { ID(_strptime_time) ID(_warn_unawaited_coroutine) ID(_xoptions) + ID(append) ID(big) ID(buffer) ID(builtins) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index a91bc8360bf5fdb..fe0fd9be9dac683 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -1084,6 +1084,7 @@ extern "C" { INIT_ID(_strptime_time), \ INIT_ID(_warn_unawaited_coroutine), \ INIT_ID(_xoptions), \ + INIT_ID(append), \ INIT_ID(big), \ INIT_ID(buffer), \ INIT_ID(builtins), \ diff --git a/Python/specialize.c b/Python/specialize.c index aec94d9e60be413..183ef4ec807f626 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1,6 +1,7 @@ #include "Python.h" #include "pycore_code.h" #include "pycore_dict.h" +#include "pycore_global_strings.h" // _Py_GET_GLOBAL_IDENTIFIER() #include "pycore_long.h" #include "pycore_moduleobject.h" #include "pycore_object.h" @@ -542,8 +543,6 @@ specialize_module_load_attr( { PyModuleObject *m = (PyModuleObject *)owner; PyObject *value = NULL; - PyObject *getattr; - _Py_IDENTIFIER(__getattr__); assert((owner->ob_type->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0); PyDictObject *dict = (PyDictObject *)m->md_dict; if (dict == NULL) { @@ -554,12 +553,7 @@ specialize_module_load_attr( SPECIALIZATION_FAIL(opcode, SPEC_FAIL_NON_STRING_OR_SPLIT); return -1; } - getattr = _PyUnicode_FromId(&PyId___getattr__); /* borrowed */ - if (getattr == NULL) { - SPECIALIZATION_FAIL(opcode, SPEC_FAIL_OVERRIDDEN); - PyErr_Clear(); - return -1; - } + PyObject *getattr = _Py_GET_GLOBAL_IDENTIFIER(__getattr__); Py_ssize_t index = _PyDict_GetItemHint(dict, getattr, -1, &value); assert(index != DKIX_ERROR); if (index != DKIX_EMPTY) { @@ -1159,7 +1153,6 @@ binary_subscr_fail_kind(PyTypeObject *container_type, PyObject *sub) } #endif -_Py_IDENTIFIER(__getitem__); #define SIMPLE_FUNCTION 0 @@ -1204,7 +1197,8 @@ _Py_Specialize_BinarySubscr( goto success; } PyTypeObject *cls = Py_TYPE(container); - PyObject *descriptor = _PyType_LookupId(cls, &PyId___getitem__); + PyObject *getitem = _Py_GET_GLOBAL_IDENTIFIER(__getitem__); + PyObject *descriptor = _PyType_Lookup(cls, getitem); if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) { PyFunctionObject *func = (PyFunctionObject *)descriptor; PyCodeObject *code = (PyCodeObject *)func->func_code; @@ -1321,8 +1315,8 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins } goto fail; } - _Py_IDENTIFIER(__setitem__); - PyObject *descriptor = _PyType_LookupId(container_type, &PyId___setitem__); + PyObject *setitem = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + PyObject *descriptor = _PyType_Lookup(container_type, setitem); if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) { PyFunctionObject *func = (PyFunctionObject *)descriptor; PyCodeObject *code = (PyCodeObject *)func->func_code; @@ -1410,7 +1404,6 @@ builtin_call_fail_kind(int ml_flags) #endif static PyMethodDescrObject *_list_append = NULL; -_Py_IDENTIFIER(append); static int specialize_method_descriptor( @@ -1422,7 +1415,8 @@ specialize_method_descriptor( return -1; } if (_list_append == NULL) { - _list_append = (PyMethodDescrObject *)_PyType_LookupId(&PyList_Type, &PyId_append); + PyObject *append = _Py_GET_GLOBAL_IDENTIFIER(append); + _list_append = (PyMethodDescrObject *)_PyType_Lookup(&PyList_Type, append); } assert(_list_append != NULL); if (nargs == 2 && descr == _list_append) { From 704d440921aaa6d988e9d724b81a73473d035c6f Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 19 Jan 2022 16:00:31 -0700 Subject: [PATCH 018/115] Get rid of _Py_IDENTIFIER() in traceback.c. --- Python/traceback.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/Python/traceback.c b/Python/traceback.c index 4d6cbaae8da6cd7..d4883f221eeadeb 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -6,6 +6,7 @@ #include "code.h" // PyCode_Addr2Line etc #include "frameobject.h" // PyFrame_GetBack() #include "pycore_ast.h" // asdl_seq_* +#include "pycore_call.h" // _PyObject_CallMethod() #include "pycore_compile.h" // _PyAST_Optimize #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH #include "pycore_frame.h" // _PyFrame_GetCode() @@ -32,11 +33,6 @@ /* Function from Parser/tokenizer.c */ extern char* _PyTokenizer_FindEncodingFilename(int, PyObject *); -_Py_IDENTIFIER(TextIOWrapper); -_Py_IDENTIFIER(close); -_Py_IDENTIFIER(open); -_Py_IDENTIFIER(path); - /*[clinic input] class TracebackType "PyTracebackObject *" "&PyTraceback_Type" [clinic start generated code]*/ @@ -317,6 +313,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * const char* filepath; Py_ssize_t len; PyObject* result; + PyObject *open = NULL; filebytes = PyUnicode_EncodeFSDefault(filename); if (filebytes == NULL) { @@ -333,11 +330,14 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * tail++; taillen = strlen(tail); - syspath = _PySys_GetObjectId(&PyId_path); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(path); + syspath = _PySys_GetAttr(tstate, attr); if (syspath == NULL || !PyList_Check(syspath)) goto error; npath = PyList_Size(syspath); + open = PyObject_GetAttr(io, _Py_GET_GLOBAL_IDENTIFIER(open)); for (i = 0; i < npath; i++) { v = PyList_GetItem(syspath, i); if (v == NULL) { @@ -364,7 +364,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * namebuf[len++] = SEP; strcpy(namebuf+len, tail); - binary = _PyObject_CallMethodId(io, &PyId_open, "ss", namebuf, "rb"); + binary = _PyObject_CallMethod(tstate, open, "ss", namebuf, "rb"); if (binary != NULL) { result = binary; goto finally; @@ -376,6 +376,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * error: result = NULL; finally: + Py_XDECREF(open); Py_DECREF(filebytes); return result; } @@ -448,10 +449,15 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int } io = PyImport_ImportModule("io"); - if (io == NULL) + if (io == NULL) { return -1; - binary = _PyObject_CallMethodId(io, &PyId_open, "Os", filename, "rb"); + } + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); + PyObject *open = PyObject_GetAttr(io, attr); + binary = _PyObject_CallMethod(tstate, open, "Os", filename, "rb"); + Py_DECREF(open); if (binary == NULL) { PyErr_Clear(); @@ -480,14 +486,18 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int PyMem_Free(found_encoding); return 0; } - fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding); + attr = _Py_GET_GLOBAL_IDENTIFIER(TextIOWrapper); + PyObject *TextIOWrapper = PyObject_GetAttr(io, attr); Py_DECREF(io); + fob = _PyObject_CallMethod(tstate, TextIOWrapper, "Os", binary, encoding); + Py_DECREF(TextIOWrapper); PyMem_Free(found_encoding); + PyObject *close = _Py_GET_GLOBAL_IDENTIFIER(close); if (fob == NULL) { PyErr_Clear(); - res = _PyObject_CallMethodIdNoArgs(binary, &PyId_close); + res = PyObject_CallMethodNoArgs(binary, close); Py_DECREF(binary); if (res) Py_DECREF(res); @@ -506,7 +516,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int break; } } - res = _PyObject_CallMethodIdNoArgs(fob, &PyId_close); + res = PyObject_CallMethodNoArgs(fob, close); if (res) { Py_DECREF(res); } From 2800db6f6b4148d1a619c3a08037e369701fb4f7 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 20 Jan 2022 15:06:45 -0700 Subject: [PATCH 019/115] Get rid of _Py_IDENTIFIER() in codecs.c. --- Python/codecs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/codecs.c b/Python/codecs.c index 343b6e2d03396e7..cd817e81d0348ae 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -522,7 +522,6 @@ PyObject *PyCodec_Decode(PyObject *object, PyObject * _PyCodec_LookupTextEncoding(const char *encoding, const char *alternate_command) { - _Py_IDENTIFIER(_is_text_encoding); PyObject *codec; PyObject *attr; int is_text_codec; @@ -536,7 +535,8 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding, * attribute. */ if (!PyTuple_CheckExact(codec)) { - if (_PyObject_LookupAttrId(codec, &PyId__is_text_encoding, &attr) < 0) { + PyObject *is_text_encoding = _Py_GET_GLOBAL_IDENTIFIER(_is_text_encoding); + if (_PyObject_LookupAttr(codec, is_text_encoding, &attr) < 0) { Py_DECREF(codec); return NULL; } From db7242927929cf6e41d69eb2b3b8e14a0fa0e1af Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 14:21:28 -0700 Subject: [PATCH 020/115] Get rid of _Py_IDENTIFIER() in compile.c. --- Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init.h | 1 + Python/compile.c | 71 ++++-------------------- 3 files changed, 13 insertions(+), 60 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 88a0972e6e20b49..9f32a0cc7728932 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -40,6 +40,7 @@ struct _Py_global_strings { STR(anon_genexpr, "") STR(anon_lambda, "") STR(anon_listcomp, "") + STR(anon_module, "") STR(anon_setcomp, "") STR(anon_string, "") STR(dot_locals, ".") diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index fe0fd9be9dac683..427ab8497a64454 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -662,6 +662,7 @@ extern "C" { INIT_STR(anon_genexpr, ""), \ INIT_STR(anon_lambda, ""), \ INIT_STR(anon_listcomp, ""), \ + INIT_STR(anon_module, ""), \ INIT_STR(anon_setcomp, ""), \ INIT_STR(anon_string, ""), \ INIT_STR(dot_locals, "."), \ diff --git a/Python/compile.c b/Python/compile.c index eda708e21f16ab4..49e38ca56a3f48a 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1616,16 +1616,11 @@ compiler_enter_scope(struct compiler *c, identifier name, } if (u->u_ste->ste_needs_class_closure) { /* Cook up an implicit __class__ cell. */ - _Py_IDENTIFIER(__class__); PyObject *name; int res; assert(u->u_scope_type == COMPILER_SCOPE_CLASS); assert(PyDict_GET_SIZE(u->u_cellvars) == 0); - name = _PyUnicode_FromId(&PyId___class__); - if (!name) { - compiler_unit_free(u); - return 0; - } + name = _Py_GET_GLOBAL_IDENTIFIER(__class__); res = PyDict_SetItem(u->u_cellvars, name, _PyLong_GetZero()); if (res < 0) { compiler_unit_free(u); @@ -2011,11 +2006,7 @@ compiler_body(struct compiler *c, asdl_stmt_seq *stmts) int i = 0; stmt_ty st; PyObject *docstring; - _Py_IDENTIFIER(__doc__); - PyObject *__doc__ = _PyUnicode_FromId(&PyId___doc__); /* borrowed ref*/ - if (__doc__ == NULL) { - return 0; - } + PyObject *__doc__ = _Py_GET_GLOBAL_IDENTIFIER(__doc__); /* Set current line number to the line number of first statement. This way line number for SETUP_ANNOTATIONS will always @@ -2054,11 +2045,7 @@ compiler_mod(struct compiler *c, mod_ty mod) { PyCodeObject *co; int addNone = 1; - _Py_static_string(PyId__module, ""); - PyObject *module = _PyUnicode_FromId(&PyId__module); /* borrowed ref */ - if (module == NULL) { - return 0; - } + PyObject *module = _Py_GET_GLOBAL_STRING(anon_module); if (!compiler_enter_scope(c, module, COMPILER_SCOPE_MODULE, mod, 1)) { return NULL; } @@ -2337,7 +2324,6 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args, Return 0 on error, -1 if no annotations pushed, 1 if a annotations is pushed. */ - _Py_IDENTIFIER(return); Py_ssize_t annotations_len = 0; if (!compiler_visit_argannotations(c, args->args, &annotations_len)) @@ -2355,10 +2341,7 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args, args->kwarg->annotation, &annotations_len)) return 0; - identifier return_str = _PyUnicode_FromId(&PyId_return); /* borrowed ref */ - if (return_str == NULL) { - return 0; - } + identifier return_str = _Py_GET_GLOBAL_IDENTIFIER(return); if (!compiler_visit_argannotation(c, return_str, returns, &annotations_len)) { return 0; } @@ -2904,7 +2887,6 @@ compiler_lambda(struct compiler *c, expr_ty e) { PyCodeObject *co; PyObject *qualname; - identifier name; Py_ssize_t funcflags; arguments_ty args = e->v.Lambda.args; assert(e->kind == Lambda_kind); @@ -2912,17 +2894,12 @@ compiler_lambda(struct compiler *c, expr_ty e) if (!compiler_check_debug_args(c, args)) return 0; - _Py_static_string(PyId_lambda, ""); - name = _PyUnicode_FromId(&PyId_lambda); /* borrowed ref */ - if (name == NULL) { - return 0; - } - funcflags = compiler_default_arguments(c, args); if (funcflags == -1) { return 0; } + identifier name = _Py_GET_GLOBAL_STRING(anon_lambda); if (!compiler_enter_scope(c, name, COMPILER_SCOPE_LAMBDA, (void *)e, e->lineno)) { return 0; @@ -3822,12 +3799,7 @@ compiler_from_import(struct compiler *c, stmt_ty s) { Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names); PyObject *names; - _Py_static_string(PyId_empty_string, ""); - PyObject *empty_string = _PyUnicode_FromId(&PyId_empty_string); /* borrowed ref */ - - if (empty_string == NULL) { - return 0; - } + PyObject *empty_string = _Py_GET_GLOBAL_STRING(empty); ADDOP_LOAD_CONST_NEW(c, PyLong_FromLong(s->v.ImportFrom.level)); @@ -5402,11 +5374,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type, static int compiler_genexp(struct compiler *c, expr_ty e) { - _Py_static_string(PyId_genexpr, ""); - identifier name = _PyUnicode_FromId(&PyId_genexpr); /* borrowed ref */ - if (name == NULL) { - return 0; - } + identifier name = _Py_GET_GLOBAL_STRING(anon_genexpr); assert(e->kind == GeneratorExp_kind); return compiler_comprehension(c, e, COMP_GENEXP, name, e->v.GeneratorExp.generators, @@ -5416,11 +5384,7 @@ compiler_genexp(struct compiler *c, expr_ty e) static int compiler_listcomp(struct compiler *c, expr_ty e) { - _Py_static_string(PyId_listcomp, ""); - identifier name = _PyUnicode_FromId(&PyId_listcomp); /* borrowed ref */ - if (name == NULL) { - return 0; - } + identifier name = _Py_GET_GLOBAL_STRING(anon_listcomp); assert(e->kind == ListComp_kind); return compiler_comprehension(c, e, COMP_LISTCOMP, name, e->v.ListComp.generators, @@ -5430,11 +5394,7 @@ compiler_listcomp(struct compiler *c, expr_ty e) static int compiler_setcomp(struct compiler *c, expr_ty e) { - _Py_static_string(PyId_setcomp, ""); - identifier name = _PyUnicode_FromId(&PyId_setcomp); /* borrowed ref */ - if (name == NULL) { - return 0; - } + identifier name = _Py_GET_GLOBAL_STRING(anon_setcomp); assert(e->kind == SetComp_kind); return compiler_comprehension(c, e, COMP_SETCOMP, name, e->v.SetComp.generators, @@ -5445,11 +5405,7 @@ compiler_setcomp(struct compiler *c, expr_ty e) static int compiler_dictcomp(struct compiler *c, expr_ty e) { - _Py_static_string(PyId_dictcomp, ""); - identifier name = _PyUnicode_FromId(&PyId_dictcomp); /* borrowed ref */ - if (name == NULL) { - return 0; - } + identifier name = _Py_GET_GLOBAL_STRING(anon_dictcomp); assert(e->kind == DictComp_kind); return compiler_comprehension(c, e, COMP_DICTCOMP, name, e->v.DictComp.generators, @@ -5973,12 +5929,7 @@ compiler_annassign(struct compiler *c, stmt_ty s) { expr_ty targ = s->v.AnnAssign.target; PyObject* mangled; - _Py_IDENTIFIER(__annotations__); - /* borrowed ref*/ - PyObject *__annotations__ = _PyUnicode_FromId(&PyId___annotations__); - if (__annotations__ == NULL) { - return 0; - } + PyObject *__annotations__ = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); assert(s->kind == AnnAssign_kind); From 737391f307f31022feac2e372de1ae32524903b3 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 14:34:03 -0700 Subject: [PATCH 021/115] Get rid of _Py_IDENTIFIER() in importdl.c. --- Python/importdl.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Python/importdl.c b/Python/importdl.c index 6d2554741f98220..97ddb4029decfc7 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -2,6 +2,9 @@ /* Support for dynamic loading of extension modules */ #include "Python.h" +#include "pycore_call.h" +#include "pycore_pystate.h" +#include "pycore_runtime.h" /* ./configure sets HAVE_DYNAMIC_LOADING if dynamic loading of modules is supported on this platform. configure will then compile and link in one @@ -38,7 +41,6 @@ get_encoded_name(PyObject *name, const char **hook_prefix) { PyObject *encoded = NULL; PyObject *modname = NULL; Py_ssize_t name_len, lastdot; - _Py_IDENTIFIER(replace); /* Get the short name (substring after last dot) */ name_len = PyUnicode_GetLength(name); @@ -76,7 +78,14 @@ get_encoded_name(PyObject *name, const char **hook_prefix) { } /* Replace '-' by '_' */ - modname = _PyObject_CallMethodId(encoded, &PyId_replace, "cc", '-', '_'); + PyObject *replace = _Py_GET_GLOBAL_IDENTIFIER(replace); + PyObject *method = PyObject_GetAttr(encoded, replace); + if (method == NULL) { + goto error; + } + PyThreadState *tstate = _PyThreadState_GET(); + modname = _PyObject_CallMethod(tstate, method, "cc", '-', '_'); + Py_DECREF(method); if (modname == NULL) goto error; From 9e3ff70d0bef843374692e39917e5fc7fe442472 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 14:41:26 -0700 Subject: [PATCH 022/115] Get rid of _Py_IDENTIFIER() in marshal.c. --- Python/marshal.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Python/marshal.c b/Python/marshal.c index 51c77555d9ea970..7bae27e0e658d7e 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -703,7 +703,6 @@ r_string(Py_ssize_t n, RFILE *p) read = fread(p->buf, 1, n, p->fp); } else { - _Py_IDENTIFIER(readinto); PyObject *res, *mview; Py_buffer buf; @@ -713,7 +712,14 @@ r_string(Py_ssize_t n, RFILE *p) if (mview == NULL) return NULL; - res = _PyObject_CallMethodId(p->readable, &PyId_readinto, "N", mview); + PyObject *readinto = _Py_GET_GLOBAL_IDENTIFIER(readinto); + PyObject *method = PyObject_GetAttr(p->readable, readinto); + if (method == NULL) { + return NULL; + } + PyThreadState *tstate = _PyThreadState_GET(); + res = _PyObject_CallMethod(tstate, method, "N", mview); + Py_DECREF(method); if (res != NULL) { read = PyNumber_AsSsize_t(res, PyExc_ValueError); Py_DECREF(res); @@ -1713,12 +1719,12 @@ marshal_dump_impl(PyObject *module, PyObject *value, PyObject *file, /* XXX Quick hack -- need to do this differently */ PyObject *s; PyObject *res; - _Py_IDENTIFIER(write); s = PyMarshal_WriteObjectToString(value, version); if (s == NULL) return NULL; - res = _PyObject_CallMethodIdOneArg(file, &PyId_write, s); + PyObject *write = _Py_GET_GLOBAL_IDENTIFIER(write); + res = _PyObject_CallMethodOneArg(file, write, s); Py_DECREF(s); return res; } @@ -1745,7 +1751,6 @@ marshal_load(PyObject *module, PyObject *file) /*[clinic end generated code: output=f8e5c33233566344 input=c85c2b594cd8124a]*/ { PyObject *data, *result; - _Py_IDENTIFIER(read); RFILE rf; /* @@ -1755,7 +1760,14 @@ marshal_load(PyObject *module, PyObject *file) * This can be removed if we guarantee good error handling * for r_string() */ - data = _PyObject_CallMethodId(file, &PyId_read, "i", 0); + PyObject *read = _Py_GET_GLOBAL_IDENTIFIER(read); + PyObject *method = PyObject_GetAttr(file, read); + if (method == NULL) { + return NULL; + } + PyThreadState *tstate = _PyThreadState_GET(); + data = _PyObject_CallMethod(tstate, method, "i", 0); + Py_DECREF(method); if (data == NULL) return NULL; if (!PyBytes_Check(data)) { From 71fc362f6f9f42ea3822e546962edad66485f1fe Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 15:05:19 -0700 Subject: [PATCH 023/115] Get rid of _Py_IDENTIFIER() in errors.c. --- Include/internal/pycore_global_strings.h | 2 + Include/internal/pycore_runtime_init.h | 2 + Python/errors.c | 70 ++++++++++++------------ 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 9f32a0cc7728932..9082963a098086f 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -487,6 +487,8 @@ struct _Py_global_strings { ID(enable) ID(encode) ID(encoding) + ID(end_lineno) + ID(end_offset) ID(errors) ID(excepthook) ID(exception) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 427ab8497a64454..e194da84891fa7f 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -1107,6 +1107,8 @@ extern "C" { 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), \ diff --git a/Python/errors.c b/Python/errors.c index 023234974c47d4d..2669d2eaaa12507 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -28,12 +28,6 @@ extern char *strerror(int); extern "C" { #endif -_Py_IDENTIFIER(__main__); -_Py_IDENTIFIER(__module__); -_Py_IDENTIFIER(builtins); -_Py_IDENTIFIER(stderr); -_Py_IDENTIFIER(flush); - /* Forward declarations */ static PyObject * _PyErr_FormatV(PyThreadState *tstate, PyObject *exception, @@ -1135,7 +1129,8 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) goto failure; } - int r = _PyDict_ContainsId(dict, &PyId___module__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + int r = PyDict_Contains(dict, attr); if (r < 0) { goto failure; } @@ -1144,7 +1139,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) (Py_ssize_t)(dot-name)); if (modulename == NULL) goto failure; - if (_PyDict_SetItemId(dict, &PyId___module__, modulename) != 0) + if (PyDict_SetItem(dict, attr, modulename) != 0) goto failure; } if (PyTuple_Check(base)) { @@ -1347,7 +1342,8 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, assert(PyExceptionClass_Check(exc_type)); - PyObject *modulename = _PyObject_GetAttrId(exc_type, &PyId___module__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + PyObject *modulename = PyObject_GetAttr(exc_type, attr); if (modulename == NULL || !PyUnicode_Check(modulename)) { Py_XDECREF(modulename); _PyErr_Clear(tstate); @@ -1356,8 +1352,10 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, } } else { - if (!_PyUnicode_EqualToASCIIId(modulename, &PyId_builtins) && - !_PyUnicode_EqualToASCIIId(modulename, &PyId___main__)) { + PyObject *builtins = _Py_GET_GLOBAL_IDENTIFIER(builtins); + PyObject *__main__ = _Py_GET_GLOBAL_IDENTIFIER(__main__); + if (!_PyUnicode_Equal(modulename, builtins) && + !_PyUnicode_Equal(modulename, __main__)) { if (PyFile_WriteObject(modulename, file, Py_PRINT_RAW) < 0) { Py_DECREF(modulename); return -1; @@ -1405,7 +1403,8 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, } /* Explicitly call file.flush() */ - PyObject *res = _PyObject_CallMethodIdNoArgs(file, &PyId_flush); + PyObject *flush = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *res = _PyObject_CallMethodNoArgs(file, flush); if (!res) { return -1; } @@ -1420,7 +1419,8 @@ write_unraisable_exc(PyThreadState *tstate, PyObject *exc_type, PyObject *exc_value, PyObject *exc_tb, PyObject *err_msg, PyObject *obj) { - PyObject *file = _PySys_GetObjectId(&PyId_stderr); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *file = _PySys_GetAttr(tstate, attr); if (file == NULL || file == Py_None) { return 0; } @@ -1524,8 +1524,8 @@ _PyErr_WriteUnraisableMsg(const char *err_msg_str, PyObject *obj) goto error; } - _Py_IDENTIFIER(unraisablehook); - PyObject *hook = _PySys_GetObjectId(&PyId_unraisablehook); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(unraisablehook); + PyObject *hook = _PySys_GetAttr(tstate, attr); if (hook == NULL) { Py_DECREF(hook_args); goto default_hook; @@ -1599,15 +1599,7 @@ static void PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, int end_lineno, int end_col_offset) { - PyObject *exc, *v, *tb, *tmp; - _Py_IDENTIFIER(filename); - _Py_IDENTIFIER(lineno); - _Py_IDENTIFIER(end_lineno); - _Py_IDENTIFIER(msg); - _Py_IDENTIFIER(offset); - _Py_IDENTIFIER(end_offset); - _Py_IDENTIFIER(print_file_and_line); - _Py_IDENTIFIER(text); + PyObject *exc, *v, *tb, *tmp, *attr; PyThreadState *tstate = _PyThreadState_GET(); /* add attributes for the line number and filename for the error */ @@ -1619,7 +1611,8 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, if (tmp == NULL) _PyErr_Clear(tstate); else { - if (_PyObject_SetAttrId(v, &PyId_lineno, tmp)) { + attr = _Py_GET_GLOBAL_IDENTIFIER(lineno); + if (PyObject_SetAttr(v, attr, tmp)) { _PyErr_Clear(tstate); } Py_DECREF(tmp); @@ -1631,7 +1624,8 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - if (_PyObject_SetAttrId(v, &PyId_offset, tmp ? tmp : Py_None)) { + attr = _Py_GET_GLOBAL_IDENTIFIER(offset); + if (PyObject_SetAttr(v, attr, tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } Py_XDECREF(tmp); @@ -1643,7 +1637,8 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - if (_PyObject_SetAttrId(v, &PyId_end_lineno, tmp ? tmp : Py_None)) { + attr = _Py_GET_GLOBAL_IDENTIFIER(end_lineno); + if (PyObject_SetAttr(v, attr, tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } Py_XDECREF(tmp); @@ -1655,20 +1650,23 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - if (_PyObject_SetAttrId(v, &PyId_end_offset, tmp ? tmp : Py_None)) { + attr = _Py_GET_GLOBAL_IDENTIFIER(end_offset); + if (PyObject_SetAttr(v, attr, tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } Py_XDECREF(tmp); tmp = NULL; if (filename != NULL) { - if (_PyObject_SetAttrId(v, &PyId_filename, filename)) { + attr = _Py_GET_GLOBAL_IDENTIFIER(filename); + if (PyObject_SetAttr(v, attr, filename)) { _PyErr_Clear(tstate); } tmp = PyErr_ProgramTextObject(filename, lineno); if (tmp) { - if (_PyObject_SetAttrId(v, &PyId_text, tmp)) { + attr = _Py_GET_GLOBAL_IDENTIFIER(text); + if (PyObject_SetAttr(v, attr, tmp)) { _PyErr_Clear(tstate); } Py_DECREF(tmp); @@ -1678,7 +1676,8 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, } } if (exc != PyExc_SyntaxError) { - if (_PyObject_LookupAttrId(v, &PyId_msg, &tmp) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(msg); + if (_PyObject_LookupAttr(v, attr, &tmp) < 0) { _PyErr_Clear(tstate); } else if (tmp) { @@ -1687,7 +1686,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, else { tmp = PyObject_Str(v); if (tmp) { - if (_PyObject_SetAttrId(v, &PyId_msg, tmp)) { + if (PyObject_SetAttr(v, attr, tmp)) { _PyErr_Clear(tstate); } Py_DECREF(tmp); @@ -1696,15 +1695,16 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - if (_PyObject_LookupAttrId(v, &PyId_print_file_and_line, &tmp) < 0) { + + attr = _Py_GET_GLOBAL_IDENTIFIER(print_file_and_line); + if (_PyObject_LookupAttr(v, attr, &tmp) < 0) { _PyErr_Clear(tstate); } else if (tmp) { Py_DECREF(tmp); } else { - if (_PyObject_SetAttrId(v, &PyId_print_file_and_line, - Py_None)) { + if (PyObject_SetAttr(v, attr, Py_None)) { _PyErr_Clear(tstate); } } From 2046b53845bd23918c4f096b8332d527426742b0 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 15:24:00 -0700 Subject: [PATCH 024/115] Get rid of _Py_IDENTIFIER() in import.c. --- Python/import.c | 101 +++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 58 deletions(-) diff --git a/Python/import.c b/Python/import.c index 51b779ca17c5265..af9b135cb21051b 100644 --- a/Python/import.c +++ b/Python/import.c @@ -38,9 +38,6 @@ extern struct _inittab _PyImport_Inittab[]; struct _inittab *PyImport_Inittab = _PyImport_Inittab; static struct _inittab *inittab_copy = NULL; -_Py_IDENTIFIER(__path__); -_Py_IDENTIFIER(__spec__); - /*[clinic input] module _imp [clinic start generated code]*/ @@ -76,9 +73,8 @@ _PyImportZip_Init(PyThreadState *tstate) } } else { - _Py_IDENTIFIER(zipimporter); - PyObject *zipimporter = _PyObject_GetAttrId(zipimport, - &PyId_zipimporter); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(zipimporter); + PyObject *zipimporter = PyObject_GetAttr(zipimport, attr); Py_DECREF(zipimport); if (zipimporter == NULL) { _PyErr_Clear(tstate); /* No zipimporter object -- okay */ @@ -345,22 +341,22 @@ import_get_module(PyThreadState *tstate, PyObject *name) static int import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *name) { - PyObject *spec; - - _Py_IDENTIFIER(_lock_unlock_module); + PyObject *spec, *attr; /* Optimization: only call _bootstrap._lock_unlock_module() if __spec__._initializing is true. NOTE: because of this, initializing must be set *before* stuffing the new module in sys.modules. */ - spec = _PyObject_GetAttrId(mod, &PyId___spec__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + spec = PyObject_GetAttr(mod, attr); int busy = _PyModuleSpec_IsInitializing(spec); Py_XDECREF(spec); if (busy) { + attr = _Py_GET_GLOBAL_IDENTIFIER(_lock_unlock_module); /* Wait until module is done importing. */ - PyObject *value = _PyObject_CallMethodIdOneArg( - interp->importlib, &PyId__lock_unlock_module, name); + PyObject *value = _PyObject_CallMethodOneArg( + interp->importlib, attr, name); if (value == NULL) { return -1; } @@ -712,7 +708,6 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, } else if (cpathobj != NULL) { PyInterpreterState *interp = _PyInterpreterState_GET(); - _Py_IDENTIFIER(_get_sourcefile); if (interp == NULL) { Py_FatalError("no current interpreter"); @@ -721,8 +716,8 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, external= PyObject_GetAttrString(interp->importlib, "_bootstrap_external"); if (external != NULL) { - pathobj = _PyObject_CallMethodIdOneArg( - external, &PyId__get_sourcefile, cpathobj); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_get_sourcefile); + pathobj = _PyObject_CallMethodOneArg(external, attr, cpathobj); Py_DECREF(external); } if (pathobj == NULL) @@ -742,7 +737,6 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, static PyObject * module_dict_for_exec(PyThreadState *tstate, PyObject *name) { - _Py_IDENTIFIER(__builtins__); PyObject *m, *d; m = import_add_module(tstate, name); @@ -751,10 +745,10 @@ module_dict_for_exec(PyThreadState *tstate, PyObject *name) /* If the module is being reloaded, we get the old module back and re-use its dict to exec the new code. */ d = PyModule_GetDict(m); - int r = _PyDict_ContainsId(d, &PyId___builtins__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); + int r = PyDict_Contains(d, attr); if (r == 0) { - r = _PyDict_SetItemId(d, &PyId___builtins__, - PyEval_GetBuiltins()); + r = PyDict_SetItem(d, attr, PyEval_GetBuiltins()); } if (r < 0) { remove_module(tstate, name); @@ -796,7 +790,6 @@ PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname, { PyThreadState *tstate = _PyThreadState_GET(); PyObject *d, *external, *res; - _Py_IDENTIFIER(_fix_up_module); d = module_dict_for_exec(tstate, name); if (d == NULL) { @@ -812,9 +805,9 @@ PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname, Py_DECREF(d); return NULL; } - res = _PyObject_CallMethodIdObjArgs(external, - &PyId__fix_up_module, - d, name, pathname, cpathname, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_fix_up_module); + res = PyObject_CallMethodObjArgs(external, attr, + d, name, pathname, cpathname, NULL); Py_DECREF(external); if (res != NULL) { Py_DECREF(res); @@ -1536,10 +1529,7 @@ remove_importlib_frames(PyThreadState *tstate) static PyObject * resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level) { - _Py_IDENTIFIER(__package__); - _Py_IDENTIFIER(__name__); - _Py_IDENTIFIER(parent); - PyObject *abs_name; + PyObject *abs_name, *attr; PyObject *package = NULL; PyObject *spec; Py_ssize_t last_dot; @@ -1554,14 +1544,16 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level _PyErr_SetString(tstate, PyExc_TypeError, "globals must be a dict"); goto error; } - package = _PyDict_GetItemIdWithError(globals, &PyId___package__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__package__); + package = PyDict_GetItemWithError(globals, attr); if (package == Py_None) { package = NULL; } else if (package == NULL && _PyErr_Occurred(tstate)) { goto error; } - spec = _PyDict_GetItemIdWithError(globals, &PyId___spec__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + spec = PyDict_GetItemWithError(globals, attr); if (spec == NULL && _PyErr_Occurred(tstate)) { goto error; } @@ -1575,7 +1567,8 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level } else if (spec != NULL && spec != Py_None) { int equal; - PyObject *parent = _PyObject_GetAttrId(spec, &PyId_parent); + attr = _Py_GET_GLOBAL_IDENTIFIER(parent); + PyObject *parent = PyObject_GetAttr(spec, attr); if (parent == NULL) { goto error; } @@ -1594,7 +1587,8 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level } } else if (spec != NULL && spec != Py_None) { - package = _PyObject_GetAttrId(spec, &PyId_parent); + attr = _Py_GET_GLOBAL_IDENTIFIER(parent); + package = PyObject_GetAttr(spec, attr); if (package == NULL) { goto error; } @@ -1611,7 +1605,8 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level goto error; } - package = _PyDict_GetItemIdWithError(globals, &PyId___name__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + package = PyDict_GetItemWithError(globals, attr); if (package == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_KeyError, @@ -1627,7 +1622,8 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level goto error; } - int haspath = _PyDict_ContainsId(globals, &PyId___path__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__path__); + int haspath = PyDict_Contains(globals, attr); if (haspath < 0) { goto error; } @@ -1695,7 +1691,6 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level static PyObject * import_find_and_load(PyThreadState *tstate, PyObject *abs_name) { - _Py_IDENTIFIER(_find_and_load); PyObject *mod = NULL; PyInterpreterState *interp = tstate->interp; int import_time = _PyInterpreterState_GetConfig(interp)->import_time; @@ -1736,9 +1731,9 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name) if (PyDTrace_IMPORT_FIND_LOAD_START_ENABLED()) PyDTrace_IMPORT_FIND_LOAD_START(PyUnicode_AsUTF8(abs_name)); - mod = _PyObject_CallMethodIdObjArgs(interp->importlib, - &PyId__find_and_load, abs_name, - interp->import_func, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_find_and_load); + mod = PyObject_CallMethodObjArgs(interp->importlib, attr, abs_name, + interp->import_func, NULL); if (PyDTrace_IMPORT_FIND_LOAD_DONE_ENABLED()) PyDTrace_IMPORT_FIND_LOAD_DONE(PyUnicode_AsUTF8(abs_name), @@ -1782,7 +1777,6 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, int level) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_IDENTIFIER(_handle_fromlist); PyObject *abs_name = NULL; PyObject *final_mod = NULL; PyObject *mod = NULL; @@ -1903,13 +1897,15 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, } else { PyObject *path; - if (_PyObject_LookupAttrId(mod, &PyId___path__, &path) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__path__); + if (_PyObject_LookupAttr(mod, attr, &path) < 0) { goto error; } if (path) { Py_DECREF(path); - final_mod = _PyObject_CallMethodIdObjArgs( - interp->importlib, &PyId__handle_fromlist, + attr = _Py_GET_GLOBAL_IDENTIFIER(_handle_fromlist); + final_mod = PyObject_CallMethodObjArgs( + interp->importlib, attr, mod, fromlist, interp->import_func, NULL); } else { @@ -1949,10 +1945,9 @@ PyImport_ImportModuleLevel(const char *name, PyObject *globals, PyObject *locals PyObject * PyImport_ReloadModule(PyObject *m) { - _Py_IDENTIFIER(importlib); - _Py_IDENTIFIER(reload); PyObject *reloaded_module = NULL; - PyObject *importlib = _PyImport_GetModuleId(&PyId_importlib); + PyObject *name = _Py_GET_GLOBAL_IDENTIFIER(importlib); + PyObject *importlib = PyImport_GetModule(name); if (importlib == NULL) { if (PyErr_Occurred()) { return NULL; @@ -1964,7 +1959,8 @@ PyImport_ReloadModule(PyObject *m) } } - reloaded_module = _PyObject_CallMethodIdOneArg(importlib, &PyId_reload, m); + name = _Py_GET_GLOBAL_IDENTIFIER(reload); + reloaded_module = PyObject_CallMethodOneArg(importlib, name, m); Py_DECREF(importlib); return reloaded_module; } @@ -1982,25 +1978,14 @@ PyImport_ReloadModule(PyObject *m) PyObject * PyImport_Import(PyObject *module_name) { - _Py_IDENTIFIER(__import__); - _Py_IDENTIFIER(__builtins__); - PyThreadState *tstate = _PyThreadState_GET(); PyObject *globals = NULL; PyObject *import = NULL; PyObject *builtins = NULL; PyObject *r = NULL; - /* Initialize constant string objects */ - PyObject *import_str = _PyUnicode_FromId(&PyId___import__); // borrowed ref - if (import_str == NULL) { - return NULL; - } - - PyObject *builtins_str = _PyUnicode_FromId(&PyId___builtins__); // borrowed ref - if (builtins_str == NULL) { - return NULL; - } + PyObject *import_str = _Py_GET_GLOBAL_IDENTIFIER(__import__); + PyObject *builtins_str = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); PyObject *from_list = PyList_New(0); if (from_list == NULL) { From a4c1aa91fe3d48d26b9326346924fc8a9c717478 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 15:55:26 -0700 Subject: [PATCH 025/115] Add _PySys_SetAttr(). --- Include/internal/pycore_sysmodule.h | 2 ++ Python/sysmodule.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/Include/internal/pycore_sysmodule.h b/Include/internal/pycore_sysmodule.h index 738a7746a03842e..10d092cdc30a2c5 100644 --- a/Include/internal/pycore_sysmodule.h +++ b/Include/internal/pycore_sysmodule.h @@ -18,6 +18,8 @@ PyAPI_FUNC(int) _PySys_Audit( PyAPI_FUNC() to not export the symbol. */ extern void _PySys_ClearAuditHooks(PyThreadState *tstate); +PyAPI_FUNC(int) _PySys_SetAttr(PyObject *, PyObject *); + #ifdef __cplusplus } #endif diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ce06e4ae275e2cb..aa17c2ab3c4d723 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -163,6 +163,13 @@ _PySys_SetObjectId(_Py_Identifier *key, PyObject *v) return sys_set_object_id(interp, key, v); } +int +_PySys_SetAttr(PyObject *key, PyObject *v) +{ + PyInterpreterState *interp = _PyInterpreterState_GET(); + return sys_set_object(interp, key, v); +} + static int sys_set_object_str(PyInterpreterState *interp, const char *name, PyObject *v) { From 48fcb062d9ce8d212241c172213246dd8a05a526 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 15:58:32 -0700 Subject: [PATCH 026/115] Get rid of _Py_IDENTIFIER() in pylifecycle.c. --- Python/pylifecycle.c | 94 +++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index ba7bcd2f8899e43..4b80071dc1aa47a 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -3,6 +3,7 @@ #include "Python.h" #include "pycore_bytesobject.h" // _PyBytes_InitTypes() +#include "pycore_call.h" // _PyObject_CallMethod() #include "pycore_ceval.h" // _PyEval_FiniGIL() #include "pycore_context.h" // _PyContext_Init() #include "pycore_exceptions.h" // _PyExc_InitTypes() @@ -21,6 +22,7 @@ #include "pycore_pylifecycle.h" // _PyErr_Print() #include "pycore_pymem.h" // _PyObject_DebugMallocStats() #include "pycore_pystate.h" // _PyThreadState_GET() +#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() #include "pycore_runtime_init.h" // _PyRuntimeState_INIT #include "pycore_sliceobject.h" // _PySlice_Fini() #include "pycore_structseq.h" // _PyStructSequence_InitState() @@ -64,13 +66,6 @@ extern void _PyIO_Fini(void); #define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str)) -_Py_IDENTIFIER(flush); -_Py_IDENTIFIER(name); -_Py_IDENTIFIER(stdin); -_Py_IDENTIFIER(stdout); -_Py_IDENTIFIER(stderr); -_Py_IDENTIFIER(threading); - #ifdef __cplusplus extern "C" { #endif @@ -1450,8 +1445,8 @@ finalize_clear_modules_dict(PyObject *modules) PyDict_Clear(modules); } else { - _Py_IDENTIFIER(clear); - if (_PyObject_CallMethodIdNoArgs(modules, &PyId_clear) == NULL) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(clear); + if (PyObject_CallMethodNoArgs(modules, attr) == NULL) { PyErr_WriteUnraisable(NULL); } } @@ -1622,13 +1617,15 @@ file_is_closed(PyObject *fobj) static int flush_std_files(void) { - PyObject *fout = _PySys_GetObjectId(&PyId_stdout); - PyObject *ferr = _PySys_GetObjectId(&PyId_stderr); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *fout = _PySys_GetAttr(tstate, _Py_GET_GLOBAL_IDENTIFIER(stdout)); + PyObject *ferr = _PySys_GetAttr(tstate, _Py_GET_GLOBAL_IDENTIFIER(stderr)); + PyObject *flush = _Py_GET_GLOBAL_IDENTIFIER(flush); PyObject *tmp; int status = 0; if (fout != NULL && fout != Py_None && !file_is_closed(fout)) { - tmp = _PyObject_CallMethodIdNoArgs(fout, &PyId_flush); + tmp = PyObject_CallMethodNoArgs(fout, flush); if (tmp == NULL) { PyErr_WriteUnraisable(fout); status = -1; @@ -1638,7 +1635,7 @@ flush_std_files(void) } if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) { - tmp = _PyObject_CallMethodIdNoArgs(ferr, &PyId_flush); + tmp = PyObject_CallMethodNoArgs(ferr, flush); if (tmp == NULL) { PyErr_Clear(); status = -1; @@ -2225,12 +2222,8 @@ create_stdio(const PyConfig *config, PyObject* io, PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res; const char* mode; const char* newline; - PyObject *line_buffering, *write_through; + PyObject *line_buffering, *write_through, *attr, *method; int buffering, isatty; - _Py_IDENTIFIER(open); - _Py_IDENTIFIER(isatty); - _Py_IDENTIFIER(TextIOWrapper); - _Py_IDENTIFIER(mode); const int buffered_stdio = config->buffered_stdio; if (!is_valid_fd(fd)) @@ -2249,16 +2242,23 @@ create_stdio(const PyConfig *config, PyObject* io, mode = "wb"; else mode = "rb"; - buf = _PyObject_CallMethodId(io, &PyId_open, "isiOOOO", - fd, mode, buffering, - Py_None, Py_None, /* encoding, errors */ - Py_None, Py_False); /* newline, closefd */ + attr = _Py_GET_GLOBAL_IDENTIFIER(open); + method = PyObject_GetAttr(io, attr); + if (method == NULL) { + goto error; + } + PyThreadState *tstate = _PyThreadState_GET(); + buf = _PyObject_CallMethod(tstate, method, "isiOOOO", + fd, mode, buffering, + Py_None, Py_None, /* encoding, errors */ + Py_None, Py_False); /* newline, closefd */ + Py_DECREF(method); if (buf == NULL) goto error; if (buffering) { - _Py_IDENTIFIER(raw); - raw = _PyObject_GetAttrId(buf, &PyId_raw); + attr = _Py_GET_GLOBAL_IDENTIFIER(raw); + raw = PyObject_GetAttr(buf, attr); if (raw == NULL) goto error; } @@ -2274,9 +2274,11 @@ create_stdio(const PyConfig *config, PyObject* io, #endif text = PyUnicode_FromString(name); - if (text == NULL || _PyObject_SetAttrId(raw, &PyId_name, text) < 0) + attr = _Py_GET_GLOBAL_IDENTIFIER(name); + if (text == NULL || PyObject_SetAttr(raw, attr, text) < 0) goto error; - res = _PyObject_CallMethodIdNoArgs(raw, &PyId_isatty); + attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + res = PyObject_CallMethodNoArgs(raw, attr); if (res == NULL) goto error; isatty = PyObject_IsTrue(res); @@ -2319,9 +2321,14 @@ create_stdio(const PyConfig *config, PyObject* io, goto error; } - stream = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "OOOsOO", - buf, encoding_str, errors_str, - newline, line_buffering, write_through); + attr = _Py_GET_GLOBAL_IDENTIFIER(TextIOWrapper); + method = PyObject_GetAttr(io, attr); + if (method == NULL) { + goto error; + } + stream = _PyObject_CallMethod(tstate, method, "OOOsOO", + buf, encoding_str, errors_str, + newline, line_buffering, write_through); Py_CLEAR(buf); Py_CLEAR(encoding_str); Py_CLEAR(errors_str); @@ -2333,7 +2340,8 @@ create_stdio(const PyConfig *config, PyObject* io, else mode = "r"; text = PyUnicode_FromString(mode); - if (!text || _PyObject_SetAttrId(stream, &PyId_mode, text) < 0) + attr = _Py_GET_GLOBAL_IDENTIFIER(mode); + if (!text || PyObject_SetAttr(stream, attr, text) < 0) goto error; Py_CLEAR(text); return stream; @@ -2399,7 +2407,7 @@ init_sys_streams(PyThreadState *tstate) PyObject *iomod = NULL; PyObject *std = NULL; int fd; - PyObject * encoding_attr; + PyObject * encoding_attr, *attr; PyStatus res = _PyStatus_OK(); const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp); @@ -2432,7 +2440,8 @@ init_sys_streams(PyThreadState *tstate) if (std == NULL) goto error; PySys_SetObject("__stdin__", std); - _PySys_SetObjectId(&PyId_stdin, std); + attr = _Py_GET_GLOBAL_IDENTIFIER(stdin); + _PySys_SetAttr(attr, std); Py_DECREF(std); /* Set sys.stdout */ @@ -2443,7 +2452,8 @@ init_sys_streams(PyThreadState *tstate) if (std == NULL) goto error; PySys_SetObject("__stdout__", std); - _PySys_SetObjectId(&PyId_stdout, std); + attr = _Py_GET_GLOBAL_IDENTIFIER(stdout); + _PySys_SetAttr(attr, std); Py_DECREF(std); #if 1 /* Disable this if you have trouble debugging bootstrap stuff */ @@ -2472,7 +2482,8 @@ init_sys_streams(PyThreadState *tstate) Py_DECREF(std); goto error; } - if (_PySys_SetObjectId(&PyId_stderr, std) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + if (_PySys_SetAttr(attr, std) < 0) { Py_DECREF(std); goto error; } @@ -2512,7 +2523,7 @@ _Py_FatalError_DumpTracebacks(int fd, PyInterpreterState *interp, static int _Py_FatalError_PrintExc(PyThreadState *tstate) { - PyObject *ferr, *res; + PyObject *ferr, *res, *attr; PyObject *exception, *v, *tb; int has_tb; @@ -2522,7 +2533,8 @@ _Py_FatalError_PrintExc(PyThreadState *tstate) return 0; } - ferr = _PySys_GetObjectId(&PyId_stderr); + attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + ferr = _PySys_GetAttr(tstate, attr); if (ferr == NULL || ferr == Py_None) { /* sys.stderr is not set yet or set to None, no need to try to display the exception */ @@ -2547,7 +2559,8 @@ _Py_FatalError_PrintExc(PyThreadState *tstate) Py_XDECREF(tb); /* sys.stderr may be buffered: call sys.stderr.flush() */ - res = _PyObject_CallMethodIdNoArgs(ferr, &PyId_flush); + attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + res = PyObject_CallMethodNoArgs(ferr, attr); if (res == NULL) { _PyErr_Clear(tstate); } @@ -2899,9 +2912,9 @@ Py_ExitStatusException(PyStatus status) static void wait_for_thread_shutdown(PyThreadState *tstate) { - _Py_IDENTIFIER(_shutdown); PyObject *result; - PyObject *threading = _PyImport_GetModuleId(&PyId_threading); + PyObject *name = _Py_GET_GLOBAL_IDENTIFIER(threading); + PyObject *threading = PyImport_GetModule(name); if (threading == NULL) { if (_PyErr_Occurred(tstate)) { PyErr_WriteUnraisable(NULL); @@ -2909,7 +2922,8 @@ wait_for_thread_shutdown(PyThreadState *tstate) /* else: threading not imported */ return; } - result = _PyObject_CallMethodIdNoArgs(threading, &PyId__shutdown); + name = _Py_GET_GLOBAL_IDENTIFIER(_shutdown); + result = PyObject_CallMethodNoArgs(threading, name); if (result == NULL) { PyErr_WriteUnraisable(threading); } From c9bc12428127ea81b5b9a9c13419039a596b4c89 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 16:21:30 -0700 Subject: [PATCH 027/115] Get rid of _Py_IDENTIFIER() in pythonrun.c. --- Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init.h | 1 + Python/pythonrun.c | 147 +++++++++++------------ 3 files changed, 72 insertions(+), 77 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 9082963a098086f..520e0c5241cac94 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -404,6 +404,7 @@ struct _Py_global_strings { ID(__newobj__) ID(__newobj_ex__) ID(__next__) + ID(__note__) ID(__or__) ID(__package__) ID(__path__) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index e194da84891fa7f..3873d413c46114e 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -1024,6 +1024,7 @@ extern "C" { INIT_ID(__newobj__), \ INIT_ID(__newobj_ex__), \ INIT_ID(__next__), \ + INIT_ID(__note__), \ INIT_ID(__or__), \ INIT_ID(__package__), \ INIT_ID(__path__), \ diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 6f170a4dd63eb34..1315e7b33564fa3 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -38,20 +38,6 @@ #endif -_Py_IDENTIFIER(__main__); -_Py_IDENTIFIER(builtins); -_Py_IDENTIFIER(excepthook); -_Py_IDENTIFIER(flush); -_Py_IDENTIFIER(last_traceback); -_Py_IDENTIFIER(last_type); -_Py_IDENTIFIER(last_value); -_Py_IDENTIFIER(ps1); -_Py_IDENTIFIER(ps2); -_Py_IDENTIFIER(stdin); -_Py_IDENTIFIER(stdout); -_Py_IDENTIFIER(stderr); -_Py_static_string(PyId_string, ""); - #ifdef __cplusplus extern "C" { #endif @@ -130,14 +116,17 @@ _PyRun_InteractiveLoopObject(FILE *fp, PyObject *filename, PyCompilerFlags *flag flags = &local_flags; } - PyObject *v = _PySys_GetObjectId(&PyId_ps1); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(ps1); + PyObject *v = _PySys_GetAttr(tstate, attr); if (v == NULL) { - _PySys_SetObjectId(&PyId_ps1, v = PyUnicode_FromString(">>> ")); + _PySys_SetAttr(attr, v = PyUnicode_FromString(">>> ")); Py_XDECREF(v); } - v = _PySys_GetObjectId(&PyId_ps2); + attr = _Py_GET_GLOBAL_IDENTIFIER(ps2); + v = _PySys_GetAttr(tstate, attr); if (v == NULL) { - _PySys_SetObjectId(&PyId_ps2, v = PyUnicode_FromString("... ")); + _PySys_SetAttr(attr, v = PyUnicode_FromString("... ")); Py_XDECREF(v); } @@ -199,31 +188,29 @@ static int PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, PyCompilerFlags *flags) { - PyObject *m, *d, *v, *w, *oenc = NULL, *mod_name; + PyObject *m, *d, *v, *w, *oenc = NULL, *mod_name, *attr; mod_ty mod; PyArena *arena; const char *ps1 = "", *ps2 = "", *enc = NULL; int errcode = 0; - _Py_IDENTIFIER(encoding); - _Py_IDENTIFIER(__main__); - - mod_name = _PyUnicode_FromId(&PyId___main__); /* borrowed */ - if (mod_name == NULL) { - return -1; - } + PyThreadState *tstate = _PyThreadState_GET(); + mod_name = _Py_GET_GLOBAL_IDENTIFIER(__main__); if (fp == stdin) { /* Fetch encoding from sys.stdin if possible. */ - v = _PySys_GetObjectId(&PyId_stdin); + attr = _Py_GET_GLOBAL_IDENTIFIER(stdin); + v = _PySys_GetAttr(tstate, attr); if (v && v != Py_None) { - oenc = _PyObject_GetAttrId(v, &PyId_encoding); + attr = _Py_GET_GLOBAL_IDENTIFIER(encoding); + oenc = PyObject_GetAttr(v, attr); if (oenc) enc = PyUnicode_AsUTF8(oenc); if (!enc) PyErr_Clear(); } } - v = _PySys_GetObjectId(&PyId_ps1); + attr = _Py_GET_GLOBAL_IDENTIFIER(ps1); + v = _PySys_GetAttr(tstate, attr); if (v != NULL) { v = PyObject_Str(v); if (v == NULL) @@ -236,7 +223,8 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, } } } - w = _PySys_GetObjectId(&PyId_ps2); + attr = _Py_GET_GLOBAL_IDENTIFIER(ps2); + w = _PySys_GetAttr(tstate, attr); if (w != NULL) { w = PyObject_Str(w); if (w == NULL) @@ -519,38 +507,32 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, PyObject **text) { Py_ssize_t hold; - PyObject *v; - _Py_IDENTIFIER(msg); - _Py_IDENTIFIER(filename); - _Py_IDENTIFIER(lineno); - _Py_IDENTIFIER(offset); - _Py_IDENTIFIER(end_lineno); - _Py_IDENTIFIER(end_offset); - _Py_IDENTIFIER(text); + PyObject *v, *attr; *message = NULL; *filename = NULL; /* new style errors. `err' is an instance */ - *message = _PyObject_GetAttrId(err, &PyId_msg); + attr = _Py_GET_GLOBAL_IDENTIFIER(msg); + *message = PyObject_GetAttr(err, attr); if (!*message) goto finally; - v = _PyObject_GetAttrId(err, &PyId_filename); + attr = _Py_GET_GLOBAL_IDENTIFIER(filename); + v = PyObject_GetAttr(err, attr); if (!v) goto finally; if (v == Py_None) { Py_DECREF(v); - *filename = _PyUnicode_FromId(&PyId_string); - if (*filename == NULL) - goto finally; + *filename = _Py_GET_GLOBAL_STRING(anon_string); Py_INCREF(*filename); } else { *filename = v; } - v = _PyObject_GetAttrId(err, &PyId_lineno); + attr = _Py_GET_GLOBAL_IDENTIFIER(lineno); + v = PyObject_GetAttr(err, attr); if (!v) goto finally; hold = PyLong_AsSsize_t(v); @@ -559,7 +541,8 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, goto finally; *lineno = hold; - v = _PyObject_GetAttrId(err, &PyId_offset); + attr = _Py_GET_GLOBAL_IDENTIFIER(offset); + v = PyObject_GetAttr(err, attr); if (!v) goto finally; if (v == Py_None) { @@ -574,7 +557,8 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, } if (Py_TYPE(err) == (PyTypeObject*)PyExc_SyntaxError) { - v = _PyObject_GetAttrId(err, &PyId_end_lineno); + attr = _Py_GET_GLOBAL_IDENTIFIER(end_lineno); + v = PyObject_GetAttr(err, attr); if (!v) { PyErr_Clear(); *end_lineno = *lineno; @@ -590,7 +574,8 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *end_lineno = hold; } - v = _PyObject_GetAttrId(err, &PyId_end_offset); + attr = _Py_GET_GLOBAL_IDENTIFIER(end_offset); + v = PyObject_GetAttr(err, attr); if (!v) { PyErr_Clear(); *end_offset = -1; @@ -611,7 +596,8 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *end_offset = -1; } - v = _PyObject_GetAttrId(err, &PyId_text); + attr = _Py_GET_GLOBAL_IDENTIFIER(text); + v = PyObject_GetAttr(err, attr); if (!v) goto finally; if (v == Py_None) { @@ -745,8 +731,8 @@ _Py_HandleSystemExit(int *exitcode_p) if (PyExceptionInstance_Check(value)) { /* The error code should be in the `code' attribute. */ - _Py_IDENTIFIER(code); - PyObject *code = _PyObject_GetAttrId(value, &PyId_code); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(code); + PyObject *code = PyObject_GetAttr(value, attr); if (code) { Py_DECREF(value); value = code; @@ -761,7 +747,9 @@ _Py_HandleSystemExit(int *exitcode_p) exitcode = (int)PyLong_AsLong(value); } else { - PyObject *sys_stderr = _PySys_GetObjectId(&PyId_stderr); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *sys_stderr = _PySys_GetAttr(tstate, attr); /* We clear the exception here to avoid triggering the assertion * in PyObject_Str that ensures it won't silently lose exception * details. @@ -803,7 +791,7 @@ handle_system_exit(void) static void _PyErr_PrintEx(PyThreadState *tstate, int set_sys_last_vars) { - PyObject *exception, *v, *tb, *hook; + PyObject *exception, *v, *tb, *hook, *attr; handle_system_exit(); @@ -824,17 +812,21 @@ _PyErr_PrintEx(PyThreadState *tstate, int set_sys_last_vars) /* Now we know v != NULL too */ if (set_sys_last_vars) { - if (_PySys_SetObjectId(&PyId_last_type, exception) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(last_type); + if (_PySys_SetAttr(attr, exception) < 0) { _PyErr_Clear(tstate); } - if (_PySys_SetObjectId(&PyId_last_value, v) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(last_value); + if (_PySys_SetAttr(attr, v) < 0) { _PyErr_Clear(tstate); } - if (_PySys_SetObjectId(&PyId_last_traceback, tb) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(last_traceback); + if (_PySys_SetAttr(attr, tb) < 0) { _PyErr_Clear(tstate); } } - hook = _PySys_GetObjectId(&PyId_excepthook); + attr = _Py_GET_GLOBAL_IDENTIFIER(excepthook); + hook = _PySys_GetAttr(tstate, attr); if (_PySys_Audit(tstate, "sys.excepthook", "OOOO", hook ? hook : Py_None, exception, v, tb) < 0) { if (PyErr_ExceptionMatches(PyExc_RuntimeError)) { @@ -979,9 +971,9 @@ print_exception_file_and_line(struct exception_print_context *ctx, { PyObject *f = ctx->file; - _Py_IDENTIFIER(print_file_and_line); PyObject *tmp; - int res = _PyObject_LookupAttrId(*value_p, &PyId_print_file_and_line, &tmp); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(print_file_and_line); + int res = _PyObject_LookupAttr(*value_p, attr, &tmp); if (res <= 0) { if (res < 0) { PyErr_Clear(); @@ -1051,14 +1043,13 @@ print_exception_message(struct exception_print_context *ctx, PyObject *type, { PyObject *f = ctx->file; - _Py_IDENTIFIER(__module__); - assert(PyExceptionClass_Check(type)); if (write_indented_margin(ctx, f) < 0) { return -1; } - PyObject *modulename = _PyObject_GetAttrId(type, &PyId___module__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + PyObject *modulename = PyObject_GetAttr(type, attr); if (modulename == NULL || !PyUnicode_Check(modulename)) { Py_XDECREF(modulename); PyErr_Clear(); @@ -1067,8 +1058,8 @@ print_exception_message(struct exception_print_context *ctx, PyObject *type, } } else { - if (!_PyUnicode_EqualToASCIIId(modulename, &PyId_builtins) && - !_PyUnicode_EqualToASCIIId(modulename, &PyId___main__)) + if (!_PyUnicode_Equal(modulename, _Py_GET_GLOBAL_IDENTIFIER(builtins)) && + !_PyUnicode_Equal(modulename, _Py_GET_GLOBAL_IDENTIFIER(__main__))) { int res = PyFile_WriteObject(modulename, f, Py_PRINT_RAW); Py_DECREF(modulename); @@ -1168,9 +1159,8 @@ print_exception_note(struct exception_print_context *ctx, PyObject *value) return 0; } - _Py_IDENTIFIER(__note__); - - PyObject *note = _PyObject_GetAttrId(value, &PyId___note__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__note__); + PyObject *note = PyObject_GetAttr(value, attr); if (note == NULL) { return -1; } @@ -1553,7 +1543,8 @@ _PyErr_Display(PyObject *file, PyObject *exception, PyObject *value, PyObject *t Py_XDECREF(ctx.seen); /* Call file.flush() */ - PyObject *res = _PyObject_CallMethodIdNoArgs(file, &PyId_flush); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *res = _PyObject_CallMethodNoArgs(file, attr); if (!res) { /* Silently ignore file.flush() error */ PyErr_Clear(); @@ -1566,7 +1557,9 @@ _PyErr_Display(PyObject *file, PyObject *exception, PyObject *value, PyObject *t void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) { - PyObject *file = _PySys_GetObjectId(&PyId_stderr); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *file = _PySys_GetAttr(tstate, attr); if (file == NULL) { _PyObject_Dump(value); fprintf(stderr, "lost sys.stderr\n"); @@ -1587,11 +1580,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *ret = NULL; mod_ty mod; PyArena *arena; - PyObject *filename; - - filename = _PyUnicode_FromId(&PyId_string); /* borrowed */ - if (filename == NULL) - return NULL; + PyObject *filename = _Py_GET_GLOBAL_STRING(anon_string); arena = _PyArena_New(); if (arena == NULL) @@ -1658,21 +1647,25 @@ flush_io(void) { PyObject *f, *r; PyObject *type, *value, *traceback; + PyObject *flush = _Py_GET_GLOBAL_IDENTIFIER(flush); /* Save the current exception */ PyErr_Fetch(&type, &value, &traceback); - f = _PySys_GetObjectId(&PyId_stderr); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + f = _PySys_GetAttr(tstate, attr); if (f != NULL) { - r = _PyObject_CallMethodIdNoArgs(f, &PyId_flush); + r = _PyObject_CallMethodNoArgs(f, flush); if (r) Py_DECREF(r); else PyErr_Clear(); } - f = _PySys_GetObjectId(&PyId_stdout); + attr = _Py_GET_GLOBAL_IDENTIFIER(stdout); + f = _PySys_GetAttr(tstate, attr); if (f != NULL) { - r = _PyObject_CallMethodIdNoArgs(f, &PyId_flush); + r = _PyObject_CallMethodNoArgs(f, flush); if (r) Py_DECREF(r); else From 816c630c7e36928ab46a5a9d352d1708a07a42c9 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 16:37:32 -0700 Subject: [PATCH 028/115] Get rid of _Py_IDENTIFIER() in sysmodule.c. --- Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init.h | 1 + Python/sysmodule.c | 86 +++++++++++++----------- 3 files changed, 48 insertions(+), 40 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 520e0c5241cac94..bc3da6a69e169f2 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -329,6 +329,7 @@ struct _Py_global_strings { ID(__builtins__) ID(__bytes__) ID(__call__) + ID(__cantrace__) ID(__class__) ID(__class_getitem__) ID(__classcell__) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 3873d413c46114e..f44bae3d65227a0 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -949,6 +949,7 @@ extern "C" { INIT_ID(__builtins__), \ INIT_ID(__bytes__), \ INIT_ID(__call__), \ + INIT_ID(__cantrace__), \ INIT_ID(__class__), \ INIT_ID(__class_getitem__), \ INIT_ID(__classcell__), \ diff --git a/Python/sysmodule.c b/Python/sysmodule.c index aa17c2ab3c4d723..4d61f34f58c92ec 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -55,18 +55,6 @@ module sys #include "clinic/sysmodule.c.h" -_Py_IDENTIFIER(_); -_Py_IDENTIFIER(__sizeof__); -_Py_IDENTIFIER(_xoptions); -_Py_IDENTIFIER(buffer); -_Py_IDENTIFIER(builtins); -_Py_IDENTIFIER(encoding); -_Py_IDENTIFIER(path); -_Py_IDENTIFIER(stdout); -_Py_IDENTIFIER(stderr); -_Py_IDENTIFIER(warnoptions); -_Py_IDENTIFIER(write); - PyObject * _PySys_GetAttr(PyThreadState *tstate, PyObject *name) { @@ -280,10 +268,10 @@ sys_audit_tstate(PyThreadState *ts, const char *event, /* Disallow tracing in hooks unless explicitly enabled */ PyThreadState_EnterTracing(ts); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__cantrace__); while ((hook = PyIter_Next(hooks)) != NULL) { - _Py_IDENTIFIER(__cantrace__); PyObject *o; - int canTrace = _PyObject_LookupAttrId(hook, &PyId___cantrace__, &o); + int canTrace = _PyObject_LookupAttr(hook, attr, &o); if (o) { canTrace = PyObject_IsTrue(o); Py_DECREF(o); @@ -654,7 +642,8 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) const char *stdout_encoding_str; int ret; - stdout_encoding = _PyObject_GetAttrId(outf, &PyId_encoding); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(encoding); + stdout_encoding = PyObject_GetAttr(outf, attr); if (stdout_encoding == NULL) goto error; stdout_encoding_str = PyUnicode_AsUTF8(stdout_encoding); @@ -671,12 +660,14 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) if (encoded == NULL) goto error; - if (_PyObject_LookupAttrId(outf, &PyId_buffer, &buffer) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(buffer); + if (_PyObject_LookupAttr(outf, attr, &buffer) < 0) { Py_DECREF(encoded); goto error; } if (buffer) { - result = _PyObject_CallMethodIdOneArg(buffer, &PyId_write, encoded); + attr = _Py_GET_GLOBAL_IDENTIFIER(write); + result = PyObject_CallMethodOneArg(buffer, attr, encoded); Py_DECREF(buffer); Py_DECREF(encoded); if (result == NULL) @@ -722,7 +713,8 @@ sys_displayhook(PyObject *module, PyObject *o) static PyObject *newline = NULL; PyThreadState *tstate = _PyThreadState_GET(); - builtins = _PyImport_GetModuleId(&PyId_builtins); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(builtins); + builtins = PyImport_GetModule(str); if (builtins == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_RuntimeError, @@ -738,9 +730,10 @@ sys_displayhook(PyObject *module, PyObject *o) if (o == Py_None) { Py_RETURN_NONE; } - if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0) + str = _Py_GET_GLOBAL_IDENTIFIER(_); + if (PyObject_SetAttr(builtins, str, Py_None) != 0) return NULL; - outf = sys_get_object_id(tstate, &PyId_stdout); + outf = _PySys_GetAttr(tstate, _Py_GET_GLOBAL_IDENTIFIER(stdout)); if (outf == NULL || outf == Py_None) { _PyErr_SetString(tstate, PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -767,7 +760,7 @@ sys_displayhook(PyObject *module, PyObject *o) } if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0) return NULL; - if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0) + if (PyObject_SetAttr(builtins, str, o) != 0) return NULL; Py_RETURN_NONE; } @@ -1699,7 +1692,8 @@ _PySys_GetSizeOf(PyObject *o) return (size_t)-1; } - method = _PyObject_LookupSpecialId(o, &PyId___sizeof__); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(__sizeof__); + method = _PyObject_LookupSpecial(o, str); if (method == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -2241,7 +2235,8 @@ _PySys_ReadPreinitXOptions(PyConfig *config) static PyObject * get_warnoptions(PyThreadState *tstate) { - PyObject *warnoptions = sys_get_object_id(tstate, &PyId_warnoptions); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(warnoptions); + PyObject *warnoptions = _PySys_GetAttr(tstate, str); if (warnoptions == NULL || !PyList_Check(warnoptions)) { /* PEP432 TODO: we can reach this if warnoptions is NULL in the main * interpreter config. When that happens, we need to properly set @@ -2257,7 +2252,7 @@ get_warnoptions(PyThreadState *tstate) if (warnoptions == NULL) { return NULL; } - if (sys_set_object_id(tstate->interp, &PyId_warnoptions, warnoptions)) { + if (sys_set_object(tstate->interp, str, warnoptions)) { Py_DECREF(warnoptions); return NULL; } @@ -2275,7 +2270,8 @@ PySys_ResetWarnOptions(void) return; } - PyObject *warnoptions = sys_get_object_id(tstate, &PyId_warnoptions); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(warnoptions); + PyObject *warnoptions = _PySys_GetAttr(tstate, str); if (warnoptions == NULL || !PyList_Check(warnoptions)) return; PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL); @@ -2329,7 +2325,8 @@ int PySys_HasWarnOptions(void) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *warnoptions = sys_get_object_id(tstate, &PyId_warnoptions); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(warnoptions); + PyObject *warnoptions = _PySys_GetAttr(tstate, str); return (warnoptions != NULL && PyList_Check(warnoptions) && PyList_GET_SIZE(warnoptions) > 0); } @@ -2337,7 +2334,8 @@ PySys_HasWarnOptions(void) static PyObject * get_xoptions(PyThreadState *tstate) { - PyObject *xoptions = sys_get_object_id(tstate, &PyId__xoptions); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(_xoptions); + PyObject *xoptions = _PySys_GetAttr(tstate, str); if (xoptions == NULL || !PyDict_Check(xoptions)) { /* PEP432 TODO: we can reach this if xoptions is NULL in the main * interpreter config. When that happens, we need to properly set @@ -2353,7 +2351,7 @@ get_xoptions(PyThreadState *tstate) if (xoptions == NULL) { return NULL; } - if (sys_set_object_id(tstate->interp, &PyId__xoptions, xoptions)) { + if (sys_set_object(tstate->interp, str, xoptions)) { Py_DECREF(xoptions); return NULL; } @@ -3055,7 +3053,8 @@ _PySys_SetPreliminaryStderr(PyObject *sysdict) if (pstderr == NULL) { goto error; } - if (_PyDict_SetItemId(sysdict, &PyId_stderr, pstderr) < 0) { + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stderr); + if (PyDict_SetItem(sysdict, str, pstderr) < 0) { goto error; } if (PyDict_SetItemString(sysdict, "__stderr__", pstderr) < 0) { @@ -3180,7 +3179,8 @@ PySys_SetPath(const wchar_t *path) if ((v = makepathobject(path, DELIM)) == NULL) Py_FatalError("can't create sys.path"); PyInterpreterState *interp = _PyInterpreterState_GET(); - if (sys_set_object_id(interp, &PyId_path, v) != 0) { + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(path); + if (sys_set_object(interp, str, v) != 0) { Py_FatalError("can't assign sys.path"); } Py_DECREF(v); @@ -3237,7 +3237,8 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) Py_FatalError("can't compute path0 from argv"); } - PyObject *sys_path = sys_get_object_id(tstate, &PyId_path); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(path); + PyObject *sys_path = _PySys_GetAttr(tstate, str); if (sys_path != NULL) { if (PyList_Insert(sys_path, 0, path0) < 0) { Py_DECREF(path0); @@ -3264,7 +3265,8 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) if (file == NULL) return -1; assert(unicode != NULL); - PyObject *result = _PyObject_CallMethodIdOneArg(file, &PyId_write, unicode); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(write); + PyObject *result = _PyObject_CallMethodOneArg(file, str, unicode); if (result == NULL) { return -1; } @@ -3319,7 +3321,7 @@ sys_pyfile_write(const char *text, PyObject *file) */ static void -sys_write(_Py_Identifier *key, FILE *fp, const char *format, va_list va) +sys_write(PyObject *key, FILE *fp, const char *format, va_list va) { PyObject *file; PyObject *error_type, *error_value, *error_traceback; @@ -3328,7 +3330,7 @@ sys_write(_Py_Identifier *key, FILE *fp, const char *format, va_list va) PyThreadState *tstate = _PyThreadState_GET(); _PyErr_Fetch(tstate, &error_type, &error_value, &error_traceback); - file = sys_get_object_id(tstate, key); + file = _PySys_GetAttr(tstate, key); written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va); if (sys_pyfile_write(buffer, file) != 0) { _PyErr_Clear(tstate); @@ -3348,7 +3350,8 @@ PySys_WriteStdout(const char *format, ...) va_list va; va_start(va, format); - sys_write(&PyId_stdout, stdout, format, va); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stdout); + sys_write(str, stdout, format, va); va_end(va); } @@ -3358,12 +3361,13 @@ PySys_WriteStderr(const char *format, ...) va_list va; va_start(va, format); - sys_write(&PyId_stderr, stderr, format, va); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stderr); + sys_write(str, stderr, format, va); va_end(va); } static void -sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va) +sys_format(PyObject *key, FILE *fp, const char *format, va_list va) { PyObject *file, *message; PyObject *error_type, *error_value, *error_traceback; @@ -3371,7 +3375,7 @@ sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va) PyThreadState *tstate = _PyThreadState_GET(); _PyErr_Fetch(tstate, &error_type, &error_value, &error_traceback); - file = sys_get_object_id(tstate, key); + file = _PySys_GetAttr(tstate, key); message = PyUnicode_FromFormatV(format, va); if (message != NULL) { if (sys_pyfile_write_unicode(message, file) != 0) { @@ -3391,7 +3395,8 @@ PySys_FormatStdout(const char *format, ...) va_list va; va_start(va, format); - sys_format(&PyId_stdout, stdout, format, va); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stdout); + sys_format(str, stdout, format, va); va_end(va); } @@ -3401,6 +3406,7 @@ PySys_FormatStderr(const char *format, ...) va_list va; va_start(va, format); - sys_format(&PyId_stderr, stderr, format, va); + PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stderr); + sys_format(str, stderr, format, va); va_end(va); } From ef2b06146dd80ec561d1454aabe859f7c6171cf4 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 24 Jan 2022 18:06:20 -0700 Subject: [PATCH 029/115] Get rid of _Py_IDENTIFIER() in typeobject.c. --- Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init.h | 1 + Objects/typeobject.c | 541 ++++++++++++----------- 3 files changed, 276 insertions(+), 267 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index bc3da6a69e169f2..8210f5e8086c080 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -448,6 +448,7 @@ struct _Py_global_strings { ID(__truediv__) ID(__trunc__) ID(__warningregistry__) + ID(__weakref__) ID(__xor__) ID(_abc_impl) ID(_blksize) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index f44bae3d65227a0..0ac1cc2d3e35103 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -1068,6 +1068,7 @@ extern "C" { INIT_ID(__truediv__), \ INIT_ID(__trunc__), \ INIT_ID(__warningregistry__), \ + INIT_ID(__weakref__), \ INIT_ID(__xor__), \ INIT_ID(_abc_impl), \ INIT_ID(_blksize), \ diff --git a/Objects/typeobject.c b/Objects/typeobject.c index dfe42cec92cd030..aad2b43f1a596ae 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -59,30 +59,6 @@ typedef struct PySlot_Offset { # define INTERN_NAME_STRINGS #endif -/* alphabetical order */ -_Py_IDENTIFIER(__abstractmethods__); -_Py_IDENTIFIER(__annotations__); -_Py_IDENTIFIER(__class__); -_Py_IDENTIFIER(__class_getitem__); -_Py_IDENTIFIER(__classcell__); -_Py_IDENTIFIER(__delitem__); -_Py_IDENTIFIER(__dict__); -_Py_IDENTIFIER(__doc__); -_Py_IDENTIFIER(__getattribute__); -_Py_IDENTIFIER(__getitem__); -_Py_IDENTIFIER(__hash__); -_Py_IDENTIFIER(__init_subclass__); -_Py_IDENTIFIER(__len__); -_Py_IDENTIFIER(__module__); -_Py_IDENTIFIER(__name__); -_Py_IDENTIFIER(__new__); -_Py_IDENTIFIER(__qualname__); -_Py_IDENTIFIER(__set_name__); -_Py_IDENTIFIER(__setitem__); -_Py_IDENTIFIER(__weakref__); -_Py_IDENTIFIER(builtins); -_Py_IDENTIFIER(mro); - static PyObject * slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds); @@ -90,7 +66,7 @@ static void clear_slotdefs(void); static PyObject * -lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound); +lookup_maybe_method(PyObject *self, PyObject *attr, int *unbound); static int slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value); @@ -175,7 +151,8 @@ _PyType_CheckConsistency(PyTypeObject *type) if (type->tp_flags & Py_TPFLAGS_DISALLOW_INSTANTIATION) { CHECK(type->tp_new == NULL); - CHECK(_PyDict_ContainsId(type->tp_dict, &PyId___new__) == 0); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + CHECK(PyDict_Contains(type->tp_dict, attr) == 0); } return 1; @@ -373,12 +350,12 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) { PyObject *type_mro_meth = NULL; if (custom) { - mro_meth = lookup_maybe_method( - (PyObject *)type, &PyId_mro, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(mro); + mro_meth = lookup_maybe_method((PyObject *)type, attr, &unbound); if (mro_meth == NULL) goto clear; type_mro_meth = lookup_maybe_method( - (PyObject *)&PyType_Type, &PyId_mro, &unbound); + (PyObject *)&PyType_Type, attr, &unbound); if (type_mro_meth == NULL) goto clear; if (mro_meth != type_mro_meth) @@ -572,7 +549,8 @@ type_module(PyTypeObject *type, void *context) PyObject *mod; if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { - mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + mod = PyDict_GetItemWithError(type->tp_dict, attr); if (mod == NULL) { if (!PyErr_Occurred()) { PyErr_Format(PyExc_AttributeError, "__module__"); @@ -590,8 +568,8 @@ type_module(PyTypeObject *type, void *context) PyUnicode_InternInPlace(&mod); } else { - mod = _PyUnicode_FromId(&PyId_builtins); - Py_XINCREF(mod); + mod = _Py_GET_GLOBAL_IDENTIFIER(builtins); + Py_INCREF(mod); } } return mod; @@ -605,7 +583,8 @@ type_set_module(PyTypeObject *type, PyObject *value, void *context) PyType_Modified(type); - return _PyDict_SetItemId(type->tp_dict, &PyId___module__, value); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + return PyDict_SetItem(type->tp_dict, attr, value); } static PyObject * @@ -614,13 +593,12 @@ type_abstractmethods(PyTypeObject *type, void *context) PyObject *mod = NULL; /* type itself has an __abstractmethods__ descriptor (this). Don't return that. */ + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__abstractmethods__); if (type != &PyType_Type) - mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___abstractmethods__); + mod = PyDict_GetItemWithError(type->tp_dict, attr); if (!mod) { if (!PyErr_Occurred()) { - PyObject *message = _PyUnicode_FromId(&PyId___abstractmethods__); - if (message) - PyErr_SetObject(PyExc_AttributeError, message); + PyErr_SetObject(PyExc_AttributeError, attr); } return NULL; } @@ -636,19 +614,18 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context) special to update subclasses. */ int abstract, res; + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__abstractmethods__); if (value != NULL) { abstract = PyObject_IsTrue(value); if (abstract < 0) return -1; - res = _PyDict_SetItemId(type->tp_dict, &PyId___abstractmethods__, value); + res = PyDict_SetItem(type->tp_dict, attr, value); } else { abstract = 0; - res = _PyDict_DelItemId(type->tp_dict, &PyId___abstractmethods__); + res = PyDict_DelItem(type->tp_dict, attr); if (res && PyErr_ExceptionMatches(PyExc_KeyError)) { - PyObject *message = _PyUnicode_FromId(&PyId___abstractmethods__); - if (message) - PyErr_SetObject(PyExc_AttributeError, message); + PyErr_SetObject(PyExc_AttributeError, attr); return -1; } } @@ -902,7 +879,8 @@ type_get_doc(PyTypeObject *type, void *context) if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) { return _PyType_GetDocFromInternalDoc(type->tp_name, type->tp_doc); } - result = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + result = PyDict_GetItemWithError(type->tp_dict, attr); if (result == NULL) { if (!PyErr_Occurred()) { result = Py_None; @@ -931,7 +909,8 @@ type_set_doc(PyTypeObject *type, PyObject *value, void *context) if (!check_set_special_type_attr(type, value, "__doc__")) return -1; PyType_Modified(type); - return _PyDict_SetItemId(type->tp_dict, &PyId___doc__, value); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + return PyDict_SetItem(type->tp_dict, attr, value); } static PyObject * @@ -944,10 +923,11 @@ type_get_annotations(PyTypeObject *type, void *context) PyObject *annotations; /* there's no _PyDict_GetItemId without WithError, so let's LBYL. */ - if (_PyDict_ContainsId(type->tp_dict, &PyId___annotations__)) { - annotations = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___annotations__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); + if (PyDict_Contains(type->tp_dict, attr)) { + annotations = PyDict_GetItemWithError(type->tp_dict, attr); /* - ** _PyDict_GetItemIdWithError could still fail, + ** PyDict_GetItemWithError could still fail, ** for instance with a well-timed Ctrl-C or a MemoryError. ** so let's be totally safe. */ @@ -962,7 +942,7 @@ type_get_annotations(PyTypeObject *type, void *context) } else { annotations = PyDict_New(); if (annotations) { - int result = _PyDict_SetItemId(type->tp_dict, &PyId___annotations__, annotations); + int result = PyDict_SetItem(type->tp_dict, attr, annotations); if (result) { Py_CLEAR(annotations); } else { @@ -984,16 +964,17 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context) } int result; + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); if (value != NULL) { /* set */ - result = _PyDict_SetItemId(type->tp_dict, &PyId___annotations__, value); + result = PyDict_SetItem(type->tp_dict, attr, value); } else { /* delete */ - if (!_PyDict_ContainsId(type->tp_dict, &PyId___annotations__)) { + if (!PyDict_Contains(type->tp_dict, attr)) { PyErr_Format(PyExc_AttributeError, "__annotations__"); return -1; } - result = _PyDict_DelItemId(type->tp_dict, &PyId___annotations__); + result = PyDict_DelItem(type->tp_dict, attr); } if (result == 0) { @@ -1074,7 +1055,8 @@ type_repr(PyTypeObject *type) return NULL; } - if (mod != NULL && !_PyUnicode_EqualToASCIIId(mod, &PyId_builtins)) + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(builtins); + if (mod != NULL && !_PyUnicode_Equal(mod, attr)) rtn = PyUnicode_FromFormat("", mod, name); else rtn = PyUnicode_FromFormat("", type->tp_name); @@ -1629,9 +1611,9 @@ _PyObject_LookupSpecialId(PyObject *self, _Py_Identifier *attrid) } static PyObject * -lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound) +lookup_maybe_method(PyObject *self, PyObject *attr, int *unbound) { - PyObject *res = _PyType_LookupId(Py_TYPE(self), attrid); + PyObject *res = _PyType_Lookup(Py_TYPE(self), attr); if (res == NULL) { return NULL; } @@ -1655,11 +1637,11 @@ lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound) } static PyObject * -lookup_method(PyObject *self, _Py_Identifier *attrid, int *unbound) +lookup_method(PyObject *self, PyObject *attr, int *unbound) { - PyObject *res = lookup_maybe_method(self, attrid, unbound); + PyObject *res = lookup_maybe_method(self, attr, unbound); if (res == NULL && !PyErr_Occurred()) { - PyErr_SetObject(PyExc_AttributeError, _PyUnicode_FromId(attrid)); + PyErr_SetObject(PyExc_AttributeError, attr); } return res; } @@ -1696,8 +1678,7 @@ call_unbound_noarg(int unbound, PyObject *func, PyObject *self) args is an argument vector of length nargs. The first element in this vector is the special object "self" which is used for the method lookup */ static PyObject * -vectorcall_method(_Py_Identifier *name, - PyObject *const *args, Py_ssize_t nargs) +vectorcall_method(PyObject *name, PyObject *const *args, Py_ssize_t nargs) { assert(nargs >= 1); @@ -1716,7 +1697,7 @@ vectorcall_method(_Py_Identifier *name, /* Clone of vectorcall_method() that returns NotImplemented * when the lookup fails. */ static PyObject * -vectorcall_maybe(PyThreadState *tstate, _Py_Identifier *name, +vectorcall_maybe(PyThreadState *tstate, PyObject *name, PyObject *const *args, Py_ssize_t nargs) { assert(nargs >= 1); @@ -1779,7 +1760,8 @@ static PyObject * class_name(PyObject *cls) { PyObject *name; - if (_PyObject_LookupAttrId(cls, &PyId___name__, &name) == 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + if (_PyObject_LookupAttr(cls, attr, &name) == 0) { name = PyObject_Repr(cls); } return name; @@ -2102,8 +2084,8 @@ mro_invoke(PyTypeObject *type) if (custom) { int unbound; - PyObject *mro_meth = lookup_method((PyObject *)type, &PyId_mro, - &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(mro); + PyObject *mro_meth = lookup_method((PyObject *)type, attr, &unbound); if (mro_meth == NULL) return NULL; mro_result = call_unbound_noarg(unbound, mro_meth, (PyObject *)type); @@ -2318,7 +2300,8 @@ get_dict_descriptor(PyTypeObject *type) { PyObject *descr; - descr = _PyType_LookupId(type, &PyId___dict__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + descr = _PyType_Lookup(type, attr); if (descr == NULL || !PyDescr_IsData(descr)) return NULL; @@ -2561,13 +2544,15 @@ type_new_visit_slots(type_new_ctx *ctx) { PyObject *slots = ctx->slots; Py_ssize_t nslot = ctx->nslot; + PyObject *__dict__ = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *__weakref__ = _Py_GET_GLOBAL_IDENTIFIER(__weakref__); for (Py_ssize_t i = 0; i < nslot; i++) { PyObject *name = PyTuple_GET_ITEM(slots, i); if (!valid_identifier(name)) { return -1; } assert(PyUnicode_Check(name)); - if (_PyUnicode_EqualToASCIIId(name, &PyId___dict__)) { + if (_PyUnicode_Equal(name, __dict__)) { if (!ctx->may_add_dict || ctx->add_dict != 0) { PyErr_SetString(PyExc_TypeError, "__dict__ slot disallowed: " @@ -2576,7 +2561,7 @@ type_new_visit_slots(type_new_ctx *ctx) } ctx->add_dict++; } - if (_PyUnicode_EqualToASCIIId(name, &PyId___weakref__)) { + if (_PyUnicode_Equal(name, __weakref__)) { if (!ctx->may_add_weak || ctx->add_weak != 0) { PyErr_SetString(PyExc_TypeError, "__weakref__ slot disallowed: " @@ -2608,12 +2593,14 @@ type_new_copy_slots(type_new_ctx *ctx, PyObject *dict) } Py_ssize_t j = 0; + PyObject *__dict__ = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *__weakref__ = _Py_GET_GLOBAL_IDENTIFIER(__weakref__); + PyObject *__qualname__ = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + PyObject *__classcell__ = _Py_GET_GLOBAL_IDENTIFIER(__classcell__); for (Py_ssize_t i = 0; i < nslot; i++) { PyObject *slot = PyTuple_GET_ITEM(slots, i); - if ((ctx->add_dict && - _PyUnicode_EqualToASCIIId(slot, &PyId___dict__)) || - (ctx->add_weak && - _PyUnicode_EqualToASCIIString(slot, "__weakref__"))) + if ((ctx->add_dict && _PyUnicode_Equal(slot, __dict__)) || + (ctx->add_weak && _PyUnicode_Equal(slot, __weakref__))) { continue; } @@ -2632,8 +2619,8 @@ type_new_copy_slots(type_new_ctx *ctx, PyObject *dict) /* CPython inserts __qualname__ and __classcell__ (when needed) into the namespace when creating a class. They will be deleted below so won't act as class variables. */ - if (!_PyUnicode_EqualToASCIIId(slot, &PyId___qualname__) && - !_PyUnicode_EqualToASCIIId(slot, &PyId___classcell__)) + if (!_PyUnicode_Equal(slot, __qualname__) && + !_PyUnicode_Equal(slot, __classcell__)) { PyErr_Format(PyExc_ValueError, "%R in __slots__ conflicts with class variable", @@ -2828,7 +2815,8 @@ type_new_set_name(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_set_module(PyTypeObject *type) { - int r = _PyDict_ContainsId(type->tp_dict, &PyId___module__); + PyObject *module_str = _Py_GET_GLOBAL_IDENTIFIER(__module__); + int r = PyDict_Contains(type->tp_dict, module_str); if (r < 0) { return -1; } @@ -2841,7 +2829,8 @@ type_new_set_module(PyTypeObject *type) return 0; } - PyObject *module = _PyDict_GetItemIdWithError(globals, &PyId___name__); + PyObject *__name__ = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *module = PyDict_GetItemWithError(globals, __name__); if (module == NULL) { if (PyErr_Occurred()) { return -1; @@ -2849,7 +2838,7 @@ type_new_set_module(PyTypeObject *type) return 0; } - if (_PyDict_SetItemId(type->tp_dict, &PyId___module__, module) < 0) { + if (PyDict_SetItem(type->tp_dict, module_str, module) < 0) { return -1; } return 0; @@ -2862,8 +2851,8 @@ static int type_new_set_ht_name(PyTypeObject *type) { PyHeapTypeObject *et = (PyHeapTypeObject *)type; - PyObject *qualname = _PyDict_GetItemIdWithError(type->tp_dict, - &PyId___qualname__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + PyObject *qualname = PyDict_GetItemWithError(type->tp_dict, attr); if (qualname != NULL) { if (!PyUnicode_Check(qualname)) { PyErr_Format(PyExc_TypeError, @@ -2872,7 +2861,7 @@ type_new_set_ht_name(PyTypeObject *type) return -1; } et->ht_qualname = Py_NewRef(qualname); - if (_PyDict_DelItemId(type->tp_dict, &PyId___qualname__) < 0) { + if (PyDict_DelItem(type->tp_dict, attr) < 0) { return -1; } } @@ -2892,7 +2881,8 @@ type_new_set_ht_name(PyTypeObject *type) static int type_new_set_doc(PyTypeObject *type) { - PyObject *doc = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + PyObject *doc = PyDict_GetItemWithError(type->tp_dict, attr); if (doc == NULL) { if (PyErr_Occurred()) { return -1; @@ -2925,9 +2915,9 @@ type_new_set_doc(PyTypeObject *type) static int -type_new_staticmethod(PyTypeObject *type, _Py_Identifier *attr_id) +type_new_staticmethod(PyTypeObject *type, PyObject *attr) { - PyObject *func = _PyDict_GetItemIdWithError(type->tp_dict, attr_id); + PyObject *func = PyDict_GetItemWithError(type->tp_dict, attr); if (func == NULL) { if (PyErr_Occurred()) { return -1; @@ -2942,7 +2932,7 @@ type_new_staticmethod(PyTypeObject *type, _Py_Identifier *attr_id) if (static_func == NULL) { return -1; } - if (_PyDict_SetItemId(type->tp_dict, attr_id, static_func) < 0) { + if (PyDict_SetItem(type->tp_dict, attr, static_func) < 0) { Py_DECREF(static_func); return -1; } @@ -2952,9 +2942,9 @@ type_new_staticmethod(PyTypeObject *type, _Py_Identifier *attr_id) static int -type_new_classmethod(PyTypeObject *type, _Py_Identifier *attr_id) +type_new_classmethod(PyTypeObject *type, PyObject *attr) { - PyObject *func = _PyDict_GetItemIdWithError(type->tp_dict, attr_id); + PyObject *func = PyDict_GetItemWithError(type->tp_dict, attr); if (func == NULL) { if (PyErr_Occurred()) { return -1; @@ -2970,7 +2960,7 @@ type_new_classmethod(PyTypeObject *type, _Py_Identifier *attr_id) return -1; } - if (_PyDict_SetItemId(type->tp_dict, attr_id, method) < 0) { + if (PyDict_SetItem(type->tp_dict, attr, method) < 0) { Py_DECREF(method); return -1; } @@ -3061,8 +3051,8 @@ type_new_set_slots(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_set_classcell(PyTypeObject *type) { - PyObject *cell = _PyDict_GetItemIdWithError(type->tp_dict, - &PyId___classcell__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__classcell__); + PyObject *cell = PyDict_GetItemWithError(type->tp_dict, attr); if (cell == NULL) { if (PyErr_Occurred()) { return -1; @@ -3079,7 +3069,7 @@ type_new_set_classcell(PyTypeObject *type) } (void)PyCell_Set(cell, (PyObject *) type); - if (_PyDict_DelItemId(type->tp_dict, &PyId___classcell__) < 0) { + if (PyDict_DelItem(type->tp_dict, attr) < 0) { return -1; } return 0; @@ -3107,16 +3097,19 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type) /* Special-case __new__: if it's a plain function, make it a static function */ - if (type_new_staticmethod(type, &PyId___new__) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + if (type_new_staticmethod(type, attr) < 0) { return -1; } /* Special-case __init_subclass__ and __class_getitem__: if they are plain functions, make them classmethods */ - if (type_new_classmethod(type, &PyId___init_subclass__) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__init_subclass__); + if (type_new_classmethod(type, attr) < 0) { return -1; } - if (type_new_classmethod(type, &PyId___class_getitem__) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__class_getitem__); + if (type_new_classmethod(type, attr) < 0) { return -1; } @@ -3136,8 +3129,8 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_get_slots(type_new_ctx *ctx, PyObject *dict) { - _Py_IDENTIFIER(__slots__); - PyObject *slots = _PyDict_GetItemIdWithError(dict, &PyId___slots__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__slots__); + PyObject *slots = PyDict_GetItemWithError(dict, attr); if (slots == NULL) { if (PyErr_Occurred()) { return -1; @@ -3260,15 +3253,14 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type) return 0; } - _Py_IDENTIFIER(__mro_entries__); for (Py_ssize_t i = 0; i < nbases; i++) { PyObject *base = PyTuple_GET_ITEM(ctx->bases, i); if (PyType_Check(base)) { continue; } PyObject *mro_entries; - if (_PyObject_LookupAttrId(base, &PyId___mro_entries__, - &mro_entries) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__mro_entries__); + if (_PyObject_LookupAttr(base, attr, &mro_entries) < 0) { return -1; } if (mro_entries != NULL) { @@ -3403,7 +3395,7 @@ PyObject * PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) { PyHeapTypeObject *res; - PyObject *modname; + PyObject *modname, *attr; PyTypeObject *type, *base; int r; @@ -3617,7 +3609,8 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) PyObject *__doc__ = PyUnicode_FromString(_PyType_DocWithoutSignature(type->tp_name, type->tp_doc)); if (!__doc__) goto fail; - r = _PyDict_SetItemId(type->tp_dict, &PyId___doc__, __doc__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + r = PyDict_SetItem(type->tp_dict, attr, __doc__); Py_DECREF(__doc__); if (r < 0) goto fail; @@ -3635,7 +3628,8 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) } /* Set type.__module__ */ - r = _PyDict_ContainsId(type->tp_dict, &PyId___module__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + r = PyDict_Contains(type->tp_dict, attr); if (r < 0) { goto fail; } @@ -3647,7 +3641,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) if (modname == NULL) { goto fail; } - r = _PyDict_SetItemId(type->tp_dict, &PyId___module__, modname); + r = PyDict_SetItem(type->tp_dict, attr, modname); Py_DECREF(modname); if (r != 0) goto fail; @@ -4227,13 +4221,13 @@ merge_class_dict(PyObject *dict, PyObject *aclass) { PyObject *classdict; PyObject *bases; - _Py_IDENTIFIER(__bases__); assert(PyDict_Check(dict)); assert(aclass); /* Merge in the type's dict (if any). */ - if (_PyObject_LookupAttrId(aclass, &PyId___dict__, &classdict) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + if (_PyObject_LookupAttr(aclass, attr, &classdict) < 0) { return -1; } if (classdict != NULL) { @@ -4244,7 +4238,8 @@ merge_class_dict(PyObject *dict, PyObject *aclass) } /* Recursively merge in the base types' (if any) dicts. */ - if (_PyObject_LookupAttrId(aclass, &PyId___bases__, &bases) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__bases__); + if (_PyObject_LookupAttr(aclass, attr, &bases) < 0) { return -1; } if (bases != NULL) { @@ -4642,7 +4637,8 @@ object_repr(PyObject *self) Py_XDECREF(mod); return NULL; } - if (mod != NULL && !_PyUnicode_EqualToASCIIId(mod, &PyId_builtins)) + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(builtins); + if (mod != NULL && !_PyUnicode_Equal(mod, attr)) rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self); else rtn = PyUnicode_FromFormat("<%s object at %p>", @@ -4935,14 +4931,9 @@ static PyGetSetDef object_getsets[] = { static PyObject * import_copyreg(void) { - PyObject *copyreg_str; PyObject *copyreg_module; - _Py_IDENTIFIER(copyreg); + PyObject *copyreg_str = _Py_GET_GLOBAL_IDENTIFIER(copyreg); - copyreg_str = _PyUnicode_FromId(&PyId_copyreg); - if (copyreg_str == NULL) { - return NULL; - } /* Try to fetch cached copy of copyreg from sys.modules first in an attempt to avoid the import overhead. Previously this was implemented by storing a reference to the cached module in a static variable, but @@ -4963,13 +4954,12 @@ _PyType_GetSlotNames(PyTypeObject *cls) { PyObject *copyreg; PyObject *slotnames; - _Py_IDENTIFIER(__slotnames__); - _Py_IDENTIFIER(_slotnames); assert(PyType_Check(cls)); /* Get the slot names from the cache in the class if possible. */ - slotnames = _PyDict_GetItemIdWithError(cls->tp_dict, &PyId___slotnames__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__slotnames__); + slotnames = PyDict_GetItemWithError(cls->tp_dict, attr); if (slotnames != NULL) { if (slotnames != Py_None && !PyList_Check(slotnames)) { PyErr_Format(PyExc_TypeError, @@ -4995,8 +4985,8 @@ _PyType_GetSlotNames(PyTypeObject *cls) /* Use _slotnames function from the copyreg module to find the slots by this class and its bases. This function will cache the result in __slotnames__. */ - slotnames = _PyObject_CallMethodIdOneArg(copyreg, &PyId__slotnames, - (PyObject *)cls); + attr = _Py_GET_GLOBAL_IDENTIFIER(_slotnames); + slotnames = PyObject_CallMethodOneArg(copyreg, attr, (PyObject *)cls); Py_DECREF(copyreg); if (slotnames == NULL) return NULL; @@ -5016,9 +5006,9 @@ _PyObject_GetState(PyObject *obj, int required) { PyObject *state; PyObject *getstate; - _Py_IDENTIFIER(__getstate__); - if (_PyObject_LookupAttrId(obj, &PyId___getstate__, &getstate) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getstate__); + if (_PyObject_LookupAttr(obj, attr, &getstate) < 0) { return NULL; } if (getstate == NULL) { @@ -5154,8 +5144,6 @@ static int _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) { PyObject *getnewargs, *getnewargs_ex; - _Py_IDENTIFIER(__getnewargs_ex__); - _Py_IDENTIFIER(__getnewargs__); if (args == NULL || kwargs == NULL) { PyErr_BadInternalCall(); @@ -5164,7 +5152,8 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* We first attempt to fetch the arguments for __new__ by calling __getnewargs_ex__ on the object. */ - getnewargs_ex = _PyObject_LookupSpecialId(obj, &PyId___getnewargs_ex__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getnewargs_ex__); + getnewargs_ex = _PyObject_LookupSpecial(obj, attr); if (getnewargs_ex != NULL) { PyObject *newargs = _PyObject_CallNoArgs(getnewargs_ex); Py_DECREF(getnewargs_ex); @@ -5217,7 +5206,8 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* The object does not have __getnewargs_ex__ so we fallback on using __getnewargs__ instead. */ - getnewargs = _PyObject_LookupSpecialId(obj, &PyId___getnewargs__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__getnewargs__); + getnewargs = _PyObject_LookupSpecial(obj, attr); if (getnewargs != NULL) { *args = _PyObject_CallNoArgs(getnewargs); Py_DECREF(getnewargs); @@ -5270,10 +5260,8 @@ _PyObject_GetItemsIter(PyObject *obj, PyObject **listitems, Py_INCREF(*dictitems); } else { - PyObject *items; - _Py_IDENTIFIER(items); - - items = _PyObject_CallMethodIdNoArgs(obj, &PyId_items); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *items = PyObject_CallMethodNoArgs(obj, attr); if (items == NULL) { Py_CLEAR(*listitems); return -1; @@ -5317,12 +5305,12 @@ reduce_newobj(PyObject *obj) } hasargs = (args != NULL); if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) { - _Py_IDENTIFIER(__newobj__); PyObject *cls; Py_ssize_t i, n; Py_XDECREF(kwargs); - newobj = _PyObject_GetAttrId(copyreg, &PyId___newobj__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__newobj__); + newobj = PyObject_GetAttr(copyreg, attr); Py_DECREF(copyreg); if (newobj == NULL) { Py_XDECREF(args); @@ -5346,9 +5334,8 @@ reduce_newobj(PyObject *obj) Py_XDECREF(args); } else if (args != NULL) { - _Py_IDENTIFIER(__newobj_ex__); - - newobj = _PyObject_GetAttrId(copyreg, &PyId___newobj_ex__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__newobj_ex__); + newobj = PyObject_GetAttr(copyreg, attr); Py_DECREF(copyreg); if (newobj == NULL) { Py_DECREF(args); @@ -5454,17 +5441,16 @@ object___reduce_ex___impl(PyObject *self, int protocol) { static PyObject *objreduce; PyObject *reduce, *res; - _Py_IDENTIFIER(__reduce__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__reduce__); if (objreduce == NULL) { - objreduce = _PyDict_GetItemIdWithError(PyBaseObject_Type.tp_dict, - &PyId___reduce__); + objreduce = PyDict_GetItemWithError(PyBaseObject_Type.tp_dict, attr); if (objreduce == NULL && PyErr_Occurred()) { return NULL; } } - if (_PyObject_LookupAttrId(self, &PyId___reduce__, &reduce) < 0) { + if (_PyObject_LookupAttr(self, attr, &reduce) < 0) { return NULL; } if (reduce != NULL) { @@ -5472,7 +5458,7 @@ object___reduce_ex___impl(PyObject *self, int protocol) int override; cls = (PyObject *) Py_TYPE(self); - clsreduce = _PyObject_GetAttrId(cls, &PyId___reduce__); + clsreduce = PyObject_GetAttr(cls, attr); if (clsreduce == NULL) { Py_DECREF(reduce); return NULL; @@ -5580,7 +5566,8 @@ object___dir___impl(PyObject *self) PyObject *itsclass = NULL; /* Get __dict__ (which may or may not be a real dict...) */ - if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + if (_PyObject_LookupAttr(self, attr, &dict) < 0) { return NULL; } if (dict == NULL) { @@ -5601,7 +5588,8 @@ object___dir___impl(PyObject *self) goto error; /* Merge in attrs reachable from its class. */ - if (_PyObject_LookupAttrId(self, &PyId___class__, &itsclass) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + if (_PyObject_LookupAttr(self, attr, &itsclass) < 0) { goto error; } /* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no @@ -5867,12 +5855,13 @@ static int overrides_hash(PyTypeObject *type) { PyObject *dict = type->tp_dict; - _Py_IDENTIFIER(__eq__); assert(dict != NULL); - int r = _PyDict_ContainsId(dict, &PyId___eq__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__eq__); + int r = PyDict_Contains(dict, attr); if (r == 0) { - r = _PyDict_ContainsId(dict, &PyId___hash__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__hash__); + r = PyDict_Contains(dict, attr); } return r; } @@ -6187,7 +6176,8 @@ type_ready_set_dict(PyTypeObject *type) static int type_dict_set_doc(PyTypeObject *type) { - int r = _PyDict_ContainsId(type->tp_dict, &PyId___doc__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + int r = PyDict_Contains(type->tp_dict, attr); if (r < 0) { return -1; } @@ -6203,14 +6193,14 @@ type_dict_set_doc(PyTypeObject *type) return -1; } - if (_PyDict_SetItemId(type->tp_dict, &PyId___doc__, doc) < 0) { + if (PyDict_SetItem(type->tp_dict, attr, doc) < 0) { Py_DECREF(doc); return -1; } Py_DECREF(doc); } else { - if (_PyDict_SetItemId(type->tp_dict, &PyId___doc__, Py_None) < 0) { + if (PyDict_SetItem(type->tp_dict, attr, Py_None) < 0) { return -1; } } @@ -6358,7 +6348,8 @@ type_ready_set_hash(PyTypeObject *type) return 0; } - int r = _PyDict_ContainsId(type->tp_dict, &PyId___hash__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__hash__); + int r = PyDict_Contains(type->tp_dict, attr); if (r < 0) { return -1; } @@ -6366,7 +6357,7 @@ type_ready_set_hash(PyTypeObject *type) return 0; } - if (_PyDict_SetItemId(type->tp_dict, &PyId___hash__, Py_None) < 0) { + if (PyDict_SetItem(type->tp_dict, attr, Py_None) < 0) { return -1; } type->tp_hash = PyObject_HashNotImplemented; @@ -7183,7 +7174,8 @@ static struct PyMethodDef tp_new_methoddef[] = { static int add_tp_new_wrapper(PyTypeObject *type) { - int r = _PyDict_ContainsId(type->tp_dict, &PyId___new__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + int r = PyDict_Contains(type->tp_dict, attr); if (r > 0) { return 0; } @@ -7195,7 +7187,7 @@ add_tp_new_wrapper(PyTypeObject *type) if (func == NULL) { return -1; } - r = _PyDict_SetItemId(type->tp_dict, &PyId___new__, func); + r = PyDict_SetItem(type->tp_dict, attr, func); Py_DECREF(func); return r; } @@ -7203,33 +7195,33 @@ add_tp_new_wrapper(PyTypeObject *type) /* Slot wrappers that call the corresponding __foo__ slot. See comments below at override_slots() for more explanation. */ -#define SLOT0(FUNCNAME, OPSTR) \ +#define SLOT0(FUNCNAME, DUNDER) \ static PyObject * \ FUNCNAME(PyObject *self) \ { \ PyObject* stack[1] = {self}; \ - _Py_static_string(id, OPSTR); \ - return vectorcall_method(&id, stack, 1); \ + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(DUNDER); \ + return vectorcall_method(attr, stack, 1); \ } -#define SLOT1(FUNCNAME, OPSTR, ARG1TYPE) \ +#define SLOT1(FUNCNAME, DUNDER, ARG1TYPE) \ static PyObject * \ FUNCNAME(PyObject *self, ARG1TYPE arg1) \ { \ PyObject* stack[2] = {self, arg1}; \ - _Py_static_string(id, OPSTR); \ - return vectorcall_method(&id, stack, 2); \ + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(DUNDER); \ + return vectorcall_method(attr, stack, 2); \ } /* Boolean helper for SLOT1BINFULL(). right.__class__ is a nontrivial subclass of left.__class__. */ static int -method_is_overloaded(PyObject *left, PyObject *right, struct _Py_Identifier *name) +method_is_overloaded(PyObject *left, PyObject *right, PyObject *name) { PyObject *a, *b; int ok; - if (_PyObject_LookupAttrId((PyObject *)(Py_TYPE(right)), name, &b) < 0) { + if (_PyObject_LookupAttr((PyObject *)(Py_TYPE(right)), name, &b) < 0) { return -1; } if (b == NULL) { @@ -7237,7 +7229,7 @@ method_is_overloaded(PyObject *left, PyObject *right, struct _Py_Identifier *nam return 0; } - if (_PyObject_LookupAttrId((PyObject *)(Py_TYPE(left)), name, &a) < 0) { + if (_PyObject_LookupAttr((PyObject *)(Py_TYPE(left)), name, &a) < 0) { Py_DECREF(b); return -1; } @@ -7254,14 +7246,14 @@ method_is_overloaded(PyObject *left, PyObject *right, struct _Py_Identifier *nam } -#define SLOT1BINFULL(FUNCNAME, TESTFUNC, SLOTNAME, OPSTR, ROPSTR) \ +#define SLOT1BINFULL(FUNCNAME, TESTFUNC, SLOTNAME, DUNDER, RDUNDER) \ static PyObject * \ FUNCNAME(PyObject *self, PyObject *other) \ { \ PyObject* stack[2]; \ PyThreadState *tstate = _PyThreadState_GET(); \ - _Py_static_string(op_id, OPSTR); \ - _Py_static_string(rop_id, ROPSTR); \ + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(DUNDER); \ + PyObject *rattr = _Py_GET_GLOBAL_IDENTIFIER(RDUNDER); \ int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \ Py_TYPE(other)->tp_as_number != NULL && \ Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \ @@ -7269,14 +7261,14 @@ FUNCNAME(PyObject *self, PyObject *other) \ Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \ PyObject *r; \ if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \ - int ok = method_is_overloaded(self, other, &rop_id); \ + int ok = method_is_overloaded(self, other, rattr); \ if (ok < 0) { \ return NULL; \ } \ if (ok) { \ stack[0] = other; \ stack[1] = self; \ - r = vectorcall_maybe(tstate, &rop_id, stack, 2); \ + r = vectorcall_maybe(tstate, rattr, stack, 2); \ if (r != Py_NotImplemented) \ return r; \ Py_DECREF(r); \ @@ -7285,7 +7277,7 @@ FUNCNAME(PyObject *self, PyObject *other) \ } \ stack[0] = self; \ stack[1] = other; \ - r = vectorcall_maybe(tstate, &op_id, stack, 2); \ + r = vectorcall_maybe(tstate, attr, stack, 2); \ if (r != Py_NotImplemented || \ Py_IS_TYPE(other, Py_TYPE(self))) \ return r; \ @@ -7294,19 +7286,20 @@ FUNCNAME(PyObject *self, PyObject *other) \ if (do_other) { \ stack[0] = other; \ stack[1] = self; \ - return vectorcall_maybe(tstate, &rop_id, stack, 2); \ + return vectorcall_maybe(tstate, rattr, stack, 2); \ } \ Py_RETURN_NOTIMPLEMENTED; \ } -#define SLOT1BIN(FUNCNAME, SLOTNAME, OPSTR, ROPSTR) \ - SLOT1BINFULL(FUNCNAME, FUNCNAME, SLOTNAME, OPSTR, ROPSTR) +#define SLOT1BIN(FUNCNAME, SLOTNAME, DUNDER, RDUNDER) \ + SLOT1BINFULL(FUNCNAME, FUNCNAME, SLOTNAME, DUNDER, RDUNDER) static Py_ssize_t slot_sq_length(PyObject *self) { PyObject* stack[1] = {self}; - PyObject *res = vectorcall_method(&PyId___len__, stack, 1); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__len__); + PyObject *res = vectorcall_method(attr, stack, 1); Py_ssize_t len; if (res == NULL) @@ -7338,7 +7331,8 @@ slot_sq_item(PyObject *self, Py_ssize_t i) return NULL; } PyObject *stack[2] = {self, ival}; - PyObject *retval = vectorcall_method(&PyId___getitem__, stack, 2); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getitem__); + PyObject *retval = vectorcall_method(attr, stack, 2); Py_DECREF(ival); return retval; } @@ -7358,11 +7352,13 @@ slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value) stack[0] = self; stack[1] = index_obj; if (value == NULL) { - res = vectorcall_method(&PyId___delitem__, stack, 2); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__delitem__); + res = vectorcall_method(attr, stack, 2); } else { stack[2] = value; - res = vectorcall_method(&PyId___setitem__, stack, 3); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + res = vectorcall_method(attr, stack, 3); } Py_DECREF(index_obj); @@ -7379,9 +7375,9 @@ slot_sq_contains(PyObject *self, PyObject *value) PyThreadState *tstate = _PyThreadState_GET(); PyObject *func, *res; int result = -1, unbound; - _Py_IDENTIFIER(__contains__); - func = lookup_maybe_method(self, &PyId___contains__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__contains__); + func = lookup_maybe_method(self, attr, &unbound); if (func == Py_None) { Py_DECREF(func); PyErr_Format(PyExc_TypeError, @@ -7408,7 +7404,7 @@ slot_sq_contains(PyObject *self, PyObject *value) #define slot_mp_length slot_sq_length -SLOT1(slot_mp_subscript, "__getitem__", PyObject *) +SLOT1(slot_mp_subscript, __getitem__, PyObject *) static int slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value) @@ -7419,11 +7415,13 @@ slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value) stack[0] = self; stack[1] = key; if (value == NULL) { - res = vectorcall_method(&PyId___delitem__, stack, 2); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__delitem__); + res = vectorcall_method(attr, stack, 2); } else { stack[2] = value; - res = vectorcall_method(&PyId___setitem__, stack, 3); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + res = vectorcall_method(attr, stack, 3); } if (res == NULL) @@ -7432,23 +7430,20 @@ slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value) return 0; } -SLOT1BIN(slot_nb_add, nb_add, "__add__", "__radd__") -SLOT1BIN(slot_nb_subtract, nb_subtract, "__sub__", "__rsub__") -SLOT1BIN(slot_nb_multiply, nb_multiply, "__mul__", "__rmul__") -SLOT1BIN(slot_nb_matrix_multiply, nb_matrix_multiply, "__matmul__", "__rmatmul__") -SLOT1BIN(slot_nb_remainder, nb_remainder, "__mod__", "__rmod__") -SLOT1BIN(slot_nb_divmod, nb_divmod, "__divmod__", "__rdivmod__") +SLOT1BIN(slot_nb_add, nb_add, __add__, __radd__) +SLOT1BIN(slot_nb_subtract, nb_subtract, __sub__, __rsub__) +SLOT1BIN(slot_nb_multiply, nb_multiply, __mul__, __rmul__) +SLOT1BIN(slot_nb_matrix_multiply, nb_matrix_multiply, __matmul__, __rmatmul__) +SLOT1BIN(slot_nb_remainder, nb_remainder, __mod__, __rmod__) +SLOT1BIN(slot_nb_divmod, nb_divmod, __divmod__, __rdivmod__) static PyObject *slot_nb_power(PyObject *, PyObject *, PyObject *); -SLOT1BINFULL(slot_nb_power_binary, slot_nb_power, - nb_power, "__pow__", "__rpow__") +SLOT1BINFULL(slot_nb_power_binary, slot_nb_power, nb_power, __pow__, __rpow__) static PyObject * slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus) { - _Py_IDENTIFIER(__pow__); - if (modulus == Py_None) return slot_nb_power_binary(self, other); /* Three-arg power doesn't use __rpow__. But ternary_op @@ -7457,14 +7452,15 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus) if (Py_TYPE(self)->tp_as_number != NULL && Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) { PyObject* stack[3] = {self, other, modulus}; - return vectorcall_method(&PyId___pow__, stack, 3); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__pow__); + return vectorcall_method(attr, stack, 3); } Py_RETURN_NOTIMPLEMENTED; } -SLOT0(slot_nb_negative, "__neg__") -SLOT0(slot_nb_positive, "__pos__") -SLOT0(slot_nb_absolute, "__abs__") +SLOT0(slot_nb_negative, __neg__) +SLOT0(slot_nb_positive, __pos__) +SLOT0(slot_nb_absolute, __abs__) static int slot_nb_bool(PyObject *self) @@ -7472,15 +7468,16 @@ slot_nb_bool(PyObject *self) PyObject *func, *value; int result, unbound; int using_len = 0; - _Py_IDENTIFIER(__bool__); - func = lookup_maybe_method(self, &PyId___bool__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__bool__); + func = lookup_maybe_method(self, attr, &unbound); if (func == NULL) { if (PyErr_Occurred()) { return -1; } - func = lookup_maybe_method(self, &PyId___len__, &unbound); + attr = _Py_GET_GLOBAL_IDENTIFIER(__len__); + func = lookup_maybe_method(self, attr, &unbound); if (func == NULL) { if (PyErr_Occurred()) { return -1; @@ -7523,53 +7520,53 @@ slot_nb_bool(PyObject *self) static PyObject * slot_nb_index(PyObject *self) { - _Py_IDENTIFIER(__index__); PyObject *stack[1] = {self}; - return vectorcall_method(&PyId___index__, stack, 1); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__index__); + return vectorcall_method(attr, stack, 1); } -SLOT0(slot_nb_invert, "__invert__") -SLOT1BIN(slot_nb_lshift, nb_lshift, "__lshift__", "__rlshift__") -SLOT1BIN(slot_nb_rshift, nb_rshift, "__rshift__", "__rrshift__") -SLOT1BIN(slot_nb_and, nb_and, "__and__", "__rand__") -SLOT1BIN(slot_nb_xor, nb_xor, "__xor__", "__rxor__") -SLOT1BIN(slot_nb_or, nb_or, "__or__", "__ror__") +SLOT0(slot_nb_invert, __invert__) +SLOT1BIN(slot_nb_lshift, nb_lshift, __lshift__, __rlshift__) +SLOT1BIN(slot_nb_rshift, nb_rshift, __rshift__, __rrshift__) +SLOT1BIN(slot_nb_and, nb_and, __and__, __rand__) +SLOT1BIN(slot_nb_xor, nb_xor, __xor__, __rxor__) +SLOT1BIN(slot_nb_or, nb_or, __or__, __ror__) -SLOT0(slot_nb_int, "__int__") -SLOT0(slot_nb_float, "__float__") -SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *) -SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *) -SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *) -SLOT1(slot_nb_inplace_matrix_multiply, "__imatmul__", PyObject *) -SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *) +SLOT0(slot_nb_int, __int__) +SLOT0(slot_nb_float, __float__) +SLOT1(slot_nb_inplace_add, __iadd__, PyObject *) +SLOT1(slot_nb_inplace_subtract, __isub__, PyObject *) +SLOT1(slot_nb_inplace_multiply, __imul__, PyObject *) +SLOT1(slot_nb_inplace_matrix_multiply, __imatmul__, PyObject *) +SLOT1(slot_nb_inplace_remainder, __imod__, PyObject *) /* Can't use SLOT1 here, because nb_inplace_power is ternary */ static PyObject * slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2) { PyObject *stack[2] = {self, arg1}; - _Py_IDENTIFIER(__ipow__); - return vectorcall_method(&PyId___ipow__, stack, 2); -} -SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *) -SLOT1(slot_nb_inplace_rshift, "__irshift__", PyObject *) -SLOT1(slot_nb_inplace_and, "__iand__", PyObject *) -SLOT1(slot_nb_inplace_xor, "__ixor__", PyObject *) -SLOT1(slot_nb_inplace_or, "__ior__", PyObject *) + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__ipow__); + return vectorcall_method(attr, stack, 2); +} +SLOT1(slot_nb_inplace_lshift, __ilshift__, PyObject *) +SLOT1(slot_nb_inplace_rshift, __irshift__, PyObject *) +SLOT1(slot_nb_inplace_and, __iand__, PyObject *) +SLOT1(slot_nb_inplace_xor, __ixor__, PyObject *) +SLOT1(slot_nb_inplace_or, __ior__, PyObject *) SLOT1BIN(slot_nb_floor_divide, nb_floor_divide, - "__floordiv__", "__rfloordiv__") -SLOT1BIN(slot_nb_true_divide, nb_true_divide, "__truediv__", "__rtruediv__") -SLOT1(slot_nb_inplace_floor_divide, "__ifloordiv__", PyObject *) -SLOT1(slot_nb_inplace_true_divide, "__itruediv__", PyObject *) + __floordiv__, __rfloordiv__) +SLOT1BIN(slot_nb_true_divide, nb_true_divide, __truediv__, __rtruediv__) +SLOT1(slot_nb_inplace_floor_divide, __ifloordiv__, PyObject *) +SLOT1(slot_nb_inplace_true_divide, __itruediv__, PyObject *) static PyObject * slot_tp_repr(PyObject *self) { PyObject *func, *res; - _Py_IDENTIFIER(__repr__); int unbound; - func = lookup_maybe_method(self, &PyId___repr__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__repr__); + func = lookup_maybe_method(self, attr, &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -7580,7 +7577,7 @@ slot_tp_repr(PyObject *self) Py_TYPE(self)->tp_name, self); } -SLOT0(slot_tp_str, "__str__") +SLOT0(slot_tp_str, __str__) static Py_hash_t slot_tp_hash(PyObject *self) @@ -7589,7 +7586,8 @@ slot_tp_hash(PyObject *self) Py_ssize_t h; int unbound; - func = lookup_maybe_method(self, &PyId___hash__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__hash__); + func = lookup_maybe_method(self, attr, &unbound); if (func == Py_None) { Py_DECREF(func); @@ -7634,10 +7632,10 @@ static PyObject * slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_IDENTIFIER(__call__); int unbound; - PyObject *meth = lookup_method(self, &PyId___call__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__call__); + PyObject *meth = lookup_method(self, attr, &unbound); if (meth == NULL) { return NULL; } @@ -7669,7 +7667,8 @@ static PyObject * slot_tp_getattro(PyObject *self, PyObject *name) { PyObject *stack[2] = {self, name}; - return vectorcall_method(&PyId___getattribute__, stack, 2); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getattribute__); + return vectorcall_method(attr, stack, 2); } static PyObject * @@ -7695,14 +7694,14 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) { PyTypeObject *tp = Py_TYPE(self); PyObject *getattr, *getattribute, *res; - _Py_IDENTIFIER(__getattr__); /* speed hack: we could use lookup_maybe, but that would resolve the method fully for each attribute lookup for classes with __getattr__, even when the attribute is present. So we use _PyType_Lookup and create the method only when needed, with call_attribute. */ - getattr = _PyType_LookupId(tp, &PyId___getattr__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getattr__); + getattr = _PyType_Lookup(tp, attr); if (getattr == NULL) { /* No __getattr__ hook: use a simpler dispatcher */ tp->tp_getattro = slot_tp_getattro; @@ -7714,7 +7713,8 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) __getattr__, even when self has the default __getattribute__ method. So we use _PyType_Lookup and create the method only when needed, with call_attribute. */ - getattribute = _PyType_LookupId(tp, &PyId___getattribute__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__getattribute__); + getattribute = _PyType_Lookup(tp, attr); if (getattribute == NULL || (Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) && ((PyWrapperDescrObject *)getattribute)->d_wrapped == @@ -7738,17 +7738,17 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) { PyObject *stack[3]; PyObject *res; - _Py_IDENTIFIER(__delattr__); - _Py_IDENTIFIER(__setattr__); stack[0] = self; stack[1] = name; if (value == NULL) { - res = vectorcall_method(&PyId___delattr__, stack, 2); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__delattr__); + res = vectorcall_method(attr, stack, 2); } else { stack[2] = value; - res = vectorcall_method(&PyId___setattr__, stack, 3); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setattr__); + res = vectorcall_method(attr, stack, 3); } if (res == NULL) return -1; @@ -7756,13 +7756,13 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) return 0; } -static _Py_Identifier name_op[] = { - _Py_static_string_init("__lt__"), - _Py_static_string_init("__le__"), - _Py_static_string_init("__eq__"), - _Py_static_string_init("__ne__"), - _Py_static_string_init("__gt__"), - _Py_static_string_init("__ge__"), +static PyObject *name_op[] = { + _Py_GET_GLOBAL_IDENTIFIER(__lt__), + _Py_GET_GLOBAL_IDENTIFIER(__le__), + _Py_GET_GLOBAL_IDENTIFIER(__eq__), + _Py_GET_GLOBAL_IDENTIFIER(__ne__), + _Py_GET_GLOBAL_IDENTIFIER(__gt__), + _Py_GET_GLOBAL_IDENTIFIER(__ge__), }; static PyObject * @@ -7771,7 +7771,7 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op) PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *func = lookup_maybe_method(self, &name_op[op], &unbound); + PyObject *func = lookup_maybe_method(self, name_op[op], &unbound); if (func == NULL) { PyErr_Clear(); Py_RETURN_NOTIMPLEMENTED; @@ -7788,9 +7788,9 @@ slot_tp_iter(PyObject *self) { int unbound; PyObject *func, *res; - _Py_IDENTIFIER(__iter__); - func = lookup_maybe_method(self, &PyId___iter__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__iter__); + func = lookup_maybe_method(self, attr, &unbound); if (func == Py_None) { Py_DECREF(func); PyErr_Format(PyExc_TypeError, @@ -7806,7 +7806,8 @@ slot_tp_iter(PyObject *self) } PyErr_Clear(); - func = lookup_maybe_method(self, &PyId___getitem__, &unbound); + attr = _Py_GET_GLOBAL_IDENTIFIER(__getitem__); + func = lookup_maybe_method(self, attr, &unbound); if (func == NULL) { PyErr_Format(PyExc_TypeError, "'%.200s' object is not iterable", @@ -7820,9 +7821,9 @@ slot_tp_iter(PyObject *self) static PyObject * slot_tp_iternext(PyObject *self) { - _Py_IDENTIFIER(__next__); PyObject *stack[1] = {self}; - return vectorcall_method(&PyId___next__, stack, 1); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__next__); + return vectorcall_method(attr, stack, 1); } static PyObject * @@ -7830,9 +7831,9 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type) { PyTypeObject *tp = Py_TYPE(self); PyObject *get; - _Py_IDENTIFIER(__get__); - get = _PyType_LookupId(tp, &PyId___get__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__get__); + get = _PyType_Lookup(tp, attr); if (get == NULL) { /* Avoid further slowdowns */ if (tp->tp_descr_get == slot_tp_descr_get) @@ -7852,17 +7853,17 @@ slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value) { PyObject* stack[3]; PyObject *res; - _Py_IDENTIFIER(__delete__); - _Py_IDENTIFIER(__set__); stack[0] = self; stack[1] = target; if (value == NULL) { - res = vectorcall_method(&PyId___delete__, stack, 2); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__delete__); + res = vectorcall_method(attr, stack, 2); } else { stack[2] = value; - res = vectorcall_method(&PyId___set__, stack, 3); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__set__); + res = vectorcall_method(attr, stack, 3); } if (res == NULL) return -1; @@ -7875,9 +7876,9 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds) { PyThreadState *tstate = _PyThreadState_GET(); - _Py_IDENTIFIER(__init__); int unbound; - PyObject *meth = lookup_method(self, &PyId___init__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__init__); + PyObject *meth = lookup_method(self, attr, &unbound); if (meth == NULL) { return -1; } @@ -7909,7 +7910,8 @@ slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); PyObject *func, *result; - func = _PyObject_GetAttrId((PyObject *)type, &PyId___new__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + func = PyObject_GetAttr((PyObject *)type, attr); if (func == NULL) { return NULL; } @@ -7922,7 +7924,6 @@ slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) static void slot_tp_finalize(PyObject *self) { - _Py_IDENTIFIER(__del__); int unbound; PyObject *del, *res; PyObject *error_type, *error_value, *error_traceback; @@ -7931,7 +7932,8 @@ slot_tp_finalize(PyObject *self) PyErr_Fetch(&error_type, &error_value, &error_traceback); /* Execute __del__ method, if any. */ - del = lookup_maybe_method(self, &PyId___del__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__del__); + del = lookup_maybe_method(self, attr, &unbound); if (del != NULL) { res = call_unbound_noarg(unbound, del, self); if (res == NULL) @@ -7950,9 +7952,9 @@ slot_am_await(PyObject *self) { int unbound; PyObject *func, *res; - _Py_IDENTIFIER(__await__); - func = lookup_maybe_method(self, &PyId___await__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__await__); + func = lookup_maybe_method(self, attr, &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -7969,9 +7971,9 @@ slot_am_aiter(PyObject *self) { int unbound; PyObject *func, *res; - _Py_IDENTIFIER(__aiter__); - func = lookup_maybe_method(self, &PyId___aiter__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__aiter__); + func = lookup_maybe_method(self, attr, &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -7988,9 +7990,9 @@ slot_am_anext(PyObject *self) { int unbound; PyObject *func, *res; - _Py_IDENTIFIER(__anext__); - func = lookup_maybe_method(self, &PyId___anext__, &unbound); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__anext__); + func = lookup_maybe_method(self, attr, &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -8621,8 +8623,9 @@ type_new_set_names(PyTypeObject *type) Py_ssize_t i = 0; PyObject *key, *value; + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__set_name__); while (PyDict_Next(names_to_set, &i, &key, &value)) { - PyObject *set_name = _PyObject_LookupSpecialId(value, &PyId___set_name__); + PyObject *set_name = _PyObject_LookupSpecial(value, attr); if (set_name == NULL) { if (PyErr_Occurred()) { goto error; @@ -8662,7 +8665,8 @@ type_new_init_subclass(PyTypeObject *type, PyObject *kwds) return -1; } - PyObject *func = _PyObject_GetAttrId(super, &PyId___init_subclass__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__init_subclass__); + PyObject *func = PyObject_GetAttr(super, attr); Py_DECREF(super); if (func == NULL) { return -1; @@ -8870,9 +8874,10 @@ super_getattro(PyObject *self, PyObject *name) /* We want __class__ to return the class of the super object (i.e. super, or a subclass), not the class of su->obj. */ + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); if (PyUnicode_Check(name) && PyUnicode_GET_LENGTH(name) == 9 && - _PyUnicode_EqualToASCIIId(name, &PyId___class__)) + _PyUnicode_Equal(name, attr)) goto skip; mro = starttype->tp_mro; @@ -8964,7 +8969,8 @@ supercheck(PyTypeObject *type, PyObject *obj) /* Try the slow way */ PyObject *class_attr; - if (_PyObject_LookupAttrId(obj, &PyId___class__, &class_attr) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + if (_PyObject_LookupAttr(obj, attr, &class_attr) < 0) { return NULL; } if (class_attr != NULL && @@ -9055,7 +9061,8 @@ super_init_without_args(PyFrameObject *f, PyCodeObject *co, assert((_PyLocals_GetKind(co->co_localspluskinds, i) & CO_FAST_FREE) != 0); PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); assert(PyUnicode_Check(name)); - if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + if (_PyUnicode_Equal(name, attr)) { PyObject *cell = _PyFrame_GetLocalsArray(f->f_frame)[i]; if (cell == NULL || !PyCell_Check(cell)) { PyErr_SetString(PyExc_RuntimeError, From 4e03f95145c3e4ea311c739a615634113bd917dc Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 10:14:00 -0700 Subject: [PATCH 030/115] Get rid of _Py_IDENTIFIER() in abstract.c. --- Objects/abstract.c | 60 ++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/Objects/abstract.c b/Objects/abstract.c index 627bbadb25ac227..1c0685bfe6ca9cc 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -92,7 +92,6 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) { PyObject *hint, *result; Py_ssize_t res; - _Py_IDENTIFIER(__length_hint__); if (_PyObject_HasLen(o)) { res = PyObject_Length(o); if (res < 0) { @@ -107,7 +106,8 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) return res; } } - hint = _PyObject_LookupSpecialId(o, &PyId___length_hint__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__length_hint__); + hint = _PyObject_LookupSpecial(o, attr); if (hint == NULL) { if (PyErr_Occurred()) { return -1; @@ -177,14 +177,14 @@ PyObject_GetItem(PyObject *o, PyObject *key) if (PyType_Check(o)) { PyObject *meth, *result; - _Py_IDENTIFIER(__class_getitem__); // Special case type[int], but disallow other types so str[int] fails if ((PyTypeObject*)o == &PyType_Type) { return Py_GenericAlias(o, key); } - if (_PyObject_LookupAttrId(o, &PyId___class_getitem__, &meth) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class_getitem__); + if (_PyObject_LookupAttr(o, attr, &meth) < 0) { return NULL; } if (meth) { @@ -770,7 +770,6 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) PyObject *meth; PyObject *empty = NULL; PyObject *result = NULL; - _Py_IDENTIFIER(__format__); if (format_spec != NULL && !PyUnicode_Check(format_spec)) { PyErr_Format(PyExc_SystemError, @@ -797,7 +796,8 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) } /* Find the (unbound!) __format__ method */ - meth = _PyObject_LookupSpecialId(obj, &PyId___format__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__format__); + meth = _PyObject_LookupSpecial(obj, attr); if (meth == NULL) { PyThreadState *tstate = _PyThreadState_GET(); if (!_PyErr_Occurred(tstate)) { @@ -1520,7 +1520,6 @@ PyNumber_Long(PyObject *o) PyNumberMethods *m; PyObject *trunc_func; Py_buffer view; - _Py_IDENTIFIER(__trunc__); if (o == NULL) { return null_error(); @@ -1562,7 +1561,8 @@ PyNumber_Long(PyObject *o) if (m && m->nb_index) { return PyNumber_Index(o); } - trunc_func = _PyObject_LookupSpecialId(o, &PyId___trunc__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__trunc__); + trunc_func = _PyObject_LookupSpecial(o, attr); if (trunc_func) { result = _PyObject_CallNoArgs(trunc_func); Py_DECREF(trunc_func); @@ -2401,12 +2401,12 @@ PyMapping_HasKey(PyObject *o, PyObject *key) a helper for PyMapping_Keys(), PyMapping_Items() and PyMapping_Values(). */ static PyObject * -method_output_as_list(PyObject *o, _Py_Identifier *meth_id) +method_output_as_list(PyObject *o, PyObject *meth) { PyObject *it, *result, *meth_output; assert(o != NULL); - meth_output = _PyObject_CallMethodIdNoArgs(o, meth_id); + meth_output = PyObject_CallMethodNoArgs(o, meth); if (meth_output == NULL || PyList_CheckExact(meth_output)) { return meth_output; } @@ -2417,7 +2417,7 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id) _PyErr_Format(tstate, PyExc_TypeError, "%.200s.%U() returned a non-iterable (type %.200s)", Py_TYPE(o)->tp_name, - _PyUnicode_FromId(meth_id), + meth, Py_TYPE(meth_output)->tp_name); } Py_DECREF(meth_output); @@ -2432,43 +2432,40 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id) PyObject * PyMapping_Keys(PyObject *o) { - _Py_IDENTIFIER(keys); - if (o == NULL) { return null_error(); } if (PyDict_CheckExact(o)) { return PyDict_Keys(o); } - return method_output_as_list(o, &PyId_keys); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(keys); + return method_output_as_list(o, attr); } PyObject * PyMapping_Items(PyObject *o) { - _Py_IDENTIFIER(items); - if (o == NULL) { return null_error(); } if (PyDict_CheckExact(o)) { return PyDict_Items(o); } - return method_output_as_list(o, &PyId_items); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + return method_output_as_list(o, attr); } PyObject * PyMapping_Values(PyObject *o) { - _Py_IDENTIFIER(values); - if (o == NULL) { return null_error(); } if (PyDict_CheckExact(o)) { return PyDict_Values(o); } - return method_output_as_list(o, &PyId_values); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(values); + return method_output_as_list(o, attr); } /* isinstance(), issubclass() */ @@ -2500,10 +2497,10 @@ PyMapping_Values(PyObject *o) static PyObject * abstract_get_bases(PyObject *cls) { - _Py_IDENTIFIER(__bases__); PyObject *bases; - (void)_PyObject_LookupAttrId(cls, &PyId___bases__, &bases); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__bases__); + (void)_PyObject_LookupAttr(cls, attr, &bases); if (bases != NULL && !PyTuple_Check(bases)) { Py_DECREF(bases); return NULL; @@ -2584,11 +2581,11 @@ object_isinstance(PyObject *inst, PyObject *cls) { PyObject *icls; int retval; - _Py_IDENTIFIER(__class__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); if (PyType_Check(cls)) { retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls); if (retval == 0) { - retval = _PyObject_LookupAttrId(inst, &PyId___class__, &icls); + retval = _PyObject_LookupAttr(inst, attr, &icls); if (icls != NULL) { if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) { retval = PyType_IsSubtype( @@ -2606,7 +2603,7 @@ object_isinstance(PyObject *inst, PyObject *cls) if (!check_class(cls, "isinstance() arg 2 must be a type, a tuple of types, or a union")) return -1; - retval = _PyObject_LookupAttrId(inst, &PyId___class__, &icls); + retval = _PyObject_LookupAttr(inst, attr, &icls); if (icls != NULL) { retval = abstract_issubclass(icls, cls); Py_DECREF(icls); @@ -2619,8 +2616,6 @@ object_isinstance(PyObject *inst, PyObject *cls) static int object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls) { - _Py_IDENTIFIER(__instancecheck__); - /* Quick test for an exact match */ if (Py_IS_TYPE(inst, (PyTypeObject *)cls)) { return 1; @@ -2651,7 +2646,8 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls return r; } - PyObject *checker = _PyObject_LookupSpecialId(cls, &PyId___instancecheck__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__instancecheck__); + PyObject *checker = _PyObject_LookupSpecial(cls, attr); if (checker != NULL) { if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) { Py_DECREF(checker); @@ -2710,7 +2706,6 @@ recursive_issubclass(PyObject *derived, PyObject *cls) static int object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) { - _Py_IDENTIFIER(__subclasscheck__); PyObject *checker; /* We know what type's __subclasscheck__ does. */ @@ -2739,7 +2734,8 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) return r; } - checker = _PyObject_LookupSpecialId(cls, &PyId___subclasscheck__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__subclasscheck__); + checker = _PyObject_LookupSpecial(cls, attr); if (checker != NULL) { int ok = -1; if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) { @@ -2874,7 +2870,6 @@ PyIter_Next(PyObject *iter) PySendResult PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result) { - _Py_IDENTIFIER(send); assert(arg != NULL); assert(result != NULL); if (Py_TYPE(iter)->tp_as_async && Py_TYPE(iter)->tp_as_async->am_send) { @@ -2886,7 +2881,8 @@ PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result) *result = Py_TYPE(iter)->tp_iternext(iter); } else { - *result = _PyObject_CallMethodIdOneArg(iter, &PyId_send, arg); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(send); + *result = PyObject_CallMethodOneArg(iter, attr, arg); } if (*result != NULL) { return PYGEN_NEXT; From 814ec4ad7b6adbab7ba29bedeb0977b641623484 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 10:19:54 -0700 Subject: [PATCH 031/115] Add _PyEval_GetBuiltin(). --- Include/cpython/ceval.h | 1 + Python/ceval.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index caf64401307c072..aedc7367a18f640 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -15,6 +15,7 @@ PyAPI_FUNC(int) _PyEval_SetAsyncGenFinalizer(PyObject *); PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void); /* Helper to look up a builtin object */ +PyAPI_FUNC(PyObject *) _PyEval_GetBuiltin(PyObject *); PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *); /* Look at the current frame's (if any) code's co_flags, and turn on the corresponding compiler flags in cf->cf_flags. Return 1 if any diff --git a/Python/ceval.c b/Python/ceval.c index ff1d539f7912643..b75f9a96eb20442 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -6809,19 +6809,25 @@ PyEval_GetBuiltins(void) /* Convenience function to get a builtin from its name */ PyObject * -_PyEval_GetBuiltinId(_Py_Identifier *name) +_PyEval_GetBuiltin(PyObject *name) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _PyDict_GetItemIdWithError(PyEval_GetBuiltins(), name); + PyObject *attr = PyDict_GetItemWithError(PyEval_GetBuiltins(), name); if (attr) { Py_INCREF(attr); } else if (!_PyErr_Occurred(tstate)) { - _PyErr_SetObject(tstate, PyExc_AttributeError, _PyUnicode_FromId(name)); + _PyErr_SetObject(tstate, PyExc_AttributeError, name); } return attr; } +PyObject * +_PyEval_GetBuiltinId(_Py_Identifier *name) +{ + return _PyEval_GetBuiltin(_PyUnicode_FromId(name)); +} + PyObject * PyEval_GetLocals(void) { From a91fe82c16a54c08de5c06ec91408c9f5d93f474 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 10:24:51 -0700 Subject: [PATCH 032/115] Get rid of _Py_IDENTIFIER() in descrobject.c. --- Objects/descrobject.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 962136beae05d2a..e7bf68b48ea5b1c 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -7,8 +7,6 @@ #include "pycore_tuple.h" // _PyTuple_ITEMS() #include "structmember.h" // PyMemberDef -_Py_IDENTIFIER(getattr); - /*[clinic input] class mappingproxy "mappingproxyobject *" "&PyDictProxy_Type" class property "propertyobject *" "&PyProperty_Type" @@ -571,7 +569,6 @@ static PyObject * calculate_qualname(PyDescrObject *descr) { PyObject *type_qualname, *res; - _Py_IDENTIFIER(__qualname__); if (descr->d_name == NULL || !PyUnicode_Check(descr->d_name)) { PyErr_SetString(PyExc_TypeError, @@ -579,8 +576,8 @@ calculate_qualname(PyDescrObject *descr) return NULL; } - type_qualname = _PyObject_GetAttrId((PyObject *)descr->d_type, - &PyId___qualname__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + type_qualname = PyObject_GetAttr((PyObject *)descr->d_type, attr); if (type_qualname == NULL) return NULL; @@ -608,7 +605,8 @@ descr_get_qualname(PyDescrObject *descr, void *Py_UNUSED(ignored)) static PyObject * descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored)) { - return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr), + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(attr), PyDescr_TYPE(descr), PyDescr_NAME(descr)); } @@ -1086,8 +1084,8 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs { return NULL; } - _Py_IDENTIFIER(get); - return _PyObject_VectorcallMethodId(&PyId_get, newargs, + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(get); + return _PyObject_VectorcallMethod(attr, newargs, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); } @@ -1095,36 +1093,36 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs static PyObject * mappingproxy_keys(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(keys); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_keys); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(keys); + return PyObject_CallMethodNoArgs(pp->mapping, attr); } static PyObject * mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(values); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_values); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(values); + return PyObject_CallMethodNoArgs(pp->mapping, attr); } static PyObject * mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(items); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_items); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + return PyObject_CallMethodNoArgs(pp->mapping, attr); } static PyObject * mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(copy); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_copy); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(copy); + return PyObject_CallMethodNoArgs(pp->mapping, attr); } static PyObject * mappingproxy_reversed(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(__reversed__); - return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId___reversed__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__reversed__); + return PyObject_CallMethodNoArgs(pp->mapping, attr); } /* WARNING: mappingproxy methods must not give access @@ -1321,7 +1319,8 @@ wrapper_repr(wrapperobject *wp) static PyObject * wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored)) { - return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr), + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(attr), wp->self, PyDescr_NAME(wp->descr)); } @@ -1756,9 +1755,9 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, /* if no docstring given and the getter has one, use that one */ if ((doc == NULL || doc == Py_None) && fget != NULL) { - _Py_IDENTIFIER(__doc__); PyObject *get_doc; - int rc = _PyObject_LookupAttrId(fget, &PyId___doc__, &get_doc); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + int rc = _PyObject_LookupAttr(fget, attr, &get_doc); if (rc <= 0) { return rc; } @@ -1770,7 +1769,7 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, in dict of the subclass instance instead, otherwise it gets shadowed by __doc__ in the class's dict. */ - int err = _PyObject_SetAttrId((PyObject *)self, &PyId___doc__, get_doc); + int err = PyObject_SetAttr((PyObject *)self, attr, get_doc); Py_DECREF(get_doc); if (err < 0) return -1; From 25a2ec4258c91c187eccfa595f940dc21607b8d7 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 10:38:05 -0700 Subject: [PATCH 033/115] Get rid of _Py_IDENTIFIER() in moduleobject.c. --- Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init.h | 1 + Objects/moduleobject.c | 81 +++++++++++++----------- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 8210f5e8086c080..6d95f43a9d45b3d 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -466,6 +466,7 @@ struct _Py_global_strings { ID(_shutdown) ID(_slotnames) ID(_strptime_time) + ID(_uninitialized_submodules) ID(_warn_unawaited_coroutine) ID(_xoptions) ID(append) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 0ac1cc2d3e35103..d5f40fefa282e56 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -1086,6 +1086,7 @@ extern "C" { INIT_ID(_shutdown), \ INIT_ID(_slotnames), \ INIT_ID(_strptime_time), \ + INIT_ID(_uninitialized_submodules), \ INIT_ID(_warn_unawaited_coroutine), \ INIT_ID(_xoptions), \ INIT_ID(append), \ diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 1d649a7932098bc..a246b7c9b578ee0 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -10,13 +10,6 @@ static Py_ssize_t max_module_number; -_Py_IDENTIFIER(__doc__); -_Py_IDENTIFIER(__name__); -_Py_IDENTIFIER(__spec__); -_Py_IDENTIFIER(__dict__); -_Py_IDENTIFIER(__dir__); -_Py_IDENTIFIER(__annotations__); - static PyMemberDef module_members[] = { {"__dict__", T_OBJECT, offsetof(PyModuleObject, md_dict), READONLY}, {0} @@ -61,22 +54,24 @@ static int module_init_dict(PyModuleObject *mod, PyObject *md_dict, PyObject *name, PyObject *doc) { - _Py_IDENTIFIER(__package__); - _Py_IDENTIFIER(__loader__); - assert(md_dict != NULL); if (doc == NULL) doc = Py_None; - if (_PyDict_SetItemId(md_dict, &PyId___name__, name) != 0) + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + if (PyDict_SetItem(md_dict, attr, name) != 0) return -1; - if (_PyDict_SetItemId(md_dict, &PyId___doc__, doc) != 0) + attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + if (PyDict_SetItem(md_dict, attr, doc) != 0) return -1; - if (_PyDict_SetItemId(md_dict, &PyId___package__, Py_None) != 0) + attr = _Py_GET_GLOBAL_IDENTIFIER(__package__); + if (PyDict_SetItem(md_dict, attr, Py_None) != 0) return -1; - if (_PyDict_SetItemId(md_dict, &PyId___loader__, Py_None) != 0) + attr = _Py_GET_GLOBAL_IDENTIFIER(__loader__); + if (PyDict_SetItem(md_dict, attr, Py_None) != 0) return -1; - if (_PyDict_SetItemId(md_dict, &PyId___spec__, Py_None) != 0) + attr = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + if (PyDict_SetItem(md_dict, attr, Py_None) != 0) return -1; if (PyUnicode_CheckExact(name)) { Py_INCREF(name); @@ -472,9 +467,10 @@ int PyModule_SetDocString(PyObject *m, const char *doc) { PyObject *v; + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); v = PyUnicode_FromString(doc); - if (v == NULL || _PyObject_SetAttrId(m, &PyId___doc__, v) != 0) { + if (v == NULL || PyObject_SetAttr(m, attr, v) != 0) { Py_XDECREF(v); return -1; } @@ -501,9 +497,10 @@ PyModule_GetNameObject(PyObject *m) PyErr_BadArgument(); return NULL; } + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); d = ((PyModuleObject *)m)->md_dict; if (d == NULL || !PyDict_Check(d) || - (name = _PyDict_GetItemIdWithError(d, &PyId___name__)) == NULL || + (name = PyDict_GetItemWithError(d, attr)) == NULL || !PyUnicode_Check(name)) { if (!PyErr_Occurred()) { @@ -528,16 +525,16 @@ PyModule_GetName(PyObject *m) PyObject* PyModule_GetFilenameObject(PyObject *m) { - _Py_IDENTIFIER(__file__); PyObject *d; PyObject *fileobj; if (!PyModule_Check(m)) { PyErr_BadArgument(); return NULL; } + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__file__); d = ((PyModuleObject *)m)->md_dict; if (d == NULL || - (fileobj = _PyDict_GetItemIdWithError(d, &PyId___file__)) == NULL || + (fileobj = PyDict_GetItemWithError(d, attr)) == NULL || !PyUnicode_Check(fileobj)) { if (!PyErr_Occurred()) { @@ -726,8 +723,8 @@ int _PyModuleSpec_IsInitializing(PyObject *spec) { if (spec != NULL) { - _Py_IDENTIFIER(_initializing); - PyObject *value = _PyObject_GetAttrId(spec, &PyId__initializing); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_initializing); + PyObject *value = PyObject_GetAttr(spec, attr); if (value != NULL) { int initializing = PyObject_IsTrue(value); Py_DECREF(value); @@ -750,8 +747,8 @@ _PyModuleSpec_IsUninitializedSubmodule(PyObject *spec, PyObject *name) return 0; } - _Py_IDENTIFIER(_uninitialized_submodules); - PyObject *value = _PyObject_GetAttrId(spec, &PyId__uninitialized_submodules); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_uninitialized_submodules); + PyObject *value = PyObject_GetAttr(spec, attr); if (value == NULL) { return 0; } @@ -767,25 +764,27 @@ _PyModuleSpec_IsUninitializedSubmodule(PyObject *spec, PyObject *name) static PyObject* module_getattro(PyModuleObject *m, PyObject *name) { - PyObject *attr, *mod_name, *getattr; + PyObject *attr, *mod_name, *getattr, *str; attr = PyObject_GenericGetAttr((PyObject *)m, name); if (attr || !PyErr_ExceptionMatches(PyExc_AttributeError)) { return attr; } PyErr_Clear(); assert(m->md_dict != NULL); - _Py_IDENTIFIER(__getattr__); - getattr = _PyDict_GetItemIdWithError(m->md_dict, &PyId___getattr__); + str = _Py_GET_GLOBAL_IDENTIFIER(__getattr__); + getattr = PyDict_GetItemWithError(m->md_dict, str); if (getattr) { return PyObject_CallOneArg(getattr, name); } if (PyErr_Occurred()) { return NULL; } - mod_name = _PyDict_GetItemIdWithError(m->md_dict, &PyId___name__); + str = _Py_GET_GLOBAL_IDENTIFIER(__name__); + mod_name = PyDict_GetItemWithError(m->md_dict, str); if (mod_name && PyUnicode_Check(mod_name)) { Py_INCREF(mod_name); - PyObject *spec = _PyDict_GetItemIdWithError(m->md_dict, &PyId___spec__); + str = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + PyObject *spec = PyDict_GetItemWithError(m->md_dict, str); if (spec == NULL && PyErr_Occurred()) { Py_DECREF(mod_name); return NULL; @@ -861,11 +860,13 @@ static PyObject * module_dir(PyObject *self, PyObject *args) { PyObject *result = NULL; - PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *dict = PyObject_GetAttr(self, attr); if (dict != NULL) { if (PyDict_Check(dict)) { - PyObject *dirfunc = _PyDict_GetItemIdWithError(dict, &PyId___dir__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__dir__); + PyObject *dirfunc = PyDict_GetItemWithError(dict, attr); if (dirfunc) { result = _PyObject_CallNoArgs(dirfunc); } @@ -891,7 +892,8 @@ static PyMethodDef module_methods[] = { static PyObject * module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) { - PyObject *dict = _PyObject_GetAttrId((PyObject *)m, &PyId___dict__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *dict = PyObject_GetAttr((PyObject *)m, attr); if ((dict == NULL) || !PyDict_Check(dict)) { PyErr_Format(PyExc_TypeError, ".__dict__ is not a dictionary"); @@ -900,9 +902,10 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) } PyObject *annotations; + attr = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); /* there's no _PyDict_GetItemId without WithError, so let's LBYL. */ - if (_PyDict_ContainsId(dict, &PyId___annotations__)) { - annotations = _PyDict_GetItemIdWithError(dict, &PyId___annotations__); + if (PyDict_Contains(dict, attr)) { + annotations = PyDict_GetItemWithError(dict, attr); /* ** _PyDict_GetItemIdWithError could still fail, ** for instance with a well-timed Ctrl-C or a MemoryError. @@ -914,7 +917,7 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) } else { annotations = PyDict_New(); if (annotations) { - int result = _PyDict_SetItemId(dict, &PyId___annotations__, annotations); + int result = PyDict_SetItem(dict, attr, annotations); if (result) { Py_CLEAR(annotations); } @@ -928,26 +931,28 @@ static int module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignored)) { int ret = -1; - PyObject *dict = _PyObject_GetAttrId((PyObject *)m, &PyId___dict__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *dict = PyObject_GetAttr((PyObject *)m, attr); if ((dict == NULL) || !PyDict_Check(dict)) { PyErr_Format(PyExc_TypeError, ".__dict__ is not a dictionary"); goto exit; } + attr = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); if (value != NULL) { /* set */ - ret = _PyDict_SetItemId(dict, &PyId___annotations__, value); + ret = PyDict_SetItem(dict, attr, value); goto exit; } /* delete */ - if (!_PyDict_ContainsId(dict, &PyId___annotations__)) { + if (!PyDict_Contains(dict, attr)) { PyErr_Format(PyExc_AttributeError, "__annotations__"); goto exit; } - ret = _PyDict_DelItemId(dict, &PyId___annotations__); + ret = PyDict_DelItem(dict, attr); exit: Py_XDECREF(dict); From 865cc8a0ac2f0f79344c7d1b32d9d423db421d01 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 10:48:56 -0700 Subject: [PATCH 034/115] Get rid of _Py_IDENTIFIER() in object.c. --- Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init.h | 1 + Objects/object.c | 44 +++++++++++------------- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 6d95f43a9d45b3d..6cc98f9a7351c68 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -533,6 +533,7 @@ struct _Py_global_strings { ID(n_unnamed_fields) ID(name) ID(newlines) + ID(obj) ID(offset) ID(onceregistry) ID(opcode) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index d5f40fefa282e56..7ffd4966e512e1d 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -1153,6 +1153,7 @@ extern "C" { INIT_ID(n_unnamed_fields), \ INIT_ID(name), \ INIT_ID(newlines), \ + INIT_ID(obj), \ INIT_ID(offset), \ INIT_ID(onceregistry), \ INIT_ID(opcode), \ diff --git a/Objects/object.c b/Objects/object.c index 2d4180d292458df..82a0541fc247657 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -31,11 +31,6 @@ extern "C" { /* Defined in tracemalloc.c */ extern void _PyMem_DumpTraceback(int fd, const void *ptr); -_Py_IDENTIFIER(Py_Repr); -_Py_IDENTIFIER(__bytes__); -_Py_IDENTIFIER(__dir__); -_Py_IDENTIFIER(__isabstractmethod__); - int _PyObject_CheckConsistency(PyObject *op, int check_content) @@ -562,7 +557,8 @@ PyObject_Bytes(PyObject *v) return v; } - func = _PyObject_LookupSpecialId(v, &PyId___bytes__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__bytes__); + func = _PyObject_LookupSpecial(v, attr); if (func != NULL) { result = _PyObject_CallNoArgs(func); Py_DECREF(func); @@ -600,12 +596,10 @@ def _PyObject_FunctionStr(x): PyObject * _PyObject_FunctionStr(PyObject *x) { - _Py_IDENTIFIER(__module__); - _Py_IDENTIFIER(__qualname__); - _Py_IDENTIFIER(builtins); assert(!PyErr_Occurred()); PyObject *qualname; - int ret = _PyObject_LookupAttrId(x, &PyId___qualname__, &qualname); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + int ret = _PyObject_LookupAttr(x, attr, &qualname); if (qualname == NULL) { if (ret < 0) { return NULL; @@ -614,12 +608,10 @@ _PyObject_FunctionStr(PyObject *x) } PyObject *module; PyObject *result = NULL; - ret = _PyObject_LookupAttrId(x, &PyId___module__, &module); + attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + ret = _PyObject_LookupAttr(x, attr, &module); if (module != NULL && module != Py_None) { - PyObject *builtinsname = _PyUnicode_FromId(&PyId_builtins); - if (builtinsname == NULL) { - goto done; - } + PyObject *builtinsname = _Py_GET_GLOBAL_IDENTIFIER(builtins); ret = PyObject_RichCompareBool(module, builtinsname, Py_NE); if (ret < 0) { // error @@ -858,7 +850,8 @@ _PyObject_IsAbstract(PyObject *obj) if (obj == NULL) return 0; - res = _PyObject_LookupAttrId(obj, &PyId___isabstractmethod__, &isabstract); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__isabstractmethod__); + res = _PyObject_LookupAttr(obj, attr, &isabstract); if (res > 0) { res = PyObject_IsTrue(isabstract); Py_DECREF(isabstract); @@ -892,17 +885,17 @@ static inline int set_attribute_error_context(PyObject* v, PyObject* name) { assert(PyErr_Occurred()); - _Py_IDENTIFIER(name); - _Py_IDENTIFIER(obj); // Intercept AttributeError exceptions and augment them to offer // suggestions later. if (PyErr_ExceptionMatches(PyExc_AttributeError)){ PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); PyErr_NormalizeException(&type, &value, &traceback); + PyObject *attr1 = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr2 = _Py_GET_GLOBAL_IDENTIFIER(obj); if (PyErr_GivenExceptionMatches(value, PyExc_AttributeError) && - (_PyObject_SetAttrId(value, &PyId_name, name) || - _PyObject_SetAttrId(value, &PyId_obj, v))) { + (PyObject_SetAttr(value, attr1, name) || + PyObject_SetAttr(value, attr2, v))) { return 1; } PyErr_Restore(type, value, traceback); @@ -1569,7 +1562,8 @@ static PyObject * _dir_object(PyObject *obj) { PyObject *result, *sorted; - PyObject *dirfunc = _PyObject_LookupSpecialId(obj, &PyId___dir__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dir__); + PyObject *dirfunc = _PyObject_LookupSpecial(obj, attr); assert(obj != NULL); if (dirfunc == NULL) { @@ -2148,7 +2142,8 @@ Py_ReprEnter(PyObject *obj) early on startup. */ if (dict == NULL) return 0; - list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(Py_Repr); + list = PyDict_GetItemWithError(dict, attr); if (list == NULL) { if (PyErr_Occurred()) { return -1; @@ -2156,7 +2151,7 @@ Py_ReprEnter(PyObject *obj) list = PyList_New(0); if (list == NULL) return -1; - if (_PyDict_SetItemId(dict, &PyId_Py_Repr, list) < 0) + if (PyDict_SetItem(dict, attr, list) < 0) return -1; Py_DECREF(list); } @@ -2184,7 +2179,8 @@ Py_ReprLeave(PyObject *obj) if (dict == NULL) goto finally; - list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(Py_Repr); + list = PyDict_GetItemWithError(dict, attr); if (list == NULL || !PyList_Check(list)) goto finally; From e4c2f0d6607a8355dd904d8561c8a8ab442aa88f Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 10:51:48 -0700 Subject: [PATCH 035/115] Get rid of _Py_IDENTIFIER() in bytearrayobject.c. --- Objects/bytearrayobject.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index a6009854221ff55..667865896a71717 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2111,10 +2111,10 @@ static PyObject * _common_reduce(PyByteArrayObject *self, int proto) { PyObject *dict; - _Py_IDENTIFIER(__dict__); char *buf; - if (_PyObject_LookupAttrId((PyObject *)self, &PyId___dict__, &dict) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + if (_PyObject_LookupAttr((PyObject *)self, attr, &dict) < 0) { return NULL; } if (dict == NULL) { @@ -2427,12 +2427,12 @@ PyDoc_STRVAR(length_hint_doc, static PyObject * bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); } else { - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); } } From f82baa897c306fa155104ad0531885ac190bc897 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 10:54:21 -0700 Subject: [PATCH 036/115] Get rid of _Py_IDENTIFIER() in bytesobject.c. --- Objects/bytesobject.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 9f8383fdbe17276..25e4c6278bc2a8b 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -23,8 +23,6 @@ class bytes "PyBytesObject *" "&PyBytes_Type" #include "clinic/bytesobject.c.h" -_Py_IDENTIFIER(__bytes__); - /* PyBytesObject_SIZE gives the basic size of a bytes object; any memory allocation for a bytes object of length n should request PyBytesObject_SIZE + n bytes. @@ -530,7 +528,8 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen) return v; } /* does it support __bytes__? */ - func = _PyObject_LookupSpecialId(v, &PyId___bytes__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__bytes__); + func = _PyObject_LookupSpecial(v, attr); if (func != NULL) { result = _PyObject_CallNoArgs(func); Py_DECREF(func); @@ -2551,6 +2550,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding, PyObject *bytes; PyObject *func; Py_ssize_t size; + PyObject *__bytes__ = _Py_GET_GLOBAL_IDENTIFIER(__bytes__); if (x == NULL) { if (encoding != NULL || errors != NULL) { @@ -2581,7 +2581,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding, /* We'd like to call PyObject_Bytes here, but we need to check for an integer argument before deferring to PyBytes_FromObject, something PyObject_Bytes doesn't do. */ - else if ((func = _PyObject_LookupSpecialId(x, &PyId___bytes__)) != NULL) { + else if ((func = _PyObject_LookupSpecial(x, __bytes__)) != NULL) { bytes = _PyObject_CallNoArgs(func); Py_DECREF(func); if (bytes == NULL) @@ -3121,12 +3121,12 @@ PyDoc_STRVAR(length_hint_doc, static PyObject * striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); } else { - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); } } From 4b1032321293e0edf803606a6c50a19921f55ed6 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 10:57:03 -0700 Subject: [PATCH 037/115] Get rid of _Py_IDENTIFIER() in classobject.c. --- Objects/classobject.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Objects/classobject.c b/Objects/classobject.c index 9d4fc99f1f858cb..6e83c8eefb9401a 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -9,8 +9,6 @@ #define TP_DESCR_GET(t) ((t)->tp_descr_get) -_Py_IDENTIFIER(__name__); -_Py_IDENTIFIER(__qualname__); PyObject * PyMethod_Function(PyObject *im) @@ -123,14 +121,14 @@ method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored)) PyObject *self = PyMethod_GET_SELF(im); PyObject *func = PyMethod_GET_FUNCTION(im); PyObject *funcname; - _Py_IDENTIFIER(getattr); - funcname = _PyObject_GetAttrId(func, &PyId___name__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + funcname = PyObject_GetAttr(func, attr); if (funcname == NULL) { return NULL; } - return Py_BuildValue("N(ON)", _PyEval_GetBuiltinId(&PyId_getattr), - self, funcname); + attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + return Py_BuildValue("N(ON)", _PyEval_GetBuiltin(attr), self, funcname); } static PyMethodDef method_methods[] = { @@ -280,9 +278,10 @@ method_repr(PyMethodObject *a) PyObject *funcname, *result; const char *defname = "?"; - if (_PyObject_LookupAttrId(func, &PyId___qualname__, &funcname) < 0 || - (funcname == NULL && - _PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0)) + PyObject *attr1 = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + PyObject *attr2 = _Py_GET_GLOBAL_IDENTIFIER(__name__); + if (_PyObject_LookupAttr(func, attr1, &funcname) < 0 || + (funcname == NULL && _PyObject_LookupAttr(func, attr2, &funcname) < 0)) { return NULL; } @@ -515,7 +514,8 @@ instancemethod_repr(PyObject *self) return NULL; } - if (_PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + if (_PyObject_LookupAttr(func, attr, &funcname) < 0) { return NULL; } if (funcname != NULL && !PyUnicode_Check(funcname)) { From ffd94932f9b0f4049885550cd2a237b2db15ffe8 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 10:58:00 -0700 Subject: [PATCH 038/115] Get rid of _Py_IDENTIFIER() in complexobject.c. --- Objects/complexobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/complexobject.c b/Objects/complexobject.c index c82445b230c0705..3f65efbd86c53dd 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -281,9 +281,9 @@ static PyObject * try_complex_special_method(PyObject *op) { PyObject *f; - _Py_IDENTIFIER(__complex__); - f = _PyObject_LookupSpecialId(op, &PyId___complex__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__complex__); + f = _PyObject_LookupSpecial(op, attr); if (f) { PyObject *res = _PyObject_CallNoArgs(f); Py_DECREF(f); From ddd887b674ad75ecfaa217c9fe84f37e1259ca99 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:03:39 -0700 Subject: [PATCH 039/115] Get rid of _Py_IDENTIFIER() in dictobject.c. --- Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init.h | 1 + Objects/dictobject.c | 31 +++++++++++------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 6cc98f9a7351c68..c3dc7d359e6ec39 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -511,6 +511,7 @@ struct _Py_global_strings { ID(imp) ID(importlib) ID(inf) + ID(intersection) ID(intersection_update) ID(isatty) ID(items) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 7ffd4966e512e1d..209e99633254591 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -1131,6 +1131,7 @@ extern "C" { INIT_ID(imp), \ INIT_ID(importlib), \ INIT_ID(inf), \ + INIT_ID(intersection), \ INIT_ID(intersection_update), \ INIT_ID(isatty), \ INIT_ID(items), \ diff --git a/Objects/dictobject.c b/Objects/dictobject.c index ed08ff1d581e8bc..2003aef87a966de 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2159,8 +2159,8 @@ dict_subscript(PyDictObject *mp, PyObject *key) if (!PyDict_CheckExact(mp)) { /* Look up __missing__ method if we're a subclass. */ PyObject *missing, *res; - _Py_IDENTIFIER(__missing__); - missing = _PyObject_LookupSpecialId((PyObject *)mp, &PyId___missing__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__missing__); + missing = _PyObject_LookupSpecial((PyObject *)mp, attr); if (missing != NULL) { res = PyObject_CallOneArg(missing, key); Py_DECREF(missing); @@ -2362,9 +2362,9 @@ dict_update_arg(PyObject *self, PyObject *arg) if (PyDict_CheckExact(arg)) { return PyDict_Merge(self, arg, 1); } - _Py_IDENTIFIER(keys); PyObject *func; - if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(keys); + if (_PyObject_LookupAttr(arg, attr, &func) < 0) { return -1; } if (func != NULL) { @@ -4120,7 +4120,6 @@ dict___reversed___impl(PyDictObject *self) static PyObject * dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); /* copy the iterator state */ dictiterobject tmp = *di; Py_XINCREF(tmp.di_dict); @@ -4130,7 +4129,8 @@ dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); } PyTypeObject PyDictRevIterItem_Type = { @@ -4400,9 +4400,8 @@ dictviews_sub(PyObject *self, PyObject *other) return NULL; } - _Py_IDENTIFIER(difference_update); - PyObject *tmp = _PyObject_CallMethodIdOneArg( - result, &PyId_difference_update, other); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(difference_update); + PyObject *tmp = PyObject_CallMethodOneArg(result, attr, other); if (tmp == NULL) { Py_DECREF(result); return NULL; @@ -4438,8 +4437,8 @@ _PyDictView_Intersect(PyObject* self, PyObject *other) /* if other is a set and self is smaller than other, reuse set intersection logic */ if (PySet_CheckExact(other) && len_self <= PyObject_Size(other)) { - _Py_IDENTIFIER(intersection); - return _PyObject_CallMethodIdObjArgs(other, &PyId_intersection, self, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(intersection); + return PyObject_CallMethodObjArgs(other, attr, self, NULL); } /* if other is another dict view, and it is bigger than self, @@ -4579,9 +4578,8 @@ dictitems_xor(PyObject *self, PyObject *other) } key = val1 = val2 = NULL; - _Py_IDENTIFIER(items); - PyObject *remaining_pairs = _PyObject_CallMethodIdNoArgs(temp_dict, - &PyId_items); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *remaining_pairs = PyObject_CallMethodNoArgs(temp_dict, attr); if (remaining_pairs == NULL) { goto error; } @@ -4613,9 +4611,8 @@ dictviews_xor(PyObject* self, PyObject *other) return NULL; } - _Py_IDENTIFIER(symmetric_difference_update); - PyObject *tmp = _PyObject_CallMethodIdOneArg( - result, &PyId_symmetric_difference_update, other); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(symmetric_difference_update); + PyObject *tmp = PyObject_CallMethodOneArg(result, attr, other); if (tmp == NULL) { Py_DECREF(result); return NULL; From 0a02936ee0d1c476cb3ec231815968728dc84134 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:04:35 -0700 Subject: [PATCH 040/115] Get rid of _Py_IDENTIFIER() in enumobject.c. --- Objects/enumobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/enumobject.c b/Objects/enumobject.c index 4c941d676e78bb2..2dea23a669c006c 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -356,9 +356,9 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq) Py_ssize_t n; PyObject *reversed_meth; reversedobject *ro; - _Py_IDENTIFIER(__reversed__); - reversed_meth = _PyObject_LookupSpecialId(seq, &PyId___reversed__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__reversed__); + reversed_meth = _PyObject_LookupSpecial(seq, attr); if (reversed_meth == Py_None) { Py_DECREF(reversed_meth); PyErr_Format(PyExc_TypeError, From d1578423f7ad6e0da748a3a305424e3b5483769b Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:05:41 -0700 Subject: [PATCH 041/115] Get rid of _Py_IDENTIFIER() in exceptions.c. --- Objects/exceptions.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Objects/exceptions.c b/Objects/exceptions.c index ea8a31076b060d7..ac26979985c7ee6 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1499,16 +1499,16 @@ ImportError_getstate(PyImportErrorObject *self) { PyObject *dict = ((PyBaseExceptionObject *)self)->dict; if (self->name || self->path) { - _Py_IDENTIFIER(name); - _Py_IDENTIFIER(path); dict = dict ? PyDict_Copy(dict) : PyDict_New(); if (dict == NULL) return NULL; - if (self->name && _PyDict_SetItemId(dict, &PyId_name, self->name) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + if (self->name && PyDict_SetItem(dict, attr, self->name) < 0) { Py_DECREF(dict); return NULL; } - if (self->path && _PyDict_SetItemId(dict, &PyId_path, self->path) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(path); + if (self->path && PyDict_SetItem(dict, attr, self->path) < 0) { Py_DECREF(dict); return NULL; } From 297240cf183fef839ffa2e13c51a27eeb72259e9 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:15:26 -0700 Subject: [PATCH 042/115] Get rid of _Py_IDENTIFIER() in fileobject.c. --- Objects/fileobject.c | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 8ca56a802b9769f..9769943240610e9 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -26,8 +26,6 @@ extern "C" { #endif -_Py_IDENTIFIER(open); - /* External C interface */ PyObject * @@ -40,10 +38,17 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c io = PyImport_ImportModule("_io"); if (io == NULL) return NULL; - stream = _PyObject_CallMethodId(io, &PyId_open, "isisssO", fd, mode, - buffering, encoding, errors, - newline, closefd ? Py_True : Py_False); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); + PyObject *meth = PyObject_GetAttr(io, attr); Py_DECREF(io); + if (meth == NULL) { + return NULL; + } + PyThreadState *tstate = _PyThreadState_GET(); + stream = _PyObject_CallMethod(tstate, meth, "isisssO", fd, mode, + buffering, encoding, errors, + newline, closefd ? Py_True : Py_False); + Py_DECREF(meth); if (stream == NULL) return NULL; /* ignore name attribute because the name attribute of _BufferedIOMixin @@ -54,7 +59,6 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c PyObject * PyFile_GetLine(PyObject *f, int n) { - _Py_IDENTIFIER(readline); PyObject *result; if (f == NULL) { @@ -62,11 +66,18 @@ PyFile_GetLine(PyObject *f, int n) return NULL; } + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readline); if (n <= 0) { - result = _PyObject_CallMethodIdNoArgs(f, &PyId_readline); + result = PyObject_CallMethodNoArgs(f, attr); } else { - result = _PyObject_CallMethodId(f, &PyId_readline, "i", n); + PyObject *meth = PyObject_GetAttr(f, attr); + if (meth == NULL) { + return NULL; + } + PyThreadState *tstate = _PyThreadState_GET(); + result = _PyObject_CallMethod(tstate, meth, "i", n); + Py_DECREF(meth); } if (result != NULL && !PyBytes_Check(result) && !PyUnicode_Check(result)) { @@ -120,13 +131,13 @@ int PyFile_WriteObject(PyObject *v, PyObject *f, int flags) { PyObject *writer, *value, *result; - _Py_IDENTIFIER(write); if (f == NULL) { PyErr_SetString(PyExc_TypeError, "writeobject with NULL file"); return -1; } - writer = _PyObject_GetAttrId(f, &PyId_write); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(write); + writer = PyObject_GetAttr(f, attr); if (writer == NULL) return -1; if (flags & Py_PRINT_RAW) { @@ -182,12 +193,12 @@ PyObject_AsFileDescriptor(PyObject *o) { int fd; PyObject *meth; - _Py_IDENTIFIER(fileno); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(fileno); if (PyLong_Check(o)) { fd = _PyLong_AsInt(o); } - else if (_PyObject_LookupAttrId(o, &PyId_fileno, &meth) < 0) { + else if (_PyObject_LookupAttr(o, attr, &meth) < 0) { return -1; } else if (meth != NULL) { @@ -509,9 +520,14 @@ PyFile_OpenCodeObject(PyObject *path) } else { iomod = PyImport_ImportModule("_io"); if (iomod) { - f = _PyObject_CallMethodId(iomod, &PyId_open, "Os", - path, "rb"); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); + PyObject *meth = PyObject_GetAttr(iomod, attr); Py_DECREF(iomod); + if (meth != NULL) { + PyThreadState *tstate = _PyThreadState_GET(); + f = _PyObject_CallMethod(tstate, meth, "Os", path, "rb"); + Py_DECREF(meth); + } } } From 875353d9c33311141bb9546d8553533460519e7c Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:16:57 -0700 Subject: [PATCH 043/115] Get rid of _Py_IDENTIFIER() in frameobject.c. --- Objects/frameobject.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 81ad4cc65d150c5..f83f1d8e2e70712 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -779,8 +779,6 @@ PyTypeObject PyFrame_Type = { 0, /* tp_dict */ }; -_Py_IDENTIFIER(__builtins__); - static void init_frame(InterpreterFrame *frame, PyFunctionObject *func, PyObject *locals) { @@ -1080,7 +1078,8 @@ PyFrame_GetBack(PyFrameObject *frame) PyObject* _PyEval_BuiltinsFromGlobals(PyThreadState *tstate, PyObject *globals) { - PyObject *builtins = _PyDict_GetItemIdWithError(globals, &PyId___builtins__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); + PyObject *builtins = PyDict_GetItemWithError(globals, attr); if (builtins) { if (PyModule_Check(builtins)) { builtins = _PyModule_GetDict(builtins); From 9138b2ed9f67fa296e1b909a028cc3052cf8e294 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:20:06 -0700 Subject: [PATCH 044/115] Get rid of _Py_IDENTIFIER() in funcobject.c. --- Objects/funcobject.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Objects/funcobject.c b/Objects/funcobject.c index a8f006da8ad33fe..f335983dc02b291 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -79,8 +79,8 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname Py_INCREF(doc); // __module__: Use globals['__name__'] if it exists, or NULL. - _Py_IDENTIFIER(__name__); - PyObject *module = _PyDict_GetItemIdWithError(globals, &PyId___name__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *module = PyDict_GetItemWithError(globals, attr); PyObject *builtins = NULL; if (module == NULL && _PyErr_Occurred(tstate)) { goto error; @@ -808,11 +808,7 @@ functools_wraps(PyObject *wrapper, PyObject *wrapped) { #define COPY_ATTR(ATTR) \ do { \ - _Py_IDENTIFIER(ATTR); \ - PyObject *attr = _PyUnicode_FromId(&PyId_ ## ATTR); \ - if (attr == NULL) { \ - return -1; \ - } \ + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(ATTR); \ if (functools_copy_attr(wrapper, wrapped, attr) < 0) { \ return -1; \ } \ From 5e576f01d72af2b3a2fea3f6a34d310050b4dfea Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:22:43 -0700 Subject: [PATCH 045/115] Get rid of _Py_IDENTIFIER() in genericaliasobject.c. --- Include/internal/pycore_global_strings.h | 3 +++ Include/internal/pycore_runtime_init.h | 3 +++ Objects/genericaliasobject.c | 24 ++++++++++++------------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index c3dc7d359e6ec39..d268bef43bb59e4 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -322,6 +322,7 @@ struct _Py_global_strings { ID(__and__) ID(__anext__) ID(__annotations__) + ID(__args__) ID(__await__) ID(__bases__) ID(__bool__) @@ -407,7 +408,9 @@ struct _Py_global_strings { ID(__next__) ID(__note__) ID(__or__) + ID(__origin__) ID(__package__) + ID(__parameters__) ID(__path__) ID(__pos__) ID(__pow__) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 209e99633254591..066b3b56ebbfe9a 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -942,6 +942,7 @@ extern "C" { INIT_ID(__and__), \ INIT_ID(__anext__), \ INIT_ID(__annotations__), \ + INIT_ID(__args__), \ INIT_ID(__await__), \ INIT_ID(__bases__), \ INIT_ID(__bool__), \ @@ -1027,7 +1028,9 @@ extern "C" { INIT_ID(__next__), \ INIT_ID(__note__), \ INIT_ID(__or__), \ + INIT_ID(__origin__), \ INIT_ID(__package__), \ + INIT_ID(__parameters__), \ INIT_ID(__path__), \ INIT_ID(__pos__), \ INIT_ID(__pow__), \ diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index dbe5d89b7396296..bb2002fd78b7d09 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -41,10 +41,6 @@ ga_traverse(PyObject *self, visitproc visit, void *arg) static int ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) { - _Py_IDENTIFIER(__module__); - _Py_IDENTIFIER(__qualname__); - _Py_IDENTIFIER(__origin__); - _Py_IDENTIFIER(__args__); PyObject *qualname = NULL; PyObject *module = NULL; PyObject *r = NULL; @@ -57,12 +53,14 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) goto done; } - if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__origin__); + if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { goto done; } if (tmp != NULL) { Py_DECREF(tmp); - if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__args__); + if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { goto done; } if (tmp != NULL) { @@ -72,13 +70,15 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) } } - if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + if (_PyObject_LookupAttr(p, attr, &qualname) < 0) { goto done; } if (qualname == NULL) { goto use_repr; } - if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + if (_PyObject_LookupAttr(p, attr, &module) < 0) { goto done; } if (module == NULL || module == Py_None) { @@ -218,9 +218,9 @@ _Py_make_parameters(PyObject *args) iparam += tuple_add(parameters, iparam, t); } else { - _Py_IDENTIFIER(__parameters__); PyObject *subparams; - if (_PyObject_LookupAttrId(t, &PyId___parameters__, &subparams) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__parameters__); + if (_PyObject_LookupAttr(t, attr, &subparams) < 0) { Py_DECREF(parameters); return NULL; } @@ -260,9 +260,9 @@ _Py_make_parameters(PyObject *args) static PyObject * subs_tvars(PyObject *obj, PyObject *params, PyObject **argitems) { - _Py_IDENTIFIER(__parameters__); PyObject *subparams; - if (_PyObject_LookupAttrId(obj, &PyId___parameters__, &subparams) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__parameters__); + if (_PyObject_LookupAttr(obj, attr, &subparams) < 0) { return NULL; } if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) { From 7591bf10bd4b15a03f5ddfdefde92083c4397744 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:26:19 -0700 Subject: [PATCH 046/115] Get rid of _Py_IDENTIFIER() in genobject.c. --- Objects/genobject.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Objects/genobject.c b/Objects/genobject.c index b2d402eba633309..23eb6cb5c6fe997 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -320,7 +320,6 @@ static int gen_close_iter(PyObject *yf) { PyObject *retval = NULL; - _Py_IDENTIFIER(close); if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) { retval = gen_close((PyGenObject *)yf, NULL); @@ -329,7 +328,8 @@ gen_close_iter(PyObject *yf) } else { PyObject *meth; - if (_PyObject_LookupAttrId(yf, &PyId_close, &meth) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(close); + if (_PyObject_LookupAttr(yf, attr, &meth) < 0) { PyErr_WriteUnraisable(yf); } if (meth) { @@ -417,7 +417,6 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, PyObject *typ, PyObject *val, PyObject *tb) { PyObject *yf = _PyGen_yf(gen); - _Py_IDENTIFIER(throw); if (yf) { InterpreterFrame *frame = (InterpreterFrame *)gen->gi_iframe; @@ -462,7 +461,8 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, } else { /* `yf` is an iterator or a coroutine-like object. */ PyObject *meth; - if (_PyObject_LookupAttrId(yf, &PyId_throw, &meth) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(throw); + if (_PyObject_LookupAttr(yf, attr, &meth) < 0) { Py_DECREF(yf); return NULL; } From f27547e410a245165478859388a4839249987faa Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:28:04 -0700 Subject: [PATCH 047/115] Get rid of _Py_IDENTIFIER() in iterobject.c. --- Objects/iterobject.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 5db6bc10fb3ff23..c37d138c7a0b85b 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -10,8 +10,6 @@ typedef struct { PyObject *it_seq; /* Set to NULL when iterator is exhausted */ } seqiterobject; -_Py_IDENTIFIER(iter); - PyObject * PySeqIter_New(PyObject *seq) { @@ -105,11 +103,12 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored)) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); if (it->it_seq != NULL) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); else - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); } PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); @@ -244,11 +243,12 @@ calliter_iternext(calliterobject *it) static PyObject * calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored)) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); if (it->it_callable != NULL && it->it_sentinel != NULL) - return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(attr), it->it_callable, it->it_sentinel); else - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); } static PyMethodDef calliter_methods[] = { From dd3900fc80c9cc45df1d264daa02b065081bf863 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 11:30:10 -0700 Subject: [PATCH 048/115] Get rid of _Py_IDENTIFIER() in listobject.c. --- Objects/listobject.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Objects/listobject.c b/Objects/listobject.c index 752d9e00bb7bfc4..bed3d5b4a7fc621 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -3505,25 +3505,28 @@ listreviter_setstate(listreviterobject *it, PyObject *state) static PyObject * listiter_reduce_general(void *_it, int forward) { - _Py_IDENTIFIER(iter); - _Py_IDENTIFIER(reversed); - PyObject *list; + PyObject *list, *attr; /* the objects are not the same, index is of different types! */ if (forward) { listiterobject *it = (listiterobject *)_it; - if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + if (it->it_seq) { + attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); + } } else { listreviterobject *it = (listreviterobject *)_it; - if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_reversed), + if (it->it_seq) { + attr = _Py_GET_GLOBAL_IDENTIFIER(reversed); + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); + } } /* empty iterator, create an empty list */ list = PyList_New(0); if (list == NULL) return NULL; - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); + attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); } From ecd568df100666c3ee611741efe923dc6f9ec9d5 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:03:47 -0700 Subject: [PATCH 049/115] Get rid of _Py_IDENTIFIER() in longobject.c. --- Objects/longobject.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Objects/longobject.c b/Objects/longobject.c index e1f6a6402841b40..7d4fb6fd7133c87 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -22,9 +22,6 @@ class int "PyObject *" "&PyLong_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=ec0275e3422a36e3]*/ -_Py_IDENTIFIER(little); -_Py_IDENTIFIER(big); - /* Is this PyLong of size 1, 0 or -1? */ #define IS_MEDIUM_VALUE(x) (((size_t)Py_SIZE(x)) + 1U < 3U) @@ -5773,11 +5770,13 @@ int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder, int little_endian; PyObject *bytes; + PyObject *little = _Py_GET_GLOBAL_IDENTIFIER(little); + PyObject *big = _Py_GET_GLOBAL_IDENTIFIER(big); if (byteorder == NULL) little_endian = 0; - else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_little)) + else if (_PyUnicode_Equal(byteorder, little)) little_endian = 1; - else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_big)) + else if (_PyUnicode_Equal(byteorder, big)) little_endian = 0; else { PyErr_SetString(PyExc_ValueError, @@ -5835,11 +5834,13 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, int little_endian; PyObject *long_obj, *bytes; + PyObject *little = _Py_GET_GLOBAL_IDENTIFIER(little); + PyObject *big = _Py_GET_GLOBAL_IDENTIFIER(big); if (byteorder == NULL) little_endian = 0; - else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_little)) + else if (_PyUnicode_Equal(byteorder, little)) little_endian = 1; - else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_big)) + else if (_PyUnicode_Equal(byteorder, big)) little_endian = 0; else { PyErr_SetString(PyExc_ValueError, From 187133d3021f3f98b79555fce36e78148ba1328f Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:05:06 -0700 Subject: [PATCH 050/115] Get rid of _Py_IDENTIFIER() in methodobject.c. --- Objects/methodobject.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 2df63cfdf6a818e..5f2dcd82fbfc542 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -179,12 +179,11 @@ meth_dealloc(PyCFunctionObject *m) static PyObject * meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(getattr); - if (m->m_self == NULL || PyModule_Check(m->m_self)) return PyUnicode_FromString(m->m_ml->ml_name); - return Py_BuildValue("N(Os)", _PyEval_GetBuiltinId(&PyId_getattr), + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + return Py_BuildValue("N(Os)", _PyEval_GetBuiltin(attr), m->m_self, m->m_ml->ml_name); } @@ -223,14 +222,14 @@ meth_get__qualname__(PyCFunctionObject *m, void *closure) Otherwise return type(m.__self__).__qualname__ + '.' + m.__name__ (e.g. [].append.__qualname__ == 'list.append') */ PyObject *type, *type_qualname, *res; - _Py_IDENTIFIER(__qualname__); if (m->m_self == NULL || PyModule_Check(m->m_self)) return PyUnicode_FromString(m->m_ml->ml_name); type = PyType_Check(m->m_self) ? m->m_self : (PyObject*)Py_TYPE(m->m_self); - type_qualname = _PyObject_GetAttrId(type, &PyId___qualname__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + type_qualname = PyObject_GetAttr(type, attr); if (type_qualname == NULL) return NULL; From e04947e5f3667cd81c13eae412fba0a442236c54 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:31:07 -0700 Subject: [PATCH 051/115] Get rid of _Py_IDENTIFIER() in odictobject.c. --- Objects/odictobject.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Objects/odictobject.c b/Objects/odictobject.c index e27bcecd75ca337..d3e214dd3b45b4c 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -525,8 +525,6 @@ struct _odictnode { #define _odict_FOREACH(od, node) \ for (node = _odict_FIRST(od); node != NULL; node = _odictnode_NEXT(node)) -_Py_IDENTIFIER(items); - /* Return the index into the hash table, regardless of a valid node. */ static Py_ssize_t _odict_get_index_raw(PyODictObject *od, PyObject *key, Py_hash_t hash) @@ -949,12 +947,12 @@ PyDoc_STRVAR(odict_reduce__doc__, "Return state information for pickling"); static PyObject * odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(__dict__); PyObject *dict = NULL, *result = NULL; PyObject *items_iter, *items, *args = NULL; /* capture any instance state */ - dict = _PyObject_GetAttrId((PyObject *)od, &PyId___dict__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + dict = PyObject_GetAttr((PyObject *)od, attr); if (dict == NULL) goto Done; else { @@ -973,7 +971,8 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) if (args == NULL) goto Done; - items = _PyObject_CallMethodIdNoArgs((PyObject *)od, &PyId_items); + attr = _Py_GET_GLOBAL_IDENTIFIER(items); + items = PyObject_CallMethodNoArgs((PyObject *)od, attr); if (items == NULL) goto Done; @@ -1431,8 +1430,8 @@ odict_repr(PyODictObject *self) } } else { - PyObject *items = _PyObject_CallMethodIdNoArgs((PyObject *)self, - &PyId_items); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *items = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (items == NULL) goto Done; pieces = PySequence_List(items); @@ -1808,7 +1807,6 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling"); static PyObject * odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); /* copy the iterator state */ odictiterobject tmp = *di; Py_XINCREF(tmp.di_odict); @@ -1821,7 +1819,8 @@ odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); } static PyMethodDef odictiter_methods[] = { @@ -2217,9 +2216,9 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg) Py_DECREF(items); return res; } - _Py_IDENTIFIER(keys); PyObject *func; - if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(keys); + if (_PyObject_LookupAttr(arg, attr, &func) < 0) { return -1; } if (func != NULL) { @@ -2251,7 +2250,8 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg) } return 0; } - if (_PyObject_LookupAttrId(arg, &PyId_items, &func) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(items); + if (_PyObject_LookupAttr(arg, attr, &func) < 0) { return -1; } if (func != NULL) { From 91ef303f1cba76ac7edcc73206e758a3fb753c63 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:32:31 -0700 Subject: [PATCH 052/115] Get rid of _Py_IDENTIFIER() in rangeobject.c. --- Objects/rangeobject.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index a848d67a65152e4..f9ed0731623cfc8 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -21,8 +21,6 @@ typedef struct { PyObject *length; } rangeobject; -_Py_IDENTIFIER(iter); - /* Helper function for validating step. Always returns a new reference or NULL on error. */ @@ -813,8 +811,8 @@ rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) if (range == NULL) goto err; /* return the result */ - return Py_BuildValue("N(N)l", _PyEval_GetBuiltinId(&PyId_iter), - range, r->index); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + return Py_BuildValue("N(N)l", _PyEval_GetBuiltin(attr), range, r->index); err: Py_XDECREF(start); Py_XDECREF(stop); @@ -967,8 +965,8 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored)) } /* return the result */ - return Py_BuildValue("N(N)O", _PyEval_GetBuiltinId(&PyId_iter), - range, r->index); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + return Py_BuildValue("N(N)O", _PyEval_GetBuiltin(attr), range, r->index); } static PyObject * From 21c564a85466a69f8ffd399ee5241f2f2f88be39 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:33:37 -0700 Subject: [PATCH 053/115] Get rid of _Py_IDENTIFIER() in setobject.c. --- Objects/setobject.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Objects/setobject.c b/Objects/setobject.c index ca3cfe8196467ac..47d1d594a73d1b9 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -770,7 +770,6 @@ static PyObject *setiter_iternext(setiterobject *si); static PyObject * setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); /* copy the iterator state */ setiterobject tmp = *si; Py_XINCREF(tmp.si_set); @@ -781,7 +780,8 @@ setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); } PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); @@ -1906,7 +1906,6 @@ static PyObject * set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored)) { PyObject *keys=NULL, *args=NULL, *result=NULL, *dict=NULL; - _Py_IDENTIFIER(__dict__); keys = PySequence_List((PyObject *)so); if (keys == NULL) @@ -1914,7 +1913,8 @@ set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored)) args = PyTuple_Pack(1, keys); if (args == NULL) goto done; - if (_PyObject_LookupAttrId((PyObject *)so, &PyId___dict__, &dict) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + if (_PyObject_LookupAttr((PyObject *)so, attr, &dict) < 0) { goto done; } if (dict == NULL) { From d833719df734b6496e275919b4b08b5427caba87 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:40:22 -0700 Subject: [PATCH 054/115] Get rid of _Py_IDENTIFIER() in structseq.c. --- Include/internal/pycore_structseq.h | 5 ---- Objects/structseq.c | 37 ++++++----------------------- Python/pylifecycle.c | 6 ----- 3 files changed, 7 insertions(+), 41 deletions(-) diff --git a/Include/internal/pycore_structseq.h b/Include/internal/pycore_structseq.h index c0323bbea89916c..0199c790e24cecf 100644 --- a/Include/internal/pycore_structseq.h +++ b/Include/internal/pycore_structseq.h @@ -9,11 +9,6 @@ extern "C" { #endif -/* runtime lifecycle */ - -extern PyStatus _PyStructSequence_InitState(PyInterpreterState *); - - /* other API */ PyAPI_FUNC(PyTypeObject *) _PyStructSequence_NewType( diff --git a/Objects/structseq.c b/Objects/structseq.c index 092e1634656a314..d76c4e128e7ec90 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -23,17 +23,9 @@ static const char match_args_key[] = "__match_args__"; They are only allowed for indices < n_visible_fields. */ const char * const PyStructSequence_UnnamedField = "unnamed field"; -_Py_IDENTIFIER(n_sequence_fields); -_Py_IDENTIFIER(n_fields); -_Py_IDENTIFIER(n_unnamed_fields); - static Py_ssize_t -get_type_attr_as_size(PyTypeObject *tp, _Py_Identifier *id) +get_type_attr_as_size(PyTypeObject *tp, PyObject *name) { - PyObject *name = _PyUnicode_FromId(id); - if (name == NULL) { - return -1; - } PyObject *v = PyDict_GetItemWithError(tp->tp_dict, name); if (v == NULL && !PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, @@ -44,11 +36,14 @@ get_type_attr_as_size(PyTypeObject *tp, _Py_Identifier *id) } #define VISIBLE_SIZE(op) Py_SIZE(op) -#define VISIBLE_SIZE_TP(tp) get_type_attr_as_size(tp, &PyId_n_sequence_fields) -#define REAL_SIZE_TP(tp) get_type_attr_as_size(tp, &PyId_n_fields) +#define VISIBLE_SIZE_TP(tp) \ + get_type_attr_as_size(tp, _Py_GET_GLOBAL_IDENTIFIER(n_sequence_fields)) +#define REAL_SIZE_TP(tp) \ + get_type_attr_as_size(tp, _Py_GET_GLOBAL_IDENTIFIER(n_fields)) #define REAL_SIZE(op) REAL_SIZE_TP(Py_TYPE(op)) -#define UNNAMED_FIELDS_TP(tp) get_type_attr_as_size(tp, &PyId_n_unnamed_fields) +#define UNNAMED_FIELDS_TP(tp) \ + get_type_attr_as_size(tp, _Py_GET_GLOBAL_IDENTIFIER(n_unnamed_fields)) #define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP(Py_TYPE(op)) @@ -622,21 +617,3 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc) { return _PyStructSequence_NewType(desc, 0); } - - -/* runtime lifecycle */ - -PyStatus _PyStructSequence_InitState(PyInterpreterState *interp) -{ - if (!_Py_IsMainInterpreter(interp)) { - return _PyStatus_OK(); - } - - if (_PyUnicode_FromId(&PyId_n_sequence_fields) == NULL - || _PyUnicode_FromId(&PyId_n_fields) == NULL - || _PyUnicode_FromId(&PyId_n_unnamed_fields) == NULL) - { - return _PyStatus_ERR("can't initialize structseq state"); - } - return _PyStatus_OK(); -} diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 4b80071dc1aa47a..4494a33586a5f6d 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -25,7 +25,6 @@ #include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() #include "pycore_runtime_init.h" // _PyRuntimeState_INIT #include "pycore_sliceobject.h" // _PySlice_Fini() -#include "pycore_structseq.h" // _PyStructSequence_InitState() #include "pycore_symtable.h" // _PySymtable_Fini() #include "pycore_sysmodule.h" // _PySys_ClearAuditHooks() #include "pycore_traceback.h" // _Py_DumpTracebackThreads() @@ -699,11 +698,6 @@ pycore_init_types(PyInterpreterState *interp) { PyStatus status; - status = _PyStructSequence_InitState(interp); - if (_PyStatus_EXCEPTION(status)) { - return status; - } - status = _PyTypes_InitState(interp); if (_PyStatus_EXCEPTION(status)) { return status; From 329f8fd0ccfb5af5618af37e0cfb1d54c0f8fd06 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:41:21 -0700 Subject: [PATCH 055/115] Get rid of _Py_IDENTIFIER() in tupleobject.c. --- Objects/tupleobject.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 86f541a96a5a141..728bc90a389ab35 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -1193,12 +1193,12 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * tupleiter_reduce(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); else - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); } static PyObject * From 0cbeb2d6fb8db3f9370583a687f827bd45d75b30 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:42:38 -0700 Subject: [PATCH 056/115] Get rid of _Py_IDENTIFIER() in unicodeobject.c. --- Objects/unicodeobject.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4cea0d8e62e858f..9042d6ecf431183 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15798,15 +15798,15 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); } else { PyObject *u = (PyObject *)_PyUnicode_New(0); if (u == NULL) return NULL; - return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), u); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), u); } } From 972044a0d8850686808a1898520bcaf004558a9b Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:44:46 -0700 Subject: [PATCH 057/115] Get rid of _Py_IDENTIFIER() in unionobject.c. --- Objects/unionobject.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Objects/unionobject.c b/Objects/unionobject.c index 80c70389ab30d6f..14cd23d462d00e1 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -255,10 +255,6 @@ _Py_union_type_or(PyObject* self, PyObject* other) static int union_repr_item(_PyUnicodeWriter *writer, PyObject *p) { - _Py_IDENTIFIER(__module__); - _Py_IDENTIFIER(__qualname__); - _Py_IDENTIFIER(__origin__); - _Py_IDENTIFIER(__args__); PyObject *qualname = NULL; PyObject *module = NULL; PyObject *tmp; @@ -269,13 +265,15 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p) return _PyUnicodeWriter_WriteASCIIString(writer, "None", 4); } - if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__origin__); + if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { goto exit; } if (tmp) { Py_DECREF(tmp); - if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__args__); + if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { goto exit; } if (tmp) { @@ -285,13 +283,15 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p) } } - if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + if (_PyObject_LookupAttr(p, attr, &qualname) < 0) { goto exit; } if (qualname == NULL) { goto use_repr; } - if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + if (_PyObject_LookupAttr(p, attr, &module) < 0) { goto exit; } if (module == NULL || module == Py_None) { From e55556f2e9980c6dd3d9fb09eb5a453418ad5bc4 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 12:46:28 -0700 Subject: [PATCH 058/115] Get rid of _Py_IDENTIFIER() in weakrefobject.c. --- Objects/weakrefobject.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index 76121f9fe8872b0..31e35799f7ae25a 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -163,7 +163,6 @@ static PyObject * weakref_repr(PyWeakReference *self) { PyObject *name, *repr; - _Py_IDENTIFIER(__name__); PyObject* obj = PyWeakref_GET_OBJECT(self); if (obj == Py_None) { @@ -171,7 +170,8 @@ weakref_repr(PyWeakReference *self) } Py_INCREF(obj); - if (_PyObject_LookupAttrId(obj, &PyId___name__, &name) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + if (_PyObject_LookupAttr(obj, attr, &name) < 0) { Py_DECREF(obj); return NULL; } @@ -462,10 +462,10 @@ proxy_checkref(PyWeakReference *proxy) #define WRAP_METHOD(method, special) \ static PyObject * \ method(PyObject *proxy, PyObject *Py_UNUSED(ignored)) { \ - _Py_IDENTIFIER(special); \ UNWRAP(proxy); \ Py_INCREF(proxy); \ - PyObject* res = _PyObject_CallMethodIdNoArgs(proxy, &PyId_##special); \ + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(special); \ + PyObject* res = PyObject_CallMethodNoArgs(proxy, attr); \ Py_DECREF(proxy); \ return res; \ } From 5e32d13b22e74204ae7bd6c987c0db59fe4915ae Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 14:25:33 -0700 Subject: [PATCH 059/115] Get rid of _Py_IDENTIFIER() in _pickle.c. --- Include/internal/pycore_global_strings.h | 10 ++ Include/internal/pycore_runtime_init.h | 10 ++ Modules/_pickle.c | 155 +++++++++++------------ 3 files changed, 95 insertions(+), 80 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index d268bef43bb59e4..bf3441541613845 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -357,6 +357,7 @@ struct _Py_global_strings { ID(__get__) ID(__getattr__) ID(__getattribute__) + ID(__getinitargs__) ID(__getitem__) ID(__getnewargs__) ID(__getnewargs_ex__) @@ -420,6 +421,7 @@ struct _Py_global_strings { ID(__rand__) ID(__rdivmod__) ID(__reduce__) + ID(__reduce_ex__) ID(__repr__) ID(__reversed__) ID(__rfloordiv__) @@ -472,6 +474,7 @@ struct _Py_global_strings { ID(_uninitialized_submodules) ID(_warn_unawaited_coroutine) ID(_xoptions) + ID(add) ID(append) ID(big) ID(buffer) @@ -490,6 +493,7 @@ struct _Py_global_strings { ID(default) ID(defaultaction) ID(difference_update) + ID(dispatch_table) ID(displayhook) ID(enable) ID(encode) @@ -504,6 +508,7 @@ struct _Py_global_strings { ID(fileno) ID(fillvalue) ID(filters) + ID(find_class) ID(flush) ID(get) ID(get_source) @@ -523,6 +528,7 @@ struct _Py_global_strings { ID(last_traceback) ID(last_type) ID(last_value) + ID(latin1) ID(line) ID(lineno) ID(little) @@ -530,6 +536,7 @@ struct _Py_global_strings { ID(match) ID(metaclass) ID(mode) + ID(modules) ID(mro) ID(msg) ID(n_fields) @@ -546,6 +553,8 @@ struct _Py_global_strings { ID(partial) ID(path) ID(peek) + ID(persistent_id) + ID(persistent_load) ID(print_file_and_line) ID(ps1) ID(ps2) @@ -557,6 +566,7 @@ struct _Py_global_strings { ID(readinto) ID(readinto1) ID(readline) + ID(reducer_override) ID(reload) ID(replace) ID(reset) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 066b3b56ebbfe9a..09ff8bfcc4bac96 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -977,6 +977,7 @@ extern "C" { INIT_ID(__get__), \ INIT_ID(__getattr__), \ INIT_ID(__getattribute__), \ + INIT_ID(__getinitargs__), \ INIT_ID(__getitem__), \ INIT_ID(__getnewargs__), \ INIT_ID(__getnewargs_ex__), \ @@ -1040,6 +1041,7 @@ extern "C" { INIT_ID(__rand__), \ INIT_ID(__rdivmod__), \ INIT_ID(__reduce__), \ + INIT_ID(__reduce_ex__), \ INIT_ID(__repr__), \ INIT_ID(__reversed__), \ INIT_ID(__rfloordiv__), \ @@ -1092,6 +1094,7 @@ extern "C" { INIT_ID(_uninitialized_submodules), \ INIT_ID(_warn_unawaited_coroutine), \ INIT_ID(_xoptions), \ + INIT_ID(add), \ INIT_ID(append), \ INIT_ID(big), \ INIT_ID(buffer), \ @@ -1109,6 +1112,7 @@ extern "C" { INIT_ID(decode), \ INIT_ID(default), \ INIT_ID(defaultaction), \ + INIT_ID(dispatch_table), \ INIT_ID(difference_update), \ INIT_ID(displayhook), \ INIT_ID(enable), \ @@ -1124,6 +1128,7 @@ extern "C" { INIT_ID(fileno), \ INIT_ID(fillvalue), \ INIT_ID(filters), \ + INIT_ID(find_class), \ INIT_ID(flush), \ INIT_ID(get), \ INIT_ID(get_source), \ @@ -1143,6 +1148,7 @@ extern "C" { INIT_ID(last_traceback), \ INIT_ID(last_type), \ INIT_ID(last_value), \ + INIT_ID(latin1), \ INIT_ID(line), \ INIT_ID(lineno), \ INIT_ID(little), \ @@ -1150,6 +1156,7 @@ extern "C" { INIT_ID(match), \ INIT_ID(metaclass), \ INIT_ID(mode), \ + INIT_ID(modules), \ INIT_ID(mro), \ INIT_ID(msg), \ INIT_ID(n_fields), \ @@ -1166,6 +1173,8 @@ extern "C" { INIT_ID(partial), \ INIT_ID(path), \ INIT_ID(peek), \ + INIT_ID(persistent_id), \ + INIT_ID(persistent_load), \ INIT_ID(print_file_and_line), \ INIT_ID(ps1), \ INIT_ID(ps2), \ @@ -1177,6 +1186,7 @@ extern "C" { INIT_ID(readinto), \ INIT_ID(readinto1), \ INIT_ID(readline), \ + INIT_ID(reducer_override), \ INIT_ID(reload), \ INIT_ID(replace), \ INIT_ID(reset), \ diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 0d9e57aa90d22fc..653d434eaa9f42c 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -11,6 +11,8 @@ #include "Python.h" #include "pycore_floatobject.h" // _PyFloat_Pack8() #include "pycore_moduleobject.h" // _PyModule_GetState() +#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() +#include "pycore_pystate.h" // _PyThreadState_GET() #include "structmember.h" // PyMemberDef #include // strtol() @@ -225,9 +227,9 @@ _Pickle_InitState(PickleState *st) PyObject *compat_pickle = NULL; PyObject *codecs = NULL; PyObject *functools = NULL; - _Py_IDENTIFIER(getattr); - st->getattr = _PyEval_GetBuiltinId(&PyId_getattr); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + st->getattr = _PyEval_GetBuiltin(attr); if (st->getattr == NULL) goto error; @@ -373,7 +375,7 @@ _Pickle_FastCall(PyObject *func, PyObject *obj) /* Retrieve and deconstruct a method for avoiding a reference cycle (pickler -> bound method of pickler -> pickler) */ static int -init_method_ref(PyObject *self, _Py_Identifier *name, +init_method_ref(PyObject *self, PyObject *name, PyObject **method_func, PyObject **method_self) { PyObject *func, *func2; @@ -381,7 +383,7 @@ init_method_ref(PyObject *self, _Py_Identifier *name, /* *method_func and *method_self should be consistent. All refcount decrements should be occurred after setting *method_self and *method_func. */ - ret = _PyObject_LookupAttrId(self, name, &func); + ret = _PyObject_LookupAttr(self, name, &func); if (func == NULL) { *method_self = NULL; Py_CLEAR(*method_func); @@ -1175,9 +1177,9 @@ _Pickler_SetProtocol(PicklerObject *self, PyObject *protocol, int fix_imports) static int _Pickler_SetOutputStream(PicklerObject *self, PyObject *file) { - _Py_IDENTIFIER(write); assert(file != NULL); - if (_PyObject_LookupAttrId(file, &PyId_write, &self->write) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(write); + if (_PyObject_LookupAttr(file, attr, &self->write) < 0) { return -1; } if (self->write == NULL) { @@ -1636,20 +1638,19 @@ _Unpickler_New(void) static int _Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file) { - _Py_IDENTIFIER(peek); - _Py_IDENTIFIER(read); - _Py_IDENTIFIER(readinto); - _Py_IDENTIFIER(readline); - /* Optional file methods */ - if (_PyObject_LookupAttrId(file, &PyId_peek, &self->peek) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(peek); + if (_PyObject_LookupAttr(file, attr, &self->peek) < 0) { return -1; } - if (_PyObject_LookupAttrId(file, &PyId_readinto, &self->readinto) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(readinto); + if (_PyObject_LookupAttr(file, attr, &self->readinto) < 0) { return -1; } - (void)_PyObject_LookupAttrId(file, &PyId_read, &self->read); - (void)_PyObject_LookupAttrId(file, &PyId_readline, &self->readline); + attr = _Py_GET_GLOBAL_IDENTIFIER(read); + (void)_PyObject_LookupAttr(file, attr, &self->read); + attr = _Py_GET_GLOBAL_IDENTIFIER(readline); + (void)_PyObject_LookupAttr(file, attr, &self->readline); if (!self->readline || !self->read) { if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, @@ -1809,11 +1810,11 @@ memo_put(PicklerObject *self, PyObject *obj) static PyObject * get_dotted_path(PyObject *obj, PyObject *name) { - _Py_static_string(PyId_dot, "."); PyObject *dotted_path; Py_ssize_t i, n; - dotted_path = PyUnicode_Split(name, _PyUnicode_FromId(&PyId_dot), -1); + PyObject *dot = _Py_GET_GLOBAL_STRING(dot); + dotted_path = PyUnicode_Split(name, dot, -1); if (dotted_path == NULL) return NULL; n = PyList_GET_SIZE(dotted_path); @@ -1914,11 +1915,9 @@ whichmodule(PyObject *global, PyObject *dotted_path) PyObject *module = NULL; Py_ssize_t i; PyObject *modules; - _Py_IDENTIFIER(__module__); - _Py_IDENTIFIER(modules); - _Py_IDENTIFIER(__main__); - if (_PyObject_LookupAttrId(global, &PyId___module__, &module_name) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + if (_PyObject_LookupAttr(global, attr, &module_name) < 0) { return NULL; } if (module_name) { @@ -1932,7 +1931,9 @@ whichmodule(PyObject *global, PyObject *dotted_path) assert(module_name == NULL); /* Fallback on walking sys.modules */ - modules = _PySys_GetObjectId(&PyId_modules); + attr = _Py_GET_GLOBAL_IDENTIFIER(modules); + PyThreadState *tstate = _PyThreadState_GET(); + modules = _PySys_GetAttr(tstate, attr); if (modules == NULL) { PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules"); return NULL; @@ -1977,8 +1978,8 @@ whichmodule(PyObject *global, PyObject *dotted_path) } /* If no module is found, use __main__. */ - module_name = _PyUnicode_FromId(&PyId___main__); - Py_XINCREF(module_name); + module_name = _Py_GET_GLOBAL_IDENTIFIER(__main__); + Py_INCREF(module_name); return module_name; } @@ -2427,13 +2428,13 @@ save_bytes(PicklerObject *self, PyObject *obj) PyUnicode_DecodeLatin1(PyBytes_AS_STRING(obj), PyBytes_GET_SIZE(obj), "strict"); - _Py_IDENTIFIER(latin1); if (unicode_str == NULL) return -1; + PyObject *latin1 = _Py_GET_GLOBAL_IDENTIFIER(latin1); reduce_value = Py_BuildValue("(O(OO))", st->codecs_encode, unicode_str, - _PyUnicode_FromId(&PyId_latin1)); + latin1); Py_DECREF(unicode_str); } @@ -3335,9 +3336,8 @@ save_dict(PicklerObject *self, PyObject *obj) status = batch_dict_exact(self, obj); Py_LeaveRecursiveCall(); } else { - _Py_IDENTIFIER(items); - - items = _PyObject_CallMethodIdNoArgs(obj, &PyId_items); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + items = PyObject_CallMethodNoArgs(obj, attr); if (items == NULL) goto error; iter = PyObject_GetIter(items); @@ -3589,8 +3589,6 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name) PyObject *cls; PickleState *st = _Pickle_GetGlobalState(); int status = 0; - _Py_IDENTIFIER(__name__); - _Py_IDENTIFIER(__qualname__); const char global_op = GLOBAL; @@ -3599,10 +3597,12 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name) global_name = name; } else { - if (_PyObject_LookupAttrId(obj, &PyId___qualname__, &global_name) < 0) + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + if (_PyObject_LookupAttr(obj, attr, &global_name) < 0) goto error; if (global_name == NULL) { - global_name = _PyObject_GetAttrId(obj, &PyId___name__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + global_name = PyObject_GetAttr(obj, attr); if (global_name == NULL) goto error; } @@ -3923,9 +3923,9 @@ static PyObject * get_class(PyObject *obj) { PyObject *cls; - _Py_IDENTIFIER(__class__); - if (_PyObject_LookupAttrId(obj, &PyId___class__, &cls) == 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + if (_PyObject_LookupAttr(obj, attr, &cls) == 0) { cls = (PyObject *) Py_TYPE(obj); Py_INCREF(cls); } @@ -3938,7 +3938,7 @@ get_class(PyObject *obj) static int save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) { - PyObject *callable; + PyObject *callable, *attr; PyObject *argtup; PyObject *state = NULL; PyObject *listitems = Py_None; @@ -4008,18 +4008,17 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) if (self->proto >= 2) { PyObject *name; - _Py_IDENTIFIER(__name__); - if (_PyObject_LookupAttrId(callable, &PyId___name__, &name) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + if (_PyObject_LookupAttr(callable, attr, &name) < 0) { return -1; } if (name != NULL && PyUnicode_Check(name)) { - _Py_IDENTIFIER(__newobj_ex__); - use_newobj_ex = _PyUnicode_EqualToASCIIId( - name, &PyId___newobj_ex__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__newobj_ex__); + use_newobj_ex = _PyUnicode_Equal(name, attr); if (!use_newobj_ex) { - _Py_IDENTIFIER(__newobj__); - use_newobj = _PyUnicode_EqualToASCIIId(name, &PyId___newobj__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__newobj__); + use_newobj = _PyUnicode_Equal(name, attr); } } Py_XDECREF(name); @@ -4071,13 +4070,13 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) PyObject *newargs; PyObject *cls_new; Py_ssize_t i; - _Py_IDENTIFIER(__new__); newargs = PyTuple_New(PyTuple_GET_SIZE(args) + 2); if (newargs == NULL) return -1; - cls_new = _PyObject_GetAttrId(cls, &PyId___new__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + cls_new = PyObject_GetAttr(cls, attr); if (cls_new == NULL) { Py_DECREF(newargs); return -1; @@ -4412,9 +4411,6 @@ save(PicklerObject *self, PyObject *obj, int pers_save) goto done; } else { - _Py_IDENTIFIER(__reduce__); - _Py_IDENTIFIER(__reduce_ex__); - /* XXX: If the __reduce__ method is defined, __reduce_ex__ is automatically defined as __reduce__. While this is convenient, this make it impossible to know which method was actually called. Of @@ -4424,7 +4420,8 @@ save(PicklerObject *self, PyObject *obj, int pers_save) don't actually have to check for a __reduce__ method. */ /* Check for a __reduce_ex__ method. */ - if (_PyObject_LookupAttrId(obj, &PyId___reduce_ex__, &reduce_func) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__reduce_ex__); + if (_PyObject_LookupAttr(obj, attr, &reduce_func) < 0) { goto error; } if (reduce_func != NULL) { @@ -4436,7 +4433,8 @@ save(PicklerObject *self, PyObject *obj, int pers_save) } else { /* Check for a __reduce__ method. */ - if (_PyObject_LookupAttrId(obj, &PyId___reduce__, &reduce_func) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(__reduce__); + if (_PyObject_LookupAttr(obj, attr, &reduce_func) < 0) { goto error; } if (reduce_func != NULL) { @@ -4489,10 +4487,10 @@ dump(PicklerObject *self, PyObject *obj) const char stop_op = STOP; int status = -1; PyObject *tmp; - _Py_IDENTIFIER(reducer_override); - if (_PyObject_LookupAttrId((PyObject *)self, &PyId_reducer_override, - &tmp) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(reducer_override); + if (_PyObject_LookupAttr((PyObject *)self, attr, + &tmp) < 0) { goto error; } /* Cache the reducer_override method, if it exists. */ @@ -4727,9 +4725,6 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, PyObject *buffer_callback) /*[clinic end generated code: output=0abedc50590d259b input=a7c969699bf5dad3]*/ { - _Py_IDENTIFIER(persistent_id); - _Py_IDENTIFIER(dispatch_table); - /* In case of multiple __init__() calls, clear previous content. */ if (self->write != NULL) (void)Pickler_clear(self); @@ -4762,14 +4757,16 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, self->fast_nesting = 0; self->fast_memo = NULL; - if (init_method_ref((PyObject *)self, &PyId_persistent_id, + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(persistent_id); + if (init_method_ref((PyObject *)self, attr, &self->pers_func, &self->pers_func_self) < 0) { return -1; } - if (_PyObject_LookupAttrId((PyObject *)self, - &PyId_dispatch_table, &self->dispatch_table) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(dispatch_table); + if (_PyObject_LookupAttr((PyObject *)self, + attr, &self->dispatch_table) < 0) { return -1; } @@ -5123,10 +5120,9 @@ static PyTypeObject Pickler_Type = { static PyObject * find_class(UnpicklerObject *self, PyObject *module_name, PyObject *global_name) { - _Py_IDENTIFIER(find_class); - - return _PyObject_CallMethodIdObjArgs((PyObject *)self, &PyId_find_class, - module_name, global_name, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(find_class); + return PyObject_CallMethodObjArgs((PyObject *)self, attr, + module_name, global_name, NULL); } static Py_ssize_t @@ -5813,14 +5809,14 @@ instantiate(PyObject *cls, PyObject *args) into a newly created tuple. */ assert(PyTuple_Check(args)); if (!PyTuple_GET_SIZE(args) && PyType_Check(cls)) { - _Py_IDENTIFIER(__getinitargs__); - _Py_IDENTIFIER(__new__); PyObject *func; - if (_PyObject_LookupAttrId(cls, &PyId___getinitargs__, &func) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getinitargs__); + if (_PyObject_LookupAttr(cls, attr, &func) < 0) { return NULL; } if (func == NULL) { - return _PyObject_CallMethodIdOneArg(cls, &PyId___new__, cls); + attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + return PyObject_CallMethodOneArg(cls, attr, cls); } Py_DECREF(func); } @@ -6465,9 +6461,9 @@ do_append(UnpicklerObject *self, Py_ssize_t x) } else { PyObject *extend_func; - _Py_IDENTIFIER(extend); - if (_PyObject_LookupAttrId(list, &PyId_extend, &extend_func) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(extend); + if (_PyObject_LookupAttr(list, attr, &extend_func) < 0) { return -1; } if (extend_func != NULL) { @@ -6484,12 +6480,12 @@ do_append(UnpicklerObject *self, Py_ssize_t x) } else { PyObject *append_func; - _Py_IDENTIFIER(append); /* Even if the PEP 307 requires extend() and append() methods, fall back on append() if the object has no extend() method for backward compatibility. */ - append_func = _PyObject_GetAttrId(list, &PyId_append); + attr = _Py_GET_GLOBAL_IDENTIFIER(append); + append_func = PyObject_GetAttr(list, attr); if (append_func == NULL) return -1; for (i = x; i < len; i++) { @@ -6612,9 +6608,9 @@ load_additems(UnpicklerObject *self) } else { PyObject *add_func; - _Py_IDENTIFIER(add); - add_func = _PyObject_GetAttrId(set, &PyId_add); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(add); + add_func = PyObject_GetAttr(set, attr); if (add_func == NULL) return -1; for (i = mark; i < len; i++) { @@ -6642,7 +6638,6 @@ load_build(UnpicklerObject *self) PyObject *state, *inst, *slotstate; PyObject *setstate; int status = 0; - _Py_IDENTIFIER(__setstate__); /* Stack is ... instance, state. We want to leave instance at * the stack top, possibly mutated via instance.__setstate__(state). @@ -6656,7 +6651,8 @@ load_build(UnpicklerObject *self) inst = self->stack->data[Py_SIZE(self->stack) - 1]; - if (_PyObject_LookupAttrId(inst, &PyId___setstate__, &setstate) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setstate__); + if (_PyObject_LookupAttr(inst, attr, &setstate) < 0) { Py_DECREF(state); return -1; } @@ -6692,14 +6688,14 @@ load_build(UnpicklerObject *self) PyObject *dict; PyObject *d_key, *d_value; Py_ssize_t i; - _Py_IDENTIFIER(__dict__); if (!PyDict_Check(state)) { PickleState *st = _Pickle_GetGlobalState(); PyErr_SetString(st->UnpicklingError, "state is not a dictionary"); goto error; } - dict = _PyObject_GetAttrId(inst, &PyId___dict__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + dict = PyObject_GetAttr(inst, attr); if (dict == NULL) goto error; @@ -7251,8 +7247,6 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, const char *errors, PyObject *buffers) /*[clinic end generated code: output=09f0192649ea3f85 input=ca4c1faea9553121]*/ { - _Py_IDENTIFIER(persistent_load); - /* In case of multiple __init__() calls, clear previous content. */ if (self->read != NULL) (void)Unpickler_clear(self); @@ -7268,7 +7262,8 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, self->fix_imports = fix_imports; - if (init_method_ref((PyObject *)self, &PyId_persistent_load, + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(persistent_load); + if (init_method_ref((PyObject *)self, attr, &self->pers_func, &self->pers_func_self) < 0) { return -1; From 6081cf140e1bb150b69f14dcf8a8d4b48822ab81 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 15:06:53 -0700 Subject: [PATCH 060/115] Add _PyObject_CallMethodObj(). --- Include/cpython/abstract.h | 4 ++++ Objects/call.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h index 2876a7bb84f52c9..5cc4176063245ed 100644 --- a/Include/cpython/abstract.h +++ b/Include/cpython/abstract.h @@ -116,6 +116,10 @@ PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg) 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); } +PyAPI_FUNC(PyObject *) _PyObject_CallMethodObj(PyObject *obj, + PyObject *name, + const char *format, ...); + /* Like PyObject_CallMethod(), but expect a _Py_Identifier* as the method name. */ PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj, diff --git a/Objects/call.c b/Objects/call.c index 304acf7060c9c04..77f8a34bc95bf99 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -657,6 +657,30 @@ PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...) } +PyObject * +_PyObject_CallMethodObj(PyObject *obj, PyObject *name, + const char *format, ...) +{ + PyThreadState *tstate = _PyThreadState_GET(); + if (obj == NULL || name == NULL) { + return null_error(tstate); + } + + PyObject *callable = PyObject_GetAttr(obj, name); + if (callable == NULL) { + return NULL; + } + + va_list va; + va_start(va, format); + PyObject *retval = callmethod(tstate, callable, format, va, 0); + va_end(va); + + Py_DECREF(callable); + return retval; +} + + PyObject * _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name, const char *format, ...) From 6aa56742222b1e933a4e7739ab7dd49092e6f6e8 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 15:19:50 -0700 Subject: [PATCH 061/115] Use _PyObject_CallMethodObj(). --- Objects/fileobject.c | 27 +++++---------------------- Parser/tokenizer.c | 10 ++-------- Python/importdl.c | 8 +------- Python/marshal.c | 16 ++-------------- Python/pylifecycle.c | 27 ++++++++------------------- Python/traceback.c | 9 ++------- 6 files changed, 20 insertions(+), 77 deletions(-) diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 9769943240610e9..410d806329a79aa 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -39,16 +39,10 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c if (io == NULL) return NULL; PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); - PyObject *meth = PyObject_GetAttr(io, attr); + stream = _PyObject_CallMethodObj(io, attr, "isisssO", fd, mode, + buffering, encoding, errors, + newline, closefd ? Py_True : Py_False); Py_DECREF(io); - if (meth == NULL) { - return NULL; - } - PyThreadState *tstate = _PyThreadState_GET(); - stream = _PyObject_CallMethod(tstate, meth, "isisssO", fd, mode, - buffering, encoding, errors, - newline, closefd ? Py_True : Py_False); - Py_DECREF(meth); if (stream == NULL) return NULL; /* ignore name attribute because the name attribute of _BufferedIOMixin @@ -71,13 +65,7 @@ PyFile_GetLine(PyObject *f, int n) result = PyObject_CallMethodNoArgs(f, attr); } else { - PyObject *meth = PyObject_GetAttr(f, attr); - if (meth == NULL) { - return NULL; - } - PyThreadState *tstate = _PyThreadState_GET(); - result = _PyObject_CallMethod(tstate, meth, "i", n); - Py_DECREF(meth); + result = _PyObject_CallMethodObj(f, attr, "i", n); } if (result != NULL && !PyBytes_Check(result) && !PyUnicode_Check(result)) { @@ -521,13 +509,8 @@ PyFile_OpenCodeObject(PyObject *path) iomod = PyImport_ImportModule("_io"); if (iomod) { PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); - PyObject *meth = PyObject_GetAttr(iomod, attr); + f = _PyObject_CallMethodObj(iomod, attr, "Os", path, "rb"); Py_DECREF(iomod); - if (meth != NULL) { - PyThreadState *tstate = _PyThreadState_GET(); - f = _PyObject_CallMethod(tstate, meth, "Os", path, "rb"); - Py_DECREF(meth); - } } } diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 2b5fc9edf46c069..b6f381644673ab8 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -459,7 +459,6 @@ fp_setreadl(struct tok_state *tok, const char* enc) return 0; } - PyThreadState *tstate = _PyThreadState_GET(); PyObject *str_open = _Py_GET_GLOBAL_IDENTIFIER(open); PyObject *str_readline = _Py_GET_GLOBAL_IDENTIFIER(readline); @@ -467,14 +466,9 @@ fp_setreadl(struct tok_state *tok, const char* enc) if (io == NULL) { return 0; } - PyObject *open = PyObject_GetAttr(io, str_open); - Py_DECREF(io); - if (open == NULL) { - return 0; - } - stream = _PyObject_CallMethod(tstate, open, "isisOOO", + stream = _PyObject_CallMethodObj(io, str_open, "isisOOO", fd, "r", -1, enc, Py_None, Py_None, Py_False); - Py_DECREF(open); + Py_DECREF(io); if (stream == NULL) { return 0; } diff --git a/Python/importdl.c b/Python/importdl.c index 97ddb4029decfc7..a768fb7f0422173 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -79,13 +79,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) { /* Replace '-' by '_' */ PyObject *replace = _Py_GET_GLOBAL_IDENTIFIER(replace); - PyObject *method = PyObject_GetAttr(encoded, replace); - if (method == NULL) { - goto error; - } - PyThreadState *tstate = _PyThreadState_GET(); - modname = _PyObject_CallMethod(tstate, method, "cc", '-', '_'); - Py_DECREF(method); + modname = _PyObject_CallMethodObj(encoded, replace, "cc", '-', '_'); if (modname == NULL) goto error; diff --git a/Python/marshal.c b/Python/marshal.c index 7bae27e0e658d7e..00dcac835638b78 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -713,13 +713,7 @@ r_string(Py_ssize_t n, RFILE *p) return NULL; PyObject *readinto = _Py_GET_GLOBAL_IDENTIFIER(readinto); - PyObject *method = PyObject_GetAttr(p->readable, readinto); - if (method == NULL) { - return NULL; - } - PyThreadState *tstate = _PyThreadState_GET(); - res = _PyObject_CallMethod(tstate, method, "N", mview); - Py_DECREF(method); + res = _PyObject_CallMethodObj(p->readable, readinto, "N", mview); if (res != NULL) { read = PyNumber_AsSsize_t(res, PyExc_ValueError); Py_DECREF(res); @@ -1761,13 +1755,7 @@ marshal_load(PyObject *module, PyObject *file) * for r_string() */ PyObject *read = _Py_GET_GLOBAL_IDENTIFIER(read); - PyObject *method = PyObject_GetAttr(file, read); - if (method == NULL) { - return NULL; - } - PyThreadState *tstate = _PyThreadState_GET(); - data = _PyObject_CallMethod(tstate, method, "i", 0); - Py_DECREF(method); + data = _PyObject_CallMethodObj(file, read, "i", 0); if (data == NULL) return NULL; if (!PyBytes_Check(data)) { diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 4494a33586a5f6d..907eb24accd02a8 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -3,7 +3,6 @@ #include "Python.h" #include "pycore_bytesobject.h" // _PyBytes_InitTypes() -#include "pycore_call.h" // _PyObject_CallMethod() #include "pycore_ceval.h" // _PyEval_FiniGIL() #include "pycore_context.h" // _PyContext_Init() #include "pycore_exceptions.h" // _PyExc_InitTypes() @@ -2216,7 +2215,7 @@ create_stdio(const PyConfig *config, PyObject* io, PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res; const char* mode; const char* newline; - PyObject *line_buffering, *write_through, *attr, *method; + PyObject *line_buffering, *write_through, *attr; int buffering, isatty; const int buffered_stdio = config->buffered_stdio; @@ -2237,16 +2236,10 @@ create_stdio(const PyConfig *config, PyObject* io, else mode = "rb"; attr = _Py_GET_GLOBAL_IDENTIFIER(open); - method = PyObject_GetAttr(io, attr); - if (method == NULL) { - goto error; - } - PyThreadState *tstate = _PyThreadState_GET(); - buf = _PyObject_CallMethod(tstate, method, "isiOOOO", - fd, mode, buffering, - Py_None, Py_None, /* encoding, errors */ - Py_None, Py_False); /* newline, closefd */ - Py_DECREF(method); + buf = _PyObject_CallMethodObj(io, attr, "isiOOOO", + fd, mode, buffering, + Py_None, Py_None, /* encoding, errors */ + Py_None, Py_False); /* newline, closefd */ if (buf == NULL) goto error; @@ -2316,13 +2309,9 @@ create_stdio(const PyConfig *config, PyObject* io, } attr = _Py_GET_GLOBAL_IDENTIFIER(TextIOWrapper); - method = PyObject_GetAttr(io, attr); - if (method == NULL) { - goto error; - } - stream = _PyObject_CallMethod(tstate, method, "OOOsOO", - buf, encoding_str, errors_str, - newline, line_buffering, write_through); + stream = _PyObject_CallMethodObj(io, attr, "OOOsOO", + buf, encoding_str, errors_str, + newline, line_buffering, write_through); Py_CLEAR(buf); Py_CLEAR(encoding_str); Py_CLEAR(errors_str); diff --git a/Python/traceback.c b/Python/traceback.c index d4883f221eeadeb..fcd7ef4642e3cf2 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -453,11 +453,8 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int return -1; } - PyThreadState *tstate = _PyThreadState_GET(); PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); - PyObject *open = PyObject_GetAttr(io, attr); - binary = _PyObject_CallMethod(tstate, open, "Os", filename, "rb"); - Py_DECREF(open); + binary = _PyObject_CallMethodObj(io, attr, "Os", filename, "rb"); if (binary == NULL) { PyErr_Clear(); @@ -487,10 +484,8 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int return 0; } attr = _Py_GET_GLOBAL_IDENTIFIER(TextIOWrapper); - PyObject *TextIOWrapper = PyObject_GetAttr(io, attr); + fob = _PyObject_CallMethodObj(io, attr, "Os", binary, encoding); Py_DECREF(io); - fob = _PyObject_CallMethod(tstate, TextIOWrapper, "Os", binary, encoding); - Py_DECREF(TextIOWrapper); PyMem_Free(found_encoding); PyObject *close = _Py_GET_GLOBAL_IDENTIFIER(close); From 37c02006a3b8ddd372b60a030db3ffa366eeeb45 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 15:22:24 -0700 Subject: [PATCH 062/115] _PyObject_CallMethod() -> _PyObject_CallMethodFormat(). --- Include/internal/pycore_call.h | 2 +- Objects/call.c | 2 +- Python/traceback.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Include/internal/pycore_call.h b/Include/internal/pycore_call.h index ae657c86d9e05c2..3ccacfa0b8b0387 100644 --- a/Include/internal/pycore_call.h +++ b/Include/internal/pycore_call.h @@ -30,7 +30,7 @@ PyAPI_FUNC(PyObject *) _PyObject_Call( PyObject *args, PyObject *kwargs); -extern PyObject * _PyObject_CallMethod( +extern PyObject * _PyObject_CallMethodFormat( PyThreadState *tstate, PyObject *callable, const char *format, ...); diff --git a/Objects/call.c b/Objects/call.c index 77f8a34bc95bf99..83746309d72342c 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -705,7 +705,7 @@ _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name, } -PyObject * _PyObject_CallMethod(PyThreadState *tstate, PyObject *callable, +PyObject * _PyObject_CallMethodFormat(PyThreadState *tstate, PyObject *callable, const char *format, ...) { va_list va; diff --git a/Python/traceback.c b/Python/traceback.c index fcd7ef4642e3cf2..6e97f0f37f0fc4c 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -6,7 +6,7 @@ #include "code.h" // PyCode_Addr2Line etc #include "frameobject.h" // PyFrame_GetBack() #include "pycore_ast.h" // asdl_seq_* -#include "pycore_call.h" // _PyObject_CallMethod() +#include "pycore_call.h" // _PyObject_CallMethodFormat() #include "pycore_compile.h" // _PyAST_Optimize #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH #include "pycore_frame.h" // _PyFrame_GetCode() @@ -364,7 +364,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * namebuf[len++] = SEP; strcpy(namebuf+len, tail); - binary = _PyObject_CallMethod(tstate, open, "ss", namebuf, "rb"); + binary = _PyObject_CallMethodFormat(tstate, open, "ss", namebuf, "rb"); if (binary != NULL) { result = binary; goto finally; From 10f82cd8e6c46e83f5c97fc56ae8c7ab142031e6 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 15:29:39 -0700 Subject: [PATCH 063/115] _PyObject_CallMethodObj() -> _PyObject_CallMethod(). --- Include/cpython/abstract.h | 6 +++--- Objects/call.c | 6 +++--- Objects/fileobject.c | 10 +++++----- Parser/tokenizer.c | 2 +- Python/importdl.c | 2 +- Python/marshal.c | 4 ++-- Python/pylifecycle.c | 14 +++++++------- Python/traceback.c | 4 ++-- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h index 5cc4176063245ed..3a688542ed6d028 100644 --- a/Include/cpython/abstract.h +++ b/Include/cpython/abstract.h @@ -116,9 +116,9 @@ PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg) 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); } -PyAPI_FUNC(PyObject *) _PyObject_CallMethodObj(PyObject *obj, - PyObject *name, - const char *format, ...); +PyAPI_FUNC(PyObject *) _PyObject_CallMethod(PyObject *obj, + PyObject *name, + const char *format, ...); /* Like PyObject_CallMethod(), but expect a _Py_Identifier* as the method name. */ diff --git a/Objects/call.c b/Objects/call.c index 83746309d72342c..dffdfea65e3646c 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -658,8 +658,8 @@ PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...) PyObject * -_PyObject_CallMethodObj(PyObject *obj, PyObject *name, - const char *format, ...) +_PyObject_CallMethod(PyObject *obj, PyObject *name, + const char *format, ...) { PyThreadState *tstate = _PyThreadState_GET(); if (obj == NULL || name == NULL) { @@ -706,7 +706,7 @@ _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name, PyObject * _PyObject_CallMethodFormat(PyThreadState *tstate, PyObject *callable, - const char *format, ...) + const char *format, ...) { va_list va; va_start(va, format); diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 410d806329a79aa..accce4c853d4c4c 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -39,9 +39,9 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c if (io == NULL) return NULL; PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); - stream = _PyObject_CallMethodObj(io, attr, "isisssO", fd, mode, - buffering, encoding, errors, - newline, closefd ? Py_True : Py_False); + stream = _PyObject_CallMethod(io, attr, "isisssO", fd, mode, + buffering, encoding, errors, + newline, closefd ? Py_True : Py_False); Py_DECREF(io); if (stream == NULL) return NULL; @@ -65,7 +65,7 @@ PyFile_GetLine(PyObject *f, int n) result = PyObject_CallMethodNoArgs(f, attr); } else { - result = _PyObject_CallMethodObj(f, attr, "i", n); + result = _PyObject_CallMethod(f, attr, "i", n); } if (result != NULL && !PyBytes_Check(result) && !PyUnicode_Check(result)) { @@ -509,7 +509,7 @@ PyFile_OpenCodeObject(PyObject *path) iomod = PyImport_ImportModule("_io"); if (iomod) { PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); - f = _PyObject_CallMethodObj(iomod, attr, "Os", path, "rb"); + f = _PyObject_CallMethod(iomod, attr, "Os", path, "rb"); Py_DECREF(iomod); } } diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index b6f381644673ab8..6cbe8fb6bdfa381 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -466,7 +466,7 @@ fp_setreadl(struct tok_state *tok, const char* enc) if (io == NULL) { return 0; } - stream = _PyObject_CallMethodObj(io, str_open, "isisOOO", + stream = _PyObject_CallMethod(io, str_open, "isisOOO", fd, "r", -1, enc, Py_None, Py_None, Py_False); Py_DECREF(io); if (stream == NULL) { diff --git a/Python/importdl.c b/Python/importdl.c index a768fb7f0422173..e9b547d05c99684 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -79,7 +79,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) { /* Replace '-' by '_' */ PyObject *replace = _Py_GET_GLOBAL_IDENTIFIER(replace); - modname = _PyObject_CallMethodObj(encoded, replace, "cc", '-', '_'); + modname = _PyObject_CallMethod(encoded, replace, "cc", '-', '_'); if (modname == NULL) goto error; diff --git a/Python/marshal.c b/Python/marshal.c index 00dcac835638b78..a087fc4c2a95a50 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -713,7 +713,7 @@ r_string(Py_ssize_t n, RFILE *p) return NULL; PyObject *readinto = _Py_GET_GLOBAL_IDENTIFIER(readinto); - res = _PyObject_CallMethodObj(p->readable, readinto, "N", mview); + res = _PyObject_CallMethod(p->readable, readinto, "N", mview); if (res != NULL) { read = PyNumber_AsSsize_t(res, PyExc_ValueError); Py_DECREF(res); @@ -1755,7 +1755,7 @@ marshal_load(PyObject *module, PyObject *file) * for r_string() */ PyObject *read = _Py_GET_GLOBAL_IDENTIFIER(read); - data = _PyObject_CallMethodObj(file, read, "i", 0); + data = _PyObject_CallMethod(file, read, "i", 0); if (data == NULL) return NULL; if (!PyBytes_Check(data)) { diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 907eb24accd02a8..e69601e6c222f56 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2236,10 +2236,10 @@ create_stdio(const PyConfig *config, PyObject* io, else mode = "rb"; attr = _Py_GET_GLOBAL_IDENTIFIER(open); - buf = _PyObject_CallMethodObj(io, attr, "isiOOOO", - fd, mode, buffering, - Py_None, Py_None, /* encoding, errors */ - Py_None, Py_False); /* newline, closefd */ + buf = _PyObject_CallMethod(io, attr, "isiOOOO", + fd, mode, buffering, + Py_None, Py_None, /* encoding, errors */ + Py_None, Py_False); /* newline, closefd */ if (buf == NULL) goto error; @@ -2309,9 +2309,9 @@ create_stdio(const PyConfig *config, PyObject* io, } attr = _Py_GET_GLOBAL_IDENTIFIER(TextIOWrapper); - stream = _PyObject_CallMethodObj(io, attr, "OOOsOO", - buf, encoding_str, errors_str, - newline, line_buffering, write_through); + stream = _PyObject_CallMethod(io, attr, "OOOsOO", + buf, encoding_str, errors_str, + newline, line_buffering, write_through); Py_CLEAR(buf); Py_CLEAR(encoding_str); Py_CLEAR(errors_str); diff --git a/Python/traceback.c b/Python/traceback.c index 6e97f0f37f0fc4c..9b6aa445b23a987 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -454,7 +454,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int } PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); - binary = _PyObject_CallMethodObj(io, attr, "Os", filename, "rb"); + binary = _PyObject_CallMethod(io, attr, "Os", filename, "rb"); if (binary == NULL) { PyErr_Clear(); @@ -484,7 +484,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int return 0; } attr = _Py_GET_GLOBAL_IDENTIFIER(TextIOWrapper); - fob = _PyObject_CallMethodObj(io, attr, "Os", binary, encoding); + fob = _PyObject_CallMethod(io, attr, "Os", binary, encoding); Py_DECREF(io); PyMem_Free(found_encoding); From 85f16a42b67d7ab41085882019e14bbf7541cd7f Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 16:38:52 -0700 Subject: [PATCH 064/115] Get rid of _Py_IDENTIFIER() in the _io module. --- Modules/_io/_iomodule.c | 18 ++-- Modules/_io/bufferedio.c | 80 +++++++++-------- Modules/_io/fileio.c | 14 +-- Modules/_io/iobase.c | 36 ++++---- Modules/_io/textio.c | 177 ++++++++++++++++++++----------------- Modules/_io/winconsoleio.c | 11 ++- 6 files changed, 173 insertions(+), 163 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 116688da5e7af84..4ae78721de3e327 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -240,11 +240,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, long isatty = 0; PyObject *raw, *modeobj = NULL, *buffer, *wrapper, *result = NULL, *path_or_fd = NULL; - - _Py_IDENTIFIER(_blksize); - _Py_IDENTIFIER(isatty); - _Py_IDENTIFIER(mode); - _Py_IDENTIFIER(close); + PyObject *attr; is_number = PyNumber_Check(file); @@ -381,7 +377,8 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, /* buffering */ if (buffering < 0) { - PyObject *res = _PyObject_CallMethodIdNoArgs(raw, &PyId_isatty); + attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + PyObject *res = PyObject_CallMethodNoArgs(raw, attr); if (res == NULL) goto error; isatty = PyLong_AsLong(res); @@ -399,7 +396,8 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, if (buffering < 0) { PyObject *blksize_obj; - blksize_obj = _PyObject_GetAttrId(raw, &PyId__blksize); + attr = _Py_GET_GLOBAL_IDENTIFIER(_blksize); + blksize_obj = PyObject_GetAttr(raw, attr); if (blksize_obj == NULL) goto error; buffering = PyLong_AsLong(blksize_obj); @@ -466,7 +464,8 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, result = wrapper; Py_DECREF(buffer); - if (_PyObject_SetAttrId(wrapper, &PyId_mode, modeobj) < 0) + attr = _Py_GET_GLOBAL_IDENTIFIER(mode); + if (PyObject_SetAttr(wrapper, attr, modeobj) < 0) goto error; Py_DECREF(modeobj); return result; @@ -475,7 +474,8 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, if (result != NULL) { PyObject *exc, *val, *tb, *close_result; PyErr_Fetch(&exc, &val, &tb); - close_result = _PyObject_CallMethodIdNoArgs(result, &PyId_close); + attr = _Py_GET_GLOBAL_IDENTIFIER(close); + close_result = PyObject_CallMethodNoArgs(result, attr); _PyErr_ChainExceptions(exc, val, tb); Py_XDECREF(close_result); Py_DECREF(result); diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 28995051abd4bb1..5457d294f85e28f 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -25,21 +25,6 @@ class _io.BufferedRandom "buffered *" "&PyBufferedRandom_Type" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=59460b9c5639984d]*/ -_Py_IDENTIFIER(close); -_Py_IDENTIFIER(_dealloc_warn); -_Py_IDENTIFIER(flush); -_Py_IDENTIFIER(isatty); -_Py_IDENTIFIER(mode); -_Py_IDENTIFIER(name); -_Py_IDENTIFIER(peek); -_Py_IDENTIFIER(read); -_Py_IDENTIFIER(read1); -_Py_IDENTIFIER(readable); -_Py_IDENTIFIER(readinto); -_Py_IDENTIFIER(readinto1); -_Py_IDENTIFIER(writable); -_Py_IDENTIFIER(write); - /* * BufferedIOBase class, inherits from IOBase. */ @@ -65,9 +50,10 @@ _bufferediobase_readinto_generic(PyObject *self, Py_buffer *buffer, char readint Py_ssize_t len; PyObject *data; - data = _PyObject_CallMethodId(self, - readinto1 ? &PyId_read1 : &PyId_read, - "n", buffer->len); + PyObject *attr = readinto1 + ? _Py_GET_GLOBAL_IDENTIFIER(read1) + : _Py_GET_GLOBAL_IDENTIFIER(read); + data = _PyObject_CallMethod(self, attr, "n", buffer->len); if (data == NULL) return NULL; @@ -436,8 +422,8 @@ buffered_dealloc_warn(buffered *self, PyObject *source) { if (self->ok && self->raw) { PyObject *r; - r = _PyObject_CallMethodIdOneArg(self->raw, &PyId__dealloc_warn, - source); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_dealloc_warn); + r = PyObject_CallMethodOneArg(self->raw, attr, source); if (r) Py_DECREF(r); else @@ -583,14 +569,16 @@ static PyObject * buffered_name_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - return _PyObject_GetAttrId(self->raw, &PyId_name); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + return PyObject_GetAttr(self->raw, attr); } static PyObject * buffered_mode_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - return _PyObject_GetAttrId(self->raw, &PyId_mode); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(mode); + return PyObject_GetAttr(self->raw, attr); } /* Lower-level APIs */ @@ -1381,7 +1369,8 @@ buffered_repr(buffered *self) { PyObject *nameobj, *res; - if (_PyObject_LookupAttrId((PyObject *) self, &PyId_name, &nameobj) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) { if (!PyErr_ExceptionMatches(PyExc_ValueError)) { return NULL; } @@ -2153,7 +2142,7 @@ bufferedrwpair_dealloc(rwpair *self) } static PyObject * -_forward_call(buffered *self, _Py_Identifier *name, PyObject *args) +_forward_call(buffered *self, PyObject *name, PyObject *args) { PyObject *func, *ret; if (self == NULL) { @@ -2162,9 +2151,9 @@ _forward_call(buffered *self, _Py_Identifier *name, PyObject *args) return NULL; } - func = _PyObject_GetAttrId((PyObject *)self, name); + func = PyObject_GetAttr((PyObject *)self, name); if (func == NULL) { - PyErr_SetString(PyExc_AttributeError, name->string); + PyErr_SetObject(PyExc_AttributeError, name); return NULL; } @@ -2176,67 +2165,78 @@ _forward_call(buffered *self, _Py_Identifier *name, PyObject *args) static PyObject * bufferedrwpair_read(rwpair *self, PyObject *args) { - return _forward_call(self->reader, &PyId_read, args); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read); + return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_peek(rwpair *self, PyObject *args) { - return _forward_call(self->reader, &PyId_peek, args); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(peek); + return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_read1(rwpair *self, PyObject *args) { - return _forward_call(self->reader, &PyId_read1, args); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read1); + return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_readinto(rwpair *self, PyObject *args) { - return _forward_call(self->reader, &PyId_readinto, args); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readinto); + return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_readinto1(rwpair *self, PyObject *args) { - return _forward_call(self->reader, &PyId_readinto1, args); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readinto1); + return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_write(rwpair *self, PyObject *args) { - return _forward_call(self->writer, &PyId_write, args); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(write); + return _forward_call(self->writer, attr, args); } static PyObject * bufferedrwpair_flush(rwpair *self, PyObject *Py_UNUSED(ignored)) { - return _forward_call(self->writer, &PyId_flush, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + return _forward_call(self->writer, attr, NULL); } static PyObject * bufferedrwpair_readable(rwpair *self, PyObject *Py_UNUSED(ignored)) { - return _forward_call(self->reader, &PyId_readable, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readable); + return _forward_call(self->reader, attr, NULL); } static PyObject * bufferedrwpair_writable(rwpair *self, PyObject *Py_UNUSED(ignored)) { - return _forward_call(self->writer, &PyId_writable, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(writable); + return _forward_call(self->writer, attr, NULL); } static PyObject * bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored)) { PyObject *exc = NULL, *val, *tb; - PyObject *ret = _forward_call(self->writer, &PyId_close, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(close); + PyObject *ret = _forward_call(self->writer, attr, NULL); if (ret == NULL) PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(ret); - ret = _forward_call(self->reader, &PyId_close, NULL); + attr = _Py_GET_GLOBAL_IDENTIFIER(close); + ret = _forward_call(self->reader, attr, NULL); if (exc != NULL) { _PyErr_ChainExceptions(exc, val, tb); Py_CLEAR(ret); @@ -2247,7 +2247,8 @@ bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored)) static PyObject * bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *ret = _forward_call(self->writer, &PyId_isatty, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + PyObject *ret = _forward_call(self->writer, attr, NULL); if (ret != Py_False) { /* either True or exception */ @@ -2255,7 +2256,8 @@ bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored)) } Py_DECREF(ret); - return _forward_call(self->reader, &PyId_isatty, NULL); + attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + return _forward_call(self->reader, attr, NULL); } static PyObject * diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index dd215e89399442a..16994b7bdf7d708 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -72,8 +72,6 @@ typedef struct { PyTypeObject PyFileIO_Type; -_Py_IDENTIFIER(name); - #define PyFileIO_Check(op) (PyObject_TypeCheck((op), &PyFileIO_Type)) /* Forward declarations */ @@ -146,9 +144,9 @@ _io_FileIO_close_impl(fileio *self) PyObject *res; PyObject *exc, *val, *tb; int rc; - _Py_IDENTIFIER(close); - res = _PyObject_CallMethodIdOneArg((PyObject*)&PyRawIOBase_Type, - &PyId_close, (PyObject *)self); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(close); + res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type, + attr, (PyObject *)self); if (!self->closefd) { self->fd = -1; return res; @@ -476,7 +474,8 @@ _Py_COMP_DIAG_POP _setmode(self->fd, O_BINARY); #endif - if (_PyObject_SetAttrId((PyObject *)self, &PyId_name, nameobj) < 0) + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + if (PyObject_SetAttr((PyObject *)self, attr, nameobj) < 0) goto error; if (self->appending) { @@ -1085,7 +1084,8 @@ fileio_repr(fileio *self) if (self->fd < 0) return PyUnicode_FromFormat("<_io.FileIO [closed]>"); - if (_PyObject_LookupAttrId((PyObject *) self, &PyId_name, &nameobj) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) { return NULL; } if (nameobj == NULL) { diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 5b687b78176e8c5..84498d316f76bfd 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -69,9 +69,6 @@ PyDoc_STRVAR(iobase_doc, of the IOBase object rather than the virtual `closed` attribute as returned by whatever subclass. */ -_Py_IDENTIFIER(__IOBase_closed); -_Py_IDENTIFIER(read); - /* Internal methods */ static PyObject * @@ -114,9 +111,8 @@ static PyObject * _io__IOBase_tell_impl(PyObject *self) /*[clinic end generated code: output=89a1c0807935abe2 input=04e615fec128801f]*/ { - _Py_IDENTIFIER(seek); - - return _PyObject_CallMethodId(self, &PyId_seek, "ii", 0, 1); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(seek); + return _PyObject_CallMethod(self, attr, "ii", 0, 1); } PyDoc_STRVAR(iobase_truncate_doc, @@ -138,7 +134,8 @@ iobase_is_closed(PyObject *self) int ret; /* This gets the derived attribute, which is *not* __IOBase_closed in most cases! */ - ret = _PyObject_LookupAttrId(self, &PyId___IOBase_closed, &res); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__IOBase_closed); + ret = _PyObject_LookupAttr(self, attr, &res); Py_XDECREF(res); return ret; } @@ -239,7 +236,8 @@ _io__IOBase_close_impl(PyObject *self) res = PyObject_CallMethodNoArgs(self, _PyIO_str_flush); PyErr_Fetch(&exc, &val, &tb); - rc = _PyObject_SetAttrId(self, &PyId___IOBase_closed, Py_True); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__IOBase_closed); + rc = PyObject_SetAttr(self, attr, Py_True); _PyErr_ChainExceptions(exc, val, tb); if (rc < 0) { Py_CLEAR(res); @@ -260,7 +258,6 @@ iobase_finalize(PyObject *self) PyObject *res; PyObject *error_type, *error_value, *error_traceback; int closed; - _Py_IDENTIFIER(_finalizing); /* Save the current exception, if any. */ PyErr_Fetch(&error_type, &error_value, &error_traceback); @@ -280,7 +277,8 @@ iobase_finalize(PyObject *self) if (closed == 0) { /* Signal close() that it was called as part of the object finalization process. */ - if (_PyObject_SetAttrId(self, &PyId__finalizing, Py_True)) + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_finalizing); + if (PyObject_SetAttr(self, attr, Py_True)) PyErr_Clear(); res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_close); /* Silencing I/O errors is bad, but printing spurious tracebacks is @@ -552,6 +550,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit) return NULL; } + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read); while (limit < 0 || PyByteArray_GET_SIZE(buffer) < limit) { Py_ssize_t nreadahead = 1; PyObject *b; @@ -597,7 +596,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit) Py_DECREF(readahead); } - b = _PyObject_CallMethodId(self, &PyId_read, "n", nreadahead); + b = _PyObject_CallMethod(self, attr, "n", nreadahead); if (b == NULL) { /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() when EINTR occurs so we needn't do it ourselves. */ @@ -697,9 +696,8 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint) /* XXX special-casing this made sense in the Python version in order to remove the bytecode interpretation overhead, but it could probably be removed here. */ - _Py_IDENTIFIER(extend); - PyObject *ret = _PyObject_CallMethodIdObjArgs(result, &PyId_extend, - self, NULL); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(extend); + PyObject *ret = PyObject_CallMethodObjArgs(result, attr, self, NULL); if (ret == NULL) { goto error; @@ -919,9 +917,8 @@ _io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n) PyObject *b, *res; if (n < 0) { - _Py_IDENTIFIER(readall); - - return _PyObject_CallMethodIdNoArgs(self, &PyId_readall); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readall); + return PyObject_CallMethodNoArgs(self, attr); } /* TODO: allocate a bytes object directly instead and manually construct @@ -967,8 +964,9 @@ _io__RawIOBase_readall_impl(PyObject *self) return NULL; while (1) { - PyObject *data = _PyObject_CallMethodId(self, &PyId_read, - "i", DEFAULT_BUFFER_SIZE); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read); + PyObject *data = _PyObject_CallMethod(self, attr, + "i", DEFAULT_BUFFER_SIZE); if (!data) { /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() when EINTR occurs so we needn't do it ourselves. */ diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index eb05ae1a16eb03a..d3021355e2cc62a 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -23,26 +23,6 @@ class _io.TextIOWrapper "textio *" "&TextIOWrapper_TYpe" [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=2097a4fc85670c26]*/ -_Py_IDENTIFIER(close); -_Py_IDENTIFIER(_dealloc_warn); -_Py_IDENTIFIER(decode); -_Py_IDENTIFIER(fileno); -_Py_IDENTIFIER(flush); -_Py_IDENTIFIER(isatty); -_Py_IDENTIFIER(mode); -_Py_IDENTIFIER(name); -_Py_IDENTIFIER(raw); -_Py_IDENTIFIER(read); -_Py_IDENTIFIER(readable); -_Py_IDENTIFIER(replace); -_Py_IDENTIFIER(reset); -_Py_IDENTIFIER(seek); -_Py_IDENTIFIER(seekable); -_Py_IDENTIFIER(setstate); -_Py_IDENTIFIER(strict); -_Py_IDENTIFIER(tell); -_Py_IDENTIFIER(writable); - /* TextIOBase */ PyDoc_STRVAR(textiobase_doc, @@ -255,9 +235,7 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self, Py_INCREF(decoder); if (errors == NULL) { - self->errors = _PyUnicode_FromId(&PyId_strict); - if (self->errors == NULL) - return -1; + self->errors = _Py_GET_GLOBAL_IDENTIFIER(strict); } else { self->errors = errors; @@ -586,11 +564,14 @@ _io_IncrementalNewlineDecoder_setstate(nldecoder_object *self, self->pendingcr = (int) (flag & 1); flag >>= 1; - if (self->decoder != Py_None) - return _PyObject_CallMethodId(self->decoder, - &PyId_setstate, "((OK))", buffer, flag); - else + if (self->decoder != Py_None) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(setstate); + return _PyObject_CallMethod(self->decoder, attr, + "((OK))", buffer, flag); + } + else { Py_RETURN_NONE; + } } /*[clinic input] @@ -865,7 +846,8 @@ _textiowrapper_set_decoder(textio *self, PyObject *codec_info, PyObject *res; int r; - res = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_readable); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readable); + res = PyObject_CallMethodNoArgs(self->buffer, attr); if (res == NULL) return -1; @@ -920,7 +902,8 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info, PyObject *res; int r; - res = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_writable); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(writable); + res = PyObject_CallMethodNoArgs(self->buffer, attr); if (res == NULL) return -1; @@ -939,7 +922,8 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info, return -1; /* Get the normalized named of the codec */ - if (_PyObject_LookupAttrId(codec_info, &PyId_name, &res) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(name); + if (_PyObject_LookupAttr(codec_info, attr, &res) < 0) { return -1; } if (res != NULL && PyUnicode_Check(res)) { @@ -1077,7 +1061,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, int write_through) /*[clinic end generated code: output=72267c0c01032ed2 input=77d8696d1a1f460b]*/ { - PyObject *raw, *codec_info = NULL; + PyObject *raw, *attr, *codec_info = NULL; _PyIO_State *state = NULL; PyObject *res; int r; @@ -1099,10 +1083,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, } if (errors == Py_None) { - errors = _PyUnicode_FromId(&PyId_strict); /* borrowed */ - if (errors == NULL) { - return -1; - } + errors = _Py_GET_GLOBAL_IDENTIFIER(strict); } else if (!PyUnicode_Check(errors)) { // Check 'errors' argument here because Argument Clinic doesn't support @@ -1142,7 +1123,8 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, state = IO_STATE(); if (state == NULL) goto error; - fileno = _PyObject_CallMethodIdNoArgs(buffer, &PyId_fileno); + attr = _Py_GET_GLOBAL_IDENTIFIER(fileno); + fileno = PyObject_CallMethodNoArgs(buffer, attr); /* Ignore only AttributeError and UnsupportedOperation */ if (fileno == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError) || @@ -1228,7 +1210,8 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, Py_IS_TYPE(buffer, &PyBufferedWriter_Type) || Py_IS_TYPE(buffer, &PyBufferedRandom_Type)) { - if (_PyObject_LookupAttrId(buffer, &PyId_raw, &raw) < 0) + attr = _Py_GET_GLOBAL_IDENTIFIER(raw); + if (_PyObject_LookupAttr(buffer, attr, &raw) < 0) goto error; /* Cache the raw FileIO object to speed up 'closed' checks */ if (raw != NULL) { @@ -1239,7 +1222,8 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, } } - res = _PyObject_CallMethodIdNoArgs(buffer, &PyId_seekable); + attr = _Py_GET_GLOBAL_IDENTIFIER(seekable); + res = PyObject_CallMethodNoArgs(buffer, attr); if (res == NULL) goto error; r = PyObject_IsTrue(res); @@ -1302,10 +1286,7 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding, } } else if (errors == Py_None) { - errors = _PyUnicode_FromId(&PyId_strict); - if (errors == NULL) { - return -1; - } + errors = _Py_GET_GLOBAL_IDENTIFIER(strict); } const char *c_errors = PyUnicode_AsUTF8(errors); @@ -1640,8 +1621,9 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) haslf = 1; if (haslf && self->writetranslate && self->writenl != NULL) { - PyObject *newtext = _PyObject_CallMethodId( - text, &PyId_replace, "ss", "\n", self->writenl); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(replace); + PyObject *newtext = _PyObject_CallMethod(text, attr + , "ss", "\n", self->writenl); Py_DECREF(text); if (newtext == NULL) return NULL; @@ -1740,7 +1722,8 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) Py_CLEAR(self->snapshot); if (self->decoder) { - ret = _PyObject_CallMethodIdNoArgs(self->decoder, &PyId_reset); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(reset); + ret = PyObject_CallMethodNoArgs(self->decoder, attr); if (ret == NULL) return NULL; Py_DECREF(ret); @@ -1944,7 +1927,8 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n) if (n < 0) { /* Read everything */ - PyObject *bytes = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_read); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read); + PyObject *bytes = PyObject_CallMethodNoArgs(self->buffer, attr); PyObject *decoded; if (bytes == NULL) goto fail; @@ -2404,13 +2388,17 @@ _textiowrapper_decoder_setstate(textio *self, cookie_type *cookie) at start is not (b"", 0) but e.g. (b"", 2) (meaning, in the case of utf-16, that we are expecting a BOM). */ - if (cookie->start_pos == 0 && cookie->dec_flags == 0) + if (cookie->start_pos == 0 && cookie->dec_flags == 0) { res = PyObject_CallMethodNoArgs(self->decoder, _PyIO_str_reset); - else - res = _PyObject_CallMethodId(self->decoder, &PyId_setstate, - "((yi))", "", cookie->dec_flags); - if (res == NULL) + } + else { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(setstate); + res = _PyObject_CallMethod(self->decoder, attr, + "((yi))", "", cookie->dec_flags); + } + if (res == NULL) { return -1; + } Py_DECREF(res); return 0; } @@ -2453,7 +2441,7 @@ static PyObject * _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) /*[clinic end generated code: output=0a15679764e2d04d input=0458abeb3d7842be]*/ { - PyObject *posobj; + PyObject *posobj, *attr; cookie_type cookie; PyObject *res; int cmp; @@ -2487,7 +2475,8 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) * sync the underlying buffer with the current position. */ Py_DECREF(cookieObj); - cookieObj = _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_tell); + attr = _Py_GET_GLOBAL_IDENTIFIER(tell); + cookieObj = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (cookieObj == NULL) goto fail; break; @@ -2503,7 +2492,8 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) goto fail; } - res = _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_flush); + attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + res = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (res == NULL) goto fail; Py_DECREF(res); @@ -2511,13 +2501,15 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) textiowrapper_set_decoded_chars(self, NULL); Py_CLEAR(self->snapshot); if (self->decoder) { - res = _PyObject_CallMethodIdNoArgs(self->decoder, &PyId_reset); + attr = _Py_GET_GLOBAL_IDENTIFIER(reset); + res = PyObject_CallMethodNoArgs(self->decoder, attr); if (res == NULL) goto fail; Py_DECREF(res); } - res = _PyObject_CallMethodId(self->buffer, &PyId_seek, "ii", 0, 2); + attr = _Py_GET_GLOBAL_IDENTIFIER(seek); + res = _PyObject_CallMethod(self->buffer, attr, "ii", 0, 2); Py_CLEAR(cookieObj); if (res == NULL) goto fail; @@ -2583,8 +2575,9 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) if (cookie.chars_to_skip) { /* Just like _read_chunk, feed the decoder and save a snapshot. */ - PyObject *input_chunk = _PyObject_CallMethodId( - self->buffer, &PyId_read, "i", cookie.bytes_to_feed); + attr = _Py_GET_GLOBAL_IDENTIFIER(read); + PyObject *input_chunk = _PyObject_CallMethod(self->buffer, attr, + "i", cookie.bytes_to_feed); PyObject *decoded; if (input_chunk == NULL) @@ -2605,7 +2598,8 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) } Py_XSETREF(self->snapshot, snapshot); - decoded = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_decode, + attr = _Py_GET_GLOBAL_IDENTIFIER(decode); + decoded = PyObject_CallMethodObjArgs(self->decoder, attr, input_chunk, cookie.need_eof ? Py_True : Py_False, NULL); if (check_decoded(decoded) < 0) @@ -2647,7 +2641,7 @@ static PyObject * _io_TextIOWrapper_tell_impl(textio *self) /*[clinic end generated code: output=4f168c08bf34ad5f input=9a2caf88c24f9ddf]*/ { - PyObject *res; + PyObject *res, *attr; PyObject *posobj = NULL; cookie_type cookie = {0,0,0,0,0}; PyObject *next_input; @@ -2673,12 +2667,14 @@ _io_TextIOWrapper_tell_impl(textio *self) if (_textiowrapper_writeflush(self) < 0) return NULL; - res = _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_flush); + attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + res = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (res == NULL) goto fail; Py_DECREF(res); - posobj = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_tell); + attr = _Py_GET_GLOBAL_IDENTIFIER(tell); + posobj = PyObject_CallMethodNoArgs(self->buffer, attr); if (posobj == NULL) goto fail; @@ -2750,14 +2746,16 @@ _io_TextIOWrapper_tell_impl(textio *self) } while (0) #define DECODER_DECODE(start, len, res) do { \ - PyObject *_decoded = _PyObject_CallMethodId( \ - self->decoder, &PyId_decode, "y#", start, len); \ + PyObject *_decoded = _PyObject_CallMethod( \ + self->decoder, attr, "y#", start, len); \ if (check_decoded(_decoded) < 0) \ goto fail; \ res = PyUnicode_GET_LENGTH(_decoded); \ Py_DECREF(_decoded); \ } while (0) + attr = _Py_GET_GLOBAL_IDENTIFIER(decode); + /* Fast search for an acceptable start point, close to our current pos */ skip_bytes = (Py_ssize_t) (self->b2cratio * chars_to_skip); @@ -2832,8 +2830,8 @@ _io_TextIOWrapper_tell_impl(textio *self) } if (input == input_end) { /* We didn't get enough decoded data; signal EOF to get more. */ - PyObject *decoded = _PyObject_CallMethodId( - self->decoder, &PyId_decode, "yO", "", /* final = */ Py_True); + PyObject *decoded = _PyObject_CallMethod( + self->decoder, attr, "yO", "", /* final = */ Py_True); if (check_decoded(decoded) < 0) goto fail; chars_decoded += PyUnicode_GET_LENGTH(decoded); @@ -2848,7 +2846,8 @@ _io_TextIOWrapper_tell_impl(textio *self) } finally: - res = _PyObject_CallMethodIdOneArg(self->decoder, &PyId_setstate, saved_state); + attr = _Py_GET_GLOBAL_IDENTIFIER(setstate); + res = PyObject_CallMethodOneArg(self->decoder, attr, saved_state); Py_DECREF(saved_state); if (res == NULL) return NULL; @@ -2862,7 +2861,8 @@ _io_TextIOWrapper_tell_impl(textio *self) if (saved_state) { PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - res = _PyObject_CallMethodIdOneArg(self->decoder, &PyId_setstate, saved_state); + attr = _Py_GET_GLOBAL_IDENTIFIER(setstate); + res = PyObject_CallMethodOneArg(self->decoder, attr, saved_state); _PyErr_ChainExceptions(type, value, traceback); Py_DECREF(saved_state); Py_XDECREF(res); @@ -2913,7 +2913,8 @@ textiowrapper_repr(textio *self) } goto error; } - if (_PyObject_LookupAttrId((PyObject *) self, &PyId_name, &nameobj) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) { if (!PyErr_ExceptionMatches(PyExc_ValueError)) { goto error; } @@ -2929,7 +2930,8 @@ textiowrapper_repr(textio *self) if (res == NULL) goto error; } - if (_PyObject_LookupAttrId((PyObject *) self, &PyId_mode, &modeobj) < 0) { + attr = _Py_GET_GLOBAL_IDENTIFIER(mode); + if (_PyObject_LookupAttr((PyObject *) self, attr, &modeobj) < 0) { goto error; } if (modeobj != NULL) { @@ -2969,7 +2971,8 @@ _io_TextIOWrapper_fileno_impl(textio *self) /*[clinic end generated code: output=21490a4c3da13e6c input=c488ca83d0069f9b]*/ { CHECK_ATTACHED(self); - return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_fileno); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(fileno); + return PyObject_CallMethodNoArgs(self->buffer, attr); } /*[clinic input] @@ -2981,7 +2984,8 @@ _io_TextIOWrapper_seekable_impl(textio *self) /*[clinic end generated code: output=ab223dbbcffc0f00 input=8b005ca06e1fca13]*/ { CHECK_ATTACHED(self); - return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_seekable); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(seekable); + return PyObject_CallMethodNoArgs(self->buffer, attr); } /*[clinic input] @@ -2993,7 +2997,8 @@ _io_TextIOWrapper_readable_impl(textio *self) /*[clinic end generated code: output=72ff7ba289a8a91b input=0704ea7e01b0d3eb]*/ { CHECK_ATTACHED(self); - return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_readable); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readable); + return PyObject_CallMethodNoArgs(self->buffer, attr); } /*[clinic input] @@ -3005,7 +3010,8 @@ _io_TextIOWrapper_writable_impl(textio *self) /*[clinic end generated code: output=a728c71790d03200 input=c41740bc9d8636e8]*/ { CHECK_ATTACHED(self); - return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_writable); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(writable); + return PyObject_CallMethodNoArgs(self->buffer, attr); } /*[clinic input] @@ -3017,7 +3023,8 @@ _io_TextIOWrapper_isatty_impl(textio *self) /*[clinic end generated code: output=12be1a35bace882e input=fb68d9f2c99bbfff]*/ { CHECK_ATTACHED(self); - return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_isatty); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + return PyObject_CallMethodNoArgs(self->buffer, attr); } /*[clinic input] @@ -3033,7 +3040,8 @@ _io_TextIOWrapper_flush_impl(textio *self) self->telling = self->seekable; if (_textiowrapper_writeflush(self) < 0) return NULL; - return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_flush); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + return PyObject_CallMethodNoArgs(self->buffer, attr); } /*[clinic input] @@ -3060,23 +3068,25 @@ _io_TextIOWrapper_close_impl(textio *self) Py_RETURN_NONE; /* stream already closed */ } else { - PyObject *exc = NULL, *val, *tb; + PyObject *exc = NULL, *val, *tb, *attr; if (self->finalizing) { - res = _PyObject_CallMethodIdOneArg(self->buffer, - &PyId__dealloc_warn, - (PyObject *)self); + attr = _Py_GET_GLOBAL_IDENTIFIER(_dealloc_warn); + res = PyObject_CallMethodOneArg(self->buffer, attr, + (PyObject *)self); if (res) Py_DECREF(res); else PyErr_Clear(); } - res = _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_flush); + attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + res = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (res == NULL) PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(res); - res = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_close); + attr = _Py_GET_GLOBAL_IDENTIFIER(close); + res = PyObject_CallMethodNoArgs(self->buffer, attr); if (exc != NULL) { _PyErr_ChainExceptions(exc, val, tb); Py_CLEAR(res); @@ -3127,7 +3137,8 @@ static PyObject * textiowrapper_name_get(textio *self, void *context) { CHECK_ATTACHED(self); - return _PyObject_GetAttrId(self->buffer, &PyId_name); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + return PyObject_GetAttr(self->buffer, attr); } static PyObject * diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index 4002d28fc9b3539..92260ebdba021b5 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -156,8 +156,6 @@ typedef struct { PyTypeObject PyWindowsConsoleIO_Type; -_Py_IDENTIFIER(name); - int _PyWindowsConsoleIO_closed(PyObject *self) { @@ -196,9 +194,9 @@ _io__WindowsConsoleIO_close_impl(winconsoleio *self) PyObject *res; PyObject *exc, *val, *tb; int rc; - _Py_IDENTIFIER(close); - res = _PyObject_CallMethodIdOneArg((PyObject*)&PyRawIOBase_Type, - &PyId_close, (PyObject*)self); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(close); + res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type, + attr, (PyObject*)self); if (!self->closefd) { self->fd = -1; return res; @@ -394,7 +392,8 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj, self->blksize = DEFAULT_BUFFER_SIZE; memset(self->buf, 0, 4); - if (_PyObject_SetAttrId((PyObject *)self, &PyId_name, nameobj) < 0) + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + if (PyObject_SetAttr((PyObject *)self, attr, nameobj) < 0) goto error; goto done; From aa641a3813beb88acedbb72dd257772a307c67ba Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 08:57:46 -0700 Subject: [PATCH 065/115] Get rid of _Py_IDENTIFIER() in _threadmodule.c. --- Modules/_threadmodule.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 9e6e462b59e06c2..2f7e2a70a64bc7e 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -17,11 +17,6 @@ // ThreadError is just an alias to PyExc_RuntimeError #define ThreadError PyExc_RuntimeError -_Py_IDENTIFIER(__dict__); - -_Py_IDENTIFIER(stderr); -_Py_IDENTIFIER(flush); - // Forward declarations static struct PyModuleDef thread_module; @@ -938,11 +933,7 @@ local_setattro(localobject *self, PyObject *name, PyObject *v) return -1; } - PyObject *str_dict = _PyUnicode_FromId(&PyId___dict__); // borrowed ref - if (str_dict == NULL) { - return -1; - } - + PyObject *str_dict = _Py_GET_GLOBAL_IDENTIFIER(__dict__); int r = PyObject_RichCompareBool(name, str_dict, Py_EQ); if (r == -1) { return -1; @@ -994,11 +985,7 @@ local_getattro(localobject *self, PyObject *name) if (ldict == NULL) return NULL; - PyObject *str_dict = _PyUnicode_FromId(&PyId___dict__); // borrowed ref - if (str_dict == NULL) { - return NULL; - } - + PyObject *str_dict = _Py_GET_GLOBAL_IDENTIFIER(__dict__); int r = PyObject_RichCompareBool(name, str_dict, Py_EQ); if (r == 1) { return Py_NewRef(ldict); @@ -1413,7 +1400,6 @@ static int thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, PyObject *exc_traceback, PyObject *thread) { - _Py_IDENTIFIER(name); /* print(f"Exception in thread {thread.name}:", file=file) */ if (PyFile_WriteString("Exception in thread ", file) < 0) { return -1; @@ -1421,7 +1407,8 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, PyObject *name = NULL; if (thread != Py_None) { - if (_PyObject_LookupAttrId(thread, &PyId_name, &name) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + if (_PyObject_LookupAttr(thread, attr, &name) < 0) { return -1; } } @@ -1459,7 +1446,8 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, _PyErr_Display(file, exc_type, exc_value, exc_traceback); /* Call file.flush() */ - PyObject *res = _PyObject_CallMethodIdNoArgs(file, &PyId_flush); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *res = PyObject_CallMethodNoArgs(file, attr); if (!res) { return -1; } @@ -1514,7 +1502,9 @@ thread_excepthook(PyObject *module, PyObject *args) PyObject *exc_tb = PyStructSequence_GET_ITEM(args, 2); PyObject *thread = PyStructSequence_GET_ITEM(args, 3); - PyObject *file = _PySys_GetObjectId(&PyId_stderr); + PyThreadState *tstate = _PyThreadState_GET(); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *file = _PySys_GetAttr(tstate, attr); if (file == NULL || file == Py_None) { if (thread == Py_None) { /* do nothing if sys.stderr is None and thread is None */ From dda08adceb087e4cf38cee147b3678da890f8e95 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 16:20:20 -0700 Subject: [PATCH 066/115] Get rid of _Py_IDENTIFIER() in _abc.c. --- Include/internal/pycore_global_strings.h | 1 + Include/internal/pycore_runtime_init.h | 1 + Modules/_abc.c | 52 +++++++++++------------- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index bf3441541613845..63984e8f5cacedf 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -312,6 +312,7 @@ struct _Py_global_strings { ID(WarningMessage) ID(_) ID(__IOBase_closed) + ID(__abc_tpflags__) ID(__abs__) ID(__abstractmethods__) ID(__add__) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 09ff8bfcc4bac96..e53f4abeedba628 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -932,6 +932,7 @@ extern "C" { INIT_ID(WarningMessage), \ INIT_ID(_), \ INIT_ID(__IOBase_closed), \ + INIT_ID(__abc_tpflags__), \ INIT_ID(__abs__), \ INIT_ID(__abstractmethods__), \ INIT_ID(__add__), \ diff --git a/Modules/_abc.c b/Modules/_abc.c index a043961812041ff..bc7c73cce8a83a2 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -4,8 +4,9 @@ #endif #include "Python.h" -#include "pycore_object.h" // _PyType_GetSubclasses() #include "pycore_moduleobject.h" // _PyModule_GetState() +#include "pycore_object.h" // _PyType_GetSubclasses() +#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() #include "clinic/_abc.c.h" /*[clinic input] @@ -16,15 +17,6 @@ module _abc PyDoc_STRVAR(_abc__doc__, "Module contains faster C implementation of abc.ABCMeta"); -_Py_IDENTIFIER(__abstractmethods__); -_Py_IDENTIFIER(__class__); -_Py_IDENTIFIER(__dict__); -_Py_IDENTIFIER(__abc_tpflags__); -_Py_IDENTIFIER(__bases__); -_Py_IDENTIFIER(_abc_impl); -_Py_IDENTIFIER(__subclasscheck__); -_Py_IDENTIFIER(__subclasshook__); - typedef struct { PyTypeObject *_abc_data_type; unsigned long long abc_invalidation_counter; @@ -122,7 +114,8 @@ static _abc_data * _get_impl(PyObject *module, PyObject *self) { _abcmodule_state *state = get_abc_state(module); - PyObject *impl = _PyObject_GetAttrId(self, &PyId__abc_impl); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_abc_impl); + PyObject *impl = PyObject_GetAttr(self, attr); if (impl == NULL) { return NULL; } @@ -311,7 +304,8 @@ compute_abstract_methods(PyObject *self) PyObject *ns = NULL, *items = NULL, *bases = NULL; // Py_XDECREF()ed on error. /* Stage 1: direct abstract methods. */ - ns = _PyObject_GetAttrId(self, &PyId___dict__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + ns = PyObject_GetAttr(self, attr); if (!ns) { goto error; } @@ -355,7 +349,8 @@ compute_abstract_methods(PyObject *self) } /* Stage 2: inherited abstract methods. */ - bases = _PyObject_GetAttrId(self, &PyId___bases__); + attr = _Py_GET_GLOBAL_IDENTIFIER(__bases__); + bases = PyObject_GetAttr(self, attr); if (!bases) { goto error; } @@ -364,12 +359,12 @@ compute_abstract_methods(PyObject *self) goto error; } + attr = _Py_GET_GLOBAL_IDENTIFIER(__abstractmethods__); for (Py_ssize_t pos = 0; pos < PyTuple_GET_SIZE(bases); pos++) { PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed PyObject *base_abstracts, *iter; - if (_PyObject_LookupAttrId(item, &PyId___abstractmethods__, - &base_abstracts) < 0) { + if (_PyObject_LookupAttr(item, attr, &base_abstracts) < 0) { goto error; } if (base_abstracts == NULL) { @@ -409,7 +404,7 @@ compute_abstract_methods(PyObject *self) } } - if (_PyObject_SetAttrId(self, &PyId___abstractmethods__, abstracts) < 0) { + if (PyObject_SetAttr(self, attr, abstracts) < 0) { goto error; } @@ -448,7 +443,8 @@ _abc__abc_init(PyObject *module, PyObject *self) if (data == NULL) { return NULL; } - if (_PyObject_SetAttrId(self, &PyId__abc_impl, data) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_abc_impl); + if (PyObject_SetAttr(self, attr, data) < 0) { Py_DECREF(data); return NULL; } @@ -459,7 +455,8 @@ _abc__abc_init(PyObject *module, PyObject *self) * their special status w.r.t. pattern matching. */ if (PyType_Check(self)) { PyTypeObject *cls = (PyTypeObject *)self; - PyObject *flags = _PyDict_GetItemIdWithError(cls->tp_dict, &PyId___abc_tpflags__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__abc_tpflags__); + PyObject *flags = PyDict_GetItemWithError(cls->tp_dict, attr); if (flags == NULL) { if (PyErr_Occurred()) { return NULL; @@ -477,7 +474,7 @@ _abc__abc_init(PyObject *module, PyObject *self) } ((PyTypeObject *)self)->tp_flags |= (val & COLLECTION_FLAGS); } - if (_PyDict_DelItemId(cls->tp_dict, &PyId___abc_tpflags__) < 0) { + if (PyDict_DelItem(cls->tp_dict, attr) < 0) { return NULL; } } @@ -593,7 +590,8 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, return NULL; } - subclass = _PyObject_GetAttrId(instance, &PyId___class__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + subclass = PyObject_GetAttr(instance, attr); if (subclass == NULL) { Py_DECREF(impl); return NULL; @@ -609,6 +607,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, goto end; } subtype = (PyObject *)Py_TYPE(instance); + attr = _Py_GET_GLOBAL_IDENTIFIER(__subclasscheck__); if (subtype == subclass) { if (impl->_abc_negative_cache_version == get_abc_state(module)->abc_invalidation_counter) { incache = _in_weak_set(impl->_abc_negative_cache, subclass); @@ -622,12 +621,10 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, } } /* Fall back to the subclass check. */ - result = _PyObject_CallMethodIdOneArg(self, &PyId___subclasscheck__, - subclass); + result = PyObject_CallMethodOneArg(self, attr, subclass); goto end; } - result = _PyObject_CallMethodIdOneArg(self, &PyId___subclasscheck__, - subclass); + result = PyObject_CallMethodOneArg(self, attr, subclass); if (result == NULL) { goto end; } @@ -639,8 +636,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, break; case 0: Py_DECREF(result); - result = _PyObject_CallMethodIdOneArg(self, &PyId___subclasscheck__, - subtype); + result = PyObject_CallMethodOneArg(self, attr, subtype); break; case 1: // Nothing to do. break; @@ -723,8 +719,8 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self, } /* 3. Check the subclass hook. */ - ok = _PyObject_CallMethodIdOneArg((PyObject *)self, &PyId___subclasshook__, - subclass); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__subclasshook__); + ok = PyObject_CallMethodOneArg((PyObject *)self, attr, subclass); if (ok == NULL) { goto end; } From 4d75c6b25c014d08fb4c166508f940c34f8170ca Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 08:52:44 -0700 Subject: [PATCH 067/115] Get rid of _Py_IDENTIFIER() in faulthandler.c. --- Modules/faulthandler.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 1888337cf9f39bd..811f99bfe5823d8 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -32,11 +32,6 @@ #define PUTS(fd, str) _Py_write_noraise(fd, str, strlen(str)) -_Py_IDENTIFIER(enable); -_Py_IDENTIFIER(fileno); -_Py_IDENTIFIER(flush); -_Py_IDENTIFIER(stderr); - #ifdef HAVE_SIGACTION typedef struct sigaction _Py_sighandler_t; #else @@ -152,10 +147,12 @@ faulthandler_get_fileno(PyObject **file_ptr) PyObject *result; long fd_long; int fd; - PyObject *file = *file_ptr; + PyObject *attr, *file = *file_ptr; if (file == NULL || file == Py_None) { - file = _PySys_GetObjectId(&PyId_stderr); + PyThreadState *tstate = _PyThreadState_GET(); + attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + file = _PySys_GetAttr(tstate, attr); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "unable to get sys.stderr"); return -1; @@ -178,7 +175,8 @@ faulthandler_get_fileno(PyObject **file_ptr) return fd; } - result = _PyObject_CallMethodIdNoArgs(file, &PyId_fileno); + attr = _Py_GET_GLOBAL_IDENTIFIER(fileno); + result = PyObject_CallMethodNoArgs(file, attr); if (result == NULL) return -1; @@ -196,7 +194,8 @@ faulthandler_get_fileno(PyObject **file_ptr) return -1; } - result = _PyObject_CallMethodIdNoArgs(file, &PyId_flush); + attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + result = PyObject_CallMethodNoArgs(file, attr); if (result != NULL) Py_DECREF(result); else { @@ -1336,7 +1335,8 @@ faulthandler_init_enable(void) return -1; } - PyObject *res = _PyObject_CallMethodIdNoArgs(module, &PyId_enable); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(enable); + PyObject *res = PyObject_CallMethodNoArgs(module, attr); Py_DECREF(module); if (res == NULL) { return -1; From 9d36c02417f43f585685772c3e6b8b527168f8cd Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 25 Jan 2022 17:26:06 -0700 Subject: [PATCH 068/115] Get rid of _Py_IDENTIFIER() in _collectionsmodule.c. --- Modules/_collectionsmodule.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 4c4e1f762a4a66e..75e534b576ea46d 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1348,9 +1348,9 @@ static PyObject * deque_reduce(dequeobject *deque, PyObject *Py_UNUSED(ignored)) { PyObject *dict, *it; - _Py_IDENTIFIER(__dict__); - if (_PyObject_LookupAttrId((PyObject *)deque, &PyId___dict__, &dict) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + if (_PyObject_LookupAttr((PyObject *)deque, attr, &dict) < 0) { return NULL; } if (dict == NULL) { @@ -2064,7 +2064,6 @@ defdict_reduce(defdictobject *dd, PyObject *Py_UNUSED(ignored)) PyObject *items; PyObject *iter; PyObject *result; - _Py_IDENTIFIER(items); if (dd->default_factory == NULL || dd->default_factory == Py_None) args = PyTuple_New(0); @@ -2072,7 +2071,8 @@ defdict_reduce(defdictobject *dd, PyObject *Py_UNUSED(ignored)) args = PyTuple_Pack(1, dd->default_factory); if (args == NULL) return NULL; - items = _PyObject_CallMethodIdNoArgs((PyObject *)dd, &PyId_items); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + items = PyObject_CallMethodNoArgs((PyObject *)dd, attr); if (items == NULL) { Py_DECREF(args); return NULL; @@ -2310,8 +2310,6 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping, PyObject *iterable) /*[clinic end generated code: output=7e0c1789636b3d8f input=e79fad04534a0b45]*/ { - _Py_IDENTIFIER(get); - _Py_IDENTIFIER(__setitem__); PyObject *it, *oldval; PyObject *newval = NULL; PyObject *key = NULL; @@ -2329,10 +2327,13 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping, /* Only take the fast path when get() and __setitem__() * have not been overridden. */ - mapping_get = _PyType_LookupId(Py_TYPE(mapping), &PyId_get); - dict_get = _PyType_LookupId(&PyDict_Type, &PyId_get); - mapping_setitem = _PyType_LookupId(Py_TYPE(mapping), &PyId___setitem__); - dict_setitem = _PyType_LookupId(&PyDict_Type, &PyId___setitem__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(get); + mapping_get = _PyType_Lookup(Py_TYPE(mapping), attr); + dict_get = _PyType_Lookup(&PyDict_Type, attr); + attr = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + mapping_setitem = _PyType_Lookup(Py_TYPE(mapping), attr); + attr = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + dict_setitem = _PyType_Lookup(&PyDict_Type, attr); if (mapping_get != NULL && mapping_get == dict_get && mapping_setitem != NULL && mapping_setitem == dict_setitem && @@ -2381,7 +2382,8 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping, } } else { - bound_get = _PyObject_GetAttrId(mapping, &PyId_get); + attr = _Py_GET_GLOBAL_IDENTIFIER(get); + bound_get = PyObject_GetAttr(mapping, attr); if (bound_get == NULL) goto done; From 1f426491e6ba44cc9abc9ed8cfa4ed645bab5ddb Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 08:54:48 -0700 Subject: [PATCH 069/115] Get rid of _Py_IDENTIFIER() in itertoolsmodule.c. --- Modules/itertoolsmodule.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 342a3e6555ba051..aae195b4625efcc 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -503,9 +503,9 @@ _grouper_next(_grouperobject *igo) static PyObject * _grouper_reduce(_grouperobject *lz, PyObject *Py_UNUSED(ignored)) { - _Py_IDENTIFIER(iter); if (((groupbyobject *)lz->parent)->currgrouper != lz) { - return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter)); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); } return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->parent, lz->tgtkey); } @@ -1015,7 +1015,6 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n) { Py_ssize_t i; PyObject *it, *copyable, *copyfunc, *result; - _Py_IDENTIFIER(__copy__); if (n < 0) { PyErr_SetString(PyExc_ValueError, "n must be >= 0"); @@ -1032,7 +1031,8 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n) return NULL; } - if (_PyObject_LookupAttrId(it, &PyId___copy__, ©func) < 0) { + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__copy__); + if (_PyObject_LookupAttr(it, attr, ©func) < 0) { Py_DECREF(it); Py_DECREF(result); return NULL; @@ -1047,7 +1047,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n) Py_DECREF(result); return NULL; } - copyfunc = _PyObject_GetAttrId(copyable, &PyId___copy__); + copyfunc = PyObject_GetAttr(copyable, attr); if (copyfunc == NULL) { Py_DECREF(copyable); Py_DECREF(result); @@ -1179,9 +1179,8 @@ cycle_reduce(cycleobject *lz, PyObject *Py_UNUSED(ignored)) if (it == NULL) return NULL; if (lz->index != 0) { - _Py_IDENTIFIER(__setstate__); - PyObject *res = _PyObject_CallMethodId(it, &PyId___setstate__, - "n", lz->index); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setstate__); + PyObject *res = _PyObject_CallMethod(it, attr, "n", lz->index); if (res == NULL) { Py_DECREF(it); return NULL; @@ -4545,7 +4544,6 @@ static PyTypeObject ziplongest_type; static PyObject * zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - _Py_IDENTIFIER(fillvalue); ziplongestobject *lz; Py_ssize_t i; PyObject *ittuple; /* tuple of iterators */ @@ -4556,7 +4554,8 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_GET_SIZE(kwds) > 0) { fillvalue = NULL; if (PyDict_GET_SIZE(kwds) == 1) { - fillvalue = _PyDict_GetItemIdWithError(kwds, &PyId_fillvalue); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(fillvalue); + fillvalue = PyDict_GetItemWithError(kwds, attr); } if (fillvalue == NULL) { if (!PyErr_Occurred()) { From c2f1cfbcec40ff45f85815eefc1ae24682c9f1b4 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 09:38:25 -0700 Subject: [PATCH 070/115] Get rid of _Py_IDENTIFIER() in posixmodule.c. --- Modules/posixmodule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 0efe5ffdbad05fe..f07576103518dea 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -323,8 +323,6 @@ corresponding Unix manual entries for more information on calls."); # endif /* _MSC_VER */ #endif /* ! __WATCOMC__ || __QNX__ */ -_Py_IDENTIFIER(__fspath__); - /*[clinic input] # one of the few times we lie about this name! module os @@ -1159,7 +1157,8 @@ path_converter(PyObject *o, void *p) /* Inline PyOS_FSPath() for better error messages. */ PyObject *func, *res; - func = _PyObject_LookupSpecialId(o, &PyId___fspath__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__fspath__); + func = _PyObject_LookupSpecial(o, attr); if (NULL == func) { goto error_format; } @@ -14437,7 +14436,8 @@ PyOS_FSPath(PyObject *path) return path; } - func = _PyObject_LookupSpecialId(path, &PyId___fspath__); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__fspath__); + func = _PyObject_LookupSpecial(path, attr); if (NULL == func) { return PyErr_Format(PyExc_TypeError, "expected str, bytes or os.PathLike object, " From 3ed68a75edb07199984b29ddbe75d9958508114a Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 09:39:46 -0700 Subject: [PATCH 071/115] Get rid of _Py_IDENTIFIER() in _operator.c. --- Modules/_operator.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Modules/_operator.c b/Modules/_operator.c index b3a8bef2eaedd98..03d9155091dc779 100644 --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -1,5 +1,6 @@ #include "Python.h" #include "pycore_moduleobject.h" // _PyModule_GetState() +#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() #include "clinic/_operator.c.h" typedef struct { @@ -1693,11 +1694,11 @@ methodcaller_reduce(methodcallerobject *mc, PyObject *Py_UNUSED(ignored)) PyObject *constructor; PyObject *newargs[2]; - _Py_IDENTIFIER(partial); functools = PyImport_ImportModule("functools"); if (!functools) return NULL; - partial = _PyObject_GetAttrId(functools, &PyId_partial); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(partial); + partial = PyObject_GetAttr(functools, attr); Py_DECREF(functools); if (!partial) return NULL; From d86ceb15a2ef1e6a20ac8dc9323f3a841cffa943 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 09:40:45 -0700 Subject: [PATCH 072/115] Get rid of _Py_IDENTIFIER() in timemodule.c. --- Modules/timemodule.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 35b8e14e827112f..6c3f0b7c62c4090 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -4,6 +4,7 @@ #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_namespace.h" // _PyNamespace_New() +#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() #include @@ -910,13 +911,13 @@ static PyObject * time_strptime(PyObject *self, PyObject *args) { PyObject *module, *func, *result; - _Py_IDENTIFIER(_strptime_time); module = PyImport_ImportModule("_strptime"); if (!module) return NULL; - func = _PyObject_GetAttrId(module, &PyId__strptime_time); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_strptime_time); + func = PyObject_GetAttr(module, attr); Py_DECREF(module); if (!func) { return NULL; From c0c6777fddd204db7b2fab442392bc5e654356c7 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 09:41:19 -0700 Subject: [PATCH 073/115] Get rid of _Py_IDENTIFIER() in main.c. --- Modules/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/main.c b/Modules/main.c index b9bcea393abe3cf..9aecf505e9ade60 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -158,11 +158,11 @@ pymain_get_importer(const wchar_t *filename, PyObject **importer_p, int *exitcod static int pymain_sys_path_add_path0(PyInterpreterState *interp, PyObject *path0) { - _Py_IDENTIFIER(path); PyObject *sys_path; PyObject *sysdict = interp->sysdict; if (sysdict != NULL) { - sys_path = _PyDict_GetItemIdWithError(sysdict, &PyId_path); + PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(path); + sys_path = PyDict_GetItemWithError(sysdict, attr); if (sys_path == NULL && PyErr_Occurred()) { return -1; } From c9f4563d2f281a2edbd3375fd9d2c076437f3488 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 11:04:49 -0700 Subject: [PATCH 074/115] Get rid of _Py_static_string() in typeobject.c. --- Objects/typeobject.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index aad2b43f1a596ae..4952067708cb9e9 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4563,7 +4563,6 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyObject *sorted_methods; PyObject *joined; PyObject *comma; - _Py_static_string(comma_id, ", "); Py_ssize_t method_count; /* Compute ", ".join(sorted(type.__abstractmethods__)) @@ -4579,11 +4578,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) Py_DECREF(sorted_methods); return NULL; } - comma = _PyUnicode_FromId(&comma_id); - if (comma == NULL) { - Py_DECREF(sorted_methods); - return NULL; - } + comma = _Py_GET_GLOBAL_STRING(comma_sep); joined = PyUnicode_Join(comma, sorted_methods); method_count = PyObject_Length(sorted_methods); Py_DECREF(sorted_methods); From 079647569134f3f16d78122ef9d19f44b4377a94 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 11:15:11 -0700 Subject: [PATCH 075/115] Get rid of _Py_static_string() in ast_opt.c. --- Include/internal/pycore_global_strings.h | 3 +++ Include/internal/pycore_runtime_init.h | 3 +++ Python/ast_opt.c | 10 ++-------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 63984e8f5cacedf..5be6c3b9a06e44b 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -36,6 +36,9 @@ struct _Py_global_strings { STR(br_dbl_open, "{{") STR(br_dbl_close, "}}") + STR(percent, "%") + STR(dbl_percent, "%%") + STR(anon_dictcomp, "") STR(anon_genexpr, "") STR(anon_lambda, "") diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index e53f4abeedba628..e5217bc8b932637 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -658,6 +658,9 @@ extern "C" { INIT_STR(br_dbl_open, "{{"), \ INIT_STR(br_dbl_close, "}}"), \ \ + INIT_STR(percent, "%"), \ + INIT_STR(dbl_percent, "%%"), \ + \ INIT_STR(anon_dictcomp, ""), \ INIT_STR(anon_genexpr, ""), \ INIT_STR(anon_lambda, ""), \ diff --git a/Python/ast_opt.c b/Python/ast_opt.c index 2821e69a35521ed..0463b3994d8f6c1 100644 --- a/Python/ast_opt.c +++ b/Python/ast_opt.c @@ -268,14 +268,8 @@ parse_literal(PyObject *fmt, Py_ssize_t *ppos, PyArena *arena) PyObject *str = PyUnicode_Substring(fmt, start, pos); /* str = str.replace('%%', '%') */ if (str && has_percents) { - _Py_static_string(PyId_double_percent, "%%"); - _Py_static_string(PyId_percent, "%"); - PyObject *double_percent = _PyUnicode_FromId(&PyId_double_percent); - PyObject *percent = _PyUnicode_FromId(&PyId_percent); - if (!double_percent || !percent) { - Py_DECREF(str); - return NULL; - } + PyObject *double_percent = _Py_GET_GLOBAL_STRING(dbl_percent); + PyObject *percent = _Py_GET_GLOBAL_STRING(percent); Py_SETREF(str, PyUnicode_Replace(str, double_percent, percent, -1)); } if (!str) { From 3e5fac384def758bb0cdee75bb1f576bc61fb9c5 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 11:15:24 -0700 Subject: [PATCH 076/115] Get rid of _Py_static_string() in compile.c. --- Python/compile.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Python/compile.c b/Python/compile.c index 49e38ca56a3f48a..879f8416c8deb9c 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -633,8 +633,6 @@ compiler_unit_free(struct compiler_unit *u) static int compiler_set_qualname(struct compiler *c) { - _Py_static_string(dot, "."); - _Py_static_string(dot_locals, "."); Py_ssize_t stack_size; struct compiler_unit *u = c->u; PyObject *name, *base, *dot_str, *dot_locals_str; @@ -668,10 +666,9 @@ compiler_set_qualname(struct compiler *c) if (!force_global) { if (parent->u_scope_type == COMPILER_SCOPE_FUNCTION || parent->u_scope_type == COMPILER_SCOPE_ASYNC_FUNCTION - || parent->u_scope_type == COMPILER_SCOPE_LAMBDA) { - dot_locals_str = _PyUnicode_FromId(&dot_locals); - if (dot_locals_str == NULL) - return 0; + || parent->u_scope_type == COMPILER_SCOPE_LAMBDA) + { + dot_locals_str = _Py_GET_GLOBAL_STRING(dot_locals); base = PyUnicode_Concat(parent->u_qualname, dot_locals_str); if (base == NULL) return 0; @@ -684,11 +681,7 @@ compiler_set_qualname(struct compiler *c) } if (base != NULL) { - dot_str = _PyUnicode_FromId(&dot); - if (dot_str == NULL) { - Py_DECREF(base); - return 0; - } + dot_str = _Py_GET_GLOBAL_STRING(dot); name = PyUnicode_Concat(base, dot_str); Py_DECREF(base); if (name == NULL) From 77d423e696d7b71e607443695d99dd3a52674020 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 09:59:43 -0700 Subject: [PATCH 077/115] Disallow _Py_IDENTIFIER in core. --- Include/cpython/abstract.h | 4 ++ Include/cpython/ceval.h | 2 + Include/cpython/dictobject.h | 13 ++++-- Include/cpython/import.h | 2 + Include/cpython/object.h | 81 ++++++++++++++++++--------------- Include/cpython/sysmodule.h | 3 ++ Include/cpython/unicodeobject.h | 20 ++++---- 7 files changed, 75 insertions(+), 50 deletions(-) diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h index 3a688542ed6d028..44c8e8af1f0d7d7 100644 --- a/Include/cpython/abstract.h +++ b/Include/cpython/abstract.h @@ -120,6 +120,8 @@ PyAPI_FUNC(PyObject *) _PyObject_CallMethod(PyObject *obj, PyObject *name, const char *format, ...); +#ifdef _Py_IDENTIFIER + /* Like PyObject_CallMethod(), but expect a _Py_Identifier* as the method name. */ PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj, @@ -165,6 +167,8 @@ _PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); } +#endif /* _Py_IDENTIFIER */ + PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o); /* Guess the size of object 'o' using len(o) or o.__length_hint__(). diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index aedc7367a18f640..db41500c667da3f 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -16,7 +16,9 @@ PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void); /* Helper to look up a builtin object */ PyAPI_FUNC(PyObject *) _PyEval_GetBuiltin(PyObject *); +#ifdef _Py_IDENTIFIER PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *); +#endif /* Look at the current frame's (if any) code's co_flags, and turn on the corresponding compiler flags in cf->cf_flags. Return 1 if any flag was set, else return 0. */ diff --git a/Include/cpython/dictobject.h b/Include/cpython/dictobject.h index d5119644c521254..107ac903446e0f6 100644 --- a/Include/cpython/dictobject.h +++ b/Include/cpython/dictobject.h @@ -31,8 +31,6 @@ typedef struct { PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, Py_hash_t hash); PyAPI_FUNC(PyObject *) _PyDict_GetItemWithError(PyObject *dp, PyObject *key); -PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, - struct _Py_Identifier *key); PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *); PyAPI_FUNC(PyObject *) PyDict_SetDefault( PyObject *mp, PyObject *key, PyObject *defaultobj); @@ -49,7 +47,6 @@ PyAPI_FUNC(int) _PyDict_Next( /* Get the number of items of a dictionary. */ #define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used) PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t); -PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, struct _Py_Identifier *); PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused); PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp); PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp); @@ -66,15 +63,21 @@ PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *); argument is raised. */ PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override); -PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item); -PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key); PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out); int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value); PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *); Py_ssize_t _PyDict_GetItemHint(PyDictObject *, PyObject *, Py_ssize_t, PyObject **); +#ifdef _Py_IDENTIFIER +PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, + struct _Py_Identifier *key); +PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, struct _Py_Identifier *); +PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item); +PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key); +#endif + /* _PyDictView */ typedef struct { diff --git a/Include/cpython/import.h b/Include/cpython/import.h index 5ec637e7ab3b8cb..829925e0837b860 100644 --- a/Include/cpython/import.h +++ b/Include/cpython/import.h @@ -6,7 +6,9 @@ PyMODINIT_FUNC PyInit__imp(void); PyAPI_FUNC(int) _PyImport_IsInitialized(PyInterpreterState *); +#ifdef _Py_IDENTIFIER PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(struct _Py_Identifier *name); +#endif PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module); PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module); diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 0acf90bb58e6bf1..89ab4261c84496f 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -14,37 +14,6 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); #endif -/********************* String Literals ****************************************/ -/* This structure helps managing static strings. The basic usage goes like this: - Instead of doing - - r = PyObject_CallMethod(o, "foo", "args", ...); - - do - - _Py_IDENTIFIER(foo); - ... - r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...); - - PyId_foo is a static variable, either on block level or file level. On first - usage, the string "foo" is interned, and the structures are linked. On interpreter - shutdown, all strings are released. - - Alternatively, _Py_static_string allows choosing the variable name. - _PyUnicode_FromId returns a borrowed reference to the interned string. - _PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*. -*/ -typedef struct _Py_Identifier { - const char* string; - // Index in PyInterpreterState.unicode.ids.array. It is process-wide - // unique and must be initialized to -1. - Py_ssize_t index; -} _Py_Identifier; - -#define _Py_static_string_init(value) { .string = value, .index = -1 } -#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value) -#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname) - /* buffer interface */ typedef struct bufferinfo { void *buf; @@ -295,24 +264,19 @@ typedef struct _heaptypeobject { PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *); PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *); -PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *); PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *); -PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *); PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *); PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *); struct PyModuleDef; PyAPI_FUNC(PyObject *) _PyType_GetModuleByDef(PyTypeObject *, struct PyModuleDef *); -struct _Py_Identifier; PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int); PyAPI_FUNC(void) _Py_BreakPoint(void); PyAPI_FUNC(void) _PyObject_Dump(PyObject *); PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *); PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *); -PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *); -PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *); /* Replacements of PyObject_GetAttr() and _PyObject_GetAttrId() which don't raise AttributeError. @@ -323,7 +287,6 @@ PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObjec is raised. */ PyAPI_FUNC(int) _PyObject_LookupAttr(PyObject *, PyObject *, PyObject **); -PyAPI_FUNC(int) _PyObject_LookupAttrId(PyObject *, struct _Py_Identifier *, PyObject **); PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); @@ -342,6 +305,50 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *, PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *); +/********************* String Literals ****************************************/ +/* This structure helps managing static strings. The basic usage goes like this: + Instead of doing + + r = PyObject_CallMethod(o, "foo", "args", ...); + + do + + _Py_IDENTIFIER(foo); + ... + r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...); + + PyId_foo is a static variable, either on block level or file level. On first + usage, the string "foo" is interned, and the structures are linked. On interpreter + shutdown, all strings are released. + + Alternatively, _Py_static_string allows choosing the variable name. + _PyUnicode_FromId returns a borrowed reference to the interned string. + _PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*. +*/ +typedef struct _Py_Identifier { + const char* string; + // Index in PyInterpreterState.unicode.ids.array. It is process-wide + // unique and must be initialized to -1. + Py_ssize_t index; +} _Py_Identifier; + +#if !defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE) +// For now we are keeping _Py_IDENTIFIER for continued use +// in non-builtin extensions (and naughty PyPI modules). + +#define _Py_static_string_init(value) { .string = value, .index = -1 } +#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value) +#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname) + +#endif /* ! Py_BUILD_CORE */ + +PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *); +PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *); +struct _Py_Identifier; +PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *); +PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *); +PyAPI_FUNC(int) _PyObject_LookupAttrId(PyObject *, struct _Py_Identifier *, PyObject **); + /* Safely decref `op` and set `op` to `op2`. * * As in case of Py_CLEAR "the obvious" code can be deadly: diff --git a/Include/cpython/sysmodule.h b/Include/cpython/sysmodule.h index 27dff7b2e3d9308..a0e3b36a930046f 100644 --- a/Include/cpython/sysmodule.h +++ b/Include/cpython/sysmodule.h @@ -4,8 +4,11 @@ PyAPI_FUNC(PyObject *) _PySys_GetAttr(PyThreadState *tstate, PyObject *name); + +#ifdef _Py_IDENTIFIER PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key); PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *); +#endif PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *); diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index be5647c7d263c29..48bc92a62a78cae 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -861,14 +861,6 @@ PyAPI_FUNC(PyObject *) _PyUnicode_JoinArray( Py_ssize_t seqlen ); -/* Test whether a unicode is equal to ASCII identifier. Return 1 if true, - 0 otherwise. The right argument must be ASCII identifier. - Any error occurs inside will be cleared before return. */ -PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId( - PyObject *left, /* Left string */ - _Py_Identifier *right /* Right identifier */ - ); - /* Test whether a unicode is equal to ASCII string. Return 1 if true, 0 otherwise. The right argument must be ASCII-encoded string. Any error occurs inside will be cleared before return. */ @@ -1013,9 +1005,21 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha( PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int); +#ifdef _Py_IDENTIFIER + +/* Test whether a unicode is equal to ASCII identifier. Return 1 if true, + 0 otherwise. The right argument must be ASCII identifier. + Any error occurs inside will be cleared before return. */ +PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId( + PyObject *left, /* Left string */ + _Py_Identifier *right /* Right identifier */ + ); + /* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/ PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*); +#endif /* _Py_IDENTIFIER */ + /* Fast equality check when the inputs are known to be exact unicode types and where the hash values are equal (i.e. a very probable match) */ PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *); From 308fb9ec3c9b2bc905b98684c4a0ed80cac87aa4 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 11:00:10 -0700 Subject: [PATCH 078/115] Leave all the functions. --- Include/cpython/abstract.h | 4 -- Include/cpython/ceval.h | 2 - Include/cpython/dictobject.h | 13 ++--- Include/cpython/import.h | 2 - Include/cpython/object.h | 87 ++++++++++++++++----------------- Include/cpython/sysmodule.h | 3 -- Include/cpython/unicodeobject.h | 20 +++----- 7 files changed, 56 insertions(+), 75 deletions(-) diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h index 44c8e8af1f0d7d7..3a688542ed6d028 100644 --- a/Include/cpython/abstract.h +++ b/Include/cpython/abstract.h @@ -120,8 +120,6 @@ PyAPI_FUNC(PyObject *) _PyObject_CallMethod(PyObject *obj, PyObject *name, const char *format, ...); -#ifdef _Py_IDENTIFIER - /* Like PyObject_CallMethod(), but expect a _Py_Identifier* as the method name. */ PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj, @@ -167,8 +165,6 @@ _PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); } -#endif /* _Py_IDENTIFIER */ - PyAPI_FUNC(int) _PyObject_HasLen(PyObject *o); /* Guess the size of object 'o' using len(o) or o.__length_hint__(). diff --git a/Include/cpython/ceval.h b/Include/cpython/ceval.h index db41500c667da3f..aedc7367a18f640 100644 --- a/Include/cpython/ceval.h +++ b/Include/cpython/ceval.h @@ -16,9 +16,7 @@ PyAPI_FUNC(PyObject *) _PyEval_GetAsyncGenFinalizer(void); /* Helper to look up a builtin object */ PyAPI_FUNC(PyObject *) _PyEval_GetBuiltin(PyObject *); -#ifdef _Py_IDENTIFIER PyAPI_FUNC(PyObject *) _PyEval_GetBuiltinId(_Py_Identifier *); -#endif /* Look at the current frame's (if any) code's co_flags, and turn on the corresponding compiler flags in cf->cf_flags. Return 1 if any flag was set, else return 0. */ diff --git a/Include/cpython/dictobject.h b/Include/cpython/dictobject.h index 107ac903446e0f6..d5119644c521254 100644 --- a/Include/cpython/dictobject.h +++ b/Include/cpython/dictobject.h @@ -31,6 +31,8 @@ typedef struct { PyAPI_FUNC(PyObject *) _PyDict_GetItem_KnownHash(PyObject *mp, PyObject *key, Py_hash_t hash); PyAPI_FUNC(PyObject *) _PyDict_GetItemWithError(PyObject *dp, PyObject *key); +PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, + struct _Py_Identifier *key); PyAPI_FUNC(PyObject *) _PyDict_GetItemStringWithError(PyObject *, const char *); PyAPI_FUNC(PyObject *) PyDict_SetDefault( PyObject *mp, PyObject *key, PyObject *defaultobj); @@ -47,6 +49,7 @@ PyAPI_FUNC(int) _PyDict_Next( /* Get the number of items of a dictionary. */ #define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used) PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t); +PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, struct _Py_Identifier *); PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused); PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp); PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp); @@ -63,21 +66,15 @@ PyObject *_PyDict_FromKeys(PyObject *, PyObject *, PyObject *); argument is raised. */ PyAPI_FUNC(int) _PyDict_MergeEx(PyObject *mp, PyObject *other, int override); +PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item); +PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key); PyAPI_FUNC(void) _PyDict_DebugMallocStats(FILE *out); int _PyObjectDict_SetItem(PyTypeObject *tp, PyObject **dictptr, PyObject *name, PyObject *value); PyObject *_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *); Py_ssize_t _PyDict_GetItemHint(PyDictObject *, PyObject *, Py_ssize_t, PyObject **); -#ifdef _Py_IDENTIFIER -PyAPI_FUNC(PyObject *) _PyDict_GetItemIdWithError(PyObject *dp, - struct _Py_Identifier *key); -PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, struct _Py_Identifier *); -PyAPI_FUNC(int) _PyDict_SetItemId(PyObject *dp, struct _Py_Identifier *key, PyObject *item); -PyAPI_FUNC(int) _PyDict_DelItemId(PyObject *mp, struct _Py_Identifier *key); -#endif - /* _PyDictView */ typedef struct { diff --git a/Include/cpython/import.h b/Include/cpython/import.h index 829925e0837b860..5ec637e7ab3b8cb 100644 --- a/Include/cpython/import.h +++ b/Include/cpython/import.h @@ -6,9 +6,7 @@ PyMODINIT_FUNC PyInit__imp(void); PyAPI_FUNC(int) _PyImport_IsInitialized(PyInterpreterState *); -#ifdef _Py_IDENTIFIER PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(struct _Py_Identifier *name); -#endif PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module); PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module); diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 89ab4261c84496f..0f77ebe97de1ba0 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -14,6 +14,43 @@ PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void); #endif +/********************* String Literals ****************************************/ +/* This structure helps managing static strings. The basic usage goes like this: + Instead of doing + + r = PyObject_CallMethod(o, "foo", "args", ...); + + do + + _Py_IDENTIFIER(foo); + ... + r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...); + + PyId_foo is a static variable, either on block level or file level. On first + usage, the string "foo" is interned, and the structures are linked. On interpreter + shutdown, all strings are released. + + Alternatively, _Py_static_string allows choosing the variable name. + _PyUnicode_FromId returns a borrowed reference to the interned string. + _PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*. +*/ +typedef struct _Py_Identifier { + const char* string; + // Index in PyInterpreterState.unicode.ids.array. It is process-wide + // unique and must be initialized to -1. + Py_ssize_t index; +} _Py_Identifier; + +#if !defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE) +// For now we are keeping _Py_IDENTIFIER for continued use +// in non-builtin extensions (and naughty PyPI modules). + +#define _Py_static_string_init(value) { .string = value, .index = -1 } +#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value) +#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname) + +#endif /* ! Py_BUILD_CORE */ + /* buffer interface */ typedef struct bufferinfo { void *buf; @@ -264,19 +301,24 @@ typedef struct _heaptypeobject { PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *); PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *); +PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *); PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *); +PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *); PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *); PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *); struct PyModuleDef; PyAPI_FUNC(PyObject *) _PyType_GetModuleByDef(PyTypeObject *, struct PyModuleDef *); +struct _Py_Identifier; PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int); PyAPI_FUNC(void) _Py_BreakPoint(void); PyAPI_FUNC(void) _PyObject_Dump(PyObject *); PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *); PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *); +PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *); +PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *); /* Replacements of PyObject_GetAttr() and _PyObject_GetAttrId() which don't raise AttributeError. @@ -287,6 +329,7 @@ PyAPI_FUNC(int) _PyObject_IsAbstract(PyObject *); is raised. */ PyAPI_FUNC(int) _PyObject_LookupAttr(PyObject *, PyObject *, PyObject **); +PyAPI_FUNC(int) _PyObject_LookupAttrId(PyObject *, struct _Py_Identifier *, PyObject **); PyAPI_FUNC(int) _PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); @@ -305,50 +348,6 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *, PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *); -/********************* String Literals ****************************************/ -/* This structure helps managing static strings. The basic usage goes like this: - Instead of doing - - r = PyObject_CallMethod(o, "foo", "args", ...); - - do - - _Py_IDENTIFIER(foo); - ... - r = _PyObject_CallMethodId(o, &PyId_foo, "args", ...); - - PyId_foo is a static variable, either on block level or file level. On first - usage, the string "foo" is interned, and the structures are linked. On interpreter - shutdown, all strings are released. - - Alternatively, _Py_static_string allows choosing the variable name. - _PyUnicode_FromId returns a borrowed reference to the interned string. - _PyObject_{Get,Set,Has}AttrId are __getattr__ versions using _Py_Identifier*. -*/ -typedef struct _Py_Identifier { - const char* string; - // Index in PyInterpreterState.unicode.ids.array. It is process-wide - // unique and must be initialized to -1. - Py_ssize_t index; -} _Py_Identifier; - -#if !defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE) -// For now we are keeping _Py_IDENTIFIER for continued use -// in non-builtin extensions (and naughty PyPI modules). - -#define _Py_static_string_init(value) { .string = value, .index = -1 } -#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value) -#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname) - -#endif /* ! Py_BUILD_CORE */ - -PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *); -PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *); -struct _Py_Identifier; -PyAPI_FUNC(PyObject *) _PyObject_GetAttrId(PyObject *, struct _Py_Identifier *); -PyAPI_FUNC(int) _PyObject_SetAttrId(PyObject *, struct _Py_Identifier *, PyObject *); -PyAPI_FUNC(int) _PyObject_LookupAttrId(PyObject *, struct _Py_Identifier *, PyObject **); - /* Safely decref `op` and set `op` to `op2`. * * As in case of Py_CLEAR "the obvious" code can be deadly: diff --git a/Include/cpython/sysmodule.h b/Include/cpython/sysmodule.h index a0e3b36a930046f..27dff7b2e3d9308 100644 --- a/Include/cpython/sysmodule.h +++ b/Include/cpython/sysmodule.h @@ -4,11 +4,8 @@ PyAPI_FUNC(PyObject *) _PySys_GetAttr(PyThreadState *tstate, PyObject *name); - -#ifdef _Py_IDENTIFIER PyAPI_FUNC(PyObject *) _PySys_GetObjectId(_Py_Identifier *key); PyAPI_FUNC(int) _PySys_SetObjectId(_Py_Identifier *key, PyObject *); -#endif PyAPI_FUNC(size_t) _PySys_GetSizeOf(PyObject *); diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 48bc92a62a78cae..be5647c7d263c29 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -861,6 +861,14 @@ PyAPI_FUNC(PyObject *) _PyUnicode_JoinArray( Py_ssize_t seqlen ); +/* Test whether a unicode is equal to ASCII identifier. Return 1 if true, + 0 otherwise. The right argument must be ASCII identifier. + Any error occurs inside will be cleared before return. */ +PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId( + PyObject *left, /* Left string */ + _Py_Identifier *right /* Right identifier */ + ); + /* Test whether a unicode is equal to ASCII string. Return 1 if true, 0 otherwise. The right argument must be ASCII-encoded string. Any error occurs inside will be cleared before return. */ @@ -1005,21 +1013,9 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha( PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int); -#ifdef _Py_IDENTIFIER - -/* Test whether a unicode is equal to ASCII identifier. Return 1 if true, - 0 otherwise. The right argument must be ASCII identifier. - Any error occurs inside will be cleared before return. */ -PyAPI_FUNC(int) _PyUnicode_EqualToASCIIId( - PyObject *left, /* Left string */ - _Py_Identifier *right /* Right identifier */ - ); - /* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/ PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*); -#endif /* _Py_IDENTIFIER */ - /* Fast equality check when the inputs are known to be exact unicode types and where the hash values are equal (i.e. a very probable match) */ PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *); From 21365773cb585b00bedbd3e30d440602e35de1ad Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 26 Jan 2022 19:30:23 -0700 Subject: [PATCH 079/115] Auto-generate the global strings. --- Include/internal/pycore_global_strings.h | 533 ++++++++++++----------- Include/internal/pycore_runtime_init.h | 523 +++++++++++----------- Tools/scripts/generate_global_objects.py | 375 ++++++++++++++++ 3 files changed, 902 insertions(+), 529 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 5be6c3b9a06e44b..014cff83bf0e05f 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -23,22 +23,24 @@ extern "C" { // XXX Order by frequency of use? +/* The following is auto-generated by Tools/scripts/generate_global_objects.py. */ struct _Py_global_strings { struct { STR(empty, "") - STR(newline, "\n") // nl + STR(newline, "\n") STR(dot, ".") + STR(comma_sep, ", ") + STR(percent, "%") + STR(dbl_percent, "%%") + STR(replace_inf, "1eNN") - STR(comma_sep, ", ") // comma_id - + // braces STR(br_open, "{") STR(br_close, "}") STR(br_dbl_open, "{{") STR(br_dbl_close, "}}") - STR(percent, "%") - STR(dbl_percent, "%%") - + // "anonymous" labels STR(anon_dictcomp, "") STR(anon_genexpr, "") STR(anon_lambda, "") @@ -48,265 +50,263 @@ struct _Py_global_strings { STR(anon_string, "") STR(dot_locals, ".") - STR(replace_inf, "1eNN") - //STR(replace_inf, ['1', 'e', 1 + DBL_MAX_10_EXP]) - - STR(latin1_0, "\x00") - STR(latin1_1, "\x01") - STR(latin1_2, "\x02") - STR(latin1_3, "\x03") - STR(latin1_4, "\x04") - STR(latin1_5, "\x05") - STR(latin1_6, "\x06") - STR(latin1_7, "\x07") - STR(latin1_8, "\x08") - STR(latin1_9, "\x09") - STR(latin1_10, "\x0A") - STR(latin1_11, "\x0B") - STR(latin1_12, "\x0C") - STR(latin1_13, "\x0D") - STR(latin1_14, "\x0E") - STR(latin1_15, "\x0F") - STR(latin1_16, "\x10") - STR(latin1_17, "\x11") - STR(latin1_18, "\x12") - STR(latin1_19, "\x13") - STR(latin1_20, "\x14") - STR(latin1_21, "\x15") - STR(latin1_22, "\x16") - STR(latin1_23, "\x17") - STR(latin1_24, "\x18") - STR(latin1_25, "\x19") - STR(latin1_26, "\x1A") - STR(latin1_27, "\x1B") - STR(latin1_28, "\x1C") - STR(latin1_29, "\x1D") - STR(latin1_30, "\x1E") - STR(latin1_31, "\x1F") - STR(latin1_32, "\x20") - STR(latin1_33, "\x21") - STR(latin1_34, "\x22") - STR(latin1_35, "\x23") - STR(latin1_36, "\x24") - STR(latin1_37, "\x25") - STR(latin1_38, "\x26") - STR(latin1_39, "\x27") - STR(latin1_40, "\x28") - STR(latin1_41, "\x29") - STR(latin1_42, "\x2A") - STR(latin1_43, "\x2B") - STR(latin1_44, "\x2C") - STR(latin1_45, "\x2D") - STR(latin1_46, "\x2E") - STR(latin1_47, "\x2F") - STR(latin1_48, "\x30") - STR(latin1_49, "\x31") - STR(latin1_50, "\x32") - STR(latin1_51, "\x33") - STR(latin1_52, "\x34") - STR(latin1_53, "\x35") - STR(latin1_54, "\x36") - STR(latin1_55, "\x37") - STR(latin1_56, "\x38") - STR(latin1_57, "\x39") - STR(latin1_58, "\x3A") - STR(latin1_59, "\x3B") - STR(latin1_60, "\x3C") - STR(latin1_61, "\x3D") - STR(latin1_62, "\x3E") - STR(latin1_63, "\x3F") - STR(latin1_64, "\x40") - STR(latin1_65, "\x41") - STR(latin1_66, "\x42") - STR(latin1_67, "\x43") - STR(latin1_68, "\x44") - STR(latin1_69, "\x45") - STR(latin1_70, "\x46") - STR(latin1_71, "\x47") - STR(latin1_72, "\x48") - STR(latin1_73, "\x49") - STR(latin1_74, "\x4A") - STR(latin1_75, "\x4B") - STR(latin1_76, "\x4C") - STR(latin1_77, "\x4D") - STR(latin1_78, "\x4E") - STR(latin1_79, "\x4F") - STR(latin1_80, "\x50") - STR(latin1_81, "\x51") - STR(latin1_82, "\x52") - STR(latin1_83, "\x53") - STR(latin1_84, "\x54") - STR(latin1_85, "\x55") - STR(latin1_86, "\x56") - STR(latin1_87, "\x57") - STR(latin1_88, "\x58") - STR(latin1_89, "\x59") - STR(latin1_90, "\x5A") - STR(latin1_91, "\x5B") - STR(latin1_92, "\x5C") - STR(latin1_93, "\x5D") - STR(latin1_94, "\x5E") - STR(latin1_95, "\x5F") - STR(latin1_96, "\x60") - STR(latin1_97, "\x61") - STR(latin1_98, "\x62") - STR(latin1_99, "\x63") - STR(latin1_100, "\x64") - STR(latin1_101, "\x65") - STR(latin1_102, "\x66") - STR(latin1_103, "\x67") - STR(latin1_104, "\x68") - STR(latin1_105, "\x69") - STR(latin1_106, "\x6A") - STR(latin1_107, "\x6B") - STR(latin1_108, "\x6C") - STR(latin1_109, "\x6D") - STR(latin1_110, "\x6E") - STR(latin1_111, "\x6F") - STR(latin1_112, "\x70") - STR(latin1_113, "\x71") - STR(latin1_114, "\x72") - STR(latin1_115, "\x73") - STR(latin1_116, "\x74") - STR(latin1_117, "\x75") - STR(latin1_118, "\x76") - STR(latin1_119, "\x77") - STR(latin1_120, "\x78") - STR(latin1_121, "\x79") - STR(latin1_122, "\x7A") - STR(latin1_123, "\x7B") - STR(latin1_124, "\x7C") - STR(latin1_125, "\x7D") - STR(latin1_126, "\x7E") - STR(latin1_127, "\x7F") - STR(latin1_128, "\x80") - STR(latin1_129, "\x81") - STR(latin1_130, "\x82") - STR(latin1_131, "\x83") - STR(latin1_132, "\x84") - STR(latin1_133, "\x85") - STR(latin1_134, "\x86") - STR(latin1_135, "\x87") - STR(latin1_136, "\x88") - STR(latin1_137, "\x89") - STR(latin1_138, "\x8A") - STR(latin1_139, "\x8B") - STR(latin1_140, "\x8C") - STR(latin1_141, "\x8D") - STR(latin1_142, "\x8E") - STR(latin1_143, "\x8F") - STR(latin1_144, "\x90") - STR(latin1_145, "\x91") - STR(latin1_146, "\x92") - STR(latin1_147, "\x93") - STR(latin1_148, "\x94") - STR(latin1_149, "\x95") - STR(latin1_150, "\x96") - STR(latin1_151, "\x97") - STR(latin1_152, "\x98") - STR(latin1_153, "\x99") - STR(latin1_154, "\x9A") - STR(latin1_155, "\x9B") - STR(latin1_156, "\x9C") - STR(latin1_157, "\x9D") - STR(latin1_158, "\x9E") - STR(latin1_159, "\x9F") - STR(latin1_160, "\xA0") - STR(latin1_161, "\xA1") - STR(latin1_162, "\xA2") - STR(latin1_163, "\xA3") - STR(latin1_164, "\xA4") - STR(latin1_165, "\xA5") - STR(latin1_166, "\xA6") - STR(latin1_167, "\xA7") - STR(latin1_168, "\xA8") - STR(latin1_169, "\xA9") - STR(latin1_170, "\xAA") - STR(latin1_171, "\xAB") - STR(latin1_172, "\xAC") - STR(latin1_173, "\xAD") - STR(latin1_174, "\xAE") - STR(latin1_175, "\xAF") - STR(latin1_176, "\xB0") - STR(latin1_177, "\xB1") - STR(latin1_178, "\xB2") - STR(latin1_179, "\xB3") - STR(latin1_180, "\xB4") - STR(latin1_181, "\xB5") - STR(latin1_182, "\xB6") - STR(latin1_183, "\xB7") - STR(latin1_184, "\xB8") - STR(latin1_185, "\xB9") - STR(latin1_186, "\xBA") - STR(latin1_187, "\xBB") - STR(latin1_188, "\xBC") - STR(latin1_189, "\xBD") - STR(latin1_190, "\xBE") - STR(latin1_191, "\xBF") - STR(latin1_192, "\xC0") - STR(latin1_193, "\xC1") - STR(latin1_194, "\xC2") - STR(latin1_195, "\xC3") - STR(latin1_196, "\xC4") - STR(latin1_197, "\xC5") - STR(latin1_198, "\xC6") - STR(latin1_199, "\xC7") - STR(latin1_200, "\xC8") - STR(latin1_201, "\xC9") - STR(latin1_202, "\xCA") - STR(latin1_203, "\xCB") - STR(latin1_204, "\xCC") - STR(latin1_205, "\xCD") - STR(latin1_206, "\xCE") - STR(latin1_207, "\xCF") - STR(latin1_208, "\xD0") - STR(latin1_209, "\xD1") - STR(latin1_210, "\xD2") - STR(latin1_211, "\xD3") - STR(latin1_212, "\xD4") - STR(latin1_213, "\xD5") - STR(latin1_214, "\xD6") - STR(latin1_215, "\xD7") - STR(latin1_216, "\xD8") - STR(latin1_217, "\xD9") - STR(latin1_218, "\xDA") - STR(latin1_219, "\xDB") - STR(latin1_220, "\xDC") - STR(latin1_221, "\xDD") - STR(latin1_222, "\xDE") - STR(latin1_223, "\xDF") - STR(latin1_224, "\xE0") - STR(latin1_225, "\xE1") - STR(latin1_226, "\xE2") - STR(latin1_227, "\xE3") - STR(latin1_228, "\xE4") - STR(latin1_229, "\xE5") - STR(latin1_230, "\xE6") - STR(latin1_231, "\xE7") - STR(latin1_232, "\xE8") - STR(latin1_233, "\xE9") - STR(latin1_234, "\xEA") - STR(latin1_235, "\xEB") - STR(latin1_236, "\xEC") - STR(latin1_237, "\xED") - STR(latin1_238, "\xEE") - STR(latin1_239, "\xEF") - STR(latin1_240, "\xF0") - STR(latin1_241, "\xF1") - STR(latin1_242, "\xF2") - STR(latin1_243, "\xF3") - STR(latin1_244, "\xF4") - STR(latin1_245, "\xF5") - STR(latin1_246, "\xF6") - STR(latin1_247, "\xF7") - STR(latin1_248, "\xF8") - STR(latin1_249, "\xF9") - STR(latin1_250, "\xFA") - STR(latin1_251, "\xFB") - STR(latin1_252, "\xFC") - STR(latin1_253, "\xFD") - STR(latin1_254, "\xFE") - STR(latin1_255, "\xFF") + // The single character latin-1 (ASCII) strings. + STR(latin1_0, "\x00") + STR(latin1_1, "\x01") + STR(latin1_2, "\x02") + STR(latin1_3, "\x03") + STR(latin1_4, "\x04") + STR(latin1_5, "\x05") + STR(latin1_6, "\x06") + STR(latin1_7, "\x07") + STR(latin1_8, "\x08") + STR(latin1_9, "\x09") + STR(latin1_10, "\x0A") + STR(latin1_11, "\x0B") + STR(latin1_12, "\x0C") + STR(latin1_13, "\x0D") + STR(latin1_14, "\x0E") + STR(latin1_15, "\x0F") + STR(latin1_16, "\x10") + STR(latin1_17, "\x11") + STR(latin1_18, "\x12") + STR(latin1_19, "\x13") + STR(latin1_20, "\x14") + STR(latin1_21, "\x15") + STR(latin1_22, "\x16") + STR(latin1_23, "\x17") + STR(latin1_24, "\x18") + STR(latin1_25, "\x19") + STR(latin1_26, "\x1A") + STR(latin1_27, "\x1B") + STR(latin1_28, "\x1C") + STR(latin1_29, "\x1D") + STR(latin1_30, "\x1E") + STR(latin1_31, "\x1F") + STR(latin1_32, "\x20") + STR(latin1_33, "\x21") + STR(latin1_34, "\x22") + STR(latin1_35, "\x23") + STR(latin1_36, "\x24") + STR(latin1_37, "\x25") + STR(latin1_38, "\x26") + STR(latin1_39, "\x27") + STR(latin1_40, "\x28") + STR(latin1_41, "\x29") + STR(latin1_42, "\x2A") + STR(latin1_43, "\x2B") + STR(latin1_44, "\x2C") + STR(latin1_45, "\x2D") + STR(latin1_46, "\x2E") + STR(latin1_47, "\x2F") + STR(latin1_48, "\x30") + STR(latin1_49, "\x31") + STR(latin1_50, "\x32") + STR(latin1_51, "\x33") + STR(latin1_52, "\x34") + STR(latin1_53, "\x35") + STR(latin1_54, "\x36") + STR(latin1_55, "\x37") + STR(latin1_56, "\x38") + STR(latin1_57, "\x39") + STR(latin1_58, "\x3A") + STR(latin1_59, "\x3B") + STR(latin1_60, "\x3C") + STR(latin1_61, "\x3D") + STR(latin1_62, "\x3E") + STR(latin1_63, "\x3F") + STR(latin1_64, "\x40") + STR(latin1_65, "\x41") + STR(latin1_66, "\x42") + STR(latin1_67, "\x43") + STR(latin1_68, "\x44") + STR(latin1_69, "\x45") + STR(latin1_70, "\x46") + STR(latin1_71, "\x47") + STR(latin1_72, "\x48") + STR(latin1_73, "\x49") + STR(latin1_74, "\x4A") + STR(latin1_75, "\x4B") + STR(latin1_76, "\x4C") + STR(latin1_77, "\x4D") + STR(latin1_78, "\x4E") + STR(latin1_79, "\x4F") + STR(latin1_80, "\x50") + STR(latin1_81, "\x51") + STR(latin1_82, "\x52") + STR(latin1_83, "\x53") + STR(latin1_84, "\x54") + STR(latin1_85, "\x55") + STR(latin1_86, "\x56") + STR(latin1_87, "\x57") + STR(latin1_88, "\x58") + STR(latin1_89, "\x59") + STR(latin1_90, "\x5A") + STR(latin1_91, "\x5B") + STR(latin1_92, "\x5C") + STR(latin1_93, "\x5D") + STR(latin1_94, "\x5E") + STR(latin1_95, "\x5F") + STR(latin1_96, "\x60") + STR(latin1_97, "\x61") + STR(latin1_98, "\x62") + STR(latin1_99, "\x63") + STR(latin1_100, "\x64") + STR(latin1_101, "\x65") + STR(latin1_102, "\x66") + STR(latin1_103, "\x67") + STR(latin1_104, "\x68") + STR(latin1_105, "\x69") + STR(latin1_106, "\x6A") + STR(latin1_107, "\x6B") + STR(latin1_108, "\x6C") + STR(latin1_109, "\x6D") + STR(latin1_110, "\x6E") + STR(latin1_111, "\x6F") + STR(latin1_112, "\x70") + STR(latin1_113, "\x71") + STR(latin1_114, "\x72") + STR(latin1_115, "\x73") + STR(latin1_116, "\x74") + STR(latin1_117, "\x75") + STR(latin1_118, "\x76") + STR(latin1_119, "\x77") + STR(latin1_120, "\x78") + STR(latin1_121, "\x79") + STR(latin1_122, "\x7A") + STR(latin1_123, "\x7B") + STR(latin1_124, "\x7C") + STR(latin1_125, "\x7D") + STR(latin1_126, "\x7E") + STR(latin1_127, "\x7F") + STR(latin1_128, "\x80") + STR(latin1_129, "\x81") + STR(latin1_130, "\x82") + STR(latin1_131, "\x83") + STR(latin1_132, "\x84") + STR(latin1_133, "\x85") + STR(latin1_134, "\x86") + STR(latin1_135, "\x87") + STR(latin1_136, "\x88") + STR(latin1_137, "\x89") + STR(latin1_138, "\x8A") + STR(latin1_139, "\x8B") + STR(latin1_140, "\x8C") + STR(latin1_141, "\x8D") + STR(latin1_142, "\x8E") + STR(latin1_143, "\x8F") + STR(latin1_144, "\x90") + STR(latin1_145, "\x91") + STR(latin1_146, "\x92") + STR(latin1_147, "\x93") + STR(latin1_148, "\x94") + STR(latin1_149, "\x95") + STR(latin1_150, "\x96") + STR(latin1_151, "\x97") + STR(latin1_152, "\x98") + STR(latin1_153, "\x99") + STR(latin1_154, "\x9A") + STR(latin1_155, "\x9B") + STR(latin1_156, "\x9C") + STR(latin1_157, "\x9D") + STR(latin1_158, "\x9E") + STR(latin1_159, "\x9F") + STR(latin1_160, "\xA0") + STR(latin1_161, "\xA1") + STR(latin1_162, "\xA2") + STR(latin1_163, "\xA3") + STR(latin1_164, "\xA4") + STR(latin1_165, "\xA5") + STR(latin1_166, "\xA6") + STR(latin1_167, "\xA7") + STR(latin1_168, "\xA8") + STR(latin1_169, "\xA9") + STR(latin1_170, "\xAA") + STR(latin1_171, "\xAB") + STR(latin1_172, "\xAC") + STR(latin1_173, "\xAD") + STR(latin1_174, "\xAE") + STR(latin1_175, "\xAF") + STR(latin1_176, "\xB0") + STR(latin1_177, "\xB1") + STR(latin1_178, "\xB2") + STR(latin1_179, "\xB3") + STR(latin1_180, "\xB4") + STR(latin1_181, "\xB5") + STR(latin1_182, "\xB6") + STR(latin1_183, "\xB7") + STR(latin1_184, "\xB8") + STR(latin1_185, "\xB9") + STR(latin1_186, "\xBA") + STR(latin1_187, "\xBB") + STR(latin1_188, "\xBC") + STR(latin1_189, "\xBD") + STR(latin1_190, "\xBE") + STR(latin1_191, "\xBF") + STR(latin1_192, "\xC0") + STR(latin1_193, "\xC1") + STR(latin1_194, "\xC2") + STR(latin1_195, "\xC3") + STR(latin1_196, "\xC4") + STR(latin1_197, "\xC5") + STR(latin1_198, "\xC6") + STR(latin1_199, "\xC7") + STR(latin1_200, "\xC8") + STR(latin1_201, "\xC9") + STR(latin1_202, "\xCA") + STR(latin1_203, "\xCB") + STR(latin1_204, "\xCC") + STR(latin1_205, "\xCD") + STR(latin1_206, "\xCE") + STR(latin1_207, "\xCF") + STR(latin1_208, "\xD0") + STR(latin1_209, "\xD1") + STR(latin1_210, "\xD2") + STR(latin1_211, "\xD3") + STR(latin1_212, "\xD4") + STR(latin1_213, "\xD5") + STR(latin1_214, "\xD6") + STR(latin1_215, "\xD7") + STR(latin1_216, "\xD8") + STR(latin1_217, "\xD9") + STR(latin1_218, "\xDA") + STR(latin1_219, "\xDB") + STR(latin1_220, "\xDC") + STR(latin1_221, "\xDD") + STR(latin1_222, "\xDE") + STR(latin1_223, "\xDF") + STR(latin1_224, "\xE0") + STR(latin1_225, "\xE1") + STR(latin1_226, "\xE2") + STR(latin1_227, "\xE3") + STR(latin1_228, "\xE4") + STR(latin1_229, "\xE5") + STR(latin1_230, "\xE6") + STR(latin1_231, "\xE7") + STR(latin1_232, "\xE8") + STR(latin1_233, "\xE9") + STR(latin1_234, "\xEA") + STR(latin1_235, "\xEB") + STR(latin1_236, "\xEC") + STR(latin1_237, "\xED") + STR(latin1_238, "\xEE") + STR(latin1_239, "\xEF") + STR(latin1_240, "\xF0") + STR(latin1_241, "\xF1") + STR(latin1_242, "\xF2") + STR(latin1_243, "\xF3") + STR(latin1_244, "\xF4") + STR(latin1_245, "\xF5") + STR(latin1_246, "\xF6") + STR(latin1_247, "\xF7") + STR(latin1_248, "\xF8") + STR(latin1_249, "\xF9") + STR(latin1_250, "\xFA") + STR(latin1_251, "\xFB") + STR(latin1_252, "\xFC") + STR(latin1_253, "\xFD") + STR(latin1_254, "\xFE") + STR(latin1_255, "\xFF") } literals; struct { @@ -348,7 +348,7 @@ struct _Py_global_strings { ID(__dict__) ID(__dir__) ID(__divmod__) - ID(__doc__) // docstr + ID(__doc__) ID(__enter__) ID(__eq__) ID(__exit__) @@ -604,6 +604,7 @@ struct _Py_global_strings { ID(zipimporter) } identifiers; }; +/* End auto-generated code */ #undef ID #undef STR diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index e5217bc8b932637..91e47d9febf2177 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -650,17 +650,16 @@ extern "C" { INIT_STR(empty, ""), \ INIT_STR(newline, "\n"), \ INIT_STR(dot, "."), \ - \ INIT_STR(comma_sep, ", "), \ + INIT_STR(percent, "%"), \ + INIT_STR(dbl_percent, "%%"), \ + INIT_STR(replace_inf, "1eNN"), \ \ INIT_STR(br_open, "{"), \ INIT_STR(br_close, "}"), \ INIT_STR(br_dbl_open, "{{"), \ INIT_STR(br_dbl_close, "}}"), \ \ - INIT_STR(percent, "%"), \ - INIT_STR(dbl_percent, "%%"), \ - \ INIT_STR(anon_dictcomp, ""), \ INIT_STR(anon_genexpr, ""), \ INIT_STR(anon_lambda, ""), \ @@ -670,264 +669,262 @@ extern "C" { INIT_STR(anon_string, ""), \ INIT_STR(dot_locals, "."), \ \ - INIT_STR(replace_inf, "1eNN"), \ - \ - INIT_STR(latin1_0, "\x00"), \ - INIT_STR(latin1_1, "\x01"), \ - INIT_STR(latin1_2, "\x02"), \ - INIT_STR(latin1_3, "\x03"), \ - INIT_STR(latin1_4, "\x04"), \ - INIT_STR(latin1_5, "\x05"), \ - INIT_STR(latin1_6, "\x06"), \ - INIT_STR(latin1_7, "\x07"), \ - INIT_STR(latin1_8, "\x08"), \ - INIT_STR(latin1_9, "\x09"), \ - INIT_STR(latin1_10, "\x0A"), \ - INIT_STR(latin1_11, "\x0B"), \ - INIT_STR(latin1_12, "\x0C"), \ - INIT_STR(latin1_13, "\x0D"), \ - INIT_STR(latin1_14, "\x0E"), \ - INIT_STR(latin1_15, "\x0F"), \ - INIT_STR(latin1_16, "\x10"), \ - INIT_STR(latin1_17, "\x11"), \ - INIT_STR(latin1_18, "\x12"), \ - INIT_STR(latin1_19, "\x13"), \ - INIT_STR(latin1_20, "\x14"), \ - INIT_STR(latin1_21, "\x15"), \ - INIT_STR(latin1_22, "\x16"), \ - INIT_STR(latin1_23, "\x17"), \ - INIT_STR(latin1_24, "\x18"), \ - INIT_STR(latin1_25, "\x19"), \ - INIT_STR(latin1_26, "\x1A"), \ - INIT_STR(latin1_27, "\x1B"), \ - INIT_STR(latin1_28, "\x1C"), \ - INIT_STR(latin1_29, "\x1D"), \ - INIT_STR(latin1_30, "\x1E"), \ - INIT_STR(latin1_31, "\x1F"), \ - INIT_STR(latin1_32, "\x20"), \ - INIT_STR(latin1_33, "\x21"), \ - INIT_STR(latin1_34, "\x22"), \ - INIT_STR(latin1_35, "\x23"), \ - INIT_STR(latin1_36, "\x24"), \ - INIT_STR(latin1_37, "\x25"), \ - INIT_STR(latin1_38, "\x26"), \ - INIT_STR(latin1_39, "\x27"), \ - INIT_STR(latin1_40, "\x28"), \ - INIT_STR(latin1_41, "\x29"), \ - INIT_STR(latin1_42, "\x2A"), \ - INIT_STR(latin1_43, "\x2B"), \ - INIT_STR(latin1_44, "\x2C"), \ - INIT_STR(latin1_45, "\x2D"), \ - INIT_STR(latin1_46, "\x2E"), \ - INIT_STR(latin1_47, "\x2F"), \ - INIT_STR(latin1_48, "\x30"), \ - INIT_STR(latin1_49, "\x31"), \ - INIT_STR(latin1_50, "\x32"), \ - INIT_STR(latin1_51, "\x33"), \ - INIT_STR(latin1_52, "\x34"), \ - INIT_STR(latin1_53, "\x35"), \ - INIT_STR(latin1_54, "\x36"), \ - INIT_STR(latin1_55, "\x37"), \ - INIT_STR(latin1_56, "\x38"), \ - INIT_STR(latin1_57, "\x39"), \ - INIT_STR(latin1_58, "\x3A"), \ - INIT_STR(latin1_59, "\x3B"), \ - INIT_STR(latin1_60, "\x3C"), \ - INIT_STR(latin1_61, "\x3D"), \ - INIT_STR(latin1_62, "\x3E"), \ - INIT_STR(latin1_63, "\x3F"), \ - INIT_STR(latin1_64, "\x40"), \ - INIT_STR(latin1_65, "\x41"), \ - INIT_STR(latin1_66, "\x42"), \ - INIT_STR(latin1_67, "\x43"), \ - INIT_STR(latin1_68, "\x44"), \ - INIT_STR(latin1_69, "\x45"), \ - INIT_STR(latin1_70, "\x46"), \ - INIT_STR(latin1_71, "\x47"), \ - INIT_STR(latin1_72, "\x48"), \ - INIT_STR(latin1_73, "\x49"), \ - INIT_STR(latin1_74, "\x4A"), \ - INIT_STR(latin1_75, "\x4B"), \ - INIT_STR(latin1_76, "\x4C"), \ - INIT_STR(latin1_77, "\x4D"), \ - INIT_STR(latin1_78, "\x4E"), \ - INIT_STR(latin1_79, "\x4F"), \ - INIT_STR(latin1_80, "\x50"), \ - INIT_STR(latin1_81, "\x51"), \ - INIT_STR(latin1_82, "\x52"), \ - INIT_STR(latin1_83, "\x53"), \ - INIT_STR(latin1_84, "\x54"), \ - INIT_STR(latin1_85, "\x55"), \ - INIT_STR(latin1_86, "\x56"), \ - INIT_STR(latin1_87, "\x57"), \ - INIT_STR(latin1_88, "\x58"), \ - INIT_STR(latin1_89, "\x59"), \ - INIT_STR(latin1_90, "\x5A"), \ - INIT_STR(latin1_91, "\x5B"), \ - INIT_STR(latin1_92, "\x5C"), \ - INIT_STR(latin1_93, "\x5D"), \ - INIT_STR(latin1_94, "\x5E"), \ - INIT_STR(latin1_95, "\x5F"), \ - INIT_STR(latin1_96, "\x60"), \ - INIT_STR(latin1_97, "\x61"), \ - INIT_STR(latin1_98, "\x62"), \ - INIT_STR(latin1_99, "\x63"), \ - INIT_STR(latin1_100, "\x64"), \ - INIT_STR(latin1_101, "\x65"), \ - INIT_STR(latin1_102, "\x66"), \ - INIT_STR(latin1_103, "\x67"), \ - INIT_STR(latin1_104, "\x68"), \ - INIT_STR(latin1_105, "\x69"), \ - INIT_STR(latin1_106, "\x6A"), \ - INIT_STR(latin1_107, "\x6B"), \ - INIT_STR(latin1_108, "\x6C"), \ - INIT_STR(latin1_109, "\x6D"), \ - INIT_STR(latin1_110, "\x6E"), \ - INIT_STR(latin1_111, "\x6F"), \ - INIT_STR(latin1_112, "\x70"), \ - INIT_STR(latin1_113, "\x71"), \ - INIT_STR(latin1_114, "\x72"), \ - INIT_STR(latin1_115, "\x73"), \ - INIT_STR(latin1_116, "\x74"), \ - INIT_STR(latin1_117, "\x75"), \ - INIT_STR(latin1_118, "\x76"), \ - INIT_STR(latin1_119, "\x77"), \ - INIT_STR(latin1_120, "\x78"), \ - INIT_STR(latin1_121, "\x79"), \ - INIT_STR(latin1_122, "\x7A"), \ - INIT_STR(latin1_123, "\x7B"), \ - INIT_STR(latin1_124, "\x7C"), \ - INIT_STR(latin1_125, "\x7D"), \ - INIT_STR(latin1_126, "\x7E"), \ - INIT_STR(latin1_127, "\x7F"), \ - INIT_STR(latin1_128, "\x80"), \ - INIT_STR(latin1_129, "\x81"), \ - INIT_STR(latin1_130, "\x82"), \ - INIT_STR(latin1_131, "\x83"), \ - INIT_STR(latin1_132, "\x84"), \ - INIT_STR(latin1_133, "\x85"), \ - INIT_STR(latin1_134, "\x86"), \ - INIT_STR(latin1_135, "\x87"), \ - INIT_STR(latin1_136, "\x88"), \ - INIT_STR(latin1_137, "\x89"), \ - INIT_STR(latin1_138, "\x8A"), \ - INIT_STR(latin1_139, "\x8B"), \ - INIT_STR(latin1_140, "\x8C"), \ - INIT_STR(latin1_141, "\x8D"), \ - INIT_STR(latin1_142, "\x8E"), \ - INIT_STR(latin1_143, "\x8F"), \ - INIT_STR(latin1_144, "\x90"), \ - INIT_STR(latin1_145, "\x91"), \ - INIT_STR(latin1_146, "\x92"), \ - INIT_STR(latin1_147, "\x93"), \ - INIT_STR(latin1_148, "\x94"), \ - INIT_STR(latin1_149, "\x95"), \ - INIT_STR(latin1_150, "\x96"), \ - INIT_STR(latin1_151, "\x97"), \ - INIT_STR(latin1_152, "\x98"), \ - INIT_STR(latin1_153, "\x99"), \ - INIT_STR(latin1_154, "\x9A"), \ - INIT_STR(latin1_155, "\x9B"), \ - INIT_STR(latin1_156, "\x9C"), \ - INIT_STR(latin1_157, "\x9D"), \ - INIT_STR(latin1_158, "\x9E"), \ - INIT_STR(latin1_159, "\x9F"), \ - INIT_STR(latin1_160, "\xA0"), \ - INIT_STR(latin1_161, "\xA1"), \ - INIT_STR(latin1_162, "\xA2"), \ - INIT_STR(latin1_163, "\xA3"), \ - INIT_STR(latin1_164, "\xA4"), \ - INIT_STR(latin1_165, "\xA5"), \ - INIT_STR(latin1_166, "\xA6"), \ - INIT_STR(latin1_167, "\xA7"), \ - INIT_STR(latin1_168, "\xA8"), \ - INIT_STR(latin1_169, "\xA9"), \ - INIT_STR(latin1_170, "\xAA"), \ - INIT_STR(latin1_171, "\xAB"), \ - INIT_STR(latin1_172, "\xAC"), \ - INIT_STR(latin1_173, "\xAD"), \ - INIT_STR(latin1_174, "\xAE"), \ - INIT_STR(latin1_175, "\xAF"), \ - INIT_STR(latin1_176, "\xB0"), \ - INIT_STR(latin1_177, "\xB1"), \ - INIT_STR(latin1_178, "\xB2"), \ - INIT_STR(latin1_179, "\xB3"), \ - INIT_STR(latin1_180, "\xB4"), \ - INIT_STR(latin1_181, "\xB5"), \ - INIT_STR(latin1_182, "\xB6"), \ - INIT_STR(latin1_183, "\xB7"), \ - INIT_STR(latin1_184, "\xB8"), \ - INIT_STR(latin1_185, "\xB9"), \ - INIT_STR(latin1_186, "\xBA"), \ - INIT_STR(latin1_187, "\xBB"), \ - INIT_STR(latin1_188, "\xBC"), \ - INIT_STR(latin1_189, "\xBD"), \ - INIT_STR(latin1_190, "\xBE"), \ - INIT_STR(latin1_191, "\xBF"), \ - INIT_STR(latin1_192, "\xC0"), \ - INIT_STR(latin1_193, "\xC1"), \ - INIT_STR(latin1_194, "\xC2"), \ - INIT_STR(latin1_195, "\xC3"), \ - INIT_STR(latin1_196, "\xC4"), \ - INIT_STR(latin1_197, "\xC5"), \ - INIT_STR(latin1_198, "\xC6"), \ - INIT_STR(latin1_199, "\xC7"), \ - INIT_STR(latin1_200, "\xC8"), \ - INIT_STR(latin1_201, "\xC9"), \ - INIT_STR(latin1_202, "\xCA"), \ - INIT_STR(latin1_203, "\xCB"), \ - INIT_STR(latin1_204, "\xCC"), \ - INIT_STR(latin1_205, "\xCD"), \ - INIT_STR(latin1_206, "\xCE"), \ - INIT_STR(latin1_207, "\xCF"), \ - INIT_STR(latin1_208, "\xD0"), \ - INIT_STR(latin1_209, "\xD1"), \ - INIT_STR(latin1_210, "\xD2"), \ - INIT_STR(latin1_211, "\xD3"), \ - INIT_STR(latin1_212, "\xD4"), \ - INIT_STR(latin1_213, "\xD5"), \ - INIT_STR(latin1_214, "\xD6"), \ - INIT_STR(latin1_215, "\xD7"), \ - INIT_STR(latin1_216, "\xD8"), \ - INIT_STR(latin1_217, "\xD9"), \ - INIT_STR(latin1_218, "\xDA"), \ - INIT_STR(latin1_219, "\xDB"), \ - INIT_STR(latin1_220, "\xDC"), \ - INIT_STR(latin1_221, "\xDD"), \ - INIT_STR(latin1_222, "\xDE"), \ - INIT_STR(latin1_223, "\xDF"), \ - INIT_STR(latin1_224, "\xE0"), \ - INIT_STR(latin1_225, "\xE1"), \ - INIT_STR(latin1_226, "\xE2"), \ - INIT_STR(latin1_227, "\xE3"), \ - INIT_STR(latin1_228, "\xE4"), \ - INIT_STR(latin1_229, "\xE5"), \ - INIT_STR(latin1_230, "\xE6"), \ - INIT_STR(latin1_231, "\xE7"), \ - INIT_STR(latin1_232, "\xE8"), \ - INIT_STR(latin1_233, "\xE9"), \ - INIT_STR(latin1_234, "\xEA"), \ - INIT_STR(latin1_235, "\xEB"), \ - INIT_STR(latin1_236, "\xEC"), \ - INIT_STR(latin1_237, "\xED"), \ - INIT_STR(latin1_238, "\xEE"), \ - INIT_STR(latin1_239, "\xEF"), \ - INIT_STR(latin1_240, "\xF0"), \ - INIT_STR(latin1_241, "\xF1"), \ - INIT_STR(latin1_242, "\xF2"), \ - INIT_STR(latin1_243, "\xF3"), \ - INIT_STR(latin1_244, "\xF4"), \ - INIT_STR(latin1_245, "\xF5"), \ - INIT_STR(latin1_246, "\xF6"), \ - INIT_STR(latin1_247, "\xF7"), \ - INIT_STR(latin1_248, "\xF8"), \ - INIT_STR(latin1_249, "\xF9"), \ - INIT_STR(latin1_250, "\xFA"), \ - INIT_STR(latin1_251, "\xFB"), \ - INIT_STR(latin1_252, "\xFC"), \ - INIT_STR(latin1_253, "\xFD"), \ - INIT_STR(latin1_254, "\xFE"), \ - INIT_STR(latin1_255, "\xFF"), \ + INIT_STR(latin1_0, "\x00"), \ + INIT_STR(latin1_1, "\x01"), \ + INIT_STR(latin1_2, "\x02"), \ + INIT_STR(latin1_3, "\x03"), \ + INIT_STR(latin1_4, "\x04"), \ + INIT_STR(latin1_5, "\x05"), \ + INIT_STR(latin1_6, "\x06"), \ + INIT_STR(latin1_7, "\x07"), \ + INIT_STR(latin1_8, "\x08"), \ + INIT_STR(latin1_9, "\x09"), \ + INIT_STR(latin1_10, "\x0A"), \ + INIT_STR(latin1_11, "\x0B"), \ + INIT_STR(latin1_12, "\x0C"), \ + INIT_STR(latin1_13, "\x0D"), \ + INIT_STR(latin1_14, "\x0E"), \ + INIT_STR(latin1_15, "\x0F"), \ + INIT_STR(latin1_16, "\x10"), \ + INIT_STR(latin1_17, "\x11"), \ + INIT_STR(latin1_18, "\x12"), \ + INIT_STR(latin1_19, "\x13"), \ + INIT_STR(latin1_20, "\x14"), \ + INIT_STR(latin1_21, "\x15"), \ + INIT_STR(latin1_22, "\x16"), \ + INIT_STR(latin1_23, "\x17"), \ + INIT_STR(latin1_24, "\x18"), \ + INIT_STR(latin1_25, "\x19"), \ + INIT_STR(latin1_26, "\x1A"), \ + INIT_STR(latin1_27, "\x1B"), \ + INIT_STR(latin1_28, "\x1C"), \ + INIT_STR(latin1_29, "\x1D"), \ + INIT_STR(latin1_30, "\x1E"), \ + INIT_STR(latin1_31, "\x1F"), \ + INIT_STR(latin1_32, "\x20"), \ + INIT_STR(latin1_33, "\x21"), \ + INIT_STR(latin1_34, "\x22"), \ + INIT_STR(latin1_35, "\x23"), \ + INIT_STR(latin1_36, "\x24"), \ + INIT_STR(latin1_37, "\x25"), \ + INIT_STR(latin1_38, "\x26"), \ + INIT_STR(latin1_39, "\x27"), \ + INIT_STR(latin1_40, "\x28"), \ + INIT_STR(latin1_41, "\x29"), \ + INIT_STR(latin1_42, "\x2A"), \ + INIT_STR(latin1_43, "\x2B"), \ + INIT_STR(latin1_44, "\x2C"), \ + INIT_STR(latin1_45, "\x2D"), \ + INIT_STR(latin1_46, "\x2E"), \ + INIT_STR(latin1_47, "\x2F"), \ + INIT_STR(latin1_48, "\x30"), \ + INIT_STR(latin1_49, "\x31"), \ + INIT_STR(latin1_50, "\x32"), \ + INIT_STR(latin1_51, "\x33"), \ + INIT_STR(latin1_52, "\x34"), \ + INIT_STR(latin1_53, "\x35"), \ + INIT_STR(latin1_54, "\x36"), \ + INIT_STR(latin1_55, "\x37"), \ + INIT_STR(latin1_56, "\x38"), \ + INIT_STR(latin1_57, "\x39"), \ + INIT_STR(latin1_58, "\x3A"), \ + INIT_STR(latin1_59, "\x3B"), \ + INIT_STR(latin1_60, "\x3C"), \ + INIT_STR(latin1_61, "\x3D"), \ + INIT_STR(latin1_62, "\x3E"), \ + INIT_STR(latin1_63, "\x3F"), \ + INIT_STR(latin1_64, "\x40"), \ + INIT_STR(latin1_65, "\x41"), \ + INIT_STR(latin1_66, "\x42"), \ + INIT_STR(latin1_67, "\x43"), \ + INIT_STR(latin1_68, "\x44"), \ + INIT_STR(latin1_69, "\x45"), \ + INIT_STR(latin1_70, "\x46"), \ + INIT_STR(latin1_71, "\x47"), \ + INIT_STR(latin1_72, "\x48"), \ + INIT_STR(latin1_73, "\x49"), \ + INIT_STR(latin1_74, "\x4A"), \ + INIT_STR(latin1_75, "\x4B"), \ + INIT_STR(latin1_76, "\x4C"), \ + INIT_STR(latin1_77, "\x4D"), \ + INIT_STR(latin1_78, "\x4E"), \ + INIT_STR(latin1_79, "\x4F"), \ + INIT_STR(latin1_80, "\x50"), \ + INIT_STR(latin1_81, "\x51"), \ + INIT_STR(latin1_82, "\x52"), \ + INIT_STR(latin1_83, "\x53"), \ + INIT_STR(latin1_84, "\x54"), \ + INIT_STR(latin1_85, "\x55"), \ + INIT_STR(latin1_86, "\x56"), \ + INIT_STR(latin1_87, "\x57"), \ + INIT_STR(latin1_88, "\x58"), \ + INIT_STR(latin1_89, "\x59"), \ + INIT_STR(latin1_90, "\x5A"), \ + INIT_STR(latin1_91, "\x5B"), \ + INIT_STR(latin1_92, "\x5C"), \ + INIT_STR(latin1_93, "\x5D"), \ + INIT_STR(latin1_94, "\x5E"), \ + INIT_STR(latin1_95, "\x5F"), \ + INIT_STR(latin1_96, "\x60"), \ + INIT_STR(latin1_97, "\x61"), \ + INIT_STR(latin1_98, "\x62"), \ + INIT_STR(latin1_99, "\x63"), \ + INIT_STR(latin1_100, "\x64"), \ + INIT_STR(latin1_101, "\x65"), \ + INIT_STR(latin1_102, "\x66"), \ + INIT_STR(latin1_103, "\x67"), \ + INIT_STR(latin1_104, "\x68"), \ + INIT_STR(latin1_105, "\x69"), \ + INIT_STR(latin1_106, "\x6A"), \ + INIT_STR(latin1_107, "\x6B"), \ + INIT_STR(latin1_108, "\x6C"), \ + INIT_STR(latin1_109, "\x6D"), \ + INIT_STR(latin1_110, "\x6E"), \ + INIT_STR(latin1_111, "\x6F"), \ + INIT_STR(latin1_112, "\x70"), \ + INIT_STR(latin1_113, "\x71"), \ + INIT_STR(latin1_114, "\x72"), \ + INIT_STR(latin1_115, "\x73"), \ + INIT_STR(latin1_116, "\x74"), \ + INIT_STR(latin1_117, "\x75"), \ + INIT_STR(latin1_118, "\x76"), \ + INIT_STR(latin1_119, "\x77"), \ + INIT_STR(latin1_120, "\x78"), \ + INIT_STR(latin1_121, "\x79"), \ + INIT_STR(latin1_122, "\x7A"), \ + INIT_STR(latin1_123, "\x7B"), \ + INIT_STR(latin1_124, "\x7C"), \ + INIT_STR(latin1_125, "\x7D"), \ + INIT_STR(latin1_126, "\x7E"), \ + INIT_STR(latin1_127, "\x7F"), \ + INIT_STR(latin1_128, "\x80"), \ + INIT_STR(latin1_129, "\x81"), \ + INIT_STR(latin1_130, "\x82"), \ + INIT_STR(latin1_131, "\x83"), \ + INIT_STR(latin1_132, "\x84"), \ + INIT_STR(latin1_133, "\x85"), \ + INIT_STR(latin1_134, "\x86"), \ + INIT_STR(latin1_135, "\x87"), \ + INIT_STR(latin1_136, "\x88"), \ + INIT_STR(latin1_137, "\x89"), \ + INIT_STR(latin1_138, "\x8A"), \ + INIT_STR(latin1_139, "\x8B"), \ + INIT_STR(latin1_140, "\x8C"), \ + INIT_STR(latin1_141, "\x8D"), \ + INIT_STR(latin1_142, "\x8E"), \ + INIT_STR(latin1_143, "\x8F"), \ + INIT_STR(latin1_144, "\x90"), \ + INIT_STR(latin1_145, "\x91"), \ + INIT_STR(latin1_146, "\x92"), \ + INIT_STR(latin1_147, "\x93"), \ + INIT_STR(latin1_148, "\x94"), \ + INIT_STR(latin1_149, "\x95"), \ + INIT_STR(latin1_150, "\x96"), \ + INIT_STR(latin1_151, "\x97"), \ + INIT_STR(latin1_152, "\x98"), \ + INIT_STR(latin1_153, "\x99"), \ + INIT_STR(latin1_154, "\x9A"), \ + INIT_STR(latin1_155, "\x9B"), \ + INIT_STR(latin1_156, "\x9C"), \ + INIT_STR(latin1_157, "\x9D"), \ + INIT_STR(latin1_158, "\x9E"), \ + INIT_STR(latin1_159, "\x9F"), \ + INIT_STR(latin1_160, "\xA0"), \ + INIT_STR(latin1_161, "\xA1"), \ + INIT_STR(latin1_162, "\xA2"), \ + INIT_STR(latin1_163, "\xA3"), \ + INIT_STR(latin1_164, "\xA4"), \ + INIT_STR(latin1_165, "\xA5"), \ + INIT_STR(latin1_166, "\xA6"), \ + INIT_STR(latin1_167, "\xA7"), \ + INIT_STR(latin1_168, "\xA8"), \ + INIT_STR(latin1_169, "\xA9"), \ + INIT_STR(latin1_170, "\xAA"), \ + INIT_STR(latin1_171, "\xAB"), \ + INIT_STR(latin1_172, "\xAC"), \ + INIT_STR(latin1_173, "\xAD"), \ + INIT_STR(latin1_174, "\xAE"), \ + INIT_STR(latin1_175, "\xAF"), \ + INIT_STR(latin1_176, "\xB0"), \ + INIT_STR(latin1_177, "\xB1"), \ + INIT_STR(latin1_178, "\xB2"), \ + INIT_STR(latin1_179, "\xB3"), \ + INIT_STR(latin1_180, "\xB4"), \ + INIT_STR(latin1_181, "\xB5"), \ + INIT_STR(latin1_182, "\xB6"), \ + INIT_STR(latin1_183, "\xB7"), \ + INIT_STR(latin1_184, "\xB8"), \ + INIT_STR(latin1_185, "\xB9"), \ + INIT_STR(latin1_186, "\xBA"), \ + INIT_STR(latin1_187, "\xBB"), \ + INIT_STR(latin1_188, "\xBC"), \ + INIT_STR(latin1_189, "\xBD"), \ + INIT_STR(latin1_190, "\xBE"), \ + INIT_STR(latin1_191, "\xBF"), \ + INIT_STR(latin1_192, "\xC0"), \ + INIT_STR(latin1_193, "\xC1"), \ + INIT_STR(latin1_194, "\xC2"), \ + INIT_STR(latin1_195, "\xC3"), \ + INIT_STR(latin1_196, "\xC4"), \ + INIT_STR(latin1_197, "\xC5"), \ + INIT_STR(latin1_198, "\xC6"), \ + INIT_STR(latin1_199, "\xC7"), \ + INIT_STR(latin1_200, "\xC8"), \ + INIT_STR(latin1_201, "\xC9"), \ + INIT_STR(latin1_202, "\xCA"), \ + INIT_STR(latin1_203, "\xCB"), \ + INIT_STR(latin1_204, "\xCC"), \ + INIT_STR(latin1_205, "\xCD"), \ + INIT_STR(latin1_206, "\xCE"), \ + INIT_STR(latin1_207, "\xCF"), \ + INIT_STR(latin1_208, "\xD0"), \ + INIT_STR(latin1_209, "\xD1"), \ + INIT_STR(latin1_210, "\xD2"), \ + INIT_STR(latin1_211, "\xD3"), \ + INIT_STR(latin1_212, "\xD4"), \ + INIT_STR(latin1_213, "\xD5"), \ + INIT_STR(latin1_214, "\xD6"), \ + INIT_STR(latin1_215, "\xD7"), \ + INIT_STR(latin1_216, "\xD8"), \ + INIT_STR(latin1_217, "\xD9"), \ + INIT_STR(latin1_218, "\xDA"), \ + INIT_STR(latin1_219, "\xDB"), \ + INIT_STR(latin1_220, "\xDC"), \ + INIT_STR(latin1_221, "\xDD"), \ + INIT_STR(latin1_222, "\xDE"), \ + INIT_STR(latin1_223, "\xDF"), \ + INIT_STR(latin1_224, "\xE0"), \ + INIT_STR(latin1_225, "\xE1"), \ + INIT_STR(latin1_226, "\xE2"), \ + INIT_STR(latin1_227, "\xE3"), \ + INIT_STR(latin1_228, "\xE4"), \ + INIT_STR(latin1_229, "\xE5"), \ + INIT_STR(latin1_230, "\xE6"), \ + INIT_STR(latin1_231, "\xE7"), \ + INIT_STR(latin1_232, "\xE8"), \ + INIT_STR(latin1_233, "\xE9"), \ + INIT_STR(latin1_234, "\xEA"), \ + INIT_STR(latin1_235, "\xEB"), \ + INIT_STR(latin1_236, "\xEC"), \ + INIT_STR(latin1_237, "\xED"), \ + INIT_STR(latin1_238, "\xEE"), \ + INIT_STR(latin1_239, "\xEF"), \ + INIT_STR(latin1_240, "\xF0"), \ + INIT_STR(latin1_241, "\xF1"), \ + INIT_STR(latin1_242, "\xF2"), \ + INIT_STR(latin1_243, "\xF3"), \ + INIT_STR(latin1_244, "\xF4"), \ + INIT_STR(latin1_245, "\xF5"), \ + INIT_STR(latin1_246, "\xF6"), \ + INIT_STR(latin1_247, "\xF7"), \ + INIT_STR(latin1_248, "\xF8"), \ + INIT_STR(latin1_249, "\xF9"), \ + INIT_STR(latin1_250, "\xFA"), \ + INIT_STR(latin1_251, "\xFB"), \ + INIT_STR(latin1_252, "\xFC"), \ + INIT_STR(latin1_253, "\xFD"), \ + INIT_STR(latin1_254, "\xFE"), \ + INIT_STR(latin1_255, "\xFF"), \ }, \ .identifiers = { \ INIT_ID(Py_Repr), \ @@ -1116,8 +1113,8 @@ extern "C" { INIT_ID(decode), \ INIT_ID(default), \ INIT_ID(defaultaction), \ - INIT_ID(dispatch_table), \ INIT_ID(difference_update), \ + INIT_ID(dispatch_table), \ INIT_ID(displayhook), \ INIT_ID(enable), \ INIT_ID(encode), \ diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index a06d201fd61442b..1979af7920e7267 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -12,6 +12,328 @@ INTERNAL = os.path.join(ROOT, 'Include', 'internal') +STRING_LITERALS = { + 'empty': '', + 'newline': r'\n', + 'dot': '.', + 'comma_sep': ', ', + 'percent': '%', + 'dbl_percent': '%%', + 'replace_inf': '1eNN', + #'replace_inf': ['1', 'e', 1 + DBL_MAX_10_EXP] + + 'braces': None, + 'br_open': '{', + 'br_close': '}', + 'br_dbl_open': '{{', + 'br_dbl_close': '}}', + + '"anonymous" labels': None, + 'anon_dictcomp': '', + 'anon_genexpr': '', + 'anon_lambda': '', + 'anon_listcomp': '', + 'anon_module': '', + 'anon_setcomp': '', + 'anon_string': '', + 'dot_locals': '.', +} +IDENTIFIERS = [ + 'Py_Repr', + 'TextIOWrapper', + 'WarningMessage', + '_', + '__IOBase_closed', + '__abc_tpflags__', + '__abs__', + '__abstractmethods__', + '__add__', + '__aenter__', + '__aexit__', + '__aiter__', + '__all__', + '__and__', + '__anext__', + '__annotations__', + '__args__', + '__await__', + '__bases__', + '__bool__', + '__build_class__', + '__builtins__', + '__bytes__', + '__call__', + '__cantrace__', + '__class__', + '__class_getitem__', + '__classcell__', + '__complex__', + '__contains__', + '__copy__', + '__del__', + '__delattr__', + '__delete__', + '__delitem__', + '__dict__', + '__dir__', + '__divmod__', + '__doc__', + '__enter__', + '__eq__', + '__exit__', + '__file__', + '__float__', + '__floordiv__', + '__format__', + '__fspath__', + '__ge__', + '__get__', + '__getattr__', + '__getattribute__', + '__getinitargs__', + '__getitem__', + '__getnewargs__', + '__getnewargs_ex__', + '__getstate__', + '__gt__', + '__hash__', + '__iadd__', + '__iand__', + '__ifloordiv__', + '__ilshift__', + '__imatmul__', + '__imod__', + '__import__', + '__imul__', + '__index__', + '__init__', + '__init_subclass__', + '__instancecheck__', + '__int__', + '__invert__', + '__ior__', + '__ipow__', + '__irshift__', + '__isabstractmethod__', + '__isub__', + '__iter__', + '__itruediv__', + '__ixor__', + '__le__', + '__len__', + '__length_hint__', + '__loader__', + '__lshift__', + '__lt__', + '__ltrace__', + '__main__', + '__matmul__', + '__missing__', + '__mod__', + '__module__', + '__mro_entries__', + '__mul__', + '__name__', + '__ne__', + '__neg__', + '__new__', + '__newobj__', + '__newobj_ex__', + '__next__', + '__note__', + '__or__', + '__origin__', + '__package__', + '__parameters__', + '__path__', + '__pos__', + '__pow__', + '__prepare__', + '__qualname__', + '__radd__', + '__rand__', + '__rdivmod__', + '__reduce__', + '__reduce_ex__', + '__repr__', + '__reversed__', + '__rfloordiv__', + '__rlshift__', + '__rmatmul__', + '__rmod__', + '__rmul__', + '__ror__', + '__round__', + '__rpow__', + '__rrshift__', + '__rshift__', + '__rsub__', + '__rtruediv__', + '__rxor__', + '__set__', + '__set_name__', + '__setattr__', + '__setitem__', + '__setstate__', + '__sizeof__', + '__slotnames__', + '__slots__', + '__spec__', + '__str__', + '__sub__', + '__subclasscheck__', + '__subclasshook__', + '__truediv__', + '__trunc__', + '__warningregistry__', + '__weakref__', + '__xor__', + '_abc_impl', + '_blksize', + '_bootstrap', + '_dealloc_warn', + '_finalizing', + '_find_and_load', + '_fix_up_module', + '_get_sourcefile', + '_handle_fromlist', + '_initializing', + '_is_text_encoding', + '_lock_unlock_module', + '_showwarnmsg', + '_shutdown', + '_slotnames', + '_strptime_time', + '_uninitialized_submodules', + '_warn_unawaited_coroutine', + '_xoptions', + 'add', + 'append', + 'big', + 'buffer', + 'builtins', + 'c_call', + 'c_exception', + 'c_return', + 'call', + 'clear', + 'close', + 'closed', + 'code', + 'copy', + 'copyreg', + 'decode', + 'default', + 'defaultaction', + 'difference_update', + 'dispatch_table', + 'displayhook', + 'enable', + 'encode', + 'encoding', + 'end_lineno', + 'end_offset', + 'errors', + 'excepthook', + 'exception', + 'extend', + 'filename', + 'fileno', + 'fillvalue', + 'filters', + 'find_class', + 'flush', + 'get', + 'get_source', + 'getattr', + 'getpreferredencoding', + 'getstate', + 'ignore', + 'imp', + 'importlib', + 'inf', + 'intersection', + 'intersection_update', + 'isatty', + 'items', + 'iter', + 'keys', + 'last_traceback', + 'last_type', + 'last_value', + 'latin1', + 'line', + 'lineno', + 'little', + 'locale', + 'match', + 'metaclass', + 'mode', + 'modules', + 'mro', + 'msg', + 'n_fields', + 'n_sequence_fields', + 'n_unnamed_fields', + 'name', + 'newlines', + 'obj', + 'offset', + 'onceregistry', + 'opcode', + 'open', + 'parent', + 'partial', + 'path', + 'peek', + 'persistent_id', + 'persistent_load', + 'print_file_and_line', + 'ps1', + 'ps2', + 'raw', + 'read', + 'read1', + 'readable', + 'readall', + 'readinto', + 'readinto1', + 'readline', + 'reducer_override', + 'reload', + 'replace', + 'reset', + 'return', + 'reversed', + 'seek', + 'seekable', + 'send', + 'setstate', + 'sort', + 'st_mode', + 'stderr', + 'stdin', + 'stdout', + 'strict', + 'struct_rusage', + 'symmetric_difference_update', + 'tell', + 'text', + 'threading', + 'throw', + 'truncate', + 'unraisablehook', + 'update', + 'values', + 'version', + 'warnings', + 'warnoptions', + 'writable', + 'write', + 'zipimporter', +] + + ####################################### # helpers @@ -64,6 +386,42 @@ def block(self, prefix, suffix="", *, continuation=None): END = '/* End auto-generated code */' +def generate_global_strings(): + filename = os.path.join(INTERNAL, 'pycore_global_strings.h') + + # Read the non-generated part of the file. + with open(filename) as infile: + before = ''.join(iter_to_marker(infile, START))[:-1] + for _ in iter_to_marker(infile, END): + pass + after = infile.read()[:-1] + + # Generate the file. + with open(filename, 'w', encoding='utf-8') as outfile: + printer = Printer(outfile) + printer.write(before) + printer.write(START) + with printer.block('struct _Py_global_strings', ';'): + with printer.block('struct', ' literals;'): + for name, literal in STRING_LITERALS.items(): + if literal is None: + outfile.write('\n') + printer.write(f'// {name}') + else: + printer.write(f'STR({name}, "{literal}")') + outfile.write('\n') + printer.write('// The single character latin-1 (ASCII) strings.') + for i in range(256): + printer.write(f'STR(latin1_{i}, "\\x{i:02X}")') + outfile.write('\n') + with printer.block('struct', ' identifiers;'): + for name in sorted(IDENTIFIERS): + assert name.isidentifier(), name + printer.write(f'ID({name})') + printer.write(END) + printer.write(after) + + def generate_runtime_init(): # First get some info from the declarations. nsmallposints = None @@ -106,6 +464,22 @@ def generate_runtime_init(): with printer.block('.bytes_characters =', ','): for i in range(256): printer.write(f'_PyBytes_CHAR_INIT({i}),') + printer.write('') + # Global strings. + with printer.block('.strings =', ','): + with printer.block('.literals =', ','): + for name, literal in STRING_LITERALS.items(): + if literal is None: + printer.write('') + else: + printer.write(f'INIT_STR({name}, "{literal}"),') + printer.write('') + for i in range(256): + printer.write(f'INIT_STR(latin1_{i}, "\\x{i:02X}"),') + with printer.block('.identifiers =', ','): + for name in sorted(IDENTIFIERS): + assert name.isidentifier(), name + printer.write(f'INIT_ID({name}),') printer.write(END) printer.write(after) @@ -114,6 +488,7 @@ def generate_runtime_init(): # the script def main() -> None: + generate_global_strings() generate_runtime_init() From b14d0a8d1fb4532467bd2e3e8ae07809f0b5be50 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 11:36:13 -0700 Subject: [PATCH 080/115] Drop _Py_unicode_state.empty_string. --- Include/internal/pycore_unicodeobject.h | 2 -- Objects/unicodeobject.c | 34 +++---------------------- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index fabe522f6fc23bc..977bbeb19171200 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -44,8 +44,6 @@ struct _Py_unicode_ids { }; struct _Py_unicode_state { - // The empty Unicode object is a singleton to improve performance. - PyObject *empty_string; /* Single character Unicode strings in the Latin-1 range are being shared as well. */ PyObject *latin1[256]; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 9042d6ecf431183..3d008927226c1b0 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -260,11 +260,7 @@ get_unicode_state(void) // Return a borrowed reference to the empty string singleton. static inline PyObject* unicode_get_empty(void) { - struct _Py_unicode_state *state = get_unicode_state(); - // unicode_get_empty() must not be called before _PyUnicode_Init() - // or after _PyUnicode_Fini() - assert(state->empty_string != NULL); - return state->empty_string; + return _Py_GET_GLOBAL_STRING(empty); } @@ -1388,25 +1384,6 @@ _PyUnicode_Dump(PyObject *op) } #endif -static int -unicode_create_empty_string_singleton(struct _Py_unicode_state *state) -{ - // Use size=1 rather than size=0, so PyUnicode_New(0, maxchar) can be - // optimized to always use state->empty_string without having to check if - // it is NULL or not. - PyObject *empty = PyUnicode_New(1, 0); - if (empty == NULL) { - return -1; - } - PyUnicode_1BYTE_DATA(empty)[0] = 0; - _PyUnicode_LENGTH(empty) = 0; - assert(_PyUnicode_CheckConsistency(empty, 1)); - - assert(state->empty_string == NULL); - state->empty_string = empty; - return 0; -} - PyObject * PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar) @@ -2010,7 +1987,7 @@ static int unicode_is_singleton(PyObject *unicode) { struct _Py_unicode_state *state = get_unicode_state(); - if (unicode == state->empty_string) { + if (unicode == _Py_GET_GLOBAL_STRING(empty)) { return 1; } PyASCIIObject *ascii = (PyASCIIObject *)unicode; @@ -15551,10 +15528,8 @@ _PyUnicode_InitState(PyInterpreterState *interp) PyStatus _PyUnicode_InitGlobalObjects(PyInterpreterState *interp) { - struct _Py_unicode_state *state = &interp->unicode; - if (unicode_create_empty_string_singleton(state) < 0) { - return _PyStatus_NO_MEMORY(); - } + PyObject *empty = _Py_GET_GLOBAL_STRING(empty); + assert(_PyUnicode_CheckConsistency(empty, 1)); return _PyStatus_OK(); } @@ -16137,7 +16112,6 @@ _PyUnicode_Fini(PyInterpreterState *interp) for (Py_ssize_t i = 0; i < 256; i++) { Py_CLEAR(state->latin1[i]); } - Py_CLEAR(state->empty_string); } From 61abdabcd579c7693b8020289d7316b64d303ea3 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 11:42:00 -0700 Subject: [PATCH 081/115] Do not include the latin-1 characters (for now). --- Include/internal/pycore_global_strings.h | 258 ----------------------- Include/internal/pycore_runtime_init.h | 257 ---------------------- Tools/scripts/generate_global_objects.py | 7 - 3 files changed, 522 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 014cff83bf0e05f..7f19718a1c1d1cf 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -49,264 +49,6 @@ struct _Py_global_strings { STR(anon_setcomp, "") STR(anon_string, "") STR(dot_locals, ".") - - // The single character latin-1 (ASCII) strings. - STR(latin1_0, "\x00") - STR(latin1_1, "\x01") - STR(latin1_2, "\x02") - STR(latin1_3, "\x03") - STR(latin1_4, "\x04") - STR(latin1_5, "\x05") - STR(latin1_6, "\x06") - STR(latin1_7, "\x07") - STR(latin1_8, "\x08") - STR(latin1_9, "\x09") - STR(latin1_10, "\x0A") - STR(latin1_11, "\x0B") - STR(latin1_12, "\x0C") - STR(latin1_13, "\x0D") - STR(latin1_14, "\x0E") - STR(latin1_15, "\x0F") - STR(latin1_16, "\x10") - STR(latin1_17, "\x11") - STR(latin1_18, "\x12") - STR(latin1_19, "\x13") - STR(latin1_20, "\x14") - STR(latin1_21, "\x15") - STR(latin1_22, "\x16") - STR(latin1_23, "\x17") - STR(latin1_24, "\x18") - STR(latin1_25, "\x19") - STR(latin1_26, "\x1A") - STR(latin1_27, "\x1B") - STR(latin1_28, "\x1C") - STR(latin1_29, "\x1D") - STR(latin1_30, "\x1E") - STR(latin1_31, "\x1F") - STR(latin1_32, "\x20") - STR(latin1_33, "\x21") - STR(latin1_34, "\x22") - STR(latin1_35, "\x23") - STR(latin1_36, "\x24") - STR(latin1_37, "\x25") - STR(latin1_38, "\x26") - STR(latin1_39, "\x27") - STR(latin1_40, "\x28") - STR(latin1_41, "\x29") - STR(latin1_42, "\x2A") - STR(latin1_43, "\x2B") - STR(latin1_44, "\x2C") - STR(latin1_45, "\x2D") - STR(latin1_46, "\x2E") - STR(latin1_47, "\x2F") - STR(latin1_48, "\x30") - STR(latin1_49, "\x31") - STR(latin1_50, "\x32") - STR(latin1_51, "\x33") - STR(latin1_52, "\x34") - STR(latin1_53, "\x35") - STR(latin1_54, "\x36") - STR(latin1_55, "\x37") - STR(latin1_56, "\x38") - STR(latin1_57, "\x39") - STR(latin1_58, "\x3A") - STR(latin1_59, "\x3B") - STR(latin1_60, "\x3C") - STR(latin1_61, "\x3D") - STR(latin1_62, "\x3E") - STR(latin1_63, "\x3F") - STR(latin1_64, "\x40") - STR(latin1_65, "\x41") - STR(latin1_66, "\x42") - STR(latin1_67, "\x43") - STR(latin1_68, "\x44") - STR(latin1_69, "\x45") - STR(latin1_70, "\x46") - STR(latin1_71, "\x47") - STR(latin1_72, "\x48") - STR(latin1_73, "\x49") - STR(latin1_74, "\x4A") - STR(latin1_75, "\x4B") - STR(latin1_76, "\x4C") - STR(latin1_77, "\x4D") - STR(latin1_78, "\x4E") - STR(latin1_79, "\x4F") - STR(latin1_80, "\x50") - STR(latin1_81, "\x51") - STR(latin1_82, "\x52") - STR(latin1_83, "\x53") - STR(latin1_84, "\x54") - STR(latin1_85, "\x55") - STR(latin1_86, "\x56") - STR(latin1_87, "\x57") - STR(latin1_88, "\x58") - STR(latin1_89, "\x59") - STR(latin1_90, "\x5A") - STR(latin1_91, "\x5B") - STR(latin1_92, "\x5C") - STR(latin1_93, "\x5D") - STR(latin1_94, "\x5E") - STR(latin1_95, "\x5F") - STR(latin1_96, "\x60") - STR(latin1_97, "\x61") - STR(latin1_98, "\x62") - STR(latin1_99, "\x63") - STR(latin1_100, "\x64") - STR(latin1_101, "\x65") - STR(latin1_102, "\x66") - STR(latin1_103, "\x67") - STR(latin1_104, "\x68") - STR(latin1_105, "\x69") - STR(latin1_106, "\x6A") - STR(latin1_107, "\x6B") - STR(latin1_108, "\x6C") - STR(latin1_109, "\x6D") - STR(latin1_110, "\x6E") - STR(latin1_111, "\x6F") - STR(latin1_112, "\x70") - STR(latin1_113, "\x71") - STR(latin1_114, "\x72") - STR(latin1_115, "\x73") - STR(latin1_116, "\x74") - STR(latin1_117, "\x75") - STR(latin1_118, "\x76") - STR(latin1_119, "\x77") - STR(latin1_120, "\x78") - STR(latin1_121, "\x79") - STR(latin1_122, "\x7A") - STR(latin1_123, "\x7B") - STR(latin1_124, "\x7C") - STR(latin1_125, "\x7D") - STR(latin1_126, "\x7E") - STR(latin1_127, "\x7F") - STR(latin1_128, "\x80") - STR(latin1_129, "\x81") - STR(latin1_130, "\x82") - STR(latin1_131, "\x83") - STR(latin1_132, "\x84") - STR(latin1_133, "\x85") - STR(latin1_134, "\x86") - STR(latin1_135, "\x87") - STR(latin1_136, "\x88") - STR(latin1_137, "\x89") - STR(latin1_138, "\x8A") - STR(latin1_139, "\x8B") - STR(latin1_140, "\x8C") - STR(latin1_141, "\x8D") - STR(latin1_142, "\x8E") - STR(latin1_143, "\x8F") - STR(latin1_144, "\x90") - STR(latin1_145, "\x91") - STR(latin1_146, "\x92") - STR(latin1_147, "\x93") - STR(latin1_148, "\x94") - STR(latin1_149, "\x95") - STR(latin1_150, "\x96") - STR(latin1_151, "\x97") - STR(latin1_152, "\x98") - STR(latin1_153, "\x99") - STR(latin1_154, "\x9A") - STR(latin1_155, "\x9B") - STR(latin1_156, "\x9C") - STR(latin1_157, "\x9D") - STR(latin1_158, "\x9E") - STR(latin1_159, "\x9F") - STR(latin1_160, "\xA0") - STR(latin1_161, "\xA1") - STR(latin1_162, "\xA2") - STR(latin1_163, "\xA3") - STR(latin1_164, "\xA4") - STR(latin1_165, "\xA5") - STR(latin1_166, "\xA6") - STR(latin1_167, "\xA7") - STR(latin1_168, "\xA8") - STR(latin1_169, "\xA9") - STR(latin1_170, "\xAA") - STR(latin1_171, "\xAB") - STR(latin1_172, "\xAC") - STR(latin1_173, "\xAD") - STR(latin1_174, "\xAE") - STR(latin1_175, "\xAF") - STR(latin1_176, "\xB0") - STR(latin1_177, "\xB1") - STR(latin1_178, "\xB2") - STR(latin1_179, "\xB3") - STR(latin1_180, "\xB4") - STR(latin1_181, "\xB5") - STR(latin1_182, "\xB6") - STR(latin1_183, "\xB7") - STR(latin1_184, "\xB8") - STR(latin1_185, "\xB9") - STR(latin1_186, "\xBA") - STR(latin1_187, "\xBB") - STR(latin1_188, "\xBC") - STR(latin1_189, "\xBD") - STR(latin1_190, "\xBE") - STR(latin1_191, "\xBF") - STR(latin1_192, "\xC0") - STR(latin1_193, "\xC1") - STR(latin1_194, "\xC2") - STR(latin1_195, "\xC3") - STR(latin1_196, "\xC4") - STR(latin1_197, "\xC5") - STR(latin1_198, "\xC6") - STR(latin1_199, "\xC7") - STR(latin1_200, "\xC8") - STR(latin1_201, "\xC9") - STR(latin1_202, "\xCA") - STR(latin1_203, "\xCB") - STR(latin1_204, "\xCC") - STR(latin1_205, "\xCD") - STR(latin1_206, "\xCE") - STR(latin1_207, "\xCF") - STR(latin1_208, "\xD0") - STR(latin1_209, "\xD1") - STR(latin1_210, "\xD2") - STR(latin1_211, "\xD3") - STR(latin1_212, "\xD4") - STR(latin1_213, "\xD5") - STR(latin1_214, "\xD6") - STR(latin1_215, "\xD7") - STR(latin1_216, "\xD8") - STR(latin1_217, "\xD9") - STR(latin1_218, "\xDA") - STR(latin1_219, "\xDB") - STR(latin1_220, "\xDC") - STR(latin1_221, "\xDD") - STR(latin1_222, "\xDE") - STR(latin1_223, "\xDF") - STR(latin1_224, "\xE0") - STR(latin1_225, "\xE1") - STR(latin1_226, "\xE2") - STR(latin1_227, "\xE3") - STR(latin1_228, "\xE4") - STR(latin1_229, "\xE5") - STR(latin1_230, "\xE6") - STR(latin1_231, "\xE7") - STR(latin1_232, "\xE8") - STR(latin1_233, "\xE9") - STR(latin1_234, "\xEA") - STR(latin1_235, "\xEB") - STR(latin1_236, "\xEC") - STR(latin1_237, "\xED") - STR(latin1_238, "\xEE") - STR(latin1_239, "\xEF") - STR(latin1_240, "\xF0") - STR(latin1_241, "\xF1") - STR(latin1_242, "\xF2") - STR(latin1_243, "\xF3") - STR(latin1_244, "\xF4") - STR(latin1_245, "\xF5") - STR(latin1_246, "\xF6") - STR(latin1_247, "\xF7") - STR(latin1_248, "\xF8") - STR(latin1_249, "\xF9") - STR(latin1_250, "\xFA") - STR(latin1_251, "\xFB") - STR(latin1_252, "\xFC") - STR(latin1_253, "\xFD") - STR(latin1_254, "\xFE") - STR(latin1_255, "\xFF") } literals; struct { diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 91e47d9febf2177..94340b2178bf521 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -668,263 +668,6 @@ extern "C" { INIT_STR(anon_setcomp, ""), \ INIT_STR(anon_string, ""), \ INIT_STR(dot_locals, "."), \ - \ - INIT_STR(latin1_0, "\x00"), \ - INIT_STR(latin1_1, "\x01"), \ - INIT_STR(latin1_2, "\x02"), \ - INIT_STR(latin1_3, "\x03"), \ - INIT_STR(latin1_4, "\x04"), \ - INIT_STR(latin1_5, "\x05"), \ - INIT_STR(latin1_6, "\x06"), \ - INIT_STR(latin1_7, "\x07"), \ - INIT_STR(latin1_8, "\x08"), \ - INIT_STR(latin1_9, "\x09"), \ - INIT_STR(latin1_10, "\x0A"), \ - INIT_STR(latin1_11, "\x0B"), \ - INIT_STR(latin1_12, "\x0C"), \ - INIT_STR(latin1_13, "\x0D"), \ - INIT_STR(latin1_14, "\x0E"), \ - INIT_STR(latin1_15, "\x0F"), \ - INIT_STR(latin1_16, "\x10"), \ - INIT_STR(latin1_17, "\x11"), \ - INIT_STR(latin1_18, "\x12"), \ - INIT_STR(latin1_19, "\x13"), \ - INIT_STR(latin1_20, "\x14"), \ - INIT_STR(latin1_21, "\x15"), \ - INIT_STR(latin1_22, "\x16"), \ - INIT_STR(latin1_23, "\x17"), \ - INIT_STR(latin1_24, "\x18"), \ - INIT_STR(latin1_25, "\x19"), \ - INIT_STR(latin1_26, "\x1A"), \ - INIT_STR(latin1_27, "\x1B"), \ - INIT_STR(latin1_28, "\x1C"), \ - INIT_STR(latin1_29, "\x1D"), \ - INIT_STR(latin1_30, "\x1E"), \ - INIT_STR(latin1_31, "\x1F"), \ - INIT_STR(latin1_32, "\x20"), \ - INIT_STR(latin1_33, "\x21"), \ - INIT_STR(latin1_34, "\x22"), \ - INIT_STR(latin1_35, "\x23"), \ - INIT_STR(latin1_36, "\x24"), \ - INIT_STR(latin1_37, "\x25"), \ - INIT_STR(latin1_38, "\x26"), \ - INIT_STR(latin1_39, "\x27"), \ - INIT_STR(latin1_40, "\x28"), \ - INIT_STR(latin1_41, "\x29"), \ - INIT_STR(latin1_42, "\x2A"), \ - INIT_STR(latin1_43, "\x2B"), \ - INIT_STR(latin1_44, "\x2C"), \ - INIT_STR(latin1_45, "\x2D"), \ - INIT_STR(latin1_46, "\x2E"), \ - INIT_STR(latin1_47, "\x2F"), \ - INIT_STR(latin1_48, "\x30"), \ - INIT_STR(latin1_49, "\x31"), \ - INIT_STR(latin1_50, "\x32"), \ - INIT_STR(latin1_51, "\x33"), \ - INIT_STR(latin1_52, "\x34"), \ - INIT_STR(latin1_53, "\x35"), \ - INIT_STR(latin1_54, "\x36"), \ - INIT_STR(latin1_55, "\x37"), \ - INIT_STR(latin1_56, "\x38"), \ - INIT_STR(latin1_57, "\x39"), \ - INIT_STR(latin1_58, "\x3A"), \ - INIT_STR(latin1_59, "\x3B"), \ - INIT_STR(latin1_60, "\x3C"), \ - INIT_STR(latin1_61, "\x3D"), \ - INIT_STR(latin1_62, "\x3E"), \ - INIT_STR(latin1_63, "\x3F"), \ - INIT_STR(latin1_64, "\x40"), \ - INIT_STR(latin1_65, "\x41"), \ - INIT_STR(latin1_66, "\x42"), \ - INIT_STR(latin1_67, "\x43"), \ - INIT_STR(latin1_68, "\x44"), \ - INIT_STR(latin1_69, "\x45"), \ - INIT_STR(latin1_70, "\x46"), \ - INIT_STR(latin1_71, "\x47"), \ - INIT_STR(latin1_72, "\x48"), \ - INIT_STR(latin1_73, "\x49"), \ - INIT_STR(latin1_74, "\x4A"), \ - INIT_STR(latin1_75, "\x4B"), \ - INIT_STR(latin1_76, "\x4C"), \ - INIT_STR(latin1_77, "\x4D"), \ - INIT_STR(latin1_78, "\x4E"), \ - INIT_STR(latin1_79, "\x4F"), \ - INIT_STR(latin1_80, "\x50"), \ - INIT_STR(latin1_81, "\x51"), \ - INIT_STR(latin1_82, "\x52"), \ - INIT_STR(latin1_83, "\x53"), \ - INIT_STR(latin1_84, "\x54"), \ - INIT_STR(latin1_85, "\x55"), \ - INIT_STR(latin1_86, "\x56"), \ - INIT_STR(latin1_87, "\x57"), \ - INIT_STR(latin1_88, "\x58"), \ - INIT_STR(latin1_89, "\x59"), \ - INIT_STR(latin1_90, "\x5A"), \ - INIT_STR(latin1_91, "\x5B"), \ - INIT_STR(latin1_92, "\x5C"), \ - INIT_STR(latin1_93, "\x5D"), \ - INIT_STR(latin1_94, "\x5E"), \ - INIT_STR(latin1_95, "\x5F"), \ - INIT_STR(latin1_96, "\x60"), \ - INIT_STR(latin1_97, "\x61"), \ - INIT_STR(latin1_98, "\x62"), \ - INIT_STR(latin1_99, "\x63"), \ - INIT_STR(latin1_100, "\x64"), \ - INIT_STR(latin1_101, "\x65"), \ - INIT_STR(latin1_102, "\x66"), \ - INIT_STR(latin1_103, "\x67"), \ - INIT_STR(latin1_104, "\x68"), \ - INIT_STR(latin1_105, "\x69"), \ - INIT_STR(latin1_106, "\x6A"), \ - INIT_STR(latin1_107, "\x6B"), \ - INIT_STR(latin1_108, "\x6C"), \ - INIT_STR(latin1_109, "\x6D"), \ - INIT_STR(latin1_110, "\x6E"), \ - INIT_STR(latin1_111, "\x6F"), \ - INIT_STR(latin1_112, "\x70"), \ - INIT_STR(latin1_113, "\x71"), \ - INIT_STR(latin1_114, "\x72"), \ - INIT_STR(latin1_115, "\x73"), \ - INIT_STR(latin1_116, "\x74"), \ - INIT_STR(latin1_117, "\x75"), \ - INIT_STR(latin1_118, "\x76"), \ - INIT_STR(latin1_119, "\x77"), \ - INIT_STR(latin1_120, "\x78"), \ - INIT_STR(latin1_121, "\x79"), \ - INIT_STR(latin1_122, "\x7A"), \ - INIT_STR(latin1_123, "\x7B"), \ - INIT_STR(latin1_124, "\x7C"), \ - INIT_STR(latin1_125, "\x7D"), \ - INIT_STR(latin1_126, "\x7E"), \ - INIT_STR(latin1_127, "\x7F"), \ - INIT_STR(latin1_128, "\x80"), \ - INIT_STR(latin1_129, "\x81"), \ - INIT_STR(latin1_130, "\x82"), \ - INIT_STR(latin1_131, "\x83"), \ - INIT_STR(latin1_132, "\x84"), \ - INIT_STR(latin1_133, "\x85"), \ - INIT_STR(latin1_134, "\x86"), \ - INIT_STR(latin1_135, "\x87"), \ - INIT_STR(latin1_136, "\x88"), \ - INIT_STR(latin1_137, "\x89"), \ - INIT_STR(latin1_138, "\x8A"), \ - INIT_STR(latin1_139, "\x8B"), \ - INIT_STR(latin1_140, "\x8C"), \ - INIT_STR(latin1_141, "\x8D"), \ - INIT_STR(latin1_142, "\x8E"), \ - INIT_STR(latin1_143, "\x8F"), \ - INIT_STR(latin1_144, "\x90"), \ - INIT_STR(latin1_145, "\x91"), \ - INIT_STR(latin1_146, "\x92"), \ - INIT_STR(latin1_147, "\x93"), \ - INIT_STR(latin1_148, "\x94"), \ - INIT_STR(latin1_149, "\x95"), \ - INIT_STR(latin1_150, "\x96"), \ - INIT_STR(latin1_151, "\x97"), \ - INIT_STR(latin1_152, "\x98"), \ - INIT_STR(latin1_153, "\x99"), \ - INIT_STR(latin1_154, "\x9A"), \ - INIT_STR(latin1_155, "\x9B"), \ - INIT_STR(latin1_156, "\x9C"), \ - INIT_STR(latin1_157, "\x9D"), \ - INIT_STR(latin1_158, "\x9E"), \ - INIT_STR(latin1_159, "\x9F"), \ - INIT_STR(latin1_160, "\xA0"), \ - INIT_STR(latin1_161, "\xA1"), \ - INIT_STR(latin1_162, "\xA2"), \ - INIT_STR(latin1_163, "\xA3"), \ - INIT_STR(latin1_164, "\xA4"), \ - INIT_STR(latin1_165, "\xA5"), \ - INIT_STR(latin1_166, "\xA6"), \ - INIT_STR(latin1_167, "\xA7"), \ - INIT_STR(latin1_168, "\xA8"), \ - INIT_STR(latin1_169, "\xA9"), \ - INIT_STR(latin1_170, "\xAA"), \ - INIT_STR(latin1_171, "\xAB"), \ - INIT_STR(latin1_172, "\xAC"), \ - INIT_STR(latin1_173, "\xAD"), \ - INIT_STR(latin1_174, "\xAE"), \ - INIT_STR(latin1_175, "\xAF"), \ - INIT_STR(latin1_176, "\xB0"), \ - INIT_STR(latin1_177, "\xB1"), \ - INIT_STR(latin1_178, "\xB2"), \ - INIT_STR(latin1_179, "\xB3"), \ - INIT_STR(latin1_180, "\xB4"), \ - INIT_STR(latin1_181, "\xB5"), \ - INIT_STR(latin1_182, "\xB6"), \ - INIT_STR(latin1_183, "\xB7"), \ - INIT_STR(latin1_184, "\xB8"), \ - INIT_STR(latin1_185, "\xB9"), \ - INIT_STR(latin1_186, "\xBA"), \ - INIT_STR(latin1_187, "\xBB"), \ - INIT_STR(latin1_188, "\xBC"), \ - INIT_STR(latin1_189, "\xBD"), \ - INIT_STR(latin1_190, "\xBE"), \ - INIT_STR(latin1_191, "\xBF"), \ - INIT_STR(latin1_192, "\xC0"), \ - INIT_STR(latin1_193, "\xC1"), \ - INIT_STR(latin1_194, "\xC2"), \ - INIT_STR(latin1_195, "\xC3"), \ - INIT_STR(latin1_196, "\xC4"), \ - INIT_STR(latin1_197, "\xC5"), \ - INIT_STR(latin1_198, "\xC6"), \ - INIT_STR(latin1_199, "\xC7"), \ - INIT_STR(latin1_200, "\xC8"), \ - INIT_STR(latin1_201, "\xC9"), \ - INIT_STR(latin1_202, "\xCA"), \ - INIT_STR(latin1_203, "\xCB"), \ - INIT_STR(latin1_204, "\xCC"), \ - INIT_STR(latin1_205, "\xCD"), \ - INIT_STR(latin1_206, "\xCE"), \ - INIT_STR(latin1_207, "\xCF"), \ - INIT_STR(latin1_208, "\xD0"), \ - INIT_STR(latin1_209, "\xD1"), \ - INIT_STR(latin1_210, "\xD2"), \ - INIT_STR(latin1_211, "\xD3"), \ - INIT_STR(latin1_212, "\xD4"), \ - INIT_STR(latin1_213, "\xD5"), \ - INIT_STR(latin1_214, "\xD6"), \ - INIT_STR(latin1_215, "\xD7"), \ - INIT_STR(latin1_216, "\xD8"), \ - INIT_STR(latin1_217, "\xD9"), \ - INIT_STR(latin1_218, "\xDA"), \ - INIT_STR(latin1_219, "\xDB"), \ - INIT_STR(latin1_220, "\xDC"), \ - INIT_STR(latin1_221, "\xDD"), \ - INIT_STR(latin1_222, "\xDE"), \ - INIT_STR(latin1_223, "\xDF"), \ - INIT_STR(latin1_224, "\xE0"), \ - INIT_STR(latin1_225, "\xE1"), \ - INIT_STR(latin1_226, "\xE2"), \ - INIT_STR(latin1_227, "\xE3"), \ - INIT_STR(latin1_228, "\xE4"), \ - INIT_STR(latin1_229, "\xE5"), \ - INIT_STR(latin1_230, "\xE6"), \ - INIT_STR(latin1_231, "\xE7"), \ - INIT_STR(latin1_232, "\xE8"), \ - INIT_STR(latin1_233, "\xE9"), \ - INIT_STR(latin1_234, "\xEA"), \ - INIT_STR(latin1_235, "\xEB"), \ - INIT_STR(latin1_236, "\xEC"), \ - INIT_STR(latin1_237, "\xED"), \ - INIT_STR(latin1_238, "\xEE"), \ - INIT_STR(latin1_239, "\xEF"), \ - INIT_STR(latin1_240, "\xF0"), \ - INIT_STR(latin1_241, "\xF1"), \ - INIT_STR(latin1_242, "\xF2"), \ - INIT_STR(latin1_243, "\xF3"), \ - INIT_STR(latin1_244, "\xF4"), \ - INIT_STR(latin1_245, "\xF5"), \ - INIT_STR(latin1_246, "\xF6"), \ - INIT_STR(latin1_247, "\xF7"), \ - INIT_STR(latin1_248, "\xF8"), \ - INIT_STR(latin1_249, "\xF9"), \ - INIT_STR(latin1_250, "\xFA"), \ - INIT_STR(latin1_251, "\xFB"), \ - INIT_STR(latin1_252, "\xFC"), \ - INIT_STR(latin1_253, "\xFD"), \ - INIT_STR(latin1_254, "\xFE"), \ - INIT_STR(latin1_255, "\xFF"), \ }, \ .identifiers = { \ INIT_ID(Py_Repr), \ diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index 1979af7920e7267..7a986f3e04ab8dc 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -409,10 +409,6 @@ def generate_global_strings(): printer.write(f'// {name}') else: printer.write(f'STR({name}, "{literal}")') - outfile.write('\n') - printer.write('// The single character latin-1 (ASCII) strings.') - for i in range(256): - printer.write(f'STR(latin1_{i}, "\\x{i:02X}")') outfile.write('\n') with printer.block('struct', ' identifiers;'): for name in sorted(IDENTIFIERS): @@ -473,9 +469,6 @@ def generate_runtime_init(): printer.write('') else: printer.write(f'INIT_STR({name}, "{literal}"),') - printer.write('') - for i in range(256): - printer.write(f'INIT_STR(latin1_{i}, "\\x{i:02X}"),') with printer.block('.identifiers =', ','): for name in sorted(IDENTIFIERS): assert name.isidentifier(), name From db9de0a1122a9419dde700ed4e827d762f4f07d9 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 12:20:13 -0700 Subject: [PATCH 082/115] Use a better prefix for the field names. --- Include/internal/pycore_global_strings.h | 10 +++++----- Include/internal/pycore_runtime_init.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 7f19718a1c1d1cf..9653a40b5d836b8 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -10,14 +10,14 @@ extern "C" { // The data structure & init here are inspired by Tools/scripts/deepfreeze.py. -// All field names generated by STR() have an extra leading dollar sign. -// This helps avoid collisions with keywords, etc. +// All field names generated by STR() have a common prefix, +// to help avoid collisions with keywords, etc. #define STR(NAME, LITERAL) \ struct { \ PyASCIIObject _ascii; \ uint8_t _data[_Py_STRING_LENGTH(LITERAL)]; \ - } $ ## NAME; + } spamspamspam_ ## NAME; #define ID(NAME) \ STR(NAME, #NAME) @@ -353,10 +353,10 @@ struct _Py_global_strings { #define _Py_GET_GLOBAL_IDENTIFIER(NAME) \ - (&_Py_SINGLETON(strings.identifiers.$ ## NAME._ascii.ob_base)) + (&_Py_SINGLETON(strings.identifiers.spamspamspam_ ## NAME._ascii.ob_base)) #define _Py_GET_GLOBAL_STRING(NAME) \ - (&_Py_SINGLETON(strings.literals.$ ## NAME._ascii.ob_base)) + (&_Py_SINGLETON(strings.literals.spamspamspam_ ## NAME._ascii.ob_base)) #ifdef __cplusplus diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 94340b2178bf521..aedaedcf652be2c 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -112,7 +112,7 @@ extern "C" { ._data = LITERAL, \ } #define INIT_STR(NAME, LITERAL) \ - .$ ## NAME = _PyASCIIObject_INIT(LITERAL) + .spamspamspam_ ## NAME = _PyASCIIObject_INIT(LITERAL) #define INIT_ID(NAME) \ INIT_STR(NAME, #NAME) From 1074b7706aec230d5cd28b371704b834ad8e505c Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 12:33:02 -0700 Subject: [PATCH 083/115] Clean up the declarations a little. --- Include/internal/pycore_global_strings.h | 46 ++++++++++++------------ Include/internal/pycore_runtime_init.h | 2 +- Tools/scripts/generate_global_objects.py | 2 +- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 9653a40b5d836b8..670e0cd6ece2400 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -13,42 +13,44 @@ extern "C" { // All field names generated by STR() have a common prefix, // to help avoid collisions with keywords, etc. -#define STR(NAME, LITERAL) \ +#define ASCII_STR(LITERAL) \ struct { \ PyASCIIObject _ascii; \ uint8_t _data[_Py_STRING_LENGTH(LITERAL)]; \ - } spamspamspam_ ## NAME; + } +#define LITERAL(NAME, LITERAL) \ + ASCII_STR(LITERAL) spamspamspam_ ## NAME; #define ID(NAME) \ - STR(NAME, #NAME) + ASCII_STR(#NAME) spamspamspam_ ## NAME; // XXX Order by frequency of use? /* The following is auto-generated by Tools/scripts/generate_global_objects.py. */ struct _Py_global_strings { struct { - STR(empty, "") - STR(newline, "\n") - STR(dot, ".") - STR(comma_sep, ", ") - STR(percent, "%") - STR(dbl_percent, "%%") - STR(replace_inf, "1eNN") + LITERAL(empty, "") + LITERAL(newline, "\n") + LITERAL(dot, ".") + LITERAL(comma_sep, ", ") + LITERAL(percent, "%") + LITERAL(dbl_percent, "%%") + LITERAL(replace_inf, "1eNN") // braces - STR(br_open, "{") - STR(br_close, "}") - STR(br_dbl_open, "{{") - STR(br_dbl_close, "}}") + LITERAL(br_open, "{") + LITERAL(br_close, "}") + LITERAL(br_dbl_open, "{{") + LITERAL(br_dbl_close, "}}") // "anonymous" labels - STR(anon_dictcomp, "") - STR(anon_genexpr, "") - STR(anon_lambda, "") - STR(anon_listcomp, "") - STR(anon_module, "") - STR(anon_setcomp, "") - STR(anon_string, "") - STR(dot_locals, ".") + LITERAL(anon_dictcomp, "") + LITERAL(anon_genexpr, "") + LITERAL(anon_lambda, "") + LITERAL(anon_listcomp, "") + LITERAL(anon_module, "") + LITERAL(anon_setcomp, "") + LITERAL(anon_string, "") + LITERAL(dot_locals, ".") } literals; struct { diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index aedaedcf652be2c..1bbc0f9d2183cdb 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -114,7 +114,7 @@ extern "C" { #define INIT_STR(NAME, LITERAL) \ .spamspamspam_ ## NAME = _PyASCIIObject_INIT(LITERAL) #define INIT_ID(NAME) \ - INIT_STR(NAME, #NAME) + .spamspamspam_ ## NAME = _PyASCIIObject_INIT(#NAME) /* The following is auto-generated by Tools/scripts/generate_global_objects.py. */ diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index 7a986f3e04ab8dc..e4d7c93715abac9 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -408,7 +408,7 @@ def generate_global_strings(): outfile.write('\n') printer.write(f'// {name}') else: - printer.write(f'STR({name}, "{literal}")') + printer.write(f'LITERAL({name}, "{literal}")') outfile.write('\n') with printer.block('struct', ' identifiers;'): for name in sorted(IDENTIFIERS): From d4f58fdd3e843daaab86753c7fd913a967726ab9 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 13:02:47 -0700 Subject: [PATCH 084/115] Add _Py_IS_POINTER_FROM_VAR(). --- Include/pymacro.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Include/pymacro.h b/Include/pymacro.h index b83df5d399fcc07..e041844eb48161a 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -68,6 +68,10 @@ #define _Py_STRING_LENGTH(str) \ (sizeof(str) / sizeof(char)) +#define _Py_IS_POINTER_FROM_VAR(PTR, VAR) \ + (((uintptr_t)(PTR) >= (uintptr_t)(&(VAR))) && \ + ((uintptr_t)(PTR) < (uintptr_t)((&(VAR)) + 1))) + /* Define macros for inline documentation. */ #define PyDoc_VAR(name) static const char name[] From 09c2a51b5ccabfc7e3eb20c2c27dc9efa23f8d67 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 13:04:03 -0700 Subject: [PATCH 085/115] Consider all global strings as singletons. --- Objects/unicodeobject.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 3d008927226c1b0..d8bb14e940bd95d 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1986,10 +1986,11 @@ unicode_dealloc(PyObject *unicode) static int unicode_is_singleton(PyObject *unicode) { - struct _Py_unicode_state *state = get_unicode_state(); - if (unicode == _Py_GET_GLOBAL_STRING(empty)) { + if (_Py_IS_POINTER_FROM_VAR(unicode, _Py_SINGLETON(strings))) { return 1; } + + struct _Py_unicode_state *state = get_unicode_state(); PyASCIIObject *ascii = (PyASCIIObject *)unicode; if (ascii->state.kind != PyUnicode_WCHAR_KIND && ascii->length == 1) { Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, 0); From 983dda01af07c86e9fdd5c724e63b9505fe8cd66 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 13:21:32 -0700 Subject: [PATCH 086/115] _Py_IS_POINTER_FROM_VAR() -> _PyObject_IsSingleton(). --- Include/internal/pycore_object.h | 14 ++++++++++++++ Include/pymacro.h | 4 ---- Objects/unicodeobject.c | 2 +- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index e2da2537c11c140..b69fe3f07a306e2 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -8,9 +8,11 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif +#include #include "pycore_gc.h" // _PyObject_GC_IS_TRACKED() #include "pycore_interp.h" // PyInterpreterState.gc #include "pycore_pystate.h" // _PyInterpreterState_GET() +#include "pycore_runtime.h" // _PyRuntime #define _PyObject_IMMORTAL_INIT(type) \ @@ -25,6 +27,18 @@ extern "C" { } +static inline bool _PyObject_IsSingleton(PyObject *obj) +{ +#define SINGLETONS (&_PyRuntime.global_objects.singletons) + if (((uintptr_t)obj >= (uintptr_t)(SINGLETONS)) && + ((uintptr_t)obj < (uintptr_t)((SINGLETONS) + 1))) { +#undef SINGLETONS + return true; + } + return false; +} + + PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type); PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content); diff --git a/Include/pymacro.h b/Include/pymacro.h index e041844eb48161a..b83df5d399fcc07 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -68,10 +68,6 @@ #define _Py_STRING_LENGTH(str) \ (sizeof(str) / sizeof(char)) -#define _Py_IS_POINTER_FROM_VAR(PTR, VAR) \ - (((uintptr_t)(PTR) >= (uintptr_t)(&(VAR))) && \ - ((uintptr_t)(PTR) < (uintptr_t)((&(VAR)) + 1))) - /* Define macros for inline documentation. */ #define PyDoc_VAR(name) static const char name[] diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index d8bb14e940bd95d..3f94837930267e2 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1986,7 +1986,7 @@ unicode_dealloc(PyObject *unicode) static int unicode_is_singleton(PyObject *unicode) { - if (_Py_IS_POINTER_FROM_VAR(unicode, _Py_SINGLETON(strings))) { + if (_PyObject_IsSingleton(unicode)) { return 1; } From 3fbc75fef9918042627c23a47685f6fc18f7eb60 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 15:48:01 -0700 Subject: [PATCH 087/115] Add _PyUnicode_InternSafe(). --- Include/internal/pycore_unicodeobject.h | 2 + Objects/unicodeobject.c | 77 +++++++++++++++---------- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index 977bbeb19171200..fcae733135eaedb 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -53,6 +53,8 @@ struct _Py_unicode_state { struct _Py_unicode_ids ids; }; +PyAPI_FUNC(PyObject *) _PyUnicode_InternSafe(PyObject *); + extern void _PyUnicode_ClearInterned(PyInterpreterState *interp); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 3f94837930267e2..b7ac66f43abb8c7 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15559,53 +15559,31 @@ _PyUnicode_InitTypes(PyInterpreterState *interp) } -void -PyUnicode_InternInPlace(PyObject **p) +static PyObject * +unicode_intern(PyObject *s) { - PyObject *s = *p; -#ifdef Py_DEBUG - assert(s != NULL); - assert(_PyUnicode_CHECK(s)); -#else - if (s == NULL || !PyUnicode_Check(s)) { - return; - } -#endif - - /* If it's a subclass, we don't really know what putting - it in the interned dict might do. */ - if (!PyUnicode_CheckExact(s)) { - return; - } - if (PyUnicode_CHECK_INTERNED(s)) { - return; + return s; } #ifdef INTERNED_STRINGS if (PyUnicode_READY(s) == -1) { - PyErr_Clear(); - return; + return NULL; } if (interned == NULL) { interned = PyDict_New(); if (interned == NULL) { - PyErr_Clear(); /* Don't leave an exception */ - return; + return NULL; } } PyObject *t = PyDict_SetDefault(interned, s, s); if (t == NULL) { - PyErr_Clear(); - return; + return NULL; } - if (t != s) { - Py_INCREF(t); - Py_SETREF(*p, t); - return; + return t; } /* The two references in interned dict (key and value) are not counted by @@ -15618,6 +15596,47 @@ PyUnicode_InternInPlace(PyObject **p) // (PyASCIIObject.hash) already computed. (void)unicode_hash(s); #endif + return s; +} + +/* Return true if already interned. */ +PyObject * +_PyUnicode_InternSafe(PyObject *s) +{ + PyObject *actual = unicode_intern(s); + if (actual == NULL) { + PyErr_Clear(); /* Don't leave an exception */ + actual = s; + } + return actual; +} + +void +PyUnicode_InternInPlace(PyObject **p) +{ + PyObject *s = *p; +#ifdef Py_DEBUG + assert(s != NULL); + assert(_PyUnicode_CHECK(s)); +#else + if (s == NULL || !PyUnicode_Check(s)) { + return; + } +#endif + + /* If it's a subclass, we don't really know what putting + it in the interned dict might do. */ + if (!PyUnicode_CheckExact(s)) { + return; + } + + PyObject *t = unicode_intern(s); + if (t == NULL) { + PyErr_Clear(); /* Don't leave an exception */ + } else if (t != s) { + Py_INCREF(t); + Py_SETREF(*p, t); + } } void From bd8b74cfce968561bbbd9f2a712368436e786c5a Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 15:48:43 -0700 Subject: [PATCH 088/115] Intern the global strings when used. --- Include/internal/pycore_global_strings.h | 8 ++++++-- Objects/typeobject.c | 15 ++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 670e0cd6ece2400..f5c7f99715b7719 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -354,11 +354,15 @@ struct _Py_global_strings { #undef STR -#define _Py_GET_GLOBAL_IDENTIFIER(NAME) \ +#define _Py_RESOLVE_GLOBAL_IDENTIFIER(NAME) \ (&_Py_SINGLETON(strings.identifiers.spamspamspam_ ## NAME._ascii.ob_base)) +#define _Py_RESOLVE_GLOBAL_STRING(NAME) \ + (&_Py_SINGLETON(strings.literals.spamspamspam_ ## NAME._ascii.ob_base)) +#define _Py_GET_GLOBAL_IDENTIFIER(NAME) \ + _PyUnicode_InternSafe(_Py_RESOLVE_GLOBAL_IDENTIFIER(NAME)) #define _Py_GET_GLOBAL_STRING(NAME) \ - (&_Py_SINGLETON(strings.literals.spamspamspam_ ## NAME._ascii.ob_base)) + _PyUnicode_InternSafe(_Py_RESOLVE_GLOBAL_STRING(NAME)) #ifdef __cplusplus diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 4952067708cb9e9..f9ff4457ae16821 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -7752,12 +7752,12 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) } static PyObject *name_op[] = { - _Py_GET_GLOBAL_IDENTIFIER(__lt__), - _Py_GET_GLOBAL_IDENTIFIER(__le__), - _Py_GET_GLOBAL_IDENTIFIER(__eq__), - _Py_GET_GLOBAL_IDENTIFIER(__ne__), - _Py_GET_GLOBAL_IDENTIFIER(__gt__), - _Py_GET_GLOBAL_IDENTIFIER(__ge__), + _Py_RESOLVE_GLOBAL_IDENTIFIER(__lt__), + _Py_RESOLVE_GLOBAL_IDENTIFIER(__le__), + _Py_RESOLVE_GLOBAL_IDENTIFIER(__eq__), + _Py_RESOLVE_GLOBAL_IDENTIFIER(__ne__), + _Py_RESOLVE_GLOBAL_IDENTIFIER(__gt__), + _Py_RESOLVE_GLOBAL_IDENTIFIER(__ge__), }; static PyObject * @@ -7766,7 +7766,8 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op) PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *func = lookup_maybe_method(self, name_op[op], &unbound); + PyObject *name = _PyUnicode_InternSafe(name_op[op]); + PyObject *func = lookup_maybe_method(self, name, &unbound); if (func == NULL) { PyErr_Clear(); Py_RETURN_NOTIMPLEMENTED; From b305ded43357fdc4a2b3bf313f1fea1eec1ce539 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 15:55:43 -0700 Subject: [PATCH 089/115] Limit when we check the global strings for consistency. --- Objects/unicodeobject.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index b7ac66f43abb8c7..8be369b9005584e 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15529,8 +15529,14 @@ _PyUnicode_InitState(PyInterpreterState *interp) PyStatus _PyUnicode_InitGlobalObjects(PyInterpreterState *interp) { + if (!_Py_IsMainInterpreter(interp)) { + return _PyStatus_OK(); + } + +#ifdef Py_DEBUG PyObject *empty = _Py_GET_GLOBAL_STRING(empty); assert(_PyUnicode_CheckConsistency(empty, 1)); +#endif return _PyStatus_OK(); } From 3da2d657fb76dacc3180b8669669d1e7bc0a64f8 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 16:01:19 -0700 Subject: [PATCH 090/115] Drop _PyUnicode_InternSafe(). --- Include/internal/pycore_global_strings.h | 9 +-- Include/internal/pycore_unicodeobject.h | 2 - Objects/typeobject.c | 15 +++-- Objects/unicodeobject.c | 77 +++++++++--------------- 4 files changed, 38 insertions(+), 65 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index f5c7f99715b7719..63e607e91feb9c6 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -354,15 +354,10 @@ struct _Py_global_strings { #undef STR -#define _Py_RESOLVE_GLOBAL_IDENTIFIER(NAME) \ - (&_Py_SINGLETON(strings.identifiers.spamspamspam_ ## NAME._ascii.ob_base)) -#define _Py_RESOLVE_GLOBAL_STRING(NAME) \ - (&_Py_SINGLETON(strings.literals.spamspamspam_ ## NAME._ascii.ob_base)) - #define _Py_GET_GLOBAL_IDENTIFIER(NAME) \ - _PyUnicode_InternSafe(_Py_RESOLVE_GLOBAL_IDENTIFIER(NAME)) + (&_Py_SINGLETON(strings.identifiers.spamspamspam_ ## NAME._ascii.ob_base)) #define _Py_GET_GLOBAL_STRING(NAME) \ - _PyUnicode_InternSafe(_Py_RESOLVE_GLOBAL_STRING(NAME)) + (&_Py_SINGLETON(strings.literals.spamspamspam_ ## NAME._ascii.ob_base)) #ifdef __cplusplus diff --git a/Include/internal/pycore_unicodeobject.h b/Include/internal/pycore_unicodeobject.h index fcae733135eaedb..977bbeb19171200 100644 --- a/Include/internal/pycore_unicodeobject.h +++ b/Include/internal/pycore_unicodeobject.h @@ -53,8 +53,6 @@ struct _Py_unicode_state { struct _Py_unicode_ids ids; }; -PyAPI_FUNC(PyObject *) _PyUnicode_InternSafe(PyObject *); - extern void _PyUnicode_ClearInterned(PyInterpreterState *interp); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index f9ff4457ae16821..4952067708cb9e9 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -7752,12 +7752,12 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) } static PyObject *name_op[] = { - _Py_RESOLVE_GLOBAL_IDENTIFIER(__lt__), - _Py_RESOLVE_GLOBAL_IDENTIFIER(__le__), - _Py_RESOLVE_GLOBAL_IDENTIFIER(__eq__), - _Py_RESOLVE_GLOBAL_IDENTIFIER(__ne__), - _Py_RESOLVE_GLOBAL_IDENTIFIER(__gt__), - _Py_RESOLVE_GLOBAL_IDENTIFIER(__ge__), + _Py_GET_GLOBAL_IDENTIFIER(__lt__), + _Py_GET_GLOBAL_IDENTIFIER(__le__), + _Py_GET_GLOBAL_IDENTIFIER(__eq__), + _Py_GET_GLOBAL_IDENTIFIER(__ne__), + _Py_GET_GLOBAL_IDENTIFIER(__gt__), + _Py_GET_GLOBAL_IDENTIFIER(__ge__), }; static PyObject * @@ -7766,8 +7766,7 @@ slot_tp_richcompare(PyObject *self, PyObject *other, int op) PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *name = _PyUnicode_InternSafe(name_op[op]); - PyObject *func = lookup_maybe_method(self, name, &unbound); + PyObject *func = lookup_maybe_method(self, name_op[op], &unbound); if (func == NULL) { PyErr_Clear(); Py_RETURN_NOTIMPLEMENTED; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 8be369b9005584e..ce9676e0aaba185 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15565,31 +15565,53 @@ _PyUnicode_InitTypes(PyInterpreterState *interp) } -static PyObject * -unicode_intern(PyObject *s) +void +PyUnicode_InternInPlace(PyObject **p) { + PyObject *s = *p; +#ifdef Py_DEBUG + assert(s != NULL); + assert(_PyUnicode_CHECK(s)); +#else + if (s == NULL || !PyUnicode_Check(s)) { + return; + } +#endif + + /* If it's a subclass, we don't really know what putting + it in the interned dict might do. */ + if (!PyUnicode_CheckExact(s)) { + return; + } + if (PyUnicode_CHECK_INTERNED(s)) { - return s; + return; } #ifdef INTERNED_STRINGS if (PyUnicode_READY(s) == -1) { - return NULL; + PyErr_Clear(); + return; } if (interned == NULL) { interned = PyDict_New(); if (interned == NULL) { - return NULL; + PyErr_Clear(); /* Don't leave an exception */ + return; } } PyObject *t = PyDict_SetDefault(interned, s, s); if (t == NULL) { - return NULL; + PyErr_Clear(); + return; } + if (t != s) { - return t; + Py_INCREF(t); + Py_SETREF(*p, t); + return; } /* The two references in interned dict (key and value) are not counted by @@ -15602,47 +15624,6 @@ unicode_intern(PyObject *s) // (PyASCIIObject.hash) already computed. (void)unicode_hash(s); #endif - return s; -} - -/* Return true if already interned. */ -PyObject * -_PyUnicode_InternSafe(PyObject *s) -{ - PyObject *actual = unicode_intern(s); - if (actual == NULL) { - PyErr_Clear(); /* Don't leave an exception */ - actual = s; - } - return actual; -} - -void -PyUnicode_InternInPlace(PyObject **p) -{ - PyObject *s = *p; -#ifdef Py_DEBUG - assert(s != NULL); - assert(_PyUnicode_CHECK(s)); -#else - if (s == NULL || !PyUnicode_Check(s)) { - return; - } -#endif - - /* If it's a subclass, we don't really know what putting - it in the interned dict might do. */ - if (!PyUnicode_CheckExact(s)) { - return; - } - - PyObject *t = unicode_intern(s); - if (t == NULL) { - PyErr_Clear(); /* Don't leave an exception */ - } else if (t != s) { - Py_INCREF(t); - Py_SETREF(*p, t); - } } void From 3673bbd20e99ea045f749a612db38134558799ea Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 17:42:16 -0700 Subject: [PATCH 091/115] Add a --check option to generate_global_objects.py. --- Tools/scripts/generate_global_objects.py | 157 +++++++++++++++++++++-- 1 file changed, 148 insertions(+), 9 deletions(-) diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index e4d7c93715abac9..8230852b2c0d7de 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -1,9 +1,7 @@ -import argparse -import ast -import builtins -import collections import contextlib +import glob import os.path +import re import sys @@ -477,16 +475,157 @@ def generate_runtime_init(): printer.write(after) +####################################### +# checks + +def err(msg): + print(msg, file=sys.stderr) + + +GETTER_RE = re.compile(r''' + ^ + .*? + (?: + (?: + _Py_GET_GLOBAL_IDENTIFIER + [(] + ( \w+ ) # + [)] + ) + | + (?: + _Py_GET_GLOBAL_STRING + [(] + ( \w+ ) # + [)] + ) + ) +''', re.VERBOSE) +TYPESLOTS_RE = re.compile(r''' + ^ + .*? + (?: + (?: + SLOT0 [(] .*?, \s* + ( \w+ ) # + [)] + ) + | + (?: + SLOT1 [(] .*?, \s* + ( \w+ ) # + , .* [)] + ) + | + (?: + SLOT1BIN [(] .*?, .*?, \s* + ( \w+ ) # + , \s* + ( \w+ ) # + [)] + ) + | + (?: + SLOT1BINFULL [(] .*?, .*?, .*?, \s* + ( \w+ ) # + , \s* + ( \w+ ) # + [)] + ) + | + ( SLOT \d .* [^)] $ ) # + ) +''', re.VERBOSE) + +def check_orphan_strings(): + literals = set(n for n, s in STRING_LITERALS.items() if s) + identifiers = set(IDENTIFIERS) + files = glob.iglob(os.path.join(ROOT, '**', '*.[ch]'), recursive=True) + for i, filename in enumerate(files, start=1): + print('.', end='') + if i % 5 == 0: + print(' ', end='') + if i % 20 == 0: + print() + if i % 100 == 0: + print() + with open(filename) as infile: + wrapped = None + for line in infile: + identifier = literal = reverse = None + + line = line.splitlines()[0] + if wrapped: + line = f'{wrapped.rstrip()} {line}' + wrapped = None + + if os.path.basename(filename) == '_warnings.c': + m = re.match(r'^.* = GET_WARNINGS_ATTR[(][^,]*, (\w+),', line) + if m: + identifier, = m.groups() + elif os.path.basename(filename) == 'typeobject.c': + m = TYPESLOTS_RE.match(line) + if m: + (slot0, + slot1, + slot1bin, reverse, + slot1binfull, fullreverse, + wrapped, + ) = m.groups() + identifier = slot0 or slot1 or slot1bin or slot1binfull + reverse = reverse or fullreverse + + if not identifier and not literal: + m = GETTER_RE.match(line) + if not m: + continue + identifier, literal = m.groups() + + if literal: + if literals and literal in literals: + literals.remove(literal) + if identifier: + if identifiers and identifier in identifiers: + identifiers.remove(identifier) + if reverse: + if identifiers and reverse in identifiers: + identifiers.remove(reverse) + if not literals and not identifiers: + break + else: + continue + break + if i % 20: + print() + if not literals and not identifiers: + return + print('ERROR:', file=sys.stderr) + if literals: + err(' unused global string literals:') + for name in sorted(literals): + err(f' {name}') + if identifiers: + if literals: + print() + err(' unused global identifiers:') + for name in sorted(identifiers): + err(f' {name}') + + ####################################### # the script -def main() -> None: +def main(*, check=False) -> None: generate_global_strings() generate_runtime_init() + if check: + check_orphan_strings() + if __name__ == '__main__': - argv = sys.argv[1:] - if argv: - sys.exit(f'ERROR: got unexpected args {argv}') - main() + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('--check', action='store_true') + args = parser.parse_args() + main(**vars(args)) From 9a419a71fe898f483119e36056ae763d345168ee Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 17:42:33 -0700 Subject: [PATCH 092/115] Drop unused global strings. --- Include/internal/pycore_global_strings.h | 31 ----------------------- Include/internal/pycore_runtime_init.h | 30 ---------------------- Tools/scripts/generate_global_objects.py | 32 ------------------------ 3 files changed, 93 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 63e607e91feb9c6..a14732001da97e9 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -29,18 +29,10 @@ extern "C" { struct _Py_global_strings { struct { LITERAL(empty, "") - LITERAL(newline, "\n") LITERAL(dot, ".") LITERAL(comma_sep, ", ") LITERAL(percent, "%") LITERAL(dbl_percent, "%%") - LITERAL(replace_inf, "1eNN") - - // braces - LITERAL(br_open, "{") - LITERAL(br_close, "}") - LITERAL(br_dbl_open, "{{") - LITERAL(br_dbl_close, "}}") // "anonymous" labels LITERAL(anon_dictcomp, "") @@ -205,7 +197,6 @@ struct _Py_global_strings { ID(__xor__) ID(_abc_impl) ID(_blksize) - ID(_bootstrap) ID(_dealloc_warn) ID(_finalizing) ID(_find_and_load) @@ -227,30 +218,22 @@ struct _Py_global_strings { ID(big) ID(buffer) ID(builtins) - ID(c_call) - ID(c_exception) - ID(c_return) - ID(call) ID(clear) ID(close) - ID(closed) ID(code) ID(copy) ID(copyreg) ID(decode) - ID(default) ID(defaultaction) ID(difference_update) ID(dispatch_table) ID(displayhook) ID(enable) - ID(encode) ID(encoding) ID(end_lineno) ID(end_offset) ID(errors) ID(excepthook) - ID(exception) ID(extend) ID(filename) ID(fileno) @@ -261,14 +244,8 @@ struct _Py_global_strings { ID(get) ID(get_source) ID(getattr) - ID(getpreferredencoding) - ID(getstate) - ID(ignore) - ID(imp) ID(importlib) - ID(inf) ID(intersection) - ID(intersection_update) ID(isatty) ID(items) ID(iter) @@ -277,10 +254,8 @@ struct _Py_global_strings { ID(last_type) ID(last_value) ID(latin1) - ID(line) ID(lineno) ID(little) - ID(locale) ID(match) ID(metaclass) ID(mode) @@ -291,11 +266,9 @@ struct _Py_global_strings { ID(n_sequence_fields) ID(n_unnamed_fields) ID(name) - ID(newlines) ID(obj) ID(offset) ID(onceregistry) - ID(opcode) ID(open) ID(parent) ID(partial) @@ -325,20 +298,16 @@ struct _Py_global_strings { ID(send) ID(setstate) ID(sort) - ID(st_mode) ID(stderr) ID(stdin) ID(stdout) ID(strict) - ID(struct_rusage) ID(symmetric_difference_update) ID(tell) ID(text) ID(threading) ID(throw) - ID(truncate) ID(unraisablehook) - ID(update) ID(values) ID(version) ID(warnings) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 1bbc0f9d2183cdb..3d0b80a64a8abc4 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -648,17 +648,10 @@ extern "C" { .strings = { \ .literals = { \ INIT_STR(empty, ""), \ - INIT_STR(newline, "\n"), \ INIT_STR(dot, "."), \ INIT_STR(comma_sep, ", "), \ INIT_STR(percent, "%"), \ INIT_STR(dbl_percent, "%%"), \ - INIT_STR(replace_inf, "1eNN"), \ - \ - INIT_STR(br_open, "{"), \ - INIT_STR(br_close, "}"), \ - INIT_STR(br_dbl_open, "{{"), \ - INIT_STR(br_dbl_close, "}}"), \ \ INIT_STR(anon_dictcomp, ""), \ INIT_STR(anon_genexpr, ""), \ @@ -821,7 +814,6 @@ extern "C" { INIT_ID(__xor__), \ INIT_ID(_abc_impl), \ INIT_ID(_blksize), \ - INIT_ID(_bootstrap), \ INIT_ID(_dealloc_warn), \ INIT_ID(_finalizing), \ INIT_ID(_find_and_load), \ @@ -843,30 +835,22 @@ 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(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), \ @@ -877,14 +861,8 @@ extern "C" { INIT_ID(get), \ INIT_ID(get_source), \ INIT_ID(getattr), \ - INIT_ID(getpreferredencoding), \ - INIT_ID(getstate), \ - INIT_ID(ignore), \ - INIT_ID(imp), \ INIT_ID(importlib), \ - INIT_ID(inf), \ INIT_ID(intersection), \ - INIT_ID(intersection_update), \ INIT_ID(isatty), \ INIT_ID(items), \ INIT_ID(iter), \ @@ -893,10 +871,8 @@ extern "C" { INIT_ID(last_type), \ INIT_ID(last_value), \ INIT_ID(latin1), \ - INIT_ID(line), \ INIT_ID(lineno), \ INIT_ID(little), \ - INIT_ID(locale), \ INIT_ID(match), \ INIT_ID(metaclass), \ INIT_ID(mode), \ @@ -907,11 +883,9 @@ 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), \ @@ -941,20 +915,16 @@ extern "C" { INIT_ID(send), \ INIT_ID(setstate), \ INIT_ID(sort), \ - INIT_ID(st_mode), \ INIT_ID(stderr), \ INIT_ID(stdin), \ INIT_ID(stdout), \ INIT_ID(strict), \ - INIT_ID(struct_rusage), \ INIT_ID(symmetric_difference_update), \ INIT_ID(tell), \ INIT_ID(text), \ INIT_ID(threading), \ INIT_ID(throw), \ - INIT_ID(truncate), \ INIT_ID(unraisablehook), \ - INIT_ID(update), \ INIT_ID(values), \ INIT_ID(version), \ INIT_ID(warnings), \ diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index 8230852b2c0d7de..7d2024b47ffae4e 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -12,19 +12,10 @@ STRING_LITERALS = { 'empty': '', - 'newline': r'\n', 'dot': '.', 'comma_sep': ', ', 'percent': '%', 'dbl_percent': '%%', - 'replace_inf': '1eNN', - #'replace_inf': ['1', 'e', 1 + DBL_MAX_10_EXP] - - 'braces': None, - 'br_open': '{', - 'br_close': '}', - 'br_dbl_open': '{{', - 'br_dbl_close': '}}', '"anonymous" labels': None, 'anon_dictcomp': '', @@ -188,7 +179,6 @@ '__xor__', '_abc_impl', '_blksize', - '_bootstrap', '_dealloc_warn', '_finalizing', '_find_and_load', @@ -210,30 +200,22 @@ 'big', 'buffer', 'builtins', - 'c_call', - 'c_exception', - 'c_return', - 'call', 'clear', 'close', - 'closed', 'code', 'copy', 'copyreg', 'decode', - 'default', 'defaultaction', 'difference_update', 'dispatch_table', 'displayhook', 'enable', - 'encode', 'encoding', 'end_lineno', 'end_offset', 'errors', 'excepthook', - 'exception', 'extend', 'filename', 'fileno', @@ -244,14 +226,8 @@ 'get', 'get_source', 'getattr', - 'getpreferredencoding', - 'getstate', - 'ignore', - 'imp', 'importlib', - 'inf', 'intersection', - 'intersection_update', 'isatty', 'items', 'iter', @@ -260,10 +236,8 @@ 'last_type', 'last_value', 'latin1', - 'line', 'lineno', 'little', - 'locale', 'match', 'metaclass', 'mode', @@ -274,11 +248,9 @@ 'n_sequence_fields', 'n_unnamed_fields', 'name', - 'newlines', 'obj', 'offset', 'onceregistry', - 'opcode', 'open', 'parent', 'partial', @@ -308,20 +280,16 @@ 'send', 'setstate', 'sort', - 'st_mode', 'stderr', 'stdin', 'stdout', 'strict', - 'struct_rusage', 'symmetric_difference_update', 'tell', 'text', 'threading', 'throw', - 'truncate', 'unraisablehook', - 'update', 'values', 'version', 'warnings', From c6a292df1f90973c95d7952321e7359afc129efb Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 27 Jan 2022 17:46:07 -0700 Subject: [PATCH 093/115] Check the global objects in CI. --- .github/workflows/build.yml | 2 ++ Makefile.pre.in | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5d36dffa80108b4..376359ccf2e2d22 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -100,6 +100,8 @@ jobs: run: make smelly - name: Check limited ABI symbols run: make check-limited-abi + - name: Check global objects + run: make check-global-objects build_win32: name: 'Windows (x86)' diff --git a/Makefile.pre.in b/Makefile.pre.in index edc5fc3b6802f96..0d132c7a5ae2b7f 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -2435,6 +2435,9 @@ patchcheck: @DEF_MAKE_RULE@ check-limited-abi: all $(RUNSHARED) ./$(BUILDPYTHON) $(srcdir)/Tools/scripts/stable_abi.py --all $(srcdir)/Misc/stable_abi.txt +check-global-objects: all + $(RUNSHARED) ./$(BUILDPYTHON) $(srcdir)/Tools/scripts/generate_global_objects.py --check + .PHONY: update-config update-config: curl -sL -o config.guess 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD' From ffbd5153937c35961a370d888ce57862430e4ca6 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 31 Jan 2022 13:28:24 -0700 Subject: [PATCH 094/115] Fix _PyObject_CallMethod() for size_t. --- Include/abstract.h | 10 +++++----- Include/cpython/abstract.h | 6 ++++++ Objects/call.c | 28 ++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Include/abstract.h b/Include/abstract.h index 9e06fbbb749138f..d2908abf5eff3f7 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -137,7 +137,7 @@ extern "C" { #ifdef PY_SSIZE_T_CLEAN # define PyObject_CallFunction _PyObject_CallFunction_SizeT -# define PyObject_CallMethod _PyObject_CallMethod_SizeT +# define PyObject_CallMethod _PyObject_CallMethodString_SizeT #endif @@ -199,10 +199,10 @@ PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...); -PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj, - const char *name, - const char *format, - ...); +PyAPI_FUNC(PyObject *) _PyObject_CallMethodString_SizeT(PyObject *obj, + const char *name, + const char *format, + ...); /* Call a callable Python object 'callable' with a variable number of C arguments. The C arguments are provided as PyObject* values, terminated diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h index 3a688542ed6d028..1e284a6050c5bf4 100644 --- a/Include/cpython/abstract.h +++ b/Include/cpython/abstract.h @@ -5,6 +5,7 @@ /* === Object Protocol ================================================== */ #ifdef PY_SSIZE_T_CLEAN +# define _PyObject_CallMethod _PyObject_CallMethod_SizeT # define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT #endif @@ -126,6 +127,11 @@ PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name, const char *format, ...); +PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj, + PyObject *name, + const char *format, + ...); + PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *obj, _Py_Identifier *name, const char *format, diff --git a/Objects/call.c b/Objects/call.c index dffdfea65e3646c..4cd33574e67f5e5 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -717,8 +717,8 @@ PyObject * _PyObject_CallMethodFormat(PyThreadState *tstate, PyObject *callable, PyObject * -_PyObject_CallMethod_SizeT(PyObject *obj, const char *name, - const char *format, ...) +_PyObject_CallMethodString_SizeT(PyObject *obj, const char *name, + const char *format, ...) { PyThreadState *tstate = _PyThreadState_GET(); if (obj == NULL || name == NULL) { @@ -740,6 +740,30 @@ _PyObject_CallMethod_SizeT(PyObject *obj, const char *name, } +PyObject * +_PyObject_CallMethod_SizeT(PyObject *obj, PyObject *name, + const char *format, ...) +{ + PyThreadState *tstate = _PyThreadState_GET(); + if (obj == NULL || name == NULL) { + return null_error(tstate); + } + + PyObject *callable = PyObject_GetAttr(obj, name); + if (callable == NULL) { + return NULL; + } + + va_list va; + va_start(va, format); + PyObject *retval = callmethod(tstate, callable, format, va, 1); + va_end(va); + + Py_DECREF(callable); + return retval; +} + + PyObject * _PyObject_CallMethodId_SizeT(PyObject *obj, _Py_Identifier *name, const char *format, ...) From 878059b7a73b45fca00d21556ceff20768f33e32 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Mon, 31 Jan 2022 17:50:32 -0700 Subject: [PATCH 095/115] Dump the exception if normal printing fails. --- Python/pythonrun.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 1315e7b33564fa3..c9fffb788f6c53e 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1539,6 +1539,8 @@ _PyErr_Display(PyObject *file, PyObject *exception, PyObject *value, PyObject *t } if (print_exception_recursive(&ctx, value) < 0) { PyErr_Clear(); + _PyObject_Dump(value); + fprintf(stderr, "lost sys.stderr\n"); } Py_XDECREF(ctx.seen); From 780e61f81dc417f7064f791945636c3ee2670b32 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 1 Feb 2022 10:11:04 -0700 Subject: [PATCH 096/115] Regenerate test_frozenmain.h. --- Programs/test_frozenmain.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Programs/test_frozenmain.h b/Programs/test_frozenmain.h index 00f36ff9bd70fa9..01e046becd13b6b 100644 --- a/Programs/test_frozenmain.h +++ b/Programs/test_frozenmain.h @@ -21,7 +21,7 @@ unsigned char M_test_frozenmain[] = { 5,112,114,105,110,116,218,4,97,114,103,118,90,11,103,101, 116,95,99,111,110,102,105,103,115,114,2,0,0,0,218,3, 107,101,121,169,0,243,0,0,0,0,250,18,116,101,115,116, - 95,102,114,111,122,101,110,109,97,105,110,46,112,121,218,8, + 95,102,114,111,122,101,110,109,97,105,110,46,112,121,250,8, 60,109,111,100,117,108,101,62,114,11,0,0,0,1,0,0, 0,115,18,0,0,0,2,128,8,3,8,1,10,2,14,1, 14,1,8,1,28,7,4,249,115,20,0,0,0,2,128,8, From 876aa77c5da0d93b7c5038fbbd38f6953f37bf12 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 1 Feb 2022 10:21:25 -0700 Subject: [PATCH 097/115] Add some identifiers that are only used in non-debug builds. --- Include/internal/pycore_global_strings.h | 2 ++ Include/internal/pycore_runtime_init.h | 2 ++ Tools/scripts/generate_global_objects.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index a14732001da97e9..fc1119a056c89fd 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -224,6 +224,7 @@ struct _Py_global_strings { ID(copy) ID(copyreg) ID(decode) + ID(default) ID(defaultaction) ID(difference_update) ID(dispatch_table) @@ -244,6 +245,7 @@ struct _Py_global_strings { ID(get) ID(get_source) ID(getattr) + ID(ignore) ID(importlib) ID(intersection) ID(isatty) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 3d0b80a64a8abc4..72d6b7209cc9441 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -841,6 +841,7 @@ extern "C" { INIT_ID(copy), \ INIT_ID(copyreg), \ INIT_ID(decode), \ + INIT_ID(default), \ INIT_ID(defaultaction), \ INIT_ID(difference_update), \ INIT_ID(dispatch_table), \ @@ -861,6 +862,7 @@ extern "C" { INIT_ID(get), \ INIT_ID(get_source), \ INIT_ID(getattr), \ + INIT_ID(ignore), \ INIT_ID(importlib), \ INIT_ID(intersection), \ INIT_ID(isatty), \ diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index 7d2024b47ffae4e..80ba2dcfdf7c39e 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -206,6 +206,7 @@ 'copy', 'copyreg', 'decode', + 'default', 'defaultaction', 'difference_update', 'dispatch_table', @@ -226,6 +227,7 @@ 'get', 'get_source', 'getattr', + 'ignore', 'importlib', 'intersection', 'isatty', From f0bd78df26504117156fdb3ee0be18f7356b7633 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 1 Feb 2022 10:28:56 -0700 Subject: [PATCH 098/115] Drop _PyObject_CallMethod_SizeT(). --- Include/abstract.h | 10 +++++----- Include/cpython/abstract.h | 6 ------ Objects/call.c | 30 +++--------------------------- 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/Include/abstract.h b/Include/abstract.h index d2908abf5eff3f7..9e06fbbb749138f 100644 --- a/Include/abstract.h +++ b/Include/abstract.h @@ -137,7 +137,7 @@ extern "C" { #ifdef PY_SSIZE_T_CLEAN # define PyObject_CallFunction _PyObject_CallFunction_SizeT -# define PyObject_CallMethod _PyObject_CallMethodString_SizeT +# define PyObject_CallMethod _PyObject_CallMethod_SizeT #endif @@ -199,10 +199,10 @@ PyAPI_FUNC(PyObject *) _PyObject_CallFunction_SizeT(PyObject *callable, const char *format, ...); -PyAPI_FUNC(PyObject *) _PyObject_CallMethodString_SizeT(PyObject *obj, - const char *name, - const char *format, - ...); +PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj, + const char *name, + const char *format, + ...); /* Call a callable Python object 'callable' with a variable number of C arguments. The C arguments are provided as PyObject* values, terminated diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h index 1e284a6050c5bf4..3a688542ed6d028 100644 --- a/Include/cpython/abstract.h +++ b/Include/cpython/abstract.h @@ -5,7 +5,6 @@ /* === Object Protocol ================================================== */ #ifdef PY_SSIZE_T_CLEAN -# define _PyObject_CallMethod _PyObject_CallMethod_SizeT # define _PyObject_CallMethodId _PyObject_CallMethodId_SizeT #endif @@ -127,11 +126,6 @@ PyAPI_FUNC(PyObject *) _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name, const char *format, ...); -PyAPI_FUNC(PyObject *) _PyObject_CallMethod_SizeT(PyObject *obj, - PyObject *name, - const char *format, - ...); - PyAPI_FUNC(PyObject *) _PyObject_CallMethodId_SizeT(PyObject *obj, _Py_Identifier *name, const char *format, diff --git a/Objects/call.c b/Objects/call.c index 4cd33574e67f5e5..c3939ea0d07da19 100644 --- a/Objects/call.c +++ b/Objects/call.c @@ -673,7 +673,7 @@ _PyObject_CallMethod(PyObject *obj, PyObject *name, va_list va; va_start(va, format); - PyObject *retval = callmethod(tstate, callable, format, va, 0); + PyObject *retval = callmethod(tstate, callable, format, va, 1); va_end(va); Py_DECREF(callable); @@ -717,31 +717,7 @@ PyObject * _PyObject_CallMethodFormat(PyThreadState *tstate, PyObject *callable, PyObject * -_PyObject_CallMethodString_SizeT(PyObject *obj, const char *name, - const char *format, ...) -{ - PyThreadState *tstate = _PyThreadState_GET(); - if (obj == NULL || name == NULL) { - return null_error(tstate); - } - - PyObject *callable = PyObject_GetAttrString(obj, name); - if (callable == NULL) { - return NULL; - } - - va_list va; - va_start(va, format); - PyObject *retval = callmethod(tstate, callable, format, va, 1); - va_end(va); - - Py_DECREF(callable); - return retval; -} - - -PyObject * -_PyObject_CallMethod_SizeT(PyObject *obj, PyObject *name, +_PyObject_CallMethod_SizeT(PyObject *obj, const char *name, const char *format, ...) { PyThreadState *tstate = _PyThreadState_GET(); @@ -749,7 +725,7 @@ _PyObject_CallMethod_SizeT(PyObject *obj, PyObject *name, return null_error(tstate); } - PyObject *callable = PyObject_GetAttr(obj, name); + PyObject *callable = PyObject_GetAttrString(obj, name); if (callable == NULL) { return NULL; } From db92384bc64ed5e096ce9428f8177caf17ffa2f0 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 1 Feb 2022 13:29:56 -0700 Subject: [PATCH 099/115] Cast to void* before casting to uint64_t. --- Include/internal/pycore_object.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index b69fe3f07a306e2..14f20eb2f1ac247 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -29,10 +29,18 @@ extern "C" { static inline bool _PyObject_IsSingleton(PyObject *obj) { -#define SINGLETONS (&_PyRuntime.global_objects.singletons) - if (((uintptr_t)obj >= (uintptr_t)(SINGLETONS)) && - ((uintptr_t)obj < (uintptr_t)((SINGLETONS) + 1))) { -#undef SINGLETONS + /* The _PyRuntimeState global objects are all singletons so we can + check if the object is in the address range of the relevant + substruct. Per the C99 spec (6.5.8 and 7.18.1.4), this is safe + only if we convert to void* and then uint64_t before comparing. + For that conversion we rely on the same uniqueness guarantees + that the builtin id() does. + */ + if (((uintptr_t)(void *)obj >= + (uintptr_t)(void *)(&_PyRuntime.global_objects.singletons)) && + ((uintptr_t)(void *)obj < + (uintptr_t)(void *)((&_PyRuntime.global_objects.singletons) + 1))) + { return true; } return false; From 955d26a90c1a2beb99e74e143ac5b5fd7b5ebfa0 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 1 Feb 2022 14:10:45 -0700 Subject: [PATCH 100/115] Explicitly mark each module that still uses _Py_IDENTIFIER(). --- Include/cpython/object.h | 4 ++-- Modules/_asynciomodule.c | 1 + Modules/_bisectmodule.c | 1 + Modules/_csv.c | 2 ++ Modules/_ctypes/_ctypes.c | 1 + Modules/_ctypes/callbacks.c | 1 + Modules/_ctypes/callproc.c | 2 ++ Modules/_ctypes/stgdict.c | 1 + Modules/_cursesmodule.c | 1 + Modules/_datetimemodule.c | 1 + Modules/_dbmmodule.c | 1 + Modules/_elementtree.c | 1 + Modules/_gdbmmodule.c | 1 + Modules/_json.c | 1 + Modules/_lzmamodule.c | 1 + Modules/_sqlite/connection.c | 2 ++ Modules/_sqlite/cursor.c | 2 ++ Modules/_sqlite/microprotocols.c | 2 ++ Modules/_sqlite/module.c | 2 ++ Modules/_ssl.c | 1 + Modules/_testcapimodule.c | 1 + Modules/arraymodule.c | 1 + Modules/cjkcodecs/multibytecodec.c | 1 + Modules/mathmodule.c | 1 + Modules/mmapmodule.c | 1 + Modules/ossaudiodev.c | 1 + Modules/pyexpat.c | 2 ++ Modules/unicodedata.c | 1 + 28 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index 0f77ebe97de1ba0..bf10c7a4f202767 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -41,7 +41,7 @@ typedef struct _Py_Identifier { Py_ssize_t index; } _Py_Identifier; -#if !defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE) +#if defined(NEEDS_PY_IDENTIFIER) || !defined(Py_BUILD_CORE) // For now we are keeping _Py_IDENTIFIER for continued use // in non-builtin extensions (and naughty PyPI modules). @@ -49,7 +49,7 @@ typedef struct _Py_Identifier { #define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value) #define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname) -#endif /* ! Py_BUILD_CORE */ +#endif /* NEEDS_PY_IDENTIFIER */ /* buffer interface */ typedef struct bufferinfo { diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index 2216dd0178173ac..72dbdb8902f1214 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -1,6 +1,7 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #include "Python.h" #include "pycore_pyerrors.h" // _PyErr_ClearExcState() diff --git a/Modules/_bisectmodule.c b/Modules/_bisectmodule.c index 26c4b9bfb26b22f..f884d94413c0d7d 100644 --- a/Modules/_bisectmodule.c +++ b/Modules/_bisectmodule.c @@ -4,6 +4,7 @@ Converted to C by Dmitry Vasiliev (dima at hlabs.spb.ru). */ #define PY_SSIZE_T_CLEAN +#define NEEDS_PY_IDENTIFIER #include "Python.h" /*[clinic input] diff --git a/Modules/_csv.c b/Modules/_csv.c index 1c2f504ea5c097f..d2cb77f9f033478 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -10,6 +10,8 @@ module instead. #define MODULE_VERSION "1.0" +#define NEEDS_PY_IDENTIFIER + #include "Python.h" #include "structmember.h" // PyMemberDef #include diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 96078c7726d597a..8a71b76128a0541 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -101,6 +101,7 @@ bytes(cdata) #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #define PY_SSIZE_T_CLEAN diff --git a/Modules/_ctypes/callbacks.c b/Modules/_ctypes/callbacks.c index 01d703745bc6065..36d7dd8bc521ef0 100644 --- a/Modules/_ctypes/callbacks.c +++ b/Modules/_ctypes/callbacks.c @@ -1,6 +1,7 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #include "Python.h" // windows.h must be included before pycore internal headers diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index e2204961070dbfa..edf7b5973c1f07b 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -54,6 +54,8 @@ */ +#define NEEDS_PY_IDENTIFIER + #include "Python.h" #include "structmember.h" // PyMemberDef diff --git a/Modules/_ctypes/stgdict.c b/Modules/_ctypes/stgdict.c index 6c1917b18d45099..4b21393f9301398 100644 --- a/Modules/_ctypes/stgdict.c +++ b/Modules/_ctypes/stgdict.c @@ -1,6 +1,7 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #include "Python.h" // windows.h must be included before pycore internal headers diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index 423b042b90755a6..7e2699e1b5c5bbe 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -103,6 +103,7 @@ static const char PyCursesVersion[] = "2.2"; #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #define PY_SSIZE_T_CLEAN diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index fda8401b84cd154..ae97190bccbde09 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -10,6 +10,7 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #include "Python.h" #include "pycore_long.h" // _PyLong_GetOne() diff --git a/Modules/_dbmmodule.c b/Modules/_dbmmodule.c index c0371fb3f3b2088..65778fa77bfec5d 100644 --- a/Modules/_dbmmodule.c +++ b/Modules/_dbmmodule.c @@ -3,6 +3,7 @@ #define PY_SSIZE_T_CLEAN +#define NEEDS_PY_IDENTIFIER #include "Python.h" #include diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 9dadeef71293843..f155dc72152d4cd 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -12,6 +12,7 @@ */ #define PY_SSIZE_T_CLEAN +#define NEEDS_PY_IDENTIFIER #include "Python.h" #include "structmember.h" // PyMemberDef diff --git a/Modules/_gdbmmodule.c b/Modules/_gdbmmodule.c index 445500c7ee4c157..2d690c0abfd0886 100644 --- a/Modules/_gdbmmodule.c +++ b/Modules/_gdbmmodule.c @@ -4,6 +4,7 @@ /* Doc strings: Mitch Chapman */ #define PY_SSIZE_T_CLEAN +#define NEEDS_PY_IDENTIFIER #include "Python.h" #include "gdbm.h" diff --git a/Modules/_json.c b/Modules/_json.c index 1c9c50665d466c1..f7a3e38de992618 100644 --- a/Modules/_json.c +++ b/Modules/_json.c @@ -7,6 +7,7 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #include "Python.h" #include "structmember.h" // PyMemberDef diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c index e50f55b75c5dc5b..e3fc90e5175eb5e 100644 --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -6,6 +6,7 @@ */ #define PY_SSIZE_T_CLEAN +#define NEEDS_PY_IDENTIFIER #include "Python.h" #include "structmember.h" // PyMemberDef diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index caefdf483a0df74..cb8cd2a3d1807cc 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -21,6 +21,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ +#define NEEDS_PY_IDENTIFIER + #include "module.h" #include "structmember.h" // PyMemberDef #include "connection.h" diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 4700afbbf11881b..395b10f33ff3a57 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -21,6 +21,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ +#define NEEDS_PY_IDENTIFIER + #include "cursor.h" #include "module.h" #include "util.h" diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c index 95c799d306f308a..697d1a788a3b01a 100644 --- a/Modules/_sqlite/microprotocols.c +++ b/Modules/_sqlite/microprotocols.c @@ -23,6 +23,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ +#define NEEDS_PY_IDENTIFIER + #include #include "cursor.h" diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c index 3b9f79799b5c590..cfa4b970e73206f 100644 --- a/Modules/_sqlite/module.c +++ b/Modules/_sqlite/module.c @@ -21,6 +21,8 @@ * 3. This notice may not be removed or altered from any source distribution. */ +#define NEEDS_PY_IDENTIFIER + #include "connection.h" #include "statement.h" #include "cursor.h" diff --git a/Modules/_ssl.c b/Modules/_ssl.c index b2e241a0a338eb7..5a9879ecbe3eaf1 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -22,6 +22,7 @@ #define OPENSSL_NO_DEPRECATED 1 #define PY_SSIZE_T_CLEAN +#define NEEDS_PY_IDENTIFIER #include "Python.h" diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 5582890be268f91..465a3e525314001 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -13,6 +13,7 @@ #undef Py_BUILD_CORE_MODULE #undef Py_BUILD_CORE_BUILTIN +#define NEEDS_PY_IDENTIFIER /* Always enable assertions */ #undef NDEBUG diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 8e430632813e6be..4aaab0c531435ee 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -6,6 +6,7 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #define PY_SSIZE_T_CLEAN #include "Python.h" diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index ba558d0dbf2f1dc..df48a0deec7e966 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -5,6 +5,7 @@ */ #define PY_SSIZE_T_CLEAN +#define NEEDS_PY_IDENTIFIER #include "Python.h" #include "structmember.h" // PyMemberDef #include "multibytecodec.h" diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 9b5c0619f7a6f16..721c9a63d51b297 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -55,6 +55,7 @@ raised for division by zero and mod by zero. #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #include "Python.h" #include "pycore_bitutils.h" // _Py_bit_length() diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 7c9c28f7fab59a4..0a216941d024871 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -21,6 +21,7 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #define PY_SSIZE_T_CLEAN #include diff --git a/Modules/ossaudiodev.c b/Modules/ossaudiodev.c index c9e788fd70457fc..172a6e42975310c 100644 --- a/Modules/ossaudiodev.c +++ b/Modules/ossaudiodev.c @@ -20,6 +20,7 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #define PY_SSIZE_T_CLEAN #include "Python.h" diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index f2baab757f90c29..f224f91f38fc3c5 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -1,3 +1,5 @@ +#define NEEDS_PY_IDENTIFIER + #include "Python.h" #include diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c index bdbddcf10b778fb..7369db53d2e0bfd 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -15,6 +15,7 @@ #ifndef Py_BUILD_CORE_BUILTIN # define Py_BUILD_CORE_MODULE 1 #endif +#define NEEDS_PY_IDENTIFIER #define PY_SSIZE_T_CLEAN From 3c66484761dc5abd4b96afb7617292421f39501a Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 1 Feb 2022 14:27:31 -0700 Subject: [PATCH 101/115] _testembed still uses _Py_IDENTIFIER(). --- Programs/_testembed.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 08e27d97723b35a..3830dc3f8b6ec70 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1,6 +1,7 @@ #ifndef Py_BUILD_CORE_MODULE # define Py_BUILD_CORE_MODULE #endif +#define NEEDS_PY_IDENTIFIER /* Always enable assertion (even in release mode) */ #undef NDEBUG From 05fd0348cc46904ebe72de69f9dda26e4b13f280 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Tue, 1 Feb 2022 15:19:05 -0700 Subject: [PATCH 102/115] Fix name collisions from Windows. --- Modules/_pickle.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 653d434eaa9f42c..ea8989701b031e3 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -37,6 +37,13 @@ enum { DEFAULT_PROTOCOL = 4 }; +#ifdef MS_WINDOWS +// These are already typedefs from windows.h, pulled in via pycore_runtime.h. +#define FLOAT FLOAT_ +#define INT INT_ +#define LONG LONG_ +#endif + /* Pickle opcodes. These must be kept updated with pickle.py. Extensive docs are in pickletools.py. */ enum opcode { From 78482cfa87497bd09f085018bbdddff4a4295043 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 10:54:48 -0700 Subject: [PATCH 103/115] _Py_GET_GLOBAL_IDENTIFIER() -> _Py_ID(). --- Include/internal/pycore_global_strings.h | 2 +- Modules/_abc.c | 20 +-- Modules/_collectionsmodule.c | 12 +- Modules/_io/_iomodule.c | 8 +- Modules/_io/bufferedio.c | 38 ++--- Modules/_io/fileio.c | 6 +- Modules/_io/iobase.c | 16 +- Modules/_io/textio.c | 74 ++++----- Modules/_io/winconsoleio.c | 4 +- Modules/_operator.c | 4 +- Modules/_pickle.c | 66 ++++---- Modules/_threadmodule.c | 10 +- Modules/faulthandler.c | 8 +- Modules/itertoolsmodule.c | 8 +- Modules/main.c | 2 +- Modules/posixmodule.c | 4 +- Modules/timemodule.c | 4 +- Objects/abstract.c | 24 +-- Objects/bytearrayobject.c | 4 +- Objects/bytesobject.c | 6 +- Objects/classobject.c | 10 +- Objects/complexobject.c | 2 +- Objects/descrobject.c | 20 +-- Objects/dictobject.c | 14 +- Objects/enumobject.c | 2 +- Objects/exceptions.c | 4 +- Objects/fileobject.c | 10 +- Objects/frameobject.c | 2 +- Objects/funcobject.c | 4 +- Objects/genericaliasobject.c | 12 +- Objects/genobject.c | 4 +- Objects/iterobject.c | 4 +- Objects/listobject.c | 6 +- Objects/longobject.c | 8 +- Objects/methodobject.c | 4 +- Objects/moduleobject.c | 38 ++--- Objects/object.c | 20 +-- Objects/odictobject.c | 12 +- Objects/rangeobject.c | 4 +- Objects/setobject.c | 4 +- Objects/structseq.c | 6 +- Objects/tupleobject.c | 2 +- Objects/typeobject.c | 200 +++++++++++------------ Objects/unicodeobject.c | 2 +- Objects/unionobject.c | 8 +- Objects/weakrefobject.c | 4 +- Parser/tokenizer.c | 4 +- Python/_warnings.c | 24 +-- Python/bltinmodule.c | 34 ++-- Python/ceval.c | 38 ++--- Python/codecs.c | 2 +- Python/compile.c | 8 +- Python/errors.c | 30 ++-- Python/import.c | 38 ++--- Python/importdl.c | 2 +- Python/marshal.c | 6 +- Python/pylifecycle.c | 36 ++-- Python/pythonrun.c | 60 +++---- Python/specialize.c | 10 +- Python/sysmodule.c | 40 ++--- Python/traceback.c | 10 +- Tools/scripts/generate_global_objects.py | 2 +- 62 files changed, 535 insertions(+), 535 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index fc1119a056c89fd..cab9a2531ccf1cd 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -325,7 +325,7 @@ struct _Py_global_strings { #undef STR -#define _Py_GET_GLOBAL_IDENTIFIER(NAME) \ +#define _Py_ID(NAME) \ (&_Py_SINGLETON(strings.identifiers.spamspamspam_ ## NAME._ascii.ob_base)) #define _Py_GET_GLOBAL_STRING(NAME) \ (&_Py_SINGLETON(strings.literals.spamspamspam_ ## NAME._ascii.ob_base)) diff --git a/Modules/_abc.c b/Modules/_abc.c index bc7c73cce8a83a2..db64961aa49fd97 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -6,7 +6,7 @@ #include "Python.h" #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_object.h" // _PyType_GetSubclasses() -#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() +#include "pycore_runtime.h" // _Py_ID() #include "clinic/_abc.c.h" /*[clinic input] @@ -114,7 +114,7 @@ static _abc_data * _get_impl(PyObject *module, PyObject *self) { _abcmodule_state *state = get_abc_state(module); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_abc_impl); + PyObject *attr = _Py_ID(_abc_impl); PyObject *impl = PyObject_GetAttr(self, attr); if (impl == NULL) { return NULL; @@ -304,7 +304,7 @@ compute_abstract_methods(PyObject *self) PyObject *ns = NULL, *items = NULL, *bases = NULL; // Py_XDECREF()ed on error. /* Stage 1: direct abstract methods. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); ns = PyObject_GetAttr(self, attr); if (!ns) { goto error; @@ -349,7 +349,7 @@ compute_abstract_methods(PyObject *self) } /* Stage 2: inherited abstract methods. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(__bases__); + attr = _Py_ID(__bases__); bases = PyObject_GetAttr(self, attr); if (!bases) { goto error; @@ -359,7 +359,7 @@ compute_abstract_methods(PyObject *self) goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__abstractmethods__); + attr = _Py_ID(__abstractmethods__); for (Py_ssize_t pos = 0; pos < PyTuple_GET_SIZE(bases); pos++) { PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed PyObject *base_abstracts, *iter; @@ -443,7 +443,7 @@ _abc__abc_init(PyObject *module, PyObject *self) if (data == NULL) { return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_abc_impl); + PyObject *attr = _Py_ID(_abc_impl); if (PyObject_SetAttr(self, attr, data) < 0) { Py_DECREF(data); return NULL; @@ -455,7 +455,7 @@ _abc__abc_init(PyObject *module, PyObject *self) * their special status w.r.t. pattern matching. */ if (PyType_Check(self)) { PyTypeObject *cls = (PyTypeObject *)self; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__abc_tpflags__); + PyObject *attr = _Py_ID(__abc_tpflags__); PyObject *flags = PyDict_GetItemWithError(cls->tp_dict, attr); if (flags == NULL) { if (PyErr_Occurred()) { @@ -590,7 +590,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + PyObject *attr = _Py_ID(__class__); subclass = PyObject_GetAttr(instance, attr); if (subclass == NULL) { Py_DECREF(impl); @@ -607,7 +607,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, goto end; } subtype = (PyObject *)Py_TYPE(instance); - attr = _Py_GET_GLOBAL_IDENTIFIER(__subclasscheck__); + attr = _Py_ID(__subclasscheck__); if (subtype == subclass) { if (impl->_abc_negative_cache_version == get_abc_state(module)->abc_invalidation_counter) { incache = _in_weak_set(impl->_abc_negative_cache, subclass); @@ -719,7 +719,7 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self, } /* 3. Check the subclass hook. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__subclasshook__); + PyObject *attr = _Py_ID(__subclasshook__); ok = PyObject_CallMethodOneArg((PyObject *)self, attr, subclass); if (ok == NULL) { goto end; diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 75e534b576ea46d..ccc0f6c85439ed7 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1349,7 +1349,7 @@ deque_reduce(dequeobject *deque, PyObject *Py_UNUSED(ignored)) { PyObject *dict, *it; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); if (_PyObject_LookupAttr((PyObject *)deque, attr, &dict) < 0) { return NULL; } @@ -2071,7 +2071,7 @@ defdict_reduce(defdictobject *dd, PyObject *Py_UNUSED(ignored)) args = PyTuple_Pack(1, dd->default_factory); if (args == NULL) return NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *attr = _Py_ID(items); items = PyObject_CallMethodNoArgs((PyObject *)dd, attr); if (items == NULL) { Py_DECREF(args); @@ -2327,12 +2327,12 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping, /* Only take the fast path when get() and __setitem__() * have not been overridden. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(get); + PyObject *attr = _Py_ID(get); mapping_get = _PyType_Lookup(Py_TYPE(mapping), attr); dict_get = _PyType_Lookup(&PyDict_Type, attr); - attr = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + attr = _Py_ID(__setitem__); mapping_setitem = _PyType_Lookup(Py_TYPE(mapping), attr); - attr = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + attr = _Py_ID(__setitem__); dict_setitem = _PyType_Lookup(&PyDict_Type, attr); if (mapping_get != NULL && mapping_get == dict_get && @@ -2382,7 +2382,7 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping, } } else { - attr = _Py_GET_GLOBAL_IDENTIFIER(get); + attr = _Py_ID(get); bound_get = PyObject_GetAttr(mapping, attr); if (bound_get == NULL) goto done; diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 4ae78721de3e327..42257b0ed5bf60a 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -377,7 +377,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, /* buffering */ if (buffering < 0) { - attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + attr = _Py_ID(isatty); PyObject *res = PyObject_CallMethodNoArgs(raw, attr); if (res == NULL) goto error; @@ -396,7 +396,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, if (buffering < 0) { PyObject *blksize_obj; - attr = _Py_GET_GLOBAL_IDENTIFIER(_blksize); + attr = _Py_ID(_blksize); blksize_obj = PyObject_GetAttr(raw, attr); if (blksize_obj == NULL) goto error; @@ -464,7 +464,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, result = wrapper; Py_DECREF(buffer); - attr = _Py_GET_GLOBAL_IDENTIFIER(mode); + attr = _Py_ID(mode); if (PyObject_SetAttr(wrapper, attr, modeobj) < 0) goto error; Py_DECREF(modeobj); @@ -474,7 +474,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, if (result != NULL) { PyObject *exc, *val, *tb, *close_result; PyErr_Fetch(&exc, &val, &tb); - attr = _Py_GET_GLOBAL_IDENTIFIER(close); + attr = _Py_ID(close); close_result = PyObject_CallMethodNoArgs(result, attr); _PyErr_ChainExceptions(exc, val, tb); Py_XDECREF(close_result); diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 5457d294f85e28f..4b1e6a4ee693e2c 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -51,8 +51,8 @@ _bufferediobase_readinto_generic(PyObject *self, Py_buffer *buffer, char readint PyObject *data; PyObject *attr = readinto1 - ? _Py_GET_GLOBAL_IDENTIFIER(read1) - : _Py_GET_GLOBAL_IDENTIFIER(read); + ? _Py_ID(read1) + : _Py_ID(read); data = _PyObject_CallMethod(self, attr, "n", buffer->len); if (data == NULL) return NULL; @@ -422,7 +422,7 @@ buffered_dealloc_warn(buffered *self, PyObject *source) { if (self->ok && self->raw) { PyObject *r; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_dealloc_warn); + PyObject *attr = _Py_ID(_dealloc_warn); r = PyObject_CallMethodOneArg(self->raw, attr, source); if (r) Py_DECREF(r); @@ -569,7 +569,7 @@ static PyObject * buffered_name_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); return PyObject_GetAttr(self->raw, attr); } @@ -577,7 +577,7 @@ static PyObject * buffered_mode_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(mode); + PyObject *attr = _Py_ID(mode); return PyObject_GetAttr(self->raw, attr); } @@ -1369,7 +1369,7 @@ buffered_repr(buffered *self) { PyObject *nameobj, *res; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) { if (!PyErr_ExceptionMatches(PyExc_ValueError)) { return NULL; @@ -2165,63 +2165,63 @@ _forward_call(buffered *self, PyObject *name, PyObject *args) static PyObject * bufferedrwpair_read(rwpair *self, PyObject *args) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read); + PyObject *attr = _Py_ID(read); return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_peek(rwpair *self, PyObject *args) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(peek); + PyObject *attr = _Py_ID(peek); return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_read1(rwpair *self, PyObject *args) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read1); + PyObject *attr = _Py_ID(read1); return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_readinto(rwpair *self, PyObject *args) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readinto); + PyObject *attr = _Py_ID(readinto); return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_readinto1(rwpair *self, PyObject *args) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readinto1); + PyObject *attr = _Py_ID(readinto1); return _forward_call(self->reader, attr, args); } static PyObject * bufferedrwpair_write(rwpair *self, PyObject *args) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(write); + PyObject *attr = _Py_ID(write); return _forward_call(self->writer, attr, args); } static PyObject * bufferedrwpair_flush(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *attr = _Py_ID(flush); return _forward_call(self->writer, attr, NULL); } static PyObject * bufferedrwpair_readable(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readable); + PyObject *attr = _Py_ID(readable); return _forward_call(self->reader, attr, NULL); } static PyObject * bufferedrwpair_writable(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(writable); + PyObject *attr = _Py_ID(writable); return _forward_call(self->writer, attr, NULL); } @@ -2229,13 +2229,13 @@ static PyObject * bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored)) { PyObject *exc = NULL, *val, *tb; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(close); + PyObject *attr = _Py_ID(close); PyObject *ret = _forward_call(self->writer, attr, NULL); if (ret == NULL) PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(ret); - attr = _Py_GET_GLOBAL_IDENTIFIER(close); + attr = _Py_ID(close); ret = _forward_call(self->reader, attr, NULL); if (exc != NULL) { _PyErr_ChainExceptions(exc, val, tb); @@ -2247,7 +2247,7 @@ bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored)) static PyObject * bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + PyObject *attr = _Py_ID(isatty); PyObject *ret = _forward_call(self->writer, attr, NULL); if (ret != Py_False) { @@ -2256,7 +2256,7 @@ bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored)) } Py_DECREF(ret); - attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + attr = _Py_ID(isatty); return _forward_call(self->reader, attr, NULL); } diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 16994b7bdf7d708..45fc7d5147ca8d8 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -144,7 +144,7 @@ _io_FileIO_close_impl(fileio *self) PyObject *res; PyObject *exc, *val, *tb; int rc; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(close); + PyObject *attr = _Py_ID(close); res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type, attr, (PyObject *)self); if (!self->closefd) { @@ -474,7 +474,7 @@ _Py_COMP_DIAG_POP _setmode(self->fd, O_BINARY); #endif - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); if (PyObject_SetAttr((PyObject *)self, attr, nameobj) < 0) goto error; @@ -1084,7 +1084,7 @@ fileio_repr(fileio *self) if (self->fd < 0) return PyUnicode_FromFormat("<_io.FileIO [closed]>"); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) { return NULL; } diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 84498d316f76bfd..553da75db04afcc 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -111,7 +111,7 @@ static PyObject * _io__IOBase_tell_impl(PyObject *self) /*[clinic end generated code: output=89a1c0807935abe2 input=04e615fec128801f]*/ { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(seek); + PyObject *attr = _Py_ID(seek); return _PyObject_CallMethod(self, attr, "ii", 0, 1); } @@ -134,7 +134,7 @@ iobase_is_closed(PyObject *self) int ret; /* This gets the derived attribute, which is *not* __IOBase_closed in most cases! */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__IOBase_closed); + PyObject *attr = _Py_ID(__IOBase_closed); ret = _PyObject_LookupAttr(self, attr, &res); Py_XDECREF(res); return ret; @@ -236,7 +236,7 @@ _io__IOBase_close_impl(PyObject *self) res = PyObject_CallMethodNoArgs(self, _PyIO_str_flush); PyErr_Fetch(&exc, &val, &tb); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__IOBase_closed); + PyObject *attr = _Py_ID(__IOBase_closed); rc = PyObject_SetAttr(self, attr, Py_True); _PyErr_ChainExceptions(exc, val, tb); if (rc < 0) { @@ -277,7 +277,7 @@ iobase_finalize(PyObject *self) if (closed == 0) { /* Signal close() that it was called as part of the object finalization process. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_finalizing); + PyObject *attr = _Py_ID(_finalizing); if (PyObject_SetAttr(self, attr, Py_True)) PyErr_Clear(); res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_close); @@ -550,7 +550,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit) return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read); + PyObject *attr = _Py_ID(read); while (limit < 0 || PyByteArray_GET_SIZE(buffer) < limit) { Py_ssize_t nreadahead = 1; PyObject *b; @@ -696,7 +696,7 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint) /* XXX special-casing this made sense in the Python version in order to remove the bytecode interpretation overhead, but it could probably be removed here. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(extend); + PyObject *attr = _Py_ID(extend); PyObject *ret = PyObject_CallMethodObjArgs(result, attr, self, NULL); if (ret == NULL) { @@ -917,7 +917,7 @@ _io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n) PyObject *b, *res; if (n < 0) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readall); + PyObject *attr = _Py_ID(readall); return PyObject_CallMethodNoArgs(self, attr); } @@ -964,7 +964,7 @@ _io__RawIOBase_readall_impl(PyObject *self) return NULL; while (1) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read); + PyObject *attr = _Py_ID(read); PyObject *data = _PyObject_CallMethod(self, attr, "i", DEFAULT_BUFFER_SIZE); if (!data) { diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index d3021355e2cc62a..2c9289b8943ec14 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -235,7 +235,7 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self, Py_INCREF(decoder); if (errors == NULL) { - self->errors = _Py_GET_GLOBAL_IDENTIFIER(strict); + self->errors = _Py_ID(strict); } else { self->errors = errors; @@ -565,7 +565,7 @@ _io_IncrementalNewlineDecoder_setstate(nldecoder_object *self, flag >>= 1; if (self->decoder != Py_None) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(setstate); + PyObject *attr = _Py_ID(setstate); return _PyObject_CallMethod(self->decoder, attr, "((OK))", buffer, flag); } @@ -846,7 +846,7 @@ _textiowrapper_set_decoder(textio *self, PyObject *codec_info, PyObject *res; int r; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readable); + PyObject *attr = _Py_ID(readable); res = PyObject_CallMethodNoArgs(self->buffer, attr); if (res == NULL) return -1; @@ -902,7 +902,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info, PyObject *res; int r; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(writable); + PyObject *attr = _Py_ID(writable); res = PyObject_CallMethodNoArgs(self->buffer, attr); if (res == NULL) return -1; @@ -922,7 +922,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info, return -1; /* Get the normalized named of the codec */ - attr = _Py_GET_GLOBAL_IDENTIFIER(name); + attr = _Py_ID(name); if (_PyObject_LookupAttr(codec_info, attr, &res) < 0) { return -1; } @@ -1083,7 +1083,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, } if (errors == Py_None) { - errors = _Py_GET_GLOBAL_IDENTIFIER(strict); + errors = _Py_ID(strict); } else if (!PyUnicode_Check(errors)) { // Check 'errors' argument here because Argument Clinic doesn't support @@ -1123,7 +1123,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, state = IO_STATE(); if (state == NULL) goto error; - attr = _Py_GET_GLOBAL_IDENTIFIER(fileno); + attr = _Py_ID(fileno); fileno = PyObject_CallMethodNoArgs(buffer, attr); /* Ignore only AttributeError and UnsupportedOperation */ if (fileno == NULL) { @@ -1210,7 +1210,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, Py_IS_TYPE(buffer, &PyBufferedWriter_Type) || Py_IS_TYPE(buffer, &PyBufferedRandom_Type)) { - attr = _Py_GET_GLOBAL_IDENTIFIER(raw); + attr = _Py_ID(raw); if (_PyObject_LookupAttr(buffer, attr, &raw) < 0) goto error; /* Cache the raw FileIO object to speed up 'closed' checks */ @@ -1222,7 +1222,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, } } - attr = _Py_GET_GLOBAL_IDENTIFIER(seekable); + attr = _Py_ID(seekable); res = PyObject_CallMethodNoArgs(buffer, attr); if (res == NULL) goto error; @@ -1286,7 +1286,7 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding, } } else if (errors == Py_None) { - errors = _Py_GET_GLOBAL_IDENTIFIER(strict); + errors = _Py_ID(strict); } const char *c_errors = PyUnicode_AsUTF8(errors); @@ -1621,7 +1621,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) haslf = 1; if (haslf && self->writetranslate && self->writenl != NULL) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(replace); + PyObject *attr = _Py_ID(replace); PyObject *newtext = _PyObject_CallMethod(text, attr , "ss", "\n", self->writenl); Py_DECREF(text); @@ -1722,7 +1722,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) Py_CLEAR(self->snapshot); if (self->decoder) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(reset); + PyObject *attr = _Py_ID(reset); ret = PyObject_CallMethodNoArgs(self->decoder, attr); if (ret == NULL) return NULL; @@ -1927,7 +1927,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n) if (n < 0) { /* Read everything */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(read); + PyObject *attr = _Py_ID(read); PyObject *bytes = PyObject_CallMethodNoArgs(self->buffer, attr); PyObject *decoded; if (bytes == NULL) @@ -2392,7 +2392,7 @@ _textiowrapper_decoder_setstate(textio *self, cookie_type *cookie) res = PyObject_CallMethodNoArgs(self->decoder, _PyIO_str_reset); } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(setstate); + PyObject *attr = _Py_ID(setstate); res = _PyObject_CallMethod(self->decoder, attr, "((yi))", "", cookie->dec_flags); } @@ -2475,7 +2475,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) * sync the underlying buffer with the current position. */ Py_DECREF(cookieObj); - attr = _Py_GET_GLOBAL_IDENTIFIER(tell); + attr = _Py_ID(tell); cookieObj = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (cookieObj == NULL) goto fail; @@ -2492,7 +2492,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) goto fail; } - attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + attr = _Py_ID(flush); res = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (res == NULL) goto fail; @@ -2501,14 +2501,14 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) textiowrapper_set_decoded_chars(self, NULL); Py_CLEAR(self->snapshot); if (self->decoder) { - attr = _Py_GET_GLOBAL_IDENTIFIER(reset); + attr = _Py_ID(reset); res = PyObject_CallMethodNoArgs(self->decoder, attr); if (res == NULL) goto fail; Py_DECREF(res); } - attr = _Py_GET_GLOBAL_IDENTIFIER(seek); + attr = _Py_ID(seek); res = _PyObject_CallMethod(self->buffer, attr, "ii", 0, 2); Py_CLEAR(cookieObj); if (res == NULL) @@ -2575,7 +2575,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) if (cookie.chars_to_skip) { /* Just like _read_chunk, feed the decoder and save a snapshot. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(read); + attr = _Py_ID(read); PyObject *input_chunk = _PyObject_CallMethod(self->buffer, attr, "i", cookie.bytes_to_feed); PyObject *decoded; @@ -2598,7 +2598,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) } Py_XSETREF(self->snapshot, snapshot); - attr = _Py_GET_GLOBAL_IDENTIFIER(decode); + attr = _Py_ID(decode); decoded = PyObject_CallMethodObjArgs(self->decoder, attr, input_chunk, cookie.need_eof ? Py_True : Py_False, NULL); @@ -2667,13 +2667,13 @@ _io_TextIOWrapper_tell_impl(textio *self) if (_textiowrapper_writeflush(self) < 0) return NULL; - attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + attr = _Py_ID(flush); res = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (res == NULL) goto fail; Py_DECREF(res); - attr = _Py_GET_GLOBAL_IDENTIFIER(tell); + attr = _Py_ID(tell); posobj = PyObject_CallMethodNoArgs(self->buffer, attr); if (posobj == NULL) goto fail; @@ -2754,7 +2754,7 @@ _io_TextIOWrapper_tell_impl(textio *self) Py_DECREF(_decoded); \ } while (0) - attr = _Py_GET_GLOBAL_IDENTIFIER(decode); + attr = _Py_ID(decode); /* Fast search for an acceptable start point, close to our current pos */ @@ -2846,7 +2846,7 @@ _io_TextIOWrapper_tell_impl(textio *self) } finally: - attr = _Py_GET_GLOBAL_IDENTIFIER(setstate); + attr = _Py_ID(setstate); res = PyObject_CallMethodOneArg(self->decoder, attr, saved_state); Py_DECREF(saved_state); if (res == NULL) @@ -2861,7 +2861,7 @@ _io_TextIOWrapper_tell_impl(textio *self) if (saved_state) { PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - attr = _Py_GET_GLOBAL_IDENTIFIER(setstate); + attr = _Py_ID(setstate); res = PyObject_CallMethodOneArg(self->decoder, attr, saved_state); _PyErr_ChainExceptions(type, value, traceback); Py_DECREF(saved_state); @@ -2913,7 +2913,7 @@ textiowrapper_repr(textio *self) } goto error; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) { if (!PyErr_ExceptionMatches(PyExc_ValueError)) { goto error; @@ -2930,7 +2930,7 @@ textiowrapper_repr(textio *self) if (res == NULL) goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(mode); + attr = _Py_ID(mode); if (_PyObject_LookupAttr((PyObject *) self, attr, &modeobj) < 0) { goto error; } @@ -2971,7 +2971,7 @@ _io_TextIOWrapper_fileno_impl(textio *self) /*[clinic end generated code: output=21490a4c3da13e6c input=c488ca83d0069f9b]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(fileno); + PyObject *attr = _Py_ID(fileno); return PyObject_CallMethodNoArgs(self->buffer, attr); } @@ -2984,7 +2984,7 @@ _io_TextIOWrapper_seekable_impl(textio *self) /*[clinic end generated code: output=ab223dbbcffc0f00 input=8b005ca06e1fca13]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(seekable); + PyObject *attr = _Py_ID(seekable); return PyObject_CallMethodNoArgs(self->buffer, attr); } @@ -2997,7 +2997,7 @@ _io_TextIOWrapper_readable_impl(textio *self) /*[clinic end generated code: output=72ff7ba289a8a91b input=0704ea7e01b0d3eb]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readable); + PyObject *attr = _Py_ID(readable); return PyObject_CallMethodNoArgs(self->buffer, attr); } @@ -3010,7 +3010,7 @@ _io_TextIOWrapper_writable_impl(textio *self) /*[clinic end generated code: output=a728c71790d03200 input=c41740bc9d8636e8]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(writable); + PyObject *attr = _Py_ID(writable); return PyObject_CallMethodNoArgs(self->buffer, attr); } @@ -3023,7 +3023,7 @@ _io_TextIOWrapper_isatty_impl(textio *self) /*[clinic end generated code: output=12be1a35bace882e input=fb68d9f2c99bbfff]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + PyObject *attr = _Py_ID(isatty); return PyObject_CallMethodNoArgs(self->buffer, attr); } @@ -3040,7 +3040,7 @@ _io_TextIOWrapper_flush_impl(textio *self) self->telling = self->seekable; if (_textiowrapper_writeflush(self) < 0) return NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *attr = _Py_ID(flush); return PyObject_CallMethodNoArgs(self->buffer, attr); } @@ -3070,7 +3070,7 @@ _io_TextIOWrapper_close_impl(textio *self) else { PyObject *exc = NULL, *val, *tb, *attr; if (self->finalizing) { - attr = _Py_GET_GLOBAL_IDENTIFIER(_dealloc_warn); + attr = _Py_ID(_dealloc_warn); res = PyObject_CallMethodOneArg(self->buffer, attr, (PyObject *)self); if (res) @@ -3078,14 +3078,14 @@ _io_TextIOWrapper_close_impl(textio *self) else PyErr_Clear(); } - attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + attr = _Py_ID(flush); res = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (res == NULL) PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(res); - attr = _Py_GET_GLOBAL_IDENTIFIER(close); + attr = _Py_ID(close); res = PyObject_CallMethodNoArgs(self->buffer, attr); if (exc != NULL) { _PyErr_ChainExceptions(exc, val, tb); @@ -3137,7 +3137,7 @@ static PyObject * textiowrapper_name_get(textio *self, void *context) { CHECK_ATTACHED(self); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); return PyObject_GetAttr(self->buffer, attr); } diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index 92260ebdba021b5..ee1590591f08129 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -194,7 +194,7 @@ _io__WindowsConsoleIO_close_impl(winconsoleio *self) PyObject *res; PyObject *exc, *val, *tb; int rc; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(close); + PyObject *attr = _Py_ID(close); res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type, attr, (PyObject*)self); if (!self->closefd) { @@ -392,7 +392,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj, self->blksize = DEFAULT_BUFFER_SIZE; memset(self->buf, 0, 4); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); if (PyObject_SetAttr((PyObject *)self, attr, nameobj) < 0) goto error; diff --git a/Modules/_operator.c b/Modules/_operator.c index 03d9155091dc779..4309d46da00a992 100644 --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -1,6 +1,6 @@ #include "Python.h" #include "pycore_moduleobject.h" // _PyModule_GetState() -#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() +#include "pycore_runtime.h" // _Py_ID() #include "clinic/_operator.c.h" typedef struct { @@ -1697,7 +1697,7 @@ methodcaller_reduce(methodcallerobject *mc, PyObject *Py_UNUSED(ignored)) functools = PyImport_ImportModule("functools"); if (!functools) return NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(partial); + PyObject *attr = _Py_ID(partial); partial = PyObject_GetAttr(functools, attr); Py_DECREF(functools); if (!partial) diff --git a/Modules/_pickle.c b/Modules/_pickle.c index ea8989701b031e3..60cf384c7ca0f94 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -11,7 +11,7 @@ #include "Python.h" #include "pycore_floatobject.h" // _PyFloat_Pack8() #include "pycore_moduleobject.h" // _PyModule_GetState() -#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() +#include "pycore_runtime.h" // _Py_ID() #include "pycore_pystate.h" // _PyThreadState_GET() #include "structmember.h" // PyMemberDef @@ -235,7 +235,7 @@ _Pickle_InitState(PickleState *st) PyObject *codecs = NULL; PyObject *functools = NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + PyObject *attr = _Py_ID(getattr); st->getattr = _PyEval_GetBuiltin(attr); if (st->getattr == NULL) goto error; @@ -1185,7 +1185,7 @@ static int _Pickler_SetOutputStream(PicklerObject *self, PyObject *file) { assert(file != NULL); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(write); + PyObject *attr = _Py_ID(write); if (_PyObject_LookupAttr(file, attr, &self->write) < 0) { return -1; } @@ -1646,17 +1646,17 @@ static int _Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file) { /* Optional file methods */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(peek); + PyObject *attr = _Py_ID(peek); if (_PyObject_LookupAttr(file, attr, &self->peek) < 0) { return -1; } - attr = _Py_GET_GLOBAL_IDENTIFIER(readinto); + attr = _Py_ID(readinto); if (_PyObject_LookupAttr(file, attr, &self->readinto) < 0) { return -1; } - attr = _Py_GET_GLOBAL_IDENTIFIER(read); + attr = _Py_ID(read); (void)_PyObject_LookupAttr(file, attr, &self->read); - attr = _Py_GET_GLOBAL_IDENTIFIER(readline); + attr = _Py_ID(readline); (void)_PyObject_LookupAttr(file, attr, &self->readline); if (!self->readline || !self->read) { if (!PyErr_Occurred()) { @@ -1923,7 +1923,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) Py_ssize_t i; PyObject *modules; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + PyObject *attr = _Py_ID(__module__); if (_PyObject_LookupAttr(global, attr, &module_name) < 0) { return NULL; } @@ -1938,7 +1938,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) assert(module_name == NULL); /* Fallback on walking sys.modules */ - attr = _Py_GET_GLOBAL_IDENTIFIER(modules); + attr = _Py_ID(modules); PyThreadState *tstate = _PyThreadState_GET(); modules = _PySys_GetAttr(tstate, attr); if (modules == NULL) { @@ -1985,7 +1985,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) } /* If no module is found, use __main__. */ - module_name = _Py_GET_GLOBAL_IDENTIFIER(__main__); + module_name = _Py_ID(__main__); Py_INCREF(module_name); return module_name; } @@ -2438,7 +2438,7 @@ save_bytes(PicklerObject *self, PyObject *obj) if (unicode_str == NULL) return -1; - PyObject *latin1 = _Py_GET_GLOBAL_IDENTIFIER(latin1); + PyObject *latin1 = _Py_ID(latin1); reduce_value = Py_BuildValue("(O(OO))", st->codecs_encode, unicode_str, latin1); @@ -3343,7 +3343,7 @@ save_dict(PicklerObject *self, PyObject *obj) status = batch_dict_exact(self, obj); Py_LeaveRecursiveCall(); } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *attr = _Py_ID(items); items = PyObject_CallMethodNoArgs(obj, attr); if (items == NULL) goto error; @@ -3604,11 +3604,11 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name) global_name = name; } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + PyObject *attr = _Py_ID(__qualname__); if (_PyObject_LookupAttr(obj, attr, &global_name) < 0) goto error; if (global_name == NULL) { - attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + attr = _Py_ID(__name__); global_name = PyObject_GetAttr(obj, attr); if (global_name == NULL) goto error; @@ -3931,7 +3931,7 @@ get_class(PyObject *obj) { PyObject *cls; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + PyObject *attr = _Py_ID(__class__); if (_PyObject_LookupAttr(obj, attr, &cls) == 0) { cls = (PyObject *) Py_TYPE(obj); Py_INCREF(cls); @@ -4016,15 +4016,15 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) if (self->proto >= 2) { PyObject *name; - attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + attr = _Py_ID(__name__); if (_PyObject_LookupAttr(callable, attr, &name) < 0) { return -1; } if (name != NULL && PyUnicode_Check(name)) { - attr = _Py_GET_GLOBAL_IDENTIFIER(__newobj_ex__); + attr = _Py_ID(__newobj_ex__); use_newobj_ex = _PyUnicode_Equal(name, attr); if (!use_newobj_ex) { - attr = _Py_GET_GLOBAL_IDENTIFIER(__newobj__); + attr = _Py_ID(__newobj__); use_newobj = _PyUnicode_Equal(name, attr); } } @@ -4082,7 +4082,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) if (newargs == NULL) return -1; - attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + attr = _Py_ID(__new__); cls_new = PyObject_GetAttr(cls, attr); if (cls_new == NULL) { Py_DECREF(newargs); @@ -4427,7 +4427,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save) don't actually have to check for a __reduce__ method. */ /* Check for a __reduce_ex__ method. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__reduce_ex__); + PyObject *attr = _Py_ID(__reduce_ex__); if (_PyObject_LookupAttr(obj, attr, &reduce_func) < 0) { goto error; } @@ -4440,7 +4440,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save) } else { /* Check for a __reduce__ method. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(__reduce__); + attr = _Py_ID(__reduce__); if (_PyObject_LookupAttr(obj, attr, &reduce_func) < 0) { goto error; } @@ -4495,7 +4495,7 @@ dump(PicklerObject *self, PyObject *obj) int status = -1; PyObject *tmp; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(reducer_override); + PyObject *attr = _Py_ID(reducer_override); if (_PyObject_LookupAttr((PyObject *)self, attr, &tmp) < 0) { goto error; @@ -4764,14 +4764,14 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, self->fast_nesting = 0; self->fast_memo = NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(persistent_id); + PyObject *attr = _Py_ID(persistent_id); if (init_method_ref((PyObject *)self, attr, &self->pers_func, &self->pers_func_self) < 0) { return -1; } - attr = _Py_GET_GLOBAL_IDENTIFIER(dispatch_table); + attr = _Py_ID(dispatch_table); if (_PyObject_LookupAttr((PyObject *)self, attr, &self->dispatch_table) < 0) { return -1; @@ -5127,7 +5127,7 @@ static PyTypeObject Pickler_Type = { static PyObject * find_class(UnpicklerObject *self, PyObject *module_name, PyObject *global_name) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(find_class); + PyObject *attr = _Py_ID(find_class); return PyObject_CallMethodObjArgs((PyObject *)self, attr, module_name, global_name, NULL); } @@ -5817,12 +5817,12 @@ instantiate(PyObject *cls, PyObject *args) assert(PyTuple_Check(args)); if (!PyTuple_GET_SIZE(args) && PyType_Check(cls)) { PyObject *func; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getinitargs__); + PyObject *attr = _Py_ID(__getinitargs__); if (_PyObject_LookupAttr(cls, attr, &func) < 0) { return NULL; } if (func == NULL) { - attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + attr = _Py_ID(__new__); return PyObject_CallMethodOneArg(cls, attr, cls); } Py_DECREF(func); @@ -6469,7 +6469,7 @@ do_append(UnpicklerObject *self, Py_ssize_t x) else { PyObject *extend_func; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(extend); + PyObject *attr = _Py_ID(extend); if (_PyObject_LookupAttr(list, attr, &extend_func) < 0) { return -1; } @@ -6491,7 +6491,7 @@ do_append(UnpicklerObject *self, Py_ssize_t x) /* Even if the PEP 307 requires extend() and append() methods, fall back on append() if the object has no extend() method for backward compatibility. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(append); + attr = _Py_ID(append); append_func = PyObject_GetAttr(list, attr); if (append_func == NULL) return -1; @@ -6616,7 +6616,7 @@ load_additems(UnpicklerObject *self) else { PyObject *add_func; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(add); + PyObject *attr = _Py_ID(add); add_func = PyObject_GetAttr(set, attr); if (add_func == NULL) return -1; @@ -6658,7 +6658,7 @@ load_build(UnpicklerObject *self) inst = self->stack->data[Py_SIZE(self->stack) - 1]; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setstate__); + PyObject *attr = _Py_ID(__setstate__); if (_PyObject_LookupAttr(inst, attr, &setstate) < 0) { Py_DECREF(state); return -1; @@ -6701,7 +6701,7 @@ load_build(UnpicklerObject *self) PyErr_SetString(st->UnpicklingError, "state is not a dictionary"); goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + attr = _Py_ID(__dict__); dict = PyObject_GetAttr(inst, attr); if (dict == NULL) goto error; @@ -7269,7 +7269,7 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, self->fix_imports = fix_imports; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(persistent_load); + PyObject *attr = _Py_ID(persistent_load); if (init_method_ref((PyObject *)self, attr, &self->pers_func, &self->pers_func_self) < 0) { diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 2f7e2a70a64bc7e..f646e300c1df6dd 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -933,7 +933,7 @@ local_setattro(localobject *self, PyObject *name, PyObject *v) return -1; } - PyObject *str_dict = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *str_dict = _Py_ID(__dict__); int r = PyObject_RichCompareBool(name, str_dict, Py_EQ); if (r == -1) { return -1; @@ -985,7 +985,7 @@ local_getattro(localobject *self, PyObject *name) if (ldict == NULL) return NULL; - PyObject *str_dict = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *str_dict = _Py_ID(__dict__); int r = PyObject_RichCompareBool(name, str_dict, Py_EQ); if (r == 1) { return Py_NewRef(ldict); @@ -1407,7 +1407,7 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, PyObject *name = NULL; if (thread != Py_None) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); if (_PyObject_LookupAttr(thread, attr, &name) < 0) { return -1; } @@ -1446,7 +1446,7 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, _PyErr_Display(file, exc_type, exc_value, exc_traceback); /* Call file.flush() */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *attr = _Py_ID(flush); PyObject *res = PyObject_CallMethodNoArgs(file, attr); if (!res) { return -1; @@ -1503,7 +1503,7 @@ thread_excepthook(PyObject *module, PyObject *args) PyObject *thread = PyStructSequence_GET_ITEM(args, 3); PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *attr = _Py_ID(stderr); PyObject *file = _PySys_GetAttr(tstate, attr); if (file == NULL || file == Py_None) { if (thread == Py_None) { diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 811f99bfe5823d8..0d7295769c52719 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -151,7 +151,7 @@ faulthandler_get_fileno(PyObject **file_ptr) if (file == NULL || file == Py_None) { PyThreadState *tstate = _PyThreadState_GET(); - attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + attr = _Py_ID(stderr); file = _PySys_GetAttr(tstate, attr); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "unable to get sys.stderr"); @@ -175,7 +175,7 @@ faulthandler_get_fileno(PyObject **file_ptr) return fd; } - attr = _Py_GET_GLOBAL_IDENTIFIER(fileno); + attr = _Py_ID(fileno); result = PyObject_CallMethodNoArgs(file, attr); if (result == NULL) return -1; @@ -194,7 +194,7 @@ faulthandler_get_fileno(PyObject **file_ptr) return -1; } - attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + attr = _Py_ID(flush); result = PyObject_CallMethodNoArgs(file, attr); if (result != NULL) Py_DECREF(result); @@ -1335,7 +1335,7 @@ faulthandler_init_enable(void) return -1; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(enable); + PyObject *attr = _Py_ID(enable); PyObject *res = PyObject_CallMethodNoArgs(module, attr); Py_DECREF(module); if (res == NULL) { diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index aae195b4625efcc..82249e8d4c26f45 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -504,7 +504,7 @@ static PyObject * _grouper_reduce(_grouperobject *lz, PyObject *Py_UNUSED(ignored)) { if (((groupbyobject *)lz->parent)->currgrouper != lz) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); } return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->parent, lz->tgtkey); @@ -1031,7 +1031,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n) return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__copy__); + PyObject *attr = _Py_ID(__copy__); if (_PyObject_LookupAttr(it, attr, ©func) < 0) { Py_DECREF(it); Py_DECREF(result); @@ -1179,7 +1179,7 @@ cycle_reduce(cycleobject *lz, PyObject *Py_UNUSED(ignored)) if (it == NULL) return NULL; if (lz->index != 0) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setstate__); + PyObject *attr = _Py_ID(__setstate__); PyObject *res = _PyObject_CallMethod(it, attr, "n", lz->index); if (res == NULL) { Py_DECREF(it); @@ -4554,7 +4554,7 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_GET_SIZE(kwds) > 0) { fillvalue = NULL; if (PyDict_GET_SIZE(kwds) == 1) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(fillvalue); + PyObject *attr = _Py_ID(fillvalue); fillvalue = PyDict_GetItemWithError(kwds, attr); } if (fillvalue == NULL) { diff --git a/Modules/main.c b/Modules/main.c index 9aecf505e9ade60..8873aa8a2f1fda7 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -161,7 +161,7 @@ pymain_sys_path_add_path0(PyInterpreterState *interp, PyObject *path0) PyObject *sys_path; PyObject *sysdict = interp->sysdict; if (sysdict != NULL) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(path); + PyObject *attr = _Py_ID(path); sys_path = PyDict_GetItemWithError(sysdict, attr); if (sys_path == NULL && PyErr_Occurred()) { return -1; diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index f07576103518dea..5440258334632d0 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1157,7 +1157,7 @@ path_converter(PyObject *o, void *p) /* Inline PyOS_FSPath() for better error messages. */ PyObject *func, *res; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__fspath__); + PyObject *attr = _Py_ID(__fspath__); func = _PyObject_LookupSpecial(o, attr); if (NULL == func) { goto error_format; @@ -14436,7 +14436,7 @@ PyOS_FSPath(PyObject *path) return path; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__fspath__); + PyObject *attr = _Py_ID(__fspath__); func = _PyObject_LookupSpecial(path, attr); if (NULL == func) { return PyErr_Format(PyExc_TypeError, diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 6c3f0b7c62c4090..b8f3ef968b0f8c3 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -4,7 +4,7 @@ #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH #include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_namespace.h" // _PyNamespace_New() -#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() +#include "pycore_runtime.h" // _Py_ID() #include @@ -916,7 +916,7 @@ time_strptime(PyObject *self, PyObject *args) if (!module) return NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_strptime_time); + PyObject *attr = _Py_ID(_strptime_time); func = PyObject_GetAttr(module, attr); Py_DECREF(module); if (!func) { diff --git a/Objects/abstract.c b/Objects/abstract.c index 1c0685bfe6ca9cc..633ab43bf11ad6c 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -106,7 +106,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) return res; } } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__length_hint__); + PyObject *attr = _Py_ID(__length_hint__); hint = _PyObject_LookupSpecial(o, attr); if (hint == NULL) { if (PyErr_Occurred()) { @@ -183,7 +183,7 @@ PyObject_GetItem(PyObject *o, PyObject *key) return Py_GenericAlias(o, key); } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class_getitem__); + PyObject *attr = _Py_ID(__class_getitem__); if (_PyObject_LookupAttr(o, attr, &meth) < 0) { return NULL; } @@ -796,7 +796,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) } /* Find the (unbound!) __format__ method */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__format__); + PyObject *attr = _Py_ID(__format__); meth = _PyObject_LookupSpecial(obj, attr); if (meth == NULL) { PyThreadState *tstate = _PyThreadState_GET(); @@ -1561,7 +1561,7 @@ PyNumber_Long(PyObject *o) if (m && m->nb_index) { return PyNumber_Index(o); } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__trunc__); + PyObject *attr = _Py_ID(__trunc__); trunc_func = _PyObject_LookupSpecial(o, attr); if (trunc_func) { result = _PyObject_CallNoArgs(trunc_func); @@ -2438,7 +2438,7 @@ PyMapping_Keys(PyObject *o) if (PyDict_CheckExact(o)) { return PyDict_Keys(o); } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(keys); + PyObject *attr = _Py_ID(keys); return method_output_as_list(o, attr); } @@ -2451,7 +2451,7 @@ PyMapping_Items(PyObject *o) if (PyDict_CheckExact(o)) { return PyDict_Items(o); } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *attr = _Py_ID(items); return method_output_as_list(o, attr); } @@ -2464,7 +2464,7 @@ PyMapping_Values(PyObject *o) if (PyDict_CheckExact(o)) { return PyDict_Values(o); } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(values); + PyObject *attr = _Py_ID(values); return method_output_as_list(o, attr); } @@ -2499,7 +2499,7 @@ abstract_get_bases(PyObject *cls) { PyObject *bases; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__bases__); + PyObject *attr = _Py_ID(__bases__); (void)_PyObject_LookupAttr(cls, attr, &bases); if (bases != NULL && !PyTuple_Check(bases)) { Py_DECREF(bases); @@ -2581,7 +2581,7 @@ object_isinstance(PyObject *inst, PyObject *cls) { PyObject *icls; int retval; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + PyObject *attr = _Py_ID(__class__); if (PyType_Check(cls)) { retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls); if (retval == 0) { @@ -2646,7 +2646,7 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls return r; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__instancecheck__); + PyObject *attr = _Py_ID(__instancecheck__); PyObject *checker = _PyObject_LookupSpecial(cls, attr); if (checker != NULL) { if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) { @@ -2734,7 +2734,7 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) return r; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__subclasscheck__); + PyObject *attr = _Py_ID(__subclasscheck__); checker = _PyObject_LookupSpecial(cls, attr); if (checker != NULL) { int ok = -1; @@ -2881,7 +2881,7 @@ PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result) *result = Py_TYPE(iter)->tp_iternext(iter); } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(send); + PyObject *attr = _Py_ID(send); *result = PyObject_CallMethodOneArg(iter, attr, arg); } if (*result != NULL) { diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 667865896a71717..6c45e7202cbdc52 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2113,7 +2113,7 @@ _common_reduce(PyByteArrayObject *self, int proto) PyObject *dict; char *buf; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); if (_PyObject_LookupAttr((PyObject *)self, attr, &dict) < 0) { return NULL; } @@ -2427,7 +2427,7 @@ PyDoc_STRVAR(length_hint_doc, static PyObject * bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); if (it->it_seq != NULL) { return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 25e4c6278bc2a8b..6a129daff76b8f0 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -528,7 +528,7 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen) return v; } /* does it support __bytes__? */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__bytes__); + PyObject *attr = _Py_ID(__bytes__); func = _PyObject_LookupSpecial(v, attr); if (func != NULL) { result = _PyObject_CallNoArgs(func); @@ -2550,7 +2550,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding, PyObject *bytes; PyObject *func; Py_ssize_t size; - PyObject *__bytes__ = _Py_GET_GLOBAL_IDENTIFIER(__bytes__); + PyObject *__bytes__ = _Py_ID(__bytes__); if (x == NULL) { if (encoding != NULL || errors != NULL) { @@ -3121,7 +3121,7 @@ PyDoc_STRVAR(length_hint_doc, static PyObject * striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); if (it->it_seq != NULL) { return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); diff --git a/Objects/classobject.c b/Objects/classobject.c index 6e83c8eefb9401a..251dc58c6cbcc5b 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -122,12 +122,12 @@ method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored)) PyObject *func = PyMethod_GET_FUNCTION(im); PyObject *funcname; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *attr = _Py_ID(__name__); funcname = PyObject_GetAttr(func, attr); if (funcname == NULL) { return NULL; } - attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + attr = _Py_ID(getattr); return Py_BuildValue("N(ON)", _PyEval_GetBuiltin(attr), self, funcname); } @@ -278,8 +278,8 @@ method_repr(PyMethodObject *a) PyObject *funcname, *result; const char *defname = "?"; - PyObject *attr1 = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); - PyObject *attr2 = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *attr1 = _Py_ID(__qualname__); + PyObject *attr2 = _Py_ID(__name__); if (_PyObject_LookupAttr(func, attr1, &funcname) < 0 || (funcname == NULL && _PyObject_LookupAttr(func, attr2, &funcname) < 0)) { @@ -514,7 +514,7 @@ instancemethod_repr(PyObject *self) return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *attr = _Py_ID(__name__); if (_PyObject_LookupAttr(func, attr, &funcname) < 0) { return NULL; } diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 3f65efbd86c53dd..338cceb0ba923df 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -282,7 +282,7 @@ try_complex_special_method(PyObject *op) { PyObject *f; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__complex__); + PyObject *attr = _Py_ID(__complex__); f = _PyObject_LookupSpecial(op, attr); if (f) { PyObject *res = _PyObject_CallNoArgs(f); diff --git a/Objects/descrobject.c b/Objects/descrobject.c index e7bf68b48ea5b1c..a64a630bd4cedf8 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -576,7 +576,7 @@ calculate_qualname(PyDescrObject *descr) return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + PyObject *attr = _Py_ID(__qualname__); type_qualname = PyObject_GetAttr((PyObject *)descr->d_type, attr); if (type_qualname == NULL) return NULL; @@ -605,7 +605,7 @@ descr_get_qualname(PyDescrObject *descr, void *Py_UNUSED(ignored)) static PyObject * descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + PyObject *attr = _Py_ID(getattr); return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(attr), PyDescr_TYPE(descr), PyDescr_NAME(descr)); } @@ -1084,7 +1084,7 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs { return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(get); + PyObject *attr = _Py_ID(get); return _PyObject_VectorcallMethod(attr, newargs, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); @@ -1093,35 +1093,35 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs static PyObject * mappingproxy_keys(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(keys); + PyObject *attr = _Py_ID(keys); return PyObject_CallMethodNoArgs(pp->mapping, attr); } static PyObject * mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(values); + PyObject *attr = _Py_ID(values); return PyObject_CallMethodNoArgs(pp->mapping, attr); } static PyObject * mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *attr = _Py_ID(items); return PyObject_CallMethodNoArgs(pp->mapping, attr); } static PyObject * mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(copy); + PyObject *attr = _Py_ID(copy); return PyObject_CallMethodNoArgs(pp->mapping, attr); } static PyObject * mappingproxy_reversed(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__reversed__); + PyObject *attr = _Py_ID(__reversed__); return PyObject_CallMethodNoArgs(pp->mapping, attr); } @@ -1319,7 +1319,7 @@ wrapper_repr(wrapperobject *wp) static PyObject * wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + PyObject *attr = _Py_ID(getattr); return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(attr), wp->self, PyDescr_NAME(wp->descr)); } @@ -1756,7 +1756,7 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, /* if no docstring given and the getter has one, use that one */ if ((doc == NULL || doc == Py_None) && fget != NULL) { PyObject *get_doc; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + PyObject *attr = _Py_ID(__doc__); int rc = _PyObject_LookupAttr(fget, attr, &get_doc); if (rc <= 0) { return rc; diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 5cc1cd2e2bca491..95ac24b01b3b4a8 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2160,7 +2160,7 @@ dict_subscript(PyDictObject *mp, PyObject *key) if (!PyDict_CheckExact(mp)) { /* Look up __missing__ method if we're a subclass. */ PyObject *missing, *res; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__missing__); + PyObject *attr = _Py_ID(__missing__); missing = _PyObject_LookupSpecial((PyObject *)mp, attr); if (missing != NULL) { res = PyObject_CallOneArg(missing, key); @@ -2364,7 +2364,7 @@ dict_update_arg(PyObject *self, PyObject *arg) return PyDict_Merge(self, arg, 1); } PyObject *func; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(keys); + PyObject *attr = _Py_ID(keys); if (_PyObject_LookupAttr(arg, attr, &func) < 0) { return -1; } @@ -4130,7 +4130,7 @@ dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); } @@ -4401,7 +4401,7 @@ dictviews_sub(PyObject *self, PyObject *other) return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(difference_update); + PyObject *attr = _Py_ID(difference_update); PyObject *tmp = PyObject_CallMethodOneArg(result, attr, other); if (tmp == NULL) { Py_DECREF(result); @@ -4438,7 +4438,7 @@ _PyDictView_Intersect(PyObject* self, PyObject *other) /* if other is a set and self is smaller than other, reuse set intersection logic */ if (PySet_CheckExact(other) && len_self <= PyObject_Size(other)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(intersection); + PyObject *attr = _Py_ID(intersection); return PyObject_CallMethodObjArgs(other, attr, self, NULL); } @@ -4579,7 +4579,7 @@ dictitems_xor(PyObject *self, PyObject *other) } key = val1 = val2 = NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *attr = _Py_ID(items); PyObject *remaining_pairs = PyObject_CallMethodNoArgs(temp_dict, attr); if (remaining_pairs == NULL) { goto error; @@ -4612,7 +4612,7 @@ dictviews_xor(PyObject* self, PyObject *other) return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(symmetric_difference_update); + PyObject *attr = _Py_ID(symmetric_difference_update); PyObject *tmp = PyObject_CallMethodOneArg(result, attr, other); if (tmp == NULL) { Py_DECREF(result); diff --git a/Objects/enumobject.c b/Objects/enumobject.c index 2dea23a669c006c..f73f811a63f282e 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -357,7 +357,7 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq) PyObject *reversed_meth; reversedobject *ro; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__reversed__); + PyObject *attr = _Py_ID(__reversed__); reversed_meth = _PyObject_LookupSpecial(seq, attr); if (reversed_meth == Py_None) { Py_DECREF(reversed_meth); diff --git a/Objects/exceptions.c b/Objects/exceptions.c index ac26979985c7ee6..5b76824090ee9e1 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1502,12 +1502,12 @@ ImportError_getstate(PyImportErrorObject *self) dict = dict ? PyDict_Copy(dict) : PyDict_New(); if (dict == NULL) return NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); if (self->name && PyDict_SetItem(dict, attr, self->name) < 0) { Py_DECREF(dict); return NULL; } - attr = _Py_GET_GLOBAL_IDENTIFIER(path); + attr = _Py_ID(path); if (self->path && PyDict_SetItem(dict, attr, self->path) < 0) { Py_DECREF(dict); return NULL; diff --git a/Objects/fileobject.c b/Objects/fileobject.c index accce4c853d4c4c..9341d1511188317 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -38,7 +38,7 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c io = PyImport_ImportModule("_io"); if (io == NULL) return NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); + PyObject *attr = _Py_ID(open); stream = _PyObject_CallMethod(io, attr, "isisssO", fd, mode, buffering, encoding, errors, newline, closefd ? Py_True : Py_False); @@ -60,7 +60,7 @@ PyFile_GetLine(PyObject *f, int n) return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(readline); + PyObject *attr = _Py_ID(readline); if (n <= 0) { result = PyObject_CallMethodNoArgs(f, attr); } @@ -124,7 +124,7 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags) PyErr_SetString(PyExc_TypeError, "writeobject with NULL file"); return -1; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(write); + PyObject *attr = _Py_ID(write); writer = PyObject_GetAttr(f, attr); if (writer == NULL) return -1; @@ -182,7 +182,7 @@ PyObject_AsFileDescriptor(PyObject *o) int fd; PyObject *meth; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(fileno); + PyObject *attr = _Py_ID(fileno); if (PyLong_Check(o)) { fd = _PyLong_AsInt(o); } @@ -508,7 +508,7 @@ PyFile_OpenCodeObject(PyObject *path) } else { iomod = PyImport_ImportModule("_io"); if (iomod) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); + PyObject *attr = _Py_ID(open); f = _PyObject_CallMethod(iomod, attr, "Os", path, "rb"); Py_DECREF(iomod); } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index f83f1d8e2e70712..03c4d1cc846c9b4 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -1078,7 +1078,7 @@ PyFrame_GetBack(PyFrameObject *frame) PyObject* _PyEval_BuiltinsFromGlobals(PyThreadState *tstate, PyObject *globals) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); + PyObject *attr = _Py_ID(__builtins__); PyObject *builtins = PyDict_GetItemWithError(globals, attr); if (builtins) { if (PyModule_Check(builtins)) { diff --git a/Objects/funcobject.c b/Objects/funcobject.c index f335983dc02b291..d83d2e99972ed1f 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -79,7 +79,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname Py_INCREF(doc); // __module__: Use globals['__name__'] if it exists, or NULL. - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *attr = _Py_ID(__name__); PyObject *module = PyDict_GetItemWithError(globals, attr); PyObject *builtins = NULL; if (module == NULL && _PyErr_Occurred(tstate)) { @@ -808,7 +808,7 @@ functools_wraps(PyObject *wrapper, PyObject *wrapped) { #define COPY_ATTR(ATTR) \ do { \ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(ATTR); \ + PyObject *attr = _Py_ID(ATTR); \ if (functools_copy_attr(wrapper, wrapped, attr) < 0) { \ return -1; \ } \ diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index bb2002fd78b7d09..ab31a2d764cda84 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -53,13 +53,13 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) goto done; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__origin__); + PyObject *attr = _Py_ID(__origin__); if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { goto done; } if (tmp != NULL) { Py_DECREF(tmp); - attr = _Py_GET_GLOBAL_IDENTIFIER(__args__); + attr = _Py_ID(__args__); if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { goto done; } @@ -70,14 +70,14 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) } } - attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + attr = _Py_ID(__qualname__); if (_PyObject_LookupAttr(p, attr, &qualname) < 0) { goto done; } if (qualname == NULL) { goto use_repr; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + attr = _Py_ID(__module__); if (_PyObject_LookupAttr(p, attr, &module) < 0) { goto done; } @@ -219,7 +219,7 @@ _Py_make_parameters(PyObject *args) } else { PyObject *subparams; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__parameters__); + PyObject *attr = _Py_ID(__parameters__); if (_PyObject_LookupAttr(t, attr, &subparams) < 0) { Py_DECREF(parameters); return NULL; @@ -261,7 +261,7 @@ static PyObject * subs_tvars(PyObject *obj, PyObject *params, PyObject **argitems) { PyObject *subparams; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__parameters__); + PyObject *attr = _Py_ID(__parameters__); if (_PyObject_LookupAttr(obj, attr, &subparams) < 0) { return NULL; } diff --git a/Objects/genobject.c b/Objects/genobject.c index 23eb6cb5c6fe997..b1c2584f5b692ad 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -328,7 +328,7 @@ gen_close_iter(PyObject *yf) } else { PyObject *meth; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(close); + PyObject *attr = _Py_ID(close); if (_PyObject_LookupAttr(yf, attr, &meth) < 0) { PyErr_WriteUnraisable(yf); } @@ -461,7 +461,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, } else { /* `yf` is an iterator or a coroutine-like object. */ PyObject *meth; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(throw); + PyObject *attr = _Py_ID(throw); if (_PyObject_LookupAttr(yf, attr, &meth) < 0) { Py_DECREF(yf); return NULL; diff --git a/Objects/iterobject.c b/Objects/iterobject.c index c37d138c7a0b85b..740efc93c549b0a 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -103,7 +103,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); if (it->it_seq != NULL) return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); @@ -243,7 +243,7 @@ calliter_iternext(calliterobject *it) static PyObject * calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); if (it->it_callable != NULL && it->it_sentinel != NULL) return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(attr), it->it_callable, it->it_sentinel); diff --git a/Objects/listobject.c b/Objects/listobject.c index bed3d5b4a7fc621..db40fe58a5ca3ee 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -3511,14 +3511,14 @@ listiter_reduce_general(void *_it, int forward) if (forward) { listiterobject *it = (listiterobject *)_it; if (it->it_seq) { - attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + attr = _Py_ID(iter); return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); } } else { listreviterobject *it = (listreviterobject *)_it; if (it->it_seq) { - attr = _Py_GET_GLOBAL_IDENTIFIER(reversed); + attr = _Py_ID(reversed); return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); } @@ -3527,6 +3527,6 @@ listiter_reduce_general(void *_it, int forward) list = PyList_New(0); if (list == NULL) return NULL; - attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + attr = _Py_ID(iter); return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); } diff --git a/Objects/longobject.c b/Objects/longobject.c index 7d4fb6fd7133c87..f3c57a49f3e8b04 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -5770,8 +5770,8 @@ int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder, int little_endian; PyObject *bytes; - PyObject *little = _Py_GET_GLOBAL_IDENTIFIER(little); - PyObject *big = _Py_GET_GLOBAL_IDENTIFIER(big); + PyObject *little = _Py_ID(little); + PyObject *big = _Py_ID(big); if (byteorder == NULL) little_endian = 0; else if (_PyUnicode_Equal(byteorder, little)) @@ -5834,8 +5834,8 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, int little_endian; PyObject *long_obj, *bytes; - PyObject *little = _Py_GET_GLOBAL_IDENTIFIER(little); - PyObject *big = _Py_GET_GLOBAL_IDENTIFIER(big); + PyObject *little = _Py_ID(little); + PyObject *big = _Py_ID(big); if (byteorder == NULL) little_endian = 0; else if (_PyUnicode_Equal(byteorder, little)) diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 5f2dcd82fbfc542..83f040d4f678d85 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -182,7 +182,7 @@ meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored)) if (m->m_self == NULL || PyModule_Check(m->m_self)) return PyUnicode_FromString(m->m_ml->ml_name); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(getattr); + PyObject *attr = _Py_ID(getattr); return Py_BuildValue("N(Os)", _PyEval_GetBuiltin(attr), m->m_self, m->m_ml->ml_name); } @@ -228,7 +228,7 @@ meth_get__qualname__(PyCFunctionObject *m, void *closure) type = PyType_Check(m->m_self) ? m->m_self : (PyObject*)Py_TYPE(m->m_self); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + PyObject *attr = _Py_ID(__qualname__); type_qualname = PyObject_GetAttr(type, attr); if (type_qualname == NULL) return NULL; diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index a246b7c9b578ee0..050c89e2b66cc67 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -58,19 +58,19 @@ module_init_dict(PyModuleObject *mod, PyObject *md_dict, if (doc == NULL) doc = Py_None; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *attr = _Py_ID(__name__); if (PyDict_SetItem(md_dict, attr, name) != 0) return -1; - attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + attr = _Py_ID(__doc__); if (PyDict_SetItem(md_dict, attr, doc) != 0) return -1; - attr = _Py_GET_GLOBAL_IDENTIFIER(__package__); + attr = _Py_ID(__package__); if (PyDict_SetItem(md_dict, attr, Py_None) != 0) return -1; - attr = _Py_GET_GLOBAL_IDENTIFIER(__loader__); + attr = _Py_ID(__loader__); if (PyDict_SetItem(md_dict, attr, Py_None) != 0) return -1; - attr = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + attr = _Py_ID(__spec__); if (PyDict_SetItem(md_dict, attr, Py_None) != 0) return -1; if (PyUnicode_CheckExact(name)) { @@ -467,7 +467,7 @@ int PyModule_SetDocString(PyObject *m, const char *doc) { PyObject *v; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + PyObject *attr = _Py_ID(__doc__); v = PyUnicode_FromString(doc); if (v == NULL || PyObject_SetAttr(m, attr, v) != 0) { @@ -497,7 +497,7 @@ PyModule_GetNameObject(PyObject *m) PyErr_BadArgument(); return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *attr = _Py_ID(__name__); d = ((PyModuleObject *)m)->md_dict; if (d == NULL || !PyDict_Check(d) || (name = PyDict_GetItemWithError(d, attr)) == NULL || @@ -531,7 +531,7 @@ PyModule_GetFilenameObject(PyObject *m) PyErr_BadArgument(); return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__file__); + PyObject *attr = _Py_ID(__file__); d = ((PyModuleObject *)m)->md_dict; if (d == NULL || (fileobj = PyDict_GetItemWithError(d, attr)) == NULL || @@ -723,7 +723,7 @@ int _PyModuleSpec_IsInitializing(PyObject *spec) { if (spec != NULL) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_initializing); + PyObject *attr = _Py_ID(_initializing); PyObject *value = PyObject_GetAttr(spec, attr); if (value != NULL) { int initializing = PyObject_IsTrue(value); @@ -747,7 +747,7 @@ _PyModuleSpec_IsUninitializedSubmodule(PyObject *spec, PyObject *name) return 0; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_uninitialized_submodules); + PyObject *attr = _Py_ID(_uninitialized_submodules); PyObject *value = PyObject_GetAttr(spec, attr); if (value == NULL) { return 0; @@ -771,7 +771,7 @@ module_getattro(PyModuleObject *m, PyObject *name) } PyErr_Clear(); assert(m->md_dict != NULL); - str = _Py_GET_GLOBAL_IDENTIFIER(__getattr__); + str = _Py_ID(__getattr__); getattr = PyDict_GetItemWithError(m->md_dict, str); if (getattr) { return PyObject_CallOneArg(getattr, name); @@ -779,11 +779,11 @@ module_getattro(PyModuleObject *m, PyObject *name) if (PyErr_Occurred()) { return NULL; } - str = _Py_GET_GLOBAL_IDENTIFIER(__name__); + str = _Py_ID(__name__); mod_name = PyDict_GetItemWithError(m->md_dict, str); if (mod_name && PyUnicode_Check(mod_name)) { Py_INCREF(mod_name); - str = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + str = _Py_ID(__spec__); PyObject *spec = PyDict_GetItemWithError(m->md_dict, str); if (spec == NULL && PyErr_Occurred()) { Py_DECREF(mod_name); @@ -860,12 +860,12 @@ static PyObject * module_dir(PyObject *self, PyObject *args) { PyObject *result = NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); PyObject *dict = PyObject_GetAttr(self, attr); if (dict != NULL) { if (PyDict_Check(dict)) { - attr = _Py_GET_GLOBAL_IDENTIFIER(__dir__); + attr = _Py_ID(__dir__); PyObject *dirfunc = PyDict_GetItemWithError(dict, attr); if (dirfunc) { result = _PyObject_CallNoArgs(dirfunc); @@ -892,7 +892,7 @@ static PyMethodDef module_methods[] = { static PyObject * module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); PyObject *dict = PyObject_GetAttr((PyObject *)m, attr); if ((dict == NULL) || !PyDict_Check(dict)) { @@ -902,7 +902,7 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) } PyObject *annotations; - attr = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); + attr = _Py_ID(__annotations__); /* there's no _PyDict_GetItemId without WithError, so let's LBYL. */ if (PyDict_Contains(dict, attr)) { annotations = PyDict_GetItemWithError(dict, attr); @@ -931,7 +931,7 @@ static int module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignored)) { int ret = -1; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); PyObject *dict = PyObject_GetAttr((PyObject *)m, attr); if ((dict == NULL) || !PyDict_Check(dict)) { @@ -939,7 +939,7 @@ module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignor goto exit; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); + attr = _Py_ID(__annotations__); if (value != NULL) { /* set */ ret = PyDict_SetItem(dict, attr, value); diff --git a/Objects/object.c b/Objects/object.c index 82a0541fc247657..02925f095936e1d 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -557,7 +557,7 @@ PyObject_Bytes(PyObject *v) return v; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__bytes__); + PyObject *attr = _Py_ID(__bytes__); func = _PyObject_LookupSpecial(v, attr); if (func != NULL) { result = _PyObject_CallNoArgs(func); @@ -598,7 +598,7 @@ _PyObject_FunctionStr(PyObject *x) { assert(!PyErr_Occurred()); PyObject *qualname; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + PyObject *attr = _Py_ID(__qualname__); int ret = _PyObject_LookupAttr(x, attr, &qualname); if (qualname == NULL) { if (ret < 0) { @@ -608,10 +608,10 @@ _PyObject_FunctionStr(PyObject *x) } PyObject *module; PyObject *result = NULL; - attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + attr = _Py_ID(__module__); ret = _PyObject_LookupAttr(x, attr, &module); if (module != NULL && module != Py_None) { - PyObject *builtinsname = _Py_GET_GLOBAL_IDENTIFIER(builtins); + PyObject *builtinsname = _Py_ID(builtins); ret = PyObject_RichCompareBool(module, builtinsname, Py_NE); if (ret < 0) { // error @@ -850,7 +850,7 @@ _PyObject_IsAbstract(PyObject *obj) if (obj == NULL) return 0; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__isabstractmethod__); + PyObject *attr = _Py_ID(__isabstractmethod__); res = _PyObject_LookupAttr(obj, attr, &isabstract); if (res > 0) { res = PyObject_IsTrue(isabstract); @@ -891,8 +891,8 @@ set_attribute_error_context(PyObject* v, PyObject* name) PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); PyErr_NormalizeException(&type, &value, &traceback); - PyObject *attr1 = _Py_GET_GLOBAL_IDENTIFIER(name); - PyObject *attr2 = _Py_GET_GLOBAL_IDENTIFIER(obj); + PyObject *attr1 = _Py_ID(name); + PyObject *attr2 = _Py_ID(obj); if (PyErr_GivenExceptionMatches(value, PyExc_AttributeError) && (PyObject_SetAttr(value, attr1, name) || PyObject_SetAttr(value, attr2, v))) { @@ -1562,7 +1562,7 @@ static PyObject * _dir_object(PyObject *obj) { PyObject *result, *sorted; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dir__); + PyObject *attr = _Py_ID(__dir__); PyObject *dirfunc = _PyObject_LookupSpecial(obj, attr); assert(obj != NULL); @@ -2142,7 +2142,7 @@ Py_ReprEnter(PyObject *obj) early on startup. */ if (dict == NULL) return 0; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(Py_Repr); + PyObject *attr = _Py_ID(Py_Repr); list = PyDict_GetItemWithError(dict, attr); if (list == NULL) { if (PyErr_Occurred()) { @@ -2179,7 +2179,7 @@ Py_ReprLeave(PyObject *obj) if (dict == NULL) goto finally; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(Py_Repr); + PyObject *attr = _Py_ID(Py_Repr); list = PyDict_GetItemWithError(dict, attr); if (list == NULL || !PyList_Check(list)) goto finally; diff --git a/Objects/odictobject.c b/Objects/odictobject.c index d3e214dd3b45b4c..153853afb7296c7 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -951,7 +951,7 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) PyObject *items_iter, *items, *args = NULL; /* capture any instance state */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); dict = PyObject_GetAttr((PyObject *)od, attr); if (dict == NULL) goto Done; @@ -971,7 +971,7 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) if (args == NULL) goto Done; - attr = _Py_GET_GLOBAL_IDENTIFIER(items); + attr = _Py_ID(items); items = PyObject_CallMethodNoArgs((PyObject *)od, attr); if (items == NULL) goto Done; @@ -1430,7 +1430,7 @@ odict_repr(PyODictObject *self) } } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *attr = _Py_ID(items); PyObject *items = PyObject_CallMethodNoArgs((PyObject *)self, attr); if (items == NULL) goto Done; @@ -1819,7 +1819,7 @@ odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); } @@ -2217,7 +2217,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg) return res; } PyObject *func; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(keys); + PyObject *attr = _Py_ID(keys); if (_PyObject_LookupAttr(arg, attr, &func) < 0) { return -1; } @@ -2250,7 +2250,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg) } return 0; } - attr = _Py_GET_GLOBAL_IDENTIFIER(items); + attr = _Py_ID(items); if (_PyObject_LookupAttr(arg, attr, &func) < 0) { return -1; } diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index f9ed0731623cfc8..7f9e9db4c6483b1 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -811,7 +811,7 @@ rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) if (range == NULL) goto err; /* return the result */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); return Py_BuildValue("N(N)l", _PyEval_GetBuiltin(attr), range, r->index); err: Py_XDECREF(start); @@ -965,7 +965,7 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored)) } /* return the result */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); return Py_BuildValue("N(N)O", _PyEval_GetBuiltin(attr), range, r->index); } diff --git a/Objects/setobject.c b/Objects/setobject.c index 47d1d594a73d1b9..88d870619c88164 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -780,7 +780,7 @@ setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); } @@ -1913,7 +1913,7 @@ set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored)) args = PyTuple_Pack(1, keys); if (args == NULL) goto done; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); if (_PyObject_LookupAttr((PyObject *)so, attr, &dict) < 0) { goto done; } diff --git a/Objects/structseq.c b/Objects/structseq.c index d76c4e128e7ec90..ae05d9c0af77a6f 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -37,13 +37,13 @@ get_type_attr_as_size(PyTypeObject *tp, PyObject *name) #define VISIBLE_SIZE(op) Py_SIZE(op) #define VISIBLE_SIZE_TP(tp) \ - get_type_attr_as_size(tp, _Py_GET_GLOBAL_IDENTIFIER(n_sequence_fields)) + get_type_attr_as_size(tp, _Py_ID(n_sequence_fields)) #define REAL_SIZE_TP(tp) \ - get_type_attr_as_size(tp, _Py_GET_GLOBAL_IDENTIFIER(n_fields)) + get_type_attr_as_size(tp, _Py_ID(n_fields)) #define REAL_SIZE(op) REAL_SIZE_TP(Py_TYPE(op)) #define UNNAMED_FIELDS_TP(tp) \ - get_type_attr_as_size(tp, _Py_GET_GLOBAL_IDENTIFIER(n_unnamed_fields)) + get_type_attr_as_size(tp, _Py_ID(n_unnamed_fields)) #define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP(Py_TYPE(op)) diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 728bc90a389ab35..5c341f8742a285d 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -1193,7 +1193,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * tupleiter_reduce(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); if (it->it_seq) return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 67c3578fd4d3eb9..fc5f611874ac9b6 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -151,7 +151,7 @@ _PyType_CheckConsistency(PyTypeObject *type) if (type->tp_flags & Py_TPFLAGS_DISALLOW_INSTANTIATION) { CHECK(type->tp_new == NULL); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + PyObject *attr = _Py_ID(__new__); CHECK(PyDict_Contains(type->tp_dict, attr) == 0); } @@ -350,7 +350,7 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) { PyObject *type_mro_meth = NULL; if (custom) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(mro); + PyObject *attr = _Py_ID(mro); mro_meth = lookup_maybe_method((PyObject *)type, attr, &unbound); if (mro_meth == NULL) goto clear; @@ -549,7 +549,7 @@ type_module(PyTypeObject *type, void *context) PyObject *mod; if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + PyObject *attr = _Py_ID(__module__); mod = PyDict_GetItemWithError(type->tp_dict, attr); if (mod == NULL) { if (!PyErr_Occurred()) { @@ -568,7 +568,7 @@ type_module(PyTypeObject *type, void *context) PyUnicode_InternInPlace(&mod); } else { - mod = _Py_GET_GLOBAL_IDENTIFIER(builtins); + mod = _Py_ID(builtins); Py_INCREF(mod); } } @@ -583,7 +583,7 @@ type_set_module(PyTypeObject *type, PyObject *value, void *context) PyType_Modified(type); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + PyObject *attr = _Py_ID(__module__); return PyDict_SetItem(type->tp_dict, attr, value); } @@ -593,7 +593,7 @@ type_abstractmethods(PyTypeObject *type, void *context) PyObject *mod = NULL; /* type itself has an __abstractmethods__ descriptor (this). Don't return that. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__abstractmethods__); + PyObject *attr = _Py_ID(__abstractmethods__); if (type != &PyType_Type) mod = PyDict_GetItemWithError(type->tp_dict, attr); if (!mod) { @@ -614,7 +614,7 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context) special to update subclasses. */ int abstract, res; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__abstractmethods__); + PyObject *attr = _Py_ID(__abstractmethods__); if (value != NULL) { abstract = PyObject_IsTrue(value); if (abstract < 0) @@ -879,7 +879,7 @@ type_get_doc(PyTypeObject *type, void *context) if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) { return _PyType_GetDocFromInternalDoc(type->tp_name, type->tp_doc); } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + PyObject *attr = _Py_ID(__doc__); result = PyDict_GetItemWithError(type->tp_dict, attr); if (result == NULL) { if (!PyErr_Occurred()) { @@ -909,7 +909,7 @@ type_set_doc(PyTypeObject *type, PyObject *value, void *context) if (!check_set_special_type_attr(type, value, "__doc__")) return -1; PyType_Modified(type); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + PyObject *attr = _Py_ID(__doc__); return PyDict_SetItem(type->tp_dict, attr, value); } @@ -923,7 +923,7 @@ type_get_annotations(PyTypeObject *type, void *context) PyObject *annotations; /* there's no _PyDict_GetItemId without WithError, so let's LBYL. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); + PyObject *attr = _Py_ID(__annotations__); if (PyDict_Contains(type->tp_dict, attr)) { annotations = PyDict_GetItemWithError(type->tp_dict, attr); /* @@ -964,7 +964,7 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context) } int result; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); + PyObject *attr = _Py_ID(__annotations__); if (value != NULL) { /* set */ result = PyDict_SetItem(type->tp_dict, attr, value); @@ -1055,7 +1055,7 @@ type_repr(PyTypeObject *type) return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(builtins); + PyObject *attr = _Py_ID(builtins); if (mod != NULL && !_PyUnicode_Equal(mod, attr)) rtn = PyUnicode_FromFormat("", mod, name); else @@ -1760,7 +1760,7 @@ static PyObject * class_name(PyObject *cls) { PyObject *name; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *attr = _Py_ID(__name__); if (_PyObject_LookupAttr(cls, attr, &name) == 0) { name = PyObject_Repr(cls); } @@ -2084,7 +2084,7 @@ mro_invoke(PyTypeObject *type) if (custom) { int unbound; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(mro); + PyObject *attr = _Py_ID(mro); PyObject *mro_meth = lookup_method((PyObject *)type, attr, &unbound); if (mro_meth == NULL) return NULL; @@ -2300,7 +2300,7 @@ get_dict_descriptor(PyTypeObject *type) { PyObject *descr; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); descr = _PyType_Lookup(type, attr); if (descr == NULL || !PyDescr_IsData(descr)) return NULL; @@ -2544,8 +2544,8 @@ type_new_visit_slots(type_new_ctx *ctx) { PyObject *slots = ctx->slots; Py_ssize_t nslot = ctx->nslot; - PyObject *__dict__ = _Py_GET_GLOBAL_IDENTIFIER(__dict__); - PyObject *__weakref__ = _Py_GET_GLOBAL_IDENTIFIER(__weakref__); + PyObject *__dict__ = _Py_ID(__dict__); + PyObject *__weakref__ = _Py_ID(__weakref__); for (Py_ssize_t i = 0; i < nslot; i++) { PyObject *name = PyTuple_GET_ITEM(slots, i); if (!valid_identifier(name)) { @@ -2593,10 +2593,10 @@ type_new_copy_slots(type_new_ctx *ctx, PyObject *dict) } Py_ssize_t j = 0; - PyObject *__dict__ = _Py_GET_GLOBAL_IDENTIFIER(__dict__); - PyObject *__weakref__ = _Py_GET_GLOBAL_IDENTIFIER(__weakref__); - PyObject *__qualname__ = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); - PyObject *__classcell__ = _Py_GET_GLOBAL_IDENTIFIER(__classcell__); + PyObject *__dict__ = _Py_ID(__dict__); + PyObject *__weakref__ = _Py_ID(__weakref__); + PyObject *__qualname__ = _Py_ID(__qualname__); + PyObject *__classcell__ = _Py_ID(__classcell__); for (Py_ssize_t i = 0; i < nslot; i++) { PyObject *slot = PyTuple_GET_ITEM(slots, i); if ((ctx->add_dict && _PyUnicode_Equal(slot, __dict__)) || @@ -2815,7 +2815,7 @@ type_new_set_name(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_set_module(PyTypeObject *type) { - PyObject *module_str = _Py_GET_GLOBAL_IDENTIFIER(__module__); + PyObject *module_str = _Py_ID(__module__); int r = PyDict_Contains(type->tp_dict, module_str); if (r < 0) { return -1; @@ -2829,7 +2829,7 @@ type_new_set_module(PyTypeObject *type) return 0; } - PyObject *__name__ = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *__name__ = _Py_ID(__name__); PyObject *module = PyDict_GetItemWithError(globals, __name__); if (module == NULL) { if (PyErr_Occurred()) { @@ -2851,7 +2851,7 @@ static int type_new_set_ht_name(PyTypeObject *type) { PyHeapTypeObject *et = (PyHeapTypeObject *)type; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + PyObject *attr = _Py_ID(__qualname__); PyObject *qualname = PyDict_GetItemWithError(type->tp_dict, attr); if (qualname != NULL) { if (!PyUnicode_Check(qualname)) { @@ -2881,7 +2881,7 @@ type_new_set_ht_name(PyTypeObject *type) static int type_new_set_doc(PyTypeObject *type) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + PyObject *attr = _Py_ID(__doc__); PyObject *doc = PyDict_GetItemWithError(type->tp_dict, attr); if (doc == NULL) { if (PyErr_Occurred()) { @@ -3051,7 +3051,7 @@ type_new_set_slots(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_set_classcell(PyTypeObject *type) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__classcell__); + PyObject *attr = _Py_ID(__classcell__); PyObject *cell = PyDict_GetItemWithError(type->tp_dict, attr); if (cell == NULL) { if (PyErr_Occurred()) { @@ -3097,18 +3097,18 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type) /* Special-case __new__: if it's a plain function, make it a static function */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + PyObject *attr = _Py_ID(__new__); if (type_new_staticmethod(type, attr) < 0) { return -1; } /* Special-case __init_subclass__ and __class_getitem__: if they are plain functions, make them classmethods */ - attr = _Py_GET_GLOBAL_IDENTIFIER(__init_subclass__); + attr = _Py_ID(__init_subclass__); if (type_new_classmethod(type, attr) < 0) { return -1; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__class_getitem__); + attr = _Py_ID(__class_getitem__); if (type_new_classmethod(type, attr) < 0) { return -1; } @@ -3129,7 +3129,7 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_get_slots(type_new_ctx *ctx, PyObject *dict) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__slots__); + PyObject *attr = _Py_ID(__slots__); PyObject *slots = PyDict_GetItemWithError(dict, attr); if (slots == NULL) { if (PyErr_Occurred()) { @@ -3259,7 +3259,7 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type) continue; } PyObject *mro_entries; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__mro_entries__); + PyObject *attr = _Py_ID(__mro_entries__); if (_PyObject_LookupAttr(base, attr, &mro_entries) < 0) { return -1; } @@ -3609,7 +3609,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) PyObject *__doc__ = PyUnicode_FromString(_PyType_DocWithoutSignature(type->tp_name, type->tp_doc)); if (!__doc__) goto fail; - attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + attr = _Py_ID(__doc__); r = PyDict_SetItem(type->tp_dict, attr, __doc__); Py_DECREF(__doc__); if (r < 0) @@ -3628,7 +3628,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) } /* Set type.__module__ */ - attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + attr = _Py_ID(__module__); r = PyDict_Contains(type->tp_dict, attr); if (r < 0) { goto fail; @@ -4226,7 +4226,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass) assert(aclass); /* Merge in the type's dict (if any). */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); if (_PyObject_LookupAttr(aclass, attr, &classdict) < 0) { return -1; } @@ -4238,7 +4238,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass) } /* Recursively merge in the base types' (if any) dicts. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(__bases__); + attr = _Py_ID(__bases__); if (_PyObject_LookupAttr(aclass, attr, &bases) < 0) { return -1; } @@ -4632,7 +4632,7 @@ object_repr(PyObject *self) Py_XDECREF(mod); return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(builtins); + PyObject *attr = _Py_ID(builtins); if (mod != NULL && !_PyUnicode_Equal(mod, attr)) rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self); else @@ -4927,7 +4927,7 @@ static PyObject * import_copyreg(void) { PyObject *copyreg_module; - PyObject *copyreg_str = _Py_GET_GLOBAL_IDENTIFIER(copyreg); + PyObject *copyreg_str = _Py_ID(copyreg); /* Try to fetch cached copy of copyreg from sys.modules first in an attempt to avoid the import overhead. Previously this was implemented @@ -4953,7 +4953,7 @@ _PyType_GetSlotNames(PyTypeObject *cls) assert(PyType_Check(cls)); /* Get the slot names from the cache in the class if possible. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__slotnames__); + PyObject *attr = _Py_ID(__slotnames__); slotnames = PyDict_GetItemWithError(cls->tp_dict, attr); if (slotnames != NULL) { if (slotnames != Py_None && !PyList_Check(slotnames)) { @@ -4980,7 +4980,7 @@ _PyType_GetSlotNames(PyTypeObject *cls) /* Use _slotnames function from the copyreg module to find the slots by this class and its bases. This function will cache the result in __slotnames__. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(_slotnames); + attr = _Py_ID(_slotnames); slotnames = PyObject_CallMethodOneArg(copyreg, attr, (PyObject *)cls); Py_DECREF(copyreg); if (slotnames == NULL) @@ -5002,7 +5002,7 @@ _PyObject_GetState(PyObject *obj, int required) PyObject *state; PyObject *getstate; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getstate__); + PyObject *attr = _Py_ID(__getstate__); if (_PyObject_LookupAttr(obj, attr, &getstate) < 0) { return NULL; } @@ -5147,7 +5147,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* We first attempt to fetch the arguments for __new__ by calling __getnewargs_ex__ on the object. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getnewargs_ex__); + PyObject *attr = _Py_ID(__getnewargs_ex__); getnewargs_ex = _PyObject_LookupSpecial(obj, attr); if (getnewargs_ex != NULL) { PyObject *newargs = _PyObject_CallNoArgs(getnewargs_ex); @@ -5201,7 +5201,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* The object does not have __getnewargs_ex__ so we fallback on using __getnewargs__ instead. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(__getnewargs__); + attr = _Py_ID(__getnewargs__); getnewargs = _PyObject_LookupSpecial(obj, attr); if (getnewargs != NULL) { *args = _PyObject_CallNoArgs(getnewargs); @@ -5255,7 +5255,7 @@ _PyObject_GetItemsIter(PyObject *obj, PyObject **listitems, Py_INCREF(*dictitems); } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(items); + PyObject *attr = _Py_ID(items); PyObject *items = PyObject_CallMethodNoArgs(obj, attr); if (items == NULL) { Py_CLEAR(*listitems); @@ -5304,7 +5304,7 @@ reduce_newobj(PyObject *obj) Py_ssize_t i, n; Py_XDECREF(kwargs); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__newobj__); + PyObject *attr = _Py_ID(__newobj__); newobj = PyObject_GetAttr(copyreg, attr); Py_DECREF(copyreg); if (newobj == NULL) { @@ -5329,7 +5329,7 @@ reduce_newobj(PyObject *obj) Py_XDECREF(args); } else if (args != NULL) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__newobj_ex__); + PyObject *attr = _Py_ID(__newobj_ex__); newobj = PyObject_GetAttr(copyreg, attr); Py_DECREF(copyreg); if (newobj == NULL) { @@ -5437,7 +5437,7 @@ object___reduce_ex___impl(PyObject *self, int protocol) static PyObject *objreduce; PyObject *reduce, *res; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__reduce__); + PyObject *attr = _Py_ID(__reduce__); if (objreduce == NULL) { objreduce = PyDict_GetItemWithError(PyBaseObject_Type.tp_dict, attr); if (objreduce == NULL && PyErr_Occurred()) { @@ -5561,7 +5561,7 @@ object___dir___impl(PyObject *self) PyObject *itsclass = NULL; /* Get __dict__ (which may or may not be a real dict...) */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); if (_PyObject_LookupAttr(self, attr, &dict) < 0) { return NULL; } @@ -5583,7 +5583,7 @@ object___dir___impl(PyObject *self) goto error; /* Merge in attrs reachable from its class. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + attr = _Py_ID(__class__); if (_PyObject_LookupAttr(self, attr, &itsclass) < 0) { goto error; } @@ -5852,10 +5852,10 @@ overrides_hash(PyTypeObject *type) PyObject *dict = type->tp_dict; assert(dict != NULL); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__eq__); + PyObject *attr = _Py_ID(__eq__); int r = PyDict_Contains(dict, attr); if (r == 0) { - attr = _Py_GET_GLOBAL_IDENTIFIER(__hash__); + attr = _Py_ID(__hash__); r = PyDict_Contains(dict, attr); } return r; @@ -6171,7 +6171,7 @@ type_ready_set_dict(PyTypeObject *type) static int type_dict_set_doc(PyTypeObject *type) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + PyObject *attr = _Py_ID(__doc__); int r = PyDict_Contains(type->tp_dict, attr); if (r < 0) { return -1; @@ -6343,7 +6343,7 @@ type_ready_set_hash(PyTypeObject *type) return 0; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__hash__); + PyObject *attr = _Py_ID(__hash__); int r = PyDict_Contains(type->tp_dict, attr); if (r < 0) { return -1; @@ -7169,7 +7169,7 @@ static struct PyMethodDef tp_new_methoddef[] = { static int add_tp_new_wrapper(PyTypeObject *type) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + PyObject *attr = _Py_ID(__new__); int r = PyDict_Contains(type->tp_dict, attr); if (r > 0) { return 0; @@ -7195,7 +7195,7 @@ static PyObject * \ FUNCNAME(PyObject *self) \ { \ PyObject* stack[1] = {self}; \ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(DUNDER); \ + PyObject *attr = _Py_ID(DUNDER); \ return vectorcall_method(attr, stack, 1); \ } @@ -7204,7 +7204,7 @@ static PyObject * \ FUNCNAME(PyObject *self, ARG1TYPE arg1) \ { \ PyObject* stack[2] = {self, arg1}; \ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(DUNDER); \ + PyObject *attr = _Py_ID(DUNDER); \ return vectorcall_method(attr, stack, 2); \ } @@ -7247,8 +7247,8 @@ FUNCNAME(PyObject *self, PyObject *other) \ { \ PyObject* stack[2]; \ PyThreadState *tstate = _PyThreadState_GET(); \ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(DUNDER); \ - PyObject *rattr = _Py_GET_GLOBAL_IDENTIFIER(RDUNDER); \ + PyObject *attr = _Py_ID(DUNDER); \ + PyObject *rattr = _Py_ID(RDUNDER); \ int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \ Py_TYPE(other)->tp_as_number != NULL && \ Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \ @@ -7293,7 +7293,7 @@ static Py_ssize_t slot_sq_length(PyObject *self) { PyObject* stack[1] = {self}; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__len__); + PyObject *attr = _Py_ID(__len__); PyObject *res = vectorcall_method(attr, stack, 1); Py_ssize_t len; @@ -7326,7 +7326,7 @@ slot_sq_item(PyObject *self, Py_ssize_t i) return NULL; } PyObject *stack[2] = {self, ival}; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getitem__); + PyObject *attr = _Py_ID(__getitem__); PyObject *retval = vectorcall_method(attr, stack, 2); Py_DECREF(ival); return retval; @@ -7347,12 +7347,12 @@ slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value) stack[0] = self; stack[1] = index_obj; if (value == NULL) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__delitem__); + PyObject *attr = _Py_ID(__delitem__); res = vectorcall_method(attr, stack, 2); } else { stack[2] = value; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + PyObject *attr = _Py_ID(__setitem__); res = vectorcall_method(attr, stack, 3); } Py_DECREF(index_obj); @@ -7371,7 +7371,7 @@ slot_sq_contains(PyObject *self, PyObject *value) PyObject *func, *res; int result = -1, unbound; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__contains__); + PyObject *attr = _Py_ID(__contains__); func = lookup_maybe_method(self, attr, &unbound); if (func == Py_None) { Py_DECREF(func); @@ -7410,12 +7410,12 @@ slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value) stack[0] = self; stack[1] = key; if (value == NULL) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__delitem__); + PyObject *attr = _Py_ID(__delitem__); res = vectorcall_method(attr, stack, 2); } else { stack[2] = value; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + PyObject *attr = _Py_ID(__setitem__); res = vectorcall_method(attr, stack, 3); } @@ -7447,7 +7447,7 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus) if (Py_TYPE(self)->tp_as_number != NULL && Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) { PyObject* stack[3] = {self, other, modulus}; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__pow__); + PyObject *attr = _Py_ID(__pow__); return vectorcall_method(attr, stack, 3); } Py_RETURN_NOTIMPLEMENTED; @@ -7464,14 +7464,14 @@ slot_nb_bool(PyObject *self) int result, unbound; int using_len = 0; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__bool__); + PyObject *attr = _Py_ID(__bool__); func = lookup_maybe_method(self, attr, &unbound); if (func == NULL) { if (PyErr_Occurred()) { return -1; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__len__); + attr = _Py_ID(__len__); func = lookup_maybe_method(self, attr, &unbound); if (func == NULL) { if (PyErr_Occurred()) { @@ -7516,7 +7516,7 @@ static PyObject * slot_nb_index(PyObject *self) { PyObject *stack[1] = {self}; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__index__); + PyObject *attr = _Py_ID(__index__); return vectorcall_method(attr, stack, 1); } @@ -7540,7 +7540,7 @@ static PyObject * slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2) { PyObject *stack[2] = {self, arg1}; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__ipow__); + PyObject *attr = _Py_ID(__ipow__); return vectorcall_method(attr, stack, 2); } SLOT1(slot_nb_inplace_lshift, __ilshift__, PyObject *) @@ -7560,7 +7560,7 @@ slot_tp_repr(PyObject *self) PyObject *func, *res; int unbound; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__repr__); + PyObject *attr = _Py_ID(__repr__); func = lookup_maybe_method(self, attr, &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); @@ -7581,7 +7581,7 @@ slot_tp_hash(PyObject *self) Py_ssize_t h; int unbound; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__hash__); + PyObject *attr = _Py_ID(__hash__); func = lookup_maybe_method(self, attr, &unbound); if (func == Py_None) { @@ -7629,7 +7629,7 @@ slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__call__); + PyObject *attr = _Py_ID(__call__); PyObject *meth = lookup_method(self, attr, &unbound); if (meth == NULL) { return NULL; @@ -7662,7 +7662,7 @@ static PyObject * slot_tp_getattro(PyObject *self, PyObject *name) { PyObject *stack[2] = {self, name}; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getattribute__); + PyObject *attr = _Py_ID(__getattribute__); return vectorcall_method(attr, stack, 2); } @@ -7695,7 +7695,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) __getattr__, even when the attribute is present. So we use _PyType_Lookup and create the method only when needed, with call_attribute. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__getattr__); + PyObject *attr = _Py_ID(__getattr__); getattr = _PyType_Lookup(tp, attr); if (getattr == NULL) { /* No __getattr__ hook: use a simpler dispatcher */ @@ -7708,7 +7708,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) __getattr__, even when self has the default __getattribute__ method. So we use _PyType_Lookup and create the method only when needed, with call_attribute. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(__getattribute__); + attr = _Py_ID(__getattribute__); getattribute = _PyType_Lookup(tp, attr); if (getattribute == NULL || (Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) && @@ -7737,12 +7737,12 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) stack[0] = self; stack[1] = name; if (value == NULL) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__delattr__); + PyObject *attr = _Py_ID(__delattr__); res = vectorcall_method(attr, stack, 2); } else { stack[2] = value; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__setattr__); + PyObject *attr = _Py_ID(__setattr__); res = vectorcall_method(attr, stack, 3); } if (res == NULL) @@ -7752,12 +7752,12 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) } static PyObject *name_op[] = { - _Py_GET_GLOBAL_IDENTIFIER(__lt__), - _Py_GET_GLOBAL_IDENTIFIER(__le__), - _Py_GET_GLOBAL_IDENTIFIER(__eq__), - _Py_GET_GLOBAL_IDENTIFIER(__ne__), - _Py_GET_GLOBAL_IDENTIFIER(__gt__), - _Py_GET_GLOBAL_IDENTIFIER(__ge__), + _Py_ID(__lt__), + _Py_ID(__le__), + _Py_ID(__eq__), + _Py_ID(__ne__), + _Py_ID(__gt__), + _Py_ID(__ge__), }; static PyObject * @@ -7784,7 +7784,7 @@ slot_tp_iter(PyObject *self) int unbound; PyObject *func, *res; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__iter__); + PyObject *attr = _Py_ID(__iter__); func = lookup_maybe_method(self, attr, &unbound); if (func == Py_None) { Py_DECREF(func); @@ -7801,7 +7801,7 @@ slot_tp_iter(PyObject *self) } PyErr_Clear(); - attr = _Py_GET_GLOBAL_IDENTIFIER(__getitem__); + attr = _Py_ID(__getitem__); func = lookup_maybe_method(self, attr, &unbound); if (func == NULL) { PyErr_Format(PyExc_TypeError, @@ -7817,7 +7817,7 @@ static PyObject * slot_tp_iternext(PyObject *self) { PyObject *stack[1] = {self}; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__next__); + PyObject *attr = _Py_ID(__next__); return vectorcall_method(attr, stack, 1); } @@ -7827,7 +7827,7 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type) PyTypeObject *tp = Py_TYPE(self); PyObject *get; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__get__); + PyObject *attr = _Py_ID(__get__); get = _PyType_Lookup(tp, attr); if (get == NULL) { /* Avoid further slowdowns */ @@ -7852,12 +7852,12 @@ slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value) stack[0] = self; stack[1] = target; if (value == NULL) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__delete__); + PyObject *attr = _Py_ID(__delete__); res = vectorcall_method(attr, stack, 2); } else { stack[2] = value; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__set__); + PyObject *attr = _Py_ID(__set__); res = vectorcall_method(attr, stack, 3); } if (res == NULL) @@ -7872,7 +7872,7 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__init__); + PyObject *attr = _Py_ID(__init__); PyObject *meth = lookup_method(self, attr, &unbound); if (meth == NULL) { return -1; @@ -7905,7 +7905,7 @@ slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); PyObject *func, *result; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__new__); + PyObject *attr = _Py_ID(__new__); func = PyObject_GetAttr((PyObject *)type, attr); if (func == NULL) { return NULL; @@ -7927,7 +7927,7 @@ slot_tp_finalize(PyObject *self) PyErr_Fetch(&error_type, &error_value, &error_traceback); /* Execute __del__ method, if any. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__del__); + PyObject *attr = _Py_ID(__del__); del = lookup_maybe_method(self, attr, &unbound); if (del != NULL) { res = call_unbound_noarg(unbound, del, self); @@ -7948,7 +7948,7 @@ slot_am_await(PyObject *self) int unbound; PyObject *func, *res; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__await__); + PyObject *attr = _Py_ID(__await__); func = lookup_maybe_method(self, attr, &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); @@ -7967,7 +7967,7 @@ slot_am_aiter(PyObject *self) int unbound; PyObject *func, *res; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__aiter__); + PyObject *attr = _Py_ID(__aiter__); func = lookup_maybe_method(self, attr, &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); @@ -7986,7 +7986,7 @@ slot_am_anext(PyObject *self) int unbound; PyObject *func, *res; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__anext__); + PyObject *attr = _Py_ID(__anext__); func = lookup_maybe_method(self, attr, &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); @@ -8618,7 +8618,7 @@ type_new_set_names(PyTypeObject *type) Py_ssize_t i = 0; PyObject *key, *value; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__set_name__); + PyObject *attr = _Py_ID(__set_name__); while (PyDict_Next(names_to_set, &i, &key, &value)) { PyObject *set_name = _PyObject_LookupSpecial(value, attr); if (set_name == NULL) { @@ -8660,7 +8660,7 @@ type_new_init_subclass(PyTypeObject *type, PyObject *kwds) return -1; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__init_subclass__); + PyObject *attr = _Py_ID(__init_subclass__); PyObject *func = PyObject_GetAttr(super, attr); Py_DECREF(super); if (func == NULL) { @@ -8869,7 +8869,7 @@ super_getattro(PyObject *self, PyObject *name) /* We want __class__ to return the class of the super object (i.e. super, or a subclass), not the class of su->obj. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + PyObject *attr = _Py_ID(__class__); if (PyUnicode_Check(name) && PyUnicode_GET_LENGTH(name) == 9 && _PyUnicode_Equal(name, attr)) @@ -8964,7 +8964,7 @@ supercheck(PyTypeObject *type, PyObject *obj) /* Try the slow way */ PyObject *class_attr; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + PyObject *attr = _Py_ID(__class__); if (_PyObject_LookupAttr(obj, attr, &class_attr) < 0) { return NULL; } @@ -9056,7 +9056,7 @@ super_init_without_args(InterpreterFrame *cframe, PyCodeObject *co, assert((_PyLocals_GetKind(co->co_localspluskinds, i) & CO_FAST_FREE) != 0); PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); assert(PyUnicode_Check(name)); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__class__); + PyObject *attr = _Py_ID(__class__); if (_PyUnicode_Equal(name, attr)) { PyObject *cell = _PyFrame_GetLocalsArray(cframe)[i]; if (cell == NULL || !PyCell_Check(cell)) { diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index ce9676e0aaba185..efe62efc5039dce 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15780,7 +15780,7 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(iter); + PyObject *attr = _Py_ID(iter); if (it->it_seq != NULL) { return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), it->it_seq, it->it_index); diff --git a/Objects/unionobject.c b/Objects/unionobject.c index 14cd23d462d00e1..7518d711769c004 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -265,14 +265,14 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p) return _PyUnicodeWriter_WriteASCIIString(writer, "None", 4); } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__origin__); + PyObject *attr = _Py_ID(__origin__); if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { goto exit; } if (tmp) { Py_DECREF(tmp); - attr = _Py_GET_GLOBAL_IDENTIFIER(__args__); + attr = _Py_ID(__args__); if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { goto exit; } @@ -283,14 +283,14 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p) } } - attr = _Py_GET_GLOBAL_IDENTIFIER(__qualname__); + attr = _Py_ID(__qualname__); if (_PyObject_LookupAttr(p, attr, &qualname) < 0) { goto exit; } if (qualname == NULL) { goto use_repr; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + attr = _Py_ID(__module__); if (_PyObject_LookupAttr(p, attr, &module) < 0) { goto exit; } diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index 31e35799f7ae25a..b896822fd9b9376 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -170,7 +170,7 @@ weakref_repr(PyWeakReference *self) } Py_INCREF(obj); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *attr = _Py_ID(__name__); if (_PyObject_LookupAttr(obj, attr, &name) < 0) { Py_DECREF(obj); return NULL; @@ -464,7 +464,7 @@ proxy_checkref(PyWeakReference *proxy) method(PyObject *proxy, PyObject *Py_UNUSED(ignored)) { \ UNWRAP(proxy); \ Py_INCREF(proxy); \ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(special); \ + PyObject *attr = _Py_ID(special); \ PyObject* res = PyObject_CallMethodNoArgs(proxy, attr); \ Py_DECREF(proxy); \ return res; \ diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 6cbe8fb6bdfa381..6bb18be00a43df4 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -459,8 +459,8 @@ fp_setreadl(struct tok_state *tok, const char* enc) return 0; } - PyObject *str_open = _Py_GET_GLOBAL_IDENTIFIER(open); - PyObject *str_readline = _Py_GET_GLOBAL_IDENTIFIER(readline); + PyObject *str_open = _Py_ID(open); + PyObject *str_readline = _Py_ID(readline); io = PyImport_ImportModule("io"); if (io == NULL) { diff --git a/Python/_warnings.c b/Python/_warnings.c index 9d37cdf4072df23..ac289e21f3a38c9 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -105,7 +105,7 @@ init_filters(PyInterpreterState *interp) size_t pos = 0; /* Post-incremented in each use. */ #define ADD(TYPE, ACTION, MODNAME) \ do { \ - PyObject *action = _Py_GET_GLOBAL_IDENTIFIER(ACTION); \ + PyObject *action = _Py_ID(ACTION); \ PyList_SET_ITEM(filters, pos++, create_filter(TYPE, action, MODNAME)); \ } while (0) ADD(PyExc_DeprecationWarning, default, "__main__"); @@ -179,7 +179,7 @@ check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg) } /* Otherwise assume a regex filter and call its match() method */ - PyObject *str_match = _Py_GET_GLOBAL_IDENTIFIER(match); + PyObject *str_match = _Py_ID(match); result = PyObject_CallMethodOneArg(obj, str_match, arg); if (result == NULL) return -1; @@ -191,7 +191,7 @@ check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg) #define GET_WARNINGS_ATTR(interp, attr, try_import) \ get_warnings_attr(interp, \ - _Py_GET_GLOBAL_IDENTIFIER(attr), \ + _Py_ID(attr), \ try_import) /* @@ -204,7 +204,7 @@ get_warnings_attr(PyInterpreterState *interp, PyObject *attr, int try_import) PyObject *warnings_str; PyObject *warnings_module, *obj; - warnings_str = _Py_GET_GLOBAL_IDENTIFIER(warnings); + warnings_str = _Py_ID(warnings); /* don't try to import after the start of the Python finallization */ if (try_import && !_Py_IsFinalizing()) { @@ -413,7 +413,7 @@ already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key, if (st == NULL) { return -1; } - PyObject *str_version = _Py_GET_GLOBAL_IDENTIFIER(version); + PyObject *str_version = _Py_ID(version); version_obj = _PyDict_GetItemWithError(registry, str_version); if (version_obj == NULL || !PyLong_CheckExact(version_obj) @@ -512,13 +512,13 @@ show_warning(PyThreadState *tstate, PyObject *filename, int lineno, PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno); - attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + attr = _Py_ID(__name__); name = PyObject_GetAttr(category, attr); if (name == NULL) { goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + attr = _Py_ID(stderr); f_stderr = _PySys_GetAttr(tstate, attr); if (f_stderr == NULL) { fprintf(stderr, "lost sys.stderr\n"); @@ -891,7 +891,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, /* Setup registry. */ assert(globals != NULL); assert(PyDict_Check(globals)); - PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__warningregistry__); + PyObject *key = _Py_ID(__warningregistry__); *registry = _PyDict_GetItemWithError(globals, key); if (*registry == NULL) { int rc; @@ -911,7 +911,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, Py_INCREF(*registry); /* Setup module. */ - key = _Py_GET_GLOBAL_IDENTIFIER(__name__); + key = _Py_ID(__name__); *module = _PyDict_GetItemWithError(globals, key); if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) { Py_INCREF(*module); @@ -1020,13 +1020,13 @@ get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno PyObject *source_line; /* Check/get the requisite pieces needed for the loader. */ - key = _Py_GET_GLOBAL_IDENTIFIER(__loader__); + key = _Py_ID(__loader__); loader = _PyDict_GetItemWithError(module_globals, key); if (loader == NULL) { return NULL; } Py_INCREF(loader); - key = _Py_GET_GLOBAL_IDENTIFIER(__name__); + key = _Py_ID(__name__); module_name = _PyDict_GetItemWithError(module_globals, key); if (!module_name) { Py_DECREF(loader); @@ -1035,7 +1035,7 @@ get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno Py_INCREF(module_name); /* Make sure the loader implements the optional get_source() method. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(get_source); + PyObject *attr = _Py_ID(get_source); (void)_PyObject_LookupAttr(loader, attr, &get_source); Py_DECREF(loader); if (!get_source) { diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index ea54eba8de03ac2..908859d114a276b 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -32,7 +32,7 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs) } continue; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__mro_entries__); + PyObject *attr = _Py_ID(__mro_entries__); if (_PyObject_LookupAttr(base, attr, &meth) < 0) { goto error; } @@ -134,7 +134,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, goto error; } - PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(metaclass); + PyObject *key = _Py_ID(metaclass); meta = _PyDict_GetItemWithError(mkw, key); if (meta != NULL) { Py_INCREF(meta); @@ -178,7 +178,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, } /* else: meta is not a class, so we cannot do the metaclass calculation, so we will use the explicitly given object as it is */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__prepare__); + PyObject *attr = _Py_ID(__prepare__); if (_PyObject_LookupAttr(meta, attr, &prep) < 0) { ns = NULL; } @@ -934,7 +934,7 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, return NULL; } - PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); + PyObject *key = _Py_ID(__builtins__); int r = PyDict_Contains(globals, key); if (r == 0) { r = PyDict_SetItem(globals, key, PyEval_GetBuiltins()); @@ -1022,7 +1022,7 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, Py_TYPE(locals)->tp_name); return NULL; } - PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); + PyObject *key = _Py_ID(__builtins__); int r = PyDict_Contains(globals, key); if (r == 0) { r = PyDict_SetItem(globals, key, PyEval_GetBuiltins()); @@ -1949,7 +1949,7 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, if (file == Py_None) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stdout); + PyObject *attr = _Py_ID(stdout); file = _PySys_GetAttr(tstate, attr); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); @@ -2010,7 +2010,7 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, } if (flush) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *attr = _Py_ID(flush); PyObject *tmp = PyObject_CallMethodNoArgs(file, attr); if (tmp == NULL) { return NULL; @@ -2043,11 +2043,11 @@ builtin_input_impl(PyObject *module, PyObject *prompt) { PyThreadState *tstate = _PyThreadState_GET(); PyObject *fin = _PySys_GetAttr( - tstate, _Py_GET_GLOBAL_IDENTIFIER(stdin)); + tstate, _Py_ID(stdin)); PyObject *fout = _PySys_GetAttr( - tstate, _Py_GET_GLOBAL_IDENTIFIER(stdout)); + tstate, _Py_ID(stdout)); PyObject *ferr = _PySys_GetAttr( - tstate, _Py_GET_GLOBAL_IDENTIFIER(stderr)); + tstate, _Py_ID(stderr)); PyObject *tmp; long fd; int tty; @@ -2074,7 +2074,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) } /* First of all, flush stderr */ - PyObject *str_flush = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *str_flush = _Py_ID(flush); tmp = PyObject_CallMethodNoArgs(ferr, str_flush); if (tmp == NULL) PyErr_Clear(); @@ -2084,7 +2084,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) /* We should only use (GNU) readline if Python's sys.stdin and sys.stdout are the same as C's stdin and stdout, because we need to pass it those. */ - PyObject *str_fileno = _Py_GET_GLOBAL_IDENTIFIER(fileno); + PyObject *str_fileno = _Py_ID(fileno); tmp = PyObject_CallMethodNoArgs(fin, str_fileno); if (tmp == NULL) { PyErr_Clear(); @@ -2122,8 +2122,8 @@ builtin_input_impl(PyObject *module, PyObject *prompt) const char *stdin_encoding_str, *stdin_errors_str; PyObject *result; size_t len; - PyObject *str_encoding = _Py_GET_GLOBAL_IDENTIFIER(encoding); - PyObject *str_errors = _Py_GET_GLOBAL_IDENTIFIER(errors); + PyObject *str_encoding = _Py_ID(encoding); + PyObject *str_errors = _Py_ID(errors); /* stdin is a text stream, so it must have an encoding. */ stdin_encoding = PyObject_GetAttr(fin, str_encoding); @@ -2284,7 +2284,7 @@ builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits) return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__round__); + PyObject *attr = _Py_ID(__round__); round = _PyObject_LookupSpecial(number, attr); if (round == NULL) { if (!PyErr_Occurred()) @@ -2346,7 +2346,7 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject if (newlist == NULL) return NULL; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(sort); + PyObject *attr = _Py_ID(sort); callable = PyObject_GetAttr(newlist, attr); if (callable == NULL) { Py_DECREF(newlist); @@ -2379,7 +2379,7 @@ builtin_vars(PyObject *self, PyObject *args) Py_XINCREF(d); } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + PyObject *attr = _Py_ID(__dict__); if (_PyObject_LookupAttr(v, attr, &d) == 0) { PyErr_SetString(PyExc_TypeError, "vars() argument must have __dict__ attribute"); diff --git a/Python/ceval.c b/Python/ceval.c index b75f9a96eb20442..93a85867f3bdbc3 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -879,7 +879,7 @@ match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys) // - Atomically check for a key and get its value without error handling. // - Don't cause key creation or resizing in dict subclasses like // collections.defaultdict that define __missing__ (or similar). - get_name = _Py_GET_GLOBAL_IDENTIFIER(get); + get_name = _Py_ID(get); int meth_found = _PyObject_GetMethod(map, get_name, &get); if (get == NULL) { goto fail; @@ -1731,7 +1731,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr #ifdef LLTRACE { - PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__ltrace__); + PyObject *key = _Py_ID(__ltrace__); int r = PyDict_Contains(GLOBALS(), key); if (r < 0) { goto exit_unwind; @@ -2367,7 +2367,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(PRINT_EXPR) { PyObject *value = POP(); - PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(displayhook); + PyObject *key = _Py_ID(displayhook); PyObject *hook = _PySys_GetAttr(tstate, key); PyObject *res; if (hook == NULL) { @@ -2577,7 +2577,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr retval = Py_TYPE(receiver)->tp_iternext(receiver); } else { - PyObject *name = _Py_GET_GLOBAL_IDENTIFIER(send); + PyObject *name = _Py_ID(send); retval = PyObject_CallMethodOneArg(receiver, name, v); } if (retval == NULL) { @@ -2713,7 +2713,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(LOAD_BUILD_CLASS) { PyObject *bc; if (PyDict_CheckExact(BUILTINS())) { - PyObject *name = _Py_GET_GLOBAL_IDENTIFIER(__build_class__); + PyObject *name = _Py_ID(__build_class__); bc = _PyDict_GetItemWithError(BUILTINS(), name); if (bc == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -2725,7 +2725,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr Py_INCREF(bc); } else { - PyObject *build_class_str = _Py_GET_GLOBAL_IDENTIFIER(__build_class__); + PyObject *build_class_str = _Py_ID(__build_class__); bc = PyObject_GetItem(BUILTINS(), build_class_str); if (bc == NULL) { if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) @@ -3288,7 +3288,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } /* check if __annotations__ in locals()... */ if (PyDict_CheckExact(LOCALS())) { - PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); + PyObject *key = _Py_ID(__annotations__); ann_dict = _PyDict_GetItemWithError(LOCALS(), key); if (ann_dict == NULL) { if (_PyErr_Occurred(tstate)) { @@ -3308,7 +3308,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } else { /* do the same if locals() is not a dict */ - PyObject *ann_str = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); + PyObject *ann_str = _Py_ID(__annotations__); ann_dict = PyObject_GetItem(LOCALS(), ann_str); if (ann_dict == NULL) { if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) { @@ -4223,7 +4223,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(BEFORE_ASYNC_WITH) { PyObject *mgr = TOP(); PyObject *res; - PyObject *str_aenter = _Py_GET_GLOBAL_IDENTIFIER(__aenter__); + PyObject *str_aenter = _Py_ID(__aenter__); PyObject *enter = _PyObject_LookupSpecial(mgr, str_aenter); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -4234,7 +4234,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *str_aexit = _Py_GET_GLOBAL_IDENTIFIER(__aexit__); + PyObject *str_aexit = _Py_ID(__aexit__); PyObject *exit = _PyObject_LookupSpecial(mgr, str_aexit); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -4261,7 +4261,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(BEFORE_WITH) { PyObject *mgr = TOP(); PyObject *res; - PyObject *str_enter = _Py_GET_GLOBAL_IDENTIFIER(__enter__); + PyObject *str_enter = _Py_ID(__enter__); PyObject *enter = _PyObject_LookupSpecial(mgr, str_enter); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -4272,7 +4272,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *str_exit = _Py_GET_GLOBAL_IDENTIFIER(__exit__); + PyObject *str_exit = _Py_ID(__exit__); PyObject *exit = _PyObject_LookupSpecial(mgr, str_exit); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -7072,7 +7072,7 @@ import_name(PyThreadState *tstate, InterpreterFrame *frame, PyObject *import_func, *res; PyObject* stack[5]; - PyObject *key = _Py_GET_GLOBAL_IDENTIFIER(__import__); + PyObject *key = _Py_ID(__import__); import_func = _PyDict_GetItemWithError(frame->f_builtins, key); if (import_func == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -7120,7 +7120,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name) /* Issue #17636: in case this failed because of a circular relative import, try to fallback on reading the module directly from sys.modules. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + PyObject *attr = _Py_ID(__name__); pkgname = PyObject_GetAttr(v, attr); if (pkgname == NULL) { goto error; @@ -7163,7 +7163,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name) PyErr_SetImportError(errmsg, pkgname, NULL); } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + PyObject *attr = _Py_ID(__spec__); PyObject *spec = PyObject_GetAttr(v, attr); const char *fmt = _PyModuleSpec_IsInitializing(spec) ? @@ -7190,12 +7190,12 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v) int skip_leading_underscores = 0; int pos, err; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__all__); + PyObject *attr = _Py_ID(__all__); if (_PyObject_LookupAttr(v, attr, &all) < 0) { return -1; /* Unexpected error */ } if (all == NULL) { - attr = _Py_GET_GLOBAL_IDENTIFIER(__dict__); + attr = _Py_ID(__dict__); if (_PyObject_LookupAttr(v, attr, &dict) < 0) { return -1; } @@ -7223,7 +7223,7 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v) break; } if (!PyUnicode_Check(name)) { - attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + attr = _Py_ID(__name__); PyObject *modname = PyObject_GetAttr(v, attr); if (modname == NULL) { Py_DECREF(name); @@ -7430,7 +7430,7 @@ format_exc_check_arg(PyThreadState *tstate, PyObject *exc, if (PyErr_GivenExceptionMatches(value, PyExc_NameError)) { // We do not care if this fails because we are going to restore the // NameError anyway. - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(name); + PyObject *attr = _Py_ID(name); (void)PyObject_SetAttr(value, attr, obj); } PyErr_Restore(type, value, traceback); diff --git a/Python/codecs.c b/Python/codecs.c index cd817e81d0348ae..1dea0a579dfb3dc 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -535,7 +535,7 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding, * attribute. */ if (!PyTuple_CheckExact(codec)) { - PyObject *is_text_encoding = _Py_GET_GLOBAL_IDENTIFIER(_is_text_encoding); + PyObject *is_text_encoding = _Py_ID(_is_text_encoding); if (_PyObject_LookupAttr(codec, is_text_encoding, &attr) < 0) { Py_DECREF(codec); return NULL; diff --git a/Python/compile.c b/Python/compile.c index 879f8416c8deb9c..3b86fb42dbf9f2f 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1613,7 +1613,7 @@ compiler_enter_scope(struct compiler *c, identifier name, int res; assert(u->u_scope_type == COMPILER_SCOPE_CLASS); assert(PyDict_GET_SIZE(u->u_cellvars) == 0); - name = _Py_GET_GLOBAL_IDENTIFIER(__class__); + name = _Py_ID(__class__); res = PyDict_SetItem(u->u_cellvars, name, _PyLong_GetZero()); if (res < 0) { compiler_unit_free(u); @@ -1999,7 +1999,7 @@ compiler_body(struct compiler *c, asdl_stmt_seq *stmts) int i = 0; stmt_ty st; PyObject *docstring; - PyObject *__doc__ = _Py_GET_GLOBAL_IDENTIFIER(__doc__); + PyObject *__doc__ = _Py_ID(__doc__); /* Set current line number to the line number of first statement. This way line number for SETUP_ANNOTATIONS will always @@ -2334,7 +2334,7 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args, args->kwarg->annotation, &annotations_len)) return 0; - identifier return_str = _Py_GET_GLOBAL_IDENTIFIER(return); + identifier return_str = _Py_ID(return); if (!compiler_visit_argannotation(c, return_str, returns, &annotations_len)) { return 0; } @@ -5922,7 +5922,7 @@ compiler_annassign(struct compiler *c, stmt_ty s) { expr_ty targ = s->v.AnnAssign.target; PyObject* mangled; - PyObject *__annotations__ = _Py_GET_GLOBAL_IDENTIFIER(__annotations__); + PyObject *__annotations__ = _Py_ID(__annotations__); assert(s->kind == AnnAssign_kind); diff --git a/Python/errors.c b/Python/errors.c index 2669d2eaaa12507..dbc74be9fe78cdb 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -1129,7 +1129,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) goto failure; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + PyObject *attr = _Py_ID(__module__); int r = PyDict_Contains(dict, attr); if (r < 0) { goto failure; @@ -1342,7 +1342,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, assert(PyExceptionClass_Check(exc_type)); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + PyObject *attr = _Py_ID(__module__); PyObject *modulename = PyObject_GetAttr(exc_type, attr); if (modulename == NULL || !PyUnicode_Check(modulename)) { Py_XDECREF(modulename); @@ -1352,8 +1352,8 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, } } else { - PyObject *builtins = _Py_GET_GLOBAL_IDENTIFIER(builtins); - PyObject *__main__ = _Py_GET_GLOBAL_IDENTIFIER(__main__); + PyObject *builtins = _Py_ID(builtins); + PyObject *__main__ = _Py_ID(__main__); if (!_PyUnicode_Equal(modulename, builtins) && !_PyUnicode_Equal(modulename, __main__)) { if (PyFile_WriteObject(modulename, file, Py_PRINT_RAW) < 0) { @@ -1403,7 +1403,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, } /* Explicitly call file.flush() */ - PyObject *flush = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *flush = _Py_ID(flush); PyObject *res = _PyObject_CallMethodNoArgs(file, flush); if (!res) { return -1; @@ -1419,7 +1419,7 @@ write_unraisable_exc(PyThreadState *tstate, PyObject *exc_type, PyObject *exc_value, PyObject *exc_tb, PyObject *err_msg, PyObject *obj) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *attr = _Py_ID(stderr); PyObject *file = _PySys_GetAttr(tstate, attr); if (file == NULL || file == Py_None) { return 0; @@ -1524,7 +1524,7 @@ _PyErr_WriteUnraisableMsg(const char *err_msg_str, PyObject *obj) goto error; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(unraisablehook); + PyObject *attr = _Py_ID(unraisablehook); PyObject *hook = _PySys_GetAttr(tstate, attr); if (hook == NULL) { Py_DECREF(hook_args); @@ -1611,7 +1611,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, if (tmp == NULL) _PyErr_Clear(tstate); else { - attr = _Py_GET_GLOBAL_IDENTIFIER(lineno); + attr = _Py_ID(lineno); if (PyObject_SetAttr(v, attr, tmp)) { _PyErr_Clear(tstate); } @@ -1624,7 +1624,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - attr = _Py_GET_GLOBAL_IDENTIFIER(offset); + attr = _Py_ID(offset); if (PyObject_SetAttr(v, attr, tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } @@ -1637,7 +1637,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - attr = _Py_GET_GLOBAL_IDENTIFIER(end_lineno); + attr = _Py_ID(end_lineno); if (PyObject_SetAttr(v, attr, tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } @@ -1650,7 +1650,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - attr = _Py_GET_GLOBAL_IDENTIFIER(end_offset); + attr = _Py_ID(end_offset); if (PyObject_SetAttr(v, attr, tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } @@ -1658,14 +1658,14 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, tmp = NULL; if (filename != NULL) { - attr = _Py_GET_GLOBAL_IDENTIFIER(filename); + attr = _Py_ID(filename); if (PyObject_SetAttr(v, attr, filename)) { _PyErr_Clear(tstate); } tmp = PyErr_ProgramTextObject(filename, lineno); if (tmp) { - attr = _Py_GET_GLOBAL_IDENTIFIER(text); + attr = _Py_ID(text); if (PyObject_SetAttr(v, attr, tmp)) { _PyErr_Clear(tstate); } @@ -1676,7 +1676,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, } } if (exc != PyExc_SyntaxError) { - attr = _Py_GET_GLOBAL_IDENTIFIER(msg); + attr = _Py_ID(msg); if (_PyObject_LookupAttr(v, attr, &tmp) < 0) { _PyErr_Clear(tstate); } @@ -1696,7 +1696,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, } } - attr = _Py_GET_GLOBAL_IDENTIFIER(print_file_and_line); + attr = _Py_ID(print_file_and_line); if (_PyObject_LookupAttr(v, attr, &tmp) < 0) { _PyErr_Clear(tstate); } diff --git a/Python/import.c b/Python/import.c index af9b135cb21051b..a20c903badae7bb 100644 --- a/Python/import.c +++ b/Python/import.c @@ -73,7 +73,7 @@ _PyImportZip_Init(PyThreadState *tstate) } } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(zipimporter); + PyObject *attr = _Py_ID(zipimporter); PyObject *zipimporter = PyObject_GetAttr(zipimport, attr); Py_DECREF(zipimport); if (zipimporter == NULL) { @@ -348,12 +348,12 @@ import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *n NOTE: because of this, initializing must be set *before* stuffing the new module in sys.modules. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + attr = _Py_ID(__spec__); spec = PyObject_GetAttr(mod, attr); int busy = _PyModuleSpec_IsInitializing(spec); Py_XDECREF(spec); if (busy) { - attr = _Py_GET_GLOBAL_IDENTIFIER(_lock_unlock_module); + attr = _Py_ID(_lock_unlock_module); /* Wait until module is done importing. */ PyObject *value = _PyObject_CallMethodOneArg( interp->importlib, attr, name); @@ -716,7 +716,7 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, external= PyObject_GetAttrString(interp->importlib, "_bootstrap_external"); if (external != NULL) { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_get_sourcefile); + PyObject *attr = _Py_ID(_get_sourcefile); pathobj = _PyObject_CallMethodOneArg(external, attr, cpathobj); Py_DECREF(external); } @@ -745,7 +745,7 @@ module_dict_for_exec(PyThreadState *tstate, PyObject *name) /* If the module is being reloaded, we get the old module back and re-use its dict to exec the new code. */ d = PyModule_GetDict(m); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); + PyObject *attr = _Py_ID(__builtins__); int r = PyDict_Contains(d, attr); if (r == 0) { r = PyDict_SetItem(d, attr, PyEval_GetBuiltins()); @@ -805,7 +805,7 @@ PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname, Py_DECREF(d); return NULL; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_fix_up_module); + PyObject *attr = _Py_ID(_fix_up_module); res = PyObject_CallMethodObjArgs(external, attr, d, name, pathname, cpathname, NULL); Py_DECREF(external); @@ -1544,7 +1544,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level _PyErr_SetString(tstate, PyExc_TypeError, "globals must be a dict"); goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__package__); + attr = _Py_ID(__package__); package = PyDict_GetItemWithError(globals, attr); if (package == Py_None) { package = NULL; @@ -1552,7 +1552,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level else if (package == NULL && _PyErr_Occurred(tstate)) { goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__spec__); + attr = _Py_ID(__spec__); spec = PyDict_GetItemWithError(globals, attr); if (spec == NULL && _PyErr_Occurred(tstate)) { goto error; @@ -1567,7 +1567,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level } else if (spec != NULL && spec != Py_None) { int equal; - attr = _Py_GET_GLOBAL_IDENTIFIER(parent); + attr = _Py_ID(parent); PyObject *parent = PyObject_GetAttr(spec, attr); if (parent == NULL) { goto error; @@ -1587,7 +1587,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level } } else if (spec != NULL && spec != Py_None) { - attr = _Py_GET_GLOBAL_IDENTIFIER(parent); + attr = _Py_ID(parent); package = PyObject_GetAttr(spec, attr); if (package == NULL) { goto error; @@ -1605,7 +1605,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__name__); + attr = _Py_ID(__name__); package = PyDict_GetItemWithError(globals, attr); if (package == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -1622,7 +1622,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(__path__); + attr = _Py_ID(__path__); int haspath = PyDict_Contains(globals, attr); if (haspath < 0) { goto error; @@ -1731,7 +1731,7 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name) if (PyDTrace_IMPORT_FIND_LOAD_START_ENABLED()) PyDTrace_IMPORT_FIND_LOAD_START(PyUnicode_AsUTF8(abs_name)); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(_find_and_load); + PyObject *attr = _Py_ID(_find_and_load); mod = PyObject_CallMethodObjArgs(interp->importlib, attr, abs_name, interp->import_func, NULL); @@ -1897,13 +1897,13 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, } else { PyObject *path; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__path__); + PyObject *attr = _Py_ID(__path__); if (_PyObject_LookupAttr(mod, attr, &path) < 0) { goto error; } if (path) { Py_DECREF(path); - attr = _Py_GET_GLOBAL_IDENTIFIER(_handle_fromlist); + attr = _Py_ID(_handle_fromlist); final_mod = PyObject_CallMethodObjArgs( interp->importlib, attr, mod, fromlist, interp->import_func, NULL); @@ -1946,7 +1946,7 @@ PyObject * PyImport_ReloadModule(PyObject *m) { PyObject *reloaded_module = NULL; - PyObject *name = _Py_GET_GLOBAL_IDENTIFIER(importlib); + PyObject *name = _Py_ID(importlib); PyObject *importlib = PyImport_GetModule(name); if (importlib == NULL) { if (PyErr_Occurred()) { @@ -1959,7 +1959,7 @@ PyImport_ReloadModule(PyObject *m) } } - name = _Py_GET_GLOBAL_IDENTIFIER(reload); + name = _Py_ID(reload); reloaded_module = PyObject_CallMethodOneArg(importlib, name, m); Py_DECREF(importlib); return reloaded_module; @@ -1984,8 +1984,8 @@ PyImport_Import(PyObject *module_name) PyObject *builtins = NULL; PyObject *r = NULL; - PyObject *import_str = _Py_GET_GLOBAL_IDENTIFIER(__import__); - PyObject *builtins_str = _Py_GET_GLOBAL_IDENTIFIER(__builtins__); + PyObject *import_str = _Py_ID(__import__); + PyObject *builtins_str = _Py_ID(__builtins__); PyObject *from_list = PyList_New(0); if (from_list == NULL) { diff --git a/Python/importdl.c b/Python/importdl.c index e9b547d05c99684..b68862e5a4ddbd7 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -78,7 +78,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) { } /* Replace '-' by '_' */ - PyObject *replace = _Py_GET_GLOBAL_IDENTIFIER(replace); + PyObject *replace = _Py_ID(replace); modname = _PyObject_CallMethod(encoded, replace, "cc", '-', '_'); if (modname == NULL) goto error; diff --git a/Python/marshal.c b/Python/marshal.c index a087fc4c2a95a50..015859c3450a464 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -712,7 +712,7 @@ r_string(Py_ssize_t n, RFILE *p) if (mview == NULL) return NULL; - PyObject *readinto = _Py_GET_GLOBAL_IDENTIFIER(readinto); + PyObject *readinto = _Py_ID(readinto); res = _PyObject_CallMethod(p->readable, readinto, "N", mview); if (res != NULL) { read = PyNumber_AsSsize_t(res, PyExc_ValueError); @@ -1717,7 +1717,7 @@ marshal_dump_impl(PyObject *module, PyObject *value, PyObject *file, s = PyMarshal_WriteObjectToString(value, version); if (s == NULL) return NULL; - PyObject *write = _Py_GET_GLOBAL_IDENTIFIER(write); + PyObject *write = _Py_ID(write); res = _PyObject_CallMethodOneArg(file, write, s); Py_DECREF(s); return res; @@ -1754,7 +1754,7 @@ marshal_load(PyObject *module, PyObject *file) * This can be removed if we guarantee good error handling * for r_string() */ - PyObject *read = _Py_GET_GLOBAL_IDENTIFIER(read); + PyObject *read = _Py_ID(read); data = _PyObject_CallMethod(file, read, "i", 0); if (data == NULL) return NULL; diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index e69601e6c222f56..16a0508709451cc 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -21,7 +21,7 @@ #include "pycore_pylifecycle.h" // _PyErr_Print() #include "pycore_pymem.h" // _PyObject_DebugMallocStats() #include "pycore_pystate.h" // _PyThreadState_GET() -#include "pycore_runtime.h" // _Py_GET_GLOBAL_IDENTIFIER() +#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() @@ -1438,7 +1438,7 @@ finalize_clear_modules_dict(PyObject *modules) PyDict_Clear(modules); } else { - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(clear); + PyObject *attr = _Py_ID(clear); if (PyObject_CallMethodNoArgs(modules, attr) == NULL) { PyErr_WriteUnraisable(NULL); } @@ -1611,9 +1611,9 @@ static int flush_std_files(void) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *fout = _PySys_GetAttr(tstate, _Py_GET_GLOBAL_IDENTIFIER(stdout)); - PyObject *ferr = _PySys_GetAttr(tstate, _Py_GET_GLOBAL_IDENTIFIER(stderr)); - PyObject *flush = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *fout = _PySys_GetAttr(tstate, _Py_ID(stdout)); + PyObject *ferr = _PySys_GetAttr(tstate, _Py_ID(stderr)); + PyObject *flush = _Py_ID(flush); PyObject *tmp; int status = 0; @@ -2235,7 +2235,7 @@ create_stdio(const PyConfig *config, PyObject* io, mode = "wb"; else mode = "rb"; - attr = _Py_GET_GLOBAL_IDENTIFIER(open); + attr = _Py_ID(open); buf = _PyObject_CallMethod(io, attr, "isiOOOO", fd, mode, buffering, Py_None, Py_None, /* encoding, errors */ @@ -2244,7 +2244,7 @@ create_stdio(const PyConfig *config, PyObject* io, goto error; if (buffering) { - attr = _Py_GET_GLOBAL_IDENTIFIER(raw); + attr = _Py_ID(raw); raw = PyObject_GetAttr(buf, attr); if (raw == NULL) goto error; @@ -2261,10 +2261,10 @@ create_stdio(const PyConfig *config, PyObject* io, #endif text = PyUnicode_FromString(name); - attr = _Py_GET_GLOBAL_IDENTIFIER(name); + attr = _Py_ID(name); if (text == NULL || PyObject_SetAttr(raw, attr, text) < 0) goto error; - attr = _Py_GET_GLOBAL_IDENTIFIER(isatty); + attr = _Py_ID(isatty); res = PyObject_CallMethodNoArgs(raw, attr); if (res == NULL) goto error; @@ -2308,7 +2308,7 @@ create_stdio(const PyConfig *config, PyObject* io, goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(TextIOWrapper); + attr = _Py_ID(TextIOWrapper); stream = _PyObject_CallMethod(io, attr, "OOOsOO", buf, encoding_str, errors_str, newline, line_buffering, write_through); @@ -2323,7 +2323,7 @@ create_stdio(const PyConfig *config, PyObject* io, else mode = "r"; text = PyUnicode_FromString(mode); - attr = _Py_GET_GLOBAL_IDENTIFIER(mode); + attr = _Py_ID(mode); if (!text || PyObject_SetAttr(stream, attr, text) < 0) goto error; Py_CLEAR(text); @@ -2423,7 +2423,7 @@ init_sys_streams(PyThreadState *tstate) if (std == NULL) goto error; PySys_SetObject("__stdin__", std); - attr = _Py_GET_GLOBAL_IDENTIFIER(stdin); + attr = _Py_ID(stdin); _PySys_SetAttr(attr, std); Py_DECREF(std); @@ -2435,7 +2435,7 @@ init_sys_streams(PyThreadState *tstate) if (std == NULL) goto error; PySys_SetObject("__stdout__", std); - attr = _Py_GET_GLOBAL_IDENTIFIER(stdout); + attr = _Py_ID(stdout); _PySys_SetAttr(attr, std); Py_DECREF(std); @@ -2465,7 +2465,7 @@ init_sys_streams(PyThreadState *tstate) Py_DECREF(std); goto error; } - attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + attr = _Py_ID(stderr); if (_PySys_SetAttr(attr, std) < 0) { Py_DECREF(std); goto error; @@ -2516,7 +2516,7 @@ _Py_FatalError_PrintExc(PyThreadState *tstate) return 0; } - attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + attr = _Py_ID(stderr); ferr = _PySys_GetAttr(tstate, attr); if (ferr == NULL || ferr == Py_None) { /* sys.stderr is not set yet or set to None, @@ -2542,7 +2542,7 @@ _Py_FatalError_PrintExc(PyThreadState *tstate) Py_XDECREF(tb); /* sys.stderr may be buffered: call sys.stderr.flush() */ - attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + attr = _Py_ID(flush); res = PyObject_CallMethodNoArgs(ferr, attr); if (res == NULL) { _PyErr_Clear(tstate); @@ -2896,7 +2896,7 @@ static void wait_for_thread_shutdown(PyThreadState *tstate) { PyObject *result; - PyObject *name = _Py_GET_GLOBAL_IDENTIFIER(threading); + PyObject *name = _Py_ID(threading); PyObject *threading = PyImport_GetModule(name); if (threading == NULL) { if (_PyErr_Occurred(tstate)) { @@ -2905,7 +2905,7 @@ wait_for_thread_shutdown(PyThreadState *tstate) /* else: threading not imported */ return; } - name = _Py_GET_GLOBAL_IDENTIFIER(_shutdown); + name = _Py_ID(_shutdown); result = PyObject_CallMethodNoArgs(threading, name); if (result == NULL) { PyErr_WriteUnraisable(threading); diff --git a/Python/pythonrun.c b/Python/pythonrun.c index c9fffb788f6c53e..69720378d6f7bf2 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -117,13 +117,13 @@ _PyRun_InteractiveLoopObject(FILE *fp, PyObject *filename, PyCompilerFlags *flag } PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(ps1); + PyObject *attr = _Py_ID(ps1); PyObject *v = _PySys_GetAttr(tstate, attr); if (v == NULL) { _PySys_SetAttr(attr, v = PyUnicode_FromString(">>> ")); Py_XDECREF(v); } - attr = _Py_GET_GLOBAL_IDENTIFIER(ps2); + attr = _Py_ID(ps2); v = _PySys_GetAttr(tstate, attr); if (v == NULL) { _PySys_SetAttr(attr, v = PyUnicode_FromString("... ")); @@ -194,14 +194,14 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, const char *ps1 = "", *ps2 = "", *enc = NULL; int errcode = 0; PyThreadState *tstate = _PyThreadState_GET(); - mod_name = _Py_GET_GLOBAL_IDENTIFIER(__main__); + mod_name = _Py_ID(__main__); if (fp == stdin) { /* Fetch encoding from sys.stdin if possible. */ - attr = _Py_GET_GLOBAL_IDENTIFIER(stdin); + attr = _Py_ID(stdin); v = _PySys_GetAttr(tstate, attr); if (v && v != Py_None) { - attr = _Py_GET_GLOBAL_IDENTIFIER(encoding); + attr = _Py_ID(encoding); oenc = PyObject_GetAttr(v, attr); if (oenc) enc = PyUnicode_AsUTF8(oenc); @@ -209,7 +209,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, PyErr_Clear(); } } - attr = _Py_GET_GLOBAL_IDENTIFIER(ps1); + attr = _Py_ID(ps1); v = _PySys_GetAttr(tstate, attr); if (v != NULL) { v = PyObject_Str(v); @@ -223,7 +223,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, } } } - attr = _Py_GET_GLOBAL_IDENTIFIER(ps2); + attr = _Py_ID(ps2); w = _PySys_GetAttr(tstate, attr); if (w != NULL) { w = PyObject_Str(w); @@ -513,12 +513,12 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *filename = NULL; /* new style errors. `err' is an instance */ - attr = _Py_GET_GLOBAL_IDENTIFIER(msg); + attr = _Py_ID(msg); *message = PyObject_GetAttr(err, attr); if (!*message) goto finally; - attr = _Py_GET_GLOBAL_IDENTIFIER(filename); + attr = _Py_ID(filename); v = PyObject_GetAttr(err, attr); if (!v) goto finally; @@ -531,7 +531,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *filename = v; } - attr = _Py_GET_GLOBAL_IDENTIFIER(lineno); + attr = _Py_ID(lineno); v = PyObject_GetAttr(err, attr); if (!v) goto finally; @@ -541,7 +541,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, goto finally; *lineno = hold; - attr = _Py_GET_GLOBAL_IDENTIFIER(offset); + attr = _Py_ID(offset); v = PyObject_GetAttr(err, attr); if (!v) goto finally; @@ -557,7 +557,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, } if (Py_TYPE(err) == (PyTypeObject*)PyExc_SyntaxError) { - attr = _Py_GET_GLOBAL_IDENTIFIER(end_lineno); + attr = _Py_ID(end_lineno); v = PyObject_GetAttr(err, attr); if (!v) { PyErr_Clear(); @@ -574,7 +574,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *end_lineno = hold; } - attr = _Py_GET_GLOBAL_IDENTIFIER(end_offset); + attr = _Py_ID(end_offset); v = PyObject_GetAttr(err, attr); if (!v) { PyErr_Clear(); @@ -596,7 +596,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *end_offset = -1; } - attr = _Py_GET_GLOBAL_IDENTIFIER(text); + attr = _Py_ID(text); v = PyObject_GetAttr(err, attr); if (!v) goto finally; @@ -731,7 +731,7 @@ _Py_HandleSystemExit(int *exitcode_p) if (PyExceptionInstance_Check(value)) { /* The error code should be in the `code' attribute. */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(code); + PyObject *attr = _Py_ID(code); PyObject *code = PyObject_GetAttr(value, attr); if (code) { Py_DECREF(value); @@ -748,7 +748,7 @@ _Py_HandleSystemExit(int *exitcode_p) } else { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *attr = _Py_ID(stderr); PyObject *sys_stderr = _PySys_GetAttr(tstate, attr); /* We clear the exception here to avoid triggering the assertion * in PyObject_Str that ensures it won't silently lose exception @@ -812,20 +812,20 @@ _PyErr_PrintEx(PyThreadState *tstate, int set_sys_last_vars) /* Now we know v != NULL too */ if (set_sys_last_vars) { - attr = _Py_GET_GLOBAL_IDENTIFIER(last_type); + attr = _Py_ID(last_type); if (_PySys_SetAttr(attr, exception) < 0) { _PyErr_Clear(tstate); } - attr = _Py_GET_GLOBAL_IDENTIFIER(last_value); + attr = _Py_ID(last_value); if (_PySys_SetAttr(attr, v) < 0) { _PyErr_Clear(tstate); } - attr = _Py_GET_GLOBAL_IDENTIFIER(last_traceback); + attr = _Py_ID(last_traceback); if (_PySys_SetAttr(attr, tb) < 0) { _PyErr_Clear(tstate); } } - attr = _Py_GET_GLOBAL_IDENTIFIER(excepthook); + attr = _Py_ID(excepthook); hook = _PySys_GetAttr(tstate, attr); if (_PySys_Audit(tstate, "sys.excepthook", "OOOO", hook ? hook : Py_None, exception, v, tb) < 0) { @@ -972,7 +972,7 @@ print_exception_file_and_line(struct exception_print_context *ctx, PyObject *f = ctx->file; PyObject *tmp; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(print_file_and_line); + PyObject *attr = _Py_ID(print_file_and_line); int res = _PyObject_LookupAttr(*value_p, attr, &tmp); if (res <= 0) { if (res < 0) { @@ -1048,7 +1048,7 @@ print_exception_message(struct exception_print_context *ctx, PyObject *type, if (write_indented_margin(ctx, f) < 0) { return -1; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__module__); + PyObject *attr = _Py_ID(__module__); PyObject *modulename = PyObject_GetAttr(type, attr); if (modulename == NULL || !PyUnicode_Check(modulename)) { Py_XDECREF(modulename); @@ -1058,8 +1058,8 @@ print_exception_message(struct exception_print_context *ctx, PyObject *type, } } else { - if (!_PyUnicode_Equal(modulename, _Py_GET_GLOBAL_IDENTIFIER(builtins)) && - !_PyUnicode_Equal(modulename, _Py_GET_GLOBAL_IDENTIFIER(__main__))) + if (!_PyUnicode_Equal(modulename, _Py_ID(builtins)) && + !_PyUnicode_Equal(modulename, _Py_ID(__main__))) { int res = PyFile_WriteObject(modulename, f, Py_PRINT_RAW); Py_DECREF(modulename); @@ -1159,7 +1159,7 @@ print_exception_note(struct exception_print_context *ctx, PyObject *value) return 0; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__note__); + PyObject *attr = _Py_ID(__note__); PyObject *note = PyObject_GetAttr(value, attr); if (note == NULL) { return -1; @@ -1545,7 +1545,7 @@ _PyErr_Display(PyObject *file, PyObject *exception, PyObject *value, PyObject *t Py_XDECREF(ctx.seen); /* Call file.flush() */ - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *attr = _Py_ID(flush); PyObject *res = _PyObject_CallMethodNoArgs(file, attr); if (!res) { /* Silently ignore file.flush() error */ @@ -1560,7 +1560,7 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *attr = _Py_ID(stderr); PyObject *file = _PySys_GetAttr(tstate, attr); if (file == NULL) { _PyObject_Dump(value); @@ -1649,13 +1649,13 @@ flush_io(void) { PyObject *f, *r; PyObject *type, *value, *traceback; - PyObject *flush = _Py_GET_GLOBAL_IDENTIFIER(flush); + PyObject *flush = _Py_ID(flush); /* Save the current exception */ PyErr_Fetch(&type, &value, &traceback); PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *attr = _Py_ID(stderr); f = _PySys_GetAttr(tstate, attr); if (f != NULL) { r = _PyObject_CallMethodNoArgs(f, flush); @@ -1664,7 +1664,7 @@ flush_io(void) else PyErr_Clear(); } - attr = _Py_GET_GLOBAL_IDENTIFIER(stdout); + attr = _Py_ID(stdout); f = _PySys_GetAttr(tstate, attr); if (f != NULL) { r = _PyObject_CallMethodNoArgs(f, flush); diff --git a/Python/specialize.c b/Python/specialize.c index cb679461107292b..34e2b6b6116a0ac 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -1,7 +1,7 @@ #include "Python.h" #include "pycore_code.h" #include "pycore_dict.h" -#include "pycore_global_strings.h" // _Py_GET_GLOBAL_IDENTIFIER() +#include "pycore_global_strings.h" // _Py_ID() #include "pycore_long.h" #include "pycore_moduleobject.h" #include "pycore_object.h" @@ -565,7 +565,7 @@ specialize_module_load_attr( SPECIALIZATION_FAIL(opcode, SPEC_FAIL_NON_STRING_OR_SPLIT); return -1; } - PyObject *getattr = _Py_GET_GLOBAL_IDENTIFIER(__getattr__); + PyObject *getattr = _Py_ID(__getattr__); Py_ssize_t index = _PyDict_GetItemHint(dict, getattr, -1, &value); assert(index != DKIX_ERROR); if (index != DKIX_EMPTY) { @@ -1209,7 +1209,7 @@ _Py_Specialize_BinarySubscr( goto success; } PyTypeObject *cls = Py_TYPE(container); - PyObject *getitem = _Py_GET_GLOBAL_IDENTIFIER(__getitem__); + PyObject *getitem = _Py_ID(__getitem__); PyObject *descriptor = _PyType_Lookup(cls, getitem); if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) { PyFunctionObject *func = (PyFunctionObject *)descriptor; @@ -1327,7 +1327,7 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins } goto fail; } - PyObject *setitem = _Py_GET_GLOBAL_IDENTIFIER(__setitem__); + PyObject *setitem = _Py_ID(__setitem__); PyObject *descriptor = _PyType_Lookup(container_type, setitem); if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) { PyFunctionObject *func = (PyFunctionObject *)descriptor; @@ -1427,7 +1427,7 @@ specialize_method_descriptor( return -1; } if (_list_append == NULL) { - PyObject *append = _Py_GET_GLOBAL_IDENTIFIER(append); + PyObject *append = _Py_ID(append); _list_append = (PyMethodDescrObject *)_PyType_Lookup(&PyList_Type, append); } assert(_list_append != NULL); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 4d61f34f58c92ec..2910ae633c6cf01 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -268,7 +268,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event, /* Disallow tracing in hooks unless explicitly enabled */ PyThreadState_EnterTracing(ts); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(__cantrace__); + PyObject *attr = _Py_ID(__cantrace__); while ((hook = PyIter_Next(hooks)) != NULL) { PyObject *o; int canTrace = _PyObject_LookupAttr(hook, attr, &o); @@ -642,7 +642,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) const char *stdout_encoding_str; int ret; - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(encoding); + PyObject *attr = _Py_ID(encoding); stdout_encoding = PyObject_GetAttr(outf, attr); if (stdout_encoding == NULL) goto error; @@ -660,13 +660,13 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) if (encoded == NULL) goto error; - attr = _Py_GET_GLOBAL_IDENTIFIER(buffer); + attr = _Py_ID(buffer); if (_PyObject_LookupAttr(outf, attr, &buffer) < 0) { Py_DECREF(encoded); goto error; } if (buffer) { - attr = _Py_GET_GLOBAL_IDENTIFIER(write); + attr = _Py_ID(write); result = PyObject_CallMethodOneArg(buffer, attr, encoded); Py_DECREF(buffer); Py_DECREF(encoded); @@ -713,7 +713,7 @@ sys_displayhook(PyObject *module, PyObject *o) static PyObject *newline = NULL; PyThreadState *tstate = _PyThreadState_GET(); - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(builtins); + PyObject *str = _Py_ID(builtins); builtins = PyImport_GetModule(str); if (builtins == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -730,10 +730,10 @@ sys_displayhook(PyObject *module, PyObject *o) if (o == Py_None) { Py_RETURN_NONE; } - str = _Py_GET_GLOBAL_IDENTIFIER(_); + str = _Py_ID(_); if (PyObject_SetAttr(builtins, str, Py_None) != 0) return NULL; - outf = _PySys_GetAttr(tstate, _Py_GET_GLOBAL_IDENTIFIER(stdout)); + outf = _PySys_GetAttr(tstate, _Py_ID(stdout)); if (outf == NULL || outf == Py_None) { _PyErr_SetString(tstate, PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -1692,7 +1692,7 @@ _PySys_GetSizeOf(PyObject *o) return (size_t)-1; } - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(__sizeof__); + PyObject *str = _Py_ID(__sizeof__); method = _PyObject_LookupSpecial(o, str); if (method == NULL) { if (!_PyErr_Occurred(tstate)) { @@ -2235,7 +2235,7 @@ _PySys_ReadPreinitXOptions(PyConfig *config) static PyObject * get_warnoptions(PyThreadState *tstate) { - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(warnoptions); + PyObject *str = _Py_ID(warnoptions); PyObject *warnoptions = _PySys_GetAttr(tstate, str); if (warnoptions == NULL || !PyList_Check(warnoptions)) { /* PEP432 TODO: we can reach this if warnoptions is NULL in the main @@ -2270,7 +2270,7 @@ PySys_ResetWarnOptions(void) return; } - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(warnoptions); + PyObject *str = _Py_ID(warnoptions); PyObject *warnoptions = _PySys_GetAttr(tstate, str); if (warnoptions == NULL || !PyList_Check(warnoptions)) return; @@ -2325,7 +2325,7 @@ int PySys_HasWarnOptions(void) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(warnoptions); + PyObject *str = _Py_ID(warnoptions); PyObject *warnoptions = _PySys_GetAttr(tstate, str); return (warnoptions != NULL && PyList_Check(warnoptions) && PyList_GET_SIZE(warnoptions) > 0); @@ -2334,7 +2334,7 @@ PySys_HasWarnOptions(void) static PyObject * get_xoptions(PyThreadState *tstate) { - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(_xoptions); + PyObject *str = _Py_ID(_xoptions); PyObject *xoptions = _PySys_GetAttr(tstate, str); if (xoptions == NULL || !PyDict_Check(xoptions)) { /* PEP432 TODO: we can reach this if xoptions is NULL in the main @@ -3053,7 +3053,7 @@ _PySys_SetPreliminaryStderr(PyObject *sysdict) if (pstderr == NULL) { goto error; } - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *str = _Py_ID(stderr); if (PyDict_SetItem(sysdict, str, pstderr) < 0) { goto error; } @@ -3179,7 +3179,7 @@ PySys_SetPath(const wchar_t *path) if ((v = makepathobject(path, DELIM)) == NULL) Py_FatalError("can't create sys.path"); PyInterpreterState *interp = _PyInterpreterState_GET(); - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(path); + PyObject *str = _Py_ID(path); if (sys_set_object(interp, str, v) != 0) { Py_FatalError("can't assign sys.path"); } @@ -3237,7 +3237,7 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) Py_FatalError("can't compute path0 from argv"); } - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(path); + PyObject *str = _Py_ID(path); PyObject *sys_path = _PySys_GetAttr(tstate, str); if (sys_path != NULL) { if (PyList_Insert(sys_path, 0, path0) < 0) { @@ -3265,7 +3265,7 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) if (file == NULL) return -1; assert(unicode != NULL); - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(write); + PyObject *str = _Py_ID(write); PyObject *result = _PyObject_CallMethodOneArg(file, str, unicode); if (result == NULL) { return -1; @@ -3350,7 +3350,7 @@ PySys_WriteStdout(const char *format, ...) va_list va; va_start(va, format); - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stdout); + PyObject *str = _Py_ID(stdout); sys_write(str, stdout, format, va); va_end(va); } @@ -3361,7 +3361,7 @@ PySys_WriteStderr(const char *format, ...) va_list va; va_start(va, format); - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *str = _Py_ID(stderr); sys_write(str, stderr, format, va); va_end(va); } @@ -3395,7 +3395,7 @@ PySys_FormatStdout(const char *format, ...) va_list va; va_start(va, format); - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stdout); + PyObject *str = _Py_ID(stdout); sys_format(str, stdout, format, va); va_end(va); } @@ -3406,7 +3406,7 @@ PySys_FormatStderr(const char *format, ...) va_list va; va_start(va, format); - PyObject *str = _Py_GET_GLOBAL_IDENTIFIER(stderr); + PyObject *str = _Py_ID(stderr); sys_format(str, stderr, format, va); va_end(va); } diff --git a/Python/traceback.c b/Python/traceback.c index 9b6aa445b23a987..ca928f024235c88 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -331,13 +331,13 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * taillen = strlen(tail); PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(path); + PyObject *attr = _Py_ID(path); syspath = _PySys_GetAttr(tstate, attr); if (syspath == NULL || !PyList_Check(syspath)) goto error; npath = PyList_Size(syspath); - open = PyObject_GetAttr(io, _Py_GET_GLOBAL_IDENTIFIER(open)); + open = PyObject_GetAttr(io, _Py_ID(open)); for (i = 0; i < npath; i++) { v = PyList_GetItem(syspath, i); if (v == NULL) { @@ -453,7 +453,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int return -1; } - PyObject *attr = _Py_GET_GLOBAL_IDENTIFIER(open); + PyObject *attr = _Py_ID(open); binary = _PyObject_CallMethod(io, attr, "Os", filename, "rb"); if (binary == NULL) { PyErr_Clear(); @@ -483,12 +483,12 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int PyMem_Free(found_encoding); return 0; } - attr = _Py_GET_GLOBAL_IDENTIFIER(TextIOWrapper); + attr = _Py_ID(TextIOWrapper); fob = _PyObject_CallMethod(io, attr, "Os", binary, encoding); Py_DECREF(io); PyMem_Free(found_encoding); - PyObject *close = _Py_GET_GLOBAL_IDENTIFIER(close); + PyObject *close = _Py_ID(close); if (fob == NULL) { PyErr_Clear(); diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index 80ba2dcfdf7c39e..674d93aa58f473b 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -457,7 +457,7 @@ def err(msg): .*? (?: (?: - _Py_GET_GLOBAL_IDENTIFIER + _Py_ID [(] ( \w+ ) # [)] From 72316f471cc4238ffe4ed3b558bf075250944683 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 10:57:28 -0700 Subject: [PATCH 104/115] _Py_GET_GLOBAL_STRING() -> _Py_STR(). --- Include/internal/pycore_global_strings.h | 2 +- Modules/_pickle.c | 2 +- Objects/typeobject.c | 2 +- Objects/unicodeobject.c | 4 ++-- Python/ast_opt.c | 4 ++-- Python/compile.c | 18 +++++++++--------- Python/pythonrun.c | 4 ++-- Tools/scripts/generate_global_objects.py | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index cab9a2531ccf1cd..c75fb8271db04e2 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -327,7 +327,7 @@ struct _Py_global_strings { #define _Py_ID(NAME) \ (&_Py_SINGLETON(strings.identifiers.spamspamspam_ ## NAME._ascii.ob_base)) -#define _Py_GET_GLOBAL_STRING(NAME) \ +#define _Py_STR(NAME) \ (&_Py_SINGLETON(strings.literals.spamspamspam_ ## NAME._ascii.ob_base)) diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 60cf384c7ca0f94..3a8351c4659250b 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1820,7 +1820,7 @@ get_dotted_path(PyObject *obj, PyObject *name) PyObject *dotted_path; Py_ssize_t i, n; - PyObject *dot = _Py_GET_GLOBAL_STRING(dot); + PyObject *dot = _Py_STR(dot); dotted_path = PyUnicode_Split(name, dot, -1); if (dotted_path == NULL) return NULL; diff --git a/Objects/typeobject.c b/Objects/typeobject.c index fc5f611874ac9b6..f6644077d455d93 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4578,7 +4578,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) Py_DECREF(sorted_methods); return NULL; } - comma = _Py_GET_GLOBAL_STRING(comma_sep); + comma = _Py_STR(comma_sep); joined = PyUnicode_Join(comma, sorted_methods); method_count = PyObject_Length(sorted_methods); Py_DECREF(sorted_methods); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index efe62efc5039dce..340d3389a716a9a 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -260,7 +260,7 @@ get_unicode_state(void) // Return a borrowed reference to the empty string singleton. static inline PyObject* unicode_get_empty(void) { - return _Py_GET_GLOBAL_STRING(empty); + return _Py_STR(empty); } @@ -15534,7 +15534,7 @@ _PyUnicode_InitGlobalObjects(PyInterpreterState *interp) } #ifdef Py_DEBUG - PyObject *empty = _Py_GET_GLOBAL_STRING(empty); + PyObject *empty = _Py_STR(empty); assert(_PyUnicode_CheckConsistency(empty, 1)); #endif diff --git a/Python/ast_opt.c b/Python/ast_opt.c index 0463b3994d8f6c1..60b878a4d3395b6 100644 --- a/Python/ast_opt.c +++ b/Python/ast_opt.c @@ -268,8 +268,8 @@ parse_literal(PyObject *fmt, Py_ssize_t *ppos, PyArena *arena) PyObject *str = PyUnicode_Substring(fmt, start, pos); /* str = str.replace('%%', '%') */ if (str && has_percents) { - PyObject *double_percent = _Py_GET_GLOBAL_STRING(dbl_percent); - PyObject *percent = _Py_GET_GLOBAL_STRING(percent); + PyObject *double_percent = _Py_STR(dbl_percent); + PyObject *percent = _Py_STR(percent); Py_SETREF(str, PyUnicode_Replace(str, double_percent, percent, -1)); } if (!str) { diff --git a/Python/compile.c b/Python/compile.c index 3b86fb42dbf9f2f..107c1286863471c 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -668,7 +668,7 @@ compiler_set_qualname(struct compiler *c) || parent->u_scope_type == COMPILER_SCOPE_ASYNC_FUNCTION || parent->u_scope_type == COMPILER_SCOPE_LAMBDA) { - dot_locals_str = _Py_GET_GLOBAL_STRING(dot_locals); + dot_locals_str = _Py_STR(dot_locals); base = PyUnicode_Concat(parent->u_qualname, dot_locals_str); if (base == NULL) return 0; @@ -681,7 +681,7 @@ compiler_set_qualname(struct compiler *c) } if (base != NULL) { - dot_str = _Py_GET_GLOBAL_STRING(dot); + dot_str = _Py_STR(dot); name = PyUnicode_Concat(base, dot_str); Py_DECREF(base); if (name == NULL) @@ -2038,7 +2038,7 @@ compiler_mod(struct compiler *c, mod_ty mod) { PyCodeObject *co; int addNone = 1; - PyObject *module = _Py_GET_GLOBAL_STRING(anon_module); + PyObject *module = _Py_STR(anon_module); if (!compiler_enter_scope(c, module, COMPILER_SCOPE_MODULE, mod, 1)) { return NULL; } @@ -2892,7 +2892,7 @@ compiler_lambda(struct compiler *c, expr_ty e) return 0; } - identifier name = _Py_GET_GLOBAL_STRING(anon_lambda); + identifier name = _Py_STR(anon_lambda); if (!compiler_enter_scope(c, name, COMPILER_SCOPE_LAMBDA, (void *)e, e->lineno)) { return 0; @@ -3792,7 +3792,7 @@ compiler_from_import(struct compiler *c, stmt_ty s) { Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names); PyObject *names; - PyObject *empty_string = _Py_GET_GLOBAL_STRING(empty); + PyObject *empty_string = _Py_STR(empty); ADDOP_LOAD_CONST_NEW(c, PyLong_FromLong(s->v.ImportFrom.level)); @@ -5367,7 +5367,7 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type, static int compiler_genexp(struct compiler *c, expr_ty e) { - identifier name = _Py_GET_GLOBAL_STRING(anon_genexpr); + identifier name = _Py_STR(anon_genexpr); assert(e->kind == GeneratorExp_kind); return compiler_comprehension(c, e, COMP_GENEXP, name, e->v.GeneratorExp.generators, @@ -5377,7 +5377,7 @@ compiler_genexp(struct compiler *c, expr_ty e) static int compiler_listcomp(struct compiler *c, expr_ty e) { - identifier name = _Py_GET_GLOBAL_STRING(anon_listcomp); + identifier name = _Py_STR(anon_listcomp); assert(e->kind == ListComp_kind); return compiler_comprehension(c, e, COMP_LISTCOMP, name, e->v.ListComp.generators, @@ -5387,7 +5387,7 @@ compiler_listcomp(struct compiler *c, expr_ty e) static int compiler_setcomp(struct compiler *c, expr_ty e) { - identifier name = _Py_GET_GLOBAL_STRING(anon_setcomp); + identifier name = _Py_STR(anon_setcomp); assert(e->kind == SetComp_kind); return compiler_comprehension(c, e, COMP_SETCOMP, name, e->v.SetComp.generators, @@ -5398,7 +5398,7 @@ compiler_setcomp(struct compiler *c, expr_ty e) static int compiler_dictcomp(struct compiler *c, expr_ty e) { - identifier name = _Py_GET_GLOBAL_STRING(anon_dictcomp); + identifier name = _Py_STR(anon_dictcomp); assert(e->kind == DictComp_kind); return compiler_comprehension(c, e, COMP_DICTCOMP, name, e->v.DictComp.generators, diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 69720378d6f7bf2..75a3e7502675436 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -524,7 +524,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, goto finally; if (v == Py_None) { Py_DECREF(v); - *filename = _Py_GET_GLOBAL_STRING(anon_string); + *filename = _Py_STR(anon_string); Py_INCREF(*filename); } else { @@ -1582,7 +1582,7 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *ret = NULL; mod_ty mod; PyArena *arena; - PyObject *filename = _Py_GET_GLOBAL_STRING(anon_string); + PyObject *filename = _Py_STR(anon_string); arena = _PyArena_New(); if (arena == NULL) diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index 674d93aa58f473b..01d6258d3392665 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -464,7 +464,7 @@ def err(msg): ) | (?: - _Py_GET_GLOBAL_STRING + _Py_STR [(] ( \w+ ) # [)] From 75b6a835484729f413debc05d1e2f92ca3563bca Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 11:02:42 -0700 Subject: [PATCH 105/115] Use a simpler field prefix than spamspamspam_. --- Include/internal/pycore_global_strings.h | 10 +++++----- Include/internal/pycore_runtime_init.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index c75fb8271db04e2..cef1eeffa476edd 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -10,7 +10,7 @@ extern "C" { // The data structure & init here are inspired by Tools/scripts/deepfreeze.py. -// All field names generated by STR() have a common prefix, +// All field names generated by ASCII_STR() have a common prefix, // to help avoid collisions with keywords, etc. #define ASCII_STR(LITERAL) \ @@ -19,9 +19,9 @@ extern "C" { uint8_t _data[_Py_STRING_LENGTH(LITERAL)]; \ } #define LITERAL(NAME, LITERAL) \ - ASCII_STR(LITERAL) spamspamspam_ ## NAME; + ASCII_STR(LITERAL) _ ## NAME; #define ID(NAME) \ - ASCII_STR(#NAME) spamspamspam_ ## NAME; + ASCII_STR(#NAME) _ ## NAME; // XXX Order by frequency of use? @@ -326,9 +326,9 @@ struct _Py_global_strings { #define _Py_ID(NAME) \ - (&_Py_SINGLETON(strings.identifiers.spamspamspam_ ## NAME._ascii.ob_base)) + (&_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base)) #define _Py_STR(NAME) \ - (&_Py_SINGLETON(strings.literals.spamspamspam_ ## NAME._ascii.ob_base)) + (&_Py_SINGLETON(strings.literals._ ## NAME._ascii.ob_base)) #ifdef __cplusplus diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 72d6b7209cc9441..ada4e57eb644400 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -112,9 +112,9 @@ extern "C" { ._data = LITERAL, \ } #define INIT_STR(NAME, LITERAL) \ - .spamspamspam_ ## NAME = _PyASCIIObject_INIT(LITERAL) + ._ ## NAME = _PyASCIIObject_INIT(LITERAL) #define INIT_ID(NAME) \ - .spamspamspam_ ## NAME = _PyASCIIObject_INIT(#NAME) + ._ ## NAME = _PyASCIIObject_INIT(#NAME) /* The following is auto-generated by Tools/scripts/generate_global_objects.py. */ From 7b670c14455f4555321dc1d830763914cb67db13 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 11:04:27 -0700 Subject: [PATCH 106/115] ASCII_STR() -> STRUCT_FOR_ASCII_STR(). --- Include/internal/pycore_global_strings.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index cef1eeffa476edd..a22545a7bd06730 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -13,15 +13,15 @@ extern "C" { // All field names generated by ASCII_STR() have a common prefix, // to help avoid collisions with keywords, etc. -#define ASCII_STR(LITERAL) \ +#define STRUCT_FOR_ASCII_STR(LITERAL) \ struct { \ PyASCIIObject _ascii; \ uint8_t _data[_Py_STRING_LENGTH(LITERAL)]; \ } #define LITERAL(NAME, LITERAL) \ - ASCII_STR(LITERAL) _ ## NAME; + STRUCT_FOR_ASCII_STR(LITERAL) _ ## NAME; #define ID(NAME) \ - ASCII_STR(#NAME) _ ## NAME; + STRUCT_FOR_ASCII_STR(#NAME) _ ## NAME; // XXX Order by frequency of use? From 144ed0fcfe0313f9e87e1aa2d910781b4fe2a6b1 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 11:07:08 -0700 Subject: [PATCH 107/115] LITERAL() -> STRUCT_FOR_STR(). --- Include/internal/pycore_global_strings.h | 28 ++++++++++++------------ Tools/scripts/generate_global_objects.py | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index a22545a7bd06730..ac5b1c869d12675 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -18,7 +18,7 @@ extern "C" { PyASCIIObject _ascii; \ uint8_t _data[_Py_STRING_LENGTH(LITERAL)]; \ } -#define LITERAL(NAME, LITERAL) \ +#define STRUCT_FOR_STR(NAME, LITERAL) \ STRUCT_FOR_ASCII_STR(LITERAL) _ ## NAME; #define ID(NAME) \ STRUCT_FOR_ASCII_STR(#NAME) _ ## NAME; @@ -28,21 +28,21 @@ extern "C" { /* The following is auto-generated by Tools/scripts/generate_global_objects.py. */ struct _Py_global_strings { struct { - LITERAL(empty, "") - LITERAL(dot, ".") - LITERAL(comma_sep, ", ") - LITERAL(percent, "%") - LITERAL(dbl_percent, "%%") + STRUCT_FOR_STR(empty, "") + STRUCT_FOR_STR(dot, ".") + STRUCT_FOR_STR(comma_sep, ", ") + STRUCT_FOR_STR(percent, "%") + STRUCT_FOR_STR(dbl_percent, "%%") // "anonymous" labels - LITERAL(anon_dictcomp, "") - LITERAL(anon_genexpr, "") - LITERAL(anon_lambda, "") - LITERAL(anon_listcomp, "") - LITERAL(anon_module, "") - LITERAL(anon_setcomp, "") - LITERAL(anon_string, "") - LITERAL(dot_locals, ".") + STRUCT_FOR_STR(anon_dictcomp, "") + STRUCT_FOR_STR(anon_genexpr, "") + STRUCT_FOR_STR(anon_lambda, "") + STRUCT_FOR_STR(anon_listcomp, "") + STRUCT_FOR_STR(anon_module, "") + STRUCT_FOR_STR(anon_setcomp, "") + STRUCT_FOR_STR(anon_string, "") + STRUCT_FOR_STR(dot_locals, ".") } literals; struct { diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index 01d6258d3392665..3dac1e5db2033a4 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -376,7 +376,7 @@ def generate_global_strings(): outfile.write('\n') printer.write(f'// {name}') else: - printer.write(f'LITERAL({name}, "{literal}")') + printer.write(f'STRUCT_FOR_STR({name}, "{literal}")') outfile.write('\n') with printer.block('struct', ' identifiers;'): for name in sorted(IDENTIFIERS): From f3aa225ea9484781c635001b17dfd6f7786d0beb Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 11:12:48 -0700 Subject: [PATCH 108/115] ID() -> STRUCT_FOR_ID(). --- Include/internal/pycore_global_strings.h | 544 +++++++++++------------ Tools/scripts/generate_global_objects.py | 2 +- 2 files changed, 273 insertions(+), 273 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index ac5b1c869d12675..6b4e9ddfbe9b1bb 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -20,7 +20,7 @@ extern "C" { } #define STRUCT_FOR_STR(NAME, LITERAL) \ STRUCT_FOR_ASCII_STR(LITERAL) _ ## NAME; -#define ID(NAME) \ +#define STRUCT_FOR_ID(NAME) \ STRUCT_FOR_ASCII_STR(#NAME) _ ## NAME; // XXX Order by frequency of use? @@ -46,277 +46,277 @@ struct _Py_global_strings { } literals; struct { - ID(Py_Repr) - ID(TextIOWrapper) - ID(WarningMessage) - ID(_) - ID(__IOBase_closed) - ID(__abc_tpflags__) - ID(__abs__) - ID(__abstractmethods__) - ID(__add__) - ID(__aenter__) - ID(__aexit__) - ID(__aiter__) - ID(__all__) - ID(__and__) - ID(__anext__) - ID(__annotations__) - ID(__args__) - ID(__await__) - ID(__bases__) - ID(__bool__) - ID(__build_class__) - ID(__builtins__) - ID(__bytes__) - ID(__call__) - ID(__cantrace__) - ID(__class__) - ID(__class_getitem__) - ID(__classcell__) - ID(__complex__) - ID(__contains__) - ID(__copy__) - ID(__del__) - ID(__delattr__) - ID(__delete__) - ID(__delitem__) - ID(__dict__) - ID(__dir__) - ID(__divmod__) - ID(__doc__) - ID(__enter__) - ID(__eq__) - ID(__exit__) - ID(__file__) - ID(__float__) - ID(__floordiv__) - ID(__format__) - ID(__fspath__) - ID(__ge__) - ID(__get__) - ID(__getattr__) - ID(__getattribute__) - ID(__getinitargs__) - ID(__getitem__) - ID(__getnewargs__) - ID(__getnewargs_ex__) - ID(__getstate__) - ID(__gt__) - ID(__hash__) - ID(__iadd__) - ID(__iand__) - ID(__ifloordiv__) - ID(__ilshift__) - ID(__imatmul__) - ID(__imod__) - ID(__import__) - ID(__imul__) - ID(__index__) - ID(__init__) - ID(__init_subclass__) - ID(__instancecheck__) - ID(__int__) - ID(__invert__) - ID(__ior__) - ID(__ipow__) - ID(__irshift__) - ID(__isabstractmethod__) - ID(__isub__) - ID(__iter__) - ID(__itruediv__) - ID(__ixor__) - ID(__le__) - ID(__len__) - ID(__length_hint__) - ID(__loader__) - ID(__lshift__) - ID(__lt__) - ID(__ltrace__) - ID(__main__) - ID(__matmul__) - ID(__missing__) - ID(__mod__) - ID(__module__) - ID(__mro_entries__) - ID(__mul__) - ID(__name__) - ID(__ne__) - ID(__neg__) - ID(__new__) - ID(__newobj__) - ID(__newobj_ex__) - ID(__next__) - ID(__note__) - ID(__or__) - ID(__origin__) - ID(__package__) - ID(__parameters__) - ID(__path__) - ID(__pos__) - ID(__pow__) - ID(__prepare__) - ID(__qualname__) - ID(__radd__) - ID(__rand__) - ID(__rdivmod__) - ID(__reduce__) - ID(__reduce_ex__) - ID(__repr__) - ID(__reversed__) - ID(__rfloordiv__) - ID(__rlshift__) - ID(__rmatmul__) - ID(__rmod__) - ID(__rmul__) - ID(__ror__) - ID(__round__) - ID(__rpow__) - ID(__rrshift__) - ID(__rshift__) - ID(__rsub__) - ID(__rtruediv__) - ID(__rxor__) - ID(__set__) - ID(__set_name__) - ID(__setattr__) - ID(__setitem__) - ID(__setstate__) - ID(__sizeof__) - ID(__slotnames__) - ID(__slots__) - ID(__spec__) - ID(__str__) - ID(__sub__) - ID(__subclasscheck__) - ID(__subclasshook__) - ID(__truediv__) - ID(__trunc__) - ID(__warningregistry__) - ID(__weakref__) - ID(__xor__) - ID(_abc_impl) - ID(_blksize) - ID(_dealloc_warn) - ID(_finalizing) - ID(_find_and_load) - ID(_fix_up_module) - ID(_get_sourcefile) - ID(_handle_fromlist) - ID(_initializing) - ID(_is_text_encoding) - ID(_lock_unlock_module) - ID(_showwarnmsg) - ID(_shutdown) - ID(_slotnames) - ID(_strptime_time) - ID(_uninitialized_submodules) - ID(_warn_unawaited_coroutine) - ID(_xoptions) - ID(add) - ID(append) - ID(big) - ID(buffer) - ID(builtins) - ID(clear) - ID(close) - ID(code) - ID(copy) - ID(copyreg) - ID(decode) - ID(default) - ID(defaultaction) - ID(difference_update) - ID(dispatch_table) - ID(displayhook) - ID(enable) - ID(encoding) - ID(end_lineno) - ID(end_offset) - ID(errors) - ID(excepthook) - ID(extend) - ID(filename) - ID(fileno) - ID(fillvalue) - ID(filters) - ID(find_class) - ID(flush) - ID(get) - ID(get_source) - ID(getattr) - ID(ignore) - ID(importlib) - ID(intersection) - ID(isatty) - ID(items) - ID(iter) - ID(keys) - ID(last_traceback) - ID(last_type) - ID(last_value) - ID(latin1) - ID(lineno) - ID(little) - ID(match) - ID(metaclass) - ID(mode) - ID(modules) - ID(mro) - ID(msg) - ID(n_fields) - ID(n_sequence_fields) - ID(n_unnamed_fields) - ID(name) - ID(obj) - ID(offset) - ID(onceregistry) - ID(open) - ID(parent) - ID(partial) - ID(path) - ID(peek) - ID(persistent_id) - ID(persistent_load) - ID(print_file_and_line) - ID(ps1) - ID(ps2) - ID(raw) - ID(read) - ID(read1) - ID(readable) - ID(readall) - ID(readinto) - ID(readinto1) - ID(readline) - ID(reducer_override) - ID(reload) - ID(replace) - ID(reset) - ID(return) - ID(reversed) - ID(seek) - ID(seekable) - ID(send) - ID(setstate) - ID(sort) - ID(stderr) - ID(stdin) - ID(stdout) - ID(strict) - ID(symmetric_difference_update) - ID(tell) - ID(text) - ID(threading) - ID(throw) - ID(unraisablehook) - ID(values) - ID(version) - ID(warnings) - ID(warnoptions) - ID(writable) - ID(write) - ID(zipimporter) + STRUCT_FOR_ID(Py_Repr) + STRUCT_FOR_ID(TextIOWrapper) + STRUCT_FOR_ID(WarningMessage) + STRUCT_FOR_ID(_) + STRUCT_FOR_ID(__IOBase_closed) + STRUCT_FOR_ID(__abc_tpflags__) + STRUCT_FOR_ID(__abs__) + STRUCT_FOR_ID(__abstractmethods__) + STRUCT_FOR_ID(__add__) + STRUCT_FOR_ID(__aenter__) + STRUCT_FOR_ID(__aexit__) + STRUCT_FOR_ID(__aiter__) + STRUCT_FOR_ID(__all__) + STRUCT_FOR_ID(__and__) + STRUCT_FOR_ID(__anext__) + STRUCT_FOR_ID(__annotations__) + STRUCT_FOR_ID(__args__) + STRUCT_FOR_ID(__await__) + STRUCT_FOR_ID(__bases__) + STRUCT_FOR_ID(__bool__) + STRUCT_FOR_ID(__build_class__) + STRUCT_FOR_ID(__builtins__) + STRUCT_FOR_ID(__bytes__) + STRUCT_FOR_ID(__call__) + STRUCT_FOR_ID(__cantrace__) + STRUCT_FOR_ID(__class__) + STRUCT_FOR_ID(__class_getitem__) + STRUCT_FOR_ID(__classcell__) + STRUCT_FOR_ID(__complex__) + STRUCT_FOR_ID(__contains__) + STRUCT_FOR_ID(__copy__) + STRUCT_FOR_ID(__del__) + STRUCT_FOR_ID(__delattr__) + STRUCT_FOR_ID(__delete__) + STRUCT_FOR_ID(__delitem__) + STRUCT_FOR_ID(__dict__) + STRUCT_FOR_ID(__dir__) + STRUCT_FOR_ID(__divmod__) + STRUCT_FOR_ID(__doc__) + STRUCT_FOR_ID(__enter__) + STRUCT_FOR_ID(__eq__) + STRUCT_FOR_ID(__exit__) + STRUCT_FOR_ID(__file__) + STRUCT_FOR_ID(__float__) + STRUCT_FOR_ID(__floordiv__) + STRUCT_FOR_ID(__format__) + STRUCT_FOR_ID(__fspath__) + STRUCT_FOR_ID(__ge__) + STRUCT_FOR_ID(__get__) + STRUCT_FOR_ID(__getattr__) + STRUCT_FOR_ID(__getattribute__) + STRUCT_FOR_ID(__getinitargs__) + STRUCT_FOR_ID(__getitem__) + STRUCT_FOR_ID(__getnewargs__) + STRUCT_FOR_ID(__getnewargs_ex__) + STRUCT_FOR_ID(__getstate__) + STRUCT_FOR_ID(__gt__) + STRUCT_FOR_ID(__hash__) + STRUCT_FOR_ID(__iadd__) + STRUCT_FOR_ID(__iand__) + STRUCT_FOR_ID(__ifloordiv__) + STRUCT_FOR_ID(__ilshift__) + STRUCT_FOR_ID(__imatmul__) + STRUCT_FOR_ID(__imod__) + STRUCT_FOR_ID(__import__) + STRUCT_FOR_ID(__imul__) + STRUCT_FOR_ID(__index__) + STRUCT_FOR_ID(__init__) + STRUCT_FOR_ID(__init_subclass__) + STRUCT_FOR_ID(__instancecheck__) + STRUCT_FOR_ID(__int__) + STRUCT_FOR_ID(__invert__) + STRUCT_FOR_ID(__ior__) + STRUCT_FOR_ID(__ipow__) + STRUCT_FOR_ID(__irshift__) + STRUCT_FOR_ID(__isabstractmethod__) + STRUCT_FOR_ID(__isub__) + STRUCT_FOR_ID(__iter__) + STRUCT_FOR_ID(__itruediv__) + STRUCT_FOR_ID(__ixor__) + STRUCT_FOR_ID(__le__) + STRUCT_FOR_ID(__len__) + STRUCT_FOR_ID(__length_hint__) + STRUCT_FOR_ID(__loader__) + STRUCT_FOR_ID(__lshift__) + STRUCT_FOR_ID(__lt__) + STRUCT_FOR_ID(__ltrace__) + STRUCT_FOR_ID(__main__) + STRUCT_FOR_ID(__matmul__) + STRUCT_FOR_ID(__missing__) + STRUCT_FOR_ID(__mod__) + STRUCT_FOR_ID(__module__) + STRUCT_FOR_ID(__mro_entries__) + STRUCT_FOR_ID(__mul__) + STRUCT_FOR_ID(__name__) + STRUCT_FOR_ID(__ne__) + STRUCT_FOR_ID(__neg__) + STRUCT_FOR_ID(__new__) + STRUCT_FOR_ID(__newobj__) + STRUCT_FOR_ID(__newobj_ex__) + STRUCT_FOR_ID(__next__) + STRUCT_FOR_ID(__note__) + STRUCT_FOR_ID(__or__) + STRUCT_FOR_ID(__origin__) + STRUCT_FOR_ID(__package__) + STRUCT_FOR_ID(__parameters__) + STRUCT_FOR_ID(__path__) + STRUCT_FOR_ID(__pos__) + STRUCT_FOR_ID(__pow__) + STRUCT_FOR_ID(__prepare__) + STRUCT_FOR_ID(__qualname__) + STRUCT_FOR_ID(__radd__) + STRUCT_FOR_ID(__rand__) + STRUCT_FOR_ID(__rdivmod__) + STRUCT_FOR_ID(__reduce__) + STRUCT_FOR_ID(__reduce_ex__) + STRUCT_FOR_ID(__repr__) + STRUCT_FOR_ID(__reversed__) + STRUCT_FOR_ID(__rfloordiv__) + STRUCT_FOR_ID(__rlshift__) + STRUCT_FOR_ID(__rmatmul__) + STRUCT_FOR_ID(__rmod__) + STRUCT_FOR_ID(__rmul__) + STRUCT_FOR_ID(__ror__) + STRUCT_FOR_ID(__round__) + STRUCT_FOR_ID(__rpow__) + STRUCT_FOR_ID(__rrshift__) + STRUCT_FOR_ID(__rshift__) + STRUCT_FOR_ID(__rsub__) + STRUCT_FOR_ID(__rtruediv__) + STRUCT_FOR_ID(__rxor__) + STRUCT_FOR_ID(__set__) + STRUCT_FOR_ID(__set_name__) + STRUCT_FOR_ID(__setattr__) + STRUCT_FOR_ID(__setitem__) + STRUCT_FOR_ID(__setstate__) + STRUCT_FOR_ID(__sizeof__) + STRUCT_FOR_ID(__slotnames__) + STRUCT_FOR_ID(__slots__) + STRUCT_FOR_ID(__spec__) + STRUCT_FOR_ID(__str__) + STRUCT_FOR_ID(__sub__) + STRUCT_FOR_ID(__subclasscheck__) + STRUCT_FOR_ID(__subclasshook__) + STRUCT_FOR_ID(__truediv__) + STRUCT_FOR_ID(__trunc__) + STRUCT_FOR_ID(__warningregistry__) + STRUCT_FOR_ID(__weakref__) + STRUCT_FOR_ID(__xor__) + STRUCT_FOR_ID(_abc_impl) + STRUCT_FOR_ID(_blksize) + STRUCT_FOR_ID(_dealloc_warn) + STRUCT_FOR_ID(_finalizing) + STRUCT_FOR_ID(_find_and_load) + STRUCT_FOR_ID(_fix_up_module) + STRUCT_FOR_ID(_get_sourcefile) + STRUCT_FOR_ID(_handle_fromlist) + STRUCT_FOR_ID(_initializing) + STRUCT_FOR_ID(_is_text_encoding) + STRUCT_FOR_ID(_lock_unlock_module) + STRUCT_FOR_ID(_showwarnmsg) + STRUCT_FOR_ID(_shutdown) + STRUCT_FOR_ID(_slotnames) + STRUCT_FOR_ID(_strptime_time) + STRUCT_FOR_ID(_uninitialized_submodules) + STRUCT_FOR_ID(_warn_unawaited_coroutine) + STRUCT_FOR_ID(_xoptions) + STRUCT_FOR_ID(add) + STRUCT_FOR_ID(append) + STRUCT_FOR_ID(big) + STRUCT_FOR_ID(buffer) + STRUCT_FOR_ID(builtins) + STRUCT_FOR_ID(clear) + STRUCT_FOR_ID(close) + 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(difference_update) + STRUCT_FOR_ID(dispatch_table) + STRUCT_FOR_ID(displayhook) + STRUCT_FOR_ID(enable) + 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(extend) + STRUCT_FOR_ID(filename) + STRUCT_FOR_ID(fileno) + STRUCT_FOR_ID(fillvalue) + STRUCT_FOR_ID(filters) + STRUCT_FOR_ID(find_class) + STRUCT_FOR_ID(flush) + STRUCT_FOR_ID(get) + STRUCT_FOR_ID(get_source) + STRUCT_FOR_ID(getattr) + STRUCT_FOR_ID(ignore) + STRUCT_FOR_ID(importlib) + STRUCT_FOR_ID(intersection) + STRUCT_FOR_ID(isatty) + STRUCT_FOR_ID(items) + STRUCT_FOR_ID(iter) + STRUCT_FOR_ID(keys) + STRUCT_FOR_ID(last_traceback) + STRUCT_FOR_ID(last_type) + STRUCT_FOR_ID(last_value) + STRUCT_FOR_ID(latin1) + STRUCT_FOR_ID(lineno) + STRUCT_FOR_ID(little) + STRUCT_FOR_ID(match) + STRUCT_FOR_ID(metaclass) + STRUCT_FOR_ID(mode) + STRUCT_FOR_ID(modules) + STRUCT_FOR_ID(mro) + STRUCT_FOR_ID(msg) + STRUCT_FOR_ID(n_fields) + STRUCT_FOR_ID(n_sequence_fields) + STRUCT_FOR_ID(n_unnamed_fields) + STRUCT_FOR_ID(name) + STRUCT_FOR_ID(obj) + STRUCT_FOR_ID(offset) + STRUCT_FOR_ID(onceregistry) + STRUCT_FOR_ID(open) + STRUCT_FOR_ID(parent) + STRUCT_FOR_ID(partial) + STRUCT_FOR_ID(path) + STRUCT_FOR_ID(peek) + STRUCT_FOR_ID(persistent_id) + STRUCT_FOR_ID(persistent_load) + STRUCT_FOR_ID(print_file_and_line) + STRUCT_FOR_ID(ps1) + STRUCT_FOR_ID(ps2) + STRUCT_FOR_ID(raw) + STRUCT_FOR_ID(read) + STRUCT_FOR_ID(read1) + STRUCT_FOR_ID(readable) + STRUCT_FOR_ID(readall) + STRUCT_FOR_ID(readinto) + STRUCT_FOR_ID(readinto1) + STRUCT_FOR_ID(readline) + STRUCT_FOR_ID(reducer_override) + STRUCT_FOR_ID(reload) + STRUCT_FOR_ID(replace) + STRUCT_FOR_ID(reset) + STRUCT_FOR_ID(return) + STRUCT_FOR_ID(reversed) + STRUCT_FOR_ID(seek) + STRUCT_FOR_ID(seekable) + STRUCT_FOR_ID(send) + STRUCT_FOR_ID(setstate) + STRUCT_FOR_ID(sort) + STRUCT_FOR_ID(stderr) + STRUCT_FOR_ID(stdin) + STRUCT_FOR_ID(stdout) + STRUCT_FOR_ID(strict) + STRUCT_FOR_ID(symmetric_difference_update) + STRUCT_FOR_ID(tell) + STRUCT_FOR_ID(text) + STRUCT_FOR_ID(threading) + STRUCT_FOR_ID(throw) + STRUCT_FOR_ID(unraisablehook) + STRUCT_FOR_ID(values) + STRUCT_FOR_ID(version) + STRUCT_FOR_ID(warnings) + STRUCT_FOR_ID(warnoptions) + STRUCT_FOR_ID(writable) + STRUCT_FOR_ID(write) + STRUCT_FOR_ID(zipimporter) } identifiers; }; /* End auto-generated code */ diff --git a/Tools/scripts/generate_global_objects.py b/Tools/scripts/generate_global_objects.py index 3dac1e5db2033a4..b184e748989406b 100644 --- a/Tools/scripts/generate_global_objects.py +++ b/Tools/scripts/generate_global_objects.py @@ -381,7 +381,7 @@ def generate_global_strings(): with printer.block('struct', ' identifiers;'): for name in sorted(IDENTIFIERS): assert name.isidentifier(), name - printer.write(f'ID({name})') + printer.write(f'STRUCT_FOR_ID({name})') printer.write(END) printer.write(after) From 050b34b21bb7e3233b3e8338f24bd4c7023c15ff Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 11:18:21 -0700 Subject: [PATCH 109/115] Use _PyObject_IMMORTAL_INIT(). --- Include/internal/pycore_runtime_init.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index ada4e57eb644400..3c776e9867e66e7 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -96,10 +96,7 @@ extern "C" { #define _PyASCIIObject_INIT(LITERAL) \ { \ ._ascii = { \ - .ob_base = { \ - .ob_refcnt = 999999999, \ - .ob_type = &PyUnicode_Type, \ - }, \ + .ob_base = _PyObject_IMMORTAL_INIT(&PyUnicode_Type), \ .length = _Py_STRING_LENGTH(LITERAL) - 1, \ .hash = -1, \ .state = { \ From dbec341bcbe53005b8d2645f775dd8e885d8a770 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 11:24:24 -0700 Subject: [PATCH 110/115] Drop _Py_STRING_LENGTH(). --- Include/internal/pycore_global_strings.h | 2 +- Include/internal/pycore_runtime_init.h | 2 +- Include/pymacro.h | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index 6b4e9ddfbe9b1bb..ba1dd74bc859bf0 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -16,7 +16,7 @@ extern "C" { #define STRUCT_FOR_ASCII_STR(LITERAL) \ struct { \ PyASCIIObject _ascii; \ - uint8_t _data[_Py_STRING_LENGTH(LITERAL)]; \ + uint8_t _data[sizeof(LITERAL)]; \ } #define STRUCT_FOR_STR(NAME, LITERAL) \ STRUCT_FOR_ASCII_STR(LITERAL) _ ## NAME; diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 3c776e9867e66e7..045ae5d2835b1fb 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -97,7 +97,7 @@ extern "C" { { \ ._ascii = { \ .ob_base = _PyObject_IMMORTAL_INIT(&PyUnicode_Type), \ - .length = _Py_STRING_LENGTH(LITERAL) - 1, \ + .length = sizeof(LITERAL) - 1, \ .hash = -1, \ .state = { \ .kind = 1, \ diff --git a/Include/pymacro.h b/Include/pymacro.h index b83df5d399fcc07..2728496976de7e5 100644 --- a/Include/pymacro.h +++ b/Include/pymacro.h @@ -65,9 +65,6 @@ (sizeof(array) / sizeof((array)[0])) #endif -#define _Py_STRING_LENGTH(str) \ - (sizeof(str) / sizeof(char)) - /* Define macros for inline documentation. */ #define PyDoc_VAR(name) static const char name[] From 7a075acd2e7e6215213cad47bbcad478f2012dde Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 14:57:36 -0700 Subject: [PATCH 111/115] Inline uses of _Py_ID(). --- Modules/_abc.c | 41 ++--- Modules/_collectionsmodule.c | 20 +-- Modules/_io/_iomodule.c | 13 +- Modules/_io/bufferedio.c | 51 ++---- Modules/_io/fileio.c | 9 +- Modules/_io/iobase.c | 26 +-- Modules/_io/textio.c | 117 +++++------- Modules/_io/winconsoleio.c | 6 +- Modules/_operator.c | 3 +- Modules/_pickle.c | 97 ++++------ Modules/_threadmodule.c | 15 +- Modules/faulthandler.c | 14 +- Modules/itertoolsmodule.c | 15 +- Modules/main.c | 3 +- Modules/posixmodule.c | 6 +- Modules/timemodule.c | 3 +- Objects/abstract.c | 38 ++-- Objects/bytearrayobject.c | 8 +- Objects/bytesobject.c | 11 +- Objects/classobject.c | 17 +- Objects/complexobject.c | 3 +- Objects/descrobject.c | 34 ++-- Objects/dictobject.c | 26 ++- Objects/enumobject.c | 3 +- Objects/exceptions.c | 6 +- Objects/fileobject.c | 17 +- Objects/frameobject.c | 3 +- Objects/funcobject.c | 6 +- Objects/genericaliasobject.c | 19 +- Objects/genobject.c | 6 +- Objects/iterobject.c | 10 +- Objects/listobject.c | 11 +- Objects/longobject.c | 12 +- Objects/methodobject.c | 6 +- Objects/moduleobject.c | 68 +++---- Objects/object.c | 32 ++-- Objects/odictobject.c | 19 +- Objects/rangeobject.c | 8 +- Objects/setobject.c | 6 +- Objects/tupleobject.c | 5 +- Objects/typeobject.c | 340 +++++++++++++---------------------- Objects/unicodeobject.c | 5 +- Objects/unionobject.c | 12 +- Objects/weakrefobject.c | 6 +- Parser/tokenizer.c | 7 +- Python/_warnings.c | 50 ++---- Python/bltinmodule.c | 58 +++--- Python/ceval.c | 66 +++---- Python/codecs.c | 3 +- Python/compile.c | 15 +- Python/errors.c | 53 ++---- Python/import.c | 73 +++----- Python/importdl.c | 3 +- Python/marshal.c | 9 +- Python/pylifecycle.c | 53 ++---- Python/pythonrun.c | 96 ++++------ Python/specialize.c | 14 +- Python/sysmodule.c | 63 +++---- Python/traceback.c | 15 +- 59 files changed, 641 insertions(+), 1113 deletions(-) diff --git a/Modules/_abc.c b/Modules/_abc.c index db64961aa49fd97..aaa5c2358b69e03 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -114,8 +114,7 @@ static _abc_data * _get_impl(PyObject *module, PyObject *self) { _abcmodule_state *state = get_abc_state(module); - PyObject *attr = _Py_ID(_abc_impl); - PyObject *impl = PyObject_GetAttr(self, attr); + PyObject *impl = PyObject_GetAttr(self, _Py_ID(_abc_impl)); if (impl == NULL) { return NULL; } @@ -304,8 +303,7 @@ compute_abstract_methods(PyObject *self) PyObject *ns = NULL, *items = NULL, *bases = NULL; // Py_XDECREF()ed on error. /* Stage 1: direct abstract methods. */ - PyObject *attr = _Py_ID(__dict__); - ns = PyObject_GetAttr(self, attr); + ns = PyObject_GetAttr(self, _Py_ID(__dict__)); if (!ns) { goto error; } @@ -349,8 +347,7 @@ compute_abstract_methods(PyObject *self) } /* Stage 2: inherited abstract methods. */ - attr = _Py_ID(__bases__); - bases = PyObject_GetAttr(self, attr); + bases = PyObject_GetAttr(self, _Py_ID(__bases__)); if (!bases) { goto error; } @@ -359,12 +356,12 @@ compute_abstract_methods(PyObject *self) goto error; } - attr = _Py_ID(__abstractmethods__); for (Py_ssize_t pos = 0; pos < PyTuple_GET_SIZE(bases); pos++) { PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed PyObject *base_abstracts, *iter; - if (_PyObject_LookupAttr(item, attr, &base_abstracts) < 0) { + if (_PyObject_LookupAttr(item, _Py_ID(__abstractmethods__), + &base_abstracts) < 0) { goto error; } if (base_abstracts == NULL) { @@ -404,7 +401,7 @@ compute_abstract_methods(PyObject *self) } } - if (PyObject_SetAttr(self, attr, abstracts) < 0) { + if (PyObject_SetAttr(self, _Py_ID(__abstractmethods__), abstracts) < 0) { goto error; } @@ -443,8 +440,7 @@ _abc__abc_init(PyObject *module, PyObject *self) if (data == NULL) { return NULL; } - PyObject *attr = _Py_ID(_abc_impl); - if (PyObject_SetAttr(self, attr, data) < 0) { + if (PyObject_SetAttr(self, _Py_ID(_abc_impl), data) < 0) { Py_DECREF(data); return NULL; } @@ -455,8 +451,8 @@ _abc__abc_init(PyObject *module, PyObject *self) * their special status w.r.t. pattern matching. */ if (PyType_Check(self)) { PyTypeObject *cls = (PyTypeObject *)self; - PyObject *attr = _Py_ID(__abc_tpflags__); - PyObject *flags = PyDict_GetItemWithError(cls->tp_dict, attr); + PyObject *flags = PyDict_GetItemWithError(cls->tp_dict, + _Py_ID(__abc_tpflags__)); if (flags == NULL) { if (PyErr_Occurred()) { return NULL; @@ -474,7 +470,7 @@ _abc__abc_init(PyObject *module, PyObject *self) } ((PyTypeObject *)self)->tp_flags |= (val & COLLECTION_FLAGS); } - if (PyDict_DelItem(cls->tp_dict, attr) < 0) { + if (PyDict_DelItem(cls->tp_dict, _Py_ID(__abc_tpflags__)) < 0) { return NULL; } } @@ -590,8 +586,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, return NULL; } - PyObject *attr = _Py_ID(__class__); - subclass = PyObject_GetAttr(instance, attr); + subclass = PyObject_GetAttr(instance, _Py_ID(__class__)); if (subclass == NULL) { Py_DECREF(impl); return NULL; @@ -607,7 +602,6 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, goto end; } subtype = (PyObject *)Py_TYPE(instance); - attr = _Py_ID(__subclasscheck__); if (subtype == subclass) { if (impl->_abc_negative_cache_version == get_abc_state(module)->abc_invalidation_counter) { incache = _in_weak_set(impl->_abc_negative_cache, subclass); @@ -621,10 +615,12 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, } } /* Fall back to the subclass check. */ - result = PyObject_CallMethodOneArg(self, attr, subclass); + result = PyObject_CallMethodOneArg(self, _Py_ID(__subclasscheck__), + subclass); goto end; } - result = PyObject_CallMethodOneArg(self, attr, subclass); + result = PyObject_CallMethodOneArg(self, _Py_ID(__subclasscheck__), + subclass); if (result == NULL) { goto end; } @@ -636,7 +632,8 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, break; case 0: Py_DECREF(result); - result = PyObject_CallMethodOneArg(self, attr, subtype); + result = PyObject_CallMethodOneArg(self, _Py_ID(__subclasscheck__), + subtype); break; case 1: // Nothing to do. break; @@ -719,8 +716,8 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self, } /* 3. Check the subclass hook. */ - PyObject *attr = _Py_ID(__subclasshook__); - ok = PyObject_CallMethodOneArg((PyObject *)self, attr, subclass); + ok = PyObject_CallMethodOneArg( + (PyObject *)self, _Py_ID(__subclasshook__), subclass); if (ok == NULL) { goto end; } diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index ccc0f6c85439ed7..9df7ac48af3ce34 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1349,8 +1349,7 @@ deque_reduce(dequeobject *deque, PyObject *Py_UNUSED(ignored)) { PyObject *dict, *it; - PyObject *attr = _Py_ID(__dict__); - if (_PyObject_LookupAttr((PyObject *)deque, attr, &dict) < 0) { + if (_PyObject_LookupAttr((PyObject *)deque, _Py_ID(__dict__), &dict) < 0) { return NULL; } if (dict == NULL) { @@ -2071,8 +2070,7 @@ defdict_reduce(defdictobject *dd, PyObject *Py_UNUSED(ignored)) args = PyTuple_Pack(1, dd->default_factory); if (args == NULL) return NULL; - PyObject *attr = _Py_ID(items); - items = PyObject_CallMethodNoArgs((PyObject *)dd, attr); + items = PyObject_CallMethodNoArgs((PyObject *)dd, _Py_ID(items)); if (items == NULL) { Py_DECREF(args); return NULL; @@ -2327,13 +2325,10 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping, /* Only take the fast path when get() and __setitem__() * have not been overridden. */ - PyObject *attr = _Py_ID(get); - mapping_get = _PyType_Lookup(Py_TYPE(mapping), attr); - dict_get = _PyType_Lookup(&PyDict_Type, attr); - attr = _Py_ID(__setitem__); - mapping_setitem = _PyType_Lookup(Py_TYPE(mapping), attr); - attr = _Py_ID(__setitem__); - dict_setitem = _PyType_Lookup(&PyDict_Type, attr); + mapping_get = _PyType_Lookup(Py_TYPE(mapping), _Py_ID(get)); + dict_get = _PyType_Lookup(&PyDict_Type, _Py_ID(get)); + mapping_setitem = _PyType_Lookup(Py_TYPE(mapping), _Py_ID(__setitem__)); + dict_setitem = _PyType_Lookup(&PyDict_Type, _Py_ID(__setitem__)); if (mapping_get != NULL && mapping_get == dict_get && mapping_setitem != NULL && mapping_setitem == dict_setitem && @@ -2382,8 +2377,7 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping, } } else { - attr = _Py_ID(get); - bound_get = PyObject_GetAttr(mapping, attr); + bound_get = PyObject_GetAttr(mapping, _Py_ID(get)); if (bound_get == NULL) goto done; diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 42257b0ed5bf60a..30a3a876ed7d59a 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -240,7 +240,6 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, long isatty = 0; PyObject *raw, *modeobj = NULL, *buffer, *wrapper, *result = NULL, *path_or_fd = NULL; - PyObject *attr; is_number = PyNumber_Check(file); @@ -377,8 +376,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, /* buffering */ if (buffering < 0) { - attr = _Py_ID(isatty); - PyObject *res = PyObject_CallMethodNoArgs(raw, attr); + PyObject *res = PyObject_CallMethodNoArgs(raw, _Py_ID(isatty)); if (res == NULL) goto error; isatty = PyLong_AsLong(res); @@ -396,8 +394,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, if (buffering < 0) { PyObject *blksize_obj; - attr = _Py_ID(_blksize); - blksize_obj = PyObject_GetAttr(raw, attr); + blksize_obj = PyObject_GetAttr(raw, _Py_ID(_blksize)); if (blksize_obj == NULL) goto error; buffering = PyLong_AsLong(blksize_obj); @@ -464,8 +461,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, result = wrapper; Py_DECREF(buffer); - attr = _Py_ID(mode); - if (PyObject_SetAttr(wrapper, attr, modeobj) < 0) + if (PyObject_SetAttr(wrapper, _Py_ID(mode), modeobj) < 0) goto error; Py_DECREF(modeobj); return result; @@ -474,8 +470,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, if (result != NULL) { PyObject *exc, *val, *tb, *close_result; PyErr_Fetch(&exc, &val, &tb); - attr = _Py_ID(close); - close_result = PyObject_CallMethodNoArgs(result, attr); + close_result = PyObject_CallMethodNoArgs(result, _Py_ID(close)); _PyErr_ChainExceptions(exc, val, tb); Py_XDECREF(close_result); Py_DECREF(result); diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 4b1e6a4ee693e2c..71daf7e96c797fa 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -422,8 +422,7 @@ buffered_dealloc_warn(buffered *self, PyObject *source) { if (self->ok && self->raw) { PyObject *r; - PyObject *attr = _Py_ID(_dealloc_warn); - r = PyObject_CallMethodOneArg(self->raw, attr, source); + r = PyObject_CallMethodOneArg(self->raw, _Py_ID(_dealloc_warn), source); if (r) Py_DECREF(r); else @@ -569,16 +568,14 @@ static PyObject * buffered_name_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - PyObject *attr = _Py_ID(name); - return PyObject_GetAttr(self->raw, attr); + return PyObject_GetAttr(self->raw, _Py_ID(name)); } static PyObject * buffered_mode_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - PyObject *attr = _Py_ID(mode); - return PyObject_GetAttr(self->raw, attr); + return PyObject_GetAttr(self->raw, _Py_ID(mode)); } /* Lower-level APIs */ @@ -1369,8 +1366,7 @@ buffered_repr(buffered *self) { PyObject *nameobj, *res; - PyObject *attr = _Py_ID(name); - if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) { + if (_PyObject_LookupAttr((PyObject *) self, _Py_ID(name), &nameobj) < 0) { if (!PyErr_ExceptionMatches(PyExc_ValueError)) { return NULL; } @@ -2165,78 +2161,67 @@ _forward_call(buffered *self, PyObject *name, PyObject *args) static PyObject * bufferedrwpair_read(rwpair *self, PyObject *args) { - PyObject *attr = _Py_ID(read); - return _forward_call(self->reader, attr, args); + return _forward_call(self->reader, _Py_ID(read), args); } static PyObject * bufferedrwpair_peek(rwpair *self, PyObject *args) { - PyObject *attr = _Py_ID(peek); - return _forward_call(self->reader, attr, args); + return _forward_call(self->reader, _Py_ID(peek), args); } static PyObject * bufferedrwpair_read1(rwpair *self, PyObject *args) { - PyObject *attr = _Py_ID(read1); - return _forward_call(self->reader, attr, args); + return _forward_call(self->reader, _Py_ID(read1), args); } static PyObject * bufferedrwpair_readinto(rwpair *self, PyObject *args) { - PyObject *attr = _Py_ID(readinto); - return _forward_call(self->reader, attr, args); + return _forward_call(self->reader, _Py_ID(readinto), args); } static PyObject * bufferedrwpair_readinto1(rwpair *self, PyObject *args) { - PyObject *attr = _Py_ID(readinto1); - return _forward_call(self->reader, attr, args); + return _forward_call(self->reader, _Py_ID(readinto1), args); } static PyObject * bufferedrwpair_write(rwpair *self, PyObject *args) { - PyObject *attr = _Py_ID(write); - return _forward_call(self->writer, attr, args); + return _forward_call(self->writer, _Py_ID(write), args); } static PyObject * bufferedrwpair_flush(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(flush); - return _forward_call(self->writer, attr, NULL); + return _forward_call(self->writer, _Py_ID(flush), NULL); } static PyObject * bufferedrwpair_readable(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(readable); - return _forward_call(self->reader, attr, NULL); + return _forward_call(self->reader, _Py_ID(readable), NULL); } static PyObject * bufferedrwpair_writable(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(writable); - return _forward_call(self->writer, attr, NULL); + return _forward_call(self->writer, _Py_ID(writable), NULL); } static PyObject * bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored)) { PyObject *exc = NULL, *val, *tb; - PyObject *attr = _Py_ID(close); - PyObject *ret = _forward_call(self->writer, attr, NULL); + PyObject *ret = _forward_call(self->writer, _Py_ID(close), NULL); if (ret == NULL) PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(ret); - attr = _Py_ID(close); - ret = _forward_call(self->reader, attr, NULL); + ret = _forward_call(self->reader, _Py_ID(close), NULL); if (exc != NULL) { _PyErr_ChainExceptions(exc, val, tb); Py_CLEAR(ret); @@ -2247,8 +2232,7 @@ bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored)) static PyObject * bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(isatty); - PyObject *ret = _forward_call(self->writer, attr, NULL); + PyObject *ret = _forward_call(self->writer, _Py_ID(isatty), NULL); if (ret != Py_False) { /* either True or exception */ @@ -2256,8 +2240,7 @@ bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored)) } Py_DECREF(ret); - attr = _Py_ID(isatty); - return _forward_call(self->reader, attr, NULL); + return _forward_call(self->reader, _Py_ID(isatty), NULL); } static PyObject * diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 45fc7d5147ca8d8..20270132c03b41e 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -144,9 +144,8 @@ _io_FileIO_close_impl(fileio *self) PyObject *res; PyObject *exc, *val, *tb; int rc; - PyObject *attr = _Py_ID(close); res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type, - attr, (PyObject *)self); + _Py_ID(close), (PyObject *)self); if (!self->closefd) { self->fd = -1; return res; @@ -474,8 +473,7 @@ _Py_COMP_DIAG_POP _setmode(self->fd, O_BINARY); #endif - PyObject *attr = _Py_ID(name); - if (PyObject_SetAttr((PyObject *)self, attr, nameobj) < 0) + if (PyObject_SetAttr((PyObject *)self, _Py_ID(name), nameobj) < 0) goto error; if (self->appending) { @@ -1084,8 +1082,7 @@ fileio_repr(fileio *self) if (self->fd < 0) return PyUnicode_FromFormat("<_io.FileIO [closed]>"); - PyObject *attr = _Py_ID(name); - if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) { + if (_PyObject_LookupAttr((PyObject *) self, _Py_ID(name), &nameobj) < 0) { return NULL; } if (nameobj == NULL) { diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 553da75db04afcc..593b6623d81f0b2 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -111,8 +111,7 @@ static PyObject * _io__IOBase_tell_impl(PyObject *self) /*[clinic end generated code: output=89a1c0807935abe2 input=04e615fec128801f]*/ { - PyObject *attr = _Py_ID(seek); - return _PyObject_CallMethod(self, attr, "ii", 0, 1); + return _PyObject_CallMethod(self, _Py_ID(seek), "ii", 0, 1); } PyDoc_STRVAR(iobase_truncate_doc, @@ -134,8 +133,7 @@ iobase_is_closed(PyObject *self) int ret; /* This gets the derived attribute, which is *not* __IOBase_closed in most cases! */ - PyObject *attr = _Py_ID(__IOBase_closed); - ret = _PyObject_LookupAttr(self, attr, &res); + ret = _PyObject_LookupAttr(self, _Py_ID(__IOBase_closed), &res); Py_XDECREF(res); return ret; } @@ -236,8 +234,7 @@ _io__IOBase_close_impl(PyObject *self) res = PyObject_CallMethodNoArgs(self, _PyIO_str_flush); PyErr_Fetch(&exc, &val, &tb); - PyObject *attr = _Py_ID(__IOBase_closed); - rc = PyObject_SetAttr(self, attr, Py_True); + rc = PyObject_SetAttr(self, _Py_ID(__IOBase_closed), Py_True); _PyErr_ChainExceptions(exc, val, tb); if (rc < 0) { Py_CLEAR(res); @@ -277,8 +274,7 @@ iobase_finalize(PyObject *self) if (closed == 0) { /* Signal close() that it was called as part of the object finalization process. */ - PyObject *attr = _Py_ID(_finalizing); - if (PyObject_SetAttr(self, attr, Py_True)) + if (PyObject_SetAttr(self, _Py_ID(_finalizing), Py_True)) PyErr_Clear(); res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_close); /* Silencing I/O errors is bad, but printing spurious tracebacks is @@ -550,7 +546,6 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit) return NULL; } - PyObject *attr = _Py_ID(read); while (limit < 0 || PyByteArray_GET_SIZE(buffer) < limit) { Py_ssize_t nreadahead = 1; PyObject *b; @@ -596,7 +591,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit) Py_DECREF(readahead); } - b = _PyObject_CallMethod(self, attr, "n", nreadahead); + b = _PyObject_CallMethod(self, _Py_ID(read), "n", nreadahead); if (b == NULL) { /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() when EINTR occurs so we needn't do it ourselves. */ @@ -696,9 +691,8 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint) /* XXX special-casing this made sense in the Python version in order to remove the bytecode interpretation overhead, but it could probably be removed here. */ - PyObject *attr = _Py_ID(extend); - PyObject *ret = PyObject_CallMethodObjArgs(result, attr, self, NULL); - + PyObject *ret = PyObject_CallMethodObjArgs(result, _Py_ID(extend), + self, NULL); if (ret == NULL) { goto error; } @@ -917,8 +911,7 @@ _io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n) PyObject *b, *res; if (n < 0) { - PyObject *attr = _Py_ID(readall); - return PyObject_CallMethodNoArgs(self, attr); + return PyObject_CallMethodNoArgs(self, _Py_ID(readall)); } /* TODO: allocate a bytes object directly instead and manually construct @@ -964,8 +957,7 @@ _io__RawIOBase_readall_impl(PyObject *self) return NULL; while (1) { - PyObject *attr = _Py_ID(read); - PyObject *data = _PyObject_CallMethod(self, attr, + PyObject *data = _PyObject_CallMethod(self, _Py_ID(read), "i", DEFAULT_BUFFER_SIZE); if (!data) { /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 2c9289b8943ec14..abfa3837a28b6de 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -565,8 +565,7 @@ _io_IncrementalNewlineDecoder_setstate(nldecoder_object *self, flag >>= 1; if (self->decoder != Py_None) { - PyObject *attr = _Py_ID(setstate); - return _PyObject_CallMethod(self->decoder, attr, + return _PyObject_CallMethod(self->decoder, _Py_ID(setstate), "((OK))", buffer, flag); } else { @@ -846,8 +845,7 @@ _textiowrapper_set_decoder(textio *self, PyObject *codec_info, PyObject *res; int r; - PyObject *attr = _Py_ID(readable); - res = PyObject_CallMethodNoArgs(self->buffer, attr); + res = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(readable)); if (res == NULL) return -1; @@ -902,8 +900,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info, PyObject *res; int r; - PyObject *attr = _Py_ID(writable); - res = PyObject_CallMethodNoArgs(self->buffer, attr); + res = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(writable)); if (res == NULL) return -1; @@ -922,8 +919,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info, return -1; /* Get the normalized named of the codec */ - attr = _Py_ID(name); - if (_PyObject_LookupAttr(codec_info, attr, &res) < 0) { + if (_PyObject_LookupAttr(codec_info, _Py_ID(name), &res) < 0) { return -1; } if (res != NULL && PyUnicode_Check(res)) { @@ -1061,7 +1057,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, int write_through) /*[clinic end generated code: output=72267c0c01032ed2 input=77d8696d1a1f460b]*/ { - PyObject *raw, *attr, *codec_info = NULL; + PyObject *raw, *codec_info = NULL; _PyIO_State *state = NULL; PyObject *res; int r; @@ -1123,8 +1119,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, state = IO_STATE(); if (state == NULL) goto error; - attr = _Py_ID(fileno); - fileno = PyObject_CallMethodNoArgs(buffer, attr); + fileno = PyObject_CallMethodNoArgs(buffer, _Py_ID(fileno)); /* Ignore only AttributeError and UnsupportedOperation */ if (fileno == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError) || @@ -1210,8 +1205,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, Py_IS_TYPE(buffer, &PyBufferedWriter_Type) || Py_IS_TYPE(buffer, &PyBufferedRandom_Type)) { - attr = _Py_ID(raw); - if (_PyObject_LookupAttr(buffer, attr, &raw) < 0) + if (_PyObject_LookupAttr(buffer, _Py_ID(raw), &raw) < 0) goto error; /* Cache the raw FileIO object to speed up 'closed' checks */ if (raw != NULL) { @@ -1222,8 +1216,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, } } - attr = _Py_ID(seekable); - res = PyObject_CallMethodNoArgs(buffer, attr); + res = PyObject_CallMethodNoArgs(buffer, _Py_ID(seekable)); if (res == NULL) goto error; r = PyObject_IsTrue(res); @@ -1621,9 +1614,8 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) haslf = 1; if (haslf && self->writetranslate && self->writenl != NULL) { - PyObject *attr = _Py_ID(replace); - PyObject *newtext = _PyObject_CallMethod(text, attr - , "ss", "\n", self->writenl); + PyObject *newtext = _PyObject_CallMethod(text, _Py_ID(replace), + "ss", "\n", self->writenl); Py_DECREF(text); if (newtext == NULL) return NULL; @@ -1722,8 +1714,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) Py_CLEAR(self->snapshot); if (self->decoder) { - PyObject *attr = _Py_ID(reset); - ret = PyObject_CallMethodNoArgs(self->decoder, attr); + ret = PyObject_CallMethodNoArgs(self->decoder, _Py_ID(reset)); if (ret == NULL) return NULL; Py_DECREF(ret); @@ -1927,8 +1918,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n) if (n < 0) { /* Read everything */ - PyObject *attr = _Py_ID(read); - PyObject *bytes = PyObject_CallMethodNoArgs(self->buffer, attr); + PyObject *bytes = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(read)); PyObject *decoded; if (bytes == NULL) goto fail; @@ -2392,8 +2382,7 @@ _textiowrapper_decoder_setstate(textio *self, cookie_type *cookie) res = PyObject_CallMethodNoArgs(self->decoder, _PyIO_str_reset); } else { - PyObject *attr = _Py_ID(setstate); - res = _PyObject_CallMethod(self->decoder, attr, + res = _PyObject_CallMethod(self->decoder, _Py_ID(setstate), "((yi))", "", cookie->dec_flags); } if (res == NULL) { @@ -2441,7 +2430,7 @@ static PyObject * _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) /*[clinic end generated code: output=0a15679764e2d04d input=0458abeb3d7842be]*/ { - PyObject *posobj, *attr; + PyObject *posobj; cookie_type cookie; PyObject *res; int cmp; @@ -2475,8 +2464,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) * sync the underlying buffer with the current position. */ Py_DECREF(cookieObj); - attr = _Py_ID(tell); - cookieObj = PyObject_CallMethodNoArgs((PyObject *)self, attr); + cookieObj = PyObject_CallMethodNoArgs((PyObject *)self, _Py_ID(tell)); if (cookieObj == NULL) goto fail; break; @@ -2492,8 +2480,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) goto fail; } - attr = _Py_ID(flush); - res = PyObject_CallMethodNoArgs((PyObject *)self, attr); + res = PyObject_CallMethodNoArgs((PyObject *)self, _Py_ID(flush)); if (res == NULL) goto fail; Py_DECREF(res); @@ -2501,15 +2488,13 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) textiowrapper_set_decoded_chars(self, NULL); Py_CLEAR(self->snapshot); if (self->decoder) { - attr = _Py_ID(reset); - res = PyObject_CallMethodNoArgs(self->decoder, attr); + res = PyObject_CallMethodNoArgs(self->decoder, _Py_ID(reset)); if (res == NULL) goto fail; Py_DECREF(res); } - attr = _Py_ID(seek); - res = _PyObject_CallMethod(self->buffer, attr, "ii", 0, 2); + res = _PyObject_CallMethod(self->buffer, _Py_ID(seek), "ii", 0, 2); Py_CLEAR(cookieObj); if (res == NULL) goto fail; @@ -2575,8 +2560,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) if (cookie.chars_to_skip) { /* Just like _read_chunk, feed the decoder and save a snapshot. */ - attr = _Py_ID(read); - PyObject *input_chunk = _PyObject_CallMethod(self->buffer, attr, + PyObject *input_chunk = _PyObject_CallMethod(self->buffer, _Py_ID(read), "i", cookie.bytes_to_feed); PyObject *decoded; @@ -2598,8 +2582,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) } Py_XSETREF(self->snapshot, snapshot); - attr = _Py_ID(decode); - decoded = PyObject_CallMethodObjArgs(self->decoder, attr, + decoded = PyObject_CallMethodObjArgs(self->decoder, _Py_ID(decode), input_chunk, cookie.need_eof ? Py_True : Py_False, NULL); if (check_decoded(decoded) < 0) @@ -2641,7 +2624,7 @@ static PyObject * _io_TextIOWrapper_tell_impl(textio *self) /*[clinic end generated code: output=4f168c08bf34ad5f input=9a2caf88c24f9ddf]*/ { - PyObject *res, *attr; + PyObject *res; PyObject *posobj = NULL; cookie_type cookie = {0,0,0,0,0}; PyObject *next_input; @@ -2667,14 +2650,12 @@ _io_TextIOWrapper_tell_impl(textio *self) if (_textiowrapper_writeflush(self) < 0) return NULL; - attr = _Py_ID(flush); - res = PyObject_CallMethodNoArgs((PyObject *)self, attr); + res = PyObject_CallMethodNoArgs((PyObject *)self, _Py_ID(flush)); if (res == NULL) goto fail; Py_DECREF(res); - attr = _Py_ID(tell); - posobj = PyObject_CallMethodNoArgs(self->buffer, attr); + posobj = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(tell)); if (posobj == NULL) goto fail; @@ -2747,15 +2728,13 @@ _io_TextIOWrapper_tell_impl(textio *self) #define DECODER_DECODE(start, len, res) do { \ PyObject *_decoded = _PyObject_CallMethod( \ - self->decoder, attr, "y#", start, len); \ + self->decoder, _Py_ID(decode), "y#", start, len); \ if (check_decoded(_decoded) < 0) \ goto fail; \ res = PyUnicode_GET_LENGTH(_decoded); \ Py_DECREF(_decoded); \ } while (0) - attr = _Py_ID(decode); - /* Fast search for an acceptable start point, close to our current pos */ skip_bytes = (Py_ssize_t) (self->b2cratio * chars_to_skip); @@ -2831,7 +2810,7 @@ _io_TextIOWrapper_tell_impl(textio *self) if (input == input_end) { /* We didn't get enough decoded data; signal EOF to get more. */ PyObject *decoded = _PyObject_CallMethod( - self->decoder, attr, "yO", "", /* final = */ Py_True); + self->decoder, _Py_ID(decode), "yO", "", /* final = */ Py_True); if (check_decoded(decoded) < 0) goto fail; chars_decoded += PyUnicode_GET_LENGTH(decoded); @@ -2846,8 +2825,8 @@ _io_TextIOWrapper_tell_impl(textio *self) } finally: - attr = _Py_ID(setstate); - res = PyObject_CallMethodOneArg(self->decoder, attr, saved_state); + res = PyObject_CallMethodOneArg( + self->decoder, _Py_ID(setstate), saved_state); Py_DECREF(saved_state); if (res == NULL) return NULL; @@ -2861,8 +2840,8 @@ _io_TextIOWrapper_tell_impl(textio *self) if (saved_state) { PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - attr = _Py_ID(setstate); - res = PyObject_CallMethodOneArg(self->decoder, attr, saved_state); + res = PyObject_CallMethodOneArg( + self->decoder, _Py_ID(setstate), saved_state); _PyErr_ChainExceptions(type, value, traceback); Py_DECREF(saved_state); Py_XDECREF(res); @@ -2913,8 +2892,7 @@ textiowrapper_repr(textio *self) } goto error; } - PyObject *attr = _Py_ID(name); - if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) { + if (_PyObject_LookupAttr((PyObject *) self, _Py_ID(name), &nameobj) < 0) { if (!PyErr_ExceptionMatches(PyExc_ValueError)) { goto error; } @@ -2930,8 +2908,7 @@ textiowrapper_repr(textio *self) if (res == NULL) goto error; } - attr = _Py_ID(mode); - if (_PyObject_LookupAttr((PyObject *) self, attr, &modeobj) < 0) { + if (_PyObject_LookupAttr((PyObject *) self, _Py_ID(mode), &modeobj) < 0) { goto error; } if (modeobj != NULL) { @@ -2971,8 +2948,7 @@ _io_TextIOWrapper_fileno_impl(textio *self) /*[clinic end generated code: output=21490a4c3da13e6c input=c488ca83d0069f9b]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_ID(fileno); - return PyObject_CallMethodNoArgs(self->buffer, attr); + return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(fileno)); } /*[clinic input] @@ -2984,8 +2960,7 @@ _io_TextIOWrapper_seekable_impl(textio *self) /*[clinic end generated code: output=ab223dbbcffc0f00 input=8b005ca06e1fca13]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_ID(seekable); - return PyObject_CallMethodNoArgs(self->buffer, attr); + return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(seekable)); } /*[clinic input] @@ -2997,8 +2972,7 @@ _io_TextIOWrapper_readable_impl(textio *self) /*[clinic end generated code: output=72ff7ba289a8a91b input=0704ea7e01b0d3eb]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_ID(readable); - return PyObject_CallMethodNoArgs(self->buffer, attr); + return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(readable)); } /*[clinic input] @@ -3010,8 +2984,7 @@ _io_TextIOWrapper_writable_impl(textio *self) /*[clinic end generated code: output=a728c71790d03200 input=c41740bc9d8636e8]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_ID(writable); - return PyObject_CallMethodNoArgs(self->buffer, attr); + return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(writable)); } /*[clinic input] @@ -3023,8 +2996,7 @@ _io_TextIOWrapper_isatty_impl(textio *self) /*[clinic end generated code: output=12be1a35bace882e input=fb68d9f2c99bbfff]*/ { CHECK_ATTACHED(self); - PyObject *attr = _Py_ID(isatty); - return PyObject_CallMethodNoArgs(self->buffer, attr); + return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(isatty)); } /*[clinic input] @@ -3040,8 +3012,7 @@ _io_TextIOWrapper_flush_impl(textio *self) self->telling = self->seekable; if (_textiowrapper_writeflush(self) < 0) return NULL; - PyObject *attr = _Py_ID(flush); - return PyObject_CallMethodNoArgs(self->buffer, attr); + return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(flush)); } /*[clinic input] @@ -3068,25 +3039,22 @@ _io_TextIOWrapper_close_impl(textio *self) Py_RETURN_NONE; /* stream already closed */ } else { - PyObject *exc = NULL, *val, *tb, *attr; + PyObject *exc = NULL, *val, *tb; if (self->finalizing) { - attr = _Py_ID(_dealloc_warn); - res = PyObject_CallMethodOneArg(self->buffer, attr, + res = PyObject_CallMethodOneArg(self->buffer, _Py_ID(_dealloc_warn), (PyObject *)self); if (res) Py_DECREF(res); else PyErr_Clear(); } - attr = _Py_ID(flush); - res = PyObject_CallMethodNoArgs((PyObject *)self, attr); + res = PyObject_CallMethodNoArgs((PyObject *)self, _Py_ID(flush)); if (res == NULL) PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(res); - attr = _Py_ID(close); - res = PyObject_CallMethodNoArgs(self->buffer, attr); + res = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(close)); if (exc != NULL) { _PyErr_ChainExceptions(exc, val, tb); Py_CLEAR(res); @@ -3137,8 +3105,7 @@ static PyObject * textiowrapper_name_get(textio *self, void *context) { CHECK_ATTACHED(self); - PyObject *attr = _Py_ID(name); - return PyObject_GetAttr(self->buffer, attr); + return PyObject_GetAttr(self->buffer, _Py_ID(name)); } static PyObject * diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index ee1590591f08129..06b9ff7e8a9178c 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -194,9 +194,8 @@ _io__WindowsConsoleIO_close_impl(winconsoleio *self) PyObject *res; PyObject *exc, *val, *tb; int rc; - PyObject *attr = _Py_ID(close); res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type, - attr, (PyObject*)self); + _Py_ID(close), (PyObject*)self); if (!self->closefd) { self->fd = -1; return res; @@ -392,8 +391,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj, self->blksize = DEFAULT_BUFFER_SIZE; memset(self->buf, 0, 4); - PyObject *attr = _Py_ID(name); - if (PyObject_SetAttr((PyObject *)self, attr, nameobj) < 0) + if (PyObject_SetAttr((PyObject *)self, _Py_ID(name), nameobj) < 0) goto error; goto done; diff --git a/Modules/_operator.c b/Modules/_operator.c index 4309d46da00a992..869c79624b5fee9 100644 --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -1697,8 +1697,7 @@ methodcaller_reduce(methodcallerobject *mc, PyObject *Py_UNUSED(ignored)) functools = PyImport_ImportModule("functools"); if (!functools) return NULL; - PyObject *attr = _Py_ID(partial); - partial = PyObject_GetAttr(functools, attr); + partial = PyObject_GetAttr(functools, _Py_ID(partial)); Py_DECREF(functools); if (!partial) return NULL; diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 3a8351c4659250b..c01653d4f88c309 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -235,8 +235,7 @@ _Pickle_InitState(PickleState *st) PyObject *codecs = NULL; PyObject *functools = NULL; - PyObject *attr = _Py_ID(getattr); - st->getattr = _PyEval_GetBuiltin(attr); + st->getattr = _PyEval_GetBuiltin(_Py_ID(getattr)); if (st->getattr == NULL) goto error; @@ -1185,8 +1184,7 @@ static int _Pickler_SetOutputStream(PicklerObject *self, PyObject *file) { assert(file != NULL); - PyObject *attr = _Py_ID(write); - if (_PyObject_LookupAttr(file, attr, &self->write) < 0) { + if (_PyObject_LookupAttr(file, _Py_ID(write), &self->write) < 0) { return -1; } if (self->write == NULL) { @@ -1646,18 +1644,14 @@ static int _Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file) { /* Optional file methods */ - PyObject *attr = _Py_ID(peek); - if (_PyObject_LookupAttr(file, attr, &self->peek) < 0) { + if (_PyObject_LookupAttr(file, _Py_ID(peek), &self->peek) < 0) { return -1; } - attr = _Py_ID(readinto); - if (_PyObject_LookupAttr(file, attr, &self->readinto) < 0) { + if (_PyObject_LookupAttr(file, _Py_ID(readinto), &self->readinto) < 0) { return -1; } - attr = _Py_ID(read); - (void)_PyObject_LookupAttr(file, attr, &self->read); - attr = _Py_ID(readline); - (void)_PyObject_LookupAttr(file, attr, &self->readline); + (void)_PyObject_LookupAttr(file, _Py_ID(read), &self->read); + (void)_PyObject_LookupAttr(file, _Py_ID(readline), &self->readline); if (!self->readline || !self->read) { if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, @@ -1923,8 +1917,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) Py_ssize_t i; PyObject *modules; - PyObject *attr = _Py_ID(__module__); - if (_PyObject_LookupAttr(global, attr, &module_name) < 0) { + if (_PyObject_LookupAttr(global, _Py_ID(__module__), &module_name) < 0) { return NULL; } if (module_name) { @@ -1938,9 +1931,8 @@ whichmodule(PyObject *global, PyObject *dotted_path) assert(module_name == NULL); /* Fallback on walking sys.modules */ - attr = _Py_ID(modules); PyThreadState *tstate = _PyThreadState_GET(); - modules = _PySys_GetAttr(tstate, attr); + modules = _PySys_GetAttr(tstate, _Py_ID(modules)); if (modules == NULL) { PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules"); return NULL; @@ -2438,10 +2430,9 @@ save_bytes(PicklerObject *self, PyObject *obj) if (unicode_str == NULL) return -1; - PyObject *latin1 = _Py_ID(latin1); reduce_value = Py_BuildValue("(O(OO))", st->codecs_encode, unicode_str, - latin1); + _Py_ID(latin1)); Py_DECREF(unicode_str); } @@ -3343,8 +3334,7 @@ save_dict(PicklerObject *self, PyObject *obj) status = batch_dict_exact(self, obj); Py_LeaveRecursiveCall(); } else { - PyObject *attr = _Py_ID(items); - items = PyObject_CallMethodNoArgs(obj, attr); + items = PyObject_CallMethodNoArgs(obj, _Py_ID(items)); if (items == NULL) goto error; iter = PyObject_GetIter(items); @@ -3604,12 +3594,10 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name) global_name = name; } else { - PyObject *attr = _Py_ID(__qualname__); - if (_PyObject_LookupAttr(obj, attr, &global_name) < 0) + if (_PyObject_LookupAttr(obj, _Py_ID(__qualname__), &global_name) < 0) goto error; if (global_name == NULL) { - attr = _Py_ID(__name__); - global_name = PyObject_GetAttr(obj, attr); + global_name = PyObject_GetAttr(obj, _Py_ID(__name__)); if (global_name == NULL) goto error; } @@ -3931,8 +3919,7 @@ get_class(PyObject *obj) { PyObject *cls; - PyObject *attr = _Py_ID(__class__); - if (_PyObject_LookupAttr(obj, attr, &cls) == 0) { + if (_PyObject_LookupAttr(obj, _Py_ID(__class__), &cls) == 0) { cls = (PyObject *) Py_TYPE(obj); Py_INCREF(cls); } @@ -3945,7 +3932,7 @@ get_class(PyObject *obj) static int save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) { - PyObject *callable, *attr; + PyObject *callable; PyObject *argtup; PyObject *state = NULL; PyObject *listitems = Py_None; @@ -4016,16 +4003,13 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) if (self->proto >= 2) { PyObject *name; - attr = _Py_ID(__name__); - if (_PyObject_LookupAttr(callable, attr, &name) < 0) { + if (_PyObject_LookupAttr(callable, _Py_ID(__name__), &name) < 0) { return -1; } if (name != NULL && PyUnicode_Check(name)) { - attr = _Py_ID(__newobj_ex__); - use_newobj_ex = _PyUnicode_Equal(name, attr); + use_newobj_ex = _PyUnicode_Equal(name, _Py_ID(__newobj_ex__)); if (!use_newobj_ex) { - attr = _Py_ID(__newobj__); - use_newobj = _PyUnicode_Equal(name, attr); + use_newobj = _PyUnicode_Equal(name, _Py_ID(__newobj__)); } } Py_XDECREF(name); @@ -4082,8 +4066,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) if (newargs == NULL) return -1; - attr = _Py_ID(__new__); - cls_new = PyObject_GetAttr(cls, attr); + cls_new = PyObject_GetAttr(cls, _Py_ID(__new__)); if (cls_new == NULL) { Py_DECREF(newargs); return -1; @@ -4427,8 +4410,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save) don't actually have to check for a __reduce__ method. */ /* Check for a __reduce_ex__ method. */ - PyObject *attr = _Py_ID(__reduce_ex__); - if (_PyObject_LookupAttr(obj, attr, &reduce_func) < 0) { + if (_PyObject_LookupAttr(obj, _Py_ID(__reduce_ex__), &reduce_func) < 0) { goto error; } if (reduce_func != NULL) { @@ -4440,8 +4422,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save) } else { /* Check for a __reduce__ method. */ - attr = _Py_ID(__reduce__); - if (_PyObject_LookupAttr(obj, attr, &reduce_func) < 0) { + if (_PyObject_LookupAttr(obj, _Py_ID(__reduce__), &reduce_func) < 0) { goto error; } if (reduce_func != NULL) { @@ -4495,8 +4476,7 @@ dump(PicklerObject *self, PyObject *obj) int status = -1; PyObject *tmp; - PyObject *attr = _Py_ID(reducer_override); - if (_PyObject_LookupAttr((PyObject *)self, attr, + if (_PyObject_LookupAttr((PyObject *)self, _Py_ID(reducer_override), &tmp) < 0) { goto error; } @@ -4764,16 +4744,14 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, self->fast_nesting = 0; self->fast_memo = NULL; - PyObject *attr = _Py_ID(persistent_id); - if (init_method_ref((PyObject *)self, attr, + if (init_method_ref((PyObject *)self, _Py_ID(persistent_id), &self->pers_func, &self->pers_func_self) < 0) { return -1; } - attr = _Py_ID(dispatch_table); - if (_PyObject_LookupAttr((PyObject *)self, - attr, &self->dispatch_table) < 0) { + if (_PyObject_LookupAttr((PyObject *)self, _Py_ID(dispatch_table), + &self->dispatch_table) < 0) { return -1; } @@ -5127,8 +5105,7 @@ static PyTypeObject Pickler_Type = { static PyObject * find_class(UnpicklerObject *self, PyObject *module_name, PyObject *global_name) { - PyObject *attr = _Py_ID(find_class); - return PyObject_CallMethodObjArgs((PyObject *)self, attr, + return PyObject_CallMethodObjArgs((PyObject *)self, _Py_ID(find_class), module_name, global_name, NULL); } @@ -5817,13 +5794,11 @@ instantiate(PyObject *cls, PyObject *args) assert(PyTuple_Check(args)); if (!PyTuple_GET_SIZE(args) && PyType_Check(cls)) { PyObject *func; - PyObject *attr = _Py_ID(__getinitargs__); - if (_PyObject_LookupAttr(cls, attr, &func) < 0) { + if (_PyObject_LookupAttr(cls, _Py_ID(__getinitargs__), &func) < 0) { return NULL; } if (func == NULL) { - attr = _Py_ID(__new__); - return PyObject_CallMethodOneArg(cls, attr, cls); + return PyObject_CallMethodOneArg(cls, _Py_ID(__new__), cls); } Py_DECREF(func); } @@ -6469,8 +6444,7 @@ do_append(UnpicklerObject *self, Py_ssize_t x) else { PyObject *extend_func; - PyObject *attr = _Py_ID(extend); - if (_PyObject_LookupAttr(list, attr, &extend_func) < 0) { + if (_PyObject_LookupAttr(list, _Py_ID(extend), &extend_func) < 0) { return -1; } if (extend_func != NULL) { @@ -6491,8 +6465,7 @@ do_append(UnpicklerObject *self, Py_ssize_t x) /* Even if the PEP 307 requires extend() and append() methods, fall back on append() if the object has no extend() method for backward compatibility. */ - attr = _Py_ID(append); - append_func = PyObject_GetAttr(list, attr); + append_func = PyObject_GetAttr(list, _Py_ID(append)); if (append_func == NULL) return -1; for (i = x; i < len; i++) { @@ -6616,8 +6589,7 @@ load_additems(UnpicklerObject *self) else { PyObject *add_func; - PyObject *attr = _Py_ID(add); - add_func = PyObject_GetAttr(set, attr); + add_func = PyObject_GetAttr(set, _Py_ID(add)); if (add_func == NULL) return -1; for (i = mark; i < len; i++) { @@ -6658,8 +6630,7 @@ load_build(UnpicklerObject *self) inst = self->stack->data[Py_SIZE(self->stack) - 1]; - PyObject *attr = _Py_ID(__setstate__); - if (_PyObject_LookupAttr(inst, attr, &setstate) < 0) { + if (_PyObject_LookupAttr(inst, _Py_ID(__setstate__), &setstate) < 0) { Py_DECREF(state); return -1; } @@ -6701,8 +6672,7 @@ load_build(UnpicklerObject *self) PyErr_SetString(st->UnpicklingError, "state is not a dictionary"); goto error; } - attr = _Py_ID(__dict__); - dict = PyObject_GetAttr(inst, attr); + dict = PyObject_GetAttr(inst, _Py_ID(__dict__)); if (dict == NULL) goto error; @@ -7269,8 +7239,7 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, self->fix_imports = fix_imports; - PyObject *attr = _Py_ID(persistent_load); - if (init_method_ref((PyObject *)self, attr, + if (init_method_ref((PyObject *)self, _Py_ID(persistent_load), &self->pers_func, &self->pers_func_self) < 0) { return -1; diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index f646e300c1df6dd..87cae7445593722 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -933,8 +933,7 @@ local_setattro(localobject *self, PyObject *name, PyObject *v) return -1; } - PyObject *str_dict = _Py_ID(__dict__); - int r = PyObject_RichCompareBool(name, str_dict, Py_EQ); + int r = PyObject_RichCompareBool(name, _Py_ID(__dict__), Py_EQ); if (r == -1) { return -1; } @@ -985,8 +984,7 @@ local_getattro(localobject *self, PyObject *name) if (ldict == NULL) return NULL; - PyObject *str_dict = _Py_ID(__dict__); - int r = PyObject_RichCompareBool(name, str_dict, Py_EQ); + int r = PyObject_RichCompareBool(name, _Py_ID(__dict__), Py_EQ); if (r == 1) { return Py_NewRef(ldict); } @@ -1407,8 +1405,7 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, PyObject *name = NULL; if (thread != Py_None) { - PyObject *attr = _Py_ID(name); - if (_PyObject_LookupAttr(thread, attr, &name) < 0) { + if (_PyObject_LookupAttr(thread, _Py_ID(name), &name) < 0) { return -1; } } @@ -1446,8 +1443,7 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, _PyErr_Display(file, exc_type, exc_value, exc_traceback); /* Call file.flush() */ - PyObject *attr = _Py_ID(flush); - PyObject *res = PyObject_CallMethodNoArgs(file, attr); + PyObject *res = PyObject_CallMethodNoArgs(file, _Py_ID(flush)); if (!res) { return -1; } @@ -1503,8 +1499,7 @@ thread_excepthook(PyObject *module, PyObject *args) PyObject *thread = PyStructSequence_GET_ITEM(args, 3); PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_ID(stderr); - PyObject *file = _PySys_GetAttr(tstate, attr); + PyObject *file = _PySys_GetAttr(tstate, _Py_ID(stderr)); if (file == NULL || file == Py_None) { if (thread == Py_None) { /* do nothing if sys.stderr is None and thread is None */ diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 0d7295769c52719..a3da993282655c1 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -147,12 +147,11 @@ faulthandler_get_fileno(PyObject **file_ptr) PyObject *result; long fd_long; int fd; - PyObject *attr, *file = *file_ptr; + PyObject *file = *file_ptr; if (file == NULL || file == Py_None) { PyThreadState *tstate = _PyThreadState_GET(); - attr = _Py_ID(stderr); - file = _PySys_GetAttr(tstate, attr); + file = _PySys_GetAttr(tstate, _Py_ID(stderr)); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "unable to get sys.stderr"); return -1; @@ -175,8 +174,7 @@ faulthandler_get_fileno(PyObject **file_ptr) return fd; } - attr = _Py_ID(fileno); - result = PyObject_CallMethodNoArgs(file, attr); + result = PyObject_CallMethodNoArgs(file, _Py_ID(fileno)); if (result == NULL) return -1; @@ -194,8 +192,7 @@ faulthandler_get_fileno(PyObject **file_ptr) return -1; } - attr = _Py_ID(flush); - result = PyObject_CallMethodNoArgs(file, attr); + result = PyObject_CallMethodNoArgs(file, _Py_ID(flush)); if (result != NULL) Py_DECREF(result); else { @@ -1335,8 +1332,7 @@ faulthandler_init_enable(void) return -1; } - PyObject *attr = _Py_ID(enable); - PyObject *res = PyObject_CallMethodNoArgs(module, attr); + PyObject *res = PyObject_CallMethodNoArgs(module, _Py_ID(enable)); Py_DECREF(module); if (res == NULL) { return -1; diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 82249e8d4c26f45..23ef9fc4df05973 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -504,8 +504,7 @@ static PyObject * _grouper_reduce(_grouperobject *lz, PyObject *Py_UNUSED(ignored)) { if (((groupbyobject *)lz->parent)->currgrouper != lz) { - PyObject *attr = _Py_ID(iter); - return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); } return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->parent, lz->tgtkey); } @@ -1031,8 +1030,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n) return NULL; } - PyObject *attr = _Py_ID(__copy__); - if (_PyObject_LookupAttr(it, attr, ©func) < 0) { + if (_PyObject_LookupAttr(it, _Py_ID(__copy__), ©func) < 0) { Py_DECREF(it); Py_DECREF(result); return NULL; @@ -1047,7 +1045,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n) Py_DECREF(result); return NULL; } - copyfunc = PyObject_GetAttr(copyable, attr); + copyfunc = PyObject_GetAttr(copyable, _Py_ID(__copy__)); if (copyfunc == NULL) { Py_DECREF(copyable); Py_DECREF(result); @@ -1179,8 +1177,8 @@ cycle_reduce(cycleobject *lz, PyObject *Py_UNUSED(ignored)) if (it == NULL) return NULL; if (lz->index != 0) { - PyObject *attr = _Py_ID(__setstate__); - PyObject *res = _PyObject_CallMethod(it, attr, "n", lz->index); + PyObject *res = _PyObject_CallMethod(it, _Py_ID(__setstate__), + "n", lz->index); if (res == NULL) { Py_DECREF(it); return NULL; @@ -4554,8 +4552,7 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_GET_SIZE(kwds) > 0) { fillvalue = NULL; if (PyDict_GET_SIZE(kwds) == 1) { - PyObject *attr = _Py_ID(fillvalue); - fillvalue = PyDict_GetItemWithError(kwds, attr); + fillvalue = PyDict_GetItemWithError(kwds, _Py_ID(fillvalue)); } if (fillvalue == NULL) { if (!PyErr_Occurred()) { diff --git a/Modules/main.c b/Modules/main.c index 8873aa8a2f1fda7..9cb1ce6de9c2b7f 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -161,8 +161,7 @@ pymain_sys_path_add_path0(PyInterpreterState *interp, PyObject *path0) PyObject *sys_path; PyObject *sysdict = interp->sysdict; if (sysdict != NULL) { - PyObject *attr = _Py_ID(path); - sys_path = PyDict_GetItemWithError(sysdict, attr); + sys_path = PyDict_GetItemWithError(sysdict, _Py_ID(path)); if (sys_path == NULL && PyErr_Occurred()) { return -1; } diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 5440258334632d0..fe0e6f1bf49a52a 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1157,8 +1157,7 @@ path_converter(PyObject *o, void *p) /* Inline PyOS_FSPath() for better error messages. */ PyObject *func, *res; - PyObject *attr = _Py_ID(__fspath__); - func = _PyObject_LookupSpecial(o, attr); + func = _PyObject_LookupSpecial(o, _Py_ID(__fspath__)); if (NULL == func) { goto error_format; } @@ -14436,8 +14435,7 @@ PyOS_FSPath(PyObject *path) return path; } - PyObject *attr = _Py_ID(__fspath__); - func = _PyObject_LookupSpecial(path, attr); + func = _PyObject_LookupSpecial(path, _Py_ID(__fspath__)); if (NULL == func) { return PyErr_Format(PyExc_TypeError, "expected str, bytes or os.PathLike object, " diff --git a/Modules/timemodule.c b/Modules/timemodule.c index b8f3ef968b0f8c3..623e3d89663b78a 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -916,8 +916,7 @@ time_strptime(PyObject *self, PyObject *args) if (!module) return NULL; - PyObject *attr = _Py_ID(_strptime_time); - func = PyObject_GetAttr(module, attr); + func = PyObject_GetAttr(module, _Py_ID(_strptime_time)); Py_DECREF(module); if (!func) { return NULL; diff --git a/Objects/abstract.c b/Objects/abstract.c index 633ab43bf11ad6c..335d80dfb79ba3f 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -106,8 +106,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) return res; } } - PyObject *attr = _Py_ID(__length_hint__); - hint = _PyObject_LookupSpecial(o, attr); + hint = _PyObject_LookupSpecial(o, _Py_ID(__length_hint__)); if (hint == NULL) { if (PyErr_Occurred()) { return -1; @@ -183,8 +182,7 @@ PyObject_GetItem(PyObject *o, PyObject *key) return Py_GenericAlias(o, key); } - PyObject *attr = _Py_ID(__class_getitem__); - if (_PyObject_LookupAttr(o, attr, &meth) < 0) { + if (_PyObject_LookupAttr(o, _Py_ID(__class_getitem__), &meth) < 0) { return NULL; } if (meth) { @@ -796,8 +794,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) } /* Find the (unbound!) __format__ method */ - PyObject *attr = _Py_ID(__format__); - meth = _PyObject_LookupSpecial(obj, attr); + meth = _PyObject_LookupSpecial(obj, _Py_ID(__format__)); if (meth == NULL) { PyThreadState *tstate = _PyThreadState_GET(); if (!_PyErr_Occurred(tstate)) { @@ -1561,8 +1558,7 @@ PyNumber_Long(PyObject *o) if (m && m->nb_index) { return PyNumber_Index(o); } - PyObject *attr = _Py_ID(__trunc__); - trunc_func = _PyObject_LookupSpecial(o, attr); + trunc_func = _PyObject_LookupSpecial(o, _Py_ID(__trunc__)); if (trunc_func) { result = _PyObject_CallNoArgs(trunc_func); Py_DECREF(trunc_func); @@ -2438,8 +2434,7 @@ PyMapping_Keys(PyObject *o) if (PyDict_CheckExact(o)) { return PyDict_Keys(o); } - PyObject *attr = _Py_ID(keys); - return method_output_as_list(o, attr); + return method_output_as_list(o, _Py_ID(keys)); } PyObject * @@ -2451,8 +2446,7 @@ PyMapping_Items(PyObject *o) if (PyDict_CheckExact(o)) { return PyDict_Items(o); } - PyObject *attr = _Py_ID(items); - return method_output_as_list(o, attr); + return method_output_as_list(o, _Py_ID(items)); } PyObject * @@ -2464,8 +2458,7 @@ PyMapping_Values(PyObject *o) if (PyDict_CheckExact(o)) { return PyDict_Values(o); } - PyObject *attr = _Py_ID(values); - return method_output_as_list(o, attr); + return method_output_as_list(o, _Py_ID(values)); } /* isinstance(), issubclass() */ @@ -2499,8 +2492,7 @@ abstract_get_bases(PyObject *cls) { PyObject *bases; - PyObject *attr = _Py_ID(__bases__); - (void)_PyObject_LookupAttr(cls, attr, &bases); + (void)_PyObject_LookupAttr(cls, _Py_ID(__bases__), &bases); if (bases != NULL && !PyTuple_Check(bases)) { Py_DECREF(bases); return NULL; @@ -2581,11 +2573,10 @@ object_isinstance(PyObject *inst, PyObject *cls) { PyObject *icls; int retval; - PyObject *attr = _Py_ID(__class__); if (PyType_Check(cls)) { retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls); if (retval == 0) { - retval = _PyObject_LookupAttr(inst, attr, &icls); + retval = _PyObject_LookupAttr(inst, _Py_ID(__class__), &icls); if (icls != NULL) { if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) { retval = PyType_IsSubtype( @@ -2603,7 +2594,7 @@ object_isinstance(PyObject *inst, PyObject *cls) if (!check_class(cls, "isinstance() arg 2 must be a type, a tuple of types, or a union")) return -1; - retval = _PyObject_LookupAttr(inst, attr, &icls); + retval = _PyObject_LookupAttr(inst, _Py_ID(__class__), &icls); if (icls != NULL) { retval = abstract_issubclass(icls, cls); Py_DECREF(icls); @@ -2646,8 +2637,7 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls return r; } - PyObject *attr = _Py_ID(__instancecheck__); - PyObject *checker = _PyObject_LookupSpecial(cls, attr); + PyObject *checker = _PyObject_LookupSpecial(cls, _Py_ID(__instancecheck__)); if (checker != NULL) { if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) { Py_DECREF(checker); @@ -2734,8 +2724,7 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) return r; } - PyObject *attr = _Py_ID(__subclasscheck__); - checker = _PyObject_LookupSpecial(cls, attr); + checker = _PyObject_LookupSpecial(cls, _Py_ID(__subclasscheck__)); if (checker != NULL) { int ok = -1; if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) { @@ -2881,8 +2870,7 @@ PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result) *result = Py_TYPE(iter)->tp_iternext(iter); } else { - PyObject *attr = _Py_ID(send); - *result = PyObject_CallMethodOneArg(iter, attr, arg); + *result = PyObject_CallMethodOneArg(iter, _Py_ID(send), arg); } if (*result != NULL) { return PYGEN_NEXT; diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 6c45e7202cbdc52..22ae442367b5a28 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2113,8 +2113,7 @@ _common_reduce(PyByteArrayObject *self, int proto) PyObject *dict; char *buf; - PyObject *attr = _Py_ID(__dict__); - if (_PyObject_LookupAttr((PyObject *)self, attr, &dict) < 0) { + if (_PyObject_LookupAttr((PyObject *)self, _Py_ID(__dict__), &dict) < 0) { return NULL; } if (dict == NULL) { @@ -2427,12 +2426,11 @@ PyDoc_STRVAR(length_hint_doc, static PyObject * bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(iter); if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), it->it_seq, it->it_index); } else { - return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); } } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index 6a129daff76b8f0..b6ff81b0f35236a 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -528,8 +528,7 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen) return v; } /* does it support __bytes__? */ - PyObject *attr = _Py_ID(__bytes__); - func = _PyObject_LookupSpecial(v, attr); + func = _PyObject_LookupSpecial(v, _Py_ID(__bytes__)); if (func != NULL) { result = _PyObject_CallNoArgs(func); Py_DECREF(func); @@ -2550,7 +2549,6 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding, PyObject *bytes; PyObject *func; Py_ssize_t size; - PyObject *__bytes__ = _Py_ID(__bytes__); if (x == NULL) { if (encoding != NULL || errors != NULL) { @@ -2581,7 +2579,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding, /* We'd like to call PyObject_Bytes here, but we need to check for an integer argument before deferring to PyBytes_FromObject, something PyObject_Bytes doesn't do. */ - else if ((func = _PyObject_LookupSpecial(x, __bytes__)) != NULL) { + else if ((func = _PyObject_LookupSpecial(x, _Py_ID(__bytes__))) != NULL) { bytes = _PyObject_CallNoArgs(func); Py_DECREF(func); if (bytes == NULL) @@ -3121,12 +3119,11 @@ PyDoc_STRVAR(length_hint_doc, static PyObject * striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(iter); if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), it->it_seq, it->it_index); } else { - return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); } } diff --git a/Objects/classobject.c b/Objects/classobject.c index 251dc58c6cbcc5b..71f932200f813cb 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -122,13 +122,12 @@ method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored)) PyObject *func = PyMethod_GET_FUNCTION(im); PyObject *funcname; - PyObject *attr = _Py_ID(__name__); - funcname = PyObject_GetAttr(func, attr); + funcname = PyObject_GetAttr(func, _Py_ID(__name__)); if (funcname == NULL) { return NULL; } - attr = _Py_ID(getattr); - return Py_BuildValue("N(ON)", _PyEval_GetBuiltin(attr), self, funcname); + return Py_BuildValue( + "N(ON)", _PyEval_GetBuiltin(_Py_ID(getattr)), self, funcname); } static PyMethodDef method_methods[] = { @@ -278,10 +277,9 @@ method_repr(PyMethodObject *a) PyObject *funcname, *result; const char *defname = "?"; - PyObject *attr1 = _Py_ID(__qualname__); - PyObject *attr2 = _Py_ID(__name__); - if (_PyObject_LookupAttr(func, attr1, &funcname) < 0 || - (funcname == NULL && _PyObject_LookupAttr(func, attr2, &funcname) < 0)) + if (_PyObject_LookupAttr(func, _Py_ID(__qualname__), &funcname) < 0 || + (funcname == NULL && + _PyObject_LookupAttr(func, _Py_ID(__name__), &funcname) < 0)) { return NULL; } @@ -514,8 +512,7 @@ instancemethod_repr(PyObject *self) return NULL; } - PyObject *attr = _Py_ID(__name__); - if (_PyObject_LookupAttr(func, attr, &funcname) < 0) { + if (_PyObject_LookupAttr(func, _Py_ID(__name__), &funcname) < 0) { return NULL; } if (funcname != NULL && !PyUnicode_Check(funcname)) { diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 338cceb0ba923df..953c9611895be2f 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -282,8 +282,7 @@ try_complex_special_method(PyObject *op) { PyObject *f; - PyObject *attr = _Py_ID(__complex__); - f = _PyObject_LookupSpecial(op, attr); + f = _PyObject_LookupSpecial(op, _Py_ID(__complex__)); if (f) { PyObject *res = _PyObject_CallNoArgs(f); Py_DECREF(f); diff --git a/Objects/descrobject.c b/Objects/descrobject.c index a64a630bd4cedf8..b3c50727cef68e9 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -576,8 +576,8 @@ calculate_qualname(PyDescrObject *descr) return NULL; } - PyObject *attr = _Py_ID(__qualname__); - type_qualname = PyObject_GetAttr((PyObject *)descr->d_type, attr); + type_qualname = PyObject_GetAttr( + (PyObject *)descr->d_type, _Py_ID(__qualname__)); if (type_qualname == NULL) return NULL; @@ -605,8 +605,7 @@ descr_get_qualname(PyDescrObject *descr, void *Py_UNUSED(ignored)) static PyObject * descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(getattr); - return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(_Py_ID(getattr)), PyDescr_TYPE(descr), PyDescr_NAME(descr)); } @@ -1084,8 +1083,7 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs { return NULL; } - PyObject *attr = _Py_ID(get); - return _PyObject_VectorcallMethod(attr, newargs, + return _PyObject_VectorcallMethod(_Py_ID(get), newargs, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); } @@ -1093,36 +1091,31 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs static PyObject * mappingproxy_keys(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(keys); - return PyObject_CallMethodNoArgs(pp->mapping, attr); + return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(keys)); } static PyObject * mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(values); - return PyObject_CallMethodNoArgs(pp->mapping, attr); + return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(values)); } static PyObject * mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(items); - return PyObject_CallMethodNoArgs(pp->mapping, attr); + return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(items)); } static PyObject * mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(copy); - return PyObject_CallMethodNoArgs(pp->mapping, attr); + return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(copy)); } static PyObject * mappingproxy_reversed(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(__reversed__); - return PyObject_CallMethodNoArgs(pp->mapping, attr); + return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(__reversed__)); } /* WARNING: mappingproxy methods must not give access @@ -1319,8 +1312,7 @@ wrapper_repr(wrapperobject *wp) static PyObject * wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(getattr); - return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(_Py_ID(getattr)), wp->self, PyDescr_NAME(wp->descr)); } @@ -1756,8 +1748,7 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, /* if no docstring given and the getter has one, use that one */ if ((doc == NULL || doc == Py_None) && fget != NULL) { PyObject *get_doc; - PyObject *attr = _Py_ID(__doc__); - int rc = _PyObject_LookupAttr(fget, attr, &get_doc); + int rc = _PyObject_LookupAttr(fget, _Py_ID(__doc__), &get_doc); if (rc <= 0) { return rc; } @@ -1769,7 +1760,8 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, in dict of the subclass instance instead, otherwise it gets shadowed by __doc__ in the class's dict. */ - int err = PyObject_SetAttr((PyObject *)self, attr, get_doc); + int err = PyObject_SetAttr( + (PyObject *)self, _Py_ID(__doc__), get_doc); Py_DECREF(get_doc); if (err < 0) return -1; diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 95ac24b01b3b4a8..292c674d1f257e8 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2160,8 +2160,8 @@ dict_subscript(PyDictObject *mp, PyObject *key) if (!PyDict_CheckExact(mp)) { /* Look up __missing__ method if we're a subclass. */ PyObject *missing, *res; - PyObject *attr = _Py_ID(__missing__); - missing = _PyObject_LookupSpecial((PyObject *)mp, attr); + missing = _PyObject_LookupSpecial( + (PyObject *)mp, _Py_ID(__missing__)); if (missing != NULL) { res = PyObject_CallOneArg(missing, key); Py_DECREF(missing); @@ -2364,8 +2364,7 @@ dict_update_arg(PyObject *self, PyObject *arg) return PyDict_Merge(self, arg, 1); } PyObject *func; - PyObject *attr = _Py_ID(keys); - if (_PyObject_LookupAttr(arg, attr, &func) < 0) { + if (_PyObject_LookupAttr(arg, _Py_ID(keys), &func) < 0) { return -1; } if (func != NULL) { @@ -4130,8 +4129,7 @@ dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - PyObject *attr = _Py_ID(iter); - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), list); } PyTypeObject PyDictRevIterItem_Type = { @@ -4401,8 +4399,8 @@ dictviews_sub(PyObject *self, PyObject *other) return NULL; } - PyObject *attr = _Py_ID(difference_update); - PyObject *tmp = PyObject_CallMethodOneArg(result, attr, other); + PyObject *tmp = PyObject_CallMethodOneArg( + result, _Py_ID(difference_update), other); if (tmp == NULL) { Py_DECREF(result); return NULL; @@ -4438,8 +4436,8 @@ _PyDictView_Intersect(PyObject* self, PyObject *other) /* if other is a set and self is smaller than other, reuse set intersection logic */ if (PySet_CheckExact(other) && len_self <= PyObject_Size(other)) { - PyObject *attr = _Py_ID(intersection); - return PyObject_CallMethodObjArgs(other, attr, self, NULL); + return PyObject_CallMethodObjArgs( + other, _Py_ID(intersection), self, NULL); } /* if other is another dict view, and it is bigger than self, @@ -4579,8 +4577,8 @@ dictitems_xor(PyObject *self, PyObject *other) } key = val1 = val2 = NULL; - PyObject *attr = _Py_ID(items); - PyObject *remaining_pairs = PyObject_CallMethodNoArgs(temp_dict, attr); + PyObject *remaining_pairs = PyObject_CallMethodNoArgs( + temp_dict, _Py_ID(items)); if (remaining_pairs == NULL) { goto error; } @@ -4612,8 +4610,8 @@ dictviews_xor(PyObject* self, PyObject *other) return NULL; } - PyObject *attr = _Py_ID(symmetric_difference_update); - PyObject *tmp = PyObject_CallMethodOneArg(result, attr, other); + PyObject *tmp = PyObject_CallMethodOneArg( + result, _Py_ID(symmetric_difference_update), other); if (tmp == NULL) { Py_DECREF(result); return NULL; diff --git a/Objects/enumobject.c b/Objects/enumobject.c index f73f811a63f282e..825cd8dcaa9cc66 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -357,8 +357,7 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq) PyObject *reversed_meth; reversedobject *ro; - PyObject *attr = _Py_ID(__reversed__); - reversed_meth = _PyObject_LookupSpecial(seq, attr); + reversed_meth = _PyObject_LookupSpecial(seq, _Py_ID(__reversed__)); if (reversed_meth == Py_None) { Py_DECREF(reversed_meth); PyErr_Format(PyExc_TypeError, diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 5b76824090ee9e1..cfd28294a7b5305 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1502,13 +1502,11 @@ ImportError_getstate(PyImportErrorObject *self) dict = dict ? PyDict_Copy(dict) : PyDict_New(); if (dict == NULL) return NULL; - PyObject *attr = _Py_ID(name); - if (self->name && PyDict_SetItem(dict, attr, self->name) < 0) { + if (self->name && PyDict_SetItem(dict, _Py_ID(name), self->name) < 0) { Py_DECREF(dict); return NULL; } - attr = _Py_ID(path); - if (self->path && PyDict_SetItem(dict, attr, self->path) < 0) { + if (self->path && PyDict_SetItem(dict, _Py_ID(path), self->path) < 0) { Py_DECREF(dict); return NULL; } diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 9341d1511188317..9c31bd8586f8970 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -38,8 +38,7 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c io = PyImport_ImportModule("_io"); if (io == NULL) return NULL; - PyObject *attr = _Py_ID(open); - stream = _PyObject_CallMethod(io, attr, "isisssO", fd, mode, + stream = _PyObject_CallMethod(io, _Py_ID(open), "isisssO", fd, mode, buffering, encoding, errors, newline, closefd ? Py_True : Py_False); Py_DECREF(io); @@ -60,12 +59,11 @@ PyFile_GetLine(PyObject *f, int n) return NULL; } - PyObject *attr = _Py_ID(readline); if (n <= 0) { - result = PyObject_CallMethodNoArgs(f, attr); + result = PyObject_CallMethodNoArgs(f, _Py_ID(readline)); } else { - result = _PyObject_CallMethod(f, attr, "i", n); + result = _PyObject_CallMethod(f, _Py_ID(readline), "i", n); } if (result != NULL && !PyBytes_Check(result) && !PyUnicode_Check(result)) { @@ -124,8 +122,7 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags) PyErr_SetString(PyExc_TypeError, "writeobject with NULL file"); return -1; } - PyObject *attr = _Py_ID(write); - writer = PyObject_GetAttr(f, attr); + writer = PyObject_GetAttr(f, _Py_ID(write)); if (writer == NULL) return -1; if (flags & Py_PRINT_RAW) { @@ -182,11 +179,10 @@ PyObject_AsFileDescriptor(PyObject *o) int fd; PyObject *meth; - PyObject *attr = _Py_ID(fileno); if (PyLong_Check(o)) { fd = _PyLong_AsInt(o); } - else if (_PyObject_LookupAttr(o, attr, &meth) < 0) { + else if (_PyObject_LookupAttr(o, _Py_ID(fileno), &meth) < 0) { return -1; } else if (meth != NULL) { @@ -508,8 +504,7 @@ PyFile_OpenCodeObject(PyObject *path) } else { iomod = PyImport_ImportModule("_io"); if (iomod) { - PyObject *attr = _Py_ID(open); - f = _PyObject_CallMethod(iomod, attr, "Os", path, "rb"); + f = _PyObject_CallMethod(iomod, _Py_ID(open), "Os", path, "rb"); Py_DECREF(iomod); } } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 03c4d1cc846c9b4..756bd3fbf407dc4 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -1078,8 +1078,7 @@ PyFrame_GetBack(PyFrameObject *frame) PyObject* _PyEval_BuiltinsFromGlobals(PyThreadState *tstate, PyObject *globals) { - PyObject *attr = _Py_ID(__builtins__); - PyObject *builtins = PyDict_GetItemWithError(globals, attr); + PyObject *builtins = PyDict_GetItemWithError(globals, _Py_ID(__builtins__)); if (builtins) { if (PyModule_Check(builtins)) { builtins = _PyModule_GetDict(builtins); diff --git a/Objects/funcobject.c b/Objects/funcobject.c index d83d2e99972ed1f..1f3f9d04f508914 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -79,8 +79,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname Py_INCREF(doc); // __module__: Use globals['__name__'] if it exists, or NULL. - PyObject *attr = _Py_ID(__name__); - PyObject *module = PyDict_GetItemWithError(globals, attr); + PyObject *module = PyDict_GetItemWithError(globals, _Py_ID(__name__)); PyObject *builtins = NULL; if (module == NULL && _PyErr_Occurred(tstate)) { goto error; @@ -808,8 +807,7 @@ functools_wraps(PyObject *wrapper, PyObject *wrapped) { #define COPY_ATTR(ATTR) \ do { \ - PyObject *attr = _Py_ID(ATTR); \ - if (functools_copy_attr(wrapper, wrapped, attr) < 0) { \ + if (functools_copy_attr(wrapper, wrapped, _Py_ID(ATTR)) < 0) { \ return -1; \ } \ } while (0) \ diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index ab31a2d764cda84..47b5a440a6354a7 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -53,14 +53,12 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) goto done; } - PyObject *attr = _Py_ID(__origin__); - if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { + if (_PyObject_LookupAttr(p, _Py_ID(__origin__), &tmp) < 0) { goto done; } if (tmp != NULL) { Py_DECREF(tmp); - attr = _Py_ID(__args__); - if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { + if (_PyObject_LookupAttr(p, _Py_ID(__args__), &tmp) < 0) { goto done; } if (tmp != NULL) { @@ -70,15 +68,13 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) } } - attr = _Py_ID(__qualname__); - if (_PyObject_LookupAttr(p, attr, &qualname) < 0) { + if (_PyObject_LookupAttr(p, _Py_ID(__qualname__), &qualname) < 0) { goto done; } if (qualname == NULL) { goto use_repr; } - attr = _Py_ID(__module__); - if (_PyObject_LookupAttr(p, attr, &module) < 0) { + if (_PyObject_LookupAttr(p, _Py_ID(__module__), &module) < 0) { goto done; } if (module == NULL || module == Py_None) { @@ -219,8 +215,8 @@ _Py_make_parameters(PyObject *args) } else { PyObject *subparams; - PyObject *attr = _Py_ID(__parameters__); - if (_PyObject_LookupAttr(t, attr, &subparams) < 0) { + if (_PyObject_LookupAttr(t, _Py_ID(__parameters__), + &subparams) < 0) { Py_DECREF(parameters); return NULL; } @@ -261,8 +257,7 @@ static PyObject * subs_tvars(PyObject *obj, PyObject *params, PyObject **argitems) { PyObject *subparams; - PyObject *attr = _Py_ID(__parameters__); - if (_PyObject_LookupAttr(obj, attr, &subparams) < 0) { + if (_PyObject_LookupAttr(obj, _Py_ID(__parameters__), &subparams) < 0) { return NULL; } if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) { diff --git a/Objects/genobject.c b/Objects/genobject.c index b1c2584f5b692ad..c213adf23464028 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -328,8 +328,7 @@ gen_close_iter(PyObject *yf) } else { PyObject *meth; - PyObject *attr = _Py_ID(close); - if (_PyObject_LookupAttr(yf, attr, &meth) < 0) { + if (_PyObject_LookupAttr(yf, _Py_ID(close), &meth) < 0) { PyErr_WriteUnraisable(yf); } if (meth) { @@ -461,8 +460,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, } else { /* `yf` is an iterator or a coroutine-like object. */ PyObject *meth; - PyObject *attr = _Py_ID(throw); - if (_PyObject_LookupAttr(yf, attr, &meth) < 0) { + if (_PyObject_LookupAttr(yf, _Py_ID(throw), &meth) < 0) { Py_DECREF(yf); return NULL; } diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 740efc93c549b0a..9a139e50b6d1ce3 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -103,12 +103,11 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(iter); if (it->it_seq != NULL) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), it->it_seq, it->it_index); else - return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); } PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); @@ -243,12 +242,11 @@ calliter_iternext(calliterobject *it) static PyObject * calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(iter); if (it->it_callable != NULL && it->it_sentinel != NULL) - return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(_Py_ID(iter)), it->it_callable, it->it_sentinel); else - return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); } static PyMethodDef calliter_methods[] = { diff --git a/Objects/listobject.c b/Objects/listobject.c index db40fe58a5ca3ee..698457939fe0742 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -3505,21 +3505,19 @@ listreviter_setstate(listreviterobject *it, PyObject *state) static PyObject * listiter_reduce_general(void *_it, int forward) { - PyObject *list, *attr; + PyObject *list; /* the objects are not the same, index is of different types! */ if (forward) { listiterobject *it = (listiterobject *)_it; if (it->it_seq) { - attr = _Py_ID(iter); - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), it->it_seq, it->it_index); } } else { listreviterobject *it = (listreviterobject *)_it; if (it->it_seq) { - attr = _Py_ID(reversed); - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(reversed)), it->it_seq, it->it_index); } } @@ -3527,6 +3525,5 @@ listiter_reduce_general(void *_it, int forward) list = PyList_New(0); if (list == NULL) return NULL; - attr = _Py_ID(iter); - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), list); } diff --git a/Objects/longobject.c b/Objects/longobject.c index f3c57a49f3e8b04..1f5082917df609a 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -5770,13 +5770,11 @@ int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder, int little_endian; PyObject *bytes; - PyObject *little = _Py_ID(little); - PyObject *big = _Py_ID(big); if (byteorder == NULL) little_endian = 0; - else if (_PyUnicode_Equal(byteorder, little)) + else if (_PyUnicode_Equal(byteorder, _Py_ID(little))) little_endian = 1; - else if (_PyUnicode_Equal(byteorder, big)) + else if (_PyUnicode_Equal(byteorder, _Py_ID(big))) little_endian = 0; else { PyErr_SetString(PyExc_ValueError, @@ -5834,13 +5832,11 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, int little_endian; PyObject *long_obj, *bytes; - PyObject *little = _Py_ID(little); - PyObject *big = _Py_ID(big); if (byteorder == NULL) little_endian = 0; - else if (_PyUnicode_Equal(byteorder, little)) + else if (_PyUnicode_Equal(byteorder, _Py_ID(little))) little_endian = 1; - else if (_PyUnicode_Equal(byteorder, big)) + else if (_PyUnicode_Equal(byteorder, _Py_ID(big))) little_endian = 0; else { PyErr_SetString(PyExc_ValueError, diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 83f040d4f678d85..912594b5bc09b21 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -182,8 +182,7 @@ meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored)) if (m->m_self == NULL || PyModule_Check(m->m_self)) return PyUnicode_FromString(m->m_ml->ml_name); - PyObject *attr = _Py_ID(getattr); - return Py_BuildValue("N(Os)", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(Os)", _PyEval_GetBuiltin(_Py_ID(getattr)), m->m_self, m->m_ml->ml_name); } @@ -228,8 +227,7 @@ meth_get__qualname__(PyCFunctionObject *m, void *closure) type = PyType_Check(m->m_self) ? m->m_self : (PyObject*)Py_TYPE(m->m_self); - PyObject *attr = _Py_ID(__qualname__); - type_qualname = PyObject_GetAttr(type, attr); + type_qualname = PyObject_GetAttr(type, _Py_ID(__qualname__)); if (type_qualname == NULL) return NULL; diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 050c89e2b66cc67..626a669d4990a64 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -58,20 +58,15 @@ module_init_dict(PyModuleObject *mod, PyObject *md_dict, if (doc == NULL) doc = Py_None; - PyObject *attr = _Py_ID(__name__); - if (PyDict_SetItem(md_dict, attr, name) != 0) + if (PyDict_SetItem(md_dict, _Py_ID(__name__), name) != 0) return -1; - attr = _Py_ID(__doc__); - if (PyDict_SetItem(md_dict, attr, doc) != 0) + if (PyDict_SetItem(md_dict, _Py_ID(__doc__), doc) != 0) return -1; - attr = _Py_ID(__package__); - if (PyDict_SetItem(md_dict, attr, Py_None) != 0) + if (PyDict_SetItem(md_dict, _Py_ID(__package__), Py_None) != 0) return -1; - attr = _Py_ID(__loader__); - if (PyDict_SetItem(md_dict, attr, Py_None) != 0) + if (PyDict_SetItem(md_dict, _Py_ID(__loader__), Py_None) != 0) return -1; - attr = _Py_ID(__spec__); - if (PyDict_SetItem(md_dict, attr, Py_None) != 0) + if (PyDict_SetItem(md_dict, _Py_ID(__spec__), Py_None) != 0) return -1; if (PyUnicode_CheckExact(name)) { Py_INCREF(name); @@ -467,10 +462,9 @@ int PyModule_SetDocString(PyObject *m, const char *doc) { PyObject *v; - PyObject *attr = _Py_ID(__doc__); v = PyUnicode_FromString(doc); - if (v == NULL || PyObject_SetAttr(m, attr, v) != 0) { + if (v == NULL || PyObject_SetAttr(m, _Py_ID(__doc__), v) != 0) { Py_XDECREF(v); return -1; } @@ -497,10 +491,9 @@ PyModule_GetNameObject(PyObject *m) PyErr_BadArgument(); return NULL; } - PyObject *attr = _Py_ID(__name__); d = ((PyModuleObject *)m)->md_dict; if (d == NULL || !PyDict_Check(d) || - (name = PyDict_GetItemWithError(d, attr)) == NULL || + (name = PyDict_GetItemWithError(d, _Py_ID(__name__))) == NULL || !PyUnicode_Check(name)) { if (!PyErr_Occurred()) { @@ -531,10 +524,9 @@ PyModule_GetFilenameObject(PyObject *m) PyErr_BadArgument(); return NULL; } - PyObject *attr = _Py_ID(__file__); d = ((PyModuleObject *)m)->md_dict; if (d == NULL || - (fileobj = PyDict_GetItemWithError(d, attr)) == NULL || + (fileobj = PyDict_GetItemWithError(d, _Py_ID(__file__))) == NULL || !PyUnicode_Check(fileobj)) { if (!PyErr_Occurred()) { @@ -723,8 +715,7 @@ int _PyModuleSpec_IsInitializing(PyObject *spec) { if (spec != NULL) { - PyObject *attr = _Py_ID(_initializing); - PyObject *value = PyObject_GetAttr(spec, attr); + PyObject *value = PyObject_GetAttr(spec, _Py_ID(_initializing)); if (value != NULL) { int initializing = PyObject_IsTrue(value); Py_DECREF(value); @@ -747,8 +738,7 @@ _PyModuleSpec_IsUninitializedSubmodule(PyObject *spec, PyObject *name) return 0; } - PyObject *attr = _Py_ID(_uninitialized_submodules); - PyObject *value = PyObject_GetAttr(spec, attr); + PyObject *value = PyObject_GetAttr(spec, _Py_ID(_uninitialized_submodules)); if (value == NULL) { return 0; } @@ -764,27 +754,24 @@ _PyModuleSpec_IsUninitializedSubmodule(PyObject *spec, PyObject *name) static PyObject* module_getattro(PyModuleObject *m, PyObject *name) { - PyObject *attr, *mod_name, *getattr, *str; + PyObject *attr, *mod_name, *getattr; attr = PyObject_GenericGetAttr((PyObject *)m, name); if (attr || !PyErr_ExceptionMatches(PyExc_AttributeError)) { return attr; } PyErr_Clear(); assert(m->md_dict != NULL); - str = _Py_ID(__getattr__); - getattr = PyDict_GetItemWithError(m->md_dict, str); + getattr = PyDict_GetItemWithError(m->md_dict, _Py_ID(__getattr__)); if (getattr) { return PyObject_CallOneArg(getattr, name); } if (PyErr_Occurred()) { return NULL; } - str = _Py_ID(__name__); - mod_name = PyDict_GetItemWithError(m->md_dict, str); + mod_name = PyDict_GetItemWithError(m->md_dict, _Py_ID(__name__)); if (mod_name && PyUnicode_Check(mod_name)) { Py_INCREF(mod_name); - str = _Py_ID(__spec__); - PyObject *spec = PyDict_GetItemWithError(m->md_dict, str); + PyObject *spec = PyDict_GetItemWithError(m->md_dict, _Py_ID(__spec__)); if (spec == NULL && PyErr_Occurred()) { Py_DECREF(mod_name); return NULL; @@ -860,13 +847,11 @@ static PyObject * module_dir(PyObject *self, PyObject *args) { PyObject *result = NULL; - PyObject *attr = _Py_ID(__dict__); - PyObject *dict = PyObject_GetAttr(self, attr); + PyObject *dict = PyObject_GetAttr(self, _Py_ID(__dict__)); if (dict != NULL) { if (PyDict_Check(dict)) { - attr = _Py_ID(__dir__); - PyObject *dirfunc = PyDict_GetItemWithError(dict, attr); + PyObject *dirfunc = PyDict_GetItemWithError(dict, _Py_ID(__dir__)); if (dirfunc) { result = _PyObject_CallNoArgs(dirfunc); } @@ -892,8 +877,7 @@ static PyMethodDef module_methods[] = { static PyObject * module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(__dict__); - PyObject *dict = PyObject_GetAttr((PyObject *)m, attr); + PyObject *dict = PyObject_GetAttr((PyObject *)m, _Py_ID(__dict__)); if ((dict == NULL) || !PyDict_Check(dict)) { PyErr_Format(PyExc_TypeError, ".__dict__ is not a dictionary"); @@ -902,10 +886,9 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) } PyObject *annotations; - attr = _Py_ID(__annotations__); /* there's no _PyDict_GetItemId without WithError, so let's LBYL. */ - if (PyDict_Contains(dict, attr)) { - annotations = PyDict_GetItemWithError(dict, attr); + if (PyDict_Contains(dict, _Py_ID(__annotations__))) { + annotations = PyDict_GetItemWithError(dict, _Py_ID(__annotations__)); /* ** _PyDict_GetItemIdWithError could still fail, ** for instance with a well-timed Ctrl-C or a MemoryError. @@ -917,7 +900,8 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) } else { annotations = PyDict_New(); if (annotations) { - int result = PyDict_SetItem(dict, attr, annotations); + int result = PyDict_SetItem( + dict, _Py_ID(__annotations__), annotations); if (result) { Py_CLEAR(annotations); } @@ -931,28 +915,26 @@ static int module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignored)) { int ret = -1; - PyObject *attr = _Py_ID(__dict__); - PyObject *dict = PyObject_GetAttr((PyObject *)m, attr); + PyObject *dict = PyObject_GetAttr((PyObject *)m, _Py_ID(__dict__)); if ((dict == NULL) || !PyDict_Check(dict)) { PyErr_Format(PyExc_TypeError, ".__dict__ is not a dictionary"); goto exit; } - attr = _Py_ID(__annotations__); if (value != NULL) { /* set */ - ret = PyDict_SetItem(dict, attr, value); + ret = PyDict_SetItem(dict, _Py_ID(__annotations__), value); goto exit; } /* delete */ - if (!PyDict_Contains(dict, attr)) { + if (!PyDict_Contains(dict, _Py_ID(__annotations__))) { PyErr_Format(PyExc_AttributeError, "__annotations__"); goto exit; } - ret = PyDict_DelItem(dict, attr); + ret = PyDict_DelItem(dict, _Py_ID(__annotations__)); exit: Py_XDECREF(dict); diff --git a/Objects/object.c b/Objects/object.c index 02925f095936e1d..2b7ae16aa7d48dc 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -557,8 +557,7 @@ PyObject_Bytes(PyObject *v) return v; } - PyObject *attr = _Py_ID(__bytes__); - func = _PyObject_LookupSpecial(v, attr); + func = _PyObject_LookupSpecial(v, _Py_ID(__bytes__)); if (func != NULL) { result = _PyObject_CallNoArgs(func); Py_DECREF(func); @@ -598,8 +597,7 @@ _PyObject_FunctionStr(PyObject *x) { assert(!PyErr_Occurred()); PyObject *qualname; - PyObject *attr = _Py_ID(__qualname__); - int ret = _PyObject_LookupAttr(x, attr, &qualname); + int ret = _PyObject_LookupAttr(x, _Py_ID(__qualname__), &qualname); if (qualname == NULL) { if (ret < 0) { return NULL; @@ -608,11 +606,9 @@ _PyObject_FunctionStr(PyObject *x) } PyObject *module; PyObject *result = NULL; - attr = _Py_ID(__module__); - ret = _PyObject_LookupAttr(x, attr, &module); + ret = _PyObject_LookupAttr(x, _Py_ID(__module__), &module); if (module != NULL && module != Py_None) { - PyObject *builtinsname = _Py_ID(builtins); - ret = PyObject_RichCompareBool(module, builtinsname, Py_NE); + ret = PyObject_RichCompareBool(module, _Py_ID(builtins), Py_NE); if (ret < 0) { // error goto done; @@ -850,8 +846,7 @@ _PyObject_IsAbstract(PyObject *obj) if (obj == NULL) return 0; - PyObject *attr = _Py_ID(__isabstractmethod__); - res = _PyObject_LookupAttr(obj, attr, &isabstract); + res = _PyObject_LookupAttr(obj, _Py_ID(__isabstractmethod__), &isabstract); if (res > 0) { res = PyObject_IsTrue(isabstract); Py_DECREF(isabstract); @@ -891,11 +886,9 @@ set_attribute_error_context(PyObject* v, PyObject* name) PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); PyErr_NormalizeException(&type, &value, &traceback); - PyObject *attr1 = _Py_ID(name); - PyObject *attr2 = _Py_ID(obj); if (PyErr_GivenExceptionMatches(value, PyExc_AttributeError) && - (PyObject_SetAttr(value, attr1, name) || - PyObject_SetAttr(value, attr2, v))) { + (PyObject_SetAttr(value, _Py_ID(name), name) || + PyObject_SetAttr(value, _Py_ID(obj), v))) { return 1; } PyErr_Restore(type, value, traceback); @@ -1562,8 +1555,7 @@ static PyObject * _dir_object(PyObject *obj) { PyObject *result, *sorted; - PyObject *attr = _Py_ID(__dir__); - PyObject *dirfunc = _PyObject_LookupSpecial(obj, attr); + PyObject *dirfunc = _PyObject_LookupSpecial(obj, _Py_ID(__dir__)); assert(obj != NULL); if (dirfunc == NULL) { @@ -2142,8 +2134,7 @@ Py_ReprEnter(PyObject *obj) early on startup. */ if (dict == NULL) return 0; - PyObject *attr = _Py_ID(Py_Repr); - list = PyDict_GetItemWithError(dict, attr); + list = PyDict_GetItemWithError(dict, _Py_ID(Py_Repr)); if (list == NULL) { if (PyErr_Occurred()) { return -1; @@ -2151,7 +2142,7 @@ Py_ReprEnter(PyObject *obj) list = PyList_New(0); if (list == NULL) return -1; - if (PyDict_SetItem(dict, attr, list) < 0) + if (PyDict_SetItem(dict, _Py_ID(Py_Repr), list) < 0) return -1; Py_DECREF(list); } @@ -2179,8 +2170,7 @@ Py_ReprLeave(PyObject *obj) if (dict == NULL) goto finally; - PyObject *attr = _Py_ID(Py_Repr); - list = PyDict_GetItemWithError(dict, attr); + list = PyDict_GetItemWithError(dict, _Py_ID(Py_Repr)); if (list == NULL || !PyList_Check(list)) goto finally; diff --git a/Objects/odictobject.c b/Objects/odictobject.c index 153853afb7296c7..a3f6846a74b68cb 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -951,8 +951,7 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) PyObject *items_iter, *items, *args = NULL; /* capture any instance state */ - PyObject *attr = _Py_ID(__dict__); - dict = PyObject_GetAttr((PyObject *)od, attr); + dict = PyObject_GetAttr((PyObject *)od, _Py_ID(__dict__)); if (dict == NULL) goto Done; else { @@ -971,8 +970,7 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) if (args == NULL) goto Done; - attr = _Py_ID(items); - items = PyObject_CallMethodNoArgs((PyObject *)od, attr); + items = PyObject_CallMethodNoArgs((PyObject *)od, _Py_ID(items)); if (items == NULL) goto Done; @@ -1430,8 +1428,8 @@ odict_repr(PyODictObject *self) } } else { - PyObject *attr = _Py_ID(items); - PyObject *items = PyObject_CallMethodNoArgs((PyObject *)self, attr); + PyObject *items = PyObject_CallMethodNoArgs( + (PyObject *)self, _Py_ID(items)); if (items == NULL) goto Done; pieces = PySequence_List(items); @@ -1819,8 +1817,7 @@ odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - PyObject *attr = _Py_ID(iter); - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), list); } static PyMethodDef odictiter_methods[] = { @@ -2217,8 +2214,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg) return res; } PyObject *func; - PyObject *attr = _Py_ID(keys); - if (_PyObject_LookupAttr(arg, attr, &func) < 0) { + if (_PyObject_LookupAttr(arg, _Py_ID(keys), &func) < 0) { return -1; } if (func != NULL) { @@ -2250,8 +2246,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg) } return 0; } - attr = _Py_ID(items); - if (_PyObject_LookupAttr(arg, attr, &func) < 0) { + if (_PyObject_LookupAttr(arg, _Py_ID(items), &func) < 0) { return -1; } if (func != NULL) { diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 7f9e9db4c6483b1..56f4deb68e19324 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -811,8 +811,8 @@ rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) if (range == NULL) goto err; /* return the result */ - PyObject *attr = _Py_ID(iter); - return Py_BuildValue("N(N)l", _PyEval_GetBuiltin(attr), range, r->index); + return Py_BuildValue( + "N(N)l", _PyEval_GetBuiltin(_Py_ID(iter)), range, r->index); err: Py_XDECREF(start); Py_XDECREF(stop); @@ -965,8 +965,8 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored)) } /* return the result */ - PyObject *attr = _Py_ID(iter); - return Py_BuildValue("N(N)O", _PyEval_GetBuiltin(attr), range, r->index); + return Py_BuildValue( + "N(N)O", _PyEval_GetBuiltin(_Py_ID(iter)), range, r->index); } static PyObject * diff --git a/Objects/setobject.c b/Objects/setobject.c index 88d870619c88164..78e310a4768b82c 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -780,8 +780,7 @@ setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - PyObject *attr = _Py_ID(iter); - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), list); } PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); @@ -1913,8 +1912,7 @@ set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored)) args = PyTuple_Pack(1, keys); if (args == NULL) goto done; - PyObject *attr = _Py_ID(__dict__); - if (_PyObject_LookupAttr((PyObject *)so, attr, &dict) < 0) { + if (_PyObject_LookupAttr((PyObject *)so, _Py_ID(__dict__), &dict) < 0) { goto done; } if (dict == NULL) { diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 5c341f8742a285d..8c229c4d35db226 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -1193,12 +1193,11 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * tupleiter_reduce(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(iter); if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), it->it_seq, it->it_index); else - return Py_BuildValue("N(())", _PyEval_GetBuiltin(attr)); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); } static PyObject * diff --git a/Objects/typeobject.c b/Objects/typeobject.c index f6644077d455d93..124777862ad6560 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -151,8 +151,7 @@ _PyType_CheckConsistency(PyTypeObject *type) if (type->tp_flags & Py_TPFLAGS_DISALLOW_INSTANTIATION) { CHECK(type->tp_new == NULL); - PyObject *attr = _Py_ID(__new__); - CHECK(PyDict_Contains(type->tp_dict, attr) == 0); + CHECK(PyDict_Contains(type->tp_dict, _Py_ID(__new__)) == 0); } return 1; @@ -350,12 +349,12 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) { PyObject *type_mro_meth = NULL; if (custom) { - PyObject *attr = _Py_ID(mro); - mro_meth = lookup_maybe_method((PyObject *)type, attr, &unbound); + mro_meth = lookup_maybe_method( + (PyObject *)type, _Py_ID(mro), &unbound); if (mro_meth == NULL) goto clear; type_mro_meth = lookup_maybe_method( - (PyObject *)&PyType_Type, attr, &unbound); + (PyObject *)&PyType_Type, _Py_ID(mro), &unbound); if (type_mro_meth == NULL) goto clear; if (mro_meth != type_mro_meth) @@ -549,8 +548,7 @@ type_module(PyTypeObject *type, void *context) PyObject *mod; if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { - PyObject *attr = _Py_ID(__module__); - mod = PyDict_GetItemWithError(type->tp_dict, attr); + mod = PyDict_GetItemWithError(type->tp_dict, _Py_ID(__module__)); if (mod == NULL) { if (!PyErr_Occurred()) { PyErr_Format(PyExc_AttributeError, "__module__"); @@ -583,8 +581,7 @@ type_set_module(PyTypeObject *type, PyObject *value, void *context) PyType_Modified(type); - PyObject *attr = _Py_ID(__module__); - return PyDict_SetItem(type->tp_dict, attr, value); + return PyDict_SetItem(type->tp_dict, _Py_ID(__module__), value); } static PyObject * @@ -593,12 +590,12 @@ type_abstractmethods(PyTypeObject *type, void *context) PyObject *mod = NULL; /* type itself has an __abstractmethods__ descriptor (this). Don't return that. */ - PyObject *attr = _Py_ID(__abstractmethods__); if (type != &PyType_Type) - mod = PyDict_GetItemWithError(type->tp_dict, attr); + mod = PyDict_GetItemWithError(type->tp_dict, + _Py_ID(__abstractmethods__)); if (!mod) { if (!PyErr_Occurred()) { - PyErr_SetObject(PyExc_AttributeError, attr); + PyErr_SetObject(PyExc_AttributeError, _Py_ID(__abstractmethods__)); } return NULL; } @@ -614,18 +611,17 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context) special to update subclasses. */ int abstract, res; - PyObject *attr = _Py_ID(__abstractmethods__); if (value != NULL) { abstract = PyObject_IsTrue(value); if (abstract < 0) return -1; - res = PyDict_SetItem(type->tp_dict, attr, value); + res = PyDict_SetItem(type->tp_dict, _Py_ID(__abstractmethods__), value); } else { abstract = 0; - res = PyDict_DelItem(type->tp_dict, attr); + res = PyDict_DelItem(type->tp_dict, _Py_ID(__abstractmethods__)); if (res && PyErr_ExceptionMatches(PyExc_KeyError)) { - PyErr_SetObject(PyExc_AttributeError, attr); + PyErr_SetObject(PyExc_AttributeError, _Py_ID(__abstractmethods__)); return -1; } } @@ -879,8 +875,7 @@ type_get_doc(PyTypeObject *type, void *context) if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) { return _PyType_GetDocFromInternalDoc(type->tp_name, type->tp_doc); } - PyObject *attr = _Py_ID(__doc__); - result = PyDict_GetItemWithError(type->tp_dict, attr); + result = PyDict_GetItemWithError(type->tp_dict, _Py_ID(__doc__)); if (result == NULL) { if (!PyErr_Occurred()) { result = Py_None; @@ -909,8 +904,7 @@ type_set_doc(PyTypeObject *type, PyObject *value, void *context) if (!check_set_special_type_attr(type, value, "__doc__")) return -1; PyType_Modified(type); - PyObject *attr = _Py_ID(__doc__); - return PyDict_SetItem(type->tp_dict, attr, value); + return PyDict_SetItem(type->tp_dict, _Py_ID(__doc__), value); } static PyObject * @@ -923,9 +917,9 @@ type_get_annotations(PyTypeObject *type, void *context) PyObject *annotations; /* there's no _PyDict_GetItemId without WithError, so let's LBYL. */ - PyObject *attr = _Py_ID(__annotations__); - if (PyDict_Contains(type->tp_dict, attr)) { - annotations = PyDict_GetItemWithError(type->tp_dict, attr); + if (PyDict_Contains(type->tp_dict, _Py_ID(__annotations__))) { + annotations = PyDict_GetItemWithError( + type->tp_dict, _Py_ID(__annotations__)); /* ** PyDict_GetItemWithError could still fail, ** for instance with a well-timed Ctrl-C or a MemoryError. @@ -933,8 +927,8 @@ type_get_annotations(PyTypeObject *type, void *context) */ if (annotations) { if (Py_TYPE(annotations)->tp_descr_get) { - annotations = Py_TYPE(annotations)->tp_descr_get(annotations, NULL, - (PyObject *)type); + annotations = Py_TYPE(annotations)->tp_descr_get( + annotations, NULL, (PyObject *)type); } else { Py_INCREF(annotations); } @@ -942,7 +936,8 @@ type_get_annotations(PyTypeObject *type, void *context) } else { annotations = PyDict_New(); if (annotations) { - int result = PyDict_SetItem(type->tp_dict, attr, annotations); + int result = PyDict_SetItem( + type->tp_dict, _Py_ID(__annotations__), annotations); if (result) { Py_CLEAR(annotations); } else { @@ -964,17 +959,16 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context) } int result; - PyObject *attr = _Py_ID(__annotations__); if (value != NULL) { /* set */ - result = PyDict_SetItem(type->tp_dict, attr, value); + result = PyDict_SetItem(type->tp_dict, _Py_ID(__annotations__), value); } else { /* delete */ - if (!PyDict_Contains(type->tp_dict, attr)) { + if (!PyDict_Contains(type->tp_dict, _Py_ID(__annotations__))) { PyErr_Format(PyExc_AttributeError, "__annotations__"); return -1; } - result = PyDict_DelItem(type->tp_dict, attr); + result = PyDict_DelItem(type->tp_dict, _Py_ID(__annotations__)); } if (result == 0) { @@ -1055,8 +1049,7 @@ type_repr(PyTypeObject *type) return NULL; } - PyObject *attr = _Py_ID(builtins); - if (mod != NULL && !_PyUnicode_Equal(mod, attr)) + if (mod != NULL && !_PyUnicode_Equal(mod, _Py_ID(builtins))) rtn = PyUnicode_FromFormat("", mod, name); else rtn = PyUnicode_FromFormat("", type->tp_name); @@ -1760,8 +1753,7 @@ static PyObject * class_name(PyObject *cls) { PyObject *name; - PyObject *attr = _Py_ID(__name__); - if (_PyObject_LookupAttr(cls, attr, &name) == 0) { + if (_PyObject_LookupAttr(cls, _Py_ID(__name__), &name) == 0) { name = PyObject_Repr(cls); } return name; @@ -2084,8 +2076,8 @@ mro_invoke(PyTypeObject *type) if (custom) { int unbound; - PyObject *attr = _Py_ID(mro); - PyObject *mro_meth = lookup_method((PyObject *)type, attr, &unbound); + PyObject *mro_meth = lookup_method( + (PyObject *)type, _Py_ID(mro), &unbound); if (mro_meth == NULL) return NULL; mro_result = call_unbound_noarg(unbound, mro_meth, (PyObject *)type); @@ -2300,8 +2292,7 @@ get_dict_descriptor(PyTypeObject *type) { PyObject *descr; - PyObject *attr = _Py_ID(__dict__); - descr = _PyType_Lookup(type, attr); + descr = _PyType_Lookup(type, _Py_ID(__dict__)); if (descr == NULL || !PyDescr_IsData(descr)) return NULL; @@ -2544,15 +2535,13 @@ type_new_visit_slots(type_new_ctx *ctx) { PyObject *slots = ctx->slots; Py_ssize_t nslot = ctx->nslot; - PyObject *__dict__ = _Py_ID(__dict__); - PyObject *__weakref__ = _Py_ID(__weakref__); for (Py_ssize_t i = 0; i < nslot; i++) { PyObject *name = PyTuple_GET_ITEM(slots, i); if (!valid_identifier(name)) { return -1; } assert(PyUnicode_Check(name)); - if (_PyUnicode_Equal(name, __dict__)) { + if (_PyUnicode_Equal(name, _Py_ID(__dict__))) { if (!ctx->may_add_dict || ctx->add_dict != 0) { PyErr_SetString(PyExc_TypeError, "__dict__ slot disallowed: " @@ -2561,7 +2550,7 @@ type_new_visit_slots(type_new_ctx *ctx) } ctx->add_dict++; } - if (_PyUnicode_Equal(name, __weakref__)) { + if (_PyUnicode_Equal(name, _Py_ID(__weakref__))) { if (!ctx->may_add_weak || ctx->add_weak != 0) { PyErr_SetString(PyExc_TypeError, "__weakref__ slot disallowed: " @@ -2593,14 +2582,10 @@ type_new_copy_slots(type_new_ctx *ctx, PyObject *dict) } Py_ssize_t j = 0; - PyObject *__dict__ = _Py_ID(__dict__); - PyObject *__weakref__ = _Py_ID(__weakref__); - PyObject *__qualname__ = _Py_ID(__qualname__); - PyObject *__classcell__ = _Py_ID(__classcell__); for (Py_ssize_t i = 0; i < nslot; i++) { PyObject *slot = PyTuple_GET_ITEM(slots, i); - if ((ctx->add_dict && _PyUnicode_Equal(slot, __dict__)) || - (ctx->add_weak && _PyUnicode_Equal(slot, __weakref__))) + if ((ctx->add_dict && _PyUnicode_Equal(slot, _Py_ID(__dict__))) || + (ctx->add_weak && _PyUnicode_Equal(slot, _Py_ID(__weakref__)))) { continue; } @@ -2619,8 +2604,8 @@ type_new_copy_slots(type_new_ctx *ctx, PyObject *dict) /* CPython inserts __qualname__ and __classcell__ (when needed) into the namespace when creating a class. They will be deleted below so won't act as class variables. */ - if (!_PyUnicode_Equal(slot, __qualname__) && - !_PyUnicode_Equal(slot, __classcell__)) + if (!_PyUnicode_Equal(slot, _Py_ID(__qualname__)) && + !_PyUnicode_Equal(slot, _Py_ID(__classcell__))) { PyErr_Format(PyExc_ValueError, "%R in __slots__ conflicts with class variable", @@ -2815,8 +2800,7 @@ type_new_set_name(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_set_module(PyTypeObject *type) { - PyObject *module_str = _Py_ID(__module__); - int r = PyDict_Contains(type->tp_dict, module_str); + int r = PyDict_Contains(type->tp_dict, _Py_ID(__module__)); if (r < 0) { return -1; } @@ -2829,8 +2813,7 @@ type_new_set_module(PyTypeObject *type) return 0; } - PyObject *__name__ = _Py_ID(__name__); - PyObject *module = PyDict_GetItemWithError(globals, __name__); + PyObject *module = PyDict_GetItemWithError(globals, _Py_ID(__name__)); if (module == NULL) { if (PyErr_Occurred()) { return -1; @@ -2838,7 +2821,7 @@ type_new_set_module(PyTypeObject *type) return 0; } - if (PyDict_SetItem(type->tp_dict, module_str, module) < 0) { + if (PyDict_SetItem(type->tp_dict, _Py_ID(__module__), module) < 0) { return -1; } return 0; @@ -2851,8 +2834,8 @@ static int type_new_set_ht_name(PyTypeObject *type) { PyHeapTypeObject *et = (PyHeapTypeObject *)type; - PyObject *attr = _Py_ID(__qualname__); - PyObject *qualname = PyDict_GetItemWithError(type->tp_dict, attr); + PyObject *qualname = PyDict_GetItemWithError( + type->tp_dict, _Py_ID(__qualname__)); if (qualname != NULL) { if (!PyUnicode_Check(qualname)) { PyErr_Format(PyExc_TypeError, @@ -2861,7 +2844,7 @@ type_new_set_ht_name(PyTypeObject *type) return -1; } et->ht_qualname = Py_NewRef(qualname); - if (PyDict_DelItem(type->tp_dict, attr) < 0) { + if (PyDict_DelItem(type->tp_dict, _Py_ID(__qualname__)) < 0) { return -1; } } @@ -2881,8 +2864,7 @@ type_new_set_ht_name(PyTypeObject *type) static int type_new_set_doc(PyTypeObject *type) { - PyObject *attr = _Py_ID(__doc__); - PyObject *doc = PyDict_GetItemWithError(type->tp_dict, attr); + PyObject *doc = PyDict_GetItemWithError(type->tp_dict, _Py_ID(__doc__)); if (doc == NULL) { if (PyErr_Occurred()) { return -1; @@ -3051,8 +3033,8 @@ type_new_set_slots(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_set_classcell(PyTypeObject *type) { - PyObject *attr = _Py_ID(__classcell__); - PyObject *cell = PyDict_GetItemWithError(type->tp_dict, attr); + PyObject *cell = PyDict_GetItemWithError( + type->tp_dict, _Py_ID(__classcell__)); if (cell == NULL) { if (PyErr_Occurred()) { return -1; @@ -3069,7 +3051,7 @@ type_new_set_classcell(PyTypeObject *type) } (void)PyCell_Set(cell, (PyObject *) type); - if (PyDict_DelItem(type->tp_dict, attr) < 0) { + if (PyDict_DelItem(type->tp_dict, _Py_ID(__classcell__)) < 0) { return -1; } return 0; @@ -3097,19 +3079,16 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type) /* Special-case __new__: if it's a plain function, make it a static function */ - PyObject *attr = _Py_ID(__new__); - if (type_new_staticmethod(type, attr) < 0) { + if (type_new_staticmethod(type, _Py_ID(__new__)) < 0) { return -1; } /* Special-case __init_subclass__ and __class_getitem__: if they are plain functions, make them classmethods */ - attr = _Py_ID(__init_subclass__); - if (type_new_classmethod(type, attr) < 0) { + if (type_new_classmethod(type, _Py_ID(__init_subclass__)) < 0) { return -1; } - attr = _Py_ID(__class_getitem__); - if (type_new_classmethod(type, attr) < 0) { + if (type_new_classmethod(type, _Py_ID(__class_getitem__)) < 0) { return -1; } @@ -3129,8 +3108,7 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_get_slots(type_new_ctx *ctx, PyObject *dict) { - PyObject *attr = _Py_ID(__slots__); - PyObject *slots = PyDict_GetItemWithError(dict, attr); + PyObject *slots = PyDict_GetItemWithError(dict, _Py_ID(__slots__)); if (slots == NULL) { if (PyErr_Occurred()) { return -1; @@ -3259,8 +3237,8 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type) continue; } PyObject *mro_entries; - PyObject *attr = _Py_ID(__mro_entries__); - if (_PyObject_LookupAttr(base, attr, &mro_entries) < 0) { + if (_PyObject_LookupAttr(base, _Py_ID(__mro_entries__), + &mro_entries) < 0) { return -1; } if (mro_entries != NULL) { @@ -3395,7 +3373,7 @@ PyObject * PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) { PyHeapTypeObject *res; - PyObject *modname, *attr; + PyObject *modname; PyTypeObject *type, *base; int r; @@ -3609,8 +3587,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) PyObject *__doc__ = PyUnicode_FromString(_PyType_DocWithoutSignature(type->tp_name, type->tp_doc)); if (!__doc__) goto fail; - attr = _Py_ID(__doc__); - r = PyDict_SetItem(type->tp_dict, attr, __doc__); + r = PyDict_SetItem(type->tp_dict, _Py_ID(__doc__), __doc__); Py_DECREF(__doc__); if (r < 0) goto fail; @@ -3628,8 +3605,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) } /* Set type.__module__ */ - attr = _Py_ID(__module__); - r = PyDict_Contains(type->tp_dict, attr); + r = PyDict_Contains(type->tp_dict, _Py_ID(__module__)); if (r < 0) { goto fail; } @@ -3641,7 +3617,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) if (modname == NULL) { goto fail; } - r = PyDict_SetItem(type->tp_dict, attr, modname); + r = PyDict_SetItem(type->tp_dict, _Py_ID(__module__), modname); Py_DECREF(modname); if (r != 0) goto fail; @@ -4226,8 +4202,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass) assert(aclass); /* Merge in the type's dict (if any). */ - PyObject *attr = _Py_ID(__dict__); - if (_PyObject_LookupAttr(aclass, attr, &classdict) < 0) { + if (_PyObject_LookupAttr(aclass, _Py_ID(__dict__), &classdict) < 0) { return -1; } if (classdict != NULL) { @@ -4238,8 +4213,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass) } /* Recursively merge in the base types' (if any) dicts. */ - attr = _Py_ID(__bases__); - if (_PyObject_LookupAttr(aclass, attr, &bases) < 0) { + if (_PyObject_LookupAttr(aclass, _Py_ID(__bases__), &bases) < 0) { return -1; } if (bases != NULL) { @@ -4632,8 +4606,7 @@ object_repr(PyObject *self) Py_XDECREF(mod); return NULL; } - PyObject *attr = _Py_ID(builtins); - if (mod != NULL && !_PyUnicode_Equal(mod, attr)) + if (mod != NULL && !_PyUnicode_Equal(mod, _Py_ID(builtins))) rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self); else rtn = PyUnicode_FromFormat("<%s object at %p>", @@ -4926,22 +4899,19 @@ static PyGetSetDef object_getsets[] = { static PyObject * import_copyreg(void) { - PyObject *copyreg_module; - PyObject *copyreg_str = _Py_ID(copyreg); - /* Try to fetch cached copy of copyreg from sys.modules first in an attempt to avoid the import overhead. Previously this was implemented by storing a reference to the cached module in a static variable, but this broke when multiple embedded interpreters were in use (see issue #17408 and #19088). */ - copyreg_module = PyImport_GetModule(copyreg_str); + PyObject *copyreg_module = PyImport_GetModule(_Py_ID(copyreg)); if (copyreg_module != NULL) { return copyreg_module; } if (PyErr_Occurred()) { return NULL; } - return PyImport_Import(copyreg_str); + return PyImport_Import(_Py_ID(copyreg)); } static PyObject * @@ -4953,8 +4923,7 @@ _PyType_GetSlotNames(PyTypeObject *cls) assert(PyType_Check(cls)); /* Get the slot names from the cache in the class if possible. */ - PyObject *attr = _Py_ID(__slotnames__); - slotnames = PyDict_GetItemWithError(cls->tp_dict, attr); + slotnames = PyDict_GetItemWithError(cls->tp_dict, _Py_ID(__slotnames__)); if (slotnames != NULL) { if (slotnames != Py_None && !PyList_Check(slotnames)) { PyErr_Format(PyExc_TypeError, @@ -4980,8 +4949,8 @@ _PyType_GetSlotNames(PyTypeObject *cls) /* Use _slotnames function from the copyreg module to find the slots by this class and its bases. This function will cache the result in __slotnames__. */ - attr = _Py_ID(_slotnames); - slotnames = PyObject_CallMethodOneArg(copyreg, attr, (PyObject *)cls); + slotnames = PyObject_CallMethodOneArg( + copyreg, _Py_ID(_slotnames), (PyObject *)cls); Py_DECREF(copyreg); if (slotnames == NULL) return NULL; @@ -5002,8 +4971,7 @@ _PyObject_GetState(PyObject *obj, int required) PyObject *state; PyObject *getstate; - PyObject *attr = _Py_ID(__getstate__); - if (_PyObject_LookupAttr(obj, attr, &getstate) < 0) { + if (_PyObject_LookupAttr(obj, _Py_ID(__getstate__), &getstate) < 0) { return NULL; } if (getstate == NULL) { @@ -5147,8 +5115,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* We first attempt to fetch the arguments for __new__ by calling __getnewargs_ex__ on the object. */ - PyObject *attr = _Py_ID(__getnewargs_ex__); - getnewargs_ex = _PyObject_LookupSpecial(obj, attr); + getnewargs_ex = _PyObject_LookupSpecial(obj, _Py_ID(__getnewargs_ex__)); if (getnewargs_ex != NULL) { PyObject *newargs = _PyObject_CallNoArgs(getnewargs_ex); Py_DECREF(getnewargs_ex); @@ -5201,8 +5168,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* The object does not have __getnewargs_ex__ so we fallback on using __getnewargs__ instead. */ - attr = _Py_ID(__getnewargs__); - getnewargs = _PyObject_LookupSpecial(obj, attr); + getnewargs = _PyObject_LookupSpecial(obj, _Py_ID(__getnewargs__)); if (getnewargs != NULL) { *args = _PyObject_CallNoArgs(getnewargs); Py_DECREF(getnewargs); @@ -5255,8 +5221,7 @@ _PyObject_GetItemsIter(PyObject *obj, PyObject **listitems, Py_INCREF(*dictitems); } else { - PyObject *attr = _Py_ID(items); - PyObject *items = PyObject_CallMethodNoArgs(obj, attr); + PyObject *items = PyObject_CallMethodNoArgs(obj, _Py_ID(items)); if (items == NULL) { Py_CLEAR(*listitems); return -1; @@ -5304,8 +5269,7 @@ reduce_newobj(PyObject *obj) Py_ssize_t i, n; Py_XDECREF(kwargs); - PyObject *attr = _Py_ID(__newobj__); - newobj = PyObject_GetAttr(copyreg, attr); + newobj = PyObject_GetAttr(copyreg, _Py_ID(__newobj__)); Py_DECREF(copyreg); if (newobj == NULL) { Py_XDECREF(args); @@ -5329,8 +5293,7 @@ reduce_newobj(PyObject *obj) Py_XDECREF(args); } else if (args != NULL) { - PyObject *attr = _Py_ID(__newobj_ex__); - newobj = PyObject_GetAttr(copyreg, attr); + newobj = PyObject_GetAttr(copyreg, _Py_ID(__newobj_ex__)); Py_DECREF(copyreg); if (newobj == NULL) { Py_DECREF(args); @@ -5437,15 +5400,15 @@ object___reduce_ex___impl(PyObject *self, int protocol) static PyObject *objreduce; PyObject *reduce, *res; - PyObject *attr = _Py_ID(__reduce__); if (objreduce == NULL) { - objreduce = PyDict_GetItemWithError(PyBaseObject_Type.tp_dict, attr); + objreduce = PyDict_GetItemWithError( + PyBaseObject_Type.tp_dict, _Py_ID(__reduce__)); if (objreduce == NULL && PyErr_Occurred()) { return NULL; } } - if (_PyObject_LookupAttr(self, attr, &reduce) < 0) { + if (_PyObject_LookupAttr(self, _Py_ID(__reduce__), &reduce) < 0) { return NULL; } if (reduce != NULL) { @@ -5453,7 +5416,7 @@ object___reduce_ex___impl(PyObject *self, int protocol) int override; cls = (PyObject *) Py_TYPE(self); - clsreduce = PyObject_GetAttr(cls, attr); + clsreduce = PyObject_GetAttr(cls, _Py_ID(__reduce__)); if (clsreduce == NULL) { Py_DECREF(reduce); return NULL; @@ -5561,8 +5524,7 @@ object___dir___impl(PyObject *self) PyObject *itsclass = NULL; /* Get __dict__ (which may or may not be a real dict...) */ - PyObject *attr = _Py_ID(__dict__); - if (_PyObject_LookupAttr(self, attr, &dict) < 0) { + if (_PyObject_LookupAttr(self, _Py_ID(__dict__), &dict) < 0) { return NULL; } if (dict == NULL) { @@ -5583,8 +5545,7 @@ object___dir___impl(PyObject *self) goto error; /* Merge in attrs reachable from its class. */ - attr = _Py_ID(__class__); - if (_PyObject_LookupAttr(self, attr, &itsclass) < 0) { + if (_PyObject_LookupAttr(self, _Py_ID(__class__), &itsclass) < 0) { goto error; } /* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no @@ -5852,11 +5813,9 @@ overrides_hash(PyTypeObject *type) PyObject *dict = type->tp_dict; assert(dict != NULL); - PyObject *attr = _Py_ID(__eq__); - int r = PyDict_Contains(dict, attr); + int r = PyDict_Contains(dict, _Py_ID(__eq__)); if (r == 0) { - attr = _Py_ID(__hash__); - r = PyDict_Contains(dict, attr); + r = PyDict_Contains(dict, _Py_ID(__hash__)); } return r; } @@ -6171,8 +6130,7 @@ type_ready_set_dict(PyTypeObject *type) static int type_dict_set_doc(PyTypeObject *type) { - PyObject *attr = _Py_ID(__doc__); - int r = PyDict_Contains(type->tp_dict, attr); + int r = PyDict_Contains(type->tp_dict, _Py_ID(__doc__)); if (r < 0) { return -1; } @@ -6188,14 +6146,14 @@ type_dict_set_doc(PyTypeObject *type) return -1; } - if (PyDict_SetItem(type->tp_dict, attr, doc) < 0) { + if (PyDict_SetItem(type->tp_dict, _Py_ID(__doc__), doc) < 0) { Py_DECREF(doc); return -1; } Py_DECREF(doc); } else { - if (PyDict_SetItem(type->tp_dict, attr, Py_None) < 0) { + if (PyDict_SetItem(type->tp_dict, _Py_ID(__doc__), Py_None) < 0) { return -1; } } @@ -6343,8 +6301,7 @@ type_ready_set_hash(PyTypeObject *type) return 0; } - PyObject *attr = _Py_ID(__hash__); - int r = PyDict_Contains(type->tp_dict, attr); + int r = PyDict_Contains(type->tp_dict, _Py_ID(__hash__)); if (r < 0) { return -1; } @@ -6352,7 +6309,7 @@ type_ready_set_hash(PyTypeObject *type) return 0; } - if (PyDict_SetItem(type->tp_dict, attr, Py_None) < 0) { + if (PyDict_SetItem(type->tp_dict, _Py_ID(__hash__), Py_None) < 0) { return -1; } type->tp_hash = PyObject_HashNotImplemented; @@ -7169,8 +7126,7 @@ static struct PyMethodDef tp_new_methoddef[] = { static int add_tp_new_wrapper(PyTypeObject *type) { - PyObject *attr = _Py_ID(__new__); - int r = PyDict_Contains(type->tp_dict, attr); + int r = PyDict_Contains(type->tp_dict, _Py_ID(__new__)); if (r > 0) { return 0; } @@ -7182,7 +7138,7 @@ add_tp_new_wrapper(PyTypeObject *type) if (func == NULL) { return -1; } - r = PyDict_SetItem(type->tp_dict, attr, func); + r = PyDict_SetItem(type->tp_dict, _Py_ID(__new__), func); Py_DECREF(func); return r; } @@ -7195,8 +7151,7 @@ static PyObject * \ FUNCNAME(PyObject *self) \ { \ PyObject* stack[1] = {self}; \ - PyObject *attr = _Py_ID(DUNDER); \ - return vectorcall_method(attr, stack, 1); \ + return vectorcall_method(_Py_ID(DUNDER), stack, 1); \ } #define SLOT1(FUNCNAME, DUNDER, ARG1TYPE) \ @@ -7204,8 +7159,7 @@ static PyObject * \ FUNCNAME(PyObject *self, ARG1TYPE arg1) \ { \ PyObject* stack[2] = {self, arg1}; \ - PyObject *attr = _Py_ID(DUNDER); \ - return vectorcall_method(attr, stack, 2); \ + return vectorcall_method(_Py_ID(DUNDER), stack, 2); \ } /* Boolean helper for SLOT1BINFULL(). @@ -7247,8 +7201,6 @@ FUNCNAME(PyObject *self, PyObject *other) \ { \ PyObject* stack[2]; \ PyThreadState *tstate = _PyThreadState_GET(); \ - PyObject *attr = _Py_ID(DUNDER); \ - PyObject *rattr = _Py_ID(RDUNDER); \ int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \ Py_TYPE(other)->tp_as_number != NULL && \ Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \ @@ -7256,14 +7208,14 @@ FUNCNAME(PyObject *self, PyObject *other) \ Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \ PyObject *r; \ if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \ - int ok = method_is_overloaded(self, other, rattr); \ + int ok = method_is_overloaded(self, other, _Py_ID(RDUNDER)); \ if (ok < 0) { \ return NULL; \ } \ if (ok) { \ stack[0] = other; \ stack[1] = self; \ - r = vectorcall_maybe(tstate, rattr, stack, 2); \ + r = vectorcall_maybe(tstate, _Py_ID(RDUNDER), stack, 2); \ if (r != Py_NotImplemented) \ return r; \ Py_DECREF(r); \ @@ -7272,7 +7224,7 @@ FUNCNAME(PyObject *self, PyObject *other) \ } \ stack[0] = self; \ stack[1] = other; \ - r = vectorcall_maybe(tstate, attr, stack, 2); \ + r = vectorcall_maybe(tstate, _Py_ID(DUNDER), stack, 2); \ if (r != Py_NotImplemented || \ Py_IS_TYPE(other, Py_TYPE(self))) \ return r; \ @@ -7281,7 +7233,7 @@ FUNCNAME(PyObject *self, PyObject *other) \ if (do_other) { \ stack[0] = other; \ stack[1] = self; \ - return vectorcall_maybe(tstate, rattr, stack, 2); \ + return vectorcall_maybe(tstate, _Py_ID(RDUNDER), stack, 2); \ } \ Py_RETURN_NOTIMPLEMENTED; \ } @@ -7293,8 +7245,7 @@ static Py_ssize_t slot_sq_length(PyObject *self) { PyObject* stack[1] = {self}; - PyObject *attr = _Py_ID(__len__); - PyObject *res = vectorcall_method(attr, stack, 1); + PyObject *res = vectorcall_method(_Py_ID(__len__), stack, 1); Py_ssize_t len; if (res == NULL) @@ -7326,8 +7277,7 @@ slot_sq_item(PyObject *self, Py_ssize_t i) return NULL; } PyObject *stack[2] = {self, ival}; - PyObject *attr = _Py_ID(__getitem__); - PyObject *retval = vectorcall_method(attr, stack, 2); + PyObject *retval = vectorcall_method(_Py_ID(__getitem__), stack, 2); Py_DECREF(ival); return retval; } @@ -7347,13 +7297,11 @@ slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value) stack[0] = self; stack[1] = index_obj; if (value == NULL) { - PyObject *attr = _Py_ID(__delitem__); - res = vectorcall_method(attr, stack, 2); + res = vectorcall_method(_Py_ID(__delitem__), stack, 2); } else { stack[2] = value; - PyObject *attr = _Py_ID(__setitem__); - res = vectorcall_method(attr, stack, 3); + res = vectorcall_method(_Py_ID(__setitem__), stack, 3); } Py_DECREF(index_obj); @@ -7371,8 +7319,7 @@ slot_sq_contains(PyObject *self, PyObject *value) PyObject *func, *res; int result = -1, unbound; - PyObject *attr = _Py_ID(__contains__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__contains__), &unbound); if (func == Py_None) { Py_DECREF(func); PyErr_Format(PyExc_TypeError, @@ -7410,13 +7357,11 @@ slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value) stack[0] = self; stack[1] = key; if (value == NULL) { - PyObject *attr = _Py_ID(__delitem__); - res = vectorcall_method(attr, stack, 2); + res = vectorcall_method(_Py_ID(__delitem__), stack, 2); } else { stack[2] = value; - PyObject *attr = _Py_ID(__setitem__); - res = vectorcall_method(attr, stack, 3); + res = vectorcall_method(_Py_ID(__setitem__), stack, 3); } if (res == NULL) @@ -7447,8 +7392,7 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus) if (Py_TYPE(self)->tp_as_number != NULL && Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) { PyObject* stack[3] = {self, other, modulus}; - PyObject *attr = _Py_ID(__pow__); - return vectorcall_method(attr, stack, 3); + return vectorcall_method(_Py_ID(__pow__), stack, 3); } Py_RETURN_NOTIMPLEMENTED; } @@ -7464,15 +7408,13 @@ slot_nb_bool(PyObject *self) int result, unbound; int using_len = 0; - PyObject *attr = _Py_ID(__bool__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__bool__), &unbound); if (func == NULL) { if (PyErr_Occurred()) { return -1; } - attr = _Py_ID(__len__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__len__), &unbound); if (func == NULL) { if (PyErr_Occurred()) { return -1; @@ -7516,8 +7458,7 @@ static PyObject * slot_nb_index(PyObject *self) { PyObject *stack[1] = {self}; - PyObject *attr = _Py_ID(__index__); - return vectorcall_method(attr, stack, 1); + return vectorcall_method(_Py_ID(__index__), stack, 1); } @@ -7540,8 +7481,7 @@ static PyObject * slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2) { PyObject *stack[2] = {self, arg1}; - PyObject *attr = _Py_ID(__ipow__); - return vectorcall_method(attr, stack, 2); + return vectorcall_method(_Py_ID(__ipow__), stack, 2); } SLOT1(slot_nb_inplace_lshift, __ilshift__, PyObject *) SLOT1(slot_nb_inplace_rshift, __irshift__, PyObject *) @@ -7560,8 +7500,7 @@ slot_tp_repr(PyObject *self) PyObject *func, *res; int unbound; - PyObject *attr = _Py_ID(__repr__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__repr__), &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -7581,8 +7520,7 @@ slot_tp_hash(PyObject *self) Py_ssize_t h; int unbound; - PyObject *attr = _Py_ID(__hash__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__hash__), &unbound); if (func == Py_None) { Py_DECREF(func); @@ -7629,8 +7567,7 @@ slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *attr = _Py_ID(__call__); - PyObject *meth = lookup_method(self, attr, &unbound); + PyObject *meth = lookup_method(self, _Py_ID(__call__), &unbound); if (meth == NULL) { return NULL; } @@ -7662,8 +7599,7 @@ static PyObject * slot_tp_getattro(PyObject *self, PyObject *name) { PyObject *stack[2] = {self, name}; - PyObject *attr = _Py_ID(__getattribute__); - return vectorcall_method(attr, stack, 2); + return vectorcall_method(_Py_ID(__getattribute__), stack, 2); } static PyObject * @@ -7695,8 +7631,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) __getattr__, even when the attribute is present. So we use _PyType_Lookup and create the method only when needed, with call_attribute. */ - PyObject *attr = _Py_ID(__getattr__); - getattr = _PyType_Lookup(tp, attr); + getattr = _PyType_Lookup(tp, _Py_ID(__getattr__)); if (getattr == NULL) { /* No __getattr__ hook: use a simpler dispatcher */ tp->tp_getattro = slot_tp_getattro; @@ -7708,8 +7643,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) __getattr__, even when self has the default __getattribute__ method. So we use _PyType_Lookup and create the method only when needed, with call_attribute. */ - attr = _Py_ID(__getattribute__); - getattribute = _PyType_Lookup(tp, attr); + getattribute = _PyType_Lookup(tp, _Py_ID(__getattribute__)); if (getattribute == NULL || (Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) && ((PyWrapperDescrObject *)getattribute)->d_wrapped == @@ -7737,13 +7671,11 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) stack[0] = self; stack[1] = name; if (value == NULL) { - PyObject *attr = _Py_ID(__delattr__); - res = vectorcall_method(attr, stack, 2); + res = vectorcall_method(_Py_ID(__delattr__), stack, 2); } else { stack[2] = value; - PyObject *attr = _Py_ID(__setattr__); - res = vectorcall_method(attr, stack, 3); + res = vectorcall_method(_Py_ID(__setattr__), stack, 3); } if (res == NULL) return -1; @@ -7784,8 +7716,7 @@ slot_tp_iter(PyObject *self) int unbound; PyObject *func, *res; - PyObject *attr = _Py_ID(__iter__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__iter__), &unbound); if (func == Py_None) { Py_DECREF(func); PyErr_Format(PyExc_TypeError, @@ -7801,8 +7732,7 @@ slot_tp_iter(PyObject *self) } PyErr_Clear(); - attr = _Py_ID(__getitem__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__getitem__), &unbound); if (func == NULL) { PyErr_Format(PyExc_TypeError, "'%.200s' object is not iterable", @@ -7817,8 +7747,7 @@ static PyObject * slot_tp_iternext(PyObject *self) { PyObject *stack[1] = {self}; - PyObject *attr = _Py_ID(__next__); - return vectorcall_method(attr, stack, 1); + return vectorcall_method(_Py_ID(__next__), stack, 1); } static PyObject * @@ -7827,8 +7756,7 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type) PyTypeObject *tp = Py_TYPE(self); PyObject *get; - PyObject *attr = _Py_ID(__get__); - get = _PyType_Lookup(tp, attr); + get = _PyType_Lookup(tp, _Py_ID(__get__)); if (get == NULL) { /* Avoid further slowdowns */ if (tp->tp_descr_get == slot_tp_descr_get) @@ -7852,13 +7780,11 @@ slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value) stack[0] = self; stack[1] = target; if (value == NULL) { - PyObject *attr = _Py_ID(__delete__); - res = vectorcall_method(attr, stack, 2); + res = vectorcall_method(_Py_ID(__delete__), stack, 2); } else { stack[2] = value; - PyObject *attr = _Py_ID(__set__); - res = vectorcall_method(attr, stack, 3); + res = vectorcall_method(_Py_ID(__set__), stack, 3); } if (res == NULL) return -1; @@ -7872,8 +7798,7 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *attr = _Py_ID(__init__); - PyObject *meth = lookup_method(self, attr, &unbound); + PyObject *meth = lookup_method(self, _Py_ID(__init__), &unbound); if (meth == NULL) { return -1; } @@ -7905,8 +7830,7 @@ slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); PyObject *func, *result; - PyObject *attr = _Py_ID(__new__); - func = PyObject_GetAttr((PyObject *)type, attr); + func = PyObject_GetAttr((PyObject *)type, _Py_ID(__new__)); if (func == NULL) { return NULL; } @@ -7927,8 +7851,7 @@ slot_tp_finalize(PyObject *self) PyErr_Fetch(&error_type, &error_value, &error_traceback); /* Execute __del__ method, if any. */ - PyObject *attr = _Py_ID(__del__); - del = lookup_maybe_method(self, attr, &unbound); + del = lookup_maybe_method(self, _Py_ID(__del__), &unbound); if (del != NULL) { res = call_unbound_noarg(unbound, del, self); if (res == NULL) @@ -7948,8 +7871,7 @@ slot_am_await(PyObject *self) int unbound; PyObject *func, *res; - PyObject *attr = _Py_ID(__await__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__await__), &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -7967,8 +7889,7 @@ slot_am_aiter(PyObject *self) int unbound; PyObject *func, *res; - PyObject *attr = _Py_ID(__aiter__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__aiter__), &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -7986,8 +7907,7 @@ slot_am_anext(PyObject *self) int unbound; PyObject *func, *res; - PyObject *attr = _Py_ID(__anext__); - func = lookup_maybe_method(self, attr, &unbound); + func = lookup_maybe_method(self, _Py_ID(__anext__), &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -8618,9 +8538,9 @@ type_new_set_names(PyTypeObject *type) Py_ssize_t i = 0; PyObject *key, *value; - PyObject *attr = _Py_ID(__set_name__); while (PyDict_Next(names_to_set, &i, &key, &value)) { - PyObject *set_name = _PyObject_LookupSpecial(value, attr); + PyObject *set_name = _PyObject_LookupSpecial(value, + _Py_ID(__set_name__)); if (set_name == NULL) { if (PyErr_Occurred()) { goto error; @@ -8660,8 +8580,7 @@ type_new_init_subclass(PyTypeObject *type, PyObject *kwds) return -1; } - PyObject *attr = _Py_ID(__init_subclass__); - PyObject *func = PyObject_GetAttr(super, attr); + PyObject *func = PyObject_GetAttr(super, _Py_ID(__init_subclass__)); Py_DECREF(super); if (func == NULL) { return -1; @@ -8869,10 +8788,9 @@ super_getattro(PyObject *self, PyObject *name) /* We want __class__ to return the class of the super object (i.e. super, or a subclass), not the class of su->obj. */ - PyObject *attr = _Py_ID(__class__); if (PyUnicode_Check(name) && PyUnicode_GET_LENGTH(name) == 9 && - _PyUnicode_Equal(name, attr)) + _PyUnicode_Equal(name, _Py_ID(__class__))) goto skip; mro = starttype->tp_mro; @@ -8964,8 +8882,7 @@ supercheck(PyTypeObject *type, PyObject *obj) /* Try the slow way */ PyObject *class_attr; - PyObject *attr = _Py_ID(__class__); - if (_PyObject_LookupAttr(obj, attr, &class_attr) < 0) { + if (_PyObject_LookupAttr(obj, _Py_ID(__class__), &class_attr) < 0) { return NULL; } if (class_attr != NULL && @@ -9056,8 +8973,7 @@ super_init_without_args(InterpreterFrame *cframe, PyCodeObject *co, assert((_PyLocals_GetKind(co->co_localspluskinds, i) & CO_FAST_FREE) != 0); PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); assert(PyUnicode_Check(name)); - PyObject *attr = _Py_ID(__class__); - if (_PyUnicode_Equal(name, attr)) { + if (_PyUnicode_Equal(name, _Py_ID(__class__))) { PyObject *cell = _PyFrame_GetLocalsArray(cframe)[i]; if (cell == NULL || !PyCell_Check(cell)) { PyErr_SetString(PyExc_RuntimeError, diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 340d3389a716a9a..f15b33d8c4fdf28 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15780,15 +15780,14 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list( static PyObject * unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) { - PyObject *attr = _Py_ID(iter); if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(attr), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), it->it_seq, it->it_index); } else { PyObject *u = (PyObject *)_PyUnicode_New(0); if (u == NULL) return NULL; - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(attr), u); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), u); } } diff --git a/Objects/unionobject.c b/Objects/unionobject.c index 7518d711769c004..77464ac56e1e9b8 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -265,15 +265,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p) return _PyUnicodeWriter_WriteASCIIString(writer, "None", 4); } - PyObject *attr = _Py_ID(__origin__); - if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { + if (_PyObject_LookupAttr(p, _Py_ID(__origin__), &tmp) < 0) { goto exit; } if (tmp) { Py_DECREF(tmp); - attr = _Py_ID(__args__); - if (_PyObject_LookupAttr(p, attr, &tmp) < 0) { + if (_PyObject_LookupAttr(p, _Py_ID(__args__), &tmp) < 0) { goto exit; } if (tmp) { @@ -283,15 +281,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p) } } - attr = _Py_ID(__qualname__); - if (_PyObject_LookupAttr(p, attr, &qualname) < 0) { + if (_PyObject_LookupAttr(p, _Py_ID(__qualname__), &qualname) < 0) { goto exit; } if (qualname == NULL) { goto use_repr; } - attr = _Py_ID(__module__); - if (_PyObject_LookupAttr(p, attr, &module) < 0) { + if (_PyObject_LookupAttr(p, _Py_ID(__module__), &module) < 0) { goto exit; } if (module == NULL || module == Py_None) { diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index b896822fd9b9376..b082bed109aed84 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -170,8 +170,7 @@ weakref_repr(PyWeakReference *self) } Py_INCREF(obj); - PyObject *attr = _Py_ID(__name__); - if (_PyObject_LookupAttr(obj, attr, &name) < 0) { + if (_PyObject_LookupAttr(obj, _Py_ID(__name__), &name) < 0) { Py_DECREF(obj); return NULL; } @@ -464,8 +463,7 @@ proxy_checkref(PyWeakReference *proxy) method(PyObject *proxy, PyObject *Py_UNUSED(ignored)) { \ UNWRAP(proxy); \ Py_INCREF(proxy); \ - PyObject *attr = _Py_ID(special); \ - PyObject* res = PyObject_CallMethodNoArgs(proxy, attr); \ + PyObject* res = PyObject_CallMethodNoArgs(proxy, _Py_ID(special)); \ Py_DECREF(proxy); \ return res; \ } diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 6bb18be00a43df4..c817c8b331b51af 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -459,21 +459,18 @@ fp_setreadl(struct tok_state *tok, const char* enc) return 0; } - PyObject *str_open = _Py_ID(open); - PyObject *str_readline = _Py_ID(readline); - io = PyImport_ImportModule("io"); if (io == NULL) { return 0; } - stream = _PyObject_CallMethod(io, str_open, "isisOOO", + stream = _PyObject_CallMethod(io, _Py_ID(open), "isisOOO", fd, "r", -1, enc, Py_None, Py_None, Py_False); Py_DECREF(io); if (stream == NULL) { return 0; } - readline = PyObject_GetAttr(stream, str_readline); + readline = PyObject_GetAttr(stream, _Py_ID(readline)); Py_DECREF(stream); if (readline == NULL) { return 0; diff --git a/Python/_warnings.c b/Python/_warnings.c index ac289e21f3a38c9..d1ab6bb4bf63f14 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -104,10 +104,8 @@ init_filters(PyInterpreterState *interp) size_t pos = 0; /* Post-incremented in each use. */ #define ADD(TYPE, ACTION, MODNAME) \ - do { \ - PyObject *action = _Py_ID(ACTION); \ - PyList_SET_ITEM(filters, pos++, create_filter(TYPE, action, MODNAME)); \ - } while (0) + PyList_SET_ITEM(filters, pos++, \ + create_filter(TYPE, _Py_ID(ACTION), MODNAME)); ADD(PyExc_DeprecationWarning, default, "__main__"); ADD(PyExc_DeprecationWarning, ignore, NULL); ADD(PyExc_PendingDeprecationWarning, ignore, NULL); @@ -179,8 +177,7 @@ check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg) } /* Otherwise assume a regex filter and call its match() method */ - PyObject *str_match = _Py_ID(match); - result = PyObject_CallMethodOneArg(obj, str_match, arg); + result = PyObject_CallMethodOneArg(obj, _Py_ID(match), arg); if (result == NULL) return -1; @@ -190,9 +187,7 @@ check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg) } #define GET_WARNINGS_ATTR(interp, attr, try_import) \ - get_warnings_attr(interp, \ - _Py_ID(attr), \ - try_import) + get_warnings_attr(interp, _Py_ID(attr), try_import) /* Returns a new reference. @@ -201,14 +196,11 @@ check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg) static PyObject * get_warnings_attr(PyInterpreterState *interp, PyObject *attr, int try_import) { - PyObject *warnings_str; PyObject *warnings_module, *obj; - warnings_str = _Py_ID(warnings); - /* don't try to import after the start of the Python finallization */ if (try_import && !_Py_IsFinalizing()) { - warnings_module = PyImport_Import(warnings_str); + warnings_module = PyImport_Import(_Py_ID(warnings)); if (warnings_module == NULL) { /* Fallback to the C implementation if we cannot get the Python implementation */ @@ -226,7 +218,7 @@ get_warnings_attr(PyInterpreterState *interp, PyObject *attr, int try_import) if (!interp->modules) { return NULL; } - warnings_module = PyImport_GetModule(warnings_str); + warnings_module = PyImport_GetModule(_Py_ID(warnings)); if (warnings_module == NULL) return NULL; } @@ -413,8 +405,7 @@ already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key, if (st == NULL) { return -1; } - PyObject *str_version = _Py_ID(version); - version_obj = _PyDict_GetItemWithError(registry, str_version); + version_obj = _PyDict_GetItemWithError(registry, _Py_ID(version)); if (version_obj == NULL || !PyLong_CheckExact(version_obj) || PyLong_AsLong(version_obj) != st->filters_version) @@ -426,7 +417,7 @@ already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key, version_obj = PyLong_FromLong(st->filters_version); if (version_obj == NULL) return -1; - if (PyDict_SetItem(registry, str_version, version_obj) < 0) { + if (PyDict_SetItem(registry, _Py_ID(version), version_obj) < 0) { Py_DECREF(version_obj); return -1; } @@ -506,20 +497,17 @@ show_warning(PyThreadState *tstate, PyObject *filename, int lineno, PyObject *text, PyObject *category, PyObject *sourceline) { PyObject *f_stderr; - PyObject *attr; PyObject *name; char lineno_str[128]; PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno); - attr = _Py_ID(__name__); - name = PyObject_GetAttr(category, attr); + name = PyObject_GetAttr(category, _Py_ID(__name__)); if (name == NULL) { goto error; } - attr = _Py_ID(stderr); - f_stderr = _PySys_GetAttr(tstate, attr); + f_stderr = _PySys_GetAttr(tstate, _Py_ID(stderr)); if (f_stderr == NULL) { fprintf(stderr, "lost sys.stderr\n"); goto error; @@ -891,8 +879,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, /* Setup registry. */ assert(globals != NULL); assert(PyDict_Check(globals)); - PyObject *key = _Py_ID(__warningregistry__); - *registry = _PyDict_GetItemWithError(globals, key); + *registry = _PyDict_GetItemWithError(globals, _Py_ID(__warningregistry__)); if (*registry == NULL) { int rc; @@ -903,7 +890,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, if (*registry == NULL) goto handle_error; - rc = PyDict_SetItem(globals, key, *registry); + rc = PyDict_SetItem(globals, _Py_ID(__warningregistry__), *registry); if (rc < 0) goto handle_error; } @@ -911,8 +898,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, Py_INCREF(*registry); /* Setup module. */ - key = _Py_ID(__name__); - *module = _PyDict_GetItemWithError(globals, key); + *module = _PyDict_GetItemWithError(globals, _Py_ID(__name__)); if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) { Py_INCREF(*module); } @@ -1011,7 +997,6 @@ warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category, static PyObject * get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno) { - PyObject *key; PyObject *loader; PyObject *module_name; PyObject *get_source; @@ -1020,14 +1005,12 @@ get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno PyObject *source_line; /* Check/get the requisite pieces needed for the loader. */ - key = _Py_ID(__loader__); - loader = _PyDict_GetItemWithError(module_globals, key); + loader = _PyDict_GetItemWithError(module_globals, _Py_ID(__loader__)); if (loader == NULL) { return NULL; } Py_INCREF(loader); - key = _Py_ID(__name__); - module_name = _PyDict_GetItemWithError(module_globals, key); + module_name = _PyDict_GetItemWithError(module_globals, _Py_ID(__name__)); if (!module_name) { Py_DECREF(loader); return NULL; @@ -1035,8 +1018,7 @@ get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno Py_INCREF(module_name); /* Make sure the loader implements the optional get_source() method. */ - PyObject *attr = _Py_ID(get_source); - (void)_PyObject_LookupAttr(loader, attr, &get_source); + (void)_PyObject_LookupAttr(loader, _Py_ID(get_source), &get_source); Py_DECREF(loader); if (!get_source) { Py_DECREF(module_name); diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 908859d114a276b..c399289a5842651 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -32,8 +32,7 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs) } continue; } - PyObject *attr = _Py_ID(__mro_entries__); - if (_PyObject_LookupAttr(base, attr, &meth) < 0) { + if (_PyObject_LookupAttr(base, _Py_ID(__mro_entries__), &meth) < 0) { goto error; } if (!meth) { @@ -134,11 +133,10 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, goto error; } - PyObject *key = _Py_ID(metaclass); - meta = _PyDict_GetItemWithError(mkw, key); + meta = _PyDict_GetItemWithError(mkw, _Py_ID(metaclass)); if (meta != NULL) { Py_INCREF(meta); - if (PyDict_DelItem(mkw, key) < 0) { + if (PyDict_DelItem(mkw, _Py_ID(metaclass)) < 0) { goto error; } /* metaclass is explicitly given, check if it's indeed a class */ @@ -178,8 +176,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, } /* else: meta is not a class, so we cannot do the metaclass calculation, so we will use the explicitly given object as it is */ - PyObject *attr = _Py_ID(__prepare__); - if (_PyObject_LookupAttr(meta, attr, &prep) < 0) { + if (_PyObject_LookupAttr(meta, _Py_ID(__prepare__), &prep) < 0) { ns = NULL; } else if (prep == NULL) { @@ -934,10 +931,9 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, return NULL; } - PyObject *key = _Py_ID(__builtins__); - int r = PyDict_Contains(globals, key); + int r = PyDict_Contains(globals, _Py_ID(__builtins__)); if (r == 0) { - r = PyDict_SetItem(globals, key, PyEval_GetBuiltins()); + r = PyDict_SetItem(globals, _Py_ID(__builtins__), PyEval_GetBuiltins()); } if (r < 0) { return NULL; @@ -1022,10 +1018,9 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, Py_TYPE(locals)->tp_name); return NULL; } - PyObject *key = _Py_ID(__builtins__); - int r = PyDict_Contains(globals, key); + int r = PyDict_Contains(globals, _Py_ID(__builtins__)); if (r == 0) { - r = PyDict_SetItem(globals, key, PyEval_GetBuiltins()); + r = PyDict_SetItem(globals, _Py_ID(__builtins__), PyEval_GetBuiltins()); } if (r < 0) { return NULL; @@ -1949,8 +1944,7 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, if (file == Py_None) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_ID(stdout); - file = _PySys_GetAttr(tstate, attr); + file = _PySys_GetAttr(tstate, _Py_ID(stdout)); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -2010,8 +2004,7 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, } if (flush) { - PyObject *attr = _Py_ID(flush); - PyObject *tmp = PyObject_CallMethodNoArgs(file, attr); + PyObject *tmp = PyObject_CallMethodNoArgs(file, _Py_ID(flush)); if (tmp == NULL) { return NULL; } @@ -2074,8 +2067,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) } /* First of all, flush stderr */ - PyObject *str_flush = _Py_ID(flush); - tmp = PyObject_CallMethodNoArgs(ferr, str_flush); + tmp = PyObject_CallMethodNoArgs(ferr, _Py_ID(flush)); if (tmp == NULL) PyErr_Clear(); else @@ -2084,8 +2076,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) /* We should only use (GNU) readline if Python's sys.stdin and sys.stdout are the same as C's stdin and stdout, because we need to pass it those. */ - PyObject *str_fileno = _Py_ID(fileno); - tmp = PyObject_CallMethodNoArgs(fin, str_fileno); + tmp = PyObject_CallMethodNoArgs(fin, _Py_ID(fileno)); if (tmp == NULL) { PyErr_Clear(); tty = 0; @@ -2098,7 +2089,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) tty = fd == fileno(stdin) && isatty(fd); } if (tty) { - tmp = PyObject_CallMethodNoArgs(fout, str_fileno); + tmp = PyObject_CallMethodNoArgs(fout, _Py_ID(fileno)); if (tmp == NULL) { PyErr_Clear(); tty = 0; @@ -2122,12 +2113,10 @@ builtin_input_impl(PyObject *module, PyObject *prompt) const char *stdin_encoding_str, *stdin_errors_str; PyObject *result; size_t len; - PyObject *str_encoding = _Py_ID(encoding); - PyObject *str_errors = _Py_ID(errors); /* stdin is a text stream, so it must have an encoding. */ - stdin_encoding = PyObject_GetAttr(fin, str_encoding); - stdin_errors = PyObject_GetAttr(fin, str_errors); + stdin_encoding = PyObject_GetAttr(fin, _Py_ID(encoding)); + stdin_errors = PyObject_GetAttr(fin, _Py_ID(errors)); if (!stdin_encoding || !stdin_errors || !PyUnicode_Check(stdin_encoding) || !PyUnicode_Check(stdin_errors)) { @@ -2138,7 +2127,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) stdin_errors_str = PyUnicode_AsUTF8(stdin_errors); if (!stdin_encoding_str || !stdin_errors_str) goto _readline_errors; - tmp = PyObject_CallMethodNoArgs(fout, str_flush); + tmp = PyObject_CallMethodNoArgs(fout, _Py_ID(flush)); if (tmp == NULL) PyErr_Clear(); else @@ -2147,8 +2136,8 @@ builtin_input_impl(PyObject *module, PyObject *prompt) /* We have a prompt, encode it as stdout would */ const char *stdout_encoding_str, *stdout_errors_str; PyObject *stringpo; - stdout_encoding = PyObject_GetAttr(fout, str_encoding); - stdout_errors = PyObject_GetAttr(fout, str_errors); + stdout_encoding = PyObject_GetAttr(fout, _Py_ID(encoding)); + stdout_errors = PyObject_GetAttr(fout, _Py_ID(errors)); if (!stdout_encoding || !stdout_errors || !PyUnicode_Check(stdout_encoding) || !PyUnicode_Check(stdout_errors)) { @@ -2233,7 +2222,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0) return NULL; } - tmp = PyObject_CallMethodNoArgs(fout, str_flush); + tmp = PyObject_CallMethodNoArgs(fout, _Py_ID(flush)); if (tmp == NULL) PyErr_Clear(); else @@ -2284,8 +2273,7 @@ builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits) return NULL; } - PyObject *attr = _Py_ID(__round__); - round = _PyObject_LookupSpecial(number, attr); + round = _PyObject_LookupSpecial(number, _Py_ID(__round__)); if (round == NULL) { if (!PyErr_Occurred()) PyErr_Format(PyExc_TypeError, @@ -2346,8 +2334,7 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject if (newlist == NULL) return NULL; - PyObject *attr = _Py_ID(sort); - callable = PyObject_GetAttr(newlist, attr); + callable = PyObject_GetAttr(newlist, _Py_ID(sort)); if (callable == NULL) { Py_DECREF(newlist); return NULL; @@ -2379,8 +2366,7 @@ builtin_vars(PyObject *self, PyObject *args) Py_XINCREF(d); } else { - PyObject *attr = _Py_ID(__dict__); - if (_PyObject_LookupAttr(v, attr, &d) == 0) { + if (_PyObject_LookupAttr(v, _Py_ID(__dict__), &d) == 0) { PyErr_SetString(PyExc_TypeError, "vars() argument must have __dict__ attribute"); } diff --git a/Python/ceval.c b/Python/ceval.c index 93a85867f3bdbc3..cb0dfa3f34ec076 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -873,14 +873,12 @@ match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys) PyObject *seen = NULL; PyObject *dummy = NULL; PyObject *values = NULL; - PyObject *get_name = NULL; PyObject *get = NULL; // We use the two argument form of map.get(key, default) for two reasons: // - Atomically check for a key and get its value without error handling. // - Don't cause key creation or resizing in dict subclasses like // collections.defaultdict that define __missing__ (or similar). - get_name = _Py_ID(get); - int meth_found = _PyObject_GetMethod(map, get_name, &get); + int meth_found = _PyObject_GetMethod(map, _Py_ID(get), &get); if (get == NULL) { goto fail; } @@ -1731,8 +1729,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr #ifdef LLTRACE { - PyObject *key = _Py_ID(__ltrace__); - int r = PyDict_Contains(GLOBALS(), key); + int r = PyDict_Contains(GLOBALS(), _Py_ID(__ltrace__)); if (r < 0) { goto exit_unwind; } @@ -2367,8 +2364,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(PRINT_EXPR) { PyObject *value = POP(); - PyObject *key = _Py_ID(displayhook); - PyObject *hook = _PySys_GetAttr(tstate, key); + PyObject *hook = _PySys_GetAttr(tstate, _Py_ID(displayhook)); PyObject *res; if (hook == NULL) { _PyErr_SetString(tstate, PyExc_RuntimeError, @@ -2577,8 +2573,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr retval = Py_TYPE(receiver)->tp_iternext(receiver); } else { - PyObject *name = _Py_ID(send); - retval = PyObject_CallMethodOneArg(receiver, name, v); + retval = PyObject_CallMethodOneArg(receiver, _Py_ID(send), v); } if (retval == NULL) { if (tstate->c_tracefunc != NULL @@ -2713,8 +2708,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(LOAD_BUILD_CLASS) { PyObject *bc; if (PyDict_CheckExact(BUILTINS())) { - PyObject *name = _Py_ID(__build_class__); - bc = _PyDict_GetItemWithError(BUILTINS(), name); + bc = _PyDict_GetItemWithError(BUILTINS(), + _Py_ID(__build_class__)); if (bc == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_NameError, @@ -2725,8 +2720,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr Py_INCREF(bc); } else { - PyObject *build_class_str = _Py_ID(__build_class__); - bc = PyObject_GetItem(BUILTINS(), build_class_str); + bc = PyObject_GetItem(BUILTINS(), _Py_ID(__build_class__)); if (bc == NULL) { if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) _PyErr_SetString(tstate, PyExc_NameError, @@ -3288,8 +3282,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } /* check if __annotations__ in locals()... */ if (PyDict_CheckExact(LOCALS())) { - PyObject *key = _Py_ID(__annotations__); - ann_dict = _PyDict_GetItemWithError(LOCALS(), key); + ann_dict = _PyDict_GetItemWithError(LOCALS(), + _Py_ID(__annotations__)); if (ann_dict == NULL) { if (_PyErr_Occurred(tstate)) { goto error; @@ -3299,7 +3293,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr if (ann_dict == NULL) { goto error; } - err = PyDict_SetItem(LOCALS(), key, ann_dict); + err = PyDict_SetItem(LOCALS(), _Py_ID(__annotations__), + ann_dict); Py_DECREF(ann_dict); if (err != 0) { goto error; @@ -3308,8 +3303,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } else { /* do the same if locals() is not a dict */ - PyObject *ann_str = _Py_ID(__annotations__); - ann_dict = PyObject_GetItem(LOCALS(), ann_str); + ann_dict = PyObject_GetItem(LOCALS(), _Py_ID(__annotations__)); if (ann_dict == NULL) { if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) { goto error; @@ -3319,7 +3313,8 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr if (ann_dict == NULL) { goto error; } - err = PyObject_SetItem(LOCALS(), ann_str, ann_dict); + err = PyObject_SetItem(LOCALS(), _Py_ID(__annotations__), + ann_dict); Py_DECREF(ann_dict); if (err != 0) { goto error; @@ -4223,8 +4218,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(BEFORE_ASYNC_WITH) { PyObject *mgr = TOP(); PyObject *res; - PyObject *str_aenter = _Py_ID(__aenter__); - PyObject *enter = _PyObject_LookupSpecial(mgr, str_aenter); + PyObject *enter = _PyObject_LookupSpecial(mgr, _Py_ID(__aenter__)); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4234,8 +4228,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *str_aexit = _Py_ID(__aexit__); - PyObject *exit = _PyObject_LookupSpecial(mgr, str_aexit); + PyObject *exit = _PyObject_LookupSpecial(mgr, _Py_ID(__aexit__)); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4261,8 +4254,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(BEFORE_WITH) { PyObject *mgr = TOP(); PyObject *res; - PyObject *str_enter = _Py_ID(__enter__); - PyObject *enter = _PyObject_LookupSpecial(mgr, str_enter); + PyObject *enter = _PyObject_LookupSpecial(mgr, _Py_ID(__enter__)); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4272,8 +4264,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *str_exit = _Py_ID(__exit__); - PyObject *exit = _PyObject_LookupSpecial(mgr, str_exit); + PyObject *exit = _PyObject_LookupSpecial(mgr, _Py_ID(__exit__)); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -7072,8 +7063,7 @@ import_name(PyThreadState *tstate, InterpreterFrame *frame, PyObject *import_func, *res; PyObject* stack[5]; - PyObject *key = _Py_ID(__import__); - import_func = _PyDict_GetItemWithError(frame->f_builtins, key); + import_func = _PyDict_GetItemWithError(frame->f_builtins, _Py_ID(__import__)); if (import_func == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found"); @@ -7120,8 +7110,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name) /* Issue #17636: in case this failed because of a circular relative import, try to fallback on reading the module directly from sys.modules. */ - PyObject *attr = _Py_ID(__name__); - pkgname = PyObject_GetAttr(v, attr); + pkgname = PyObject_GetAttr(v, _Py_ID(__name__)); if (pkgname == NULL) { goto error; } @@ -7163,8 +7152,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name) PyErr_SetImportError(errmsg, pkgname, NULL); } else { - PyObject *attr = _Py_ID(__spec__); - PyObject *spec = PyObject_GetAttr(v, attr); + PyObject *spec = PyObject_GetAttr(v, _Py_ID(__spec__)); const char *fmt = _PyModuleSpec_IsInitializing(spec) ? "cannot import name %R from partially initialized module %R " @@ -7190,13 +7178,11 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v) int skip_leading_underscores = 0; int pos, err; - PyObject *attr = _Py_ID(__all__); - if (_PyObject_LookupAttr(v, attr, &all) < 0) { + if (_PyObject_LookupAttr(v, _Py_ID(__all__), &all) < 0) { return -1; /* Unexpected error */ } if (all == NULL) { - attr = _Py_ID(__dict__); - if (_PyObject_LookupAttr(v, attr, &dict) < 0) { + if (_PyObject_LookupAttr(v, _Py_ID(__dict__), &dict) < 0) { return -1; } if (dict == NULL) { @@ -7223,8 +7209,7 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v) break; } if (!PyUnicode_Check(name)) { - attr = _Py_ID(__name__); - PyObject *modname = PyObject_GetAttr(v, attr); + PyObject *modname = PyObject_GetAttr(v, _Py_ID(__name__)); if (modname == NULL) { Py_DECREF(name); err = -1; @@ -7430,8 +7415,7 @@ format_exc_check_arg(PyThreadState *tstate, PyObject *exc, if (PyErr_GivenExceptionMatches(value, PyExc_NameError)) { // We do not care if this fails because we are going to restore the // NameError anyway. - PyObject *attr = _Py_ID(name); - (void)PyObject_SetAttr(value, attr, obj); + (void)PyObject_SetAttr(value, _Py_ID(name), obj); } PyErr_Restore(type, value, traceback); } diff --git a/Python/codecs.c b/Python/codecs.c index 1dea0a579dfb3dc..803382b09c526e2 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -535,8 +535,7 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding, * attribute. */ if (!PyTuple_CheckExact(codec)) { - PyObject *is_text_encoding = _Py_ID(_is_text_encoding); - if (_PyObject_LookupAttr(codec, is_text_encoding, &attr) < 0) { + if (_PyObject_LookupAttr(codec, _Py_ID(_is_text_encoding), &attr) < 0) { Py_DECREF(codec); return NULL; } diff --git a/Python/compile.c b/Python/compile.c index 107c1286863471c..9a540192477c5a1 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -1609,12 +1609,11 @@ compiler_enter_scope(struct compiler *c, identifier name, } if (u->u_ste->ste_needs_class_closure) { /* Cook up an implicit __class__ cell. */ - PyObject *name; int res; assert(u->u_scope_type == COMPILER_SCOPE_CLASS); assert(PyDict_GET_SIZE(u->u_cellvars) == 0); - name = _Py_ID(__class__); - res = PyDict_SetItem(u->u_cellvars, name, _PyLong_GetZero()); + res = PyDict_SetItem(u->u_cellvars, _Py_ID(__class__), + _PyLong_GetZero()); if (res < 0) { compiler_unit_free(u); return 0; @@ -1999,7 +1998,6 @@ compiler_body(struct compiler *c, asdl_stmt_seq *stmts) int i = 0; stmt_ty st; PyObject *docstring; - PyObject *__doc__ = _Py_ID(__doc__); /* Set current line number to the line number of first statement. This way line number for SETUP_ANNOTATIONS will always @@ -2024,7 +2022,7 @@ compiler_body(struct compiler *c, asdl_stmt_seq *stmts) assert(st->kind == Expr_kind); VISIT(c, expr, st->v.Expr.value); UNSET_LOC(c); - if (!compiler_nameop(c, __doc__, Store)) + if (!compiler_nameop(c, _Py_ID(__doc__), Store)) return 0; } } @@ -2334,8 +2332,8 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args, args->kwarg->annotation, &annotations_len)) return 0; - identifier return_str = _Py_ID(return); - if (!compiler_visit_argannotation(c, return_str, returns, &annotations_len)) { + if (!compiler_visit_argannotation(c, _Py_ID(return), returns, + &annotations_len)) { return 0; } @@ -5922,7 +5920,6 @@ compiler_annassign(struct compiler *c, stmt_ty s) { expr_ty targ = s->v.AnnAssign.target; PyObject* mangled; - PyObject *__annotations__ = _Py_ID(__annotations__); assert(s->kind == AnnAssign_kind); @@ -5945,7 +5942,7 @@ compiler_annassign(struct compiler *c, stmt_ty s) else { VISIT(c, expr, s->v.AnnAssign.annotation); } - ADDOP_NAME(c, LOAD_NAME, __annotations__, names); + ADDOP_NAME(c, LOAD_NAME, _Py_ID(__annotations__), names); mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id); ADDOP_LOAD_CONST_NEW(c, mangled); ADDOP(c, STORE_SUBSCR); diff --git a/Python/errors.c b/Python/errors.c index dbc74be9fe78cdb..310fc914b7cbe2f 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -1129,8 +1129,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) goto failure; } - PyObject *attr = _Py_ID(__module__); - int r = PyDict_Contains(dict, attr); + int r = PyDict_Contains(dict, _Py_ID(__module__)); if (r < 0) { goto failure; } @@ -1139,7 +1138,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) (Py_ssize_t)(dot-name)); if (modulename == NULL) goto failure; - if (PyDict_SetItem(dict, attr, modulename) != 0) + if (PyDict_SetItem(dict, _Py_ID(__module__), modulename) != 0) goto failure; } if (PyTuple_Check(base)) { @@ -1342,8 +1341,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, assert(PyExceptionClass_Check(exc_type)); - PyObject *attr = _Py_ID(__module__); - PyObject *modulename = PyObject_GetAttr(exc_type, attr); + PyObject *modulename = PyObject_GetAttr(exc_type, _Py_ID(__module__)); if (modulename == NULL || !PyUnicode_Check(modulename)) { Py_XDECREF(modulename); _PyErr_Clear(tstate); @@ -1352,10 +1350,8 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, } } else { - PyObject *builtins = _Py_ID(builtins); - PyObject *__main__ = _Py_ID(__main__); - if (!_PyUnicode_Equal(modulename, builtins) && - !_PyUnicode_Equal(modulename, __main__)) { + if (!_PyUnicode_Equal(modulename, _Py_ID(builtins)) && + !_PyUnicode_Equal(modulename, _Py_ID(__main__))) { if (PyFile_WriteObject(modulename, file, Py_PRINT_RAW) < 0) { Py_DECREF(modulename); return -1; @@ -1403,8 +1399,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, } /* Explicitly call file.flush() */ - PyObject *flush = _Py_ID(flush); - PyObject *res = _PyObject_CallMethodNoArgs(file, flush); + PyObject *res = _PyObject_CallMethodNoArgs(file, _Py_ID(flush)); if (!res) { return -1; } @@ -1419,8 +1414,7 @@ write_unraisable_exc(PyThreadState *tstate, PyObject *exc_type, PyObject *exc_value, PyObject *exc_tb, PyObject *err_msg, PyObject *obj) { - PyObject *attr = _Py_ID(stderr); - PyObject *file = _PySys_GetAttr(tstate, attr); + PyObject *file = _PySys_GetAttr(tstate, _Py_ID(stderr)); if (file == NULL || file == Py_None) { return 0; } @@ -1524,8 +1518,7 @@ _PyErr_WriteUnraisableMsg(const char *err_msg_str, PyObject *obj) goto error; } - PyObject *attr = _Py_ID(unraisablehook); - PyObject *hook = _PySys_GetAttr(tstate, attr); + PyObject *hook = _PySys_GetAttr(tstate, _Py_ID(unraisablehook)); if (hook == NULL) { Py_DECREF(hook_args); goto default_hook; @@ -1599,7 +1592,7 @@ static void PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, int end_lineno, int end_col_offset) { - PyObject *exc, *v, *tb, *tmp, *attr; + PyObject *exc, *v, *tb, *tmp; PyThreadState *tstate = _PyThreadState_GET(); /* add attributes for the line number and filename for the error */ @@ -1611,8 +1604,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, if (tmp == NULL) _PyErr_Clear(tstate); else { - attr = _Py_ID(lineno); - if (PyObject_SetAttr(v, attr, tmp)) { + if (PyObject_SetAttr(v, _Py_ID(lineno), tmp)) { _PyErr_Clear(tstate); } Py_DECREF(tmp); @@ -1624,8 +1616,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - attr = _Py_ID(offset); - if (PyObject_SetAttr(v, attr, tmp ? tmp : Py_None)) { + if (PyObject_SetAttr(v, _Py_ID(offset), tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } Py_XDECREF(tmp); @@ -1637,8 +1628,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - attr = _Py_ID(end_lineno); - if (PyObject_SetAttr(v, attr, tmp ? tmp : Py_None)) { + if (PyObject_SetAttr(v, _Py_ID(end_lineno), tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } Py_XDECREF(tmp); @@ -1650,23 +1640,20 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - attr = _Py_ID(end_offset); - if (PyObject_SetAttr(v, attr, tmp ? tmp : Py_None)) { + if (PyObject_SetAttr(v, _Py_ID(end_offset), tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } Py_XDECREF(tmp); tmp = NULL; if (filename != NULL) { - attr = _Py_ID(filename); - if (PyObject_SetAttr(v, attr, filename)) { + if (PyObject_SetAttr(v, _Py_ID(filename), filename)) { _PyErr_Clear(tstate); } tmp = PyErr_ProgramTextObject(filename, lineno); if (tmp) { - attr = _Py_ID(text); - if (PyObject_SetAttr(v, attr, tmp)) { + if (PyObject_SetAttr(v, _Py_ID(text), tmp)) { _PyErr_Clear(tstate); } Py_DECREF(tmp); @@ -1676,8 +1663,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, } } if (exc != PyExc_SyntaxError) { - attr = _Py_ID(msg); - if (_PyObject_LookupAttr(v, attr, &tmp) < 0) { + if (_PyObject_LookupAttr(v, _Py_ID(msg), &tmp) < 0) { _PyErr_Clear(tstate); } else if (tmp) { @@ -1686,7 +1672,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, else { tmp = PyObject_Str(v); if (tmp) { - if (PyObject_SetAttr(v, attr, tmp)) { + if (PyObject_SetAttr(v, _Py_ID(msg), tmp)) { _PyErr_Clear(tstate); } Py_DECREF(tmp); @@ -1696,15 +1682,14 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, } } - attr = _Py_ID(print_file_and_line); - if (_PyObject_LookupAttr(v, attr, &tmp) < 0) { + if (_PyObject_LookupAttr(v, _Py_ID(print_file_and_line), &tmp) < 0) { _PyErr_Clear(tstate); } else if (tmp) { Py_DECREF(tmp); } else { - if (PyObject_SetAttr(v, attr, Py_None)) { + if (PyObject_SetAttr(v, _Py_ID(print_file_and_line), Py_None)) { _PyErr_Clear(tstate); } } diff --git a/Python/import.c b/Python/import.c index a20c903badae7bb..63c53c00c4d16e0 100644 --- a/Python/import.c +++ b/Python/import.c @@ -73,8 +73,7 @@ _PyImportZip_Init(PyThreadState *tstate) } } else { - PyObject *attr = _Py_ID(zipimporter); - PyObject *zipimporter = PyObject_GetAttr(zipimport, attr); + PyObject *zipimporter = PyObject_GetAttr(zipimport, _Py_ID(zipimporter)); Py_DECREF(zipimport); if (zipimporter == NULL) { _PyErr_Clear(tstate); /* No zipimporter object -- okay */ @@ -341,22 +340,20 @@ import_get_module(PyThreadState *tstate, PyObject *name) static int import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *name) { - PyObject *spec, *attr; + PyObject *spec; /* Optimization: only call _bootstrap._lock_unlock_module() if __spec__._initializing is true. NOTE: because of this, initializing must be set *before* stuffing the new module in sys.modules. */ - attr = _Py_ID(__spec__); - spec = PyObject_GetAttr(mod, attr); + spec = PyObject_GetAttr(mod, _Py_ID(__spec__)); int busy = _PyModuleSpec_IsInitializing(spec); Py_XDECREF(spec); if (busy) { - attr = _Py_ID(_lock_unlock_module); /* Wait until module is done importing. */ PyObject *value = _PyObject_CallMethodOneArg( - interp->importlib, attr, name); + interp->importlib, _Py_ID(_lock_unlock_module), name); if (value == NULL) { return -1; } @@ -716,8 +713,8 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, external= PyObject_GetAttrString(interp->importlib, "_bootstrap_external"); if (external != NULL) { - PyObject *attr = _Py_ID(_get_sourcefile); - pathobj = _PyObject_CallMethodOneArg(external, attr, cpathobj); + pathobj = _PyObject_CallMethodOneArg( + external, _Py_ID(_get_sourcefile), cpathobj); Py_DECREF(external); } if (pathobj == NULL) @@ -745,10 +742,9 @@ module_dict_for_exec(PyThreadState *tstate, PyObject *name) /* If the module is being reloaded, we get the old module back and re-use its dict to exec the new code. */ d = PyModule_GetDict(m); - PyObject *attr = _Py_ID(__builtins__); - int r = PyDict_Contains(d, attr); + int r = PyDict_Contains(d, _Py_ID(__builtins__)); if (r == 0) { - r = PyDict_SetItem(d, attr, PyEval_GetBuiltins()); + r = PyDict_SetItem(d, _Py_ID(__builtins__), PyEval_GetBuiltins()); } if (r < 0) { remove_module(tstate, name); @@ -805,8 +801,7 @@ PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname, Py_DECREF(d); return NULL; } - PyObject *attr = _Py_ID(_fix_up_module); - res = PyObject_CallMethodObjArgs(external, attr, + res = PyObject_CallMethodObjArgs(external, _Py_ID(_fix_up_module), d, name, pathname, cpathname, NULL); Py_DECREF(external); if (res != NULL) { @@ -1529,7 +1524,7 @@ remove_importlib_frames(PyThreadState *tstate) static PyObject * resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level) { - PyObject *abs_name, *attr; + PyObject *abs_name; PyObject *package = NULL; PyObject *spec; Py_ssize_t last_dot; @@ -1544,16 +1539,14 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level _PyErr_SetString(tstate, PyExc_TypeError, "globals must be a dict"); goto error; } - attr = _Py_ID(__package__); - package = PyDict_GetItemWithError(globals, attr); + package = PyDict_GetItemWithError(globals, _Py_ID(__package__)); if (package == Py_None) { package = NULL; } else if (package == NULL && _PyErr_Occurred(tstate)) { goto error; } - attr = _Py_ID(__spec__); - spec = PyDict_GetItemWithError(globals, attr); + spec = PyDict_GetItemWithError(globals, _Py_ID(__spec__)); if (spec == NULL && _PyErr_Occurred(tstate)) { goto error; } @@ -1567,8 +1560,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level } else if (spec != NULL && spec != Py_None) { int equal; - attr = _Py_ID(parent); - PyObject *parent = PyObject_GetAttr(spec, attr); + PyObject *parent = PyObject_GetAttr(spec, _Py_ID(parent)); if (parent == NULL) { goto error; } @@ -1587,8 +1579,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level } } else if (spec != NULL && spec != Py_None) { - attr = _Py_ID(parent); - package = PyObject_GetAttr(spec, attr); + package = PyObject_GetAttr(spec, _Py_ID(parent)); if (package == NULL) { goto error; } @@ -1605,8 +1596,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level goto error; } - attr = _Py_ID(__name__); - package = PyDict_GetItemWithError(globals, attr); + package = PyDict_GetItemWithError(globals, _Py_ID(__name__)); if (package == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_KeyError, @@ -1622,8 +1612,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level goto error; } - attr = _Py_ID(__path__); - int haspath = PyDict_Contains(globals, attr); + int haspath = PyDict_Contains(globals, _Py_ID(__path__)); if (haspath < 0) { goto error; } @@ -1731,9 +1720,8 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name) if (PyDTrace_IMPORT_FIND_LOAD_START_ENABLED()) PyDTrace_IMPORT_FIND_LOAD_START(PyUnicode_AsUTF8(abs_name)); - PyObject *attr = _Py_ID(_find_and_load); - mod = PyObject_CallMethodObjArgs(interp->importlib, attr, abs_name, - interp->import_func, NULL); + mod = PyObject_CallMethodObjArgs(interp->importlib, _Py_ID(_find_and_load), + abs_name, interp->import_func, NULL); if (PyDTrace_IMPORT_FIND_LOAD_DONE_ENABLED()) PyDTrace_IMPORT_FIND_LOAD_DONE(PyUnicode_AsUTF8(abs_name), @@ -1897,15 +1885,13 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, } else { PyObject *path; - PyObject *attr = _Py_ID(__path__); - if (_PyObject_LookupAttr(mod, attr, &path) < 0) { + if (_PyObject_LookupAttr(mod, _Py_ID(__path__), &path) < 0) { goto error; } if (path) { Py_DECREF(path); - attr = _Py_ID(_handle_fromlist); final_mod = PyObject_CallMethodObjArgs( - interp->importlib, attr, + interp->importlib, _Py_ID(_handle_fromlist), mod, fromlist, interp->import_func, NULL); } else { @@ -1946,8 +1932,7 @@ PyObject * PyImport_ReloadModule(PyObject *m) { PyObject *reloaded_module = NULL; - PyObject *name = _Py_ID(importlib); - PyObject *importlib = PyImport_GetModule(name); + PyObject *importlib = PyImport_GetModule(_Py_ID(importlib)); if (importlib == NULL) { if (PyErr_Occurred()) { return NULL; @@ -1959,8 +1944,7 @@ PyImport_ReloadModule(PyObject *m) } } - name = _Py_ID(reload); - reloaded_module = PyObject_CallMethodOneArg(importlib, name, m); + reloaded_module = PyObject_CallMethodOneArg(importlib, _Py_ID(reload), m); Py_DECREF(importlib); return reloaded_module; } @@ -1984,9 +1968,6 @@ PyImport_Import(PyObject *module_name) PyObject *builtins = NULL; PyObject *r = NULL; - PyObject *import_str = _Py_ID(__import__); - PyObject *builtins_str = _Py_ID(__builtins__); - PyObject *from_list = PyList_New(0); if (from_list == NULL) { goto err; @@ -1996,7 +1977,7 @@ PyImport_Import(PyObject *module_name) globals = PyEval_GetGlobals(); if (globals != NULL) { Py_INCREF(globals); - builtins = PyObject_GetItem(globals, builtins_str); + builtins = PyObject_GetItem(globals, _Py_ID(__builtins__)); if (builtins == NULL) goto err; } @@ -2007,20 +1988,20 @@ PyImport_Import(PyObject *module_name) if (builtins == NULL) { goto err; } - globals = Py_BuildValue("{OO}", builtins_str, builtins); + globals = Py_BuildValue("{OO}", _Py_ID(__builtins__), builtins); if (globals == NULL) goto err; } /* Get the __import__ function from the builtins */ if (PyDict_Check(builtins)) { - import = PyObject_GetItem(builtins, import_str); + import = PyObject_GetItem(builtins, _Py_ID(__import__)); if (import == NULL) { - _PyErr_SetObject(tstate, PyExc_KeyError, import_str); + _PyErr_SetObject(tstate, PyExc_KeyError, _Py_ID(__import__)); } } else - import = PyObject_GetAttr(builtins, import_str); + import = PyObject_GetAttr(builtins, _Py_ID(__import__)); if (import == NULL) goto err; diff --git a/Python/importdl.c b/Python/importdl.c index b68862e5a4ddbd7..0d98b4a235e81db 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -78,8 +78,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) { } /* Replace '-' by '_' */ - PyObject *replace = _Py_ID(replace); - modname = _PyObject_CallMethod(encoded, replace, "cc", '-', '_'); + modname = _PyObject_CallMethod(encoded, _Py_ID(replace), "cc", '-', '_'); if (modname == NULL) goto error; diff --git a/Python/marshal.c b/Python/marshal.c index 015859c3450a464..74bc704233b0790 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -712,8 +712,7 @@ r_string(Py_ssize_t n, RFILE *p) if (mview == NULL) return NULL; - PyObject *readinto = _Py_ID(readinto); - res = _PyObject_CallMethod(p->readable, readinto, "N", mview); + res = _PyObject_CallMethod(p->readable, _Py_ID(readinto), "N", mview); if (res != NULL) { read = PyNumber_AsSsize_t(res, PyExc_ValueError); Py_DECREF(res); @@ -1717,8 +1716,7 @@ marshal_dump_impl(PyObject *module, PyObject *value, PyObject *file, s = PyMarshal_WriteObjectToString(value, version); if (s == NULL) return NULL; - PyObject *write = _Py_ID(write); - res = _PyObject_CallMethodOneArg(file, write, s); + res = _PyObject_CallMethodOneArg(file, _Py_ID(write), s); Py_DECREF(s); return res; } @@ -1754,8 +1752,7 @@ marshal_load(PyObject *module, PyObject *file) * This can be removed if we guarantee good error handling * for r_string() */ - PyObject *read = _Py_ID(read); - data = _PyObject_CallMethod(file, read, "i", 0); + data = _PyObject_CallMethod(file, _Py_ID(read), "i", 0); if (data == NULL) return NULL; if (!PyBytes_Check(data)) { diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 16a0508709451cc..93542244096c769 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1438,8 +1438,7 @@ finalize_clear_modules_dict(PyObject *modules) PyDict_Clear(modules); } else { - PyObject *attr = _Py_ID(clear); - if (PyObject_CallMethodNoArgs(modules, attr) == NULL) { + if (PyObject_CallMethodNoArgs(modules, _Py_ID(clear)) == NULL) { PyErr_WriteUnraisable(NULL); } } @@ -1613,12 +1612,11 @@ flush_std_files(void) PyThreadState *tstate = _PyThreadState_GET(); PyObject *fout = _PySys_GetAttr(tstate, _Py_ID(stdout)); PyObject *ferr = _PySys_GetAttr(tstate, _Py_ID(stderr)); - PyObject *flush = _Py_ID(flush); PyObject *tmp; int status = 0; if (fout != NULL && fout != Py_None && !file_is_closed(fout)) { - tmp = PyObject_CallMethodNoArgs(fout, flush); + tmp = PyObject_CallMethodNoArgs(fout, _Py_ID(flush)); if (tmp == NULL) { PyErr_WriteUnraisable(fout); status = -1; @@ -1628,7 +1626,7 @@ flush_std_files(void) } if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) { - tmp = PyObject_CallMethodNoArgs(ferr, flush); + tmp = PyObject_CallMethodNoArgs(ferr, _Py_ID(flush)); if (tmp == NULL) { PyErr_Clear(); status = -1; @@ -2215,7 +2213,7 @@ create_stdio(const PyConfig *config, PyObject* io, PyObject *buf = NULL, *stream = NULL, *text = NULL, *raw = NULL, *res; const char* mode; const char* newline; - PyObject *line_buffering, *write_through, *attr; + PyObject *line_buffering, *write_through; int buffering, isatty; const int buffered_stdio = config->buffered_stdio; @@ -2235,8 +2233,7 @@ create_stdio(const PyConfig *config, PyObject* io, mode = "wb"; else mode = "rb"; - attr = _Py_ID(open); - buf = _PyObject_CallMethod(io, attr, "isiOOOO", + buf = _PyObject_CallMethod(io, _Py_ID(open), "isiOOOO", fd, mode, buffering, Py_None, Py_None, /* encoding, errors */ Py_None, Py_False); /* newline, closefd */ @@ -2244,8 +2241,7 @@ create_stdio(const PyConfig *config, PyObject* io, goto error; if (buffering) { - attr = _Py_ID(raw); - raw = PyObject_GetAttr(buf, attr); + raw = PyObject_GetAttr(buf, _Py_ID(raw)); if (raw == NULL) goto error; } @@ -2261,11 +2257,9 @@ create_stdio(const PyConfig *config, PyObject* io, #endif text = PyUnicode_FromString(name); - attr = _Py_ID(name); - if (text == NULL || PyObject_SetAttr(raw, attr, text) < 0) + if (text == NULL || PyObject_SetAttr(raw, _Py_ID(name), text) < 0) goto error; - attr = _Py_ID(isatty); - res = PyObject_CallMethodNoArgs(raw, attr); + res = PyObject_CallMethodNoArgs(raw, _Py_ID(isatty)); if (res == NULL) goto error; isatty = PyObject_IsTrue(res); @@ -2308,8 +2302,7 @@ create_stdio(const PyConfig *config, PyObject* io, goto error; } - attr = _Py_ID(TextIOWrapper); - stream = _PyObject_CallMethod(io, attr, "OOOsOO", + stream = _PyObject_CallMethod(io, _Py_ID(TextIOWrapper), "OOOsOO", buf, encoding_str, errors_str, newline, line_buffering, write_through); Py_CLEAR(buf); @@ -2323,8 +2316,7 @@ create_stdio(const PyConfig *config, PyObject* io, else mode = "r"; text = PyUnicode_FromString(mode); - attr = _Py_ID(mode); - if (!text || PyObject_SetAttr(stream, attr, text) < 0) + if (!text || PyObject_SetAttr(stream, _Py_ID(mode), text) < 0) goto error; Py_CLEAR(text); return stream; @@ -2390,7 +2382,7 @@ init_sys_streams(PyThreadState *tstate) PyObject *iomod = NULL; PyObject *std = NULL; int fd; - PyObject * encoding_attr, *attr; + PyObject * encoding_attr; PyStatus res = _PyStatus_OK(); const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp); @@ -2423,8 +2415,7 @@ init_sys_streams(PyThreadState *tstate) if (std == NULL) goto error; PySys_SetObject("__stdin__", std); - attr = _Py_ID(stdin); - _PySys_SetAttr(attr, std); + _PySys_SetAttr(_Py_ID(stdin), std); Py_DECREF(std); /* Set sys.stdout */ @@ -2435,8 +2426,7 @@ init_sys_streams(PyThreadState *tstate) if (std == NULL) goto error; PySys_SetObject("__stdout__", std); - attr = _Py_ID(stdout); - _PySys_SetAttr(attr, std); + _PySys_SetAttr(_Py_ID(stdout), std); Py_DECREF(std); #if 1 /* Disable this if you have trouble debugging bootstrap stuff */ @@ -2465,8 +2455,7 @@ init_sys_streams(PyThreadState *tstate) Py_DECREF(std); goto error; } - attr = _Py_ID(stderr); - if (_PySys_SetAttr(attr, std) < 0) { + if (_PySys_SetAttr(_Py_ID(stderr), std) < 0) { Py_DECREF(std); goto error; } @@ -2506,7 +2495,7 @@ _Py_FatalError_DumpTracebacks(int fd, PyInterpreterState *interp, static int _Py_FatalError_PrintExc(PyThreadState *tstate) { - PyObject *ferr, *res, *attr; + PyObject *ferr, *res; PyObject *exception, *v, *tb; int has_tb; @@ -2516,8 +2505,7 @@ _Py_FatalError_PrintExc(PyThreadState *tstate) return 0; } - attr = _Py_ID(stderr); - ferr = _PySys_GetAttr(tstate, attr); + ferr = _PySys_GetAttr(tstate, _Py_ID(stderr)); if (ferr == NULL || ferr == Py_None) { /* sys.stderr is not set yet or set to None, no need to try to display the exception */ @@ -2542,8 +2530,7 @@ _Py_FatalError_PrintExc(PyThreadState *tstate) Py_XDECREF(tb); /* sys.stderr may be buffered: call sys.stderr.flush() */ - attr = _Py_ID(flush); - res = PyObject_CallMethodNoArgs(ferr, attr); + res = PyObject_CallMethodNoArgs(ferr, _Py_ID(flush)); if (res == NULL) { _PyErr_Clear(tstate); } @@ -2896,8 +2883,7 @@ static void wait_for_thread_shutdown(PyThreadState *tstate) { PyObject *result; - PyObject *name = _Py_ID(threading); - PyObject *threading = PyImport_GetModule(name); + PyObject *threading = PyImport_GetModule(_Py_ID(threading)); if (threading == NULL) { if (_PyErr_Occurred(tstate)) { PyErr_WriteUnraisable(NULL); @@ -2905,8 +2891,7 @@ wait_for_thread_shutdown(PyThreadState *tstate) /* else: threading not imported */ return; } - name = _Py_ID(_shutdown); - result = PyObject_CallMethodNoArgs(threading, name); + result = PyObject_CallMethodNoArgs(threading, _Py_ID(_shutdown)); if (result == NULL) { PyErr_WriteUnraisable(threading); } diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 75a3e7502675436..91053dbcdf13fe5 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -117,16 +117,14 @@ _PyRun_InteractiveLoopObject(FILE *fp, PyObject *filename, PyCompilerFlags *flag } PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_ID(ps1); - PyObject *v = _PySys_GetAttr(tstate, attr); + PyObject *v = _PySys_GetAttr(tstate, _Py_ID(ps1)); if (v == NULL) { - _PySys_SetAttr(attr, v = PyUnicode_FromString(">>> ")); + _PySys_SetAttr(_Py_ID(ps1), v = PyUnicode_FromString(">>> ")); Py_XDECREF(v); } - attr = _Py_ID(ps2); - v = _PySys_GetAttr(tstate, attr); + v = _PySys_GetAttr(tstate, _Py_ID(ps2)); if (v == NULL) { - _PySys_SetAttr(attr, v = PyUnicode_FromString("... ")); + _PySys_SetAttr(_Py_ID(ps2), v = PyUnicode_FromString("... ")); Py_XDECREF(v); } @@ -188,29 +186,25 @@ static int PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, PyCompilerFlags *flags) { - PyObject *m, *d, *v, *w, *oenc = NULL, *mod_name, *attr; + PyObject *m, *d, *v, *w, *oenc = NULL; mod_ty mod; PyArena *arena; const char *ps1 = "", *ps2 = "", *enc = NULL; int errcode = 0; PyThreadState *tstate = _PyThreadState_GET(); - mod_name = _Py_ID(__main__); if (fp == stdin) { /* Fetch encoding from sys.stdin if possible. */ - attr = _Py_ID(stdin); - v = _PySys_GetAttr(tstate, attr); + v = _PySys_GetAttr(tstate, _Py_ID(stdin)); if (v && v != Py_None) { - attr = _Py_ID(encoding); - oenc = PyObject_GetAttr(v, attr); + oenc = PyObject_GetAttr(v, _Py_ID(encoding)); if (oenc) enc = PyUnicode_AsUTF8(oenc); if (!enc) PyErr_Clear(); } } - attr = _Py_ID(ps1); - v = _PySys_GetAttr(tstate, attr); + v = _PySys_GetAttr(tstate, _Py_ID(ps1)); if (v != NULL) { v = PyObject_Str(v); if (v == NULL) @@ -223,8 +217,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, } } } - attr = _Py_ID(ps2); - w = _PySys_GetAttr(tstate, attr); + w = _PySys_GetAttr(tstate, _Py_ID(ps2)); if (w != NULL) { w = PyObject_Str(w); if (w == NULL) @@ -259,7 +252,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, } return -1; } - m = PyImport_AddModuleObject(mod_name); + m = PyImport_AddModuleObject(_Py_ID(__main__)); if (m == NULL) { _PyArena_Free(arena); return -1; @@ -507,19 +500,17 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, PyObject **text) { Py_ssize_t hold; - PyObject *v, *attr; + PyObject *v; *message = NULL; *filename = NULL; /* new style errors. `err' is an instance */ - attr = _Py_ID(msg); - *message = PyObject_GetAttr(err, attr); + *message = PyObject_GetAttr(err, _Py_ID(msg)); if (!*message) goto finally; - attr = _Py_ID(filename); - v = PyObject_GetAttr(err, attr); + v = PyObject_GetAttr(err, _Py_ID(filename)); if (!v) goto finally; if (v == Py_None) { @@ -531,8 +522,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *filename = v; } - attr = _Py_ID(lineno); - v = PyObject_GetAttr(err, attr); + v = PyObject_GetAttr(err, _Py_ID(lineno)); if (!v) goto finally; hold = PyLong_AsSsize_t(v); @@ -541,8 +531,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, goto finally; *lineno = hold; - attr = _Py_ID(offset); - v = PyObject_GetAttr(err, attr); + v = PyObject_GetAttr(err, _Py_ID(offset)); if (!v) goto finally; if (v == Py_None) { @@ -557,8 +546,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, } if (Py_TYPE(err) == (PyTypeObject*)PyExc_SyntaxError) { - attr = _Py_ID(end_lineno); - v = PyObject_GetAttr(err, attr); + v = PyObject_GetAttr(err, _Py_ID(end_lineno)); if (!v) { PyErr_Clear(); *end_lineno = *lineno; @@ -574,8 +562,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *end_lineno = hold; } - attr = _Py_ID(end_offset); - v = PyObject_GetAttr(err, attr); + v = PyObject_GetAttr(err, _Py_ID(end_offset)); if (!v) { PyErr_Clear(); *end_offset = -1; @@ -596,8 +583,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *end_offset = -1; } - attr = _Py_ID(text); - v = PyObject_GetAttr(err, attr); + v = PyObject_GetAttr(err, _Py_ID(text)); if (!v) goto finally; if (v == Py_None) { @@ -731,8 +717,7 @@ _Py_HandleSystemExit(int *exitcode_p) if (PyExceptionInstance_Check(value)) { /* The error code should be in the `code' attribute. */ - PyObject *attr = _Py_ID(code); - PyObject *code = PyObject_GetAttr(value, attr); + PyObject *code = PyObject_GetAttr(value, _Py_ID(code)); if (code) { Py_DECREF(value); value = code; @@ -748,8 +733,7 @@ _Py_HandleSystemExit(int *exitcode_p) } else { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_ID(stderr); - PyObject *sys_stderr = _PySys_GetAttr(tstate, attr); + PyObject *sys_stderr = _PySys_GetAttr(tstate, _Py_ID(stderr)); /* We clear the exception here to avoid triggering the assertion * in PyObject_Str that ensures it won't silently lose exception * details. @@ -791,7 +775,7 @@ handle_system_exit(void) static void _PyErr_PrintEx(PyThreadState *tstate, int set_sys_last_vars) { - PyObject *exception, *v, *tb, *hook, *attr; + PyObject *exception, *v, *tb, *hook; handle_system_exit(); @@ -812,21 +796,17 @@ _PyErr_PrintEx(PyThreadState *tstate, int set_sys_last_vars) /* Now we know v != NULL too */ if (set_sys_last_vars) { - attr = _Py_ID(last_type); - if (_PySys_SetAttr(attr, exception) < 0) { + if (_PySys_SetAttr(_Py_ID(last_type), exception) < 0) { _PyErr_Clear(tstate); } - attr = _Py_ID(last_value); - if (_PySys_SetAttr(attr, v) < 0) { + if (_PySys_SetAttr(_Py_ID(last_value), v) < 0) { _PyErr_Clear(tstate); } - attr = _Py_ID(last_traceback); - if (_PySys_SetAttr(attr, tb) < 0) { + if (_PySys_SetAttr(_Py_ID(last_traceback), tb) < 0) { _PyErr_Clear(tstate); } } - attr = _Py_ID(excepthook); - hook = _PySys_GetAttr(tstate, attr); + hook = _PySys_GetAttr(tstate, _Py_ID(excepthook)); if (_PySys_Audit(tstate, "sys.excepthook", "OOOO", hook ? hook : Py_None, exception, v, tb) < 0) { if (PyErr_ExceptionMatches(PyExc_RuntimeError)) { @@ -972,8 +952,7 @@ print_exception_file_and_line(struct exception_print_context *ctx, PyObject *f = ctx->file; PyObject *tmp; - PyObject *attr = _Py_ID(print_file_and_line); - int res = _PyObject_LookupAttr(*value_p, attr, &tmp); + int res = _PyObject_LookupAttr(*value_p, _Py_ID(print_file_and_line), &tmp); if (res <= 0) { if (res < 0) { PyErr_Clear(); @@ -1048,8 +1027,7 @@ print_exception_message(struct exception_print_context *ctx, PyObject *type, if (write_indented_margin(ctx, f) < 0) { return -1; } - PyObject *attr = _Py_ID(__module__); - PyObject *modulename = PyObject_GetAttr(type, attr); + PyObject *modulename = PyObject_GetAttr(type, _Py_ID(__module__)); if (modulename == NULL || !PyUnicode_Check(modulename)) { Py_XDECREF(modulename); PyErr_Clear(); @@ -1159,8 +1137,7 @@ print_exception_note(struct exception_print_context *ctx, PyObject *value) return 0; } - PyObject *attr = _Py_ID(__note__); - PyObject *note = PyObject_GetAttr(value, attr); + PyObject *note = PyObject_GetAttr(value, _Py_ID(__note__)); if (note == NULL) { return -1; } @@ -1545,8 +1522,7 @@ _PyErr_Display(PyObject *file, PyObject *exception, PyObject *value, PyObject *t Py_XDECREF(ctx.seen); /* Call file.flush() */ - PyObject *attr = _Py_ID(flush); - PyObject *res = _PyObject_CallMethodNoArgs(file, attr); + PyObject *res = _PyObject_CallMethodNoArgs(file, _Py_ID(flush)); if (!res) { /* Silently ignore file.flush() error */ PyErr_Clear(); @@ -1560,8 +1536,7 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_ID(stderr); - PyObject *file = _PySys_GetAttr(tstate, attr); + PyObject *file = _PySys_GetAttr(tstate, _Py_ID(stderr)); if (file == NULL) { _PyObject_Dump(value); fprintf(stderr, "lost sys.stderr\n"); @@ -1649,25 +1624,22 @@ flush_io(void) { PyObject *f, *r; PyObject *type, *value, *traceback; - PyObject *flush = _Py_ID(flush); /* Save the current exception */ PyErr_Fetch(&type, &value, &traceback); PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_ID(stderr); - f = _PySys_GetAttr(tstate, attr); + f = _PySys_GetAttr(tstate, _Py_ID(stderr)); if (f != NULL) { - r = _PyObject_CallMethodNoArgs(f, flush); + r = _PyObject_CallMethodNoArgs(f, _Py_ID(flush)); if (r) Py_DECREF(r); else PyErr_Clear(); } - attr = _Py_ID(stdout); - f = _PySys_GetAttr(tstate, attr); + f = _PySys_GetAttr(tstate, _Py_ID(stdout)); if (f != NULL) { - r = _PyObject_CallMethodNoArgs(f, flush); + r = _PyObject_CallMethodNoArgs(f, _Py_ID(flush)); if (r) Py_DECREF(r); else diff --git a/Python/specialize.c b/Python/specialize.c index 34e2b6b6116a0ac..fd475e9f3ed4f3c 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -565,8 +565,8 @@ specialize_module_load_attr( SPECIALIZATION_FAIL(opcode, SPEC_FAIL_NON_STRING_OR_SPLIT); return -1; } - PyObject *getattr = _Py_ID(__getattr__); - Py_ssize_t index = _PyDict_GetItemHint(dict, getattr, -1, &value); + Py_ssize_t index = _PyDict_GetItemHint(dict, _Py_ID(__getattr__), -1, + &value); assert(index != DKIX_ERROR); if (index != DKIX_EMPTY) { SPECIALIZATION_FAIL(opcode, SPEC_FAIL_MODULE_ATTR_NOT_FOUND); @@ -1209,8 +1209,7 @@ _Py_Specialize_BinarySubscr( goto success; } PyTypeObject *cls = Py_TYPE(container); - PyObject *getitem = _Py_ID(__getitem__); - PyObject *descriptor = _PyType_Lookup(cls, getitem); + PyObject *descriptor = _PyType_Lookup(cls, _Py_ID(__getitem__)); if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) { PyFunctionObject *func = (PyFunctionObject *)descriptor; PyCodeObject *code = (PyCodeObject *)func->func_code; @@ -1327,8 +1326,7 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins } goto fail; } - PyObject *setitem = _Py_ID(__setitem__); - PyObject *descriptor = _PyType_Lookup(container_type, setitem); + PyObject *descriptor = _PyType_Lookup(container_type, _Py_ID(__setitem__)); if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) { PyFunctionObject *func = (PyFunctionObject *)descriptor; PyCodeObject *code = (PyCodeObject *)func->func_code; @@ -1427,8 +1425,8 @@ specialize_method_descriptor( return -1; } if (_list_append == NULL) { - PyObject *append = _Py_ID(append); - _list_append = (PyMethodDescrObject *)_PyType_Lookup(&PyList_Type, append); + _list_append = (PyMethodDescrObject *)_PyType_Lookup(&PyList_Type, + _Py_ID(append)); } assert(_list_append != NULL); if (nargs == 2 && descr == _list_append) { diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 2910ae633c6cf01..4e5a333c53a040c 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -268,10 +268,9 @@ sys_audit_tstate(PyThreadState *ts, const char *event, /* Disallow tracing in hooks unless explicitly enabled */ PyThreadState_EnterTracing(ts); - PyObject *attr = _Py_ID(__cantrace__); while ((hook = PyIter_Next(hooks)) != NULL) { PyObject *o; - int canTrace = _PyObject_LookupAttr(hook, attr, &o); + int canTrace = _PyObject_LookupAttr(hook, _Py_ID(__cantrace__), &o); if (o) { canTrace = PyObject_IsTrue(o); Py_DECREF(o); @@ -642,8 +641,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) const char *stdout_encoding_str; int ret; - PyObject *attr = _Py_ID(encoding); - stdout_encoding = PyObject_GetAttr(outf, attr); + stdout_encoding = PyObject_GetAttr(outf, _Py_ID(encoding)); if (stdout_encoding == NULL) goto error; stdout_encoding_str = PyUnicode_AsUTF8(stdout_encoding); @@ -660,14 +658,12 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) if (encoded == NULL) goto error; - attr = _Py_ID(buffer); - if (_PyObject_LookupAttr(outf, attr, &buffer) < 0) { + if (_PyObject_LookupAttr(outf, _Py_ID(buffer), &buffer) < 0) { Py_DECREF(encoded); goto error; } if (buffer) { - attr = _Py_ID(write); - result = PyObject_CallMethodOneArg(buffer, attr, encoded); + result = PyObject_CallMethodOneArg(buffer, _Py_ID(write), encoded); Py_DECREF(buffer); Py_DECREF(encoded); if (result == NULL) @@ -713,8 +709,7 @@ sys_displayhook(PyObject *module, PyObject *o) static PyObject *newline = NULL; PyThreadState *tstate = _PyThreadState_GET(); - PyObject *str = _Py_ID(builtins); - builtins = PyImport_GetModule(str); + builtins = PyImport_GetModule(_Py_ID(builtins)); if (builtins == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_RuntimeError, @@ -730,8 +725,7 @@ sys_displayhook(PyObject *module, PyObject *o) if (o == Py_None) { Py_RETURN_NONE; } - str = _Py_ID(_); - if (PyObject_SetAttr(builtins, str, Py_None) != 0) + if (PyObject_SetAttr(builtins, _Py_ID(_), Py_None) != 0) return NULL; outf = _PySys_GetAttr(tstate, _Py_ID(stdout)); if (outf == NULL || outf == Py_None) { @@ -760,7 +754,7 @@ sys_displayhook(PyObject *module, PyObject *o) } if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0) return NULL; - if (PyObject_SetAttr(builtins, str, o) != 0) + if (PyObject_SetAttr(builtins, _Py_ID(_), o) != 0) return NULL; Py_RETURN_NONE; } @@ -1692,8 +1686,7 @@ _PySys_GetSizeOf(PyObject *o) return (size_t)-1; } - PyObject *str = _Py_ID(__sizeof__); - method = _PyObject_LookupSpecial(o, str); + method = _PyObject_LookupSpecial(o, _Py_ID(__sizeof__)); if (method == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -2235,8 +2228,7 @@ _PySys_ReadPreinitXOptions(PyConfig *config) static PyObject * get_warnoptions(PyThreadState *tstate) { - PyObject *str = _Py_ID(warnoptions); - PyObject *warnoptions = _PySys_GetAttr(tstate, str); + PyObject *warnoptions = _PySys_GetAttr(tstate, _Py_ID(warnoptions)); if (warnoptions == NULL || !PyList_Check(warnoptions)) { /* PEP432 TODO: we can reach this if warnoptions is NULL in the main * interpreter config. When that happens, we need to properly set @@ -2252,7 +2244,7 @@ get_warnoptions(PyThreadState *tstate) if (warnoptions == NULL) { return NULL; } - if (sys_set_object(tstate->interp, str, warnoptions)) { + if (sys_set_object(tstate->interp, _Py_ID(warnoptions), warnoptions)) { Py_DECREF(warnoptions); return NULL; } @@ -2270,8 +2262,7 @@ PySys_ResetWarnOptions(void) return; } - PyObject *str = _Py_ID(warnoptions); - PyObject *warnoptions = _PySys_GetAttr(tstate, str); + PyObject *warnoptions = _PySys_GetAttr(tstate, _Py_ID(warnoptions)); if (warnoptions == NULL || !PyList_Check(warnoptions)) return; PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL); @@ -2325,8 +2316,7 @@ int PySys_HasWarnOptions(void) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *str = _Py_ID(warnoptions); - PyObject *warnoptions = _PySys_GetAttr(tstate, str); + PyObject *warnoptions = _PySys_GetAttr(tstate, _Py_ID(warnoptions)); return (warnoptions != NULL && PyList_Check(warnoptions) && PyList_GET_SIZE(warnoptions) > 0); } @@ -2334,8 +2324,7 @@ PySys_HasWarnOptions(void) static PyObject * get_xoptions(PyThreadState *tstate) { - PyObject *str = _Py_ID(_xoptions); - PyObject *xoptions = _PySys_GetAttr(tstate, str); + PyObject *xoptions = _PySys_GetAttr(tstate, _Py_ID(_xoptions)); if (xoptions == NULL || !PyDict_Check(xoptions)) { /* PEP432 TODO: we can reach this if xoptions is NULL in the main * interpreter config. When that happens, we need to properly set @@ -2351,7 +2340,7 @@ get_xoptions(PyThreadState *tstate) if (xoptions == NULL) { return NULL; } - if (sys_set_object(tstate->interp, str, xoptions)) { + if (sys_set_object(tstate->interp, _Py_ID(_xoptions), xoptions)) { Py_DECREF(xoptions); return NULL; } @@ -3053,8 +3042,7 @@ _PySys_SetPreliminaryStderr(PyObject *sysdict) if (pstderr == NULL) { goto error; } - PyObject *str = _Py_ID(stderr); - if (PyDict_SetItem(sysdict, str, pstderr) < 0) { + if (PyDict_SetItem(sysdict, _Py_ID(stderr), pstderr) < 0) { goto error; } if (PyDict_SetItemString(sysdict, "__stderr__", pstderr) < 0) { @@ -3179,8 +3167,7 @@ PySys_SetPath(const wchar_t *path) if ((v = makepathobject(path, DELIM)) == NULL) Py_FatalError("can't create sys.path"); PyInterpreterState *interp = _PyInterpreterState_GET(); - PyObject *str = _Py_ID(path); - if (sys_set_object(interp, str, v) != 0) { + if (sys_set_object(interp, _Py_ID(path), v) != 0) { Py_FatalError("can't assign sys.path"); } Py_DECREF(v); @@ -3237,8 +3224,7 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) Py_FatalError("can't compute path0 from argv"); } - PyObject *str = _Py_ID(path); - PyObject *sys_path = _PySys_GetAttr(tstate, str); + PyObject *sys_path = _PySys_GetAttr(tstate, _Py_ID(path)); if (sys_path != NULL) { if (PyList_Insert(sys_path, 0, path0) < 0) { Py_DECREF(path0); @@ -3265,8 +3251,7 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) if (file == NULL) return -1; assert(unicode != NULL); - PyObject *str = _Py_ID(write); - PyObject *result = _PyObject_CallMethodOneArg(file, str, unicode); + PyObject *result = _PyObject_CallMethodOneArg(file, _Py_ID(write), unicode); if (result == NULL) { return -1; } @@ -3350,8 +3335,7 @@ PySys_WriteStdout(const char *format, ...) va_list va; va_start(va, format); - PyObject *str = _Py_ID(stdout); - sys_write(str, stdout, format, va); + sys_write(_Py_ID(stdout), stdout, format, va); va_end(va); } @@ -3361,8 +3345,7 @@ PySys_WriteStderr(const char *format, ...) va_list va; va_start(va, format); - PyObject *str = _Py_ID(stderr); - sys_write(str, stderr, format, va); + sys_write(_Py_ID(stderr), stderr, format, va); va_end(va); } @@ -3395,8 +3378,7 @@ PySys_FormatStdout(const char *format, ...) va_list va; va_start(va, format); - PyObject *str = _Py_ID(stdout); - sys_format(str, stdout, format, va); + sys_format(_Py_ID(stdout), stdout, format, va); va_end(va); } @@ -3406,7 +3388,6 @@ PySys_FormatStderr(const char *format, ...) va_list va; va_start(va, format); - PyObject *str = _Py_ID(stderr); - sys_format(str, stderr, format, va); + sys_format(_Py_ID(stderr), stderr, format, va); va_end(va); } diff --git a/Python/traceback.c b/Python/traceback.c index ca928f024235c88..90d1d5e8ca9a971 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -331,8 +331,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * taillen = strlen(tail); PyThreadState *tstate = _PyThreadState_GET(); - PyObject *attr = _Py_ID(path); - syspath = _PySys_GetAttr(tstate, attr); + syspath = _PySys_GetAttr(tstate, _Py_ID(path)); if (syspath == NULL || !PyList_Check(syspath)) goto error; npath = PyList_Size(syspath); @@ -453,8 +452,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int return -1; } - PyObject *attr = _Py_ID(open); - binary = _PyObject_CallMethod(io, attr, "Os", filename, "rb"); + binary = _PyObject_CallMethod(io, _Py_ID(open), "Os", filename, "rb"); if (binary == NULL) { PyErr_Clear(); @@ -483,16 +481,15 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int PyMem_Free(found_encoding); return 0; } - attr = _Py_ID(TextIOWrapper); - fob = _PyObject_CallMethod(io, attr, "Os", binary, encoding); + fob = _PyObject_CallMethod(io, _Py_ID(TextIOWrapper), + "Os", binary, encoding); Py_DECREF(io); PyMem_Free(found_encoding); - PyObject *close = _Py_ID(close); if (fob == NULL) { PyErr_Clear(); - res = PyObject_CallMethodNoArgs(binary, close); + res = PyObject_CallMethodNoArgs(binary, _Py_ID(close)); Py_DECREF(binary); if (res) Py_DECREF(res); @@ -511,7 +508,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int break; } } - res = PyObject_CallMethodNoArgs(fob, close); + res = PyObject_CallMethodNoArgs(fob, _Py_ID(close)); if (res) { Py_DECREF(res); } From 6fdba801c316b79ab1f00201c1c42a326cdd5a46 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 15:28:43 -0700 Subject: [PATCH 112/115] Inline uses of _Py_STR(). --- Modules/_pickle.c | 3 +-- Objects/typeobject.c | 4 +--- Objects/unicodeobject.c | 3 +-- Python/ast_opt.c | 5 ++--- Python/compile.c | 31 ++++++++++++------------------- Python/pythonrun.c | 6 +++--- 6 files changed, 20 insertions(+), 32 deletions(-) diff --git a/Modules/_pickle.c b/Modules/_pickle.c index c01653d4f88c309..9fb61677a59f24d 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -1814,8 +1814,7 @@ get_dotted_path(PyObject *obj, PyObject *name) PyObject *dotted_path; Py_ssize_t i, n; - PyObject *dot = _Py_STR(dot); - dotted_path = PyUnicode_Split(name, dot, -1); + dotted_path = PyUnicode_Split(name, _Py_STR(dot), -1); if (dotted_path == NULL) return NULL; n = PyList_GET_SIZE(dotted_path); diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 124777862ad6560..589556a28dae35d 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4536,7 +4536,6 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyObject *abstract_methods; PyObject *sorted_methods; PyObject *joined; - PyObject *comma; Py_ssize_t method_count; /* Compute ", ".join(sorted(type.__abstractmethods__)) @@ -4552,8 +4551,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) Py_DECREF(sorted_methods); return NULL; } - comma = _Py_STR(comma_sep); - joined = PyUnicode_Join(comma, sorted_methods); + joined = PyUnicode_Join(_Py_STR(comma_sep), sorted_methods); method_count = PyObject_Length(sorted_methods); Py_DECREF(sorted_methods); if (joined == NULL) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index f15b33d8c4fdf28..527d5e5274e1472 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -15534,8 +15534,7 @@ _PyUnicode_InitGlobalObjects(PyInterpreterState *interp) } #ifdef Py_DEBUG - PyObject *empty = _Py_STR(empty); - assert(_PyUnicode_CheckConsistency(empty, 1)); + assert(_PyUnicode_CheckConsistency(_Py_STR(empty), 1)); #endif return _PyStatus_OK(); diff --git a/Python/ast_opt.c b/Python/ast_opt.c index 60b878a4d3395b6..fd28f5483453135 100644 --- a/Python/ast_opt.c +++ b/Python/ast_opt.c @@ -268,9 +268,8 @@ parse_literal(PyObject *fmt, Py_ssize_t *ppos, PyArena *arena) PyObject *str = PyUnicode_Substring(fmt, start, pos); /* str = str.replace('%%', '%') */ if (str && has_percents) { - PyObject *double_percent = _Py_STR(dbl_percent); - PyObject *percent = _Py_STR(percent); - Py_SETREF(str, PyUnicode_Replace(str, double_percent, percent, -1)); + Py_SETREF(str, PyUnicode_Replace(str, _Py_STR(dbl_percent), + _Py_STR(percent), -1)); } if (!str) { return NULL; diff --git a/Python/compile.c b/Python/compile.c index 9a540192477c5a1..f64adaeb77d994a 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -635,7 +635,7 @@ compiler_set_qualname(struct compiler *c) { Py_ssize_t stack_size; struct compiler_unit *u = c->u; - PyObject *name, *base, *dot_str, *dot_locals_str; + PyObject *name, *base; base = NULL; stack_size = PyList_GET_SIZE(c->c_stack); @@ -668,8 +668,8 @@ compiler_set_qualname(struct compiler *c) || parent->u_scope_type == COMPILER_SCOPE_ASYNC_FUNCTION || parent->u_scope_type == COMPILER_SCOPE_LAMBDA) { - dot_locals_str = _Py_STR(dot_locals); - base = PyUnicode_Concat(parent->u_qualname, dot_locals_str); + base = PyUnicode_Concat(parent->u_qualname, + _Py_STR(dot_locals)); if (base == NULL) return 0; } @@ -681,8 +681,7 @@ compiler_set_qualname(struct compiler *c) } if (base != NULL) { - dot_str = _Py_STR(dot); - name = PyUnicode_Concat(base, dot_str); + name = PyUnicode_Concat(base, _Py_STR(dot)); Py_DECREF(base); if (name == NULL) return 0; @@ -2036,8 +2035,8 @@ compiler_mod(struct compiler *c, mod_ty mod) { PyCodeObject *co; int addNone = 1; - PyObject *module = _Py_STR(anon_module); - if (!compiler_enter_scope(c, module, COMPILER_SCOPE_MODULE, mod, 1)) { + if (!compiler_enter_scope(c, _Py_STR(anon_module), COMPILER_SCOPE_MODULE, + mod, 1)) { return NULL; } c->u->u_lineno = 1; @@ -2890,8 +2889,7 @@ compiler_lambda(struct compiler *c, expr_ty e) return 0; } - identifier name = _Py_STR(anon_lambda); - if (!compiler_enter_scope(c, name, COMPILER_SCOPE_LAMBDA, + if (!compiler_enter_scope(c, _Py_STR(anon_lambda), COMPILER_SCOPE_LAMBDA, (void *)e, e->lineno)) { return 0; } @@ -3790,7 +3788,6 @@ compiler_from_import(struct compiler *c, stmt_ty s) { Py_ssize_t i, n = asdl_seq_LEN(s->v.ImportFrom.names); PyObject *names; - PyObject *empty_string = _Py_STR(empty); ADDOP_LOAD_CONST_NEW(c, PyLong_FromLong(s->v.ImportFrom.level)); @@ -3817,7 +3814,7 @@ compiler_from_import(struct compiler *c, stmt_ty s) ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names); } else { - ADDOP_NAME(c, IMPORT_NAME, empty_string, names); + ADDOP_NAME(c, IMPORT_NAME, _Py_STR(empty), names); } for (i = 0; i < n; i++) { alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i); @@ -5365,9 +5362,8 @@ compiler_comprehension(struct compiler *c, expr_ty e, int type, static int compiler_genexp(struct compiler *c, expr_ty e) { - identifier name = _Py_STR(anon_genexpr); assert(e->kind == GeneratorExp_kind); - return compiler_comprehension(c, e, COMP_GENEXP, name, + return compiler_comprehension(c, e, COMP_GENEXP, _Py_STR(anon_genexpr), e->v.GeneratorExp.generators, e->v.GeneratorExp.elt, NULL); } @@ -5375,9 +5371,8 @@ compiler_genexp(struct compiler *c, expr_ty e) static int compiler_listcomp(struct compiler *c, expr_ty e) { - identifier name = _Py_STR(anon_listcomp); assert(e->kind == ListComp_kind); - return compiler_comprehension(c, e, COMP_LISTCOMP, name, + return compiler_comprehension(c, e, COMP_LISTCOMP, _Py_STR(anon_listcomp), e->v.ListComp.generators, e->v.ListComp.elt, NULL); } @@ -5385,9 +5380,8 @@ compiler_listcomp(struct compiler *c, expr_ty e) static int compiler_setcomp(struct compiler *c, expr_ty e) { - identifier name = _Py_STR(anon_setcomp); assert(e->kind == SetComp_kind); - return compiler_comprehension(c, e, COMP_SETCOMP, name, + return compiler_comprehension(c, e, COMP_SETCOMP, _Py_STR(anon_setcomp), e->v.SetComp.generators, e->v.SetComp.elt, NULL); } @@ -5396,9 +5390,8 @@ compiler_setcomp(struct compiler *c, expr_ty e) static int compiler_dictcomp(struct compiler *c, expr_ty e) { - identifier name = _Py_STR(anon_dictcomp); assert(e->kind == DictComp_kind); - return compiler_comprehension(c, e, COMP_DICTCOMP, name, + return compiler_comprehension(c, e, COMP_DICTCOMP, _Py_STR(anon_dictcomp), e->v.DictComp.generators, e->v.DictComp.key, e->v.DictComp.value); } diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 91053dbcdf13fe5..f9a692dd385bbc9 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1557,16 +1557,16 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals, PyObject *ret = NULL; mod_ty mod; PyArena *arena; - PyObject *filename = _Py_STR(anon_string); arena = _PyArena_New(); if (arena == NULL) return NULL; - mod = _PyParser_ASTFromString(str, filename, start, flags, arena); + mod = _PyParser_ASTFromString( + str, _Py_STR(anon_string), start, flags, arena); if (mod != NULL) - ret = run_mod(mod, filename, globals, locals, flags, arena); + ret = run_mod(mod, _Py_STR(anon_string), globals, locals, flags, arena); _PyArena_Free(arena); return ret; } From 4e00c8701d52f44864b285b129ed511ff241c71c Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 15:33:07 -0700 Subject: [PATCH 113/115] Drop _PyObject_IsSingleton(). (C99 undefined makes it too tricky.) --- Include/internal/pycore_object.h | 20 -------------------- Objects/unicodeobject.c | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 14f20eb2f1ac247..46b9d7828c8f620 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -27,26 +27,6 @@ extern "C" { } -static inline bool _PyObject_IsSingleton(PyObject *obj) -{ - /* The _PyRuntimeState global objects are all singletons so we can - check if the object is in the address range of the relevant - substruct. Per the C99 spec (6.5.8 and 7.18.1.4), this is safe - only if we convert to void* and then uint64_t before comparing. - For that conversion we rely on the same uniqueness guarantees - that the builtin id() does. - */ - if (((uintptr_t)(void *)obj >= - (uintptr_t)(void *)(&_PyRuntime.global_objects.singletons)) && - ((uintptr_t)(void *)obj < - (uintptr_t)(void *)((&_PyRuntime.global_objects.singletons) + 1))) - { - return true; - } - return false; -} - - PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type); PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content); diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 527d5e5274e1472..cf43d9ba9199f14 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -1986,7 +1986,7 @@ unicode_dealloc(PyObject *unicode) static int unicode_is_singleton(PyObject *unicode) { - if (_PyObject_IsSingleton(unicode)) { + if (unicode == _Py_STR(empty)) { return 1; } From fbe8f4ac22eea8191069f4277ebcb23cdb9ca51a Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 15:41:45 -0700 Subject: [PATCH 114/115] Drop address-taking from _PY_ID() and _Py_STR(). --- Include/internal/pycore_global_strings.h | 4 +- Modules/_abc.c | 26 +-- Modules/_collectionsmodule.c | 14 +- Modules/_io/_iomodule.c | 8 +- Modules/_io/bufferedio.c | 38 ++-- Modules/_io/fileio.c | 6 +- Modules/_io/iobase.c | 16 +- Modules/_io/textio.c | 76 +++---- Modules/_io/winconsoleio.c | 4 +- Modules/_operator.c | 2 +- Modules/_pickle.c | 66 +++--- Modules/_threadmodule.c | 10 +- Modules/faulthandler.c | 8 +- Modules/itertoolsmodule.c | 10 +- Modules/main.c | 2 +- Modules/posixmodule.c | 4 +- Modules/timemodule.c | 2 +- Objects/abstract.c | 26 +-- Objects/bytearrayobject.c | 6 +- Objects/bytesobject.c | 8 +- Objects/classobject.c | 10 +- Objects/complexobject.c | 2 +- Objects/descrobject.c | 22 +- Objects/dictobject.c | 14 +- Objects/enumobject.c | 2 +- Objects/exceptions.c | 4 +- Objects/fileobject.c | 12 +- Objects/frameobject.c | 2 +- Objects/funcobject.c | 4 +- Objects/genericaliasobject.c | 12 +- Objects/genobject.c | 4 +- Objects/iterobject.c | 8 +- Objects/listobject.c | 6 +- Objects/longobject.c | 8 +- Objects/methodobject.c | 4 +- Objects/moduleobject.c | 46 ++--- Objects/object.c | 22 +- Objects/odictobject.c | 12 +- Objects/rangeobject.c | 4 +- Objects/setobject.c | 4 +- Objects/structseq.c | 6 +- Objects/tupleobject.c | 4 +- Objects/typeobject.c | 244 +++++++++++------------ Objects/unicodeobject.c | 10 +- Objects/unionobject.c | 8 +- Objects/weakrefobject.c | 4 +- Parser/tokenizer.c | 4 +- Python/_warnings.c | 30 +-- Python/ast_opt.c | 4 +- Python/bltinmodule.c | 50 ++--- Python/ceval.c | 42 ++-- Python/codecs.c | 2 +- Python/compile.c | 26 +-- Python/errors.c | 36 ++-- Python/import.c | 46 ++--- Python/importdl.c | 2 +- Python/marshal.c | 6 +- Python/pylifecycle.c | 36 ++-- Python/pythonrun.c | 72 +++---- Python/specialize.c | 8 +- Python/sysmodule.c | 46 ++--- Python/traceback.c | 12 +- 62 files changed, 618 insertions(+), 618 deletions(-) diff --git a/Include/internal/pycore_global_strings.h b/Include/internal/pycore_global_strings.h index ba1dd74bc859bf0..17241b3a3dd1666 100644 --- a/Include/internal/pycore_global_strings.h +++ b/Include/internal/pycore_global_strings.h @@ -326,9 +326,9 @@ struct _Py_global_strings { #define _Py_ID(NAME) \ - (&_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base)) + (_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base)) #define _Py_STR(NAME) \ - (&_Py_SINGLETON(strings.literals._ ## NAME._ascii.ob_base)) + (_Py_SINGLETON(strings.literals._ ## NAME._ascii.ob_base)) #ifdef __cplusplus diff --git a/Modules/_abc.c b/Modules/_abc.c index aaa5c2358b69e03..641d6198d1fec43 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -114,7 +114,7 @@ static _abc_data * _get_impl(PyObject *module, PyObject *self) { _abcmodule_state *state = get_abc_state(module); - PyObject *impl = PyObject_GetAttr(self, _Py_ID(_abc_impl)); + PyObject *impl = PyObject_GetAttr(self, &_Py_ID(_abc_impl)); if (impl == NULL) { return NULL; } @@ -303,7 +303,7 @@ compute_abstract_methods(PyObject *self) PyObject *ns = NULL, *items = NULL, *bases = NULL; // Py_XDECREF()ed on error. /* Stage 1: direct abstract methods. */ - ns = PyObject_GetAttr(self, _Py_ID(__dict__)); + ns = PyObject_GetAttr(self, &_Py_ID(__dict__)); if (!ns) { goto error; } @@ -347,7 +347,7 @@ compute_abstract_methods(PyObject *self) } /* Stage 2: inherited abstract methods. */ - bases = PyObject_GetAttr(self, _Py_ID(__bases__)); + bases = PyObject_GetAttr(self, &_Py_ID(__bases__)); if (!bases) { goto error; } @@ -360,7 +360,7 @@ compute_abstract_methods(PyObject *self) PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed PyObject *base_abstracts, *iter; - if (_PyObject_LookupAttr(item, _Py_ID(__abstractmethods__), + if (_PyObject_LookupAttr(item, &_Py_ID(__abstractmethods__), &base_abstracts) < 0) { goto error; } @@ -401,7 +401,7 @@ compute_abstract_methods(PyObject *self) } } - if (PyObject_SetAttr(self, _Py_ID(__abstractmethods__), abstracts) < 0) { + if (PyObject_SetAttr(self, &_Py_ID(__abstractmethods__), abstracts) < 0) { goto error; } @@ -440,7 +440,7 @@ _abc__abc_init(PyObject *module, PyObject *self) if (data == NULL) { return NULL; } - if (PyObject_SetAttr(self, _Py_ID(_abc_impl), data) < 0) { + if (PyObject_SetAttr(self, &_Py_ID(_abc_impl), data) < 0) { Py_DECREF(data); return NULL; } @@ -452,7 +452,7 @@ _abc__abc_init(PyObject *module, PyObject *self) if (PyType_Check(self)) { PyTypeObject *cls = (PyTypeObject *)self; PyObject *flags = PyDict_GetItemWithError(cls->tp_dict, - _Py_ID(__abc_tpflags__)); + &_Py_ID(__abc_tpflags__)); if (flags == NULL) { if (PyErr_Occurred()) { return NULL; @@ -470,7 +470,7 @@ _abc__abc_init(PyObject *module, PyObject *self) } ((PyTypeObject *)self)->tp_flags |= (val & COLLECTION_FLAGS); } - if (PyDict_DelItem(cls->tp_dict, _Py_ID(__abc_tpflags__)) < 0) { + if (PyDict_DelItem(cls->tp_dict, &_Py_ID(__abc_tpflags__)) < 0) { return NULL; } } @@ -586,7 +586,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, return NULL; } - subclass = PyObject_GetAttr(instance, _Py_ID(__class__)); + subclass = PyObject_GetAttr(instance, &_Py_ID(__class__)); if (subclass == NULL) { Py_DECREF(impl); return NULL; @@ -615,11 +615,11 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, } } /* Fall back to the subclass check. */ - result = PyObject_CallMethodOneArg(self, _Py_ID(__subclasscheck__), + result = PyObject_CallMethodOneArg(self, &_Py_ID(__subclasscheck__), subclass); goto end; } - result = PyObject_CallMethodOneArg(self, _Py_ID(__subclasscheck__), + result = PyObject_CallMethodOneArg(self, &_Py_ID(__subclasscheck__), subclass); if (result == NULL) { goto end; @@ -632,7 +632,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self, break; case 0: Py_DECREF(result); - result = PyObject_CallMethodOneArg(self, _Py_ID(__subclasscheck__), + result = PyObject_CallMethodOneArg(self, &_Py_ID(__subclasscheck__), subtype); break; case 1: // Nothing to do. @@ -717,7 +717,7 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self, /* 3. Check the subclass hook. */ ok = PyObject_CallMethodOneArg( - (PyObject *)self, _Py_ID(__subclasshook__), subclass); + (PyObject *)self, &_Py_ID(__subclasshook__), subclass); if (ok == NULL) { goto end; } diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 9df7ac48af3ce34..e7bd8bc15122f50 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1349,7 +1349,7 @@ deque_reduce(dequeobject *deque, PyObject *Py_UNUSED(ignored)) { PyObject *dict, *it; - if (_PyObject_LookupAttr((PyObject *)deque, _Py_ID(__dict__), &dict) < 0) { + if (_PyObject_LookupAttr((PyObject *)deque, &_Py_ID(__dict__), &dict) < 0) { return NULL; } if (dict == NULL) { @@ -2070,7 +2070,7 @@ defdict_reduce(defdictobject *dd, PyObject *Py_UNUSED(ignored)) args = PyTuple_Pack(1, dd->default_factory); if (args == NULL) return NULL; - items = PyObject_CallMethodNoArgs((PyObject *)dd, _Py_ID(items)); + items = PyObject_CallMethodNoArgs((PyObject *)dd, &_Py_ID(items)); if (items == NULL) { Py_DECREF(args); return NULL; @@ -2325,10 +2325,10 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping, /* Only take the fast path when get() and __setitem__() * have not been overridden. */ - mapping_get = _PyType_Lookup(Py_TYPE(mapping), _Py_ID(get)); - dict_get = _PyType_Lookup(&PyDict_Type, _Py_ID(get)); - mapping_setitem = _PyType_Lookup(Py_TYPE(mapping), _Py_ID(__setitem__)); - dict_setitem = _PyType_Lookup(&PyDict_Type, _Py_ID(__setitem__)); + mapping_get = _PyType_Lookup(Py_TYPE(mapping), &_Py_ID(get)); + dict_get = _PyType_Lookup(&PyDict_Type, &_Py_ID(get)); + mapping_setitem = _PyType_Lookup(Py_TYPE(mapping), &_Py_ID(__setitem__)); + dict_setitem = _PyType_Lookup(&PyDict_Type, &_Py_ID(__setitem__)); if (mapping_get != NULL && mapping_get == dict_get && mapping_setitem != NULL && mapping_setitem == dict_setitem && @@ -2377,7 +2377,7 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping, } } else { - bound_get = PyObject_GetAttr(mapping, _Py_ID(get)); + bound_get = PyObject_GetAttr(mapping, &_Py_ID(get)); if (bound_get == NULL) goto done; diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 30a3a876ed7d59a..9ecc6718cb1fd5d 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -376,7 +376,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, /* buffering */ if (buffering < 0) { - PyObject *res = PyObject_CallMethodNoArgs(raw, _Py_ID(isatty)); + PyObject *res = PyObject_CallMethodNoArgs(raw, &_Py_ID(isatty)); if (res == NULL) goto error; isatty = PyLong_AsLong(res); @@ -394,7 +394,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, if (buffering < 0) { PyObject *blksize_obj; - blksize_obj = PyObject_GetAttr(raw, _Py_ID(_blksize)); + blksize_obj = PyObject_GetAttr(raw, &_Py_ID(_blksize)); if (blksize_obj == NULL) goto error; buffering = PyLong_AsLong(blksize_obj); @@ -461,7 +461,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, result = wrapper; Py_DECREF(buffer); - if (PyObject_SetAttr(wrapper, _Py_ID(mode), modeobj) < 0) + if (PyObject_SetAttr(wrapper, &_Py_ID(mode), modeobj) < 0) goto error; Py_DECREF(modeobj); return result; @@ -470,7 +470,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, if (result != NULL) { PyObject *exc, *val, *tb, *close_result; PyErr_Fetch(&exc, &val, &tb); - close_result = PyObject_CallMethodNoArgs(result, _Py_ID(close)); + close_result = PyObject_CallMethodNoArgs(result, &_Py_ID(close)); _PyErr_ChainExceptions(exc, val, tb); Py_XDECREF(close_result); Py_DECREF(result); diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 71daf7e96c797fa..bb93ae361f89251 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -51,8 +51,8 @@ _bufferediobase_readinto_generic(PyObject *self, Py_buffer *buffer, char readint PyObject *data; PyObject *attr = readinto1 - ? _Py_ID(read1) - : _Py_ID(read); + ? &_Py_ID(read1) + : &_Py_ID(read); data = _PyObject_CallMethod(self, attr, "n", buffer->len); if (data == NULL) return NULL; @@ -422,7 +422,7 @@ buffered_dealloc_warn(buffered *self, PyObject *source) { if (self->ok && self->raw) { PyObject *r; - r = PyObject_CallMethodOneArg(self->raw, _Py_ID(_dealloc_warn), source); + r = PyObject_CallMethodOneArg(self->raw, &_Py_ID(_dealloc_warn), source); if (r) Py_DECREF(r); else @@ -568,14 +568,14 @@ static PyObject * buffered_name_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - return PyObject_GetAttr(self->raw, _Py_ID(name)); + return PyObject_GetAttr(self->raw, &_Py_ID(name)); } static PyObject * buffered_mode_get(buffered *self, void *context) { CHECK_INITIALIZED(self) - return PyObject_GetAttr(self->raw, _Py_ID(mode)); + return PyObject_GetAttr(self->raw, &_Py_ID(mode)); } /* Lower-level APIs */ @@ -1366,7 +1366,7 @@ buffered_repr(buffered *self) { PyObject *nameobj, *res; - if (_PyObject_LookupAttr((PyObject *) self, _Py_ID(name), &nameobj) < 0) { + if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) { if (!PyErr_ExceptionMatches(PyExc_ValueError)) { return NULL; } @@ -2161,67 +2161,67 @@ _forward_call(buffered *self, PyObject *name, PyObject *args) static PyObject * bufferedrwpair_read(rwpair *self, PyObject *args) { - return _forward_call(self->reader, _Py_ID(read), args); + return _forward_call(self->reader, &_Py_ID(read), args); } static PyObject * bufferedrwpair_peek(rwpair *self, PyObject *args) { - return _forward_call(self->reader, _Py_ID(peek), args); + return _forward_call(self->reader, &_Py_ID(peek), args); } static PyObject * bufferedrwpair_read1(rwpair *self, PyObject *args) { - return _forward_call(self->reader, _Py_ID(read1), args); + return _forward_call(self->reader, &_Py_ID(read1), args); } static PyObject * bufferedrwpair_readinto(rwpair *self, PyObject *args) { - return _forward_call(self->reader, _Py_ID(readinto), args); + return _forward_call(self->reader, &_Py_ID(readinto), args); } static PyObject * bufferedrwpair_readinto1(rwpair *self, PyObject *args) { - return _forward_call(self->reader, _Py_ID(readinto1), args); + return _forward_call(self->reader, &_Py_ID(readinto1), args); } static PyObject * bufferedrwpair_write(rwpair *self, PyObject *args) { - return _forward_call(self->writer, _Py_ID(write), args); + return _forward_call(self->writer, &_Py_ID(write), args); } static PyObject * bufferedrwpair_flush(rwpair *self, PyObject *Py_UNUSED(ignored)) { - return _forward_call(self->writer, _Py_ID(flush), NULL); + return _forward_call(self->writer, &_Py_ID(flush), NULL); } static PyObject * bufferedrwpair_readable(rwpair *self, PyObject *Py_UNUSED(ignored)) { - return _forward_call(self->reader, _Py_ID(readable), NULL); + return _forward_call(self->reader, &_Py_ID(readable), NULL); } static PyObject * bufferedrwpair_writable(rwpair *self, PyObject *Py_UNUSED(ignored)) { - return _forward_call(self->writer, _Py_ID(writable), NULL); + return _forward_call(self->writer, &_Py_ID(writable), NULL); } static PyObject * bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored)) { PyObject *exc = NULL, *val, *tb; - PyObject *ret = _forward_call(self->writer, _Py_ID(close), NULL); + PyObject *ret = _forward_call(self->writer, &_Py_ID(close), NULL); if (ret == NULL) PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(ret); - ret = _forward_call(self->reader, _Py_ID(close), NULL); + ret = _forward_call(self->reader, &_Py_ID(close), NULL); if (exc != NULL) { _PyErr_ChainExceptions(exc, val, tb); Py_CLEAR(ret); @@ -2232,7 +2232,7 @@ bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored)) static PyObject * bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored)) { - PyObject *ret = _forward_call(self->writer, _Py_ID(isatty), NULL); + PyObject *ret = _forward_call(self->writer, &_Py_ID(isatty), NULL); if (ret != Py_False) { /* either True or exception */ @@ -2240,7 +2240,7 @@ bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored)) } Py_DECREF(ret); - return _forward_call(self->reader, _Py_ID(isatty), NULL); + return _forward_call(self->reader, &_Py_ID(isatty), NULL); } static PyObject * diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 20270132c03b41e..8b1cff56d75fa33 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -145,7 +145,7 @@ _io_FileIO_close_impl(fileio *self) PyObject *exc, *val, *tb; int rc; res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type, - _Py_ID(close), (PyObject *)self); + &_Py_ID(close), (PyObject *)self); if (!self->closefd) { self->fd = -1; return res; @@ -473,7 +473,7 @@ _Py_COMP_DIAG_POP _setmode(self->fd, O_BINARY); #endif - if (PyObject_SetAttr((PyObject *)self, _Py_ID(name), nameobj) < 0) + if (PyObject_SetAttr((PyObject *)self, &_Py_ID(name), nameobj) < 0) goto error; if (self->appending) { @@ -1082,7 +1082,7 @@ fileio_repr(fileio *self) if (self->fd < 0) return PyUnicode_FromFormat("<_io.FileIO [closed]>"); - if (_PyObject_LookupAttr((PyObject *) self, _Py_ID(name), &nameobj) < 0) { + if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) { return NULL; } if (nameobj == NULL) { diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c index 593b6623d81f0b2..74663e007b1e5bf 100644 --- a/Modules/_io/iobase.c +++ b/Modules/_io/iobase.c @@ -111,7 +111,7 @@ static PyObject * _io__IOBase_tell_impl(PyObject *self) /*[clinic end generated code: output=89a1c0807935abe2 input=04e615fec128801f]*/ { - return _PyObject_CallMethod(self, _Py_ID(seek), "ii", 0, 1); + return _PyObject_CallMethod(self, &_Py_ID(seek), "ii", 0, 1); } PyDoc_STRVAR(iobase_truncate_doc, @@ -133,7 +133,7 @@ iobase_is_closed(PyObject *self) int ret; /* This gets the derived attribute, which is *not* __IOBase_closed in most cases! */ - ret = _PyObject_LookupAttr(self, _Py_ID(__IOBase_closed), &res); + ret = _PyObject_LookupAttr(self, &_Py_ID(__IOBase_closed), &res); Py_XDECREF(res); return ret; } @@ -234,7 +234,7 @@ _io__IOBase_close_impl(PyObject *self) res = PyObject_CallMethodNoArgs(self, _PyIO_str_flush); PyErr_Fetch(&exc, &val, &tb); - rc = PyObject_SetAttr(self, _Py_ID(__IOBase_closed), Py_True); + rc = PyObject_SetAttr(self, &_Py_ID(__IOBase_closed), Py_True); _PyErr_ChainExceptions(exc, val, tb); if (rc < 0) { Py_CLEAR(res); @@ -274,7 +274,7 @@ iobase_finalize(PyObject *self) if (closed == 0) { /* Signal close() that it was called as part of the object finalization process. */ - if (PyObject_SetAttr(self, _Py_ID(_finalizing), Py_True)) + if (PyObject_SetAttr(self, &_Py_ID(_finalizing), Py_True)) PyErr_Clear(); res = PyObject_CallMethodNoArgs((PyObject *)self, _PyIO_str_close); /* Silencing I/O errors is bad, but printing spurious tracebacks is @@ -591,7 +591,7 @@ _io__IOBase_readline_impl(PyObject *self, Py_ssize_t limit) Py_DECREF(readahead); } - b = _PyObject_CallMethod(self, _Py_ID(read), "n", nreadahead); + b = _PyObject_CallMethod(self, &_Py_ID(read), "n", nreadahead); if (b == NULL) { /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() when EINTR occurs so we needn't do it ourselves. */ @@ -691,7 +691,7 @@ _io__IOBase_readlines_impl(PyObject *self, Py_ssize_t hint) /* XXX special-casing this made sense in the Python version in order to remove the bytecode interpretation overhead, but it could probably be removed here. */ - PyObject *ret = PyObject_CallMethodObjArgs(result, _Py_ID(extend), + PyObject *ret = PyObject_CallMethodObjArgs(result, &_Py_ID(extend), self, NULL); if (ret == NULL) { goto error; @@ -911,7 +911,7 @@ _io__RawIOBase_read_impl(PyObject *self, Py_ssize_t n) PyObject *b, *res; if (n < 0) { - return PyObject_CallMethodNoArgs(self, _Py_ID(readall)); + return PyObject_CallMethodNoArgs(self, &_Py_ID(readall)); } /* TODO: allocate a bytes object directly instead and manually construct @@ -957,7 +957,7 @@ _io__RawIOBase_readall_impl(PyObject *self) return NULL; while (1) { - PyObject *data = _PyObject_CallMethod(self, _Py_ID(read), + PyObject *data = _PyObject_CallMethod(self, &_Py_ID(read), "i", DEFAULT_BUFFER_SIZE); if (!data) { /* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals() diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index abfa3837a28b6de..d5ceec7981f3a2d 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -235,7 +235,7 @@ _io_IncrementalNewlineDecoder___init___impl(nldecoder_object *self, Py_INCREF(decoder); if (errors == NULL) { - self->errors = _Py_ID(strict); + self->errors = &_Py_ID(strict); } else { self->errors = errors; @@ -565,7 +565,7 @@ _io_IncrementalNewlineDecoder_setstate(nldecoder_object *self, flag >>= 1; if (self->decoder != Py_None) { - return _PyObject_CallMethod(self->decoder, _Py_ID(setstate), + return _PyObject_CallMethod(self->decoder, &_Py_ID(setstate), "((OK))", buffer, flag); } else { @@ -845,7 +845,7 @@ _textiowrapper_set_decoder(textio *self, PyObject *codec_info, PyObject *res; int r; - res = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(readable)); + res = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(readable)); if (res == NULL) return -1; @@ -900,7 +900,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info, PyObject *res; int r; - res = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(writable)); + res = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(writable)); if (res == NULL) return -1; @@ -919,7 +919,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info, return -1; /* Get the normalized named of the codec */ - if (_PyObject_LookupAttr(codec_info, _Py_ID(name), &res) < 0) { + if (_PyObject_LookupAttr(codec_info, &_Py_ID(name), &res) < 0) { return -1; } if (res != NULL && PyUnicode_Check(res)) { @@ -1079,7 +1079,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, } if (errors == Py_None) { - errors = _Py_ID(strict); + errors = &_Py_ID(strict); } else if (!PyUnicode_Check(errors)) { // Check 'errors' argument here because Argument Clinic doesn't support @@ -1119,7 +1119,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, state = IO_STATE(); if (state == NULL) goto error; - fileno = PyObject_CallMethodNoArgs(buffer, _Py_ID(fileno)); + fileno = PyObject_CallMethodNoArgs(buffer, &_Py_ID(fileno)); /* Ignore only AttributeError and UnsupportedOperation */ if (fileno == NULL) { if (PyErr_ExceptionMatches(PyExc_AttributeError) || @@ -1205,7 +1205,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, Py_IS_TYPE(buffer, &PyBufferedWriter_Type) || Py_IS_TYPE(buffer, &PyBufferedRandom_Type)) { - if (_PyObject_LookupAttr(buffer, _Py_ID(raw), &raw) < 0) + if (_PyObject_LookupAttr(buffer, &_Py_ID(raw), &raw) < 0) goto error; /* Cache the raw FileIO object to speed up 'closed' checks */ if (raw != NULL) { @@ -1216,7 +1216,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, } } - res = PyObject_CallMethodNoArgs(buffer, _Py_ID(seekable)); + res = PyObject_CallMethodNoArgs(buffer, &_Py_ID(seekable)); if (res == NULL) goto error; r = PyObject_IsTrue(res); @@ -1279,7 +1279,7 @@ textiowrapper_change_encoding(textio *self, PyObject *encoding, } } else if (errors == Py_None) { - errors = _Py_ID(strict); + errors = &_Py_ID(strict); } const char *c_errors = PyUnicode_AsUTF8(errors); @@ -1614,7 +1614,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) haslf = 1; if (haslf && self->writetranslate && self->writenl != NULL) { - PyObject *newtext = _PyObject_CallMethod(text, _Py_ID(replace), + PyObject *newtext = _PyObject_CallMethod(text, &_Py_ID(replace), "ss", "\n", self->writenl); Py_DECREF(text); if (newtext == NULL) @@ -1714,7 +1714,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text) Py_CLEAR(self->snapshot); if (self->decoder) { - ret = PyObject_CallMethodNoArgs(self->decoder, _Py_ID(reset)); + ret = PyObject_CallMethodNoArgs(self->decoder, &_Py_ID(reset)); if (ret == NULL) return NULL; Py_DECREF(ret); @@ -1918,7 +1918,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n) if (n < 0) { /* Read everything */ - PyObject *bytes = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(read)); + PyObject *bytes = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(read)); PyObject *decoded; if (bytes == NULL) goto fail; @@ -2382,7 +2382,7 @@ _textiowrapper_decoder_setstate(textio *self, cookie_type *cookie) res = PyObject_CallMethodNoArgs(self->decoder, _PyIO_str_reset); } else { - res = _PyObject_CallMethod(self->decoder, _Py_ID(setstate), + res = _PyObject_CallMethod(self->decoder, &_Py_ID(setstate), "((yi))", "", cookie->dec_flags); } if (res == NULL) { @@ -2464,7 +2464,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) * sync the underlying buffer with the current position. */ Py_DECREF(cookieObj); - cookieObj = PyObject_CallMethodNoArgs((PyObject *)self, _Py_ID(tell)); + cookieObj = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(tell)); if (cookieObj == NULL) goto fail; break; @@ -2480,7 +2480,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) goto fail; } - res = PyObject_CallMethodNoArgs((PyObject *)self, _Py_ID(flush)); + res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush)); if (res == NULL) goto fail; Py_DECREF(res); @@ -2488,13 +2488,13 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) textiowrapper_set_decoded_chars(self, NULL); Py_CLEAR(self->snapshot); if (self->decoder) { - res = PyObject_CallMethodNoArgs(self->decoder, _Py_ID(reset)); + res = PyObject_CallMethodNoArgs(self->decoder, &_Py_ID(reset)); if (res == NULL) goto fail; Py_DECREF(res); } - res = _PyObject_CallMethod(self->buffer, _Py_ID(seek), "ii", 0, 2); + res = _PyObject_CallMethod(self->buffer, &_Py_ID(seek), "ii", 0, 2); Py_CLEAR(cookieObj); if (res == NULL) goto fail; @@ -2560,7 +2560,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) if (cookie.chars_to_skip) { /* Just like _read_chunk, feed the decoder and save a snapshot. */ - PyObject *input_chunk = _PyObject_CallMethod(self->buffer, _Py_ID(read), + PyObject *input_chunk = _PyObject_CallMethod(self->buffer, &_Py_ID(read), "i", cookie.bytes_to_feed); PyObject *decoded; @@ -2582,7 +2582,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence) } Py_XSETREF(self->snapshot, snapshot); - decoded = PyObject_CallMethodObjArgs(self->decoder, _Py_ID(decode), + decoded = PyObject_CallMethodObjArgs(self->decoder, &_Py_ID(decode), input_chunk, cookie.need_eof ? Py_True : Py_False, NULL); if (check_decoded(decoded) < 0) @@ -2650,12 +2650,12 @@ _io_TextIOWrapper_tell_impl(textio *self) if (_textiowrapper_writeflush(self) < 0) return NULL; - res = PyObject_CallMethodNoArgs((PyObject *)self, _Py_ID(flush)); + res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush)); if (res == NULL) goto fail; Py_DECREF(res); - posobj = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(tell)); + posobj = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(tell)); if (posobj == NULL) goto fail; @@ -2728,7 +2728,7 @@ _io_TextIOWrapper_tell_impl(textio *self) #define DECODER_DECODE(start, len, res) do { \ PyObject *_decoded = _PyObject_CallMethod( \ - self->decoder, _Py_ID(decode), "y#", start, len); \ + self->decoder, &_Py_ID(decode), "y#", start, len); \ if (check_decoded(_decoded) < 0) \ goto fail; \ res = PyUnicode_GET_LENGTH(_decoded); \ @@ -2810,7 +2810,7 @@ _io_TextIOWrapper_tell_impl(textio *self) if (input == input_end) { /* We didn't get enough decoded data; signal EOF to get more. */ PyObject *decoded = _PyObject_CallMethod( - self->decoder, _Py_ID(decode), "yO", "", /* final = */ Py_True); + self->decoder, &_Py_ID(decode), "yO", "", /* final = */ Py_True); if (check_decoded(decoded) < 0) goto fail; chars_decoded += PyUnicode_GET_LENGTH(decoded); @@ -2826,7 +2826,7 @@ _io_TextIOWrapper_tell_impl(textio *self) finally: res = PyObject_CallMethodOneArg( - self->decoder, _Py_ID(setstate), saved_state); + self->decoder, &_Py_ID(setstate), saved_state); Py_DECREF(saved_state); if (res == NULL) return NULL; @@ -2841,7 +2841,7 @@ _io_TextIOWrapper_tell_impl(textio *self) PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); res = PyObject_CallMethodOneArg( - self->decoder, _Py_ID(setstate), saved_state); + self->decoder, &_Py_ID(setstate), saved_state); _PyErr_ChainExceptions(type, value, traceback); Py_DECREF(saved_state); Py_XDECREF(res); @@ -2892,7 +2892,7 @@ textiowrapper_repr(textio *self) } goto error; } - if (_PyObject_LookupAttr((PyObject *) self, _Py_ID(name), &nameobj) < 0) { + if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) { if (!PyErr_ExceptionMatches(PyExc_ValueError)) { goto error; } @@ -2908,7 +2908,7 @@ textiowrapper_repr(textio *self) if (res == NULL) goto error; } - if (_PyObject_LookupAttr((PyObject *) self, _Py_ID(mode), &modeobj) < 0) { + if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(mode), &modeobj) < 0) { goto error; } if (modeobj != NULL) { @@ -2948,7 +2948,7 @@ _io_TextIOWrapper_fileno_impl(textio *self) /*[clinic end generated code: output=21490a4c3da13e6c input=c488ca83d0069f9b]*/ { CHECK_ATTACHED(self); - return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(fileno)); + return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(fileno)); } /*[clinic input] @@ -2960,7 +2960,7 @@ _io_TextIOWrapper_seekable_impl(textio *self) /*[clinic end generated code: output=ab223dbbcffc0f00 input=8b005ca06e1fca13]*/ { CHECK_ATTACHED(self); - return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(seekable)); + return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(seekable)); } /*[clinic input] @@ -2972,7 +2972,7 @@ _io_TextIOWrapper_readable_impl(textio *self) /*[clinic end generated code: output=72ff7ba289a8a91b input=0704ea7e01b0d3eb]*/ { CHECK_ATTACHED(self); - return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(readable)); + return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(readable)); } /*[clinic input] @@ -2984,7 +2984,7 @@ _io_TextIOWrapper_writable_impl(textio *self) /*[clinic end generated code: output=a728c71790d03200 input=c41740bc9d8636e8]*/ { CHECK_ATTACHED(self); - return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(writable)); + return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(writable)); } /*[clinic input] @@ -2996,7 +2996,7 @@ _io_TextIOWrapper_isatty_impl(textio *self) /*[clinic end generated code: output=12be1a35bace882e input=fb68d9f2c99bbfff]*/ { CHECK_ATTACHED(self); - return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(isatty)); + return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(isatty)); } /*[clinic input] @@ -3012,7 +3012,7 @@ _io_TextIOWrapper_flush_impl(textio *self) self->telling = self->seekable; if (_textiowrapper_writeflush(self) < 0) return NULL; - return PyObject_CallMethodNoArgs(self->buffer, _Py_ID(flush)); + return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(flush)); } /*[clinic input] @@ -3041,20 +3041,20 @@ _io_TextIOWrapper_close_impl(textio *self) else { PyObject *exc = NULL, *val, *tb; if (self->finalizing) { - res = PyObject_CallMethodOneArg(self->buffer, _Py_ID(_dealloc_warn), + res = PyObject_CallMethodOneArg(self->buffer, &_Py_ID(_dealloc_warn), (PyObject *)self); if (res) Py_DECREF(res); else PyErr_Clear(); } - res = PyObject_CallMethodNoArgs((PyObject *)self, _Py_ID(flush)); + res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush)); if (res == NULL) PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(res); - res = PyObject_CallMethodNoArgs(self->buffer, _Py_ID(close)); + res = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(close)); if (exc != NULL) { _PyErr_ChainExceptions(exc, val, tb); Py_CLEAR(res); @@ -3105,7 +3105,7 @@ static PyObject * textiowrapper_name_get(textio *self, void *context) { CHECK_ATTACHED(self); - return PyObject_GetAttr(self->buffer, _Py_ID(name)); + return PyObject_GetAttr(self->buffer, &_Py_ID(name)); } static PyObject * diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index 06b9ff7e8a9178c..5c1a6dd86fc54f2 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -195,7 +195,7 @@ _io__WindowsConsoleIO_close_impl(winconsoleio *self) PyObject *exc, *val, *tb; int rc; res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type, - _Py_ID(close), (PyObject*)self); + &_Py_ID(close), (PyObject*)self); if (!self->closefd) { self->fd = -1; return res; @@ -391,7 +391,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj, self->blksize = DEFAULT_BUFFER_SIZE; memset(self->buf, 0, 4); - if (PyObject_SetAttr((PyObject *)self, _Py_ID(name), nameobj) < 0) + if (PyObject_SetAttr((PyObject *)self, &_Py_ID(name), nameobj) < 0) goto error; goto done; diff --git a/Modules/_operator.c b/Modules/_operator.c index 869c79624b5fee9..10adabcbf0e8582 100644 --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -1697,7 +1697,7 @@ methodcaller_reduce(methodcallerobject *mc, PyObject *Py_UNUSED(ignored)) functools = PyImport_ImportModule("functools"); if (!functools) return NULL; - partial = PyObject_GetAttr(functools, _Py_ID(partial)); + partial = PyObject_GetAttr(functools, &_Py_ID(partial)); Py_DECREF(functools); if (!partial) return NULL; diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 9fb61677a59f24d..19e8a71073c9741 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -235,7 +235,7 @@ _Pickle_InitState(PickleState *st) PyObject *codecs = NULL; PyObject *functools = NULL; - st->getattr = _PyEval_GetBuiltin(_Py_ID(getattr)); + st->getattr = _PyEval_GetBuiltin(&_Py_ID(getattr)); if (st->getattr == NULL) goto error; @@ -1184,7 +1184,7 @@ static int _Pickler_SetOutputStream(PicklerObject *self, PyObject *file) { assert(file != NULL); - if (_PyObject_LookupAttr(file, _Py_ID(write), &self->write) < 0) { + if (_PyObject_LookupAttr(file, &_Py_ID(write), &self->write) < 0) { return -1; } if (self->write == NULL) { @@ -1644,14 +1644,14 @@ static int _Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file) { /* Optional file methods */ - if (_PyObject_LookupAttr(file, _Py_ID(peek), &self->peek) < 0) { + if (_PyObject_LookupAttr(file, &_Py_ID(peek), &self->peek) < 0) { return -1; } - if (_PyObject_LookupAttr(file, _Py_ID(readinto), &self->readinto) < 0) { + if (_PyObject_LookupAttr(file, &_Py_ID(readinto), &self->readinto) < 0) { return -1; } - (void)_PyObject_LookupAttr(file, _Py_ID(read), &self->read); - (void)_PyObject_LookupAttr(file, _Py_ID(readline), &self->readline); + (void)_PyObject_LookupAttr(file, &_Py_ID(read), &self->read); + (void)_PyObject_LookupAttr(file, &_Py_ID(readline), &self->readline); if (!self->readline || !self->read) { if (!PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, @@ -1814,7 +1814,7 @@ get_dotted_path(PyObject *obj, PyObject *name) PyObject *dotted_path; Py_ssize_t i, n; - dotted_path = PyUnicode_Split(name, _Py_STR(dot), -1); + dotted_path = PyUnicode_Split(name, &_Py_STR(dot), -1); if (dotted_path == NULL) return NULL; n = PyList_GET_SIZE(dotted_path); @@ -1916,7 +1916,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) Py_ssize_t i; PyObject *modules; - if (_PyObject_LookupAttr(global, _Py_ID(__module__), &module_name) < 0) { + if (_PyObject_LookupAttr(global, &_Py_ID(__module__), &module_name) < 0) { return NULL; } if (module_name) { @@ -1931,7 +1931,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) /* Fallback on walking sys.modules */ PyThreadState *tstate = _PyThreadState_GET(); - modules = _PySys_GetAttr(tstate, _Py_ID(modules)); + modules = _PySys_GetAttr(tstate, &_Py_ID(modules)); if (modules == NULL) { PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules"); return NULL; @@ -1976,7 +1976,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) } /* If no module is found, use __main__. */ - module_name = _Py_ID(__main__); + module_name = &_Py_ID(__main__); Py_INCREF(module_name); return module_name; } @@ -2431,7 +2431,7 @@ save_bytes(PicklerObject *self, PyObject *obj) return -1; reduce_value = Py_BuildValue("(O(OO))", st->codecs_encode, unicode_str, - _Py_ID(latin1)); + &_Py_ID(latin1)); Py_DECREF(unicode_str); } @@ -3333,7 +3333,7 @@ save_dict(PicklerObject *self, PyObject *obj) status = batch_dict_exact(self, obj); Py_LeaveRecursiveCall(); } else { - items = PyObject_CallMethodNoArgs(obj, _Py_ID(items)); + items = PyObject_CallMethodNoArgs(obj, &_Py_ID(items)); if (items == NULL) goto error; iter = PyObject_GetIter(items); @@ -3593,10 +3593,10 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name) global_name = name; } else { - if (_PyObject_LookupAttr(obj, _Py_ID(__qualname__), &global_name) < 0) + if (_PyObject_LookupAttr(obj, &_Py_ID(__qualname__), &global_name) < 0) goto error; if (global_name == NULL) { - global_name = PyObject_GetAttr(obj, _Py_ID(__name__)); + global_name = PyObject_GetAttr(obj, &_Py_ID(__name__)); if (global_name == NULL) goto error; } @@ -3918,7 +3918,7 @@ get_class(PyObject *obj) { PyObject *cls; - if (_PyObject_LookupAttr(obj, _Py_ID(__class__), &cls) == 0) { + if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &cls) == 0) { cls = (PyObject *) Py_TYPE(obj); Py_INCREF(cls); } @@ -4002,13 +4002,13 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) if (self->proto >= 2) { PyObject *name; - if (_PyObject_LookupAttr(callable, _Py_ID(__name__), &name) < 0) { + if (_PyObject_LookupAttr(callable, &_Py_ID(__name__), &name) < 0) { return -1; } if (name != NULL && PyUnicode_Check(name)) { - use_newobj_ex = _PyUnicode_Equal(name, _Py_ID(__newobj_ex__)); + use_newobj_ex = _PyUnicode_Equal(name, &_Py_ID(__newobj_ex__)); if (!use_newobj_ex) { - use_newobj = _PyUnicode_Equal(name, _Py_ID(__newobj__)); + use_newobj = _PyUnicode_Equal(name, &_Py_ID(__newobj__)); } } Py_XDECREF(name); @@ -4065,7 +4065,7 @@ save_reduce(PicklerObject *self, PyObject *args, PyObject *obj) if (newargs == NULL) return -1; - cls_new = PyObject_GetAttr(cls, _Py_ID(__new__)); + cls_new = PyObject_GetAttr(cls, &_Py_ID(__new__)); if (cls_new == NULL) { Py_DECREF(newargs); return -1; @@ -4409,7 +4409,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save) don't actually have to check for a __reduce__ method. */ /* Check for a __reduce_ex__ method. */ - if (_PyObject_LookupAttr(obj, _Py_ID(__reduce_ex__), &reduce_func) < 0) { + if (_PyObject_LookupAttr(obj, &_Py_ID(__reduce_ex__), &reduce_func) < 0) { goto error; } if (reduce_func != NULL) { @@ -4421,7 +4421,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save) } else { /* Check for a __reduce__ method. */ - if (_PyObject_LookupAttr(obj, _Py_ID(__reduce__), &reduce_func) < 0) { + if (_PyObject_LookupAttr(obj, &_Py_ID(__reduce__), &reduce_func) < 0) { goto error; } if (reduce_func != NULL) { @@ -4475,7 +4475,7 @@ dump(PicklerObject *self, PyObject *obj) int status = -1; PyObject *tmp; - if (_PyObject_LookupAttr((PyObject *)self, _Py_ID(reducer_override), + if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(reducer_override), &tmp) < 0) { goto error; } @@ -4743,13 +4743,13 @@ _pickle_Pickler___init___impl(PicklerObject *self, PyObject *file, self->fast_nesting = 0; self->fast_memo = NULL; - if (init_method_ref((PyObject *)self, _Py_ID(persistent_id), + if (init_method_ref((PyObject *)self, &_Py_ID(persistent_id), &self->pers_func, &self->pers_func_self) < 0) { return -1; } - if (_PyObject_LookupAttr((PyObject *)self, _Py_ID(dispatch_table), + if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(dispatch_table), &self->dispatch_table) < 0) { return -1; } @@ -5104,7 +5104,7 @@ static PyTypeObject Pickler_Type = { static PyObject * find_class(UnpicklerObject *self, PyObject *module_name, PyObject *global_name) { - return PyObject_CallMethodObjArgs((PyObject *)self, _Py_ID(find_class), + return PyObject_CallMethodObjArgs((PyObject *)self, &_Py_ID(find_class), module_name, global_name, NULL); } @@ -5793,11 +5793,11 @@ instantiate(PyObject *cls, PyObject *args) assert(PyTuple_Check(args)); if (!PyTuple_GET_SIZE(args) && PyType_Check(cls)) { PyObject *func; - if (_PyObject_LookupAttr(cls, _Py_ID(__getinitargs__), &func) < 0) { + if (_PyObject_LookupAttr(cls, &_Py_ID(__getinitargs__), &func) < 0) { return NULL; } if (func == NULL) { - return PyObject_CallMethodOneArg(cls, _Py_ID(__new__), cls); + return PyObject_CallMethodOneArg(cls, &_Py_ID(__new__), cls); } Py_DECREF(func); } @@ -6443,7 +6443,7 @@ do_append(UnpicklerObject *self, Py_ssize_t x) else { PyObject *extend_func; - if (_PyObject_LookupAttr(list, _Py_ID(extend), &extend_func) < 0) { + if (_PyObject_LookupAttr(list, &_Py_ID(extend), &extend_func) < 0) { return -1; } if (extend_func != NULL) { @@ -6464,7 +6464,7 @@ do_append(UnpicklerObject *self, Py_ssize_t x) /* Even if the PEP 307 requires extend() and append() methods, fall back on append() if the object has no extend() method for backward compatibility. */ - append_func = PyObject_GetAttr(list, _Py_ID(append)); + append_func = PyObject_GetAttr(list, &_Py_ID(append)); if (append_func == NULL) return -1; for (i = x; i < len; i++) { @@ -6588,7 +6588,7 @@ load_additems(UnpicklerObject *self) else { PyObject *add_func; - add_func = PyObject_GetAttr(set, _Py_ID(add)); + add_func = PyObject_GetAttr(set, &_Py_ID(add)); if (add_func == NULL) return -1; for (i = mark; i < len; i++) { @@ -6629,7 +6629,7 @@ load_build(UnpicklerObject *self) inst = self->stack->data[Py_SIZE(self->stack) - 1]; - if (_PyObject_LookupAttr(inst, _Py_ID(__setstate__), &setstate) < 0) { + if (_PyObject_LookupAttr(inst, &_Py_ID(__setstate__), &setstate) < 0) { Py_DECREF(state); return -1; } @@ -6671,7 +6671,7 @@ load_build(UnpicklerObject *self) PyErr_SetString(st->UnpicklingError, "state is not a dictionary"); goto error; } - dict = PyObject_GetAttr(inst, _Py_ID(__dict__)); + dict = PyObject_GetAttr(inst, &_Py_ID(__dict__)); if (dict == NULL) goto error; @@ -7238,7 +7238,7 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file, self->fix_imports = fix_imports; - if (init_method_ref((PyObject *)self, _Py_ID(persistent_load), + if (init_method_ref((PyObject *)self, &_Py_ID(persistent_load), &self->pers_func, &self->pers_func_self) < 0) { return -1; diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 87cae7445593722..130900c54b74b01 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -933,7 +933,7 @@ local_setattro(localobject *self, PyObject *name, PyObject *v) return -1; } - int r = PyObject_RichCompareBool(name, _Py_ID(__dict__), Py_EQ); + int r = PyObject_RichCompareBool(name, &_Py_ID(__dict__), Py_EQ); if (r == -1) { return -1; } @@ -984,7 +984,7 @@ local_getattro(localobject *self, PyObject *name) if (ldict == NULL) return NULL; - int r = PyObject_RichCompareBool(name, _Py_ID(__dict__), Py_EQ); + int r = PyObject_RichCompareBool(name, &_Py_ID(__dict__), Py_EQ); if (r == 1) { return Py_NewRef(ldict); } @@ -1405,7 +1405,7 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, PyObject *name = NULL; if (thread != Py_None) { - if (_PyObject_LookupAttr(thread, _Py_ID(name), &name) < 0) { + if (_PyObject_LookupAttr(thread, &_Py_ID(name), &name) < 0) { return -1; } } @@ -1443,7 +1443,7 @@ thread_excepthook_file(PyObject *file, PyObject *exc_type, PyObject *exc_value, _PyErr_Display(file, exc_type, exc_value, exc_traceback); /* Call file.flush() */ - PyObject *res = PyObject_CallMethodNoArgs(file, _Py_ID(flush)); + PyObject *res = PyObject_CallMethodNoArgs(file, &_Py_ID(flush)); if (!res) { return -1; } @@ -1499,7 +1499,7 @@ thread_excepthook(PyObject *module, PyObject *args) PyObject *thread = PyStructSequence_GET_ITEM(args, 3); PyThreadState *tstate = _PyThreadState_GET(); - PyObject *file = _PySys_GetAttr(tstate, _Py_ID(stderr)); + PyObject *file = _PySys_GetAttr(tstate, &_Py_ID(stderr)); if (file == NULL || file == Py_None) { if (thread == Py_None) { /* do nothing if sys.stderr is None and thread is None */ diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index a3da993282655c1..46e18c17d8d3533 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -151,7 +151,7 @@ faulthandler_get_fileno(PyObject **file_ptr) if (file == NULL || file == Py_None) { PyThreadState *tstate = _PyThreadState_GET(); - file = _PySys_GetAttr(tstate, _Py_ID(stderr)); + file = _PySys_GetAttr(tstate, &_Py_ID(stderr)); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "unable to get sys.stderr"); return -1; @@ -174,7 +174,7 @@ faulthandler_get_fileno(PyObject **file_ptr) return fd; } - result = PyObject_CallMethodNoArgs(file, _Py_ID(fileno)); + result = PyObject_CallMethodNoArgs(file, &_Py_ID(fileno)); if (result == NULL) return -1; @@ -192,7 +192,7 @@ faulthandler_get_fileno(PyObject **file_ptr) return -1; } - result = PyObject_CallMethodNoArgs(file, _Py_ID(flush)); + result = PyObject_CallMethodNoArgs(file, &_Py_ID(flush)); if (result != NULL) Py_DECREF(result); else { @@ -1332,7 +1332,7 @@ faulthandler_init_enable(void) return -1; } - PyObject *res = PyObject_CallMethodNoArgs(module, _Py_ID(enable)); + PyObject *res = PyObject_CallMethodNoArgs(module, &_Py_ID(enable)); Py_DECREF(module); if (res == NULL) { return -1; diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c index 23ef9fc4df05973..0ec65d57381d822 100644 --- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -504,7 +504,7 @@ static PyObject * _grouper_reduce(_grouperobject *lz, PyObject *Py_UNUSED(ignored)) { if (((groupbyobject *)lz->parent)->currgrouper != lz) { - return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter))); } return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->parent, lz->tgtkey); } @@ -1030,7 +1030,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n) return NULL; } - if (_PyObject_LookupAttr(it, _Py_ID(__copy__), ©func) < 0) { + if (_PyObject_LookupAttr(it, &_Py_ID(__copy__), ©func) < 0) { Py_DECREF(it); Py_DECREF(result); return NULL; @@ -1045,7 +1045,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n) Py_DECREF(result); return NULL; } - copyfunc = PyObject_GetAttr(copyable, _Py_ID(__copy__)); + copyfunc = PyObject_GetAttr(copyable, &_Py_ID(__copy__)); if (copyfunc == NULL) { Py_DECREF(copyable); Py_DECREF(result); @@ -1177,7 +1177,7 @@ cycle_reduce(cycleobject *lz, PyObject *Py_UNUSED(ignored)) if (it == NULL) return NULL; if (lz->index != 0) { - PyObject *res = _PyObject_CallMethod(it, _Py_ID(__setstate__), + PyObject *res = _PyObject_CallMethod(it, &_Py_ID(__setstate__), "n", lz->index); if (res == NULL) { Py_DECREF(it); @@ -4552,7 +4552,7 @@ zip_longest_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (kwds != NULL && PyDict_CheckExact(kwds) && PyDict_GET_SIZE(kwds) > 0) { fillvalue = NULL; if (PyDict_GET_SIZE(kwds) == 1) { - fillvalue = PyDict_GetItemWithError(kwds, _Py_ID(fillvalue)); + fillvalue = PyDict_GetItemWithError(kwds, &_Py_ID(fillvalue)); } if (fillvalue == NULL) { if (!PyErr_Occurred()) { diff --git a/Modules/main.c b/Modules/main.c index 9cb1ce6de9c2b7f..2443f5631b94bb2 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -161,7 +161,7 @@ pymain_sys_path_add_path0(PyInterpreterState *interp, PyObject *path0) PyObject *sys_path; PyObject *sysdict = interp->sysdict; if (sysdict != NULL) { - sys_path = PyDict_GetItemWithError(sysdict, _Py_ID(path)); + sys_path = PyDict_GetItemWithError(sysdict, &_Py_ID(path)); if (sys_path == NULL && PyErr_Occurred()) { return -1; } diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index fe0e6f1bf49a52a..b3468cae3f57366 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1157,7 +1157,7 @@ path_converter(PyObject *o, void *p) /* Inline PyOS_FSPath() for better error messages. */ PyObject *func, *res; - func = _PyObject_LookupSpecial(o, _Py_ID(__fspath__)); + func = _PyObject_LookupSpecial(o, &_Py_ID(__fspath__)); if (NULL == func) { goto error_format; } @@ -14435,7 +14435,7 @@ PyOS_FSPath(PyObject *path) return path; } - func = _PyObject_LookupSpecial(path, _Py_ID(__fspath__)); + func = _PyObject_LookupSpecial(path, &_Py_ID(__fspath__)); if (NULL == func) { return PyErr_Format(PyExc_TypeError, "expected str, bytes or os.PathLike object, " diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 623e3d89663b78a..b449a041bb6887f 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -916,7 +916,7 @@ time_strptime(PyObject *self, PyObject *args) if (!module) return NULL; - func = PyObject_GetAttr(module, _Py_ID(_strptime_time)); + func = PyObject_GetAttr(module, &_Py_ID(_strptime_time)); Py_DECREF(module); if (!func) { return NULL; diff --git a/Objects/abstract.c b/Objects/abstract.c index 335d80dfb79ba3f..5c914b021e12f79 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -106,7 +106,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) return res; } } - hint = _PyObject_LookupSpecial(o, _Py_ID(__length_hint__)); + hint = _PyObject_LookupSpecial(o, &_Py_ID(__length_hint__)); if (hint == NULL) { if (PyErr_Occurred()) { return -1; @@ -182,7 +182,7 @@ PyObject_GetItem(PyObject *o, PyObject *key) return Py_GenericAlias(o, key); } - if (_PyObject_LookupAttr(o, _Py_ID(__class_getitem__), &meth) < 0) { + if (_PyObject_LookupAttr(o, &_Py_ID(__class_getitem__), &meth) < 0) { return NULL; } if (meth) { @@ -794,7 +794,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec) } /* Find the (unbound!) __format__ method */ - meth = _PyObject_LookupSpecial(obj, _Py_ID(__format__)); + meth = _PyObject_LookupSpecial(obj, &_Py_ID(__format__)); if (meth == NULL) { PyThreadState *tstate = _PyThreadState_GET(); if (!_PyErr_Occurred(tstate)) { @@ -1558,7 +1558,7 @@ PyNumber_Long(PyObject *o) if (m && m->nb_index) { return PyNumber_Index(o); } - trunc_func = _PyObject_LookupSpecial(o, _Py_ID(__trunc__)); + trunc_func = _PyObject_LookupSpecial(o, &_Py_ID(__trunc__)); if (trunc_func) { result = _PyObject_CallNoArgs(trunc_func); Py_DECREF(trunc_func); @@ -2434,7 +2434,7 @@ PyMapping_Keys(PyObject *o) if (PyDict_CheckExact(o)) { return PyDict_Keys(o); } - return method_output_as_list(o, _Py_ID(keys)); + return method_output_as_list(o, &_Py_ID(keys)); } PyObject * @@ -2446,7 +2446,7 @@ PyMapping_Items(PyObject *o) if (PyDict_CheckExact(o)) { return PyDict_Items(o); } - return method_output_as_list(o, _Py_ID(items)); + return method_output_as_list(o, &_Py_ID(items)); } PyObject * @@ -2458,7 +2458,7 @@ PyMapping_Values(PyObject *o) if (PyDict_CheckExact(o)) { return PyDict_Values(o); } - return method_output_as_list(o, _Py_ID(values)); + return method_output_as_list(o, &_Py_ID(values)); } /* isinstance(), issubclass() */ @@ -2492,7 +2492,7 @@ abstract_get_bases(PyObject *cls) { PyObject *bases; - (void)_PyObject_LookupAttr(cls, _Py_ID(__bases__), &bases); + (void)_PyObject_LookupAttr(cls, &_Py_ID(__bases__), &bases); if (bases != NULL && !PyTuple_Check(bases)) { Py_DECREF(bases); return NULL; @@ -2576,7 +2576,7 @@ object_isinstance(PyObject *inst, PyObject *cls) if (PyType_Check(cls)) { retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls); if (retval == 0) { - retval = _PyObject_LookupAttr(inst, _Py_ID(__class__), &icls); + retval = _PyObject_LookupAttr(inst, &_Py_ID(__class__), &icls); if (icls != NULL) { if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) { retval = PyType_IsSubtype( @@ -2594,7 +2594,7 @@ object_isinstance(PyObject *inst, PyObject *cls) if (!check_class(cls, "isinstance() arg 2 must be a type, a tuple of types, or a union")) return -1; - retval = _PyObject_LookupAttr(inst, _Py_ID(__class__), &icls); + retval = _PyObject_LookupAttr(inst, &_Py_ID(__class__), &icls); if (icls != NULL) { retval = abstract_issubclass(icls, cls); Py_DECREF(icls); @@ -2637,7 +2637,7 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls return r; } - PyObject *checker = _PyObject_LookupSpecial(cls, _Py_ID(__instancecheck__)); + PyObject *checker = _PyObject_LookupSpecial(cls, &_Py_ID(__instancecheck__)); if (checker != NULL) { if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) { Py_DECREF(checker); @@ -2724,7 +2724,7 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls) return r; } - checker = _PyObject_LookupSpecial(cls, _Py_ID(__subclasscheck__)); + checker = _PyObject_LookupSpecial(cls, &_Py_ID(__subclasscheck__)); if (checker != NULL) { int ok = -1; if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) { @@ -2870,7 +2870,7 @@ PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result) *result = Py_TYPE(iter)->tp_iternext(iter); } else { - *result = PyObject_CallMethodOneArg(iter, _Py_ID(send), arg); + *result = PyObject_CallMethodOneArg(iter, &_Py_ID(send), arg); } if (*result != NULL) { return PYGEN_NEXT; diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 22ae442367b5a28..224ca95a50b2814 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2113,7 +2113,7 @@ _common_reduce(PyByteArrayObject *self, int proto) PyObject *dict; char *buf; - if (_PyObject_LookupAttr((PyObject *)self, _Py_ID(__dict__), &dict) < 0) { + if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(__dict__), &dict) < 0) { return NULL; } if (dict == NULL) { @@ -2427,10 +2427,10 @@ static PyObject * bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)), it->it_seq, it->it_index); } else { - return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter))); } } diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index b6ff81b0f35236a..9518bd70252d1f3 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -528,7 +528,7 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen) return v; } /* does it support __bytes__? */ - func = _PyObject_LookupSpecial(v, _Py_ID(__bytes__)); + func = _PyObject_LookupSpecial(v, &_Py_ID(__bytes__)); if (func != NULL) { result = _PyObject_CallNoArgs(func); Py_DECREF(func); @@ -2579,7 +2579,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding, /* We'd like to call PyObject_Bytes here, but we need to check for an integer argument before deferring to PyBytes_FromObject, something PyObject_Bytes doesn't do. */ - else if ((func = _PyObject_LookupSpecial(x, _Py_ID(__bytes__))) != NULL) { + else if ((func = _PyObject_LookupSpecial(x, &_Py_ID(__bytes__))) != NULL) { bytes = _PyObject_CallNoArgs(func); Py_DECREF(func); if (bytes == NULL) @@ -3120,10 +3120,10 @@ static PyObject * striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)), it->it_seq, it->it_index); } else { - return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter))); } } diff --git a/Objects/classobject.c b/Objects/classobject.c index 71f932200f813cb..d7ccf31244e8b77 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -122,12 +122,12 @@ method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored)) PyObject *func = PyMethod_GET_FUNCTION(im); PyObject *funcname; - funcname = PyObject_GetAttr(func, _Py_ID(__name__)); + funcname = PyObject_GetAttr(func, &_Py_ID(__name__)); if (funcname == NULL) { return NULL; } return Py_BuildValue( - "N(ON)", _PyEval_GetBuiltin(_Py_ID(getattr)), self, funcname); + "N(ON)", _PyEval_GetBuiltin(&_Py_ID(getattr)), self, funcname); } static PyMethodDef method_methods[] = { @@ -277,9 +277,9 @@ method_repr(PyMethodObject *a) PyObject *funcname, *result; const char *defname = "?"; - if (_PyObject_LookupAttr(func, _Py_ID(__qualname__), &funcname) < 0 || + if (_PyObject_LookupAttr(func, &_Py_ID(__qualname__), &funcname) < 0 || (funcname == NULL && - _PyObject_LookupAttr(func, _Py_ID(__name__), &funcname) < 0)) + _PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0)) { return NULL; } @@ -512,7 +512,7 @@ instancemethod_repr(PyObject *self) return NULL; } - if (_PyObject_LookupAttr(func, _Py_ID(__name__), &funcname) < 0) { + if (_PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0) { return NULL; } if (funcname != NULL && !PyUnicode_Check(funcname)) { diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 953c9611895be2f..9bd68d50c30ae0d 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -282,7 +282,7 @@ try_complex_special_method(PyObject *op) { PyObject *f; - f = _PyObject_LookupSpecial(op, _Py_ID(__complex__)); + f = _PyObject_LookupSpecial(op, &_Py_ID(__complex__)); if (f) { PyObject *res = _PyObject_CallNoArgs(f); Py_DECREF(f); diff --git a/Objects/descrobject.c b/Objects/descrobject.c index b3c50727cef68e9..95162683edd7d1b 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -577,7 +577,7 @@ calculate_qualname(PyDescrObject *descr) } type_qualname = PyObject_GetAttr( - (PyObject *)descr->d_type, _Py_ID(__qualname__)); + (PyObject *)descr->d_type, &_Py_ID(__qualname__)); if (type_qualname == NULL) return NULL; @@ -605,7 +605,7 @@ descr_get_qualname(PyDescrObject *descr, void *Py_UNUSED(ignored)) static PyObject * descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored)) { - return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(_Py_ID(getattr)), + return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(&_Py_ID(getattr)), PyDescr_TYPE(descr), PyDescr_NAME(descr)); } @@ -1083,7 +1083,7 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs { return NULL; } - return _PyObject_VectorcallMethod(_Py_ID(get), newargs, + return _PyObject_VectorcallMethod(&_Py_ID(get), newargs, 3 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); } @@ -1091,31 +1091,31 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs static PyObject * mappingproxy_keys(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(keys)); + return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(keys)); } static PyObject * mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(values)); + return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(values)); } static PyObject * mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(items)); + return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(items)); } static PyObject * mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(copy)); + return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(copy)); } static PyObject * mappingproxy_reversed(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored)) { - return PyObject_CallMethodNoArgs(pp->mapping, _Py_ID(__reversed__)); + return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(__reversed__)); } /* WARNING: mappingproxy methods must not give access @@ -1312,7 +1312,7 @@ wrapper_repr(wrapperobject *wp) static PyObject * wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored)) { - return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(_Py_ID(getattr)), + return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(&_Py_ID(getattr)), wp->self, PyDescr_NAME(wp->descr)); } @@ -1748,7 +1748,7 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, /* if no docstring given and the getter has one, use that one */ if ((doc == NULL || doc == Py_None) && fget != NULL) { PyObject *get_doc; - int rc = _PyObject_LookupAttr(fget, _Py_ID(__doc__), &get_doc); + int rc = _PyObject_LookupAttr(fget, &_Py_ID(__doc__), &get_doc); if (rc <= 0) { return rc; } @@ -1761,7 +1761,7 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset, otherwise it gets shadowed by __doc__ in the class's dict. */ int err = PyObject_SetAttr( - (PyObject *)self, _Py_ID(__doc__), get_doc); + (PyObject *)self, &_Py_ID(__doc__), get_doc); Py_DECREF(get_doc); if (err < 0) return -1; diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 292c674d1f257e8..c3665d2387315e3 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2161,7 +2161,7 @@ dict_subscript(PyDictObject *mp, PyObject *key) /* Look up __missing__ method if we're a subclass. */ PyObject *missing, *res; missing = _PyObject_LookupSpecial( - (PyObject *)mp, _Py_ID(__missing__)); + (PyObject *)mp, &_Py_ID(__missing__)); if (missing != NULL) { res = PyObject_CallOneArg(missing, key); Py_DECREF(missing); @@ -2364,7 +2364,7 @@ dict_update_arg(PyObject *self, PyObject *arg) return PyDict_Merge(self, arg, 1); } PyObject *func; - if (_PyObject_LookupAttr(arg, _Py_ID(keys), &func) < 0) { + if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) { return -1; } if (func != NULL) { @@ -4129,7 +4129,7 @@ dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list); } PyTypeObject PyDictRevIterItem_Type = { @@ -4400,7 +4400,7 @@ dictviews_sub(PyObject *self, PyObject *other) } PyObject *tmp = PyObject_CallMethodOneArg( - result, _Py_ID(difference_update), other); + result, &_Py_ID(difference_update), other); if (tmp == NULL) { Py_DECREF(result); return NULL; @@ -4437,7 +4437,7 @@ _PyDictView_Intersect(PyObject* self, PyObject *other) reuse set intersection logic */ if (PySet_CheckExact(other) && len_self <= PyObject_Size(other)) { return PyObject_CallMethodObjArgs( - other, _Py_ID(intersection), self, NULL); + other, &_Py_ID(intersection), self, NULL); } /* if other is another dict view, and it is bigger than self, @@ -4578,7 +4578,7 @@ dictitems_xor(PyObject *self, PyObject *other) key = val1 = val2 = NULL; PyObject *remaining_pairs = PyObject_CallMethodNoArgs( - temp_dict, _Py_ID(items)); + temp_dict, &_Py_ID(items)); if (remaining_pairs == NULL) { goto error; } @@ -4611,7 +4611,7 @@ dictviews_xor(PyObject* self, PyObject *other) } PyObject *tmp = PyObject_CallMethodOneArg( - result, _Py_ID(symmetric_difference_update), other); + result, &_Py_ID(symmetric_difference_update), other); if (tmp == NULL) { Py_DECREF(result); return NULL; diff --git a/Objects/enumobject.c b/Objects/enumobject.c index 825cd8dcaa9cc66..d84bac6f4c9af20 100644 --- a/Objects/enumobject.c +++ b/Objects/enumobject.c @@ -357,7 +357,7 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq) PyObject *reversed_meth; reversedobject *ro; - reversed_meth = _PyObject_LookupSpecial(seq, _Py_ID(__reversed__)); + reversed_meth = _PyObject_LookupSpecial(seq, &_Py_ID(__reversed__)); if (reversed_meth == Py_None) { Py_DECREF(reversed_meth); PyErr_Format(PyExc_TypeError, diff --git a/Objects/exceptions.c b/Objects/exceptions.c index cfd28294a7b5305..9b1c9f1018077be 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -1502,11 +1502,11 @@ ImportError_getstate(PyImportErrorObject *self) dict = dict ? PyDict_Copy(dict) : PyDict_New(); if (dict == NULL) return NULL; - if (self->name && PyDict_SetItem(dict, _Py_ID(name), self->name) < 0) { + if (self->name && PyDict_SetItem(dict, &_Py_ID(name), self->name) < 0) { Py_DECREF(dict); return NULL; } - if (self->path && PyDict_SetItem(dict, _Py_ID(path), self->path) < 0) { + if (self->path && PyDict_SetItem(dict, &_Py_ID(path), self->path) < 0) { Py_DECREF(dict); return NULL; } diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 9c31bd8586f8970..8dba5b9aea6db18 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -38,7 +38,7 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c io = PyImport_ImportModule("_io"); if (io == NULL) return NULL; - stream = _PyObject_CallMethod(io, _Py_ID(open), "isisssO", fd, mode, + stream = _PyObject_CallMethod(io, &_Py_ID(open), "isisssO", fd, mode, buffering, encoding, errors, newline, closefd ? Py_True : Py_False); Py_DECREF(io); @@ -60,10 +60,10 @@ PyFile_GetLine(PyObject *f, int n) } if (n <= 0) { - result = PyObject_CallMethodNoArgs(f, _Py_ID(readline)); + result = PyObject_CallMethodNoArgs(f, &_Py_ID(readline)); } else { - result = _PyObject_CallMethod(f, _Py_ID(readline), "i", n); + result = _PyObject_CallMethod(f, &_Py_ID(readline), "i", n); } if (result != NULL && !PyBytes_Check(result) && !PyUnicode_Check(result)) { @@ -122,7 +122,7 @@ PyFile_WriteObject(PyObject *v, PyObject *f, int flags) PyErr_SetString(PyExc_TypeError, "writeobject with NULL file"); return -1; } - writer = PyObject_GetAttr(f, _Py_ID(write)); + writer = PyObject_GetAttr(f, &_Py_ID(write)); if (writer == NULL) return -1; if (flags & Py_PRINT_RAW) { @@ -182,7 +182,7 @@ PyObject_AsFileDescriptor(PyObject *o) if (PyLong_Check(o)) { fd = _PyLong_AsInt(o); } - else if (_PyObject_LookupAttr(o, _Py_ID(fileno), &meth) < 0) { + else if (_PyObject_LookupAttr(o, &_Py_ID(fileno), &meth) < 0) { return -1; } else if (meth != NULL) { @@ -504,7 +504,7 @@ PyFile_OpenCodeObject(PyObject *path) } else { iomod = PyImport_ImportModule("_io"); if (iomod) { - f = _PyObject_CallMethod(iomod, _Py_ID(open), "Os", path, "rb"); + f = _PyObject_CallMethod(iomod, &_Py_ID(open), "Os", path, "rb"); Py_DECREF(iomod); } } diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 756bd3fbf407dc4..cb2175a3755257b 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -1078,7 +1078,7 @@ PyFrame_GetBack(PyFrameObject *frame) PyObject* _PyEval_BuiltinsFromGlobals(PyThreadState *tstate, PyObject *globals) { - PyObject *builtins = PyDict_GetItemWithError(globals, _Py_ID(__builtins__)); + PyObject *builtins = PyDict_GetItemWithError(globals, &_Py_ID(__builtins__)); if (builtins) { if (PyModule_Check(builtins)) { builtins = _PyModule_GetDict(builtins); diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 1f3f9d04f508914..deacfd55dd2866b 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -79,7 +79,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname Py_INCREF(doc); // __module__: Use globals['__name__'] if it exists, or NULL. - PyObject *module = PyDict_GetItemWithError(globals, _Py_ID(__name__)); + PyObject *module = PyDict_GetItemWithError(globals, &_Py_ID(__name__)); PyObject *builtins = NULL; if (module == NULL && _PyErr_Occurred(tstate)) { goto error; @@ -807,7 +807,7 @@ functools_wraps(PyObject *wrapper, PyObject *wrapped) { #define COPY_ATTR(ATTR) \ do { \ - if (functools_copy_attr(wrapper, wrapped, _Py_ID(ATTR)) < 0) { \ + if (functools_copy_attr(wrapper, wrapped, &_Py_ID(ATTR)) < 0) { \ return -1; \ } \ } while (0) \ diff --git a/Objects/genericaliasobject.c b/Objects/genericaliasobject.c index 47b5a440a6354a7..b41644910f5d256 100644 --- a/Objects/genericaliasobject.c +++ b/Objects/genericaliasobject.c @@ -53,12 +53,12 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) goto done; } - if (_PyObject_LookupAttr(p, _Py_ID(__origin__), &tmp) < 0) { + if (_PyObject_LookupAttr(p, &_Py_ID(__origin__), &tmp) < 0) { goto done; } if (tmp != NULL) { Py_DECREF(tmp); - if (_PyObject_LookupAttr(p, _Py_ID(__args__), &tmp) < 0) { + if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) { goto done; } if (tmp != NULL) { @@ -68,13 +68,13 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p) } } - if (_PyObject_LookupAttr(p, _Py_ID(__qualname__), &qualname) < 0) { + if (_PyObject_LookupAttr(p, &_Py_ID(__qualname__), &qualname) < 0) { goto done; } if (qualname == NULL) { goto use_repr; } - if (_PyObject_LookupAttr(p, _Py_ID(__module__), &module) < 0) { + if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) { goto done; } if (module == NULL || module == Py_None) { @@ -215,7 +215,7 @@ _Py_make_parameters(PyObject *args) } else { PyObject *subparams; - if (_PyObject_LookupAttr(t, _Py_ID(__parameters__), + if (_PyObject_LookupAttr(t, &_Py_ID(__parameters__), &subparams) < 0) { Py_DECREF(parameters); return NULL; @@ -257,7 +257,7 @@ static PyObject * subs_tvars(PyObject *obj, PyObject *params, PyObject **argitems) { PyObject *subparams; - if (_PyObject_LookupAttr(obj, _Py_ID(__parameters__), &subparams) < 0) { + if (_PyObject_LookupAttr(obj, &_Py_ID(__parameters__), &subparams) < 0) { return NULL; } if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) { diff --git a/Objects/genobject.c b/Objects/genobject.c index c213adf23464028..b34931a95a6807d 100644 --- a/Objects/genobject.c +++ b/Objects/genobject.c @@ -328,7 +328,7 @@ gen_close_iter(PyObject *yf) } else { PyObject *meth; - if (_PyObject_LookupAttr(yf, _Py_ID(close), &meth) < 0) { + if (_PyObject_LookupAttr(yf, &_Py_ID(close), &meth) < 0) { PyErr_WriteUnraisable(yf); } if (meth) { @@ -460,7 +460,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit, } else { /* `yf` is an iterator or a coroutine-like object. */ PyObject *meth; - if (_PyObject_LookupAttr(yf, _Py_ID(throw), &meth) < 0) { + if (_PyObject_LookupAttr(yf, &_Py_ID(throw), &meth) < 0) { Py_DECREF(yf); return NULL; } diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 9a139e50b6d1ce3..1732a037600c9e9 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -104,10 +104,10 @@ static PyObject * iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq != NULL) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)), it->it_seq, it->it_index); else - return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter))); } PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); @@ -243,10 +243,10 @@ static PyObject * calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_callable != NULL && it->it_sentinel != NULL) - return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(_Py_ID(iter)), + return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(&_Py_ID(iter)), it->it_callable, it->it_sentinel); else - return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter))); } static PyMethodDef calliter_methods[] = { diff --git a/Objects/listobject.c b/Objects/listobject.c index 698457939fe0742..1ba1c1b053143bd 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -3511,13 +3511,13 @@ listiter_reduce_general(void *_it, int forward) if (forward) { listiterobject *it = (listiterobject *)_it; if (it->it_seq) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)), it->it_seq, it->it_index); } } else { listreviterobject *it = (listreviterobject *)_it; if (it->it_seq) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(reversed)), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(reversed)), it->it_seq, it->it_index); } } @@ -3525,5 +3525,5 @@ listiter_reduce_general(void *_it, int forward) list = PyList_New(0); if (list == NULL) return NULL; - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list); } diff --git a/Objects/longobject.c b/Objects/longobject.c index 1f5082917df609a..3438906d842758a 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -5772,9 +5772,9 @@ int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder, if (byteorder == NULL) little_endian = 0; - else if (_PyUnicode_Equal(byteorder, _Py_ID(little))) + else if (_PyUnicode_Equal(byteorder, &_Py_ID(little))) little_endian = 1; - else if (_PyUnicode_Equal(byteorder, _Py_ID(big))) + else if (_PyUnicode_Equal(byteorder, &_Py_ID(big))) little_endian = 0; else { PyErr_SetString(PyExc_ValueError, @@ -5834,9 +5834,9 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj, if (byteorder == NULL) little_endian = 0; - else if (_PyUnicode_Equal(byteorder, _Py_ID(little))) + else if (_PyUnicode_Equal(byteorder, &_Py_ID(little))) little_endian = 1; - else if (_PyUnicode_Equal(byteorder, _Py_ID(big))) + else if (_PyUnicode_Equal(byteorder, &_Py_ID(big))) little_endian = 0; else { PyErr_SetString(PyExc_ValueError, diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 912594b5bc09b21..93fac22ec437c1f 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -182,7 +182,7 @@ meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored)) if (m->m_self == NULL || PyModule_Check(m->m_self)) return PyUnicode_FromString(m->m_ml->ml_name); - return Py_BuildValue("N(Os)", _PyEval_GetBuiltin(_Py_ID(getattr)), + return Py_BuildValue("N(Os)", _PyEval_GetBuiltin(&_Py_ID(getattr)), m->m_self, m->m_ml->ml_name); } @@ -227,7 +227,7 @@ meth_get__qualname__(PyCFunctionObject *m, void *closure) type = PyType_Check(m->m_self) ? m->m_self : (PyObject*)Py_TYPE(m->m_self); - type_qualname = PyObject_GetAttr(type, _Py_ID(__qualname__)); + type_qualname = PyObject_GetAttr(type, &_Py_ID(__qualname__)); if (type_qualname == NULL) return NULL; diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index 626a669d4990a64..bd5e5611ec27e0c 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -58,15 +58,15 @@ module_init_dict(PyModuleObject *mod, PyObject *md_dict, if (doc == NULL) doc = Py_None; - if (PyDict_SetItem(md_dict, _Py_ID(__name__), name) != 0) + if (PyDict_SetItem(md_dict, &_Py_ID(__name__), name) != 0) return -1; - if (PyDict_SetItem(md_dict, _Py_ID(__doc__), doc) != 0) + if (PyDict_SetItem(md_dict, &_Py_ID(__doc__), doc) != 0) return -1; - if (PyDict_SetItem(md_dict, _Py_ID(__package__), Py_None) != 0) + if (PyDict_SetItem(md_dict, &_Py_ID(__package__), Py_None) != 0) return -1; - if (PyDict_SetItem(md_dict, _Py_ID(__loader__), Py_None) != 0) + if (PyDict_SetItem(md_dict, &_Py_ID(__loader__), Py_None) != 0) return -1; - if (PyDict_SetItem(md_dict, _Py_ID(__spec__), Py_None) != 0) + if (PyDict_SetItem(md_dict, &_Py_ID(__spec__), Py_None) != 0) return -1; if (PyUnicode_CheckExact(name)) { Py_INCREF(name); @@ -464,7 +464,7 @@ PyModule_SetDocString(PyObject *m, const char *doc) PyObject *v; v = PyUnicode_FromString(doc); - if (v == NULL || PyObject_SetAttr(m, _Py_ID(__doc__), v) != 0) { + if (v == NULL || PyObject_SetAttr(m, &_Py_ID(__doc__), v) != 0) { Py_XDECREF(v); return -1; } @@ -493,7 +493,7 @@ PyModule_GetNameObject(PyObject *m) } d = ((PyModuleObject *)m)->md_dict; if (d == NULL || !PyDict_Check(d) || - (name = PyDict_GetItemWithError(d, _Py_ID(__name__))) == NULL || + (name = PyDict_GetItemWithError(d, &_Py_ID(__name__))) == NULL || !PyUnicode_Check(name)) { if (!PyErr_Occurred()) { @@ -526,7 +526,7 @@ PyModule_GetFilenameObject(PyObject *m) } d = ((PyModuleObject *)m)->md_dict; if (d == NULL || - (fileobj = PyDict_GetItemWithError(d, _Py_ID(__file__))) == NULL || + (fileobj = PyDict_GetItemWithError(d, &_Py_ID(__file__))) == NULL || !PyUnicode_Check(fileobj)) { if (!PyErr_Occurred()) { @@ -715,7 +715,7 @@ int _PyModuleSpec_IsInitializing(PyObject *spec) { if (spec != NULL) { - PyObject *value = PyObject_GetAttr(spec, _Py_ID(_initializing)); + PyObject *value = PyObject_GetAttr(spec, &_Py_ID(_initializing)); if (value != NULL) { int initializing = PyObject_IsTrue(value); Py_DECREF(value); @@ -738,7 +738,7 @@ _PyModuleSpec_IsUninitializedSubmodule(PyObject *spec, PyObject *name) return 0; } - PyObject *value = PyObject_GetAttr(spec, _Py_ID(_uninitialized_submodules)); + PyObject *value = PyObject_GetAttr(spec, &_Py_ID(_uninitialized_submodules)); if (value == NULL) { return 0; } @@ -761,17 +761,17 @@ module_getattro(PyModuleObject *m, PyObject *name) } PyErr_Clear(); assert(m->md_dict != NULL); - getattr = PyDict_GetItemWithError(m->md_dict, _Py_ID(__getattr__)); + getattr = PyDict_GetItemWithError(m->md_dict, &_Py_ID(__getattr__)); if (getattr) { return PyObject_CallOneArg(getattr, name); } if (PyErr_Occurred()) { return NULL; } - mod_name = PyDict_GetItemWithError(m->md_dict, _Py_ID(__name__)); + mod_name = PyDict_GetItemWithError(m->md_dict, &_Py_ID(__name__)); if (mod_name && PyUnicode_Check(mod_name)) { Py_INCREF(mod_name); - PyObject *spec = PyDict_GetItemWithError(m->md_dict, _Py_ID(__spec__)); + PyObject *spec = PyDict_GetItemWithError(m->md_dict, &_Py_ID(__spec__)); if (spec == NULL && PyErr_Occurred()) { Py_DECREF(mod_name); return NULL; @@ -847,11 +847,11 @@ static PyObject * module_dir(PyObject *self, PyObject *args) { PyObject *result = NULL; - PyObject *dict = PyObject_GetAttr(self, _Py_ID(__dict__)); + PyObject *dict = PyObject_GetAttr(self, &_Py_ID(__dict__)); if (dict != NULL) { if (PyDict_Check(dict)) { - PyObject *dirfunc = PyDict_GetItemWithError(dict, _Py_ID(__dir__)); + PyObject *dirfunc = PyDict_GetItemWithError(dict, &_Py_ID(__dir__)); if (dirfunc) { result = _PyObject_CallNoArgs(dirfunc); } @@ -877,7 +877,7 @@ static PyMethodDef module_methods[] = { static PyObject * module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) { - PyObject *dict = PyObject_GetAttr((PyObject *)m, _Py_ID(__dict__)); + PyObject *dict = PyObject_GetAttr((PyObject *)m, &_Py_ID(__dict__)); if ((dict == NULL) || !PyDict_Check(dict)) { PyErr_Format(PyExc_TypeError, ".__dict__ is not a dictionary"); @@ -887,8 +887,8 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) PyObject *annotations; /* there's no _PyDict_GetItemId without WithError, so let's LBYL. */ - if (PyDict_Contains(dict, _Py_ID(__annotations__))) { - annotations = PyDict_GetItemWithError(dict, _Py_ID(__annotations__)); + if (PyDict_Contains(dict, &_Py_ID(__annotations__))) { + annotations = PyDict_GetItemWithError(dict, &_Py_ID(__annotations__)); /* ** _PyDict_GetItemIdWithError could still fail, ** for instance with a well-timed Ctrl-C or a MemoryError. @@ -901,7 +901,7 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored)) annotations = PyDict_New(); if (annotations) { int result = PyDict_SetItem( - dict, _Py_ID(__annotations__), annotations); + dict, &_Py_ID(__annotations__), annotations); if (result) { Py_CLEAR(annotations); } @@ -915,7 +915,7 @@ static int module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignored)) { int ret = -1; - PyObject *dict = PyObject_GetAttr((PyObject *)m, _Py_ID(__dict__)); + PyObject *dict = PyObject_GetAttr((PyObject *)m, &_Py_ID(__dict__)); if ((dict == NULL) || !PyDict_Check(dict)) { PyErr_Format(PyExc_TypeError, ".__dict__ is not a dictionary"); @@ -924,17 +924,17 @@ module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignor if (value != NULL) { /* set */ - ret = PyDict_SetItem(dict, _Py_ID(__annotations__), value); + ret = PyDict_SetItem(dict, &_Py_ID(__annotations__), value); goto exit; } /* delete */ - if (!PyDict_Contains(dict, _Py_ID(__annotations__))) { + if (!PyDict_Contains(dict, &_Py_ID(__annotations__))) { PyErr_Format(PyExc_AttributeError, "__annotations__"); goto exit; } - ret = PyDict_DelItem(dict, _Py_ID(__annotations__)); + ret = PyDict_DelItem(dict, &_Py_ID(__annotations__)); exit: Py_XDECREF(dict); diff --git a/Objects/object.c b/Objects/object.c index 2b7ae16aa7d48dc..3044c862fb9dac6 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -557,7 +557,7 @@ PyObject_Bytes(PyObject *v) return v; } - func = _PyObject_LookupSpecial(v, _Py_ID(__bytes__)); + func = _PyObject_LookupSpecial(v, &_Py_ID(__bytes__)); if (func != NULL) { result = _PyObject_CallNoArgs(func); Py_DECREF(func); @@ -597,7 +597,7 @@ _PyObject_FunctionStr(PyObject *x) { assert(!PyErr_Occurred()); PyObject *qualname; - int ret = _PyObject_LookupAttr(x, _Py_ID(__qualname__), &qualname); + int ret = _PyObject_LookupAttr(x, &_Py_ID(__qualname__), &qualname); if (qualname == NULL) { if (ret < 0) { return NULL; @@ -606,9 +606,9 @@ _PyObject_FunctionStr(PyObject *x) } PyObject *module; PyObject *result = NULL; - ret = _PyObject_LookupAttr(x, _Py_ID(__module__), &module); + ret = _PyObject_LookupAttr(x, &_Py_ID(__module__), &module); if (module != NULL && module != Py_None) { - ret = PyObject_RichCompareBool(module, _Py_ID(builtins), Py_NE); + ret = PyObject_RichCompareBool(module, &_Py_ID(builtins), Py_NE); if (ret < 0) { // error goto done; @@ -846,7 +846,7 @@ _PyObject_IsAbstract(PyObject *obj) if (obj == NULL) return 0; - res = _PyObject_LookupAttr(obj, _Py_ID(__isabstractmethod__), &isabstract); + res = _PyObject_LookupAttr(obj, &_Py_ID(__isabstractmethod__), &isabstract); if (res > 0) { res = PyObject_IsTrue(isabstract); Py_DECREF(isabstract); @@ -887,8 +887,8 @@ set_attribute_error_context(PyObject* v, PyObject* name) PyErr_Fetch(&type, &value, &traceback); PyErr_NormalizeException(&type, &value, &traceback); if (PyErr_GivenExceptionMatches(value, PyExc_AttributeError) && - (PyObject_SetAttr(value, _Py_ID(name), name) || - PyObject_SetAttr(value, _Py_ID(obj), v))) { + (PyObject_SetAttr(value, &_Py_ID(name), name) || + PyObject_SetAttr(value, &_Py_ID(obj), v))) { return 1; } PyErr_Restore(type, value, traceback); @@ -1555,7 +1555,7 @@ static PyObject * _dir_object(PyObject *obj) { PyObject *result, *sorted; - PyObject *dirfunc = _PyObject_LookupSpecial(obj, _Py_ID(__dir__)); + PyObject *dirfunc = _PyObject_LookupSpecial(obj, &_Py_ID(__dir__)); assert(obj != NULL); if (dirfunc == NULL) { @@ -2134,7 +2134,7 @@ Py_ReprEnter(PyObject *obj) early on startup. */ if (dict == NULL) return 0; - list = PyDict_GetItemWithError(dict, _Py_ID(Py_Repr)); + list = PyDict_GetItemWithError(dict, &_Py_ID(Py_Repr)); if (list == NULL) { if (PyErr_Occurred()) { return -1; @@ -2142,7 +2142,7 @@ Py_ReprEnter(PyObject *obj) list = PyList_New(0); if (list == NULL) return -1; - if (PyDict_SetItem(dict, _Py_ID(Py_Repr), list) < 0) + if (PyDict_SetItem(dict, &_Py_ID(Py_Repr), list) < 0) return -1; Py_DECREF(list); } @@ -2170,7 +2170,7 @@ Py_ReprLeave(PyObject *obj) if (dict == NULL) goto finally; - list = PyDict_GetItemWithError(dict, _Py_ID(Py_Repr)); + list = PyDict_GetItemWithError(dict, &_Py_ID(Py_Repr)); if (list == NULL || !PyList_Check(list)) goto finally; diff --git a/Objects/odictobject.c b/Objects/odictobject.c index a3f6846a74b68cb..c207593ab79f722 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -951,7 +951,7 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) PyObject *items_iter, *items, *args = NULL; /* capture any instance state */ - dict = PyObject_GetAttr((PyObject *)od, _Py_ID(__dict__)); + dict = PyObject_GetAttr((PyObject *)od, &_Py_ID(__dict__)); if (dict == NULL) goto Done; else { @@ -970,7 +970,7 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored)) if (args == NULL) goto Done; - items = PyObject_CallMethodNoArgs((PyObject *)od, _Py_ID(items)); + items = PyObject_CallMethodNoArgs((PyObject *)od, &_Py_ID(items)); if (items == NULL) goto Done; @@ -1429,7 +1429,7 @@ odict_repr(PyODictObject *self) } else { PyObject *items = PyObject_CallMethodNoArgs( - (PyObject *)self, _Py_ID(items)); + (PyObject *)self, &_Py_ID(items)); if (items == NULL) goto Done; pieces = PySequence_List(items); @@ -1817,7 +1817,7 @@ odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list); } static PyMethodDef odictiter_methods[] = { @@ -2214,7 +2214,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg) return res; } PyObject *func; - if (_PyObject_LookupAttr(arg, _Py_ID(keys), &func) < 0) { + if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) { return -1; } if (func != NULL) { @@ -2246,7 +2246,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg) } return 0; } - if (_PyObject_LookupAttr(arg, _Py_ID(items), &func) < 0) { + if (_PyObject_LookupAttr(arg, &_Py_ID(items), &func) < 0) { return -1; } if (func != NULL) { diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 56f4deb68e19324..5d583b2edf0e941 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -812,7 +812,7 @@ rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored)) goto err; /* return the result */ return Py_BuildValue( - "N(N)l", _PyEval_GetBuiltin(_Py_ID(iter)), range, r->index); + "N(N)l", _PyEval_GetBuiltin(&_Py_ID(iter)), range, r->index); err: Py_XDECREF(start); Py_XDECREF(stop); @@ -966,7 +966,7 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored)) /* return the result */ return Py_BuildValue( - "N(N)O", _PyEval_GetBuiltin(_Py_ID(iter)), range, r->index); + "N(N)O", _PyEval_GetBuiltin(&_Py_ID(iter)), range, r->index); } static PyObject * diff --git a/Objects/setobject.c b/Objects/setobject.c index 78e310a4768b82c..fe124945b1c7e00 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -780,7 +780,7 @@ setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored)) if (list == NULL) { return NULL; } - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), list); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list); } PyDoc_STRVAR(reduce_doc, "Return state information for pickling."); @@ -1912,7 +1912,7 @@ set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored)) args = PyTuple_Pack(1, keys); if (args == NULL) goto done; - if (_PyObject_LookupAttr((PyObject *)so, _Py_ID(__dict__), &dict) < 0) { + if (_PyObject_LookupAttr((PyObject *)so, &_Py_ID(__dict__), &dict) < 0) { goto done; } if (dict == NULL) { diff --git a/Objects/structseq.c b/Objects/structseq.c index ae05d9c0af77a6f..229e3d893ff6aa8 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -37,13 +37,13 @@ get_type_attr_as_size(PyTypeObject *tp, PyObject *name) #define VISIBLE_SIZE(op) Py_SIZE(op) #define VISIBLE_SIZE_TP(tp) \ - get_type_attr_as_size(tp, _Py_ID(n_sequence_fields)) + get_type_attr_as_size(tp, &_Py_ID(n_sequence_fields)) #define REAL_SIZE_TP(tp) \ - get_type_attr_as_size(tp, _Py_ID(n_fields)) + get_type_attr_as_size(tp, &_Py_ID(n_fields)) #define REAL_SIZE(op) REAL_SIZE_TP(Py_TYPE(op)) #define UNNAMED_FIELDS_TP(tp) \ - get_type_attr_as_size(tp, _Py_ID(n_unnamed_fields)) + get_type_attr_as_size(tp, &_Py_ID(n_unnamed_fields)) #define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP(Py_TYPE(op)) diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 8c229c4d35db226..ec9147cdcfedffa 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -1194,10 +1194,10 @@ static PyObject * tupleiter_reduce(tupleiterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq) - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)), it->it_seq, it->it_index); else - return Py_BuildValue("N(())", _PyEval_GetBuiltin(_Py_ID(iter))); + return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter))); } static PyObject * diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 589556a28dae35d..16e78e9877bd9aa 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -151,7 +151,7 @@ _PyType_CheckConsistency(PyTypeObject *type) if (type->tp_flags & Py_TPFLAGS_DISALLOW_INSTANTIATION) { CHECK(type->tp_new == NULL); - CHECK(PyDict_Contains(type->tp_dict, _Py_ID(__new__)) == 0); + CHECK(PyDict_Contains(type->tp_dict, &_Py_ID(__new__)) == 0); } return 1; @@ -350,11 +350,11 @@ type_mro_modified(PyTypeObject *type, PyObject *bases) { if (custom) { mro_meth = lookup_maybe_method( - (PyObject *)type, _Py_ID(mro), &unbound); + (PyObject *)type, &_Py_ID(mro), &unbound); if (mro_meth == NULL) goto clear; type_mro_meth = lookup_maybe_method( - (PyObject *)&PyType_Type, _Py_ID(mro), &unbound); + (PyObject *)&PyType_Type, &_Py_ID(mro), &unbound); if (type_mro_meth == NULL) goto clear; if (mro_meth != type_mro_meth) @@ -548,7 +548,7 @@ type_module(PyTypeObject *type, void *context) PyObject *mod; if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { - mod = PyDict_GetItemWithError(type->tp_dict, _Py_ID(__module__)); + mod = PyDict_GetItemWithError(type->tp_dict, &_Py_ID(__module__)); if (mod == NULL) { if (!PyErr_Occurred()) { PyErr_Format(PyExc_AttributeError, "__module__"); @@ -566,7 +566,7 @@ type_module(PyTypeObject *type, void *context) PyUnicode_InternInPlace(&mod); } else { - mod = _Py_ID(builtins); + mod = &_Py_ID(builtins); Py_INCREF(mod); } } @@ -581,7 +581,7 @@ type_set_module(PyTypeObject *type, PyObject *value, void *context) PyType_Modified(type); - return PyDict_SetItem(type->tp_dict, _Py_ID(__module__), value); + return PyDict_SetItem(type->tp_dict, &_Py_ID(__module__), value); } static PyObject * @@ -592,10 +592,10 @@ type_abstractmethods(PyTypeObject *type, void *context) that. */ if (type != &PyType_Type) mod = PyDict_GetItemWithError(type->tp_dict, - _Py_ID(__abstractmethods__)); + &_Py_ID(__abstractmethods__)); if (!mod) { if (!PyErr_Occurred()) { - PyErr_SetObject(PyExc_AttributeError, _Py_ID(__abstractmethods__)); + PyErr_SetObject(PyExc_AttributeError, &_Py_ID(__abstractmethods__)); } return NULL; } @@ -615,13 +615,13 @@ type_set_abstractmethods(PyTypeObject *type, PyObject *value, void *context) abstract = PyObject_IsTrue(value); if (abstract < 0) return -1; - res = PyDict_SetItem(type->tp_dict, _Py_ID(__abstractmethods__), value); + res = PyDict_SetItem(type->tp_dict, &_Py_ID(__abstractmethods__), value); } else { abstract = 0; - res = PyDict_DelItem(type->tp_dict, _Py_ID(__abstractmethods__)); + res = PyDict_DelItem(type->tp_dict, &_Py_ID(__abstractmethods__)); if (res && PyErr_ExceptionMatches(PyExc_KeyError)) { - PyErr_SetObject(PyExc_AttributeError, _Py_ID(__abstractmethods__)); + PyErr_SetObject(PyExc_AttributeError, &_Py_ID(__abstractmethods__)); return -1; } } @@ -875,7 +875,7 @@ type_get_doc(PyTypeObject *type, void *context) if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) { return _PyType_GetDocFromInternalDoc(type->tp_name, type->tp_doc); } - result = PyDict_GetItemWithError(type->tp_dict, _Py_ID(__doc__)); + result = PyDict_GetItemWithError(type->tp_dict, &_Py_ID(__doc__)); if (result == NULL) { if (!PyErr_Occurred()) { result = Py_None; @@ -904,7 +904,7 @@ type_set_doc(PyTypeObject *type, PyObject *value, void *context) if (!check_set_special_type_attr(type, value, "__doc__")) return -1; PyType_Modified(type); - return PyDict_SetItem(type->tp_dict, _Py_ID(__doc__), value); + return PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), value); } static PyObject * @@ -917,9 +917,9 @@ type_get_annotations(PyTypeObject *type, void *context) PyObject *annotations; /* there's no _PyDict_GetItemId without WithError, so let's LBYL. */ - if (PyDict_Contains(type->tp_dict, _Py_ID(__annotations__))) { + if (PyDict_Contains(type->tp_dict, &_Py_ID(__annotations__))) { annotations = PyDict_GetItemWithError( - type->tp_dict, _Py_ID(__annotations__)); + type->tp_dict, &_Py_ID(__annotations__)); /* ** PyDict_GetItemWithError could still fail, ** for instance with a well-timed Ctrl-C or a MemoryError. @@ -937,7 +937,7 @@ type_get_annotations(PyTypeObject *type, void *context) annotations = PyDict_New(); if (annotations) { int result = PyDict_SetItem( - type->tp_dict, _Py_ID(__annotations__), annotations); + type->tp_dict, &_Py_ID(__annotations__), annotations); if (result) { Py_CLEAR(annotations); } else { @@ -961,14 +961,14 @@ type_set_annotations(PyTypeObject *type, PyObject *value, void *context) int result; if (value != NULL) { /* set */ - result = PyDict_SetItem(type->tp_dict, _Py_ID(__annotations__), value); + result = PyDict_SetItem(type->tp_dict, &_Py_ID(__annotations__), value); } else { /* delete */ - if (!PyDict_Contains(type->tp_dict, _Py_ID(__annotations__))) { + if (!PyDict_Contains(type->tp_dict, &_Py_ID(__annotations__))) { PyErr_Format(PyExc_AttributeError, "__annotations__"); return -1; } - result = PyDict_DelItem(type->tp_dict, _Py_ID(__annotations__)); + result = PyDict_DelItem(type->tp_dict, &_Py_ID(__annotations__)); } if (result == 0) { @@ -1049,7 +1049,7 @@ type_repr(PyTypeObject *type) return NULL; } - if (mod != NULL && !_PyUnicode_Equal(mod, _Py_ID(builtins))) + if (mod != NULL && !_PyUnicode_Equal(mod, &_Py_ID(builtins))) rtn = PyUnicode_FromFormat("", mod, name); else rtn = PyUnicode_FromFormat("", type->tp_name); @@ -1753,7 +1753,7 @@ static PyObject * class_name(PyObject *cls) { PyObject *name; - if (_PyObject_LookupAttr(cls, _Py_ID(__name__), &name) == 0) { + if (_PyObject_LookupAttr(cls, &_Py_ID(__name__), &name) == 0) { name = PyObject_Repr(cls); } return name; @@ -2077,7 +2077,7 @@ mro_invoke(PyTypeObject *type) if (custom) { int unbound; PyObject *mro_meth = lookup_method( - (PyObject *)type, _Py_ID(mro), &unbound); + (PyObject *)type, &_Py_ID(mro), &unbound); if (mro_meth == NULL) return NULL; mro_result = call_unbound_noarg(unbound, mro_meth, (PyObject *)type); @@ -2292,7 +2292,7 @@ get_dict_descriptor(PyTypeObject *type) { PyObject *descr; - descr = _PyType_Lookup(type, _Py_ID(__dict__)); + descr = _PyType_Lookup(type, &_Py_ID(__dict__)); if (descr == NULL || !PyDescr_IsData(descr)) return NULL; @@ -2541,7 +2541,7 @@ type_new_visit_slots(type_new_ctx *ctx) return -1; } assert(PyUnicode_Check(name)); - if (_PyUnicode_Equal(name, _Py_ID(__dict__))) { + if (_PyUnicode_Equal(name, &_Py_ID(__dict__))) { if (!ctx->may_add_dict || ctx->add_dict != 0) { PyErr_SetString(PyExc_TypeError, "__dict__ slot disallowed: " @@ -2550,7 +2550,7 @@ type_new_visit_slots(type_new_ctx *ctx) } ctx->add_dict++; } - if (_PyUnicode_Equal(name, _Py_ID(__weakref__))) { + if (_PyUnicode_Equal(name, &_Py_ID(__weakref__))) { if (!ctx->may_add_weak || ctx->add_weak != 0) { PyErr_SetString(PyExc_TypeError, "__weakref__ slot disallowed: " @@ -2584,8 +2584,8 @@ type_new_copy_slots(type_new_ctx *ctx, PyObject *dict) Py_ssize_t j = 0; for (Py_ssize_t i = 0; i < nslot; i++) { PyObject *slot = PyTuple_GET_ITEM(slots, i); - if ((ctx->add_dict && _PyUnicode_Equal(slot, _Py_ID(__dict__))) || - (ctx->add_weak && _PyUnicode_Equal(slot, _Py_ID(__weakref__)))) + if ((ctx->add_dict && _PyUnicode_Equal(slot, &_Py_ID(__dict__))) || + (ctx->add_weak && _PyUnicode_Equal(slot, &_Py_ID(__weakref__)))) { continue; } @@ -2604,8 +2604,8 @@ type_new_copy_slots(type_new_ctx *ctx, PyObject *dict) /* CPython inserts __qualname__ and __classcell__ (when needed) into the namespace when creating a class. They will be deleted below so won't act as class variables. */ - if (!_PyUnicode_Equal(slot, _Py_ID(__qualname__)) && - !_PyUnicode_Equal(slot, _Py_ID(__classcell__))) + if (!_PyUnicode_Equal(slot, &_Py_ID(__qualname__)) && + !_PyUnicode_Equal(slot, &_Py_ID(__classcell__))) { PyErr_Format(PyExc_ValueError, "%R in __slots__ conflicts with class variable", @@ -2800,7 +2800,7 @@ type_new_set_name(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_set_module(PyTypeObject *type) { - int r = PyDict_Contains(type->tp_dict, _Py_ID(__module__)); + int r = PyDict_Contains(type->tp_dict, &_Py_ID(__module__)); if (r < 0) { return -1; } @@ -2813,7 +2813,7 @@ type_new_set_module(PyTypeObject *type) return 0; } - PyObject *module = PyDict_GetItemWithError(globals, _Py_ID(__name__)); + PyObject *module = PyDict_GetItemWithError(globals, &_Py_ID(__name__)); if (module == NULL) { if (PyErr_Occurred()) { return -1; @@ -2821,7 +2821,7 @@ type_new_set_module(PyTypeObject *type) return 0; } - if (PyDict_SetItem(type->tp_dict, _Py_ID(__module__), module) < 0) { + if (PyDict_SetItem(type->tp_dict, &_Py_ID(__module__), module) < 0) { return -1; } return 0; @@ -2835,7 +2835,7 @@ type_new_set_ht_name(PyTypeObject *type) { PyHeapTypeObject *et = (PyHeapTypeObject *)type; PyObject *qualname = PyDict_GetItemWithError( - type->tp_dict, _Py_ID(__qualname__)); + type->tp_dict, &_Py_ID(__qualname__)); if (qualname != NULL) { if (!PyUnicode_Check(qualname)) { PyErr_Format(PyExc_TypeError, @@ -2844,7 +2844,7 @@ type_new_set_ht_name(PyTypeObject *type) return -1; } et->ht_qualname = Py_NewRef(qualname); - if (PyDict_DelItem(type->tp_dict, _Py_ID(__qualname__)) < 0) { + if (PyDict_DelItem(type->tp_dict, &_Py_ID(__qualname__)) < 0) { return -1; } } @@ -2864,7 +2864,7 @@ type_new_set_ht_name(PyTypeObject *type) static int type_new_set_doc(PyTypeObject *type) { - PyObject *doc = PyDict_GetItemWithError(type->tp_dict, _Py_ID(__doc__)); + PyObject *doc = PyDict_GetItemWithError(type->tp_dict, &_Py_ID(__doc__)); if (doc == NULL) { if (PyErr_Occurred()) { return -1; @@ -3034,7 +3034,7 @@ static int type_new_set_classcell(PyTypeObject *type) { PyObject *cell = PyDict_GetItemWithError( - type->tp_dict, _Py_ID(__classcell__)); + type->tp_dict, &_Py_ID(__classcell__)); if (cell == NULL) { if (PyErr_Occurred()) { return -1; @@ -3051,7 +3051,7 @@ type_new_set_classcell(PyTypeObject *type) } (void)PyCell_Set(cell, (PyObject *) type); - if (PyDict_DelItem(type->tp_dict, _Py_ID(__classcell__)) < 0) { + if (PyDict_DelItem(type->tp_dict, &_Py_ID(__classcell__)) < 0) { return -1; } return 0; @@ -3079,16 +3079,16 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type) /* Special-case __new__: if it's a plain function, make it a static function */ - if (type_new_staticmethod(type, _Py_ID(__new__)) < 0) { + if (type_new_staticmethod(type, &_Py_ID(__new__)) < 0) { return -1; } /* Special-case __init_subclass__ and __class_getitem__: if they are plain functions, make them classmethods */ - if (type_new_classmethod(type, _Py_ID(__init_subclass__)) < 0) { + if (type_new_classmethod(type, &_Py_ID(__init_subclass__)) < 0) { return -1; } - if (type_new_classmethod(type, _Py_ID(__class_getitem__)) < 0) { + if (type_new_classmethod(type, &_Py_ID(__class_getitem__)) < 0) { return -1; } @@ -3108,7 +3108,7 @@ type_new_set_attrs(const type_new_ctx *ctx, PyTypeObject *type) static int type_new_get_slots(type_new_ctx *ctx, PyObject *dict) { - PyObject *slots = PyDict_GetItemWithError(dict, _Py_ID(__slots__)); + PyObject *slots = PyDict_GetItemWithError(dict, &_Py_ID(__slots__)); if (slots == NULL) { if (PyErr_Occurred()) { return -1; @@ -3237,7 +3237,7 @@ type_new_get_bases(type_new_ctx *ctx, PyObject **type) continue; } PyObject *mro_entries; - if (_PyObject_LookupAttr(base, _Py_ID(__mro_entries__), + if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__), &mro_entries) < 0) { return -1; } @@ -3587,7 +3587,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) PyObject *__doc__ = PyUnicode_FromString(_PyType_DocWithoutSignature(type->tp_name, type->tp_doc)); if (!__doc__) goto fail; - r = PyDict_SetItem(type->tp_dict, _Py_ID(__doc__), __doc__); + r = PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), __doc__); Py_DECREF(__doc__); if (r < 0) goto fail; @@ -3605,7 +3605,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) } /* Set type.__module__ */ - r = PyDict_Contains(type->tp_dict, _Py_ID(__module__)); + r = PyDict_Contains(type->tp_dict, &_Py_ID(__module__)); if (r < 0) { goto fail; } @@ -3617,7 +3617,7 @@ PyType_FromModuleAndSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) if (modname == NULL) { goto fail; } - r = PyDict_SetItem(type->tp_dict, _Py_ID(__module__), modname); + r = PyDict_SetItem(type->tp_dict, &_Py_ID(__module__), modname); Py_DECREF(modname); if (r != 0) goto fail; @@ -4202,7 +4202,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass) assert(aclass); /* Merge in the type's dict (if any). */ - if (_PyObject_LookupAttr(aclass, _Py_ID(__dict__), &classdict) < 0) { + if (_PyObject_LookupAttr(aclass, &_Py_ID(__dict__), &classdict) < 0) { return -1; } if (classdict != NULL) { @@ -4213,7 +4213,7 @@ merge_class_dict(PyObject *dict, PyObject *aclass) } /* Recursively merge in the base types' (if any) dicts. */ - if (_PyObject_LookupAttr(aclass, _Py_ID(__bases__), &bases) < 0) { + if (_PyObject_LookupAttr(aclass, &_Py_ID(__bases__), &bases) < 0) { return -1; } if (bases != NULL) { @@ -4551,7 +4551,7 @@ object_new(PyTypeObject *type, PyObject *args, PyObject *kwds) Py_DECREF(sorted_methods); return NULL; } - joined = PyUnicode_Join(_Py_STR(comma_sep), sorted_methods); + joined = PyUnicode_Join(&_Py_STR(comma_sep), sorted_methods); method_count = PyObject_Length(sorted_methods); Py_DECREF(sorted_methods); if (joined == NULL) @@ -4604,7 +4604,7 @@ object_repr(PyObject *self) Py_XDECREF(mod); return NULL; } - if (mod != NULL && !_PyUnicode_Equal(mod, _Py_ID(builtins))) + if (mod != NULL && !_PyUnicode_Equal(mod, &_Py_ID(builtins))) rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self); else rtn = PyUnicode_FromFormat("<%s object at %p>", @@ -4902,14 +4902,14 @@ import_copyreg(void) by storing a reference to the cached module in a static variable, but this broke when multiple embedded interpreters were in use (see issue #17408 and #19088). */ - PyObject *copyreg_module = PyImport_GetModule(_Py_ID(copyreg)); + PyObject *copyreg_module = PyImport_GetModule(&_Py_ID(copyreg)); if (copyreg_module != NULL) { return copyreg_module; } if (PyErr_Occurred()) { return NULL; } - return PyImport_Import(_Py_ID(copyreg)); + return PyImport_Import(&_Py_ID(copyreg)); } static PyObject * @@ -4921,7 +4921,7 @@ _PyType_GetSlotNames(PyTypeObject *cls) assert(PyType_Check(cls)); /* Get the slot names from the cache in the class if possible. */ - slotnames = PyDict_GetItemWithError(cls->tp_dict, _Py_ID(__slotnames__)); + slotnames = PyDict_GetItemWithError(cls->tp_dict, &_Py_ID(__slotnames__)); if (slotnames != NULL) { if (slotnames != Py_None && !PyList_Check(slotnames)) { PyErr_Format(PyExc_TypeError, @@ -4948,7 +4948,7 @@ _PyType_GetSlotNames(PyTypeObject *cls) by this class and its bases. This function will cache the result in __slotnames__. */ slotnames = PyObject_CallMethodOneArg( - copyreg, _Py_ID(_slotnames), (PyObject *)cls); + copyreg, &_Py_ID(_slotnames), (PyObject *)cls); Py_DECREF(copyreg); if (slotnames == NULL) return NULL; @@ -4969,7 +4969,7 @@ _PyObject_GetState(PyObject *obj, int required) PyObject *state; PyObject *getstate; - if (_PyObject_LookupAttr(obj, _Py_ID(__getstate__), &getstate) < 0) { + if (_PyObject_LookupAttr(obj, &_Py_ID(__getstate__), &getstate) < 0) { return NULL; } if (getstate == NULL) { @@ -5113,7 +5113,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* We first attempt to fetch the arguments for __new__ by calling __getnewargs_ex__ on the object. */ - getnewargs_ex = _PyObject_LookupSpecial(obj, _Py_ID(__getnewargs_ex__)); + getnewargs_ex = _PyObject_LookupSpecial(obj, &_Py_ID(__getnewargs_ex__)); if (getnewargs_ex != NULL) { PyObject *newargs = _PyObject_CallNoArgs(getnewargs_ex); Py_DECREF(getnewargs_ex); @@ -5166,7 +5166,7 @@ _PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs) /* The object does not have __getnewargs_ex__ so we fallback on using __getnewargs__ instead. */ - getnewargs = _PyObject_LookupSpecial(obj, _Py_ID(__getnewargs__)); + getnewargs = _PyObject_LookupSpecial(obj, &_Py_ID(__getnewargs__)); if (getnewargs != NULL) { *args = _PyObject_CallNoArgs(getnewargs); Py_DECREF(getnewargs); @@ -5219,7 +5219,7 @@ _PyObject_GetItemsIter(PyObject *obj, PyObject **listitems, Py_INCREF(*dictitems); } else { - PyObject *items = PyObject_CallMethodNoArgs(obj, _Py_ID(items)); + PyObject *items = PyObject_CallMethodNoArgs(obj, &_Py_ID(items)); if (items == NULL) { Py_CLEAR(*listitems); return -1; @@ -5267,7 +5267,7 @@ reduce_newobj(PyObject *obj) Py_ssize_t i, n; Py_XDECREF(kwargs); - newobj = PyObject_GetAttr(copyreg, _Py_ID(__newobj__)); + newobj = PyObject_GetAttr(copyreg, &_Py_ID(__newobj__)); Py_DECREF(copyreg); if (newobj == NULL) { Py_XDECREF(args); @@ -5291,7 +5291,7 @@ reduce_newobj(PyObject *obj) Py_XDECREF(args); } else if (args != NULL) { - newobj = PyObject_GetAttr(copyreg, _Py_ID(__newobj_ex__)); + newobj = PyObject_GetAttr(copyreg, &_Py_ID(__newobj_ex__)); Py_DECREF(copyreg); if (newobj == NULL) { Py_DECREF(args); @@ -5400,13 +5400,13 @@ object___reduce_ex___impl(PyObject *self, int protocol) if (objreduce == NULL) { objreduce = PyDict_GetItemWithError( - PyBaseObject_Type.tp_dict, _Py_ID(__reduce__)); + PyBaseObject_Type.tp_dict, &_Py_ID(__reduce__)); if (objreduce == NULL && PyErr_Occurred()) { return NULL; } } - if (_PyObject_LookupAttr(self, _Py_ID(__reduce__), &reduce) < 0) { + if (_PyObject_LookupAttr(self, &_Py_ID(__reduce__), &reduce) < 0) { return NULL; } if (reduce != NULL) { @@ -5414,7 +5414,7 @@ object___reduce_ex___impl(PyObject *self, int protocol) int override; cls = (PyObject *) Py_TYPE(self); - clsreduce = PyObject_GetAttr(cls, _Py_ID(__reduce__)); + clsreduce = PyObject_GetAttr(cls, &_Py_ID(__reduce__)); if (clsreduce == NULL) { Py_DECREF(reduce); return NULL; @@ -5522,7 +5522,7 @@ object___dir___impl(PyObject *self) PyObject *itsclass = NULL; /* Get __dict__ (which may or may not be a real dict...) */ - if (_PyObject_LookupAttr(self, _Py_ID(__dict__), &dict) < 0) { + if (_PyObject_LookupAttr(self, &_Py_ID(__dict__), &dict) < 0) { return NULL; } if (dict == NULL) { @@ -5543,7 +5543,7 @@ object___dir___impl(PyObject *self) goto error; /* Merge in attrs reachable from its class. */ - if (_PyObject_LookupAttr(self, _Py_ID(__class__), &itsclass) < 0) { + if (_PyObject_LookupAttr(self, &_Py_ID(__class__), &itsclass) < 0) { goto error; } /* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no @@ -5811,9 +5811,9 @@ overrides_hash(PyTypeObject *type) PyObject *dict = type->tp_dict; assert(dict != NULL); - int r = PyDict_Contains(dict, _Py_ID(__eq__)); + int r = PyDict_Contains(dict, &_Py_ID(__eq__)); if (r == 0) { - r = PyDict_Contains(dict, _Py_ID(__hash__)); + r = PyDict_Contains(dict, &_Py_ID(__hash__)); } return r; } @@ -6128,7 +6128,7 @@ type_ready_set_dict(PyTypeObject *type) static int type_dict_set_doc(PyTypeObject *type) { - int r = PyDict_Contains(type->tp_dict, _Py_ID(__doc__)); + int r = PyDict_Contains(type->tp_dict, &_Py_ID(__doc__)); if (r < 0) { return -1; } @@ -6144,14 +6144,14 @@ type_dict_set_doc(PyTypeObject *type) return -1; } - if (PyDict_SetItem(type->tp_dict, _Py_ID(__doc__), doc) < 0) { + if (PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), doc) < 0) { Py_DECREF(doc); return -1; } Py_DECREF(doc); } else { - if (PyDict_SetItem(type->tp_dict, _Py_ID(__doc__), Py_None) < 0) { + if (PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), Py_None) < 0) { return -1; } } @@ -6299,7 +6299,7 @@ type_ready_set_hash(PyTypeObject *type) return 0; } - int r = PyDict_Contains(type->tp_dict, _Py_ID(__hash__)); + int r = PyDict_Contains(type->tp_dict, &_Py_ID(__hash__)); if (r < 0) { return -1; } @@ -6307,7 +6307,7 @@ type_ready_set_hash(PyTypeObject *type) return 0; } - if (PyDict_SetItem(type->tp_dict, _Py_ID(__hash__), Py_None) < 0) { + if (PyDict_SetItem(type->tp_dict, &_Py_ID(__hash__), Py_None) < 0) { return -1; } type->tp_hash = PyObject_HashNotImplemented; @@ -7124,7 +7124,7 @@ static struct PyMethodDef tp_new_methoddef[] = { static int add_tp_new_wrapper(PyTypeObject *type) { - int r = PyDict_Contains(type->tp_dict, _Py_ID(__new__)); + int r = PyDict_Contains(type->tp_dict, &_Py_ID(__new__)); if (r > 0) { return 0; } @@ -7136,7 +7136,7 @@ add_tp_new_wrapper(PyTypeObject *type) if (func == NULL) { return -1; } - r = PyDict_SetItem(type->tp_dict, _Py_ID(__new__), func); + r = PyDict_SetItem(type->tp_dict, &_Py_ID(__new__), func); Py_DECREF(func); return r; } @@ -7149,7 +7149,7 @@ static PyObject * \ FUNCNAME(PyObject *self) \ { \ PyObject* stack[1] = {self}; \ - return vectorcall_method(_Py_ID(DUNDER), stack, 1); \ + return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \ } #define SLOT1(FUNCNAME, DUNDER, ARG1TYPE) \ @@ -7157,7 +7157,7 @@ static PyObject * \ FUNCNAME(PyObject *self, ARG1TYPE arg1) \ { \ PyObject* stack[2] = {self, arg1}; \ - return vectorcall_method(_Py_ID(DUNDER), stack, 2); \ + return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \ } /* Boolean helper for SLOT1BINFULL(). @@ -7206,14 +7206,14 @@ FUNCNAME(PyObject *self, PyObject *other) \ Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \ PyObject *r; \ if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \ - int ok = method_is_overloaded(self, other, _Py_ID(RDUNDER)); \ + int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \ if (ok < 0) { \ return NULL; \ } \ if (ok) { \ stack[0] = other; \ stack[1] = self; \ - r = vectorcall_maybe(tstate, _Py_ID(RDUNDER), stack, 2); \ + r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \ if (r != Py_NotImplemented) \ return r; \ Py_DECREF(r); \ @@ -7222,7 +7222,7 @@ FUNCNAME(PyObject *self, PyObject *other) \ } \ stack[0] = self; \ stack[1] = other; \ - r = vectorcall_maybe(tstate, _Py_ID(DUNDER), stack, 2); \ + r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \ if (r != Py_NotImplemented || \ Py_IS_TYPE(other, Py_TYPE(self))) \ return r; \ @@ -7231,7 +7231,7 @@ FUNCNAME(PyObject *self, PyObject *other) \ if (do_other) { \ stack[0] = other; \ stack[1] = self; \ - return vectorcall_maybe(tstate, _Py_ID(RDUNDER), stack, 2); \ + return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \ } \ Py_RETURN_NOTIMPLEMENTED; \ } @@ -7243,7 +7243,7 @@ static Py_ssize_t slot_sq_length(PyObject *self) { PyObject* stack[1] = {self}; - PyObject *res = vectorcall_method(_Py_ID(__len__), stack, 1); + PyObject *res = vectorcall_method(&_Py_ID(__len__), stack, 1); Py_ssize_t len; if (res == NULL) @@ -7275,7 +7275,7 @@ slot_sq_item(PyObject *self, Py_ssize_t i) return NULL; } PyObject *stack[2] = {self, ival}; - PyObject *retval = vectorcall_method(_Py_ID(__getitem__), stack, 2); + PyObject *retval = vectorcall_method(&_Py_ID(__getitem__), stack, 2); Py_DECREF(ival); return retval; } @@ -7295,11 +7295,11 @@ slot_sq_ass_item(PyObject *self, Py_ssize_t index, PyObject *value) stack[0] = self; stack[1] = index_obj; if (value == NULL) { - res = vectorcall_method(_Py_ID(__delitem__), stack, 2); + res = vectorcall_method(&_Py_ID(__delitem__), stack, 2); } else { stack[2] = value; - res = vectorcall_method(_Py_ID(__setitem__), stack, 3); + res = vectorcall_method(&_Py_ID(__setitem__), stack, 3); } Py_DECREF(index_obj); @@ -7317,7 +7317,7 @@ slot_sq_contains(PyObject *self, PyObject *value) PyObject *func, *res; int result = -1, unbound; - func = lookup_maybe_method(self, _Py_ID(__contains__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__contains__), &unbound); if (func == Py_None) { Py_DECREF(func); PyErr_Format(PyExc_TypeError, @@ -7355,11 +7355,11 @@ slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value) stack[0] = self; stack[1] = key; if (value == NULL) { - res = vectorcall_method(_Py_ID(__delitem__), stack, 2); + res = vectorcall_method(&_Py_ID(__delitem__), stack, 2); } else { stack[2] = value; - res = vectorcall_method(_Py_ID(__setitem__), stack, 3); + res = vectorcall_method(&_Py_ID(__setitem__), stack, 3); } if (res == NULL) @@ -7390,7 +7390,7 @@ slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus) if (Py_TYPE(self)->tp_as_number != NULL && Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) { PyObject* stack[3] = {self, other, modulus}; - return vectorcall_method(_Py_ID(__pow__), stack, 3); + return vectorcall_method(&_Py_ID(__pow__), stack, 3); } Py_RETURN_NOTIMPLEMENTED; } @@ -7406,13 +7406,13 @@ slot_nb_bool(PyObject *self) int result, unbound; int using_len = 0; - func = lookup_maybe_method(self, _Py_ID(__bool__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__bool__), &unbound); if (func == NULL) { if (PyErr_Occurred()) { return -1; } - func = lookup_maybe_method(self, _Py_ID(__len__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__len__), &unbound); if (func == NULL) { if (PyErr_Occurred()) { return -1; @@ -7456,7 +7456,7 @@ static PyObject * slot_nb_index(PyObject *self) { PyObject *stack[1] = {self}; - return vectorcall_method(_Py_ID(__index__), stack, 1); + return vectorcall_method(&_Py_ID(__index__), stack, 1); } @@ -7479,7 +7479,7 @@ static PyObject * slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2) { PyObject *stack[2] = {self, arg1}; - return vectorcall_method(_Py_ID(__ipow__), stack, 2); + return vectorcall_method(&_Py_ID(__ipow__), stack, 2); } SLOT1(slot_nb_inplace_lshift, __ilshift__, PyObject *) SLOT1(slot_nb_inplace_rshift, __irshift__, PyObject *) @@ -7498,7 +7498,7 @@ slot_tp_repr(PyObject *self) PyObject *func, *res; int unbound; - func = lookup_maybe_method(self, _Py_ID(__repr__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__repr__), &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -7518,7 +7518,7 @@ slot_tp_hash(PyObject *self) Py_ssize_t h; int unbound; - func = lookup_maybe_method(self, _Py_ID(__hash__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__hash__), &unbound); if (func == Py_None) { Py_DECREF(func); @@ -7565,7 +7565,7 @@ slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *meth = lookup_method(self, _Py_ID(__call__), &unbound); + PyObject *meth = lookup_method(self, &_Py_ID(__call__), &unbound); if (meth == NULL) { return NULL; } @@ -7597,7 +7597,7 @@ static PyObject * slot_tp_getattro(PyObject *self, PyObject *name) { PyObject *stack[2] = {self, name}; - return vectorcall_method(_Py_ID(__getattribute__), stack, 2); + return vectorcall_method(&_Py_ID(__getattribute__), stack, 2); } static PyObject * @@ -7629,7 +7629,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) __getattr__, even when the attribute is present. So we use _PyType_Lookup and create the method only when needed, with call_attribute. */ - getattr = _PyType_Lookup(tp, _Py_ID(__getattr__)); + getattr = _PyType_Lookup(tp, &_Py_ID(__getattr__)); if (getattr == NULL) { /* No __getattr__ hook: use a simpler dispatcher */ tp->tp_getattro = slot_tp_getattro; @@ -7641,7 +7641,7 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) __getattr__, even when self has the default __getattribute__ method. So we use _PyType_Lookup and create the method only when needed, with call_attribute. */ - getattribute = _PyType_Lookup(tp, _Py_ID(__getattribute__)); + getattribute = _PyType_Lookup(tp, &_Py_ID(__getattribute__)); if (getattribute == NULL || (Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) && ((PyWrapperDescrObject *)getattribute)->d_wrapped == @@ -7669,11 +7669,11 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) stack[0] = self; stack[1] = name; if (value == NULL) { - res = vectorcall_method(_Py_ID(__delattr__), stack, 2); + res = vectorcall_method(&_Py_ID(__delattr__), stack, 2); } else { stack[2] = value; - res = vectorcall_method(_Py_ID(__setattr__), stack, 3); + res = vectorcall_method(&_Py_ID(__setattr__), stack, 3); } if (res == NULL) return -1; @@ -7682,12 +7682,12 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value) } static PyObject *name_op[] = { - _Py_ID(__lt__), - _Py_ID(__le__), - _Py_ID(__eq__), - _Py_ID(__ne__), - _Py_ID(__gt__), - _Py_ID(__ge__), + &_Py_ID(__lt__), + &_Py_ID(__le__), + &_Py_ID(__eq__), + &_Py_ID(__ne__), + &_Py_ID(__gt__), + &_Py_ID(__ge__), }; static PyObject * @@ -7714,7 +7714,7 @@ slot_tp_iter(PyObject *self) int unbound; PyObject *func, *res; - func = lookup_maybe_method(self, _Py_ID(__iter__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__iter__), &unbound); if (func == Py_None) { Py_DECREF(func); PyErr_Format(PyExc_TypeError, @@ -7730,7 +7730,7 @@ slot_tp_iter(PyObject *self) } PyErr_Clear(); - func = lookup_maybe_method(self, _Py_ID(__getitem__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__getitem__), &unbound); if (func == NULL) { PyErr_Format(PyExc_TypeError, "'%.200s' object is not iterable", @@ -7745,7 +7745,7 @@ static PyObject * slot_tp_iternext(PyObject *self) { PyObject *stack[1] = {self}; - return vectorcall_method(_Py_ID(__next__), stack, 1); + return vectorcall_method(&_Py_ID(__next__), stack, 1); } static PyObject * @@ -7754,7 +7754,7 @@ slot_tp_descr_get(PyObject *self, PyObject *obj, PyObject *type) PyTypeObject *tp = Py_TYPE(self); PyObject *get; - get = _PyType_Lookup(tp, _Py_ID(__get__)); + get = _PyType_Lookup(tp, &_Py_ID(__get__)); if (get == NULL) { /* Avoid further slowdowns */ if (tp->tp_descr_get == slot_tp_descr_get) @@ -7778,11 +7778,11 @@ slot_tp_descr_set(PyObject *self, PyObject *target, PyObject *value) stack[0] = self; stack[1] = target; if (value == NULL) { - res = vectorcall_method(_Py_ID(__delete__), stack, 2); + res = vectorcall_method(&_Py_ID(__delete__), stack, 2); } else { stack[2] = value; - res = vectorcall_method(_Py_ID(__set__), stack, 3); + res = vectorcall_method(&_Py_ID(__set__), stack, 3); } if (res == NULL) return -1; @@ -7796,7 +7796,7 @@ slot_tp_init(PyObject *self, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); int unbound; - PyObject *meth = lookup_method(self, _Py_ID(__init__), &unbound); + PyObject *meth = lookup_method(self, &_Py_ID(__init__), &unbound); if (meth == NULL) { return -1; } @@ -7828,7 +7828,7 @@ slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PyThreadState *tstate = _PyThreadState_GET(); PyObject *func, *result; - func = PyObject_GetAttr((PyObject *)type, _Py_ID(__new__)); + func = PyObject_GetAttr((PyObject *)type, &_Py_ID(__new__)); if (func == NULL) { return NULL; } @@ -7849,7 +7849,7 @@ slot_tp_finalize(PyObject *self) PyErr_Fetch(&error_type, &error_value, &error_traceback); /* Execute __del__ method, if any. */ - del = lookup_maybe_method(self, _Py_ID(__del__), &unbound); + del = lookup_maybe_method(self, &_Py_ID(__del__), &unbound); if (del != NULL) { res = call_unbound_noarg(unbound, del, self); if (res == NULL) @@ -7869,7 +7869,7 @@ slot_am_await(PyObject *self) int unbound; PyObject *func, *res; - func = lookup_maybe_method(self, _Py_ID(__await__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__await__), &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -7887,7 +7887,7 @@ slot_am_aiter(PyObject *self) int unbound; PyObject *func, *res; - func = lookup_maybe_method(self, _Py_ID(__aiter__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__aiter__), &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -7905,7 +7905,7 @@ slot_am_anext(PyObject *self) int unbound; PyObject *func, *res; - func = lookup_maybe_method(self, _Py_ID(__anext__), &unbound); + func = lookup_maybe_method(self, &_Py_ID(__anext__), &unbound); if (func != NULL) { res = call_unbound_noarg(unbound, func, self); Py_DECREF(func); @@ -8538,7 +8538,7 @@ type_new_set_names(PyTypeObject *type) PyObject *key, *value; while (PyDict_Next(names_to_set, &i, &key, &value)) { PyObject *set_name = _PyObject_LookupSpecial(value, - _Py_ID(__set_name__)); + &_Py_ID(__set_name__)); if (set_name == NULL) { if (PyErr_Occurred()) { goto error; @@ -8578,7 +8578,7 @@ type_new_init_subclass(PyTypeObject *type, PyObject *kwds) return -1; } - PyObject *func = PyObject_GetAttr(super, _Py_ID(__init_subclass__)); + PyObject *func = PyObject_GetAttr(super, &_Py_ID(__init_subclass__)); Py_DECREF(super); if (func == NULL) { return -1; @@ -8788,7 +8788,7 @@ super_getattro(PyObject *self, PyObject *name) (i.e. super, or a subclass), not the class of su->obj. */ if (PyUnicode_Check(name) && PyUnicode_GET_LENGTH(name) == 9 && - _PyUnicode_Equal(name, _Py_ID(__class__))) + _PyUnicode_Equal(name, &_Py_ID(__class__))) goto skip; mro = starttype->tp_mro; @@ -8880,7 +8880,7 @@ supercheck(PyTypeObject *type, PyObject *obj) /* Try the slow way */ PyObject *class_attr; - if (_PyObject_LookupAttr(obj, _Py_ID(__class__), &class_attr) < 0) { + if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &class_attr) < 0) { return NULL; } if (class_attr != NULL && @@ -8971,7 +8971,7 @@ super_init_without_args(InterpreterFrame *cframe, PyCodeObject *co, assert((_PyLocals_GetKind(co->co_localspluskinds, i) & CO_FAST_FREE) != 0); PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i); assert(PyUnicode_Check(name)); - if (_PyUnicode_Equal(name, _Py_ID(__class__))) { + if (_PyUnicode_Equal(name, &_Py_ID(__class__))) { PyObject *cell = _PyFrame_GetLocalsArray(cframe)[i]; if (cell == NULL || !PyCell_Check(cell)) { PyErr_SetString(PyExc_RuntimeError, diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index cf43d9ba9199f14..1744afab0bc22aa 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -260,7 +260,7 @@ get_unicode_state(void) // Return a borrowed reference to the empty string singleton. static inline PyObject* unicode_get_empty(void) { - return _Py_STR(empty); + return &_Py_STR(empty); } @@ -1986,7 +1986,7 @@ unicode_dealloc(PyObject *unicode) static int unicode_is_singleton(PyObject *unicode) { - if (unicode == _Py_STR(empty)) { + if (unicode == &_Py_STR(empty)) { return 1; } @@ -15534,7 +15534,7 @@ _PyUnicode_InitGlobalObjects(PyInterpreterState *interp) } #ifdef Py_DEBUG - assert(_PyUnicode_CheckConsistency(_Py_STR(empty), 1)); + assert(_PyUnicode_CheckConsistency(&_Py_STR(empty), 1)); #endif return _PyStatus_OK(); @@ -15780,13 +15780,13 @@ static PyObject * unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored)) { if (it->it_seq != NULL) { - return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(_Py_ID(iter)), + return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)), it->it_seq, it->it_index); } else { PyObject *u = (PyObject *)_PyUnicode_New(0); if (u == NULL) return NULL; - return Py_BuildValue("N(N)", _PyEval_GetBuiltin(_Py_ID(iter)), u); + return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), u); } } diff --git a/Objects/unionobject.c b/Objects/unionobject.c index 77464ac56e1e9b8..72a0a3f2cf8d221 100644 --- a/Objects/unionobject.c +++ b/Objects/unionobject.c @@ -265,13 +265,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p) return _PyUnicodeWriter_WriteASCIIString(writer, "None", 4); } - if (_PyObject_LookupAttr(p, _Py_ID(__origin__), &tmp) < 0) { + if (_PyObject_LookupAttr(p, &_Py_ID(__origin__), &tmp) < 0) { goto exit; } if (tmp) { Py_DECREF(tmp); - if (_PyObject_LookupAttr(p, _Py_ID(__args__), &tmp) < 0) { + if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) { goto exit; } if (tmp) { @@ -281,13 +281,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p) } } - if (_PyObject_LookupAttr(p, _Py_ID(__qualname__), &qualname) < 0) { + if (_PyObject_LookupAttr(p, &_Py_ID(__qualname__), &qualname) < 0) { goto exit; } if (qualname == NULL) { goto use_repr; } - if (_PyObject_LookupAttr(p, _Py_ID(__module__), &module) < 0) { + if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) { goto exit; } if (module == NULL || module == Py_None) { diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index b082bed109aed84..71dfa640ebf5784 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -170,7 +170,7 @@ weakref_repr(PyWeakReference *self) } Py_INCREF(obj); - if (_PyObject_LookupAttr(obj, _Py_ID(__name__), &name) < 0) { + if (_PyObject_LookupAttr(obj, &_Py_ID(__name__), &name) < 0) { Py_DECREF(obj); return NULL; } @@ -463,7 +463,7 @@ proxy_checkref(PyWeakReference *proxy) method(PyObject *proxy, PyObject *Py_UNUSED(ignored)) { \ UNWRAP(proxy); \ Py_INCREF(proxy); \ - PyObject* res = PyObject_CallMethodNoArgs(proxy, _Py_ID(special)); \ + PyObject* res = PyObject_CallMethodNoArgs(proxy, &_Py_ID(special)); \ Py_DECREF(proxy); \ return res; \ } diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index c817c8b331b51af..a645af1dae84669 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -463,14 +463,14 @@ fp_setreadl(struct tok_state *tok, const char* enc) if (io == NULL) { return 0; } - stream = _PyObject_CallMethod(io, _Py_ID(open), "isisOOO", + stream = _PyObject_CallMethod(io, &_Py_ID(open), "isisOOO", fd, "r", -1, enc, Py_None, Py_None, Py_False); Py_DECREF(io); if (stream == NULL) { return 0; } - readline = PyObject_GetAttr(stream, _Py_ID(readline)); + readline = PyObject_GetAttr(stream, &_Py_ID(readline)); Py_DECREF(stream); if (readline == NULL) { return 0; diff --git a/Python/_warnings.c b/Python/_warnings.c index d1ab6bb4bf63f14..a47e5fef6865f1b 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -105,7 +105,7 @@ init_filters(PyInterpreterState *interp) size_t pos = 0; /* Post-incremented in each use. */ #define ADD(TYPE, ACTION, MODNAME) \ PyList_SET_ITEM(filters, pos++, \ - create_filter(TYPE, _Py_ID(ACTION), MODNAME)); + create_filter(TYPE, &_Py_ID(ACTION), MODNAME)); ADD(PyExc_DeprecationWarning, default, "__main__"); ADD(PyExc_DeprecationWarning, ignore, NULL); ADD(PyExc_PendingDeprecationWarning, ignore, NULL); @@ -177,7 +177,7 @@ check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg) } /* Otherwise assume a regex filter and call its match() method */ - result = PyObject_CallMethodOneArg(obj, _Py_ID(match), arg); + result = PyObject_CallMethodOneArg(obj, &_Py_ID(match), arg); if (result == NULL) return -1; @@ -187,7 +187,7 @@ check_matched(PyInterpreterState *interp, PyObject *obj, PyObject *arg) } #define GET_WARNINGS_ATTR(interp, attr, try_import) \ - get_warnings_attr(interp, _Py_ID(attr), try_import) + get_warnings_attr(interp, &_Py_ID(attr), try_import) /* Returns a new reference. @@ -200,7 +200,7 @@ get_warnings_attr(PyInterpreterState *interp, PyObject *attr, int try_import) /* don't try to import after the start of the Python finallization */ if (try_import && !_Py_IsFinalizing()) { - warnings_module = PyImport_Import(_Py_ID(warnings)); + warnings_module = PyImport_Import(&_Py_ID(warnings)); if (warnings_module == NULL) { /* Fallback to the C implementation if we cannot get the Python implementation */ @@ -218,7 +218,7 @@ get_warnings_attr(PyInterpreterState *interp, PyObject *attr, int try_import) if (!interp->modules) { return NULL; } - warnings_module = PyImport_GetModule(_Py_ID(warnings)); + warnings_module = PyImport_GetModule(&_Py_ID(warnings)); if (warnings_module == NULL) return NULL; } @@ -405,7 +405,7 @@ already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key, if (st == NULL) { return -1; } - version_obj = _PyDict_GetItemWithError(registry, _Py_ID(version)); + version_obj = _PyDict_GetItemWithError(registry, &_Py_ID(version)); if (version_obj == NULL || !PyLong_CheckExact(version_obj) || PyLong_AsLong(version_obj) != st->filters_version) @@ -417,7 +417,7 @@ already_warned(PyInterpreterState *interp, PyObject *registry, PyObject *key, version_obj = PyLong_FromLong(st->filters_version); if (version_obj == NULL) return -1; - if (PyDict_SetItem(registry, _Py_ID(version), version_obj) < 0) { + if (PyDict_SetItem(registry, &_Py_ID(version), version_obj) < 0) { Py_DECREF(version_obj); return -1; } @@ -502,12 +502,12 @@ show_warning(PyThreadState *tstate, PyObject *filename, int lineno, PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno); - name = PyObject_GetAttr(category, _Py_ID(__name__)); + name = PyObject_GetAttr(category, &_Py_ID(__name__)); if (name == NULL) { goto error; } - f_stderr = _PySys_GetAttr(tstate, _Py_ID(stderr)); + f_stderr = _PySys_GetAttr(tstate, &_Py_ID(stderr)); if (f_stderr == NULL) { fprintf(stderr, "lost sys.stderr\n"); goto error; @@ -879,7 +879,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, /* Setup registry. */ assert(globals != NULL); assert(PyDict_Check(globals)); - *registry = _PyDict_GetItemWithError(globals, _Py_ID(__warningregistry__)); + *registry = _PyDict_GetItemWithError(globals, &_Py_ID(__warningregistry__)); if (*registry == NULL) { int rc; @@ -890,7 +890,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, if (*registry == NULL) goto handle_error; - rc = PyDict_SetItem(globals, _Py_ID(__warningregistry__), *registry); + rc = PyDict_SetItem(globals, &_Py_ID(__warningregistry__), *registry); if (rc < 0) goto handle_error; } @@ -898,7 +898,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno, Py_INCREF(*registry); /* Setup module. */ - *module = _PyDict_GetItemWithError(globals, _Py_ID(__name__)); + *module = _PyDict_GetItemWithError(globals, &_Py_ID(__name__)); if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) { Py_INCREF(*module); } @@ -1005,12 +1005,12 @@ get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno PyObject *source_line; /* Check/get the requisite pieces needed for the loader. */ - loader = _PyDict_GetItemWithError(module_globals, _Py_ID(__loader__)); + loader = _PyDict_GetItemWithError(module_globals, &_Py_ID(__loader__)); if (loader == NULL) { return NULL; } Py_INCREF(loader); - module_name = _PyDict_GetItemWithError(module_globals, _Py_ID(__name__)); + module_name = _PyDict_GetItemWithError(module_globals, &_Py_ID(__name__)); if (!module_name) { Py_DECREF(loader); return NULL; @@ -1018,7 +1018,7 @@ get_source_line(PyInterpreterState *interp, PyObject *module_globals, int lineno Py_INCREF(module_name); /* Make sure the loader implements the optional get_source() method. */ - (void)_PyObject_LookupAttr(loader, _Py_ID(get_source), &get_source); + (void)_PyObject_LookupAttr(loader, &_Py_ID(get_source), &get_source); Py_DECREF(loader); if (!get_source) { Py_DECREF(module_name); diff --git a/Python/ast_opt.c b/Python/ast_opt.c index fd28f5483453135..3a6c7040abc290f 100644 --- a/Python/ast_opt.c +++ b/Python/ast_opt.c @@ -268,8 +268,8 @@ parse_literal(PyObject *fmt, Py_ssize_t *ppos, PyArena *arena) PyObject *str = PyUnicode_Substring(fmt, start, pos); /* str = str.replace('%%', '%') */ if (str && has_percents) { - Py_SETREF(str, PyUnicode_Replace(str, _Py_STR(dbl_percent), - _Py_STR(percent), -1)); + Py_SETREF(str, PyUnicode_Replace(str, &_Py_STR(dbl_percent), + &_Py_STR(percent), -1)); } if (!str) { return NULL; diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index c399289a5842651..b253f88a04baeb3 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -32,7 +32,7 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs) } continue; } - if (_PyObject_LookupAttr(base, _Py_ID(__mro_entries__), &meth) < 0) { + if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__), &meth) < 0) { goto error; } if (!meth) { @@ -133,10 +133,10 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, goto error; } - meta = _PyDict_GetItemWithError(mkw, _Py_ID(metaclass)); + meta = _PyDict_GetItemWithError(mkw, &_Py_ID(metaclass)); if (meta != NULL) { Py_INCREF(meta); - if (PyDict_DelItem(mkw, _Py_ID(metaclass)) < 0) { + if (PyDict_DelItem(mkw, &_Py_ID(metaclass)) < 0) { goto error; } /* metaclass is explicitly given, check if it's indeed a class */ @@ -176,7 +176,7 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs, } /* else: meta is not a class, so we cannot do the metaclass calculation, so we will use the explicitly given object as it is */ - if (_PyObject_LookupAttr(meta, _Py_ID(__prepare__), &prep) < 0) { + if (_PyObject_LookupAttr(meta, &_Py_ID(__prepare__), &prep) < 0) { ns = NULL; } else if (prep == NULL) { @@ -931,9 +931,9 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals, return NULL; } - int r = PyDict_Contains(globals, _Py_ID(__builtins__)); + int r = PyDict_Contains(globals, &_Py_ID(__builtins__)); if (r == 0) { - r = PyDict_SetItem(globals, _Py_ID(__builtins__), PyEval_GetBuiltins()); + r = PyDict_SetItem(globals, &_Py_ID(__builtins__), PyEval_GetBuiltins()); } if (r < 0) { return NULL; @@ -1018,9 +1018,9 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals, Py_TYPE(locals)->tp_name); return NULL; } - int r = PyDict_Contains(globals, _Py_ID(__builtins__)); + int r = PyDict_Contains(globals, &_Py_ID(__builtins__)); if (r == 0) { - r = PyDict_SetItem(globals, _Py_ID(__builtins__), PyEval_GetBuiltins()); + r = PyDict_SetItem(globals, &_Py_ID(__builtins__), PyEval_GetBuiltins()); } if (r < 0) { return NULL; @@ -1944,7 +1944,7 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, if (file == Py_None) { PyThreadState *tstate = _PyThreadState_GET(); - file = _PySys_GetAttr(tstate, _Py_ID(stdout)); + file = _PySys_GetAttr(tstate, &_Py_ID(stdout)); if (file == NULL) { PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -2004,7 +2004,7 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep, } if (flush) { - PyObject *tmp = PyObject_CallMethodNoArgs(file, _Py_ID(flush)); + PyObject *tmp = PyObject_CallMethodNoArgs(file, &_Py_ID(flush)); if (tmp == NULL) { return NULL; } @@ -2036,11 +2036,11 @@ builtin_input_impl(PyObject *module, PyObject *prompt) { PyThreadState *tstate = _PyThreadState_GET(); PyObject *fin = _PySys_GetAttr( - tstate, _Py_ID(stdin)); + tstate, &_Py_ID(stdin)); PyObject *fout = _PySys_GetAttr( - tstate, _Py_ID(stdout)); + tstate, &_Py_ID(stdout)); PyObject *ferr = _PySys_GetAttr( - tstate, _Py_ID(stderr)); + tstate, &_Py_ID(stderr)); PyObject *tmp; long fd; int tty; @@ -2067,7 +2067,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) } /* First of all, flush stderr */ - tmp = PyObject_CallMethodNoArgs(ferr, _Py_ID(flush)); + tmp = PyObject_CallMethodNoArgs(ferr, &_Py_ID(flush)); if (tmp == NULL) PyErr_Clear(); else @@ -2076,7 +2076,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) /* We should only use (GNU) readline if Python's sys.stdin and sys.stdout are the same as C's stdin and stdout, because we need to pass it those. */ - tmp = PyObject_CallMethodNoArgs(fin, _Py_ID(fileno)); + tmp = PyObject_CallMethodNoArgs(fin, &_Py_ID(fileno)); if (tmp == NULL) { PyErr_Clear(); tty = 0; @@ -2089,7 +2089,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) tty = fd == fileno(stdin) && isatty(fd); } if (tty) { - tmp = PyObject_CallMethodNoArgs(fout, _Py_ID(fileno)); + tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(fileno)); if (tmp == NULL) { PyErr_Clear(); tty = 0; @@ -2115,8 +2115,8 @@ builtin_input_impl(PyObject *module, PyObject *prompt) size_t len; /* stdin is a text stream, so it must have an encoding. */ - stdin_encoding = PyObject_GetAttr(fin, _Py_ID(encoding)); - stdin_errors = PyObject_GetAttr(fin, _Py_ID(errors)); + stdin_encoding = PyObject_GetAttr(fin, &_Py_ID(encoding)); + stdin_errors = PyObject_GetAttr(fin, &_Py_ID(errors)); if (!stdin_encoding || !stdin_errors || !PyUnicode_Check(stdin_encoding) || !PyUnicode_Check(stdin_errors)) { @@ -2127,7 +2127,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) stdin_errors_str = PyUnicode_AsUTF8(stdin_errors); if (!stdin_encoding_str || !stdin_errors_str) goto _readline_errors; - tmp = PyObject_CallMethodNoArgs(fout, _Py_ID(flush)); + tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(flush)); if (tmp == NULL) PyErr_Clear(); else @@ -2136,8 +2136,8 @@ builtin_input_impl(PyObject *module, PyObject *prompt) /* We have a prompt, encode it as stdout would */ const char *stdout_encoding_str, *stdout_errors_str; PyObject *stringpo; - stdout_encoding = PyObject_GetAttr(fout, _Py_ID(encoding)); - stdout_errors = PyObject_GetAttr(fout, _Py_ID(errors)); + stdout_encoding = PyObject_GetAttr(fout, &_Py_ID(encoding)); + stdout_errors = PyObject_GetAttr(fout, &_Py_ID(errors)); if (!stdout_encoding || !stdout_errors || !PyUnicode_Check(stdout_encoding) || !PyUnicode_Check(stdout_errors)) { @@ -2222,7 +2222,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt) if (PyFile_WriteObject(prompt, fout, Py_PRINT_RAW) != 0) return NULL; } - tmp = PyObject_CallMethodNoArgs(fout, _Py_ID(flush)); + tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(flush)); if (tmp == NULL) PyErr_Clear(); else @@ -2273,7 +2273,7 @@ builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits) return NULL; } - round = _PyObject_LookupSpecial(number, _Py_ID(__round__)); + round = _PyObject_LookupSpecial(number, &_Py_ID(__round__)); if (round == NULL) { if (!PyErr_Occurred()) PyErr_Format(PyExc_TypeError, @@ -2334,7 +2334,7 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject if (newlist == NULL) return NULL; - callable = PyObject_GetAttr(newlist, _Py_ID(sort)); + callable = PyObject_GetAttr(newlist, &_Py_ID(sort)); if (callable == NULL) { Py_DECREF(newlist); return NULL; @@ -2366,7 +2366,7 @@ builtin_vars(PyObject *self, PyObject *args) Py_XINCREF(d); } else { - if (_PyObject_LookupAttr(v, _Py_ID(__dict__), &d) == 0) { + if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &d) == 0) { PyErr_SetString(PyExc_TypeError, "vars() argument must have __dict__ attribute"); } diff --git a/Python/ceval.c b/Python/ceval.c index cb0dfa3f34ec076..756d892b8dbbb26 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -878,7 +878,7 @@ match_keys(PyThreadState *tstate, PyObject *map, PyObject *keys) // - Atomically check for a key and get its value without error handling. // - Don't cause key creation or resizing in dict subclasses like // collections.defaultdict that define __missing__ (or similar). - int meth_found = _PyObject_GetMethod(map, _Py_ID(get), &get); + int meth_found = _PyObject_GetMethod(map, &_Py_ID(get), &get); if (get == NULL) { goto fail; } @@ -1729,7 +1729,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr #ifdef LLTRACE { - int r = PyDict_Contains(GLOBALS(), _Py_ID(__ltrace__)); + int r = PyDict_Contains(GLOBALS(), &_Py_ID(__ltrace__)); if (r < 0) { goto exit_unwind; } @@ -2364,7 +2364,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(PRINT_EXPR) { PyObject *value = POP(); - PyObject *hook = _PySys_GetAttr(tstate, _Py_ID(displayhook)); + PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(displayhook)); PyObject *res; if (hook == NULL) { _PyErr_SetString(tstate, PyExc_RuntimeError, @@ -2573,7 +2573,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr retval = Py_TYPE(receiver)->tp_iternext(receiver); } else { - retval = PyObject_CallMethodOneArg(receiver, _Py_ID(send), v); + retval = PyObject_CallMethodOneArg(receiver, &_Py_ID(send), v); } if (retval == NULL) { if (tstate->c_tracefunc != NULL @@ -2709,7 +2709,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr PyObject *bc; if (PyDict_CheckExact(BUILTINS())) { bc = _PyDict_GetItemWithError(BUILTINS(), - _Py_ID(__build_class__)); + &_Py_ID(__build_class__)); if (bc == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_NameError, @@ -2720,7 +2720,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr Py_INCREF(bc); } else { - bc = PyObject_GetItem(BUILTINS(), _Py_ID(__build_class__)); + bc = PyObject_GetItem(BUILTINS(), &_Py_ID(__build_class__)); if (bc == NULL) { if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) _PyErr_SetString(tstate, PyExc_NameError, @@ -3283,7 +3283,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr /* check if __annotations__ in locals()... */ if (PyDict_CheckExact(LOCALS())) { ann_dict = _PyDict_GetItemWithError(LOCALS(), - _Py_ID(__annotations__)); + &_Py_ID(__annotations__)); if (ann_dict == NULL) { if (_PyErr_Occurred(tstate)) { goto error; @@ -3293,7 +3293,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr if (ann_dict == NULL) { goto error; } - err = PyDict_SetItem(LOCALS(), _Py_ID(__annotations__), + err = PyDict_SetItem(LOCALS(), &_Py_ID(__annotations__), ann_dict); Py_DECREF(ann_dict); if (err != 0) { @@ -3303,7 +3303,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } else { /* do the same if locals() is not a dict */ - ann_dict = PyObject_GetItem(LOCALS(), _Py_ID(__annotations__)); + ann_dict = PyObject_GetItem(LOCALS(), &_Py_ID(__annotations__)); if (ann_dict == NULL) { if (!_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) { goto error; @@ -3313,7 +3313,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr if (ann_dict == NULL) { goto error; } - err = PyObject_SetItem(LOCALS(), _Py_ID(__annotations__), + err = PyObject_SetItem(LOCALS(), &_Py_ID(__annotations__), ann_dict); Py_DECREF(ann_dict); if (err != 0) { @@ -4218,7 +4218,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(BEFORE_ASYNC_WITH) { PyObject *mgr = TOP(); PyObject *res; - PyObject *enter = _PyObject_LookupSpecial(mgr, _Py_ID(__aenter__)); + PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__aenter__)); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4228,7 +4228,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *exit = _PyObject_LookupSpecial(mgr, _Py_ID(__aexit__)); + PyObject *exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__aexit__)); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4254,7 +4254,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr TARGET(BEFORE_WITH) { PyObject *mgr = TOP(); PyObject *res; - PyObject *enter = _PyObject_LookupSpecial(mgr, _Py_ID(__enter__)); + PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__enter__)); if (enter == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -4264,7 +4264,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr } goto error; } - PyObject *exit = _PyObject_LookupSpecial(mgr, _Py_ID(__exit__)); + PyObject *exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__exit__)); if (exit == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -7063,7 +7063,7 @@ import_name(PyThreadState *tstate, InterpreterFrame *frame, PyObject *import_func, *res; PyObject* stack[5]; - import_func = _PyDict_GetItemWithError(frame->f_builtins, _Py_ID(__import__)); + import_func = _PyDict_GetItemWithError(frame->f_builtins, &_Py_ID(__import__)); if (import_func == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_ImportError, "__import__ not found"); @@ -7110,7 +7110,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name) /* Issue #17636: in case this failed because of a circular relative import, try to fallback on reading the module directly from sys.modules. */ - pkgname = PyObject_GetAttr(v, _Py_ID(__name__)); + pkgname = PyObject_GetAttr(v, &_Py_ID(__name__)); if (pkgname == NULL) { goto error; } @@ -7152,7 +7152,7 @@ import_from(PyThreadState *tstate, PyObject *v, PyObject *name) PyErr_SetImportError(errmsg, pkgname, NULL); } else { - PyObject *spec = PyObject_GetAttr(v, _Py_ID(__spec__)); + PyObject *spec = PyObject_GetAttr(v, &_Py_ID(__spec__)); const char *fmt = _PyModuleSpec_IsInitializing(spec) ? "cannot import name %R from partially initialized module %R " @@ -7178,11 +7178,11 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v) int skip_leading_underscores = 0; int pos, err; - if (_PyObject_LookupAttr(v, _Py_ID(__all__), &all) < 0) { + if (_PyObject_LookupAttr(v, &_Py_ID(__all__), &all) < 0) { return -1; /* Unexpected error */ } if (all == NULL) { - if (_PyObject_LookupAttr(v, _Py_ID(__dict__), &dict) < 0) { + if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &dict) < 0) { return -1; } if (dict == NULL) { @@ -7209,7 +7209,7 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v) break; } if (!PyUnicode_Check(name)) { - PyObject *modname = PyObject_GetAttr(v, _Py_ID(__name__)); + PyObject *modname = PyObject_GetAttr(v, &_Py_ID(__name__)); if (modname == NULL) { Py_DECREF(name); err = -1; @@ -7415,7 +7415,7 @@ format_exc_check_arg(PyThreadState *tstate, PyObject *exc, if (PyErr_GivenExceptionMatches(value, PyExc_NameError)) { // We do not care if this fails because we are going to restore the // NameError anyway. - (void)PyObject_SetAttr(value, _Py_ID(name), obj); + (void)PyObject_SetAttr(value, &_Py_ID(name), obj); } PyErr_Restore(type, value, traceback); } diff --git a/Python/codecs.c b/Python/codecs.c index 803382b09c526e2..33965f885f7064e 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -535,7 +535,7 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding, * attribute. */ if (!PyTuple_CheckExact(codec)) { - if (_PyObject_LookupAttr(codec, _Py_ID(_is_text_encoding), &attr) < 0) { + if (_PyObject_LookupAttr(codec, &_Py_ID(_is_text_encoding), &attr) < 0) { Py_DECREF(codec); return NULL; } diff --git a/Python/compile.c b/Python/compile.c index f64adaeb77d994a..631711ccdb6225b 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -669,7 +669,7 @@ compiler_set_qualname(struct compiler *c) || parent->u_scope_type == COMPILER_SCOPE_LAMBDA) { base = PyUnicode_Concat(parent->u_qualname, - _Py_STR(dot_locals)); + &_Py_STR(dot_locals)); if (base == NULL) return 0; } @@ -681,7 +681,7 @@ compiler_set_qualname(struct compiler *c) } if (base != NULL) { - name = PyUnicode_Concat(base, _Py_STR(dot)); + name = PyUnicode_Concat(base, &_Py_STR(dot)); Py_DECREF(base); if (name == NULL) return 0; @@ -1611,7 +1611,7 @@ compiler_enter_scope(struct compiler *c, identifier name, int res; assert(u->u_scope_type == COMPILER_SCOPE_CLASS); assert(PyDict_GET_SIZE(u->u_cellvars) == 0); - res = PyDict_SetItem(u->u_cellvars, _Py_ID(__class__), + res = PyDict_SetItem(u->u_cellvars, &_Py_ID(__class__), _PyLong_GetZero()); if (res < 0) { compiler_unit_free(u); @@ -2021,7 +2021,7 @@ compiler_body(struct compiler *c, asdl_stmt_seq *stmts) assert(st->kind == Expr_kind); VISIT(c, expr, st->v.Expr.value); UNSET_LOC(c); - if (!compiler_nameop(c, _Py_ID(__doc__), Store)) + if (!compiler_nameop(c, &_Py_ID(__doc__), Store)) return 0; } } @@ -2035,7 +2035,7 @@ compiler_mod(struct compiler *c, mod_ty mod) { PyCodeObject *co; int addNone = 1; - if (!compiler_enter_scope(c, _Py_STR(anon_module), COMPILER_SCOPE_MODULE, + if (!compiler_enter_scope(c, &_Py_STR(anon_module), COMPILER_SCOPE_MODULE, mod, 1)) { return NULL; } @@ -2331,7 +2331,7 @@ compiler_visit_annotations(struct compiler *c, arguments_ty args, args->kwarg->annotation, &annotations_len)) return 0; - if (!compiler_visit_argannotation(c, _Py_ID(return), returns, + if (!compiler_visit_argannotation(c, &_Py_ID(return), returns, &annotations_len)) { return 0; } @@ -2889,7 +2889,7 @@ compiler_lambda(struct compiler *c, expr_ty e) return 0; } - if (!compiler_enter_scope(c, _Py_STR(anon_lambda), COMPILER_SCOPE_LAMBDA, + if (!compiler_enter_scope(c, &_Py_STR(anon_lambda), COMPILER_SCOPE_LAMBDA, (void *)e, e->lineno)) { return 0; } @@ -3814,7 +3814,7 @@ compiler_from_import(struct compiler *c, stmt_ty s) ADDOP_NAME(c, IMPORT_NAME, s->v.ImportFrom.module, names); } else { - ADDOP_NAME(c, IMPORT_NAME, _Py_STR(empty), names); + ADDOP_NAME(c, IMPORT_NAME, &_Py_STR(empty), names); } for (i = 0; i < n; i++) { alias_ty alias = (alias_ty)asdl_seq_GET(s->v.ImportFrom.names, i); @@ -5363,7 +5363,7 @@ static int compiler_genexp(struct compiler *c, expr_ty e) { assert(e->kind == GeneratorExp_kind); - return compiler_comprehension(c, e, COMP_GENEXP, _Py_STR(anon_genexpr), + return compiler_comprehension(c, e, COMP_GENEXP, &_Py_STR(anon_genexpr), e->v.GeneratorExp.generators, e->v.GeneratorExp.elt, NULL); } @@ -5372,7 +5372,7 @@ static int compiler_listcomp(struct compiler *c, expr_ty e) { assert(e->kind == ListComp_kind); - return compiler_comprehension(c, e, COMP_LISTCOMP, _Py_STR(anon_listcomp), + return compiler_comprehension(c, e, COMP_LISTCOMP, &_Py_STR(anon_listcomp), e->v.ListComp.generators, e->v.ListComp.elt, NULL); } @@ -5381,7 +5381,7 @@ static int compiler_setcomp(struct compiler *c, expr_ty e) { assert(e->kind == SetComp_kind); - return compiler_comprehension(c, e, COMP_SETCOMP, _Py_STR(anon_setcomp), + return compiler_comprehension(c, e, COMP_SETCOMP, &_Py_STR(anon_setcomp), e->v.SetComp.generators, e->v.SetComp.elt, NULL); } @@ -5391,7 +5391,7 @@ static int compiler_dictcomp(struct compiler *c, expr_ty e) { assert(e->kind == DictComp_kind); - return compiler_comprehension(c, e, COMP_DICTCOMP, _Py_STR(anon_dictcomp), + return compiler_comprehension(c, e, COMP_DICTCOMP, &_Py_STR(anon_dictcomp), e->v.DictComp.generators, e->v.DictComp.key, e->v.DictComp.value); } @@ -5935,7 +5935,7 @@ compiler_annassign(struct compiler *c, stmt_ty s) else { VISIT(c, expr, s->v.AnnAssign.annotation); } - ADDOP_NAME(c, LOAD_NAME, _Py_ID(__annotations__), names); + ADDOP_NAME(c, LOAD_NAME, &_Py_ID(__annotations__), names); mangled = _Py_Mangle(c->u->u_private, targ->v.Name.id); ADDOP_LOAD_CONST_NEW(c, mangled); ADDOP(c, STORE_SUBSCR); diff --git a/Python/errors.c b/Python/errors.c index 310fc914b7cbe2f..10a06a5ae326724 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -1129,7 +1129,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) goto failure; } - int r = PyDict_Contains(dict, _Py_ID(__module__)); + int r = PyDict_Contains(dict, &_Py_ID(__module__)); if (r < 0) { goto failure; } @@ -1138,7 +1138,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict) (Py_ssize_t)(dot-name)); if (modulename == NULL) goto failure; - if (PyDict_SetItem(dict, _Py_ID(__module__), modulename) != 0) + if (PyDict_SetItem(dict, &_Py_ID(__module__), modulename) != 0) goto failure; } if (PyTuple_Check(base)) { @@ -1341,7 +1341,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, assert(PyExceptionClass_Check(exc_type)); - PyObject *modulename = PyObject_GetAttr(exc_type, _Py_ID(__module__)); + PyObject *modulename = PyObject_GetAttr(exc_type, &_Py_ID(__module__)); if (modulename == NULL || !PyUnicode_Check(modulename)) { Py_XDECREF(modulename); _PyErr_Clear(tstate); @@ -1350,8 +1350,8 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, } } else { - if (!_PyUnicode_Equal(modulename, _Py_ID(builtins)) && - !_PyUnicode_Equal(modulename, _Py_ID(__main__))) { + if (!_PyUnicode_Equal(modulename, &_Py_ID(builtins)) && + !_PyUnicode_Equal(modulename, &_Py_ID(__main__))) { if (PyFile_WriteObject(modulename, file, Py_PRINT_RAW) < 0) { Py_DECREF(modulename); return -1; @@ -1399,7 +1399,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type, } /* Explicitly call file.flush() */ - PyObject *res = _PyObject_CallMethodNoArgs(file, _Py_ID(flush)); + PyObject *res = _PyObject_CallMethodNoArgs(file, &_Py_ID(flush)); if (!res) { return -1; } @@ -1414,7 +1414,7 @@ write_unraisable_exc(PyThreadState *tstate, PyObject *exc_type, PyObject *exc_value, PyObject *exc_tb, PyObject *err_msg, PyObject *obj) { - PyObject *file = _PySys_GetAttr(tstate, _Py_ID(stderr)); + PyObject *file = _PySys_GetAttr(tstate, &_Py_ID(stderr)); if (file == NULL || file == Py_None) { return 0; } @@ -1518,7 +1518,7 @@ _PyErr_WriteUnraisableMsg(const char *err_msg_str, PyObject *obj) goto error; } - PyObject *hook = _PySys_GetAttr(tstate, _Py_ID(unraisablehook)); + PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(unraisablehook)); if (hook == NULL) { Py_DECREF(hook_args); goto default_hook; @@ -1604,7 +1604,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, if (tmp == NULL) _PyErr_Clear(tstate); else { - if (PyObject_SetAttr(v, _Py_ID(lineno), tmp)) { + if (PyObject_SetAttr(v, &_Py_ID(lineno), tmp)) { _PyErr_Clear(tstate); } Py_DECREF(tmp); @@ -1616,7 +1616,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - if (PyObject_SetAttr(v, _Py_ID(offset), tmp ? tmp : Py_None)) { + if (PyObject_SetAttr(v, &_Py_ID(offset), tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } Py_XDECREF(tmp); @@ -1628,7 +1628,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - if (PyObject_SetAttr(v, _Py_ID(end_lineno), tmp ? tmp : Py_None)) { + if (PyObject_SetAttr(v, &_Py_ID(end_lineno), tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } Py_XDECREF(tmp); @@ -1640,20 +1640,20 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, _PyErr_Clear(tstate); } } - if (PyObject_SetAttr(v, _Py_ID(end_offset), tmp ? tmp : Py_None)) { + if (PyObject_SetAttr(v, &_Py_ID(end_offset), tmp ? tmp : Py_None)) { _PyErr_Clear(tstate); } Py_XDECREF(tmp); tmp = NULL; if (filename != NULL) { - if (PyObject_SetAttr(v, _Py_ID(filename), filename)) { + if (PyObject_SetAttr(v, &_Py_ID(filename), filename)) { _PyErr_Clear(tstate); } tmp = PyErr_ProgramTextObject(filename, lineno); if (tmp) { - if (PyObject_SetAttr(v, _Py_ID(text), tmp)) { + if (PyObject_SetAttr(v, &_Py_ID(text), tmp)) { _PyErr_Clear(tstate); } Py_DECREF(tmp); @@ -1663,7 +1663,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, } } if (exc != PyExc_SyntaxError) { - if (_PyObject_LookupAttr(v, _Py_ID(msg), &tmp) < 0) { + if (_PyObject_LookupAttr(v, &_Py_ID(msg), &tmp) < 0) { _PyErr_Clear(tstate); } else if (tmp) { @@ -1672,7 +1672,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, else { tmp = PyObject_Str(v); if (tmp) { - if (PyObject_SetAttr(v, _Py_ID(msg), tmp)) { + if (PyObject_SetAttr(v, &_Py_ID(msg), tmp)) { _PyErr_Clear(tstate); } Py_DECREF(tmp); @@ -1682,14 +1682,14 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset, } } - if (_PyObject_LookupAttr(v, _Py_ID(print_file_and_line), &tmp) < 0) { + if (_PyObject_LookupAttr(v, &_Py_ID(print_file_and_line), &tmp) < 0) { _PyErr_Clear(tstate); } else if (tmp) { Py_DECREF(tmp); } else { - if (PyObject_SetAttr(v, _Py_ID(print_file_and_line), Py_None)) { + if (PyObject_SetAttr(v, &_Py_ID(print_file_and_line), Py_None)) { _PyErr_Clear(tstate); } } diff --git a/Python/import.c b/Python/import.c index 63c53c00c4d16e0..aaf1dc0c9a143bc 100644 --- a/Python/import.c +++ b/Python/import.c @@ -73,7 +73,7 @@ _PyImportZip_Init(PyThreadState *tstate) } } else { - PyObject *zipimporter = PyObject_GetAttr(zipimport, _Py_ID(zipimporter)); + PyObject *zipimporter = PyObject_GetAttr(zipimport, &_Py_ID(zipimporter)); Py_DECREF(zipimport); if (zipimporter == NULL) { _PyErr_Clear(tstate); /* No zipimporter object -- okay */ @@ -347,13 +347,13 @@ import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *n NOTE: because of this, initializing must be set *before* stuffing the new module in sys.modules. */ - spec = PyObject_GetAttr(mod, _Py_ID(__spec__)); + spec = PyObject_GetAttr(mod, &_Py_ID(__spec__)); int busy = _PyModuleSpec_IsInitializing(spec); Py_XDECREF(spec); if (busy) { /* Wait until module is done importing. */ PyObject *value = _PyObject_CallMethodOneArg( - interp->importlib, _Py_ID(_lock_unlock_module), name); + interp->importlib, &_Py_ID(_lock_unlock_module), name); if (value == NULL) { return -1; } @@ -714,7 +714,7 @@ PyImport_ExecCodeModuleWithPathnames(const char *name, PyObject *co, "_bootstrap_external"); if (external != NULL) { pathobj = _PyObject_CallMethodOneArg( - external, _Py_ID(_get_sourcefile), cpathobj); + external, &_Py_ID(_get_sourcefile), cpathobj); Py_DECREF(external); } if (pathobj == NULL) @@ -742,9 +742,9 @@ module_dict_for_exec(PyThreadState *tstate, PyObject *name) /* If the module is being reloaded, we get the old module back and re-use its dict to exec the new code. */ d = PyModule_GetDict(m); - int r = PyDict_Contains(d, _Py_ID(__builtins__)); + int r = PyDict_Contains(d, &_Py_ID(__builtins__)); if (r == 0) { - r = PyDict_SetItem(d, _Py_ID(__builtins__), PyEval_GetBuiltins()); + r = PyDict_SetItem(d, &_Py_ID(__builtins__), PyEval_GetBuiltins()); } if (r < 0) { remove_module(tstate, name); @@ -801,7 +801,7 @@ PyImport_ExecCodeModuleObject(PyObject *name, PyObject *co, PyObject *pathname, Py_DECREF(d); return NULL; } - res = PyObject_CallMethodObjArgs(external, _Py_ID(_fix_up_module), + res = PyObject_CallMethodObjArgs(external, &_Py_ID(_fix_up_module), d, name, pathname, cpathname, NULL); Py_DECREF(external); if (res != NULL) { @@ -1539,14 +1539,14 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level _PyErr_SetString(tstate, PyExc_TypeError, "globals must be a dict"); goto error; } - package = PyDict_GetItemWithError(globals, _Py_ID(__package__)); + package = PyDict_GetItemWithError(globals, &_Py_ID(__package__)); if (package == Py_None) { package = NULL; } else if (package == NULL && _PyErr_Occurred(tstate)) { goto error; } - spec = PyDict_GetItemWithError(globals, _Py_ID(__spec__)); + spec = PyDict_GetItemWithError(globals, &_Py_ID(__spec__)); if (spec == NULL && _PyErr_Occurred(tstate)) { goto error; } @@ -1560,7 +1560,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level } else if (spec != NULL && spec != Py_None) { int equal; - PyObject *parent = PyObject_GetAttr(spec, _Py_ID(parent)); + PyObject *parent = PyObject_GetAttr(spec, &_Py_ID(parent)); if (parent == NULL) { goto error; } @@ -1579,7 +1579,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level } } else if (spec != NULL && spec != Py_None) { - package = PyObject_GetAttr(spec, _Py_ID(parent)); + package = PyObject_GetAttr(spec, &_Py_ID(parent)); if (package == NULL) { goto error; } @@ -1596,7 +1596,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level goto error; } - package = PyDict_GetItemWithError(globals, _Py_ID(__name__)); + package = PyDict_GetItemWithError(globals, &_Py_ID(__name__)); if (package == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_KeyError, @@ -1612,7 +1612,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level goto error; } - int haspath = PyDict_Contains(globals, _Py_ID(__path__)); + int haspath = PyDict_Contains(globals, &_Py_ID(__path__)); if (haspath < 0) { goto error; } @@ -1720,7 +1720,7 @@ import_find_and_load(PyThreadState *tstate, PyObject *abs_name) if (PyDTrace_IMPORT_FIND_LOAD_START_ENABLED()) PyDTrace_IMPORT_FIND_LOAD_START(PyUnicode_AsUTF8(abs_name)); - mod = PyObject_CallMethodObjArgs(interp->importlib, _Py_ID(_find_and_load), + mod = PyObject_CallMethodObjArgs(interp->importlib, &_Py_ID(_find_and_load), abs_name, interp->import_func, NULL); if (PyDTrace_IMPORT_FIND_LOAD_DONE_ENABLED()) @@ -1885,13 +1885,13 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, } else { PyObject *path; - if (_PyObject_LookupAttr(mod, _Py_ID(__path__), &path) < 0) { + if (_PyObject_LookupAttr(mod, &_Py_ID(__path__), &path) < 0) { goto error; } if (path) { Py_DECREF(path); final_mod = PyObject_CallMethodObjArgs( - interp->importlib, _Py_ID(_handle_fromlist), + interp->importlib, &_Py_ID(_handle_fromlist), mod, fromlist, interp->import_func, NULL); } else { @@ -1932,7 +1932,7 @@ PyObject * PyImport_ReloadModule(PyObject *m) { PyObject *reloaded_module = NULL; - PyObject *importlib = PyImport_GetModule(_Py_ID(importlib)); + PyObject *importlib = PyImport_GetModule(&_Py_ID(importlib)); if (importlib == NULL) { if (PyErr_Occurred()) { return NULL; @@ -1944,7 +1944,7 @@ PyImport_ReloadModule(PyObject *m) } } - reloaded_module = PyObject_CallMethodOneArg(importlib, _Py_ID(reload), m); + reloaded_module = PyObject_CallMethodOneArg(importlib, &_Py_ID(reload), m); Py_DECREF(importlib); return reloaded_module; } @@ -1977,7 +1977,7 @@ PyImport_Import(PyObject *module_name) globals = PyEval_GetGlobals(); if (globals != NULL) { Py_INCREF(globals); - builtins = PyObject_GetItem(globals, _Py_ID(__builtins__)); + builtins = PyObject_GetItem(globals, &_Py_ID(__builtins__)); if (builtins == NULL) goto err; } @@ -1988,20 +1988,20 @@ PyImport_Import(PyObject *module_name) if (builtins == NULL) { goto err; } - globals = Py_BuildValue("{OO}", _Py_ID(__builtins__), builtins); + globals = Py_BuildValue("{OO}", &_Py_ID(__builtins__), builtins); if (globals == NULL) goto err; } /* Get the __import__ function from the builtins */ if (PyDict_Check(builtins)) { - import = PyObject_GetItem(builtins, _Py_ID(__import__)); + import = PyObject_GetItem(builtins, &_Py_ID(__import__)); if (import == NULL) { - _PyErr_SetObject(tstate, PyExc_KeyError, _Py_ID(__import__)); + _PyErr_SetObject(tstate, PyExc_KeyError, &_Py_ID(__import__)); } } else - import = PyObject_GetAttr(builtins, _Py_ID(__import__)); + import = PyObject_GetAttr(builtins, &_Py_ID(__import__)); if (import == NULL) goto err; diff --git a/Python/importdl.c b/Python/importdl.c index 0d98b4a235e81db..f66c6013d2c9892 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -78,7 +78,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) { } /* Replace '-' by '_' */ - modname = _PyObject_CallMethod(encoded, _Py_ID(replace), "cc", '-', '_'); + modname = _PyObject_CallMethod(encoded, &_Py_ID(replace), "cc", '-', '_'); if (modname == NULL) goto error; diff --git a/Python/marshal.c b/Python/marshal.c index 74bc704233b0790..44e492925cb25fc 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -712,7 +712,7 @@ r_string(Py_ssize_t n, RFILE *p) if (mview == NULL) return NULL; - res = _PyObject_CallMethod(p->readable, _Py_ID(readinto), "N", mview); + res = _PyObject_CallMethod(p->readable, &_Py_ID(readinto), "N", mview); if (res != NULL) { read = PyNumber_AsSsize_t(res, PyExc_ValueError); Py_DECREF(res); @@ -1716,7 +1716,7 @@ marshal_dump_impl(PyObject *module, PyObject *value, PyObject *file, s = PyMarshal_WriteObjectToString(value, version); if (s == NULL) return NULL; - res = _PyObject_CallMethodOneArg(file, _Py_ID(write), s); + res = _PyObject_CallMethodOneArg(file, &_Py_ID(write), s); Py_DECREF(s); return res; } @@ -1752,7 +1752,7 @@ marshal_load(PyObject *module, PyObject *file) * This can be removed if we guarantee good error handling * for r_string() */ - data = _PyObject_CallMethod(file, _Py_ID(read), "i", 0); + data = _PyObject_CallMethod(file, &_Py_ID(read), "i", 0); if (data == NULL) return NULL; if (!PyBytes_Check(data)) { diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 93542244096c769..4a3a1abb3a4f0a2 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1438,7 +1438,7 @@ finalize_clear_modules_dict(PyObject *modules) PyDict_Clear(modules); } else { - if (PyObject_CallMethodNoArgs(modules, _Py_ID(clear)) == NULL) { + if (PyObject_CallMethodNoArgs(modules, &_Py_ID(clear)) == NULL) { PyErr_WriteUnraisable(NULL); } } @@ -1610,13 +1610,13 @@ static int flush_std_files(void) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *fout = _PySys_GetAttr(tstate, _Py_ID(stdout)); - PyObject *ferr = _PySys_GetAttr(tstate, _Py_ID(stderr)); + PyObject *fout = _PySys_GetAttr(tstate, &_Py_ID(stdout)); + PyObject *ferr = _PySys_GetAttr(tstate, &_Py_ID(stderr)); PyObject *tmp; int status = 0; if (fout != NULL && fout != Py_None && !file_is_closed(fout)) { - tmp = PyObject_CallMethodNoArgs(fout, _Py_ID(flush)); + tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(flush)); if (tmp == NULL) { PyErr_WriteUnraisable(fout); status = -1; @@ -1626,7 +1626,7 @@ flush_std_files(void) } if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) { - tmp = PyObject_CallMethodNoArgs(ferr, _Py_ID(flush)); + tmp = PyObject_CallMethodNoArgs(ferr, &_Py_ID(flush)); if (tmp == NULL) { PyErr_Clear(); status = -1; @@ -2233,7 +2233,7 @@ create_stdio(const PyConfig *config, PyObject* io, mode = "wb"; else mode = "rb"; - buf = _PyObject_CallMethod(io, _Py_ID(open), "isiOOOO", + buf = _PyObject_CallMethod(io, &_Py_ID(open), "isiOOOO", fd, mode, buffering, Py_None, Py_None, /* encoding, errors */ Py_None, Py_False); /* newline, closefd */ @@ -2241,7 +2241,7 @@ create_stdio(const PyConfig *config, PyObject* io, goto error; if (buffering) { - raw = PyObject_GetAttr(buf, _Py_ID(raw)); + raw = PyObject_GetAttr(buf, &_Py_ID(raw)); if (raw == NULL) goto error; } @@ -2257,9 +2257,9 @@ create_stdio(const PyConfig *config, PyObject* io, #endif text = PyUnicode_FromString(name); - if (text == NULL || PyObject_SetAttr(raw, _Py_ID(name), text) < 0) + if (text == NULL || PyObject_SetAttr(raw, &_Py_ID(name), text) < 0) goto error; - res = PyObject_CallMethodNoArgs(raw, _Py_ID(isatty)); + res = PyObject_CallMethodNoArgs(raw, &_Py_ID(isatty)); if (res == NULL) goto error; isatty = PyObject_IsTrue(res); @@ -2302,7 +2302,7 @@ create_stdio(const PyConfig *config, PyObject* io, goto error; } - stream = _PyObject_CallMethod(io, _Py_ID(TextIOWrapper), "OOOsOO", + stream = _PyObject_CallMethod(io, &_Py_ID(TextIOWrapper), "OOOsOO", buf, encoding_str, errors_str, newline, line_buffering, write_through); Py_CLEAR(buf); @@ -2316,7 +2316,7 @@ create_stdio(const PyConfig *config, PyObject* io, else mode = "r"; text = PyUnicode_FromString(mode); - if (!text || PyObject_SetAttr(stream, _Py_ID(mode), text) < 0) + if (!text || PyObject_SetAttr(stream, &_Py_ID(mode), text) < 0) goto error; Py_CLEAR(text); return stream; @@ -2415,7 +2415,7 @@ init_sys_streams(PyThreadState *tstate) if (std == NULL) goto error; PySys_SetObject("__stdin__", std); - _PySys_SetAttr(_Py_ID(stdin), std); + _PySys_SetAttr(&_Py_ID(stdin), std); Py_DECREF(std); /* Set sys.stdout */ @@ -2426,7 +2426,7 @@ init_sys_streams(PyThreadState *tstate) if (std == NULL) goto error; PySys_SetObject("__stdout__", std); - _PySys_SetAttr(_Py_ID(stdout), std); + _PySys_SetAttr(&_Py_ID(stdout), std); Py_DECREF(std); #if 1 /* Disable this if you have trouble debugging bootstrap stuff */ @@ -2455,7 +2455,7 @@ init_sys_streams(PyThreadState *tstate) Py_DECREF(std); goto error; } - if (_PySys_SetAttr(_Py_ID(stderr), std) < 0) { + if (_PySys_SetAttr(&_Py_ID(stderr), std) < 0) { Py_DECREF(std); goto error; } @@ -2505,7 +2505,7 @@ _Py_FatalError_PrintExc(PyThreadState *tstate) return 0; } - ferr = _PySys_GetAttr(tstate, _Py_ID(stderr)); + ferr = _PySys_GetAttr(tstate, &_Py_ID(stderr)); if (ferr == NULL || ferr == Py_None) { /* sys.stderr is not set yet or set to None, no need to try to display the exception */ @@ -2530,7 +2530,7 @@ _Py_FatalError_PrintExc(PyThreadState *tstate) Py_XDECREF(tb); /* sys.stderr may be buffered: call sys.stderr.flush() */ - res = PyObject_CallMethodNoArgs(ferr, _Py_ID(flush)); + res = PyObject_CallMethodNoArgs(ferr, &_Py_ID(flush)); if (res == NULL) { _PyErr_Clear(tstate); } @@ -2883,7 +2883,7 @@ static void wait_for_thread_shutdown(PyThreadState *tstate) { PyObject *result; - PyObject *threading = PyImport_GetModule(_Py_ID(threading)); + PyObject *threading = PyImport_GetModule(&_Py_ID(threading)); if (threading == NULL) { if (_PyErr_Occurred(tstate)) { PyErr_WriteUnraisable(NULL); @@ -2891,7 +2891,7 @@ wait_for_thread_shutdown(PyThreadState *tstate) /* else: threading not imported */ return; } - result = PyObject_CallMethodNoArgs(threading, _Py_ID(_shutdown)); + result = PyObject_CallMethodNoArgs(threading, &_Py_ID(_shutdown)); if (result == NULL) { PyErr_WriteUnraisable(threading); } diff --git a/Python/pythonrun.c b/Python/pythonrun.c index f9a692dd385bbc9..b34a22391822b7c 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -117,14 +117,14 @@ _PyRun_InteractiveLoopObject(FILE *fp, PyObject *filename, PyCompilerFlags *flag } PyThreadState *tstate = _PyThreadState_GET(); - PyObject *v = _PySys_GetAttr(tstate, _Py_ID(ps1)); + PyObject *v = _PySys_GetAttr(tstate, &_Py_ID(ps1)); if (v == NULL) { - _PySys_SetAttr(_Py_ID(ps1), v = PyUnicode_FromString(">>> ")); + _PySys_SetAttr(&_Py_ID(ps1), v = PyUnicode_FromString(">>> ")); Py_XDECREF(v); } - v = _PySys_GetAttr(tstate, _Py_ID(ps2)); + v = _PySys_GetAttr(tstate, &_Py_ID(ps2)); if (v == NULL) { - _PySys_SetAttr(_Py_ID(ps2), v = PyUnicode_FromString("... ")); + _PySys_SetAttr(&_Py_ID(ps2), v = PyUnicode_FromString("... ")); Py_XDECREF(v); } @@ -195,16 +195,16 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, if (fp == stdin) { /* Fetch encoding from sys.stdin if possible. */ - v = _PySys_GetAttr(tstate, _Py_ID(stdin)); + v = _PySys_GetAttr(tstate, &_Py_ID(stdin)); if (v && v != Py_None) { - oenc = PyObject_GetAttr(v, _Py_ID(encoding)); + oenc = PyObject_GetAttr(v, &_Py_ID(encoding)); if (oenc) enc = PyUnicode_AsUTF8(oenc); if (!enc) PyErr_Clear(); } } - v = _PySys_GetAttr(tstate, _Py_ID(ps1)); + v = _PySys_GetAttr(tstate, &_Py_ID(ps1)); if (v != NULL) { v = PyObject_Str(v); if (v == NULL) @@ -217,7 +217,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, } } } - w = _PySys_GetAttr(tstate, _Py_ID(ps2)); + w = _PySys_GetAttr(tstate, &_Py_ID(ps2)); if (w != NULL) { w = PyObject_Str(w); if (w == NULL) @@ -252,7 +252,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename, } return -1; } - m = PyImport_AddModuleObject(_Py_ID(__main__)); + m = PyImport_AddModuleObject(&_Py_ID(__main__)); if (m == NULL) { _PyArena_Free(arena); return -1; @@ -506,23 +506,23 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *filename = NULL; /* new style errors. `err' is an instance */ - *message = PyObject_GetAttr(err, _Py_ID(msg)); + *message = PyObject_GetAttr(err, &_Py_ID(msg)); if (!*message) goto finally; - v = PyObject_GetAttr(err, _Py_ID(filename)); + v = PyObject_GetAttr(err, &_Py_ID(filename)); if (!v) goto finally; if (v == Py_None) { Py_DECREF(v); - *filename = _Py_STR(anon_string); + *filename = &_Py_STR(anon_string); Py_INCREF(*filename); } else { *filename = v; } - v = PyObject_GetAttr(err, _Py_ID(lineno)); + v = PyObject_GetAttr(err, &_Py_ID(lineno)); if (!v) goto finally; hold = PyLong_AsSsize_t(v); @@ -531,7 +531,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, goto finally; *lineno = hold; - v = PyObject_GetAttr(err, _Py_ID(offset)); + v = PyObject_GetAttr(err, &_Py_ID(offset)); if (!v) goto finally; if (v == Py_None) { @@ -546,7 +546,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, } if (Py_TYPE(err) == (PyTypeObject*)PyExc_SyntaxError) { - v = PyObject_GetAttr(err, _Py_ID(end_lineno)); + v = PyObject_GetAttr(err, &_Py_ID(end_lineno)); if (!v) { PyErr_Clear(); *end_lineno = *lineno; @@ -562,7 +562,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *end_lineno = hold; } - v = PyObject_GetAttr(err, _Py_ID(end_offset)); + v = PyObject_GetAttr(err, &_Py_ID(end_offset)); if (!v) { PyErr_Clear(); *end_offset = -1; @@ -583,7 +583,7 @@ parse_syntax_error(PyObject *err, PyObject **message, PyObject **filename, *end_offset = -1; } - v = PyObject_GetAttr(err, _Py_ID(text)); + v = PyObject_GetAttr(err, &_Py_ID(text)); if (!v) goto finally; if (v == Py_None) { @@ -717,7 +717,7 @@ _Py_HandleSystemExit(int *exitcode_p) if (PyExceptionInstance_Check(value)) { /* The error code should be in the `code' attribute. */ - PyObject *code = PyObject_GetAttr(value, _Py_ID(code)); + PyObject *code = PyObject_GetAttr(value, &_Py_ID(code)); if (code) { Py_DECREF(value); value = code; @@ -733,7 +733,7 @@ _Py_HandleSystemExit(int *exitcode_p) } else { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *sys_stderr = _PySys_GetAttr(tstate, _Py_ID(stderr)); + PyObject *sys_stderr = _PySys_GetAttr(tstate, &_Py_ID(stderr)); /* We clear the exception here to avoid triggering the assertion * in PyObject_Str that ensures it won't silently lose exception * details. @@ -796,17 +796,17 @@ _PyErr_PrintEx(PyThreadState *tstate, int set_sys_last_vars) /* Now we know v != NULL too */ if (set_sys_last_vars) { - if (_PySys_SetAttr(_Py_ID(last_type), exception) < 0) { + if (_PySys_SetAttr(&_Py_ID(last_type), exception) < 0) { _PyErr_Clear(tstate); } - if (_PySys_SetAttr(_Py_ID(last_value), v) < 0) { + if (_PySys_SetAttr(&_Py_ID(last_value), v) < 0) { _PyErr_Clear(tstate); } - if (_PySys_SetAttr(_Py_ID(last_traceback), tb) < 0) { + if (_PySys_SetAttr(&_Py_ID(last_traceback), tb) < 0) { _PyErr_Clear(tstate); } } - hook = _PySys_GetAttr(tstate, _Py_ID(excepthook)); + hook = _PySys_GetAttr(tstate, &_Py_ID(excepthook)); if (_PySys_Audit(tstate, "sys.excepthook", "OOOO", hook ? hook : Py_None, exception, v, tb) < 0) { if (PyErr_ExceptionMatches(PyExc_RuntimeError)) { @@ -952,7 +952,7 @@ print_exception_file_and_line(struct exception_print_context *ctx, PyObject *f = ctx->file; PyObject *tmp; - int res = _PyObject_LookupAttr(*value_p, _Py_ID(print_file_and_line), &tmp); + int res = _PyObject_LookupAttr(*value_p, &_Py_ID(print_file_and_line), &tmp); if (res <= 0) { if (res < 0) { PyErr_Clear(); @@ -1027,7 +1027,7 @@ print_exception_message(struct exception_print_context *ctx, PyObject *type, if (write_indented_margin(ctx, f) < 0) { return -1; } - PyObject *modulename = PyObject_GetAttr(type, _Py_ID(__module__)); + PyObject *modulename = PyObject_GetAttr(type, &_Py_ID(__module__)); if (modulename == NULL || !PyUnicode_Check(modulename)) { Py_XDECREF(modulename); PyErr_Clear(); @@ -1036,8 +1036,8 @@ print_exception_message(struct exception_print_context *ctx, PyObject *type, } } else { - if (!_PyUnicode_Equal(modulename, _Py_ID(builtins)) && - !_PyUnicode_Equal(modulename, _Py_ID(__main__))) + if (!_PyUnicode_Equal(modulename, &_Py_ID(builtins)) && + !_PyUnicode_Equal(modulename, &_Py_ID(__main__))) { int res = PyFile_WriteObject(modulename, f, Py_PRINT_RAW); Py_DECREF(modulename); @@ -1137,7 +1137,7 @@ print_exception_note(struct exception_print_context *ctx, PyObject *value) return 0; } - PyObject *note = PyObject_GetAttr(value, _Py_ID(__note__)); + PyObject *note = PyObject_GetAttr(value, &_Py_ID(__note__)); if (note == NULL) { return -1; } @@ -1522,7 +1522,7 @@ _PyErr_Display(PyObject *file, PyObject *exception, PyObject *value, PyObject *t Py_XDECREF(ctx.seen); /* Call file.flush() */ - PyObject *res = _PyObject_CallMethodNoArgs(file, _Py_ID(flush)); + PyObject *res = _PyObject_CallMethodNoArgs(file, &_Py_ID(flush)); if (!res) { /* Silently ignore file.flush() error */ PyErr_Clear(); @@ -1536,7 +1536,7 @@ void PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *file = _PySys_GetAttr(tstate, _Py_ID(stderr)); + PyObject *file = _PySys_GetAttr(tstate, &_Py_ID(stderr)); if (file == NULL) { _PyObject_Dump(value); fprintf(stderr, "lost sys.stderr\n"); @@ -1563,10 +1563,10 @@ PyRun_StringFlags(const char *str, int start, PyObject *globals, return NULL; mod = _PyParser_ASTFromString( - str, _Py_STR(anon_string), start, flags, arena); + str, &_Py_STR(anon_string), start, flags, arena); if (mod != NULL) - ret = run_mod(mod, _Py_STR(anon_string), globals, locals, flags, arena); + ret = run_mod(mod, &_Py_STR(anon_string), globals, locals, flags, arena); _PyArena_Free(arena); return ret; } @@ -1629,17 +1629,17 @@ flush_io(void) PyErr_Fetch(&type, &value, &traceback); PyThreadState *tstate = _PyThreadState_GET(); - f = _PySys_GetAttr(tstate, _Py_ID(stderr)); + f = _PySys_GetAttr(tstate, &_Py_ID(stderr)); if (f != NULL) { - r = _PyObject_CallMethodNoArgs(f, _Py_ID(flush)); + r = _PyObject_CallMethodNoArgs(f, &_Py_ID(flush)); if (r) Py_DECREF(r); else PyErr_Clear(); } - f = _PySys_GetAttr(tstate, _Py_ID(stdout)); + f = _PySys_GetAttr(tstate, &_Py_ID(stdout)); if (f != NULL) { - r = _PyObject_CallMethodNoArgs(f, _Py_ID(flush)); + r = _PyObject_CallMethodNoArgs(f, &_Py_ID(flush)); if (r) Py_DECREF(r); else diff --git a/Python/specialize.c b/Python/specialize.c index fd475e9f3ed4f3c..9d3ac1ebdf601c9 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -565,7 +565,7 @@ specialize_module_load_attr( SPECIALIZATION_FAIL(opcode, SPEC_FAIL_NON_STRING_OR_SPLIT); return -1; } - Py_ssize_t index = _PyDict_GetItemHint(dict, _Py_ID(__getattr__), -1, + Py_ssize_t index = _PyDict_GetItemHint(dict, &_Py_ID(__getattr__), -1, &value); assert(index != DKIX_ERROR); if (index != DKIX_EMPTY) { @@ -1209,7 +1209,7 @@ _Py_Specialize_BinarySubscr( goto success; } PyTypeObject *cls = Py_TYPE(container); - PyObject *descriptor = _PyType_Lookup(cls, _Py_ID(__getitem__)); + PyObject *descriptor = _PyType_Lookup(cls, &_Py_ID(__getitem__)); if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) { PyFunctionObject *func = (PyFunctionObject *)descriptor; PyCodeObject *code = (PyCodeObject *)func->func_code; @@ -1326,7 +1326,7 @@ _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *ins } goto fail; } - PyObject *descriptor = _PyType_Lookup(container_type, _Py_ID(__setitem__)); + PyObject *descriptor = _PyType_Lookup(container_type, &_Py_ID(__setitem__)); if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) { PyFunctionObject *func = (PyFunctionObject *)descriptor; PyCodeObject *code = (PyCodeObject *)func->func_code; @@ -1426,7 +1426,7 @@ specialize_method_descriptor( } if (_list_append == NULL) { _list_append = (PyMethodDescrObject *)_PyType_Lookup(&PyList_Type, - _Py_ID(append)); + &_Py_ID(append)); } assert(_list_append != NULL); if (nargs == 2 && descr == _list_append) { diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 4e5a333c53a040c..13645f1b50c34fa 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -270,7 +270,7 @@ sys_audit_tstate(PyThreadState *ts, const char *event, PyThreadState_EnterTracing(ts); while ((hook = PyIter_Next(hooks)) != NULL) { PyObject *o; - int canTrace = _PyObject_LookupAttr(hook, _Py_ID(__cantrace__), &o); + int canTrace = _PyObject_LookupAttr(hook, &_Py_ID(__cantrace__), &o); if (o) { canTrace = PyObject_IsTrue(o); Py_DECREF(o); @@ -641,7 +641,7 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) const char *stdout_encoding_str; int ret; - stdout_encoding = PyObject_GetAttr(outf, _Py_ID(encoding)); + stdout_encoding = PyObject_GetAttr(outf, &_Py_ID(encoding)); if (stdout_encoding == NULL) goto error; stdout_encoding_str = PyUnicode_AsUTF8(stdout_encoding); @@ -658,12 +658,12 @@ sys_displayhook_unencodable(PyObject *outf, PyObject *o) if (encoded == NULL) goto error; - if (_PyObject_LookupAttr(outf, _Py_ID(buffer), &buffer) < 0) { + if (_PyObject_LookupAttr(outf, &_Py_ID(buffer), &buffer) < 0) { Py_DECREF(encoded); goto error; } if (buffer) { - result = PyObject_CallMethodOneArg(buffer, _Py_ID(write), encoded); + result = PyObject_CallMethodOneArg(buffer, &_Py_ID(write), encoded); Py_DECREF(buffer); Py_DECREF(encoded); if (result == NULL) @@ -709,7 +709,7 @@ sys_displayhook(PyObject *module, PyObject *o) static PyObject *newline = NULL; PyThreadState *tstate = _PyThreadState_GET(); - builtins = PyImport_GetModule(_Py_ID(builtins)); + builtins = PyImport_GetModule(&_Py_ID(builtins)); if (builtins == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_SetString(tstate, PyExc_RuntimeError, @@ -725,9 +725,9 @@ sys_displayhook(PyObject *module, PyObject *o) if (o == Py_None) { Py_RETURN_NONE; } - if (PyObject_SetAttr(builtins, _Py_ID(_), Py_None) != 0) + if (PyObject_SetAttr(builtins, &_Py_ID(_), Py_None) != 0) return NULL; - outf = _PySys_GetAttr(tstate, _Py_ID(stdout)); + outf = _PySys_GetAttr(tstate, &_Py_ID(stdout)); if (outf == NULL || outf == Py_None) { _PyErr_SetString(tstate, PyExc_RuntimeError, "lost sys.stdout"); return NULL; @@ -754,7 +754,7 @@ sys_displayhook(PyObject *module, PyObject *o) } if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0) return NULL; - if (PyObject_SetAttr(builtins, _Py_ID(_), o) != 0) + if (PyObject_SetAttr(builtins, &_Py_ID(_), o) != 0) return NULL; Py_RETURN_NONE; } @@ -1686,7 +1686,7 @@ _PySys_GetSizeOf(PyObject *o) return (size_t)-1; } - method = _PyObject_LookupSpecial(o, _Py_ID(__sizeof__)); + method = _PyObject_LookupSpecial(o, &_Py_ID(__sizeof__)); if (method == NULL) { if (!_PyErr_Occurred(tstate)) { _PyErr_Format(tstate, PyExc_TypeError, @@ -2228,7 +2228,7 @@ _PySys_ReadPreinitXOptions(PyConfig *config) static PyObject * get_warnoptions(PyThreadState *tstate) { - PyObject *warnoptions = _PySys_GetAttr(tstate, _Py_ID(warnoptions)); + PyObject *warnoptions = _PySys_GetAttr(tstate, &_Py_ID(warnoptions)); if (warnoptions == NULL || !PyList_Check(warnoptions)) { /* PEP432 TODO: we can reach this if warnoptions is NULL in the main * interpreter config. When that happens, we need to properly set @@ -2244,7 +2244,7 @@ get_warnoptions(PyThreadState *tstate) if (warnoptions == NULL) { return NULL; } - if (sys_set_object(tstate->interp, _Py_ID(warnoptions), warnoptions)) { + if (sys_set_object(tstate->interp, &_Py_ID(warnoptions), warnoptions)) { Py_DECREF(warnoptions); return NULL; } @@ -2262,7 +2262,7 @@ PySys_ResetWarnOptions(void) return; } - PyObject *warnoptions = _PySys_GetAttr(tstate, _Py_ID(warnoptions)); + PyObject *warnoptions = _PySys_GetAttr(tstate, &_Py_ID(warnoptions)); if (warnoptions == NULL || !PyList_Check(warnoptions)) return; PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL); @@ -2316,7 +2316,7 @@ int PySys_HasWarnOptions(void) { PyThreadState *tstate = _PyThreadState_GET(); - PyObject *warnoptions = _PySys_GetAttr(tstate, _Py_ID(warnoptions)); + PyObject *warnoptions = _PySys_GetAttr(tstate, &_Py_ID(warnoptions)); return (warnoptions != NULL && PyList_Check(warnoptions) && PyList_GET_SIZE(warnoptions) > 0); } @@ -2324,7 +2324,7 @@ PySys_HasWarnOptions(void) static PyObject * get_xoptions(PyThreadState *tstate) { - PyObject *xoptions = _PySys_GetAttr(tstate, _Py_ID(_xoptions)); + PyObject *xoptions = _PySys_GetAttr(tstate, &_Py_ID(_xoptions)); if (xoptions == NULL || !PyDict_Check(xoptions)) { /* PEP432 TODO: we can reach this if xoptions is NULL in the main * interpreter config. When that happens, we need to properly set @@ -2340,7 +2340,7 @@ get_xoptions(PyThreadState *tstate) if (xoptions == NULL) { return NULL; } - if (sys_set_object(tstate->interp, _Py_ID(_xoptions), xoptions)) { + if (sys_set_object(tstate->interp, &_Py_ID(_xoptions), xoptions)) { Py_DECREF(xoptions); return NULL; } @@ -3042,7 +3042,7 @@ _PySys_SetPreliminaryStderr(PyObject *sysdict) if (pstderr == NULL) { goto error; } - if (PyDict_SetItem(sysdict, _Py_ID(stderr), pstderr) < 0) { + if (PyDict_SetItem(sysdict, &_Py_ID(stderr), pstderr) < 0) { goto error; } if (PyDict_SetItemString(sysdict, "__stderr__", pstderr) < 0) { @@ -3167,7 +3167,7 @@ PySys_SetPath(const wchar_t *path) if ((v = makepathobject(path, DELIM)) == NULL) Py_FatalError("can't create sys.path"); PyInterpreterState *interp = _PyInterpreterState_GET(); - if (sys_set_object(interp, _Py_ID(path), v) != 0) { + if (sys_set_object(interp, &_Py_ID(path), v) != 0) { Py_FatalError("can't assign sys.path"); } Py_DECREF(v); @@ -3224,7 +3224,7 @@ PySys_SetArgvEx(int argc, wchar_t **argv, int updatepath) Py_FatalError("can't compute path0 from argv"); } - PyObject *sys_path = _PySys_GetAttr(tstate, _Py_ID(path)); + PyObject *sys_path = _PySys_GetAttr(tstate, &_Py_ID(path)); if (sys_path != NULL) { if (PyList_Insert(sys_path, 0, path0) < 0) { Py_DECREF(path0); @@ -3251,7 +3251,7 @@ sys_pyfile_write_unicode(PyObject *unicode, PyObject *file) if (file == NULL) return -1; assert(unicode != NULL); - PyObject *result = _PyObject_CallMethodOneArg(file, _Py_ID(write), unicode); + PyObject *result = _PyObject_CallMethodOneArg(file, &_Py_ID(write), unicode); if (result == NULL) { return -1; } @@ -3335,7 +3335,7 @@ PySys_WriteStdout(const char *format, ...) va_list va; va_start(va, format); - sys_write(_Py_ID(stdout), stdout, format, va); + sys_write(&_Py_ID(stdout), stdout, format, va); va_end(va); } @@ -3345,7 +3345,7 @@ PySys_WriteStderr(const char *format, ...) va_list va; va_start(va, format); - sys_write(_Py_ID(stderr), stderr, format, va); + sys_write(&_Py_ID(stderr), stderr, format, va); va_end(va); } @@ -3378,7 +3378,7 @@ PySys_FormatStdout(const char *format, ...) va_list va; va_start(va, format); - sys_format(_Py_ID(stdout), stdout, format, va); + sys_format(&_Py_ID(stdout), stdout, format, va); va_end(va); } @@ -3388,6 +3388,6 @@ PySys_FormatStderr(const char *format, ...) va_list va; va_start(va, format); - sys_format(_Py_ID(stderr), stderr, format, va); + sys_format(&_Py_ID(stderr), stderr, format, va); va_end(va); } diff --git a/Python/traceback.c b/Python/traceback.c index 90d1d5e8ca9a971..f2ae38e56c33074 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -331,12 +331,12 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject * taillen = strlen(tail); PyThreadState *tstate = _PyThreadState_GET(); - syspath = _PySys_GetAttr(tstate, _Py_ID(path)); + syspath = _PySys_GetAttr(tstate, &_Py_ID(path)); if (syspath == NULL || !PyList_Check(syspath)) goto error; npath = PyList_Size(syspath); - open = PyObject_GetAttr(io, _Py_ID(open)); + open = PyObject_GetAttr(io, &_Py_ID(open)); for (i = 0; i < npath; i++) { v = PyList_GetItem(syspath, i); if (v == NULL) { @@ -452,7 +452,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int return -1; } - binary = _PyObject_CallMethod(io, _Py_ID(open), "Os", filename, "rb"); + binary = _PyObject_CallMethod(io, &_Py_ID(open), "Os", filename, "rb"); if (binary == NULL) { PyErr_Clear(); @@ -481,7 +481,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int PyMem_Free(found_encoding); return 0; } - fob = _PyObject_CallMethod(io, _Py_ID(TextIOWrapper), + fob = _PyObject_CallMethod(io, &_Py_ID(TextIOWrapper), "Os", binary, encoding); Py_DECREF(io); PyMem_Free(found_encoding); @@ -489,7 +489,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int if (fob == NULL) { PyErr_Clear(); - res = PyObject_CallMethodNoArgs(binary, _Py_ID(close)); + res = PyObject_CallMethodNoArgs(binary, &_Py_ID(close)); Py_DECREF(binary); if (res) Py_DECREF(res); @@ -508,7 +508,7 @@ display_source_line_with_margin(PyObject *f, PyObject *filename, int lineno, int break; } } - res = PyObject_CallMethodNoArgs(fob, _Py_ID(close)); + res = PyObject_CallMethodNoArgs(fob, &_Py_ID(close)); if (res) { Py_DECREF(res); } From f2d9b81ddc08a7b630bd88eccf7871da24b22753 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Fri, 4 Feb 2022 15:56:02 -0700 Subject: [PATCH 115/115] Add a compatibility shim for _PyObject_LookupSpecialId(). --- Include/cpython/object.h | 6 +++++- Include/internal/pycore_object.h | 2 ++ Modules/posixmodule.c | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Include/cpython/object.h b/Include/cpython/object.h index bf10c7a4f202767..f0e579c5b77d3cc 100644 --- a/Include/cpython/object.h +++ b/Include/cpython/object.h @@ -302,8 +302,12 @@ typedef struct _heaptypeobject { PyAPI_FUNC(const char *) _PyType_Name(PyTypeObject *); PyAPI_FUNC(PyObject *) _PyType_Lookup(PyTypeObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyType_LookupId(PyTypeObject *, _Py_Identifier *); -PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyObject_LookupSpecialId(PyObject *, _Py_Identifier *); +#ifndef Py_BUILD_CORE +// Backward compatibility for 3rd-party extensions +// that may be using the old name. +#define _PyObject_LookupSpecial _PyObject_LookupSpecialId +#endif PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *); PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *); PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *); diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h index 46b9d7828c8f620..65abc1884c3bbde 100644 --- a/Include/internal/pycore_object.h +++ b/Include/internal/pycore_object.h @@ -238,6 +238,8 @@ extern PyObject* _PyType_GetSubclasses(PyTypeObject *); #define _PyHeapType_GET_MEMBERS(etype) \ ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize)) +PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *); + #ifdef __cplusplus } #endif diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b3468cae3f57366..35e5486a9000880 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -22,11 +22,12 @@ # include "pycore_bitutils.h" // _Py_popcount32() #endif #include "pycore_call.h" // _PyObject_CallNoArgs() -#include "pycore_fileutils.h" // _Py_closerange() -#include "pycore_moduleobject.h" // _PyModule_GetState() #include "pycore_ceval.h" // _PyEval_ReInitThreads() +#include "pycore_fileutils.h" // _Py_closerange() #include "pycore_import.h" // _PyImport_ReInitLock() #include "pycore_initconfig.h" // _PyStatus_EXCEPTION() +#include "pycore_moduleobject.h" // _PyModule_GetState() +#include "pycore_object.h" // _PyObject_LookupSpecial() #include "pycore_pystate.h" // _PyInterpreterState_GET() #include "structmember.h" // PyMemberDef