bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928)

We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code.  It is still used in a number of non-builtin stdlib modules.

The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime.  A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings).

https://bugs.python.org/issue46541#msg411799 explains the rationale for this change.

The core of the change is in:

* (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros
* Include/internal/pycore_runtime_init.h - added the static initializers for the global strings
* Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState
* Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers

I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings.  That check is added to the PR CI config.

The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()).  This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *.

The following are not changed (yet):

* stop using _Py_IDENTIFIER() in the stdlib modules
* (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API
* (maybe) intern the strings during runtime init

https://bugs.python.org/issue46541
This commit is contained in:
Eric Snow 2022-02-08 13:39:07 -07:00 committed by GitHub
parent c018d3037b
commit 81c72044a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
108 changed files with 2282 additions and 1573 deletions

View File

@ -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)'

View File

@ -116,6 +116,10 @@ PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg)
2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL);
}
PyAPI_FUNC(PyObject *) _PyObject_CallMethod(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,

View File

@ -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

View File

@ -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 *);

View File

@ -43,10 +43,16 @@ typedef struct _Py_Identifier {
Py_ssize_t index;
} _Py_Identifier;
#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).
#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 /* NEEDS_PY_IDENTIFIER */
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
@ -249,7 +255,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 *, _Py_Identifier *);
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 *);

View File

@ -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 *);

View File

@ -30,6 +30,9 @@ PyAPI_FUNC(PyObject *) _PyObject_Call(
PyObject *args,
PyObject *kwargs);
extern PyObject * _PyObject_CallMethodFormat(
PyThreadState *tstate, PyObject *callable, const char *format, ...);
// Static inline variant of public PyVectorcall_Function().
static inline vectorcallfunc

View File

@ -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;
};

View File

@ -0,0 +1,337 @@
#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 ASCII_STR() have a common prefix,
// to help avoid collisions with keywords, etc.
#define STRUCT_FOR_ASCII_STR(LITERAL) \
struct { \
PyASCIIObject _ascii; \
uint8_t _data[sizeof(LITERAL)]; \
}
#define STRUCT_FOR_STR(NAME, LITERAL) \
STRUCT_FOR_ASCII_STR(LITERAL) _ ## NAME;
#define STRUCT_FOR_ID(NAME) \
STRUCT_FOR_ASCII_STR(#NAME) _ ## NAME;
// XXX Order by frequency of use?
/* The following is auto-generated by Tools/scripts/generate_global_objects.py. */
struct _Py_global_strings {
struct {
STRUCT_FOR_STR(empty, "")
STRUCT_FOR_STR(dot, ".")
STRUCT_FOR_STR(comma_sep, ", ")
STRUCT_FOR_STR(percent, "%")
STRUCT_FOR_STR(dbl_percent, "%%")
// "anonymous" labels
STRUCT_FOR_STR(anon_dictcomp, "<dictcomp>")
STRUCT_FOR_STR(anon_genexpr, "<genexpr>")
STRUCT_FOR_STR(anon_lambda, "<lambda>")
STRUCT_FOR_STR(anon_listcomp, "<listcomp>")
STRUCT_FOR_STR(anon_module, "<module>")
STRUCT_FOR_STR(anon_setcomp, "<setcomp>")
STRUCT_FOR_STR(anon_string, "<string>")
STRUCT_FOR_STR(dot_locals, ".<locals>")
} literals;
struct {
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 */
#undef ID
#undef STR
#define _Py_ID(NAME) \
(_Py_SINGLETON(strings.identifiers._ ## NAME._ascii.ob_base))
#define _Py_STR(NAME) \
(_Py_SINGLETON(strings.literals._ ## NAME._ascii.ob_base))
#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_GLOBAL_STRINGS_H */

View File

@ -8,9 +8,11 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
#include <stdbool.h>
#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) \
@ -236,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

View File

@ -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,26 @@ extern "C" {
_PyBytes_SIMPLE_INIT(CH, 1) \
}
#define _PyASCIIObject_INIT(LITERAL) \
{ \
._ascii = { \
.ob_base = _PyObject_IMMORTAL_INIT(&PyUnicode_Type), \
.length = sizeof(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) \
._ ## NAME = _PyASCIIObject_INIT(#NAME)
/* The following is auto-generated by Tools/scripts/generate_global_objects.py. */
#define _Py_global_objects_INIT { \
@ -622,6 +641,298 @@ extern "C" {
_PyBytes_CHAR_INIT(254), \
_PyBytes_CHAR_INIT(255), \
}, \
\
.strings = { \
.literals = { \
INIT_STR(empty, ""), \
INIT_STR(dot, "."), \
INIT_STR(comma_sep, ", "), \
INIT_STR(percent, "%"), \
INIT_STR(dbl_percent, "%%"), \
\
INIT_STR(anon_dictcomp, "<dictcomp>"), \
INIT_STR(anon_genexpr, "<genexpr>"), \
INIT_STR(anon_lambda, "<lambda>"), \
INIT_STR(anon_listcomp, "<listcomp>"), \
INIT_STR(anon_module, "<module>"), \
INIT_STR(anon_setcomp, "<setcomp>"), \
INIT_STR(anon_string, "<string>"), \
INIT_STR(dot_locals, ".<locals>"), \
}, \
.identifiers = { \
INIT_ID(Py_Repr), \
INIT_ID(TextIOWrapper), \
INIT_ID(WarningMessage), \
INIT_ID(_), \
INIT_ID(__IOBase_closed), \
INIT_ID(__abc_tpflags__), \
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(__args__), \
INIT_ID(__await__), \
INIT_ID(__bases__), \
INIT_ID(__bool__), \
INIT_ID(__build_class__), \
INIT_ID(__builtins__), \
INIT_ID(__bytes__), \
INIT_ID(__call__), \
INIT_ID(__cantrace__), \
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(__getinitargs__), \
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(__note__), \
INIT_ID(__or__), \
INIT_ID(__origin__), \
INIT_ID(__package__), \
INIT_ID(__parameters__), \
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(__reduce_ex__), \
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(__weakref__), \
INIT_ID(__xor__), \
INIT_ID(_abc_impl), \
INIT_ID(_blksize), \
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(_uninitialized_submodules), \
INIT_ID(_warn_unawaited_coroutine), \
INIT_ID(_xoptions), \
INIT_ID(add), \
INIT_ID(append), \
INIT_ID(big), \
INIT_ID(buffer), \
INIT_ID(builtins), \
INIT_ID(clear), \
INIT_ID(close), \
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(encoding), \
INIT_ID(end_lineno), \
INIT_ID(end_offset), \
INIT_ID(errors), \
INIT_ID(excepthook), \
INIT_ID(extend), \
INIT_ID(filename), \
INIT_ID(fileno), \
INIT_ID(fillvalue), \
INIT_ID(filters), \
INIT_ID(find_class), \
INIT_ID(flush), \
INIT_ID(get), \
INIT_ID(get_source), \
INIT_ID(getattr), \
INIT_ID(ignore), \
INIT_ID(importlib), \
INIT_ID(intersection), \
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(latin1), \
INIT_ID(lineno), \
INIT_ID(little), \
INIT_ID(match), \
INIT_ID(metaclass), \
INIT_ID(mode), \
INIT_ID(modules), \
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(obj), \
INIT_ID(offset), \
INIT_ID(onceregistry), \
INIT_ID(open), \
INIT_ID(parent), \
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), \
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(reducer_override), \
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(stderr), \
INIT_ID(stdin), \
INIT_ID(stdout), \
INIT_ID(strict), \
INIT_ID(symmetric_difference_update), \
INIT_ID(tell), \
INIT_ID(text), \
INIT_ID(threading), \
INIT_ID(throw), \
INIT_ID(unraisablehook), \
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 */

View File

@ -9,11 +9,6 @@ extern "C" {
#endif
/* runtime lifecycle */
extern PyStatus _PyStructSequence_InitState(PyInterpreterState *);
/* other API */
PyAPI_FUNC(PyTypeObject *) _PyStructSequence_NewType(

View File

@ -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

View File

@ -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];

View File

@ -2436,6 +2436,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'

View File

@ -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_ID()
#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,7 @@ 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 *impl = PyObject_GetAttr(self, &_Py_ID(_abc_impl));
if (impl == NULL) {
return NULL;
}
@ -311,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_GetAttrId(self, &PyId___dict__);
ns = PyObject_GetAttr(self, &_Py_ID(__dict__));
if (!ns) {
goto error;
}
@ -355,7 +347,7 @@ compute_abstract_methods(PyObject *self)
}
/* Stage 2: inherited abstract methods. */
bases = _PyObject_GetAttrId(self, &PyId___bases__);
bases = PyObject_GetAttr(self, &_Py_ID(__bases__));
if (!bases) {
goto error;
}
@ -368,8 +360,8 @@ compute_abstract_methods(PyObject *self)
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, &_Py_ID(__abstractmethods__),
&base_abstracts) < 0) {
goto error;
}
if (base_abstracts == NULL) {
@ -409,7 +401,7 @@ compute_abstract_methods(PyObject *self)
}
}
if (_PyObject_SetAttrId(self, &PyId___abstractmethods__, abstracts) < 0) {
if (PyObject_SetAttr(self, &_Py_ID(__abstractmethods__), abstracts) < 0) {
goto error;
}
@ -448,7 +440,7 @@ _abc__abc_init(PyObject *module, PyObject *self)
if (data == NULL) {
return NULL;
}
if (_PyObject_SetAttrId(self, &PyId__abc_impl, data) < 0) {
if (PyObject_SetAttr(self, &_Py_ID(_abc_impl), data) < 0) {
Py_DECREF(data);
return NULL;
}
@ -459,7 +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 *flags = _PyDict_GetItemIdWithError(cls->tp_dict, &PyId___abc_tpflags__);
PyObject *flags = PyDict_GetItemWithError(cls->tp_dict,
&_Py_ID(__abc_tpflags__));
if (flags == NULL) {
if (PyErr_Occurred()) {
return NULL;
@ -477,7 +470,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, &_Py_ID(__abc_tpflags__)) < 0) {
return NULL;
}
}
@ -593,7 +586,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self,
return NULL;
}
subclass = _PyObject_GetAttrId(instance, &PyId___class__);
subclass = PyObject_GetAttr(instance, &_Py_ID(__class__));
if (subclass == NULL) {
Py_DECREF(impl);
return NULL;
@ -622,12 +615,12 @@ _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, &_Py_ID(__subclasscheck__),
subclass);
goto end;
}
result = _PyObject_CallMethodIdOneArg(self, &PyId___subclasscheck__,
subclass);
result = PyObject_CallMethodOneArg(self, &_Py_ID(__subclasscheck__),
subclass);
if (result == NULL) {
goto end;
}
@ -639,8 +632,8 @@ _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, &_Py_ID(__subclasscheck__),
subtype);
break;
case 1: // Nothing to do.
break;
@ -723,8 +716,8 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
}
/* 3. Check the subclass hook. */
ok = _PyObject_CallMethodIdOneArg((PyObject *)self, &PyId___subclasshook__,
subclass);
ok = PyObject_CallMethodOneArg(
(PyObject *)self, &_Py_ID(__subclasshook__), subclass);
if (ok == NULL) {
goto end;
}

View File

@ -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()

View File

@ -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]

View File

@ -1348,9 +1348,8 @@ 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) {
if (_PyObject_LookupAttr((PyObject *)deque, &_Py_ID(__dict__), &dict) < 0) {
return NULL;
}
if (dict == NULL) {
@ -2064,7 +2063,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 +2070,7 @@ 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);
items = PyObject_CallMethodNoArgs((PyObject *)dd, &_Py_ID(items));
if (items == NULL) {
Py_DECREF(args);
return NULL;
@ -2310,8 +2308,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 +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_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__);
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 &&
@ -2381,7 +2377,7 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
}
}
else {
bound_get = _PyObject_GetAttrId(mapping, &PyId_get);
bound_get = PyObject_GetAttr(mapping, &_Py_ID(get));
if (bound_get == NULL)
goto done;

View File

@ -10,6 +10,8 @@ module instead.
#define MODULE_VERSION "1.0"
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef
#include <stdbool.h>

View File

@ -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

View File

@ -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

View File

@ -54,6 +54,8 @@
*/
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef

View File

@ -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

View File

@ -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

View File

@ -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()

View File

@ -3,6 +3,7 @@
#define PY_SSIZE_T_CLEAN
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include <sys/types.h>

View File

@ -12,6 +12,7 @@
*/
#define PY_SSIZE_T_CLEAN
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef

View File

@ -4,6 +4,7 @@
/* Doc strings: Mitch Chapman */
#define PY_SSIZE_T_CLEAN
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "gdbm.h"

View File

@ -241,11 +241,6 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
PyObject *raw, *modeobj = NULL, *buffer, *wrapper, *result = NULL, *path_or_fd = NULL;
_Py_IDENTIFIER(_blksize);
_Py_IDENTIFIER(isatty);
_Py_IDENTIFIER(mode);
_Py_IDENTIFIER(close);
is_number = PyNumber_Check(file);
if (is_number) {
@ -381,7 +376,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
/* buffering */
if (buffering < 0) {
PyObject *res = _PyObject_CallMethodIdNoArgs(raw, &PyId_isatty);
PyObject *res = PyObject_CallMethodNoArgs(raw, &_Py_ID(isatty));
if (res == NULL)
goto error;
isatty = PyLong_AsLong(res);
@ -399,7 +394,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
if (buffering < 0) {
PyObject *blksize_obj;
blksize_obj = _PyObject_GetAttrId(raw, &PyId__blksize);
blksize_obj = PyObject_GetAttr(raw, &_Py_ID(_blksize));
if (blksize_obj == NULL)
goto error;
buffering = PyLong_AsLong(blksize_obj);
@ -466,7 +461,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
result = wrapper;
Py_DECREF(buffer);
if (_PyObject_SetAttrId(wrapper, &PyId_mode, modeobj) < 0)
if (PyObject_SetAttr(wrapper, &_Py_ID(mode), modeobj) < 0)
goto error;
Py_DECREF(modeobj);
return result;
@ -475,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_CallMethodIdNoArgs(result, &PyId_close);
close_result = PyObject_CallMethodNoArgs(result, &_Py_ID(close));
_PyErr_ChainExceptions(exc, val, tb);
Py_XDECREF(close_result);
Py_DECREF(result);

View File

@ -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_ID(read1)
: &_Py_ID(read);
data = _PyObject_CallMethod(self, attr, "n", buffer->len);
if (data == NULL)
return NULL;
@ -436,8 +422,7 @@ buffered_dealloc_warn(buffered *self, PyObject *source)
{
if (self->ok && self->raw) {
PyObject *r;
r = _PyObject_CallMethodIdOneArg(self->raw, &PyId__dealloc_warn,
source);
r = PyObject_CallMethodOneArg(self->raw, &_Py_ID(_dealloc_warn), source);
if (r)
Py_DECREF(r);
else
@ -583,14 +568,14 @@ static PyObject *
buffered_name_get(buffered *self, void *context)
{
CHECK_INITIALIZED(self)
return _PyObject_GetAttrId(self->raw, &PyId_name);
return PyObject_GetAttr(self->raw, &_Py_ID(name));
}
static PyObject *
buffered_mode_get(buffered *self, void *context)
{
CHECK_INITIALIZED(self)
return _PyObject_GetAttrId(self->raw, &PyId_mode);
return PyObject_GetAttr(self->raw, &_Py_ID(mode));
}
/* Lower-level APIs */
@ -1381,7 +1366,7 @@ buffered_repr(buffered *self)
{
PyObject *nameobj, *res;
if (_PyObject_LookupAttrId((PyObject *) self, &PyId_name, &nameobj) < 0) {
if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) {
if (!PyErr_ExceptionMatches(PyExc_ValueError)) {
return NULL;
}
@ -2153,7 +2138,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 +2147,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 +2161,67 @@ _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);
return _forward_call(self->reader, &_Py_ID(read), args);
}
static PyObject *
bufferedrwpair_peek(rwpair *self, PyObject *args)
{
return _forward_call(self->reader, &PyId_peek, args);
return _forward_call(self->reader, &_Py_ID(peek), args);
}
static PyObject *
bufferedrwpair_read1(rwpair *self, PyObject *args)
{
return _forward_call(self->reader, &PyId_read1, args);
return _forward_call(self->reader, &_Py_ID(read1), args);
}
static PyObject *
bufferedrwpair_readinto(rwpair *self, PyObject *args)
{
return _forward_call(self->reader, &PyId_readinto, args);
return _forward_call(self->reader, &_Py_ID(readinto), args);
}
static PyObject *
bufferedrwpair_readinto1(rwpair *self, PyObject *args)
{
return _forward_call(self->reader, &PyId_readinto1, args);
return _forward_call(self->reader, &_Py_ID(readinto1), args);
}
static PyObject *
bufferedrwpair_write(rwpair *self, PyObject *args)
{
return _forward_call(self->writer, &PyId_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, &PyId_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, &PyId_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, &PyId_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, &PyId_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, &PyId_close, NULL);
ret = _forward_call(self->reader, &_Py_ID(close), NULL);
if (exc != NULL) {
_PyErr_ChainExceptions(exc, val, tb);
Py_CLEAR(ret);
@ -2247,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, &PyId_isatty, NULL);
PyObject *ret = _forward_call(self->writer, &_Py_ID(isatty), NULL);
if (ret != Py_False) {
/* either True or exception */
@ -2255,7 +2240,7 @@ bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored))
}
Py_DECREF(ret);
return _forward_call(self->reader, &PyId_isatty, NULL);
return _forward_call(self->reader, &_Py_ID(isatty), NULL);
}
static PyObject *

View File

@ -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,8 @@ _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);
res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type,
&_Py_ID(close), (PyObject *)self);
if (!self->closefd) {
self->fd = -1;
return res;
@ -476,7 +473,7 @@ _Py_COMP_DIAG_POP
_setmode(self->fd, O_BINARY);
#endif
if (_PyObject_SetAttrId((PyObject *)self, &PyId_name, nameobj) < 0)
if (PyObject_SetAttr((PyObject *)self, &_Py_ID(name), nameobj) < 0)
goto error;
if (self->appending) {
@ -1085,7 +1082,7 @@ fileio_repr(fileio *self)
if (self->fd < 0)
return PyUnicode_FromFormat("<_io.FileIO [closed]>");
if (_PyObject_LookupAttrId((PyObject *) self, &PyId_name, &nameobj) < 0) {
if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) {
return NULL;
}
if (nameobj == NULL) {

View File

@ -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,7 @@ 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);
return _PyObject_CallMethod(self, &_Py_ID(seek), "ii", 0, 1);
}
PyDoc_STRVAR(iobase_truncate_doc,
@ -138,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_LookupAttrId(self, &PyId___IOBase_closed, &res);
ret = _PyObject_LookupAttr(self, &_Py_ID(__IOBase_closed), &res);
Py_XDECREF(res);
return ret;
}
@ -239,7 +234,7 @@ _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);
rc = PyObject_SetAttr(self, &_Py_ID(__IOBase_closed), Py_True);
_PyErr_ChainExceptions(exc, val, tb);
if (rc < 0) {
Py_CLEAR(res);
@ -260,7 +255,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 +274,7 @@ 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))
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
@ -597,7 +591,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, &_Py_ID(read), "n", nreadahead);
if (b == NULL) {
/* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals()
when EINTR occurs so we needn't do it ourselves. */
@ -697,10 +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. */
_Py_IDENTIFIER(extend);
PyObject *ret = _PyObject_CallMethodIdObjArgs(result, &PyId_extend,
self, NULL);
PyObject *ret = PyObject_CallMethodObjArgs(result, &_Py_ID(extend),
self, NULL);
if (ret == NULL) {
goto error;
}
@ -919,9 +911,7 @@ _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);
return PyObject_CallMethodNoArgs(self, &_Py_ID(readall));
}
/* TODO: allocate a bytes object directly instead and manually construct
@ -967,8 +957,8 @@ _io__RawIOBase_readall_impl(PyObject *self)
return NULL;
while (1) {
PyObject *data = _PyObject_CallMethodId(self, &PyId_read,
"i", DEFAULT_BUFFER_SIZE);
PyObject *data = _PyObject_CallMethod(self, &_Py_ID(read),
"i", DEFAULT_BUFFER_SIZE);
if (!data) {
/* NOTE: PyErr_SetFromErrno() calls PyErr_CheckSignals()
when EINTR occurs so we needn't do it ourselves. */

View File

@ -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_ID(strict);
}
else {
self->errors = errors;
@ -586,11 +564,13 @@ _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) {
return _PyObject_CallMethod(self->decoder, &_Py_ID(setstate),
"((OK))", buffer, flag);
}
else {
Py_RETURN_NONE;
}
}
/*[clinic input]
@ -865,7 +845,7 @@ _textiowrapper_set_decoder(textio *self, PyObject *codec_info,
PyObject *res;
int r;
res = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_readable);
res = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(readable));
if (res == NULL)
return -1;
@ -920,7 +900,7 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info,
PyObject *res;
int r;
res = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_writable);
res = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(writable));
if (res == NULL)
return -1;
@ -939,7 +919,7 @@ _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) {
if (_PyObject_LookupAttr(codec_info, &_Py_ID(name), &res) < 0) {
return -1;
}
if (res != NULL && PyUnicode_Check(res)) {
@ -1099,10 +1079,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_ID(strict);
}
else if (!PyUnicode_Check(errors)) {
// Check 'errors' argument here because Argument Clinic doesn't support
@ -1142,7 +1119,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
state = IO_STATE();
if (state == NULL)
goto error;
fileno = _PyObject_CallMethodIdNoArgs(buffer, &PyId_fileno);
fileno = PyObject_CallMethodNoArgs(buffer, &_Py_ID(fileno));
/* Ignore only AttributeError and UnsupportedOperation */
if (fileno == NULL) {
if (PyErr_ExceptionMatches(PyExc_AttributeError) ||
@ -1228,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_LookupAttrId(buffer, &PyId_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) {
@ -1239,7 +1216,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
}
}
res = _PyObject_CallMethodIdNoArgs(buffer, &PyId_seekable);
res = PyObject_CallMethodNoArgs(buffer, &_Py_ID(seekable));
if (res == NULL)
goto error;
r = PyObject_IsTrue(res);
@ -1302,10 +1279,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_ID(strict);
}
const char *c_errors = PyUnicode_AsUTF8(errors);
@ -1640,8 +1614,8 @@ _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 *newtext = _PyObject_CallMethod(text, &_Py_ID(replace),
"ss", "\n", self->writenl);
Py_DECREF(text);
if (newtext == NULL)
return NULL;
@ -1740,7 +1714,7 @@ _io_TextIOWrapper_write_impl(textio *self, PyObject *text)
Py_CLEAR(self->snapshot);
if (self->decoder) {
ret = _PyObject_CallMethodIdNoArgs(self->decoder, &PyId_reset);
ret = PyObject_CallMethodNoArgs(self->decoder, &_Py_ID(reset));
if (ret == NULL)
return NULL;
Py_DECREF(ret);
@ -1944,7 +1918,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
if (n < 0) {
/* Read everything */
PyObject *bytes = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_read);
PyObject *bytes = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(read));
PyObject *decoded;
if (bytes == NULL)
goto fail;
@ -2404,13 +2378,16 @@ _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 {
res = _PyObject_CallMethod(self->decoder, &_Py_ID(setstate),
"((yi))", "", cookie->dec_flags);
}
if (res == NULL) {
return -1;
}
Py_DECREF(res);
return 0;
}
@ -2487,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_CallMethodIdNoArgs((PyObject *)self, &PyId_tell);
cookieObj = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(tell));
if (cookieObj == NULL)
goto fail;
break;
@ -2503,7 +2480,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
goto fail;
}
res = _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_flush);
res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (res == NULL)
goto fail;
Py_DECREF(res);
@ -2511,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_CallMethodIdNoArgs(self->decoder, &PyId_reset);
res = PyObject_CallMethodNoArgs(self->decoder, &_Py_ID(reset));
if (res == NULL)
goto fail;
Py_DECREF(res);
}
res = _PyObject_CallMethodId(self->buffer, &PyId_seek, "ii", 0, 2);
res = _PyObject_CallMethod(self->buffer, &_Py_ID(seek), "ii", 0, 2);
Py_CLEAR(cookieObj);
if (res == NULL)
goto fail;
@ -2583,8 +2560,8 @@ _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);
PyObject *input_chunk = _PyObject_CallMethod(self->buffer, &_Py_ID(read),
"i", cookie.bytes_to_feed);
PyObject *decoded;
if (input_chunk == NULL)
@ -2605,7 +2582,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
}
Py_XSETREF(self->snapshot, snapshot);
decoded = _PyObject_CallMethodIdObjArgs(self->decoder, &PyId_decode,
decoded = PyObject_CallMethodObjArgs(self->decoder, &_Py_ID(decode),
input_chunk, cookie.need_eof ? Py_True : Py_False, NULL);
if (check_decoded(decoded) < 0)
@ -2673,12 +2650,12 @@ _io_TextIOWrapper_tell_impl(textio *self)
if (_textiowrapper_writeflush(self) < 0)
return NULL;
res = _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_flush);
res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (res == NULL)
goto fail;
Py_DECREF(res);
posobj = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_tell);
posobj = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(tell));
if (posobj == NULL)
goto fail;
@ -2750,8 +2727,8 @@ _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, &_Py_ID(decode), "y#", start, len); \
if (check_decoded(_decoded) < 0) \
goto fail; \
res = PyUnicode_GET_LENGTH(_decoded); \
@ -2832,8 +2809,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, &_Py_ID(decode), "yO", "", /* final = */ Py_True);
if (check_decoded(decoded) < 0)
goto fail;
chars_decoded += PyUnicode_GET_LENGTH(decoded);
@ -2848,7 +2825,8 @@ _io_TextIOWrapper_tell_impl(textio *self)
}
finally:
res = _PyObject_CallMethodIdOneArg(self->decoder, &PyId_setstate, saved_state);
res = PyObject_CallMethodOneArg(
self->decoder, &_Py_ID(setstate), saved_state);
Py_DECREF(saved_state);
if (res == NULL)
return NULL;
@ -2862,7 +2840,8 @@ fail:
if (saved_state) {
PyObject *type, *value, *traceback;
PyErr_Fetch(&type, &value, &traceback);
res = _PyObject_CallMethodIdOneArg(self->decoder, &PyId_setstate, 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,7 +2892,7 @@ textiowrapper_repr(textio *self)
}
goto error;
}
if (_PyObject_LookupAttrId((PyObject *) self, &PyId_name, &nameobj) < 0) {
if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(name), &nameobj) < 0) {
if (!PyErr_ExceptionMatches(PyExc_ValueError)) {
goto error;
}
@ -2929,7 +2908,7 @@ textiowrapper_repr(textio *self)
if (res == NULL)
goto error;
}
if (_PyObject_LookupAttrId((PyObject *) self, &PyId_mode, &modeobj) < 0) {
if (_PyObject_LookupAttr((PyObject *) self, &_Py_ID(mode), &modeobj) < 0) {
goto error;
}
if (modeobj != NULL) {
@ -2969,7 +2948,7 @@ _io_TextIOWrapper_fileno_impl(textio *self)
/*[clinic end generated code: output=21490a4c3da13e6c input=c488ca83d0069f9b]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_fileno);
return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(fileno));
}
/*[clinic input]
@ -2981,7 +2960,7 @@ _io_TextIOWrapper_seekable_impl(textio *self)
/*[clinic end generated code: output=ab223dbbcffc0f00 input=8b005ca06e1fca13]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_seekable);
return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(seekable));
}
/*[clinic input]
@ -2993,7 +2972,7 @@ _io_TextIOWrapper_readable_impl(textio *self)
/*[clinic end generated code: output=72ff7ba289a8a91b input=0704ea7e01b0d3eb]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_readable);
return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(readable));
}
/*[clinic input]
@ -3005,7 +2984,7 @@ _io_TextIOWrapper_writable_impl(textio *self)
/*[clinic end generated code: output=a728c71790d03200 input=c41740bc9d8636e8]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_writable);
return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(writable));
}
/*[clinic input]
@ -3017,7 +2996,7 @@ _io_TextIOWrapper_isatty_impl(textio *self)
/*[clinic end generated code: output=12be1a35bace882e input=fb68d9f2c99bbfff]*/
{
CHECK_ATTACHED(self);
return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_isatty);
return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(isatty));
}
/*[clinic input]
@ -3033,7 +3012,7 @@ _io_TextIOWrapper_flush_impl(textio *self)
self->telling = self->seekable;
if (_textiowrapper_writeflush(self) < 0)
return NULL;
return _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_flush);
return PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(flush));
}
/*[clinic input]
@ -3062,21 +3041,20 @@ _io_TextIOWrapper_close_impl(textio *self)
else {
PyObject *exc = NULL, *val, *tb;
if (self->finalizing) {
res = _PyObject_CallMethodIdOneArg(self->buffer,
&PyId__dealloc_warn,
(PyObject *)self);
res = PyObject_CallMethodOneArg(self->buffer, &_Py_ID(_dealloc_warn),
(PyObject *)self);
if (res)
Py_DECREF(res);
else
PyErr_Clear();
}
res = _PyObject_CallMethodIdNoArgs((PyObject *)self, &PyId_flush);
res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(flush));
if (res == NULL)
PyErr_Fetch(&exc, &val, &tb);
else
Py_DECREF(res);
res = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_close);
res = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(close));
if (exc != NULL) {
_PyErr_ChainExceptions(exc, val, tb);
Py_CLEAR(res);
@ -3127,7 +3105,7 @@ static PyObject *
textiowrapper_name_get(textio *self, void *context)
{
CHECK_ATTACHED(self);
return _PyObject_GetAttrId(self->buffer, &PyId_name);
return PyObject_GetAttr(self->buffer, &_Py_ID(name));
}
static PyObject *

View File

@ -156,8 +156,6 @@ typedef struct {
PyTypeObject PyWindowsConsoleIO_Type;
_Py_IDENTIFIER(name);
int
_PyWindowsConsoleIO_closed(PyObject *self)
{
@ -196,9 +194,8 @@ _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);
res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type,
&_Py_ID(close), (PyObject*)self);
if (!self->closefd) {
self->fd = -1;
return res;
@ -394,7 +391,7 @@ _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)
if (PyObject_SetAttr((PyObject *)self, &_Py_ID(name), nameobj) < 0)
goto error;
goto done;

View File

@ -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

View File

@ -6,6 +6,7 @@
*/
#define PY_SSIZE_T_CLEAN
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef

View File

@ -1,5 +1,6 @@
#include "Python.h"
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_runtime.h" // _Py_ID()
#include "clinic/_operator.c.h"
typedef struct {
@ -1693,11 +1694,10 @@ 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);
partial = PyObject_GetAttr(functools, &_Py_ID(partial));
Py_DECREF(functools);
if (!partial)
return NULL;

View File

@ -11,6 +11,8 @@
#include "Python.h"
#include "pycore_floatobject.h" // _PyFloat_Pack8()
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_runtime.h" // _Py_ID()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "structmember.h" // PyMemberDef
#include <stdlib.h> // strtol()
@ -35,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 {
@ -225,9 +234,8 @@ _Pickle_InitState(PickleState *st)
PyObject *compat_pickle = NULL;
PyObject *codecs = NULL;
PyObject *functools = NULL;
_Py_IDENTIFIER(getattr);
st->getattr = _PyEval_GetBuiltinId(&PyId_getattr);
st->getattr = _PyEval_GetBuiltin(&_Py_ID(getattr));
if (st->getattr == NULL)
goto error;
@ -373,7 +381,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 +389,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 +1183,8 @@ _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) {
if (_PyObject_LookupAttr(file, &_Py_ID(write), &self->write) < 0) {
return -1;
}
if (self->write == NULL) {
@ -1636,20 +1643,15 @@ _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) {
if (_PyObject_LookupAttr(file, &_Py_ID(peek), &self->peek) < 0) {
return -1;
}
if (_PyObject_LookupAttrId(file, &PyId_readinto, &self->readinto) < 0) {
if (_PyObject_LookupAttr(file, &_Py_ID(readinto), &self->readinto) < 0) {
return -1;
}
(void)_PyObject_LookupAttrId(file, &PyId_read, &self->read);
(void)_PyObject_LookupAttrId(file, &PyId_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,
@ -1809,11 +1811,10 @@ 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);
dotted_path = PyUnicode_Split(name, &_Py_STR(dot), -1);
if (dotted_path == NULL)
return NULL;
n = PyList_GET_SIZE(dotted_path);
@ -1914,11 +1915,8 @@ 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) {
if (_PyObject_LookupAttr(global, &_Py_ID(__module__), &module_name) < 0) {
return NULL;
}
if (module_name) {
@ -1932,7 +1930,8 @@ whichmodule(PyObject *global, PyObject *dotted_path)
assert(module_name == NULL);
/* Fallback on walking sys.modules */
modules = _PySys_GetObjectId(&PyId_modules);
PyThreadState *tstate = _PyThreadState_GET();
modules = _PySys_GetAttr(tstate, &_Py_ID(modules));
if (modules == NULL) {
PyErr_SetString(PyExc_RuntimeError, "unable to get sys.modules");
return NULL;
@ -1977,8 +1976,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_ID(__main__);
Py_INCREF(module_name);
return module_name;
}
@ -2427,13 +2426,12 @@ 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;
reduce_value = Py_BuildValue("(O(OO))",
st->codecs_encode, unicode_str,
_PyUnicode_FromId(&PyId_latin1));
&_Py_ID(latin1));
Py_DECREF(unicode_str);
}
@ -3335,9 +3333,7 @@ save_dict(PicklerObject *self, PyObject *obj)
status = batch_dict_exact(self, obj);
Py_LeaveRecursiveCall();
} else {
_Py_IDENTIFIER(items);
items = _PyObject_CallMethodIdNoArgs(obj, &PyId_items);
items = PyObject_CallMethodNoArgs(obj, &_Py_ID(items));
if (items == NULL)
goto error;
iter = PyObject_GetIter(items);
@ -3589,8 +3585,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 +3593,10 @@ save_global(PicklerObject *self, PyObject *obj, PyObject *name)
global_name = name;
}
else {
if (_PyObject_LookupAttrId(obj, &PyId___qualname__, &global_name) < 0)
if (_PyObject_LookupAttr(obj, &_Py_ID(__qualname__), &global_name) < 0)
goto error;
if (global_name == NULL) {
global_name = _PyObject_GetAttrId(obj, &PyId___name__);
global_name = PyObject_GetAttr(obj, &_Py_ID(__name__));
if (global_name == NULL)
goto error;
}
@ -3923,9 +3917,8 @@ static PyObject *
get_class(PyObject *obj)
{
PyObject *cls;
_Py_IDENTIFIER(__class__);
if (_PyObject_LookupAttrId(obj, &PyId___class__, &cls) == 0) {
if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &cls) == 0) {
cls = (PyObject *) Py_TYPE(obj);
Py_INCREF(cls);
}
@ -4008,18 +4001,14 @@ 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) {
if (_PyObject_LookupAttr(callable, &_Py_ID(__name__), &name) < 0) {
return -1;
}
if (name != NULL && PyUnicode_Check(name)) {
_Py_IDENTIFIER(__newobj_ex__);
use_newobj_ex = _PyUnicode_EqualToASCIIId(
name, &PyId___newobj_ex__);
use_newobj_ex = _PyUnicode_Equal(name, &_Py_ID(__newobj_ex__));
if (!use_newobj_ex) {
_Py_IDENTIFIER(__newobj__);
use_newobj = _PyUnicode_EqualToASCIIId(name, &PyId___newobj__);
use_newobj = _PyUnicode_Equal(name, &_Py_ID(__newobj__));
}
}
Py_XDECREF(name);
@ -4071,13 +4060,12 @@ 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__);
cls_new = PyObject_GetAttr(cls, &_Py_ID(__new__));
if (cls_new == NULL) {
Py_DECREF(newargs);
return -1;
@ -4412,9 +4400,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 +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_LookupAttrId(obj, &PyId___reduce_ex__, &reduce_func) < 0) {
if (_PyObject_LookupAttr(obj, &_Py_ID(__reduce_ex__), &reduce_func) < 0) {
goto error;
}
if (reduce_func != NULL) {
@ -4436,7 +4421,7 @@ save(PicklerObject *self, PyObject *obj, int pers_save)
}
else {
/* Check for a __reduce__ method. */
if (_PyObject_LookupAttrId(obj, &PyId___reduce__, &reduce_func) < 0) {
if (_PyObject_LookupAttr(obj, &_Py_ID(__reduce__), &reduce_func) < 0) {
goto error;
}
if (reduce_func != NULL) {
@ -4489,10 +4474,9 @@ 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) {
if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(reducer_override),
&tmp) < 0) {
goto error;
}
/* Cache the reducer_override method, if it exists. */
@ -4727,9 +4711,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 +4743,14 @@ _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,
if (init_method_ref((PyObject *)self, &_Py_ID(persistent_id),
&self->pers_func, &self->pers_func_self) < 0)
{
return -1;
}
if (_PyObject_LookupAttrId((PyObject *)self,
&PyId_dispatch_table, &self->dispatch_table) < 0) {
if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(dispatch_table),
&self->dispatch_table) < 0) {
return -1;
}
@ -5123,10 +5104,8 @@ 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);
return PyObject_CallMethodObjArgs((PyObject *)self, &_Py_ID(find_class),
module_name, global_name, NULL);
}
static Py_ssize_t
@ -5813,14 +5792,12 @@ 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) {
if (_PyObject_LookupAttr(cls, &_Py_ID(__getinitargs__), &func) < 0) {
return NULL;
}
if (func == NULL) {
return _PyObject_CallMethodIdOneArg(cls, &PyId___new__, cls);
return PyObject_CallMethodOneArg(cls, &_Py_ID(__new__), cls);
}
Py_DECREF(func);
}
@ -6465,9 +6442,8 @@ do_append(UnpicklerObject *self, Py_ssize_t x)
}
else {
PyObject *extend_func;
_Py_IDENTIFIER(extend);
if (_PyObject_LookupAttrId(list, &PyId_extend, &extend_func) < 0) {
if (_PyObject_LookupAttr(list, &_Py_ID(extend), &extend_func) < 0) {
return -1;
}
if (extend_func != NULL) {
@ -6484,12 +6460,11 @@ 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);
append_func = PyObject_GetAttr(list, &_Py_ID(append));
if (append_func == NULL)
return -1;
for (i = x; i < len; i++) {
@ -6612,9 +6587,8 @@ load_additems(UnpicklerObject *self)
}
else {
PyObject *add_func;
_Py_IDENTIFIER(add);
add_func = _PyObject_GetAttrId(set, &PyId_add);
add_func = PyObject_GetAttr(set, &_Py_ID(add));
if (add_func == NULL)
return -1;
for (i = mark; i < len; i++) {
@ -6642,7 +6616,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 +6629,7 @@ load_build(UnpicklerObject *self)
inst = self->stack->data[Py_SIZE(self->stack) - 1];
if (_PyObject_LookupAttrId(inst, &PyId___setstate__, &setstate) < 0) {
if (_PyObject_LookupAttr(inst, &_Py_ID(__setstate__), &setstate) < 0) {
Py_DECREF(state);
return -1;
}
@ -6692,14 +6665,13 @@ 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__);
dict = PyObject_GetAttr(inst, &_Py_ID(__dict__));
if (dict == NULL)
goto error;
@ -7251,8 +7223,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 +7238,7 @@ _pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file,
self->fix_imports = fix_imports;
if (init_method_ref((PyObject *)self, &PyId_persistent_load,
if (init_method_ref((PyObject *)self, &_Py_ID(persistent_load),
&self->pers_func, &self->pers_func_self) < 0)
{
return -1;

View File

@ -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"

View File

@ -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"

View File

@ -23,6 +23,8 @@
* 3. This notice may not be removed or altered from any source distribution.
*/
#define NEEDS_PY_IDENTIFIER
#include <Python.h>
#include "cursor.h"

View File

@ -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"

View File

@ -22,6 +22,7 @@
#define OPENSSL_NO_DEPRECATED 1
#define PY_SSIZE_T_CLEAN
#define NEEDS_PY_IDENTIFIER
#include "Python.h"

View File

@ -13,6 +13,7 @@
#undef Py_BUILD_CORE_MODULE
#undef Py_BUILD_CORE_BUILTIN
#define NEEDS_PY_IDENTIFIER
/* Always enable assertions */
#undef NDEBUG
@ -3865,7 +3866,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)

View File

@ -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,12 +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;
}
int r = PyObject_RichCompareBool(name, str_dict, Py_EQ);
int r = PyObject_RichCompareBool(name, &_Py_ID(__dict__), Py_EQ);
if (r == -1) {
return -1;
}
@ -994,12 +984,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;
}
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);
}
@ -1413,7 +1398,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 +1405,7 @@ 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) {
if (_PyObject_LookupAttr(thread, &_Py_ID(name), &name) < 0) {
return -1;
}
}
@ -1459,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_CallMethodIdNoArgs(file, &PyId_flush);
PyObject *res = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (!res) {
return -1;
}
@ -1514,7 +1498,8 @@ 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 *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 */

View File

@ -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"

View File

@ -5,6 +5,7 @@
*/
#define PY_SSIZE_T_CLEAN
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef
#include "multibytecodec.h"

View File

@ -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
@ -155,7 +150,8 @@ faulthandler_get_fileno(PyObject **file_ptr)
PyObject *file = *file_ptr;
if (file == NULL || file == Py_None) {
file = _PySys_GetObjectId(&PyId_stderr);
PyThreadState *tstate = _PyThreadState_GET();
file = _PySys_GetAttr(tstate, &_Py_ID(stderr));
if (file == NULL) {
PyErr_SetString(PyExc_RuntimeError, "unable to get sys.stderr");
return -1;
@ -178,7 +174,7 @@ faulthandler_get_fileno(PyObject **file_ptr)
return fd;
}
result = _PyObject_CallMethodIdNoArgs(file, &PyId_fileno);
result = PyObject_CallMethodNoArgs(file, &_Py_ID(fileno));
if (result == NULL)
return -1;
@ -196,7 +192,7 @@ faulthandler_get_fileno(PyObject **file_ptr)
return -1;
}
result = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
result = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (result != NULL)
Py_DECREF(result);
else {
@ -1336,7 +1332,7 @@ faulthandler_init_enable(void)
return -1;
}
PyObject *res = _PyObject_CallMethodIdNoArgs(module, &PyId_enable);
PyObject *res = PyObject_CallMethodNoArgs(module, &_Py_ID(enable));
Py_DECREF(module);
if (res == NULL) {
return -1;

View File

@ -503,9 +503,8 @@ _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));
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
}
return Py_BuildValue("O(OO)", Py_TYPE(lz), lz->parent, lz->tgtkey);
}
@ -1015,7 +1014,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 +1030,7 @@ itertools_tee_impl(PyObject *module, PyObject *iterable, Py_ssize_t n)
return NULL;
}
if (_PyObject_LookupAttrId(it, &PyId___copy__, &copyfunc) < 0) {
if (_PyObject_LookupAttr(it, &_Py_ID(__copy__), &copyfunc) < 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_GetAttrId(copyable, &PyId___copy__);
copyfunc = PyObject_GetAttr(copyable, &_Py_ID(__copy__));
if (copyfunc == NULL) {
Py_DECREF(copyable);
Py_DECREF(result);
@ -1179,9 +1177,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 *res = _PyObject_CallMethod(it, &_Py_ID(__setstate__),
"n", lz->index);
if (res == NULL) {
Py_DECREF(it);
return NULL;
@ -4545,7 +4542,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 +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_GetItemIdWithError(kwds, &PyId_fillvalue);
fillvalue = PyDict_GetItemWithError(kwds, &_Py_ID(fillvalue));
}
if (fillvalue == NULL) {
if (!PyErr_Occurred()) {

View File

@ -158,11 +158,10 @@ error:
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);
sys_path = PyDict_GetItemWithError(sysdict, &_Py_ID(path));
if (sys_path == NULL && PyErr_Occurred()) {
return -1;
}

View File

@ -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()
@ -1216,7 +1217,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 +1289,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 +2167,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,

View File

@ -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 <Python.h>

View File

@ -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"

View File

@ -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
@ -323,8 +324,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 +1158,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_LookupSpecial(o, &_Py_ID(__fspath__));
if (NULL == func) {
goto error_format;
}
@ -14437,7 +14436,7 @@ PyOS_FSPath(PyObject *path)
return path;
}
func = _PyObject_LookupSpecial(path, &PyId___fspath__);
func = _PyObject_LookupSpecial(path, &_Py_ID(__fspath__));
if (NULL == func) {
return PyErr_Format(PyExc_TypeError,
"expected str, bytes or os.PathLike object, "

View File

@ -1,3 +1,5 @@
#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include <ctype.h>

View File

@ -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_ID()
#include <ctype.h>
@ -910,13 +911,12 @@ 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);
func = PyObject_GetAttr(module, &_Py_ID(_strptime_time));
Py_DECREF(module);
if (!func) {
return NULL;

View File

@ -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

View File

@ -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,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
return res;
}
}
hint = _PyObject_LookupSpecial(o, &PyId___length_hint__);
hint = _PyObject_LookupSpecial(o, &_Py_ID(__length_hint__));
if (hint == NULL) {
if (PyErr_Occurred()) {
return -1;
@ -177,14 +176,13 @@ 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) {
if (_PyObject_LookupAttr(o, &_Py_ID(__class_getitem__), &meth) < 0) {
return NULL;
}
if (meth) {
@ -770,7 +768,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 +794,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
}
/* Find the (unbound!) __format__ method */
meth = _PyObject_LookupSpecial(obj, &PyId___format__);
meth = _PyObject_LookupSpecial(obj, &_Py_ID(__format__));
if (meth == NULL) {
PyThreadState *tstate = _PyThreadState_GET();
if (!_PyErr_Occurred(tstate)) {
@ -1520,7 +1517,6 @@ PyNumber_Long(PyObject *o)
PyNumberMethods *m;
PyObject *trunc_func;
Py_buffer view;
_Py_IDENTIFIER(__trunc__);
if (o == NULL) {
return null_error();
@ -1562,7 +1558,7 @@ PyNumber_Long(PyObject *o)
if (m && m->nb_index) {
return PyNumber_Index(o);
}
trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__);
trunc_func = _PyObject_LookupSpecial(o, &_Py_ID(__trunc__));
if (trunc_func) {
if (PyErr_WarnEx(PyExc_DeprecationWarning,
"The delegation of int() to __trunc__ is deprecated.", 1)) {
@ -2406,12 +2402,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;
}
@ -2422,7 +2418,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);
@ -2437,43 +2433,37 @@ 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);
return method_output_as_list(o, &_Py_ID(keys));
}
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);
return method_output_as_list(o, &_Py_ID(items));
}
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);
return method_output_as_list(o, &_Py_ID(values));
}
/* isinstance(), issubclass() */
@ -2505,10 +2495,9 @@ PyMapping_Values(PyObject *o)
static PyObject *
abstract_get_bases(PyObject *cls)
{
_Py_IDENTIFIER(__bases__);
PyObject *bases;
(void)_PyObject_LookupAttrId(cls, &PyId___bases__, &bases);
(void)_PyObject_LookupAttr(cls, &_Py_ID(__bases__), &bases);
if (bases != NULL && !PyTuple_Check(bases)) {
Py_DECREF(bases);
return NULL;
@ -2589,11 +2578,10 @@ object_isinstance(PyObject *inst, PyObject *cls)
{
PyObject *icls;
int retval;
_Py_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, &_Py_ID(__class__), &icls);
if (icls != NULL) {
if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) {
retval = PyType_IsSubtype(
@ -2611,7 +2599,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, &_Py_ID(__class__), &icls);
if (icls != NULL) {
retval = abstract_issubclass(icls, cls);
Py_DECREF(icls);
@ -2624,8 +2612,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;
@ -2656,7 +2642,7 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls
return r;
}
PyObject *checker = _PyObject_LookupSpecial(cls, &PyId___instancecheck__);
PyObject *checker = _PyObject_LookupSpecial(cls, &_Py_ID(__instancecheck__));
if (checker != NULL) {
if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) {
Py_DECREF(checker);
@ -2715,7 +2701,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. */
@ -2744,7 +2729,7 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls)
return r;
}
checker = _PyObject_LookupSpecial(cls, &PyId___subclasscheck__);
checker = _PyObject_LookupSpecial(cls, &_Py_ID(__subclasscheck__));
if (checker != NULL) {
int ok = -1;
if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) {
@ -2879,7 +2864,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) {
@ -2891,7 +2875,7 @@ PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result)
*result = Py_TYPE(iter)->tp_iternext(iter);
}
else {
*result = _PyObject_CallMethodIdOneArg(iter, &PyId_send, arg);
*result = PyObject_CallMethodOneArg(iter, &_Py_ID(send), arg);
}
if (*result != NULL) {
return PYGEN_NEXT;

View File

@ -2112,10 +2112,9 @@ static PyObject *
_common_reduce(PyByteArrayObject *self, int proto)
{
PyObject *dict;
_Py_IDENTIFIER(__dict__);
char *buf;
if (_PyObject_LookupAttrId((PyObject *)self, &PyId___dict__, &dict) < 0) {
if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(__dict__), &dict) < 0) {
return NULL;
}
if (dict == NULL) {
@ -2428,12 +2427,11 @@ PyDoc_STRVAR(length_hint_doc,
static PyObject *
bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored))
{
_Py_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(&_Py_ID(iter)),
it->it_seq, it->it_index);
} else {
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
}
}

View File

@ -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,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_LookupSpecial(v, &_Py_ID(__bytes__));
if (func != NULL) {
result = _PyObject_CallNoArgs(func);
Py_DECREF(func);
@ -2582,7 +2580,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_LookupSpecial(x, &_Py_ID(__bytes__))) != NULL) {
bytes = _PyObject_CallNoArgs(func);
Py_DECREF(func);
if (bytes == NULL)
@ -3122,12 +3120,11 @@ PyDoc_STRVAR(length_hint_doc,
static PyObject *
striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored))
{
_Py_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(&_Py_ID(iter)),
it->it_seq, it->it_index);
} else {
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
}
}

View File

@ -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, ...)
{
@ -658,6 +657,30 @@ PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...)
}
PyObject *
_PyObject_CallMethod(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(PyObject *obj, _Py_Identifier *name,
const char *format, ...)
@ -682,6 +705,17 @@ _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name,
}
PyObject * _PyObject_CallMethodFormat(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, ...)

View File

@ -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,13 @@ 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__);
funcname = PyObject_GetAttr(func, &_Py_ID(__name__));
if (funcname == NULL) {
return NULL;
}
return Py_BuildValue("N(ON)", _PyEval_GetBuiltinId(&PyId_getattr),
self, funcname);
return Py_BuildValue(
"N(ON)", _PyEval_GetBuiltin(&_Py_ID(getattr)), self, funcname);
}
static PyMethodDef method_methods[] = {
@ -280,9 +277,9 @@ method_repr(PyMethodObject *a)
PyObject *funcname, *result;
const char *defname = "?";
if (_PyObject_LookupAttrId(func, &PyId___qualname__, &funcname) < 0 ||
if (_PyObject_LookupAttr(func, &_Py_ID(__qualname__), &funcname) < 0 ||
(funcname == NULL &&
_PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0))
_PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0))
{
return NULL;
}
@ -515,7 +512,7 @@ instancemethod_repr(PyObject *self)
return NULL;
}
if (_PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0) {
if (_PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0) {
return NULL;
}
if (funcname != NULL && !PyUnicode_Check(funcname)) {

View File

@ -281,9 +281,8 @@ static PyObject *
try_complex_special_method(PyObject *op)
{
PyObject *f;
_Py_IDENTIFIER(__complex__);
f = _PyObject_LookupSpecial(op, &PyId___complex__);
f = _PyObject_LookupSpecial(op, &_Py_ID(__complex__));
if (f) {
PyObject *res = _PyObject_CallNoArgs(f);
Py_DECREF(f);

View File

@ -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__);
type_qualname = PyObject_GetAttr(
(PyObject *)descr->d_type, &_Py_ID(__qualname__));
if (type_qualname == NULL)
return NULL;
@ -608,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_GetBuiltinId(&PyId_getattr),
return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(&_Py_ID(getattr)),
PyDescr_TYPE(descr), PyDescr_NAME(descr));
}
@ -1086,8 +1083,7 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs
{
return NULL;
}
_Py_IDENTIFIER(get);
return _PyObject_VectorcallMethodId(&PyId_get, newargs,
return _PyObject_VectorcallMethod(&_Py_ID(get), newargs,
3 | PY_VECTORCALL_ARGUMENTS_OFFSET,
NULL);
}
@ -1095,36 +1091,31 @@ 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);
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(keys));
}
static PyObject *
mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
{
_Py_IDENTIFIER(values);
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_values);
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(values));
}
static PyObject *
mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
{
_Py_IDENTIFIER(items);
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_items);
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(items));
}
static PyObject *
mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
{
_Py_IDENTIFIER(copy);
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_copy);
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(copy));
}
static PyObject *
mappingproxy_reversed(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
{
_Py_IDENTIFIER(__reversed__);
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId___reversed__);
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(__reversed__));
}
/* WARNING: mappingproxy methods must not give access
@ -1321,7 +1312,7 @@ wrapper_repr(wrapperobject *wp)
static PyObject *
wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored))
{
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr),
return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(&_Py_ID(getattr)),
wp->self, PyDescr_NAME(wp->descr));
}
@ -1756,9 +1747,8 @@ 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);
int rc = _PyObject_LookupAttr(fget, &_Py_ID(__doc__), &get_doc);
if (rc <= 0) {
return rc;
}
@ -1770,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_SetAttrId((PyObject *)self, &PyId___doc__, get_doc);
int err = PyObject_SetAttr(
(PyObject *)self, &_Py_ID(__doc__), get_doc);
Py_DECREF(get_doc);
if (err < 0)
return -1;

View File

@ -1484,6 +1484,17 @@ PyDict_GetItemWithError(PyObject *op, PyObject *key)
return value;
}
PyObject *
_PyDict_GetItemWithError(PyObject *dp, PyObject *kv)
{
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);
}
PyObject *
_PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key)
{
@ -2166,8 +2177,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_LookupSpecial((PyObject *)mp, &PyId___missing__);
missing = _PyObject_LookupSpecial(
(PyObject *)mp, &_Py_ID(__missing__));
if (missing != NULL) {
res = PyObject_CallOneArg(missing, key);
Py_DECREF(missing);
@ -2369,9 +2380,8 @@ 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) {
if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
return -1;
}
if (func != NULL) {
@ -4128,7 +4138,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);
@ -4138,7 +4147,7 @@ dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored))
if (list == NULL) {
return NULL;
}
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list);
}
PyTypeObject PyDictRevIterItem_Type = {
@ -4408,9 +4417,8 @@ dictviews_sub(PyObject *self, PyObject *other)
return NULL;
}
_Py_IDENTIFIER(difference_update);
PyObject *tmp = _PyObject_CallMethodIdOneArg(
result, &PyId_difference_update, other);
PyObject *tmp = PyObject_CallMethodOneArg(
result, &_Py_ID(difference_update), other);
if (tmp == NULL) {
Py_DECREF(result);
return NULL;
@ -4446,8 +4454,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);
return PyObject_CallMethodObjArgs(
other, &_Py_ID(intersection), self, NULL);
}
/* if other is another dict view, and it is bigger than self,
@ -4587,9 +4595,8 @@ dictitems_xor(PyObject *self, PyObject *other)
}
key = val1 = val2 = NULL;
_Py_IDENTIFIER(items);
PyObject *remaining_pairs = _PyObject_CallMethodIdNoArgs(temp_dict,
&PyId_items);
PyObject *remaining_pairs = PyObject_CallMethodNoArgs(
temp_dict, &_Py_ID(items));
if (remaining_pairs == NULL) {
goto error;
}
@ -4621,9 +4628,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 *tmp = PyObject_CallMethodOneArg(
result, &_Py_ID(symmetric_difference_update), other);
if (tmp == NULL) {
Py_DECREF(result);
return NULL;

View File

@ -356,9 +356,8 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq)
Py_ssize_t n;
PyObject *reversed_meth;
reversedobject *ro;
_Py_IDENTIFIER(__reversed__);
reversed_meth = _PyObject_LookupSpecial(seq, &PyId___reversed__);
reversed_meth = _PyObject_LookupSpecial(seq, &_Py_ID(__reversed__));
if (reversed_meth == Py_None) {
Py_DECREF(reversed_meth);
PyErr_Format(PyExc_TypeError,

View File

@ -1499,16 +1499,14 @@ 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) {
if (self->name && PyDict_SetItem(dict, &_Py_ID(name), self->name) < 0) {
Py_DECREF(dict);
return NULL;
}
if (self->path && _PyDict_SetItemId(dict, &PyId_path, self->path) < 0) {
if (self->path && PyDict_SetItem(dict, &_Py_ID(path), self->path) < 0) {
Py_DECREF(dict);
return NULL;
}

View File

@ -26,8 +26,6 @@
extern "C" {
#endif
_Py_IDENTIFIER(open);
/* External C interface */
PyObject *
@ -40,9 +38,9 @@ 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);
stream = _PyObject_CallMethod(io, &_Py_ID(open), "isisssO", fd, mode,
buffering, encoding, errors,
newline, closefd ? Py_True : Py_False);
Py_DECREF(io);
if (stream == NULL)
return NULL;
@ -54,7 +52,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) {
@ -63,10 +60,10 @@ PyFile_GetLine(PyObject *f, int n)
}
if (n <= 0) {
result = _PyObject_CallMethodIdNoArgs(f, &PyId_readline);
result = PyObject_CallMethodNoArgs(f, &_Py_ID(readline));
}
else {
result = _PyObject_CallMethodId(f, &PyId_readline, "i", n);
result = _PyObject_CallMethod(f, &_Py_ID(readline), "i", n);
}
if (result != NULL && !PyBytes_Check(result) &&
!PyUnicode_Check(result)) {
@ -120,13 +117,12 @@ 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);
writer = PyObject_GetAttr(f, &_Py_ID(write));
if (writer == NULL)
return -1;
if (flags & Py_PRINT_RAW) {
@ -182,12 +178,11 @@ PyObject_AsFileDescriptor(PyObject *o)
{
int fd;
PyObject *meth;
_Py_IDENTIFIER(fileno);
if (PyLong_Check(o)) {
fd = _PyLong_AsInt(o);
}
else if (_PyObject_LookupAttrId(o, &PyId_fileno, &meth) < 0) {
else if (_PyObject_LookupAttr(o, &_Py_ID(fileno), &meth) < 0) {
return -1;
}
else if (meth != NULL) {
@ -509,8 +504,7 @@ PyFile_OpenCodeObject(PyObject *path)
} else {
iomod = PyImport_ImportModule("_io");
if (iomod) {
f = _PyObject_CallMethodId(iomod, &PyId_open, "Os",
path, "rb");
f = _PyObject_CallMethod(iomod, &_Py_ID(open), "Os", path, "rb");
Py_DECREF(iomod);
}
}

View File

@ -770,8 +770,6 @@ PyTypeObject PyFrame_Type = {
0, /* tp_dict */
};
_Py_IDENTIFIER(__builtins__);
static void
init_frame(InterpreterFrame *frame, PyFunctionObject *func, PyObject *locals)
{
@ -1074,7 +1072,7 @@ PyFrame_GetBack(PyFrameObject *frame)
PyObject*
_PyEval_BuiltinsFromGlobals(PyThreadState *tstate, PyObject *globals)
{
PyObject *builtins = _PyDict_GetItemIdWithError(globals, &PyId___builtins__);
PyObject *builtins = PyDict_GetItemWithError(globals, &_Py_ID(__builtins__));
if (builtins) {
if (PyModule_Check(builtins)) {
builtins = _PyModule_GetDict(builtins);

View File

@ -79,8 +79,7 @@ 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 *module = PyDict_GetItemWithError(globals, &_Py_ID(__name__));
PyObject *builtins = NULL;
if (module == NULL && _PyErr_Occurred(tstate)) {
goto error;
@ -808,12 +807,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; \
} \
if (functools_copy_attr(wrapper, wrapped, attr) < 0) { \
if (functools_copy_attr(wrapper, wrapped, &_Py_ID(ATTR)) < 0) { \
return -1; \
} \
} while (0) \

View File

@ -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,12 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
goto done;
}
if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) {
if (_PyObject_LookupAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
goto done;
}
if (tmp != NULL) {
Py_DECREF(tmp);
if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) {
if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) {
goto done;
}
if (tmp != NULL) {
@ -72,13 +68,13 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
}
}
if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) {
if (_PyObject_LookupAttr(p, &_Py_ID(__qualname__), &qualname) < 0) {
goto done;
}
if (qualname == NULL) {
goto use_repr;
}
if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) {
if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) {
goto done;
}
if (module == NULL || module == Py_None) {
@ -218,9 +214,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) {
if (_PyObject_LookupAttr(t, &_Py_ID(__parameters__),
&subparams) < 0) {
Py_DECREF(parameters);
return NULL;
}
@ -260,9 +256,8 @@ _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) {
if (_PyObject_LookupAttr(obj, &_Py_ID(__parameters__), &subparams) < 0) {
return NULL;
}
if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) {

View File

@ -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,7 @@ gen_close_iter(PyObject *yf)
}
else {
PyObject *meth;
if (_PyObject_LookupAttrId(yf, &PyId_close, &meth) < 0) {
if (_PyObject_LookupAttr(yf, &_Py_ID(close), &meth) < 0) {
PyErr_WriteUnraisable(yf);
}
if (meth) {
@ -417,7 +416,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 +460,7 @@ _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) {
if (_PyObject_LookupAttr(yf, &_Py_ID(throw), &meth) < 0) {
Py_DECREF(yf);
return NULL;
}

View File

@ -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)
{
@ -106,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_GetBuiltinId(&PyId_iter),
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
it->it_seq, it->it_index);
else
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
}
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
@ -245,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_GetBuiltinId(&PyId_iter),
return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(&_Py_ID(iter)),
it->it_callable, it->it_sentinel);
else
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
}
static PyMethodDef calliter_methods[] = {

View File

@ -3505,25 +3505,25 @@ listreviter_setstate(listreviterobject *it, PyObject *state)
static PyObject *
listiter_reduce_general(void *_it, int forward)
{
_Py_IDENTIFIER(iter);
_Py_IDENTIFIER(reversed);
PyObject *list;
/* 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) {
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_GetBuiltinId(&PyId_reversed),
if (it->it_seq) {
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(reversed)),
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);
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list);
}

View File

@ -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)
@ -5775,9 +5772,9 @@ int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder,
if (byteorder == NULL)
little_endian = 0;
else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_little))
else if (_PyUnicode_Equal(byteorder, &_Py_ID(little)))
little_endian = 1;
else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_big))
else if (_PyUnicode_Equal(byteorder, &_Py_ID(big)))
little_endian = 0;
else {
PyErr_SetString(PyExc_ValueError,
@ -5837,9 +5834,9 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
if (byteorder == NULL)
little_endian = 0;
else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_little))
else if (_PyUnicode_Equal(byteorder, &_Py_ID(little)))
little_endian = 1;
else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_big))
else if (_PyUnicode_Equal(byteorder, &_Py_ID(big)))
little_endian = 0;
else {
PyErr_SetString(PyExc_ValueError,

View File

@ -179,12 +179,10 @@ 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),
return Py_BuildValue("N(Os)", _PyEval_GetBuiltin(&_Py_ID(getattr)),
m->m_self, m->m_ml->ml_name);
}
@ -223,14 +221,13 @@ 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__);
type_qualname = PyObject_GetAttr(type, &_Py_ID(__qualname__));
if (type_qualname == NULL)
return NULL;

View File

@ -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,19 @@ 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)
if (PyDict_SetItem(md_dict, &_Py_ID(__name__), name) != 0)
return -1;
if (_PyDict_SetItemId(md_dict, &PyId___doc__, doc) != 0)
if (PyDict_SetItem(md_dict, &_Py_ID(__doc__), doc) != 0)
return -1;
if (_PyDict_SetItemId(md_dict, &PyId___package__, Py_None) != 0)
if (PyDict_SetItem(md_dict, &_Py_ID(__package__), Py_None) != 0)
return -1;
if (_PyDict_SetItemId(md_dict, &PyId___loader__, Py_None) != 0)
if (PyDict_SetItem(md_dict, &_Py_ID(__loader__), Py_None) != 0)
return -1;
if (_PyDict_SetItemId(md_dict, &PyId___spec__, Py_None) != 0)
if (PyDict_SetItem(md_dict, &_Py_ID(__spec__), Py_None) != 0)
return -1;
if (PyUnicode_CheckExact(name)) {
Py_INCREF(name);
@ -474,7 +464,7 @@ PyModule_SetDocString(PyObject *m, const char *doc)
PyObject *v;
v = PyUnicode_FromString(doc);
if (v == NULL || _PyObject_SetAttrId(m, &PyId___doc__, v) != 0) {
if (v == NULL || PyObject_SetAttr(m, &_Py_ID(__doc__), v) != 0) {
Py_XDECREF(v);
return -1;
}
@ -503,7 +493,7 @@ PyModule_GetNameObject(PyObject *m)
}
d = ((PyModuleObject *)m)->md_dict;
if (d == NULL || !PyDict_Check(d) ||
(name = _PyDict_GetItemIdWithError(d, &PyId___name__)) == NULL ||
(name = PyDict_GetItemWithError(d, &_Py_ID(__name__))) == NULL ||
!PyUnicode_Check(name))
{
if (!PyErr_Occurred()) {
@ -528,7 +518,6 @@ PyModule_GetName(PyObject *m)
PyObject*
PyModule_GetFilenameObject(PyObject *m)
{
_Py_IDENTIFIER(__file__);
PyObject *d;
PyObject *fileobj;
if (!PyModule_Check(m)) {
@ -537,7 +526,7 @@ PyModule_GetFilenameObject(PyObject *m)
}
d = ((PyModuleObject *)m)->md_dict;
if (d == NULL ||
(fileobj = _PyDict_GetItemIdWithError(d, &PyId___file__)) == NULL ||
(fileobj = PyDict_GetItemWithError(d, &_Py_ID(__file__))) == NULL ||
!PyUnicode_Check(fileobj))
{
if (!PyErr_Occurred()) {
@ -726,8 +715,7 @@ int
_PyModuleSpec_IsInitializing(PyObject *spec)
{
if (spec != NULL) {
_Py_IDENTIFIER(_initializing);
PyObject *value = _PyObject_GetAttrId(spec, &PyId__initializing);
PyObject *value = PyObject_GetAttr(spec, &_Py_ID(_initializing));
if (value != NULL) {
int initializing = PyObject_IsTrue(value);
Py_DECREF(value);
@ -750,8 +738,7 @@ _PyModuleSpec_IsUninitializedSubmodule(PyObject *spec, PyObject *name)
return 0;
}
_Py_IDENTIFIER(_uninitialized_submodules);
PyObject *value = _PyObject_GetAttrId(spec, &PyId__uninitialized_submodules);
PyObject *value = PyObject_GetAttr(spec, &_Py_ID(_uninitialized_submodules));
if (value == NULL) {
return 0;
}
@ -774,18 +761,17 @@ module_getattro(PyModuleObject *m, PyObject *name)
}
PyErr_Clear();
assert(m->md_dict != NULL);
_Py_IDENTIFIER(__getattr__);
getattr = _PyDict_GetItemIdWithError(m->md_dict, &PyId___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_GetItemIdWithError(m->md_dict, &PyId___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_GetItemIdWithError(m->md_dict, &PyId___spec__);
PyObject *spec = PyDict_GetItemWithError(m->md_dict, &_Py_ID(__spec__));
if (spec == NULL && PyErr_Occurred()) {
Py_DECREF(mod_name);
return NULL;
@ -861,11 +847,11 @@ static PyObject *
module_dir(PyObject *self, PyObject *args)
{
PyObject *result = NULL;
PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__);
PyObject *dict = PyObject_GetAttr(self, &_Py_ID(__dict__));
if (dict != NULL) {
if (PyDict_Check(dict)) {
PyObject *dirfunc = _PyDict_GetItemIdWithError(dict, &PyId___dir__);
PyObject *dirfunc = PyDict_GetItemWithError(dict, &_Py_ID(__dir__));
if (dirfunc) {
result = _PyObject_CallNoArgs(dirfunc);
}
@ -891,7 +877,7 @@ static PyMethodDef module_methods[] = {
static PyObject *
module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored))
{
PyObject *dict = _PyObject_GetAttrId((PyObject *)m, &PyId___dict__);
PyObject *dict = PyObject_GetAttr((PyObject *)m, &_Py_ID(__dict__));
if ((dict == NULL) || !PyDict_Check(dict)) {
PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary");
@ -901,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_ContainsId(dict, &PyId___annotations__)) {
annotations = _PyDict_GetItemIdWithError(dict, &PyId___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.
@ -914,7 +900,8 @@ 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, &_Py_ID(__annotations__), annotations);
if (result) {
Py_CLEAR(annotations);
}
@ -928,7 +915,7 @@ 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 *dict = PyObject_GetAttr((PyObject *)m, &_Py_ID(__dict__));
if ((dict == NULL) || !PyDict_Check(dict)) {
PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary");
@ -937,17 +924,17 @@ module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignor
if (value != NULL) {
/* set */
ret = _PyDict_SetItemId(dict, &PyId___annotations__, value);
ret = PyDict_SetItem(dict, &_Py_ID(__annotations__), value);
goto exit;
}
/* delete */
if (!_PyDict_ContainsId(dict, &PyId___annotations__)) {
if (!PyDict_Contains(dict, &_Py_ID(__annotations__))) {
PyErr_Format(PyExc_AttributeError, "__annotations__");
goto exit;
}
ret = _PyDict_DelItemId(dict, &PyId___annotations__);
ret = PyDict_DelItem(dict, &_Py_ID(__annotations__));
exit:
Py_XDECREF(dict);

View File

@ -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,7 @@ PyObject_Bytes(PyObject *v)
return v;
}
func = _PyObject_LookupSpecial(v, &PyId___bytes__);
func = _PyObject_LookupSpecial(v, &_Py_ID(__bytes__));
if (func != NULL) {
result = _PyObject_CallNoArgs(func);
Py_DECREF(func);
@ -600,12 +595,9 @@ 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);
int ret = _PyObject_LookupAttr(x, &_Py_ID(__qualname__), &qualname);
if (qualname == NULL) {
if (ret < 0) {
return NULL;
@ -614,13 +606,9 @@ _PyObject_FunctionStr(PyObject *x)
}
PyObject *module;
PyObject *result = NULL;
ret = _PyObject_LookupAttrId(x, &PyId___module__, &module);
ret = _PyObject_LookupAttr(x, &_Py_ID(__module__), &module);
if (module != NULL && module != Py_None) {
PyObject *builtinsname = _PyUnicode_FromId(&PyId_builtins);
if (builtinsname == NULL) {
goto done;
}
ret = PyObject_RichCompareBool(module, builtinsname, Py_NE);
ret = PyObject_RichCompareBool(module, &_Py_ID(builtins), Py_NE);
if (ret < 0) {
// error
goto done;
@ -858,7 +846,7 @@ _PyObject_IsAbstract(PyObject *obj)
if (obj == NULL)
return 0;
res = _PyObject_LookupAttrId(obj, &PyId___isabstractmethod__, &isabstract);
res = _PyObject_LookupAttr(obj, &_Py_ID(__isabstractmethod__), &isabstract);
if (res > 0) {
res = PyObject_IsTrue(isabstract);
Py_DECREF(isabstract);
@ -892,8 +880,6 @@ 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)){
@ -901,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_SetAttrId(value, &PyId_name, name) ||
_PyObject_SetAttrId(value, &PyId_obj, v))) {
(PyObject_SetAttr(value, &_Py_ID(name), name) ||
PyObject_SetAttr(value, &_Py_ID(obj), v))) {
return 1;
}
PyErr_Restore(type, value, traceback);
@ -1569,7 +1555,7 @@ static PyObject *
_dir_object(PyObject *obj)
{
PyObject *result, *sorted;
PyObject *dirfunc = _PyObject_LookupSpecial(obj, &PyId___dir__);
PyObject *dirfunc = _PyObject_LookupSpecial(obj, &_Py_ID(__dir__));
assert(obj != NULL);
if (dirfunc == NULL) {
@ -2148,7 +2134,7 @@ Py_ReprEnter(PyObject *obj)
early on startup. */
if (dict == NULL)
return 0;
list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr);
list = PyDict_GetItemWithError(dict, &_Py_ID(Py_Repr));
if (list == NULL) {
if (PyErr_Occurred()) {
return -1;
@ -2156,7 +2142,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, &_Py_ID(Py_Repr), list) < 0)
return -1;
Py_DECREF(list);
}
@ -2184,7 +2170,7 @@ Py_ReprLeave(PyObject *obj)
if (dict == NULL)
goto finally;
list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr);
list = PyDict_GetItemWithError(dict, &_Py_ID(Py_Repr));
if (list == NULL || !PyList_Check(list))
goto finally;

View File

@ -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,11 @@ 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__);
dict = PyObject_GetAttr((PyObject *)od, &_Py_ID(__dict__));
if (dict == NULL)
goto Done;
else {
@ -973,7 +970,7 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored))
if (args == NULL)
goto Done;
items = _PyObject_CallMethodIdNoArgs((PyObject *)od, &PyId_items);
items = PyObject_CallMethodNoArgs((PyObject *)od, &_Py_ID(items));
if (items == NULL)
goto Done;
@ -1431,8 +1428,8 @@ odict_repr(PyODictObject *self)
}
}
else {
PyObject *items = _PyObject_CallMethodIdNoArgs((PyObject *)self,
&PyId_items);
PyObject *items = PyObject_CallMethodNoArgs(
(PyObject *)self, &_Py_ID(items));
if (items == NULL)
goto Done;
pieces = PySequence_List(items);
@ -1808,7 +1805,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 +1817,7 @@ odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored))
if (list == NULL) {
return NULL;
}
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list);
}
static PyMethodDef odictiter_methods[] = {
@ -2217,9 +2213,8 @@ 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) {
if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
return -1;
}
if (func != NULL) {
@ -2251,7 +2246,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg)
}
return 0;
}
if (_PyObject_LookupAttrId(arg, &PyId_items, &func) < 0) {
if (_PyObject_LookupAttr(arg, &_Py_ID(items), &func) < 0) {
return -1;
}
if (func != NULL) {

View File

@ -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);
return Py_BuildValue(
"N(N)l", _PyEval_GetBuiltin(&_Py_ID(iter)), 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);
return Py_BuildValue(
"N(N)O", _PyEval_GetBuiltin(&_Py_ID(iter)), range, r->index);
}
static PyObject *

View File

@ -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,7 @@ setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored))
if (list == NULL) {
return NULL;
}
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list);
}
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
@ -1906,7 +1905,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 +1912,7 @@ 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) {
if (_PyObject_LookupAttr((PyObject *)so, &_Py_ID(__dict__), &dict) < 0) {
goto done;
}
if (dict == NULL) {

View File

@ -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_ID(n_sequence_fields))
#define REAL_SIZE_TP(tp) \
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, &PyId_n_unnamed_fields)
#define UNNAMED_FIELDS_TP(tp) \
get_type_attr_as_size(tp, &_Py_ID(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();
}

View File

@ -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))
{
_Py_IDENTIFIER(iter);
if (it->it_seq)
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
it->it_seq, it->it_index);
else
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
}
static PyObject *

File diff suppressed because it is too large Load Diff

View File

@ -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_STR(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)
@ -2009,10 +1986,11 @@ unicode_dealloc(PyObject *unicode)
static int
unicode_is_singleton(PyObject *unicode)
{
struct _Py_unicode_state *state = get_unicode_state();
if (unicode == state->empty_string) {
if (unicode == &_Py_STR(empty)) {
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);
@ -15551,11 +15529,14 @@ _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();
if (!_Py_IsMainInterpreter(interp)) {
return _PyStatus_OK();
}
#ifdef Py_DEBUG
assert(_PyUnicode_CheckConsistency(&_Py_STR(empty), 1));
#endif
return _PyStatus_OK();
}
@ -15798,15 +15779,14 @@ 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);
if (it->it_seq != NULL) {
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_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_GetBuiltinId(&PyId_iter), u);
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), u);
}
}
@ -16137,7 +16117,6 @@ _PyUnicode_Fini(PyInterpreterState *interp)
for (Py_ssize_t i = 0; i < 256; i++) {
Py_CLEAR(state->latin1[i]);
}
Py_CLEAR(state->empty_string);
}

View File

@ -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,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
return _PyUnicodeWriter_WriteASCIIString(writer, "None", 4);
}
if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) {
if (_PyObject_LookupAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
goto exit;
}
if (tmp) {
Py_DECREF(tmp);
if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) {
if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) {
goto exit;
}
if (tmp) {
@ -285,13 +281,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
}
}
if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) {
if (_PyObject_LookupAttr(p, &_Py_ID(__qualname__), &qualname) < 0) {
goto exit;
}
if (qualname == NULL) {
goto use_repr;
}
if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) {
if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) {
goto exit;
}
if (module == NULL || module == Py_None) {

View File

@ -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,7 @@ weakref_repr(PyWeakReference *self)
}
Py_INCREF(obj);
if (_PyObject_LookupAttrId(obj, &PyId___name__, &name) < 0) {
if (_PyObject_LookupAttr(obj, &_Py_ID(__name__), &name) < 0) {
Py_DECREF(obj);
return NULL;
}
@ -462,10 +461,9 @@ 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* res = PyObject_CallMethodNoArgs(proxy, &_Py_ID(special)); \
Py_DECREF(proxy); \
return res; \
}

View File

@ -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;
@ -462,25 +460,28 @@ fp_setreadl(struct tok_state *tok, const char* enc)
}
io = PyImport_ImportModule("io");
if (io == NULL)
if (io == NULL) {
return 0;
stream = _PyObject_CallMethodId(io, &PyId_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)
if (stream == NULL) {
return 0;
}
readline = _PyObject_GetAttrId(stream, &PyId_readline);
readline = PyObject_GetAttr(stream, &_Py_ID(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);
}

View File

@ -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

View File

@ -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,

View File

@ -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,15 @@ 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) \
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);
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 +130,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 +158,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 +177,7 @@ check_matched(PyObject *obj, PyObject *arg)
}
/* Otherwise assume a regex filter and call its match() method */
result = _PyObject_CallMethodIdOneArg(obj, &PyId_match, arg);
result = PyObject_CallMethodOneArg(obj, &_Py_ID(match), arg);
if (result == NULL)
return -1;
@ -177,25 +186,21 @@ check_matched(PyObject *obj, PyObject *arg)
return rc;
}
#define GET_WARNINGS_ATTR(interp, attr, try_import) \
get_warnings_attr(interp, &_Py_ID(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;
}
/* 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 */
@ -210,27 +215,31 @@ 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);
warnings_module = PyImport_GetModule(&_Py_ID(warnings));
if (warnings_module == NULL)
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 +260,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 +292,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 +349,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 +381,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 +393,19 @@ 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);
version_obj = _PyDict_GetItemWithError(registry, &_Py_ID(version));
if (version_obj == NULL
|| !PyLong_CheckExact(version_obj)
|| PyLong_AsLong(version_obj) != st->filters_version)
@ -404,7 +417,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, &_Py_ID(version), version_obj) < 0) {
Py_DECREF(version_obj);
return -1;
}
@ -463,8 +476,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,14 +487,14 @@ 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 *name;
@ -489,12 +502,12 @@ show_warning(PyObject *filename, int lineno, PyObject *text,
PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno);
name = _PyObject_GetAttrId(category, &PyId___name__);
name = PyObject_GetAttr(category, &_Py_ID(__name__));
if (name == NULL) {
goto error;
}
f_stderr = _PySys_GetObjectId(&PyId_stderr);
f_stderr = _PySys_GetAttr(tstate, &_Py_ID(stderr));
if (f_stderr == NULL) {
fprintf(stderr, "lost sys.stderr\n");
goto error;
@ -553,22 +566,22 @@ error:
}
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 +591,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 +623,7 @@ error:
}
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 +632,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 +688,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 +696,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 +721,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 +744,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 +837,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 +862,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 +879,7 @@ 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__);
*registry = _PyDict_GetItemWithError(globals, &_Py_ID(__warningregistry__));
if (*registry == NULL) {
int rc;
@ -877,7 +890,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, &_Py_ID(__warningregistry__), *registry);
if (rc < 0)
goto handle_error;
}
@ -885,7 +898,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
Py_INCREF(*registry);
/* Setup module. */
*module = _PyDict_GetItemIdWithError(globals, &PyId___name__);
*module = _PyDict_GetItemWithError(globals, &_Py_ID(__name__));
if (*module == Py_None || (*module != NULL && PyUnicode_Check(*module))) {
Py_INCREF(*module);
}
@ -943,10 +956,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, &registry))
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 +995,8 @@ 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 *loader;
PyObject *module_name;
PyObject *get_source;
@ -989,12 +1005,12 @@ 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__);
loader = _PyDict_GetItemWithError(module_globals, &_Py_ID(__loader__));
if (loader == NULL) {
return NULL;
}
Py_INCREF(loader);
module_name = _PyDict_GetItemIdWithError(module_globals, &PyId___name__);
module_name = _PyDict_GetItemWithError(module_globals, &_Py_ID(__name__));
if (!module_name) {
Py_DECREF(loader);
return NULL;
@ -1002,7 +1018,7 @@ 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);
(void)_PyObject_LookupAttr(loader, &_Py_ID(get_source), &get_source);
Py_DECREF(loader);
if (!get_source) {
Py_DECREF(module_name);
@ -1056,6 +1072,11 @@ warnings_warn_explicit(PyObject *self, PyObject *args, PyObject *kwds)
&registry, &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 +1085,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 +1099,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 +1233,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 +1301,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 +1341,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 +1385,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;
}

View File

@ -268,15 +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;
}
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;

View File

@ -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,7 @@ update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs)
}
continue;
}
if (_PyObject_LookupAttrId(base, &PyId___mro_entries__, &meth) < 0) {
if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__), &meth) < 0) {
goto error;
}
if (!meth) {
@ -148,10 +133,10 @@ builtin___build_class__(PyObject *self, PyObject *const *args, Py_ssize_t nargs,
goto error;
}
meta = _PyDict_GetItemIdWithError(mkw, &PyId_metaclass);
meta = _PyDict_GetItemWithError(mkw, &_Py_ID(metaclass));
if (meta != NULL) {
Py_INCREF(meta);
if (_PyDict_DelItemId(mkw, &PyId_metaclass) < 0) {
if (PyDict_DelItem(mkw, &_Py_ID(metaclass)) < 0) {
goto error;
}
/* metaclass is explicitly given, check if it's indeed a class */
@ -191,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_LookupAttrId(meta, &PyId___prepare__, &prep) < 0) {
if (_PyObject_LookupAttr(meta, &_Py_ID(__prepare__), &prep) < 0) {
ns = NULL;
}
else if (prep == NULL) {
@ -946,10 +931,9 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
return NULL;
}
int r = _PyDict_ContainsId(globals, &PyId___builtins__);
int r = PyDict_Contains(globals, &_Py_ID(__builtins__));
if (r == 0) {
r = _PyDict_SetItemId(globals, &PyId___builtins__,
PyEval_GetBuiltins());
r = PyDict_SetItem(globals, &_Py_ID(__builtins__), PyEval_GetBuiltins());
}
if (r < 0) {
return NULL;
@ -1034,10 +1018,9 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
Py_TYPE(locals)->tp_name);
return NULL;
}
int r = _PyDict_ContainsId(globals, &PyId___builtins__);
int r = PyDict_Contains(globals, &_Py_ID(__builtins__));
if (r == 0) {
r = _PyDict_SetItemId(globals, &PyId___builtins__,
PyEval_GetBuiltins());
r = PyDict_SetItem(globals, &_Py_ID(__builtins__), PyEval_GetBuiltins());
}
if (r < 0) {
return NULL;
@ -1960,7 +1943,8 @@ 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();
file = _PySys_GetAttr(tstate, &_Py_ID(stdout));
if (file == NULL) {
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
return NULL;
@ -2020,7 +2004,7 @@ builtin_print_impl(PyObject *module, PyObject *args, PyObject *sep,
}
if (flush) {
PyObject *tmp = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
PyObject *tmp = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (tmp == NULL) {
return NULL;
}
@ -2050,9 +2034,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_ID(stdin));
PyObject *fout = _PySys_GetAttr(
tstate, &_Py_ID(stdout));
PyObject *ferr = _PySys_GetAttr(
tstate, &_Py_ID(stderr));
PyObject *tmp;
long fd;
int tty;
@ -2079,7 +2067,7 @@ builtin_input_impl(PyObject *module, PyObject *prompt)
}
/* First of all, flush stderr */
tmp = _PyObject_CallMethodIdNoArgs(ferr, &PyId_flush);
tmp = PyObject_CallMethodNoArgs(ferr, &_Py_ID(flush));
if (tmp == NULL)
PyErr_Clear();
else
@ -2088,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_CallMethodIdNoArgs(fin, &PyId_fileno);
tmp = PyObject_CallMethodNoArgs(fin, &_Py_ID(fileno));
if (tmp == NULL) {
PyErr_Clear();
tty = 0;
@ -2101,7 +2089,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, &_Py_ID(fileno));
if (tmp == NULL) {
PyErr_Clear();
tty = 0;
@ -2127,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_GetAttrId(fin, &PyId_encoding);
stdin_errors = _PyObject_GetAttrId(fin, &PyId_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)) {
@ -2139,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_CallMethodIdNoArgs(fout, &PyId_flush);
tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(flush));
if (tmp == NULL)
PyErr_Clear();
else
@ -2148,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_GetAttrId(fout, &PyId_encoding);
stdout_errors = _PyObject_GetAttrId(fout, &PyId_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)) {
@ -2234,7 +2222,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, &_Py_ID(flush));
if (tmp == NULL)
PyErr_Clear();
else
@ -2285,7 +2273,7 @@ builtin_round_impl(PyObject *module, PyObject *number, PyObject *ndigits)
return NULL;
}
round = _PyObject_LookupSpecial(number, &PyId___round__);
round = _PyObject_LookupSpecial(number, &_Py_ID(__round__));
if (round == NULL) {
if (!PyErr_Occurred())
PyErr_Format(PyExc_TypeError,
@ -2346,7 +2334,7 @@ builtin_sorted(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject
if (newlist == NULL)
return NULL;
callable = _PyObject_GetAttrId(newlist, &PyId_sort);
callable = PyObject_GetAttr(newlist, &_Py_ID(sort));
if (callable == NULL) {
Py_DECREF(newlist);
return NULL;
@ -2378,7 +2366,7 @@ builtin_vars(PyObject *self, PyObject *args)
Py_XINCREF(d);
}
else {
if (_PyObject_LookupAttrId(v, &PyId___dict__, &d) == 0) {
if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &d) == 0) {
PyErr_SetString(PyExc_TypeError,
"vars() argument must have __dict__ attribute");
}

View File

@ -48,8 +48,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,
@ -864,18 +862,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).
_Py_IDENTIFIER(get);
get_name = _PyUnicode_FromId(&PyId_get); // borrowed
if (get_name == NULL) {
return NULL;
}
int meth_found = _PyObject_GetMethod(map, get_name, &get);
int meth_found = _PyObject_GetMethod(map, &_Py_ID(get), &get);
if (get == NULL) {
goto fail;
}
@ -1692,9 +1684,8 @@ resume_frame:
SET_LOCALS_FROM_FRAME();
#ifdef LLTRACE
_Py_IDENTIFIER(__ltrace__);
{
int r = _PyDict_ContainsId(GLOBALS(), &PyId___ltrace__);
int r = PyDict_Contains(GLOBALS(), &_Py_ID(__ltrace__));
if (r < 0) {
goto exit_unwind;
}
@ -2330,9 +2321,8 @@ handle_eval_breaker:
}
TARGET(PRINT_EXPR) {
_Py_IDENTIFIER(displayhook);
PyObject *value = POP();
PyObject *hook = _PySys_GetObjectId(&PyId_displayhook);
PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(displayhook));
PyObject *res;
if (hook == NULL) {
_PyErr_SetString(tstate, PyExc_RuntimeError,
@ -2537,12 +2527,11 @@ handle_eval_breaker:
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);
retval = PyObject_CallMethodOneArg(receiver, &_Py_ID(send), v);
}
if (retval == NULL) {
if (tstate->c_tracefunc != NULL
@ -2675,11 +2664,10 @@ handle_eval_breaker:
}
TARGET(LOAD_BUILD_CLASS) {
_Py_IDENTIFIER(__build_class__);
PyObject *bc;
if (PyDict_CheckExact(BUILTINS())) {
bc = _PyDict_GetItemIdWithError(BUILTINS(), &PyId___build_class__);
bc = _PyDict_GetItemWithError(BUILTINS(),
&_Py_ID(__build_class__));
if (bc == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_SetString(tstate, PyExc_NameError,
@ -2690,10 +2678,7 @@ handle_eval_breaker:
Py_INCREF(bc);
}
else {
PyObject *build_class_str = _PyUnicode_FromId(&PyId___build_class__);
if (build_class_str == NULL)
goto error;
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,
@ -3252,7 +3237,6 @@ handle_eval_breaker:
}
TARGET(SETUP_ANNOTATIONS) {
_Py_IDENTIFIER(__annotations__);
int err;
PyObject *ann_dict;
if (LOCALS() == NULL) {
@ -3262,8 +3246,8 @@ handle_eval_breaker:
}
/* check if __annotations__ in locals()... */
if (PyDict_CheckExact(LOCALS())) {
ann_dict = _PyDict_GetItemIdWithError(LOCALS(),
&PyId___annotations__);
ann_dict = _PyDict_GetItemWithError(LOCALS(),
&_Py_ID(__annotations__));
if (ann_dict == NULL) {
if (_PyErr_Occurred(tstate)) {
goto error;
@ -3273,8 +3257,8 @@ handle_eval_breaker:
if (ann_dict == NULL) {
goto error;
}
err = _PyDict_SetItemId(LOCALS(),
&PyId___annotations__, ann_dict);
err = PyDict_SetItem(LOCALS(), &_Py_ID(__annotations__),
ann_dict);
Py_DECREF(ann_dict);
if (err != 0) {
goto error;
@ -3283,11 +3267,7 @@ handle_eval_breaker:
}
else {
/* do the same if locals() is not a dict */
PyObject *ann_str = _PyUnicode_FromId(&PyId___annotations__);
if (ann_str == NULL) {
goto error;
}
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;
@ -3297,7 +3277,8 @@ handle_eval_breaker:
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;
@ -4203,11 +4184,9 @@ handle_eval_breaker:
}
TARGET(BEFORE_ASYNC_WITH) {
_Py_IDENTIFIER(__aenter__);
_Py_IDENTIFIER(__aexit__);
PyObject *mgr = TOP();
PyObject *res;
PyObject *enter = _PyObject_LookupSpecial(mgr, &PyId___aenter__);
PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__aenter__));
if (enter == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_Format(tstate, PyExc_TypeError,
@ -4217,7 +4196,7 @@ handle_eval_breaker:
}
goto error;
}
PyObject *exit = _PyObject_LookupSpecial(mgr, &PyId___aexit__);
PyObject *exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__aexit__));
if (exit == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_Format(tstate, PyExc_TypeError,
@ -4241,11 +4220,9 @@ handle_eval_breaker:
}
TARGET(BEFORE_WITH) {
_Py_IDENTIFIER(__enter__);
_Py_IDENTIFIER(__exit__);
PyObject *mgr = TOP();
PyObject *res;
PyObject *enter = _PyObject_LookupSpecial(mgr, &PyId___enter__);
PyObject *enter = _PyObject_LookupSpecial(mgr, &_Py_ID(__enter__));
if (enter == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_Format(tstate, PyExc_TypeError,
@ -4255,7 +4232,7 @@ handle_eval_breaker:
}
goto error;
}
PyObject *exit = _PyObject_LookupSpecial(mgr, &PyId___exit__);
PyObject *exit = _PyObject_LookupSpecial(mgr, &_Py_ID(__exit__));
if (exit == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_Format(tstate, PyExc_TypeError,
@ -6793,19 +6770,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)
{
@ -7047,11 +7030,10 @@ 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__);
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");
@ -7098,7 +7080,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_GetAttrId(v, &PyId___name__);
pkgname = PyObject_GetAttr(v, &_Py_ID(__name__));
if (pkgname == NULL) {
goto error;
}
@ -7140,8 +7122,7 @@ 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 *spec = PyObject_GetAttr(v, &_Py_ID(__spec__));
const char *fmt =
_PyModuleSpec_IsInitializing(spec) ?
"cannot import name %R from partially initialized module %R "
@ -7163,17 +7144,15 @@ 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) {
if (_PyObject_LookupAttr(v, &_Py_ID(__all__), &all) < 0) {
return -1; /* Unexpected error */
}
if (all == NULL) {
if (_PyObject_LookupAttrId(v, &PyId___dict__, &dict) < 0) {
if (_PyObject_LookupAttr(v, &_Py_ID(__dict__), &dict) < 0) {
return -1;
}
if (dict == NULL) {
@ -7200,7 +7179,7 @@ import_all_from(PyThreadState *tstate, PyObject *locals, PyObject *v)
break;
}
if (!PyUnicode_Check(name)) {
PyObject *modname = _PyObject_GetAttrId(v, &PyId___name__);
PyObject *modname = PyObject_GetAttr(v, &_Py_ID(__name__));
if (modname == NULL) {
Py_DECREF(name);
err = -1;
@ -7400,14 +7379,13 @@ 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);
(void)PyObject_SetAttr(value, &_Py_ID(name), obj);
}
PyErr_Restore(type, value, traceback);
}

View File

@ -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,7 @@ PyObject * _PyCodec_LookupTextEncoding(const char *encoding,
* attribute.
*/
if (!PyTuple_CheckExact(codec)) {
if (_PyObject_LookupAttrId(codec, &PyId__is_text_encoding, &attr) < 0) {
if (_PyObject_LookupAttr(codec, &_Py_ID(_is_text_encoding), &attr) < 0) {
Py_DECREF(codec);
return NULL;
}

View File

@ -632,11 +632,9 @@ compiler_unit_free(struct compiler_unit *u)
static int
compiler_set_qualname(struct compiler *c)
{
_Py_static_string(dot, ".");
_Py_static_string(dot_locals, ".<locals>");
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);
@ -667,11 +665,10 @@ 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;
base = PyUnicode_Concat(parent->u_qualname, dot_locals_str);
|| parent->u_scope_type == COMPILER_SCOPE_LAMBDA)
{
base = PyUnicode_Concat(parent->u_qualname,
&_Py_STR(dot_locals));
if (base == NULL)
return 0;
}
@ -683,12 +680,7 @@ compiler_set_qualname(struct compiler *c)
}
if (base != NULL) {
dot_str = _PyUnicode_FromId(&dot);
if (dot_str == NULL) {
Py_DECREF(base);
return 0;
}
name = PyUnicode_Concat(base, dot_str);
name = PyUnicode_Concat(base, &_Py_STR(dot));
Py_DECREF(base);
if (name == NULL)
return 0;
@ -1603,17 +1595,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;
}
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;
@ -1998,11 +1984,6 @@ 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;
}
/* Set current line number to the line number of first statement.
This way line number for SETUP_ANNOTATIONS will always
@ -2027,7 +2008,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;
}
}
@ -2041,12 +2022,8 @@ compiler_mod(struct compiler *c, mod_ty mod)
{
PyCodeObject *co;
int addNone = 1;
_Py_static_string(PyId__module, "<module>");
PyObject *module = _PyUnicode_FromId(&PyId__module); /* borrowed ref */
if (module == NULL) {
return 0;
}
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;
@ -2324,7 +2301,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))
@ -2342,11 +2318,8 @@ 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;
}
if (!compiler_visit_argannotation(c, return_str, returns, &annotations_len)) {
if (!compiler_visit_argannotation(c, &_Py_ID(return), returns,
&annotations_len)) {
return 0;
}
@ -2891,7 +2864,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);
@ -2899,18 +2871,12 @@ compiler_lambda(struct compiler *c, expr_ty e)
if (!compiler_check_debug_args(c, args))
return 0;
_Py_static_string(PyId_lambda, "<lambda>");
name = _PyUnicode_FromId(&PyId_lambda); /* borrowed ref */
if (name == NULL) {
return 0;
}
funcflags = compiler_default_arguments(c, args);
if (funcflags == -1) {
return 0;
}
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;
}
@ -3809,12 +3775,6 @@ 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;
}
ADDOP_LOAD_CONST_NEW(c, PyLong_FromLong(s->v.ImportFrom.level));
@ -3841,7 +3801,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);
@ -5389,13 +5349,8 @@ error:
static int
compiler_genexp(struct compiler *c, expr_ty e)
{
_Py_static_string(PyId_genexpr, "<genexpr>");
identifier name = _PyUnicode_FromId(&PyId_genexpr); /* borrowed ref */
if (name == NULL) {
return 0;
}
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);
}
@ -5403,13 +5358,8 @@ compiler_genexp(struct compiler *c, expr_ty e)
static int
compiler_listcomp(struct compiler *c, expr_ty e)
{
_Py_static_string(PyId_listcomp, "<listcomp>");
identifier name = _PyUnicode_FromId(&PyId_listcomp); /* borrowed ref */
if (name == NULL) {
return 0;
}
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);
}
@ -5417,13 +5367,8 @@ compiler_listcomp(struct compiler *c, expr_ty e)
static int
compiler_setcomp(struct compiler *c, expr_ty e)
{
_Py_static_string(PyId_setcomp, "<setcomp>");
identifier name = _PyUnicode_FromId(&PyId_setcomp); /* borrowed ref */
if (name == NULL) {
return 0;
}
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);
}
@ -5432,13 +5377,8 @@ compiler_setcomp(struct compiler *c, expr_ty e)
static int
compiler_dictcomp(struct compiler *c, expr_ty e)
{
_Py_static_string(PyId_dictcomp, "<dictcomp>");
identifier name = _PyUnicode_FromId(&PyId_dictcomp); /* borrowed ref */
if (name == NULL) {
return 0;
}
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);
}
@ -5960,12 +5900,6 @@ 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;
}
assert(s->kind == AnnAssign_kind);
@ -5988,7 +5922,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);

View File

@ -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,7 @@ PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
goto failure;
}
int r = _PyDict_ContainsId(dict, &PyId___module__);
int r = PyDict_Contains(dict, &_Py_ID(__module__));
if (r < 0) {
goto failure;
}
@ -1144,7 +1138,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, &_Py_ID(__module__), modulename) != 0)
goto failure;
}
if (PyTuple_Check(base)) {
@ -1347,7 +1341,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type,
assert(PyExceptionClass_Check(exc_type));
PyObject *modulename = _PyObject_GetAttrId(exc_type, &PyId___module__);
PyObject *modulename = PyObject_GetAttr(exc_type, &_Py_ID(__module__));
if (modulename == NULL || !PyUnicode_Check(modulename)) {
Py_XDECREF(modulename);
_PyErr_Clear(tstate);
@ -1356,8 +1350,8 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type,
}
}
else {
if (!_PyUnicode_EqualToASCIIId(modulename, &PyId_builtins) &&
!_PyUnicode_EqualToASCIIId(modulename, &PyId___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;
@ -1405,7 +1399,7 @@ write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type,
}
/* Explicitly call file.flush() */
PyObject *res = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
PyObject *res = _PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (!res) {
return -1;
}
@ -1420,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_GetObjectId(&PyId_stderr);
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;
}
_Py_IDENTIFIER(unraisablehook);
PyObject *hook = _PySys_GetObjectId(&PyId_unraisablehook);
PyObject *hook = _PySys_GetAttr(tstate, &_Py_ID(unraisablehook));
if (hook == NULL) {
Py_DECREF(hook_args);
goto default_hook;
@ -1600,14 +1593,6 @@ 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);
PyThreadState *tstate = _PyThreadState_GET();
/* add attributes for the line number and filename for the error */
@ -1619,7 +1604,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
if (tmp == NULL)
_PyErr_Clear(tstate);
else {
if (_PyObject_SetAttrId(v, &PyId_lineno, tmp)) {
if (PyObject_SetAttr(v, &_Py_ID(lineno), tmp)) {
_PyErr_Clear(tstate);
}
Py_DECREF(tmp);
@ -1631,7 +1616,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
_PyErr_Clear(tstate);
}
}
if (_PyObject_SetAttrId(v, &PyId_offset, tmp ? tmp : Py_None)) {
if (PyObject_SetAttr(v, &_Py_ID(offset), tmp ? tmp : Py_None)) {
_PyErr_Clear(tstate);
}
Py_XDECREF(tmp);
@ -1643,7 +1628,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
_PyErr_Clear(tstate);
}
}
if (_PyObject_SetAttrId(v, &PyId_end_lineno, tmp ? tmp : Py_None)) {
if (PyObject_SetAttr(v, &_Py_ID(end_lineno), tmp ? tmp : Py_None)) {
_PyErr_Clear(tstate);
}
Py_XDECREF(tmp);
@ -1655,20 +1640,20 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
_PyErr_Clear(tstate);
}
}
if (_PyObject_SetAttrId(v, &PyId_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_SetAttrId(v, &PyId_filename, filename)) {
if (PyObject_SetAttr(v, &_Py_ID(filename), filename)) {
_PyErr_Clear(tstate);
}
tmp = PyErr_ProgramTextObject(filename, lineno);
if (tmp) {
if (_PyObject_SetAttrId(v, &PyId_text, tmp)) {
if (PyObject_SetAttr(v, &_Py_ID(text), tmp)) {
_PyErr_Clear(tstate);
}
Py_DECREF(tmp);
@ -1678,7 +1663,7 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
}
}
if (exc != PyExc_SyntaxError) {
if (_PyObject_LookupAttrId(v, &PyId_msg, &tmp) < 0) {
if (_PyObject_LookupAttr(v, &_Py_ID(msg), &tmp) < 0) {
_PyErr_Clear(tstate);
}
else if (tmp) {
@ -1687,7 +1672,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, &_Py_ID(msg), tmp)) {
_PyErr_Clear(tstate);
}
Py_DECREF(tmp);
@ -1696,15 +1681,15 @@ PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
_PyErr_Clear(tstate);
}
}
if (_PyObject_LookupAttrId(v, &PyId_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_SetAttrId(v, &PyId_print_file_and_line,
Py_None)) {
if (PyObject_SetAttr(v, &_Py_ID(print_file_and_line), Py_None)) {
_PyErr_Clear(tstate);
}
}

View File

@ -36,9 +36,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]*/
@ -74,9 +71,7 @@ _PyImportZip_Init(PyThreadState *tstate)
}
}
else {
_Py_IDENTIFIER(zipimporter);
PyObject *zipimporter = _PyObject_GetAttrId(zipimport,
&PyId_zipimporter);
PyObject *zipimporter = PyObject_GetAttr(zipimport, &_Py_ID(zipimporter));
Py_DECREF(zipimport);
if (zipimporter == NULL) {
_PyErr_Clear(tstate); /* No zipimporter object -- okay */
@ -345,20 +340,18 @@ import_ensure_initialized(PyInterpreterState *interp, PyObject *mod, PyObject *n
{
PyObject *spec;
_Py_IDENTIFIER(_lock_unlock_module);
/* 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__);
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_CallMethodIdOneArg(
interp->importlib, &PyId__lock_unlock_module, name);
PyObject *value = _PyObject_CallMethodOneArg(
interp->importlib, &_Py_ID(_lock_unlock_module), name);
if (value == NULL) {
return -1;
}
@ -710,7 +703,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");
@ -719,8 +711,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);
pathobj = _PyObject_CallMethodOneArg(
external, &_Py_ID(_get_sourcefile), cpathobj);
Py_DECREF(external);
}
if (pathobj == NULL)
@ -740,7 +732,6 @@ error:
static PyObject *
module_dict_for_exec(PyThreadState *tstate, PyObject *name)
{
_Py_IDENTIFIER(__builtins__);
PyObject *m, *d;
m = import_add_module(tstate, name);
@ -749,10 +740,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_ContainsId(d, &PyId___builtins__);
int r = PyDict_Contains(d, &_Py_ID(__builtins__));
if (r == 0) {
r = _PyDict_SetItemId(d, &PyId___builtins__,
PyEval_GetBuiltins());
r = PyDict_SetItem(d, &_Py_ID(__builtins__), PyEval_GetBuiltins());
}
if (r < 0) {
remove_module(tstate, name);
@ -794,7 +784,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) {
@ -810,9 +799,8 @@ 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);
res = PyObject_CallMethodObjArgs(external, &_Py_ID(_fix_up_module),
d, name, pathname, cpathname, NULL);
Py_DECREF(external);
if (res != NULL) {
Py_DECREF(res);
@ -1542,9 +1530,6 @@ done:
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 *package = NULL;
PyObject *spec;
@ -1560,14 +1545,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_GetItemIdWithError(globals, &PyId___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_GetItemIdWithError(globals, &PyId___spec__);
spec = PyDict_GetItemWithError(globals, &_Py_ID(__spec__));
if (spec == NULL && _PyErr_Occurred(tstate)) {
goto error;
}
@ -1581,7 +1566,7 @@ 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);
PyObject *parent = PyObject_GetAttr(spec, &_Py_ID(parent));
if (parent == NULL) {
goto error;
}
@ -1600,7 +1585,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level
}
}
else if (spec != NULL && spec != Py_None) {
package = _PyObject_GetAttrId(spec, &PyId_parent);
package = PyObject_GetAttr(spec, &_Py_ID(parent));
if (package == NULL) {
goto error;
}
@ -1617,7 +1602,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level
goto error;
}
package = _PyDict_GetItemIdWithError(globals, &PyId___name__);
package = PyDict_GetItemWithError(globals, &_Py_ID(__name__));
if (package == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_SetString(tstate, PyExc_KeyError,
@ -1633,7 +1618,7 @@ resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level
goto error;
}
int haspath = _PyDict_ContainsId(globals, &PyId___path__);
int haspath = PyDict_Contains(globals, &_Py_ID(__path__));
if (haspath < 0) {
goto error;
}
@ -1701,7 +1686,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;
@ -1742,9 +1726,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));
mod = _PyObject_CallMethodIdObjArgs(interp->importlib,
&PyId__find_and_load, 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),
@ -1788,7 +1771,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;
@ -1909,13 +1891,13 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals,
}
else {
PyObject *path;
if (_PyObject_LookupAttrId(mod, &PyId___path__, &path) < 0) {
if (_PyObject_LookupAttr(mod, &_Py_ID(__path__), &path) < 0) {
goto error;
}
if (path) {
Py_DECREF(path);
final_mod = _PyObject_CallMethodIdObjArgs(
interp->importlib, &PyId__handle_fromlist,
final_mod = PyObject_CallMethodObjArgs(
interp->importlib, &_Py_ID(_handle_fromlist),
mod, fromlist, interp->import_func, NULL);
}
else {
@ -1955,10 +1937,8 @@ 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 *importlib = PyImport_GetModule(&_Py_ID(importlib));
if (importlib == NULL) {
if (PyErr_Occurred()) {
return NULL;
@ -1970,7 +1950,7 @@ PyImport_ReloadModule(PyObject *m)
}
}
reloaded_module = _PyObject_CallMethodIdOneArg(importlib, &PyId_reload, m);
reloaded_module = PyObject_CallMethodOneArg(importlib, &_Py_ID(reload), m);
Py_DECREF(importlib);
return reloaded_module;
}
@ -1988,26 +1968,12 @@ 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 *from_list = PyList_New(0);
if (from_list == NULL) {
goto err;
@ -2017,7 +1983,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;
}
@ -2028,20 +1994,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;

View File

@ -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,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) {
}
/* Replace '-' by '_' */
modname = _PyObject_CallMethodId(encoded, &PyId_replace, "cc", '-', '_');
modname = _PyObject_CallMethod(encoded, &_Py_ID(replace), "cc", '-', '_');
if (modname == NULL)
goto error;

Some files were not shown because too many files have changed in this diff Show More