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
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)'
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,
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
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 *);
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 *);
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 *);
# 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 *);
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
# 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
PyBytesObject ob;
char eos;
} bytes_characters[256];
+
+ struct _Py_global_strings strings;
} singletons;
};
--- /dev/null
+#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 */
# 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) \
#define _PyHeapType_GET_MEMBERS(etype) \
((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
+PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *);
+
#ifdef __cplusplus
}
#endif
.ob_digit = { ((val) >= 0 ? (val) : -(val)) }, \
}
-
#define _PyBytes_SIMPLE_INIT(CH, LEN) \
{ \
_PyVarObject_IMMORTAL_INIT(&PyBytes_Type, LEN), \
_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 { \
_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 */
#endif
-/* runtime lifecycle */
-
-extern PyStatus _PyStructSequence_InitState(PyInterpreterState *);
-
-
/* other API */
PyAPI_FUNC(PyTypeObject *) _PyStructSequence_NewType(
PyAPI_FUNC() to not export the symbol. */
extern void _PySys_ClearAuditHooks(PyThreadState *tstate);
+PyAPI_FUNC(int) _PySys_SetAttr(PyObject *, PyObject *);
+
#ifdef __cplusplus
}
#endif
};
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];
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'
#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]
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;
_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;
}
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;
}
}
/* Stage 2: inherited abstract methods. */
- bases = _PyObject_GetAttrId(self, &PyId___bases__);
+ bases = PyObject_GetAttr(self, &_Py_ID(__bases__));
if (!bases) {
goto error;
}
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) {
}
}
- if (_PyObject_SetAttrId(self, &PyId___abstractmethods__, abstracts) < 0) {
+ if (PyObject_SetAttr(self, &_Py_ID(__abstractmethods__), abstracts) < 0) {
goto error;
}
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;
}
* 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;
}
((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;
}
}
return NULL;
}
- subclass = _PyObject_GetAttrId(instance, &PyId___class__);
+ subclass = PyObject_GetAttr(instance, &_Py_ID(__class__));
if (subclass == NULL) {
Py_DECREF(impl);
return NULL;
}
}
/* 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;
}
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;
}
/* 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;
}
#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()
*/
#define PY_SSIZE_T_CLEAN
+#define NEEDS_PY_IDENTIFIER
#include "Python.h"
/*[clinic input]
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) {
PyObject *items;
PyObject *iter;
PyObject *result;
- _Py_IDENTIFIER(items);
if (dd->default_factory == NULL || dd->default_factory == Py_None)
args = PyTuple_New(0);
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;
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;
/* 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 &&
}
}
else {
- bound_get = _PyObject_GetAttrId(mapping, &PyId_get);
+ bound_get = PyObject_GetAttr(mapping, &_Py_ID(get));
if (bound_get == NULL)
goto done;
#define MODULE_VERSION "1.0"
+#define NEEDS_PY_IDENTIFIER
+
#include "Python.h"
#include "structmember.h" // PyMemberDef
#include <stdbool.h>
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
+#define NEEDS_PY_IDENTIFIER
#define PY_SSIZE_T_CLEAN
#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
*/
+#define NEEDS_PY_IDENTIFIER
+
#include "Python.h"
#include "structmember.h" // PyMemberDef
#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
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
+#define NEEDS_PY_IDENTIFIER
#define PY_SSIZE_T_CLEAN
#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()
#define PY_SSIZE_T_CLEAN
+#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include <sys/types.h>
*/
#define PY_SSIZE_T_CLEAN
+#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef
/* Doc strings: Mitch Chapman */
#define PY_SSIZE_T_CLEAN
+#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "gdbm.h"
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) {
/* 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);
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);
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;
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);
[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.
*/
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;
{
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
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 */
{
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;
}
}
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) {
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;
}
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);
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 */
}
Py_DECREF(ret);
- return _forward_call(self->reader, &PyId_isatty, NULL);
+ return _forward_call(self->reader, &_Py_ID(isatty), NULL);
}
static PyObject *
PyTypeObject PyFileIO_Type;
-_Py_IDENTIFIER(name);
-
#define PyFileIO_Check(op) (PyObject_TypeCheck((op), &PyFileIO_Type))
/* Forward declarations */
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;
_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) {
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) {
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 *
_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,
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;
}
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);
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);
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
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. */
/* 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;
}
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
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. */
[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,
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;
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]
PyObject *res;
int r;
- res = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_readable);
+ res = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(readable));
if (res == NULL)
return -1;
PyObject *res;
int r;
- res = _PyObject_CallMethodIdNoArgs(self->buffer, &PyId_writable);
+ res = PyObject_CallMethodNoArgs(self->buffer, &_Py_ID(writable));
if (res == NULL)
return -1;
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)) {
}
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
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) ||
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) {
}
}
- res = _PyObject_CallMethodIdNoArgs(buffer, &PyId_seekable);
+ res = PyObject_CallMethodNoArgs(buffer, &_Py_ID(seekable));
if (res == NULL)
goto error;
r = PyObject_IsTrue(res);
}
}
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);
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;
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);
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;
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;
}
* 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;
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);
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;
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)
}
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)
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;
} 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); \
}
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);
}
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;
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);
}
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;
}
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) {
/*[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]
/*[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]
/*[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]
/*[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]
/*[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]
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]
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);
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 *
PyTypeObject PyWindowsConsoleIO_Type;
-_Py_IDENTIFIER(name);
-
int
_PyWindowsConsoleIO_closed(PyObject *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;
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;
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
+#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef
*/
#define PY_SSIZE_T_CLEAN
+#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef
#include "Python.h"
#include "pycore_moduleobject.h" // _PyModule_GetState()
+#include "pycore_runtime.h" // _Py_ID()
#include "clinic/_operator.c.h"
typedef struct {
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;
#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()
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 {
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;
/* 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;
/* *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);
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) {
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,
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);
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) {
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;
}
/* 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;
}
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);
}
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);
PyObject *cls;
PickleState *st = _Pickle_GetGlobalState();
int status = 0;
- _Py_IDENTIFIER(__name__);
- _Py_IDENTIFIER(__qualname__);
const char global_op = GLOBAL;
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;
}
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);
}
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);
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;
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
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) {
}
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) {
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. */
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);
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;
}
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
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);
}
}
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) {
}
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++) {
}
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++) {
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).
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;
}
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;
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);
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;
* 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"
* 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"
* 3. This notice may not be removed or altered from any source distribution.
*/
+#define NEEDS_PY_IDENTIFIER
+
#include <Python.h>
#include "cursor.h"
* 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"
#define OPENSSL_NO_DEPRECATED 1
#define PY_SSIZE_T_CLEAN
+#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#undef Py_BUILD_CORE_MODULE
#undef Py_BUILD_CORE_BUILTIN
+#define NEEDS_PY_IDENTIFIER
/* Always enable assertions */
#undef NDEBUG
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)
// 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;
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;
}
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);
}
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;
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;
}
}
_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;
}
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 */
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
+#define NEEDS_PY_IDENTIFIER
#define PY_SSIZE_T_CLEAN
#include "Python.h"
*/
#define PY_SSIZE_T_CLEAN
+#define NEEDS_PY_IDENTIFIER
#include "Python.h"
#include "structmember.h" // PyMemberDef
#include "multibytecodec.h"
#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
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;
return fd;
}
- result = _PyObject_CallMethodIdNoArgs(file, &PyId_fileno);
+ result = PyObject_CallMethodNoArgs(file, &_Py_ID(fileno));
if (result == NULL)
return -1;
return -1;
}
- result = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
+ result = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (result != NULL)
Py_DECREF(result);
else {
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;
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);
}
{
Py_ssize_t i;
PyObject *it, *copyable, *copyfunc, *result;
- _Py_IDENTIFIER(__copy__);
if (n < 0) {
PyErr_SetString(PyExc_ValueError, "n must be >= 0");
return NULL;
}
- if (_PyObject_LookupAttrId(it, &PyId___copy__, ©func) < 0) {
+ if (_PyObject_LookupAttr(it, &_Py_ID(__copy__), ©func) < 0) {
Py_DECREF(it);
Py_DECREF(result);
return NULL;
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);
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;
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 */
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()) {
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;
}
#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()
_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);
}
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);
return NULL;
}
- trunc = _PyObject_LookupSpecial(x, &PyId___trunc__);
+ trunc = _PyObject_LookupSpecialId(x, &PyId___trunc__);
if (trunc == NULL) {
if (!PyErr_Occurred())
PyErr_Format(PyExc_TypeError,
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
+#define NEEDS_PY_IDENTIFIER
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
+#define NEEDS_PY_IDENTIFIER
#define PY_SSIZE_T_CLEAN
#include "Python.h"
# 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
# endif /* _MSC_VER */
#endif /* ! __WATCOMC__ || __QNX__ */
-_Py_IDENTIFIER(__fspath__);
-
/*[clinic input]
# one of the few times we lie about this name!
module os
/* 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;
}
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, "
+#define NEEDS_PY_IDENTIFIER
+
#include "Python.h"
#include <ctype.h>
#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>
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;
#ifndef Py_BUILD_CORE_BUILTIN
# define Py_BUILD_CORE_MODULE 1
#endif
+#define NEEDS_PY_IDENTIFIER
#define PY_SSIZE_T_CLEAN
{
PyObject *hint, *result;
Py_ssize_t res;
- _Py_IDENTIFIER(__length_hint__);
if (_PyObject_HasLen(o)) {
res = PyObject_Length(o);
if (res < 0) {
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;
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) {
PyObject *meth;
PyObject *empty = NULL;
PyObject *result = NULL;
- _Py_IDENTIFIER(__format__);
if (format_spec != NULL && !PyUnicode_Check(format_spec)) {
PyErr_Format(PyExc_SystemError,
}
/* 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)) {
PyNumberMethods *m;
PyObject *trunc_func;
Py_buffer view;
- _Py_IDENTIFIER(__trunc__);
if (o == NULL) {
return null_error();
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)) {
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;
}
_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);
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() */
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;
{
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(
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);
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;
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);
static int
object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls)
{
- _Py_IDENTIFIER(__subclasscheck__);
PyObject *checker;
/* We know what type's __subclasscheck__ does. */
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__")) {
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) {
*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;
_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) {
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)));
}
}
#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.
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);
/* 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)
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)));
}
}
return _PyObject_CallFunctionVa(tstate, callable, format, va, is_size_t);
}
-
PyObject *
PyObject_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, ...)
}
+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, ...)
#define TP_DESCR_GET(t) ((t)->tp_descr_get)
-_Py_IDENTIFIER(__name__);
-_Py_IDENTIFIER(__qualname__);
PyObject *
PyMethod_Function(PyObject *im)
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[] = {
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;
}
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)) {
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);
#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"
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,
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;
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));
}
{
return NULL;
}
- _Py_IDENTIFIER(get);
- return _PyObject_VectorcallMethodId(&PyId_get, newargs,
+ return _PyObject_VectorcallMethod(&_Py_ID(get), newargs,
3 | PY_VECTORCALL_ARGUMENTS_OFFSET,
NULL);
}
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
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));
}
/* 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;
}
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;
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)
{
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);
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) {
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);
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 = {
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;
/* 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,
}
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;
}
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;
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,
{
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;
}
extern "C" {
#endif
-_Py_IDENTIFIER(open);
-
/* External C interface */
PyObject *
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;
PyObject *
PyFile_GetLine(PyObject *f, int n)
{
- _Py_IDENTIFIER(readline);
PyObject *result;
if (f == NULL) {
}
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)) {
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) {
{
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) {
} 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);
}
}
0, /* tp_dict */
};
-_Py_IDENTIFIER(__builtins__);
-
static void
init_frame(InterpreterFrame *frame, PyFunctionObject *func, PyObject *locals)
{
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);
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;
{
#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) \
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;
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) {
}
}
- 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) {
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;
}
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)) {
gen_close_iter(PyObject *yf)
{
PyObject *retval = NULL;
- _Py_IDENTIFIER(close);
if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) {
retval = gen_close((PyGenObject *)yf, NULL);
}
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) {
PyObject *typ, PyObject *val, PyObject *tb)
{
PyObject *yf = _PyGen_yf(gen);
- _Py_IDENTIFIER(throw);
if (yf) {
InterpreterFrame *frame = (InterpreterFrame *)gen->gi_iframe;
} 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;
}
PyObject *it_seq; /* Set to NULL when iterator is exhausted */
} seqiterobject;
-_Py_IDENTIFIER(iter);
-
PyObject *
PySeqIter_New(PyObject *seq)
{
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.");
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[] = {
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);
}
[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)
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,
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,
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);
}
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;
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}
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);
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;
}
}
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()) {
PyObject*
PyModule_GetFilenameObject(PyObject *m)
{
- _Py_IDENTIFIER(__file__);
PyObject *d;
PyObject *fileobj;
if (!PyModule_Check(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()) {
_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);
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;
}
}
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;
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);
}
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");
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.
} 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);
}
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");
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);
/* 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)
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);
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;
}
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;
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);
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)){
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);
_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) {
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;
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);
}
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;
#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)
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 {
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;
}
}
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);
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);
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[] = {
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) {
}
return 0;
}
- if (_PyObject_LookupAttrId(arg, &PyId_items, &func) < 0) {
+ if (_PyObject_LookupAttr(arg, &_Py_ID(items), &func) < 0) {
return -1;
}
if (func != NULL) {
PyObject *length;
} rangeobject;
-_Py_IDENTIFIER(iter);
-
/* Helper function for validating step. Always returns a new reference or
NULL on error.
*/
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);
}
/* 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 *
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);
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.");
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)
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) {
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,
}
#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))
{
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();
-}
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 *
# define INTERN_NAME_STRINGS
#endif
-/* alphabetical order */
-_Py_IDENTIFIER(__abstractmethods__);
-_Py_IDENTIFIER(__annotations__);
-_Py_IDENTIFIER(__class__);
-_Py_IDENTIFIER(__class_getitem__);
-_Py_IDENTIFIER(__classcell__);
-_Py_IDENTIFIER(__delitem__);
-_Py_IDENTIFIER(__dict__);
-_Py_IDENTIFIER(__doc__);
-_Py_IDENTIFIER(__getattribute__);
-_Py_IDENTIFIER(__getitem__);
-_Py_IDENTIFIER(__hash__);
-_Py_IDENTIFIER(__init_subclass__);
-_Py_IDENTIFIER(__len__);
-_Py_IDENTIFIER(__module__);
-_Py_IDENTIFIER(__name__);
-_Py_IDENTIFIER(__new__);
-_Py_IDENTIFIER(__qualname__);
-_Py_IDENTIFIER(__set_name__);
-_Py_IDENTIFIER(__setitem__);
-_Py_IDENTIFIER(__weakref__);
-_Py_IDENTIFIER(builtins);
-_Py_IDENTIFIER(mro);
-
static PyObject *
slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
clear_slotdefs(void);
static PyObject *
-lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound);
+lookup_maybe_method(PyObject *self, PyObject *attr, int *unbound);
static int
slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value);
if (type->tp_flags & Py_TPFLAGS_DISALLOW_INSTANTIATION) {
CHECK(type->tp_new == NULL);
- CHECK(_PyDict_ContainsId(type->tp_dict, &PyId___new__) == 0);
+ CHECK(PyDict_Contains(type->tp_dict, &_Py_ID(__new__)) == 0);
}
return 1;
if (custom) {
mro_meth = lookup_maybe_method(
- (PyObject *)type, &PyId_mro, &unbound);
+ (PyObject *)type, &_Py_ID(mro), &unbound);
if (mro_meth == NULL)
goto clear;
type_mro_meth = lookup_maybe_method(
- (PyObject *)&PyType_Type, &PyId_mro, &unbound);
+ (PyObject *)&PyType_Type, &_Py_ID(mro), &unbound);
if (type_mro_meth == NULL)
goto clear;
if (mro_meth != type_mro_meth)
PyObject *mod;
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) {
- mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___module__);
+ mod = PyDict_GetItemWithError(type->tp_dict, &_Py_ID(__module__));
if (mod == NULL) {
if (!PyErr_Occurred()) {
PyErr_Format(PyExc_AttributeError, "__module__");
PyUnicode_InternInPlace(&mod);
}
else {
- mod = _PyUnicode_FromId(&PyId_builtins);
- Py_XINCREF(mod);
+ mod = &_Py_ID(builtins);
+ Py_INCREF(mod);
}
}
return mod;
PyType_Modified(type);
- return _PyDict_SetItemId(type->tp_dict, &PyId___module__, value);
+ return PyDict_SetItem(type->tp_dict, &_Py_ID(__module__), value);
}
static PyObject *
/* type itself has an __abstractmethods__ descriptor (this). Don't return
that. */
if (type != &PyType_Type)
- mod = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___abstractmethods__);
+ mod = PyDict_GetItemWithError(type->tp_dict,
+ &_Py_ID(__abstractmethods__));
if (!mod) {
if (!PyErr_Occurred()) {
- PyObject *message = _PyUnicode_FromId(&PyId___abstractmethods__);
- if (message)
- PyErr_SetObject(PyExc_AttributeError, message);
+ PyErr_SetObject(PyExc_AttributeError, &_Py_ID(__abstractmethods__));
}
return NULL;
}
abstract = PyObject_IsTrue(value);
if (abstract < 0)
return -1;
- res = _PyDict_SetItemId(type->tp_dict, &PyId___abstractmethods__, value);
+ res = PyDict_SetItem(type->tp_dict, &_Py_ID(__abstractmethods__), value);
}
else {
abstract = 0;
- res = _PyDict_DelItemId(type->tp_dict, &PyId___abstractmethods__);
+ res = PyDict_DelItem(type->tp_dict, &_Py_ID(__abstractmethods__));
if (res && PyErr_ExceptionMatches(PyExc_KeyError)) {
- PyObject *message = _PyUnicode_FromId(&PyId___abstractmethods__);
- if (message)
- PyErr_SetObject(PyExc_AttributeError, message);
+ PyErr_SetObject(PyExc_AttributeError, &_Py_ID(__abstractmethods__));
return -1;
}
}
if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && type->tp_doc != NULL) {
return _PyType_GetDocFromInternalDoc(type->tp_name, type->tp_doc);
}
- result = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__);
+ result = PyDict_GetItemWithError(type->tp_dict, &_Py_ID(__doc__));
if (result == NULL) {
if (!PyErr_Occurred()) {
result = Py_None;
if (!check_set_special_type_attr(type, value, "__doc__"))
return -1;
PyType_Modified(type);
- return _PyDict_SetItemId(type->tp_dict, &PyId___doc__, value);
+ return PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), value);
}
static PyObject *
PyObject *annotations;
/* there's no _PyDict_GetItemId without WithError, so let's LBYL. */
- if (_PyDict_ContainsId(type->tp_dict, &PyId___annotations__)) {
- annotations = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___annotations__);
+ if (PyDict_Contains(type->tp_dict, &_Py_ID(__annotations__))) {
+ annotations = PyDict_GetItemWithError(
+ type->tp_dict, &_Py_ID(__annotations__));
/*
- ** _PyDict_GetItemIdWithError could still fail,
+ ** PyDict_GetItemWithError could still fail,
** for instance with a well-timed Ctrl-C or a MemoryError.
** so let's be totally safe.
*/
if (annotations) {
if (Py_TYPE(annotations)->tp_descr_get) {
- annotations = Py_TYPE(annotations)->tp_descr_get(annotations, NULL,
- (PyObject *)type);
+ annotations = Py_TYPE(annotations)->tp_descr_get(
+ annotations, NULL, (PyObject *)type);
} else {
Py_INCREF(annotations);
}
} else {
annotations = PyDict_New();
if (annotations) {
- int result = _PyDict_SetItemId(type->tp_dict, &PyId___annotations__, annotations);
+ int result = PyDict_SetItem(
+ type->tp_dict, &_Py_ID(__annotations__), annotations);
if (result) {
Py_CLEAR(annotations);
} else {
int result;
if (value != NULL) {
/* set */
- result = _PyDict_SetItemId(type->tp_dict, &PyId___annotations__, value);
+ result = PyDict_SetItem(type->tp_dict, &_Py_ID(__annotations__), value);
} else {
/* delete */
- if (!_PyDict_ContainsId(type->tp_dict, &PyId___annotations__)) {
+ if (!PyDict_Contains(type->tp_dict, &_Py_ID(__annotations__))) {
PyErr_Format(PyExc_AttributeError, "__annotations__");
return -1;
}
- result = _PyDict_DelItemId(type->tp_dict, &PyId___annotations__);
+ result = PyDict_DelItem(type->tp_dict, &_Py_ID(__annotations__));
}
if (result == 0) {
return NULL;
}
- if (mod != NULL && !_PyUnicode_EqualToASCIIId(mod, &PyId_builtins))
+ if (mod != NULL && !_PyUnicode_Equal(mod, &_Py_ID(builtins)))
rtn = PyUnicode_FromFormat("<class '%U.%U'>", mod, name);
else
rtn = PyUnicode_FromFormat("<class '%s'>", type->tp_name);
*/
PyObject *
-_PyObject_LookupSpecial(PyObject *self, _Py_Identifier *attrid)
+_PyObject_LookupSpecial(PyObject *self, PyObject *attr)
{
PyObject *res;
- res = _PyType_LookupId(Py_TYPE(self), attrid);
+ res = _PyType_Lookup(Py_TYPE(self), attr);
if (res != NULL) {
descrgetfunc f;
if ((f = Py_TYPE(res)->tp_descr_get) == NULL)
return res;
}
+PyObject *
+_PyObject_LookupSpecialId(PyObject *self, _Py_Identifier *attrid)
+{
+ PyObject *attr = _PyUnicode_FromId(attrid); /* borrowed */
+ if (attr == NULL)
+ return NULL;
+ return _PyObject_LookupSpecial(self, attr);
+}
+
static PyObject *
-lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound)
+lookup_maybe_method(PyObject *self, PyObject *attr, int *unbound)
{
- PyObject *res = _PyType_LookupId(Py_TYPE(self), attrid);
+ PyObject *res = _PyType_Lookup(Py_TYPE(self), attr);
if (res == NULL) {
return NULL;
}
}
static PyObject *
-lookup_method(PyObject *self, _Py_Identifier *attrid, int *unbound)
+lookup_method(PyObject *self, PyObject *attr, int *unbound)
{
- PyObject *res = lookup_maybe_method(self, attrid, unbound);
+ PyObject *res = lookup_maybe_method(self, attr, unbound);
if (res == NULL && !PyErr_Occurred()) {
- PyErr_SetObject(PyExc_AttributeError, _PyUnicode_FromId(attrid));
+ PyErr_SetObject(PyExc_AttributeError, attr);
}
return res;
}
args is an argument vector of length nargs. The first element in this
vector is the special object "self" which is used for the method lookup */
static PyObject *
-vectorcall_method(_Py_Identifier *name,
- PyObject *const *args, Py_ssize_t nargs)
+vectorcall_method(PyObject *name, PyObject *const *args, Py_ssize_t nargs)
{
assert(nargs >= 1);
/* Clone of vectorcall_method() that returns NotImplemented
* when the lookup fails. */
static PyObject *
-vectorcall_maybe(PyThreadState *tstate, _Py_Identifier *name,
+vectorcall_maybe(PyThreadState *tstate, PyObject *name,
PyObject *const *args, Py_ssize_t nargs)
{
assert(nargs >= 1);
class_name(PyObject *cls)
{
PyObject *name;
- if (_PyObject_LookupAttrId(cls, &PyId___name__, &name) == 0) {
+ if (_PyObject_LookupAttr(cls, &_Py_ID(__name__), &name) == 0) {
name = PyObject_Repr(cls);
}
return name;
if (custom) {
int unbound;
- PyObject *mro_meth = lookup_method((PyObject *)type, &PyId_mro,
- &unbound);
+ PyObject *mro_meth = lookup_method(
+ (PyObject *)type, &_Py_ID(mro), &unbound);
if (mro_meth == NULL)
return NULL;
mro_result = call_unbound_noarg(unbound, mro_meth, (PyObject *)type);
{
PyObject *descr;
- descr = _PyType_LookupId(type, &PyId___dict__);
+ descr = _PyType_Lookup(type, &_Py_ID(__dict__));
if (descr == NULL || !PyDescr_IsData(descr))
return NULL;
return -1;
}
assert(PyUnicode_Check(name));
- if (_PyUnicode_EqualToASCIIId(name, &PyId___dict__)) {
+ if (_PyUnicode_Equal(name, &_Py_ID(__dict__))) {
if (!ctx->may_add_dict || ctx->add_dict != 0) {
PyErr_SetString(PyExc_TypeError,
"__dict__ slot disallowed: "
}
ctx->add_dict++;
}
- if (_PyUnicode_EqualToASCIIId(name, &PyId___weakref__)) {
+ if (_PyUnicode_Equal(name, &_Py_ID(__weakref__))) {
if (!ctx->may_add_weak || ctx->add_weak != 0) {
PyErr_SetString(PyExc_TypeError,
"__weakref__ slot disallowed: "
Py_ssize_t j = 0;
for (Py_ssize_t i = 0; i < nslot; i++) {
PyObject *slot = PyTuple_GET_ITEM(slots, i);
- if ((ctx->add_dict &&
- _PyUnicode_EqualToASCIIId(slot, &PyId___dict__)) ||
- (ctx->add_weak &&
- _PyUnicode_EqualToASCIIString(slot, "__weakref__")))
+ if ((ctx->add_dict && _PyUnicode_Equal(slot, &_Py_ID(__dict__))) ||
+ (ctx->add_weak && _PyUnicode_Equal(slot, &_Py_ID(__weakref__))))
{
continue;
}
/* CPython inserts __qualname__ and __classcell__ (when needed)
into the namespace when creating a class. They will be deleted
below so won't act as class variables. */
- if (!_PyUnicode_EqualToASCIIId(slot, &PyId___qualname__) &&
- !_PyUnicode_EqualToASCIIId(slot, &PyId___classcell__))
+ if (!_PyUnicode_Equal(slot, &_Py_ID(__qualname__)) &&
+ !_PyUnicode_Equal(slot, &_Py_ID(__classcell__)))
{
PyErr_Format(PyExc_ValueError,
"%R in __slots__ conflicts with class variable",
static int
type_new_set_module(PyTypeObject *type)
{
- int r = _PyDict_ContainsId(type->tp_dict, &PyId___module__);
+ int r = PyDict_Contains(type->tp_dict, &_Py_ID(__module__));
if (r < 0) {
return -1;
}
return 0;
}
- PyObject *module = _PyDict_GetItemIdWithError(globals, &PyId___name__);
+ PyObject *module = PyDict_GetItemWithError(globals, &_Py_ID(__name__));
if (module == NULL) {
if (PyErr_Occurred()) {
return -1;
return 0;
}
- if (_PyDict_SetItemId(type->tp_dict, &PyId___module__, module) < 0) {
+ if (PyDict_SetItem(type->tp_dict, &_Py_ID(__module__), module) < 0) {
return -1;
}
return 0;
type_new_set_ht_name(PyTypeObject *type)
{
PyHeapTypeObject *et = (PyHeapTypeObject *)type;
- PyObject *qualname = _PyDict_GetItemIdWithError(type->tp_dict,
- &PyId___qualname__);
+ PyObject *qualname = PyDict_GetItemWithError(
+ type->tp_dict, &_Py_ID(__qualname__));
if (qualname != NULL) {
if (!PyUnicode_Check(qualname)) {
PyErr_Format(PyExc_TypeError,
return -1;
}
et->ht_qualname = Py_NewRef(qualname);
- if (_PyDict_DelItemId(type->tp_dict, &PyId___qualname__) < 0) {
+ if (PyDict_DelItem(type->tp_dict, &_Py_ID(__qualname__)) < 0) {
return -1;
}
}
static int
type_new_set_doc(PyTypeObject *type)
{
- PyObject *doc = _PyDict_GetItemIdWithError(type->tp_dict, &PyId___doc__);
+ PyObject *doc = PyDict_GetItemWithError(type->tp_dict, &_Py_ID(__doc__));
if (doc == NULL) {
if (PyErr_Occurred()) {
return -1;
static int
-type_new_staticmethod(PyTypeObject *type, _Py_Identifier *attr_id)
+type_new_staticmethod(PyTypeObject *type, PyObject *attr)
{
- PyObject *func = _PyDict_GetItemIdWithError(type->tp_dict, attr_id);
+ PyObject *func = PyDict_GetItemWithError(type->tp_dict, attr);
if (func == NULL) {
if (PyErr_Occurred()) {
return -1;
if (static_func == NULL) {
return -1;
}
- if (_PyDict_SetItemId(type->tp_dict, attr_id, static_func) < 0) {
+ if (PyDict_SetItem(type->tp_dict, attr, static_func) < 0) {
Py_DECREF(static_func);
return -1;
}
static int
-type_new_classmethod(PyTypeObject *type, _Py_Identifier *attr_id)
+type_new_classmethod(PyTypeObject *type, PyObject *attr)
{
- PyObject *func = _PyDict_GetItemIdWithError(type->tp_dict, attr_id);
+ PyObject *func = PyDict_GetItemWithError(type->tp_dict, attr);
if (func == NULL) {
if (PyErr_Occurred()) {
return -1;
return -1;
}
- if (_PyDict_SetItemId(type->tp_dict, attr_id, method) < 0) {
+ if (PyDict_SetItem(type->tp_dict, attr, method) < 0) {
Py_DECREF(method);
return -1;
}
static int
type_new_set_classcell(PyTypeObject *type)
{
- PyObject *cell = _PyDict_GetItemIdWithError(type->tp_dict,
- &PyId___classcell__);
+ PyObject *cell = PyDict_GetItemWithError(
+ type->tp_dict, &_Py_ID(__classcell__));
if (cell == NULL) {
if (PyErr_Occurred()) {
return -1;
}
(void)PyCell_Set(cell, (PyObject *) type);
- if (_PyDict_DelItemId(type->tp_dict, &PyId___classcell__) < 0) {
+ if (PyDict_DelItem(type->tp_dict, &_Py_ID(__classcell__)) < 0) {
return -1;
}
return 0;
/* Special-case __new__: if it's a plain function,
make it a static function */
- if (type_new_staticmethod(type, &PyId___new__) < 0) {
+ if (type_new_staticmethod(type, &_Py_ID(__new__)) < 0) {
return -1;
}
/* Special-case __init_subclass__ and __class_getitem__:
if they are plain functions, make them classmethods */
- if (type_new_classmethod(type, &PyId___init_subclass__) < 0) {
+ if (type_new_classmethod(type, &_Py_ID(__init_subclass__)) < 0) {
return -1;
}
- if (type_new_classmethod(type, &PyId___class_getitem__) < 0) {
+ if (type_new_classmethod(type, &_Py_ID(__class_getitem__)) < 0) {
return -1;
}
static int
type_new_get_slots(type_new_ctx *ctx, PyObject *dict)
{
- _Py_IDENTIFIER(__slots__);
- PyObject *slots = _PyDict_GetItemIdWithError(dict, &PyId___slots__);
+ PyObject *slots = PyDict_GetItemWithError(dict, &_Py_ID(__slots__));
if (slots == NULL) {
if (PyErr_Occurred()) {
return -1;
return 0;
}
- _Py_IDENTIFIER(__mro_entries__);
for (Py_ssize_t i = 0; i < nbases; i++) {
PyObject *base = PyTuple_GET_ITEM(ctx->bases, i);
if (PyType_Check(base)) {
continue;
}
PyObject *mro_entries;
- if (_PyObject_LookupAttrId(base, &PyId___mro_entries__,
- &mro_entries) < 0) {
+ if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__),
+ &mro_entries) < 0) {
return -1;
}
if (mro_entries != NULL) {
PyObject *__doc__ = PyUnicode_FromString(_PyType_DocWithoutSignature(type->tp_name, type->tp_doc));
if (!__doc__)
goto fail;
- r = _PyDict_SetItemId(type->tp_dict, &PyId___doc__, __doc__);
+ r = PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), __doc__);
Py_DECREF(__doc__);
if (r < 0)
goto fail;
}
/* Set type.__module__ */
- r = _PyDict_ContainsId(type->tp_dict, &PyId___module__);
+ r = PyDict_Contains(type->tp_dict, &_Py_ID(__module__));
if (r < 0) {
goto fail;
}
if (modname == NULL) {
goto fail;
}
- r = _PyDict_SetItemId(type->tp_dict, &PyId___module__, modname);
+ r = PyDict_SetItem(type->tp_dict, &_Py_ID(__module__), modname);
Py_DECREF(modname);
if (r != 0)
goto fail;
{
PyObject *classdict;
PyObject *bases;
- _Py_IDENTIFIER(__bases__);
assert(PyDict_Check(dict));
assert(aclass);
/* Merge in the type's dict (if any). */
- if (_PyObject_LookupAttrId(aclass, &PyId___dict__, &classdict) < 0) {
+ if (_PyObject_LookupAttr(aclass, &_Py_ID(__dict__), &classdict) < 0) {
return -1;
}
if (classdict != NULL) {
}
/* Recursively merge in the base types' (if any) dicts. */
- if (_PyObject_LookupAttrId(aclass, &PyId___bases__, &bases) < 0) {
+ if (_PyObject_LookupAttr(aclass, &_Py_ID(__bases__), &bases) < 0) {
return -1;
}
if (bases != NULL) {
PyObject *abstract_methods;
PyObject *sorted_methods;
PyObject *joined;
- PyObject *comma;
- _Py_static_string(comma_id, ", ");
Py_ssize_t method_count;
/* Compute ", ".join(sorted(type.__abstractmethods__))
Py_DECREF(sorted_methods);
return NULL;
}
- comma = _PyUnicode_FromId(&comma_id);
- if (comma == NULL) {
- Py_DECREF(sorted_methods);
- return NULL;
- }
- joined = PyUnicode_Join(comma, sorted_methods);
+ joined = PyUnicode_Join(&_Py_STR(comma_sep), sorted_methods);
method_count = PyObject_Length(sorted_methods);
Py_DECREF(sorted_methods);
if (joined == NULL)
Py_XDECREF(mod);
return NULL;
}
- if (mod != NULL && !_PyUnicode_EqualToASCIIId(mod, &PyId_builtins))
+ if (mod != NULL && !_PyUnicode_Equal(mod, &_Py_ID(builtins)))
rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self);
else
rtn = PyUnicode_FromFormat("<%s object at %p>",
static PyObject *
import_copyreg(void)
{
- PyObject *copyreg_str;
- PyObject *copyreg_module;
- _Py_IDENTIFIER(copyreg);
-
- copyreg_str = _PyUnicode_FromId(&PyId_copyreg);
- if (copyreg_str == NULL) {
- return NULL;
- }
/* Try to fetch cached copy of copyreg from sys.modules first in an
attempt to avoid the import overhead. Previously this was implemented
by storing a reference to the cached module in a static variable, but
this broke when multiple embedded interpreters were in use (see issue
#17408 and #19088). */
- copyreg_module = PyImport_GetModule(copyreg_str);
+ PyObject *copyreg_module = PyImport_GetModule(&_Py_ID(copyreg));
if (copyreg_module != NULL) {
return copyreg_module;
}
if (PyErr_Occurred()) {
return NULL;
}
- return PyImport_Import(copyreg_str);
+ return PyImport_Import(&_Py_ID(copyreg));
}
static PyObject *
{
PyObject *copyreg;
PyObject *slotnames;
- _Py_IDENTIFIER(__slotnames__);
- _Py_IDENTIFIER(_slotnames);
assert(PyType_Check(cls));
/* Get the slot names from the cache in the class if possible. */
- slotnames = _PyDict_GetItemIdWithError(cls->tp_dict, &PyId___slotnames__);
+ slotnames = PyDict_GetItemWithError(cls->tp_dict, &_Py_ID(__slotnames__));
if (slotnames != NULL) {
if (slotnames != Py_None && !PyList_Check(slotnames)) {
PyErr_Format(PyExc_TypeError,
/* Use _slotnames function from the copyreg module to find the slots
by this class and its bases. This function will cache the result
in __slotnames__. */
- slotnames = _PyObject_CallMethodIdOneArg(copyreg, &PyId__slotnames,
- (PyObject *)cls);
+ slotnames = PyObject_CallMethodOneArg(
+ copyreg, &_Py_ID(_slotnames), (PyObject *)cls);
Py_DECREF(copyreg);
if (slotnames == NULL)
return NULL;
{
PyObject *state;
PyObject *getstate;
- _Py_IDENTIFIER(__getstate__);
- if (_PyObject_LookupAttrId(obj, &PyId___getstate__, &getstate) < 0) {
+ if (_PyObject_LookupAttr(obj, &_Py_ID(__getstate__), &getstate) < 0) {
return NULL;
}
if (getstate == NULL) {
_PyObject_GetNewArguments(PyObject *obj, PyObject **args, PyObject **kwargs)
{
PyObject *getnewargs, *getnewargs_ex;
- _Py_IDENTIFIER(__getnewargs_ex__);
- _Py_IDENTIFIER(__getnewargs__);
if (args == NULL || kwargs == NULL) {
PyErr_BadInternalCall();
/* We first attempt to fetch the arguments for __new__ by calling
__getnewargs_ex__ on the object. */
- getnewargs_ex = _PyObject_LookupSpecial(obj, &PyId___getnewargs_ex__);
+ getnewargs_ex = _PyObject_LookupSpecial(obj, &_Py_ID(__getnewargs_ex__));
if (getnewargs_ex != NULL) {
PyObject *newargs = _PyObject_CallNoArgs(getnewargs_ex);
Py_DECREF(getnewargs_ex);
/* The object does not have __getnewargs_ex__ so we fallback on using
__getnewargs__ instead. */
- getnewargs = _PyObject_LookupSpecial(obj, &PyId___getnewargs__);
+ getnewargs = _PyObject_LookupSpecial(obj, &_Py_ID(__getnewargs__));
if (getnewargs != NULL) {
*args = _PyObject_CallNoArgs(getnewargs);
Py_DECREF(getnewargs);
Py_INCREF(*dictitems);
}
else {
- PyObject *items;
- _Py_IDENTIFIER(items);
-
- items = _PyObject_CallMethodIdNoArgs(obj, &PyId_items);
+ PyObject *items = PyObject_CallMethodNoArgs(obj, &_Py_ID(items));
if (items == NULL) {
Py_CLEAR(*listitems);
return -1;
}
hasargs = (args != NULL);
if (kwargs == NULL || PyDict_GET_SIZE(kwargs) == 0) {
- _Py_IDENTIFIER(__newobj__);
PyObject *cls;
Py_ssize_t i, n;
Py_XDECREF(kwargs);
- newobj = _PyObject_GetAttrId(copyreg, &PyId___newobj__);
+ newobj = PyObject_GetAttr(copyreg, &_Py_ID(__newobj__));
Py_DECREF(copyreg);
if (newobj == NULL) {
Py_XDECREF(args);
Py_XDECREF(args);
}
else if (args != NULL) {
- _Py_IDENTIFIER(__newobj_ex__);
-
- newobj = _PyObject_GetAttrId(copyreg, &PyId___newobj_ex__);
+ newobj = PyObject_GetAttr(copyreg, &_Py_ID(__newobj_ex__));
Py_DECREF(copyreg);
if (newobj == NULL) {
Py_DECREF(args);
{
static PyObject *objreduce;
PyObject *reduce, *res;
- _Py_IDENTIFIER(__reduce__);
if (objreduce == NULL) {
- objreduce = _PyDict_GetItemIdWithError(PyBaseObject_Type.tp_dict,
- &PyId___reduce__);
+ objreduce = PyDict_GetItemWithError(
+ PyBaseObject_Type.tp_dict, &_Py_ID(__reduce__));
if (objreduce == NULL && PyErr_Occurred()) {
return NULL;
}
}
- if (_PyObject_LookupAttrId(self, &PyId___reduce__, &reduce) < 0) {
+ if (_PyObject_LookupAttr(self, &_Py_ID(__reduce__), &reduce) < 0) {
return NULL;
}
if (reduce != NULL) {
int override;
cls = (PyObject *) Py_TYPE(self);
- clsreduce = _PyObject_GetAttrId(cls, &PyId___reduce__);
+ clsreduce = PyObject_GetAttr(cls, &_Py_ID(__reduce__));
if (clsreduce == NULL) {
Py_DECREF(reduce);
return NULL;
PyObject *itsclass = NULL;
/* Get __dict__ (which may or may not be a real dict...) */
- if (_PyObject_LookupAttrId(self, &PyId___dict__, &dict) < 0) {
+ if (_PyObject_LookupAttr(self, &_Py_ID(__dict__), &dict) < 0) {
return NULL;
}
if (dict == NULL) {
goto error;
/* Merge in attrs reachable from its class. */
- if (_PyObject_LookupAttrId(self, &PyId___class__, &itsclass) < 0) {
+ if (_PyObject_LookupAttr(self, &_Py_ID(__class__), &itsclass) < 0) {
goto error;
}
/* XXX(tomer): Perhaps fall back to Py_TYPE(obj) if no
overrides_hash(PyTypeObject *type)
{
PyObject *dict = type->tp_dict;
- _Py_IDENTIFIER(__eq__);
assert(dict != NULL);
- int r = _PyDict_ContainsId(dict, &PyId___eq__);
+ int r = PyDict_Contains(dict, &_Py_ID(__eq__));
if (r == 0) {
- r = _PyDict_ContainsId(dict, &PyId___hash__);
+ r = PyDict_Contains(dict, &_Py_ID(__hash__));
}
return r;
}
static int
type_dict_set_doc(PyTypeObject *type)
{
- int r = _PyDict_ContainsId(type->tp_dict, &PyId___doc__);
+ int r = PyDict_Contains(type->tp_dict, &_Py_ID(__doc__));
if (r < 0) {
return -1;
}
return -1;
}
- if (_PyDict_SetItemId(type->tp_dict, &PyId___doc__, doc) < 0) {
+ if (PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), doc) < 0) {
Py_DECREF(doc);
return -1;
}
Py_DECREF(doc);
}
else {
- if (_PyDict_SetItemId(type->tp_dict, &PyId___doc__, Py_None) < 0) {
+ if (PyDict_SetItem(type->tp_dict, &_Py_ID(__doc__), Py_None) < 0) {
return -1;
}
}
return 0;
}
- int r = _PyDict_ContainsId(type->tp_dict, &PyId___hash__);
+ int r = PyDict_Contains(type->tp_dict, &_Py_ID(__hash__));
if (r < 0) {
return -1;
}
return 0;
}
- if (_PyDict_SetItemId(type->tp_dict, &PyId___hash__, Py_None) < 0) {
+ if (PyDict_SetItem(type->tp_dict, &_Py_ID(__hash__), Py_None) < 0) {
return -1;
}
type->tp_hash = PyObject_HashNotImplemented;
static int
add_tp_new_wrapper(PyTypeObject *type)
{
- int r = _PyDict_ContainsId(type->tp_dict, &PyId___new__);
+ int r = PyDict_Contains(type->tp_dict, &_Py_ID(__new__));
if (r > 0) {
return 0;
}
if (func == NULL) {
return -1;
}
- r = _PyDict_SetItemId(type->tp_dict, &PyId___new__, func);
+ r = PyDict_SetItem(type->tp_dict, &_Py_ID(__new__), func);
Py_DECREF(func);
return r;
}
/* Slot wrappers that call the corresponding __foo__ slot. See comments
below at override_slots() for more explanation. */
-#define SLOT0(FUNCNAME, OPSTR) \
+#define SLOT0(FUNCNAME, DUNDER) \
static PyObject * \
FUNCNAME(PyObject *self) \
{ \
PyObject* stack[1] = {self}; \
- _Py_static_string(id, OPSTR); \
- return vectorcall_method(&id, stack, 1); \
+ return vectorcall_method(&_Py_ID(DUNDER), stack, 1); \
}
-#define SLOT1(FUNCNAME, OPSTR, ARG1TYPE) \
+#define SLOT1(FUNCNAME, DUNDER, ARG1TYPE) \
static PyObject * \
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
{ \
PyObject* stack[2] = {self, arg1}; \
- _Py_static_string(id, OPSTR); \
- return vectorcall_method(&id, stack, 2); \
+ return vectorcall_method(&_Py_ID(DUNDER), stack, 2); \
}
/* Boolean helper for SLOT1BINFULL().
right.__class__ is a nontrivial subclass of left.__class__. */
static int
-method_is_overloaded(PyObject *left, PyObject *right, struct _Py_Identifier *name)
+method_is_overloaded(PyObject *left, PyObject *right, PyObject *name)
{
PyObject *a, *b;
int ok;
- if (_PyObject_LookupAttrId((PyObject *)(Py_TYPE(right)), name, &b) < 0) {
+ if (_PyObject_LookupAttr((PyObject *)(Py_TYPE(right)), name, &b) < 0) {
return -1;
}
if (b == NULL) {
return 0;
}
- if (_PyObject_LookupAttrId((PyObject *)(Py_TYPE(left)), name, &a) < 0) {
+ if (_PyObject_LookupAttr((PyObject *)(Py_TYPE(left)), name, &a) < 0) {
Py_DECREF(b);
return -1;
}
}
-#define SLOT1BINFULL(FUNCNAME, TESTFUNC, SLOTNAME, OPSTR, ROPSTR) \
+#define SLOT1BINFULL(FUNCNAME, TESTFUNC, SLOTNAME, DUNDER, RDUNDER) \
static PyObject * \
FUNCNAME(PyObject *self, PyObject *other) \
{ \
PyObject* stack[2]; \
PyThreadState *tstate = _PyThreadState_GET(); \
- _Py_static_string(op_id, OPSTR); \
- _Py_static_string(rop_id, ROPSTR); \
int do_other = !Py_IS_TYPE(self, Py_TYPE(other)) && \
Py_TYPE(other)->tp_as_number != NULL && \
Py_TYPE(other)->tp_as_number->SLOTNAME == TESTFUNC; \
Py_TYPE(self)->tp_as_number->SLOTNAME == TESTFUNC) { \
PyObject *r; \
if (do_other && PyType_IsSubtype(Py_TYPE(other), Py_TYPE(self))) { \
- int ok = method_is_overloaded(self, other, &rop_id); \
+ int ok = method_is_overloaded(self, other, &_Py_ID(RDUNDER)); \
if (ok < 0) { \
return NULL; \
} \
if (ok) { \
stack[0] = other; \
stack[1] = self; \
- r = vectorcall_maybe(tstate, &rop_id, stack, 2); \
+ r = vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
if (r != Py_NotImplemented) \
return r; \
Py_DECREF(r); \
} \
stack[0] = self; \
stack[1] = other; \
- r = vectorcall_maybe(tstate, &op_id, stack, 2); \
+ r = vectorcall_maybe(tstate, &_Py_ID(DUNDER), stack, 2); \
if (r != Py_NotImplemented || \
Py_IS_TYPE(other, Py_TYPE(self))) \
return r; \
if (do_other) { \
stack[0] = other; \
stack[1] = self; \
- return vectorcall_maybe(tstate, &rop_id, stack, 2); \
+ return vectorcall_maybe(tstate, &_Py_ID(RDUNDER), stack, 2); \
} \
Py_RETURN_NOTIMPLEMENTED; \
}
-#define SLOT1BIN(FUNCNAME, SLOTNAME, OPSTR, ROPSTR) \
- SLOT1BINFULL(FUNCNAME, FUNCNAME, SLOTNAME, OPSTR, ROPSTR)
+#define SLOT1BIN(FUNCNAME, SLOTNAME, DUNDER, RDUNDER) \
+ SLOT1BINFULL(FUNCNAME, FUNCNAME, SLOTNAME, DUNDER, RDUNDER)
static Py_ssize_t
slot_sq_length(PyObject *self)
{
PyObject* stack[1] = {self};
- PyObject *res = vectorcall_method(&PyId___len__, stack, 1);
+ PyObject *res = vectorcall_method(&_Py_ID(__len__), stack, 1);
Py_ssize_t len;
if (res == NULL)
return NULL;
}
PyObject *stack[2] = {self, ival};
- PyObject *retval = vectorcall_method(&PyId___getitem__, stack, 2);
+ PyObject *retval = vectorcall_method(&_Py_ID(__getitem__), stack, 2);
Py_DECREF(ival);
return retval;
}
stack[0] = self;
stack[1] = index_obj;
if (value == NULL) {
- res = vectorcall_method(&PyId___delitem__, stack, 2);
+ res = vectorcall_method(&_Py_ID(__delitem__), stack, 2);
}
else {
stack[2] = value;
- res = vectorcall_method(&PyId___setitem__, stack, 3);
+ res = vectorcall_method(&_Py_ID(__setitem__), stack, 3);
}
Py_DECREF(index_obj);
PyThreadState *tstate = _PyThreadState_GET();
PyObject *func, *res;
int result = -1, unbound;
- _Py_IDENTIFIER(__contains__);
- func = lookup_maybe_method(self, &PyId___contains__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__contains__), &unbound);
if (func == Py_None) {
Py_DECREF(func);
PyErr_Format(PyExc_TypeError,
#define slot_mp_length slot_sq_length
-SLOT1(slot_mp_subscript, "__getitem__", PyObject *)
+SLOT1(slot_mp_subscript, __getitem__, PyObject *)
static int
slot_mp_ass_subscript(PyObject *self, PyObject *key, PyObject *value)
stack[0] = self;
stack[1] = key;
if (value == NULL) {
- res = vectorcall_method(&PyId___delitem__, stack, 2);
+ res = vectorcall_method(&_Py_ID(__delitem__), stack, 2);
}
else {
stack[2] = value;
- res = vectorcall_method(&PyId___setitem__, stack, 3);
+ res = vectorcall_method(&_Py_ID(__setitem__), stack, 3);
}
if (res == NULL)
return 0;
}
-SLOT1BIN(slot_nb_add, nb_add, "__add__", "__radd__")
-SLOT1BIN(slot_nb_subtract, nb_subtract, "__sub__", "__rsub__")
-SLOT1BIN(slot_nb_multiply, nb_multiply, "__mul__", "__rmul__")
-SLOT1BIN(slot_nb_matrix_multiply, nb_matrix_multiply, "__matmul__", "__rmatmul__")
-SLOT1BIN(slot_nb_remainder, nb_remainder, "__mod__", "__rmod__")
-SLOT1BIN(slot_nb_divmod, nb_divmod, "__divmod__", "__rdivmod__")
+SLOT1BIN(slot_nb_add, nb_add, __add__, __radd__)
+SLOT1BIN(slot_nb_subtract, nb_subtract, __sub__, __rsub__)
+SLOT1BIN(slot_nb_multiply, nb_multiply, __mul__, __rmul__)
+SLOT1BIN(slot_nb_matrix_multiply, nb_matrix_multiply, __matmul__, __rmatmul__)
+SLOT1BIN(slot_nb_remainder, nb_remainder, __mod__, __rmod__)
+SLOT1BIN(slot_nb_divmod, nb_divmod, __divmod__, __rdivmod__)
static PyObject *slot_nb_power(PyObject *, PyObject *, PyObject *);
-SLOT1BINFULL(slot_nb_power_binary, slot_nb_power,
- nb_power, "__pow__", "__rpow__")
+SLOT1BINFULL(slot_nb_power_binary, slot_nb_power, nb_power, __pow__, __rpow__)
static PyObject *
slot_nb_power(PyObject *self, PyObject *other, PyObject *modulus)
{
- _Py_IDENTIFIER(__pow__);
-
if (modulus == Py_None)
return slot_nb_power_binary(self, other);
/* Three-arg power doesn't use __rpow__. But ternary_op
if (Py_TYPE(self)->tp_as_number != NULL &&
Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) {
PyObject* stack[3] = {self, other, modulus};
- return vectorcall_method(&PyId___pow__, stack, 3);
+ return vectorcall_method(&_Py_ID(__pow__), stack, 3);
}
Py_RETURN_NOTIMPLEMENTED;
}
-SLOT0(slot_nb_negative, "__neg__")
-SLOT0(slot_nb_positive, "__pos__")
-SLOT0(slot_nb_absolute, "__abs__")
+SLOT0(slot_nb_negative, __neg__)
+SLOT0(slot_nb_positive, __pos__)
+SLOT0(slot_nb_absolute, __abs__)
static int
slot_nb_bool(PyObject *self)
PyObject *func, *value;
int result, unbound;
int using_len = 0;
- _Py_IDENTIFIER(__bool__);
- func = lookup_maybe_method(self, &PyId___bool__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__bool__), &unbound);
if (func == NULL) {
if (PyErr_Occurred()) {
return -1;
}
- func = lookup_maybe_method(self, &PyId___len__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__len__), &unbound);
if (func == NULL) {
if (PyErr_Occurred()) {
return -1;
static PyObject *
slot_nb_index(PyObject *self)
{
- _Py_IDENTIFIER(__index__);
PyObject *stack[1] = {self};
- return vectorcall_method(&PyId___index__, stack, 1);
+ return vectorcall_method(&_Py_ID(__index__), stack, 1);
}
-SLOT0(slot_nb_invert, "__invert__")
-SLOT1BIN(slot_nb_lshift, nb_lshift, "__lshift__", "__rlshift__")
-SLOT1BIN(slot_nb_rshift, nb_rshift, "__rshift__", "__rrshift__")
-SLOT1BIN(slot_nb_and, nb_and, "__and__", "__rand__")
-SLOT1BIN(slot_nb_xor, nb_xor, "__xor__", "__rxor__")
-SLOT1BIN(slot_nb_or, nb_or, "__or__", "__ror__")
+SLOT0(slot_nb_invert, __invert__)
+SLOT1BIN(slot_nb_lshift, nb_lshift, __lshift__, __rlshift__)
+SLOT1BIN(slot_nb_rshift, nb_rshift, __rshift__, __rrshift__)
+SLOT1BIN(slot_nb_and, nb_and, __and__, __rand__)
+SLOT1BIN(slot_nb_xor, nb_xor, __xor__, __rxor__)
+SLOT1BIN(slot_nb_or, nb_or, __or__, __ror__)
-SLOT0(slot_nb_int, "__int__")
-SLOT0(slot_nb_float, "__float__")
-SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *)
-SLOT1(slot_nb_inplace_subtract, "__isub__", PyObject *)
-SLOT1(slot_nb_inplace_multiply, "__imul__", PyObject *)
-SLOT1(slot_nb_inplace_matrix_multiply, "__imatmul__", PyObject *)
-SLOT1(slot_nb_inplace_remainder, "__imod__", PyObject *)
+SLOT0(slot_nb_int, __int__)
+SLOT0(slot_nb_float, __float__)
+SLOT1(slot_nb_inplace_add, __iadd__, PyObject *)
+SLOT1(slot_nb_inplace_subtract, __isub__, PyObject *)
+SLOT1(slot_nb_inplace_multiply, __imul__, PyObject *)
+SLOT1(slot_nb_inplace_matrix_multiply, __imatmul__, PyObject *)
+SLOT1(slot_nb_inplace_remainder, __imod__, PyObject *)
/* Can't use SLOT1 here, because nb_inplace_power is ternary */
static PyObject *
slot_nb_inplace_power(PyObject *self, PyObject * arg1, PyObject *arg2)
{
PyObject *stack[2] = {self, arg1};
- _Py_IDENTIFIER(__ipow__);
- return vectorcall_method(&PyId___ipow__, stack, 2);
-}
-SLOT1(slot_nb_inplace_lshift, "__ilshift__", PyObject *)
-SLOT1(slot_nb_inplace_rshift, "__irshift__", PyObject *)
-SLOT1(slot_nb_inplace_and, "__iand__", PyObject *)
-SLOT1(slot_nb_inplace_xor, "__ixor__", PyObject *)
-SLOT1(slot_nb_inplace_or, "__ior__", PyObject *)
+ return vectorcall_method(&_Py_ID(__ipow__), stack, 2);
+}
+SLOT1(slot_nb_inplace_lshift, __ilshift__, PyObject *)
+SLOT1(slot_nb_inplace_rshift, __irshift__, PyObject *)
+SLOT1(slot_nb_inplace_and, __iand__, PyObject *)
+SLOT1(slot_nb_inplace_xor, __ixor__, PyObject *)
+SLOT1(slot_nb_inplace_or, __ior__, PyObject *)
SLOT1BIN(slot_nb_floor_divide, nb_floor_divide,
- "__floordiv__", "__rfloordiv__")
-SLOT1BIN(slot_nb_true_divide, nb_true_divide, "__truediv__", "__rtruediv__")
-SLOT1(slot_nb_inplace_floor_divide, "__ifloordiv__", PyObject *)
-SLOT1(slot_nb_inplace_true_divide, "__itruediv__", PyObject *)
+ __floordiv__, __rfloordiv__)
+SLOT1BIN(slot_nb_true_divide, nb_true_divide, __truediv__, __rtruediv__)
+SLOT1(slot_nb_inplace_floor_divide, __ifloordiv__, PyObject *)
+SLOT1(slot_nb_inplace_true_divide, __itruediv__, PyObject *)
static PyObject *
slot_tp_repr(PyObject *self)
{
PyObject *func, *res;
- _Py_IDENTIFIER(__repr__);
int unbound;
- func = lookup_maybe_method(self, &PyId___repr__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__repr__), &unbound);
if (func != NULL) {
res = call_unbound_noarg(unbound, func, self);
Py_DECREF(func);
Py_TYPE(self)->tp_name, self);
}
-SLOT0(slot_tp_str, "__str__")
+SLOT0(slot_tp_str, __str__)
static Py_hash_t
slot_tp_hash(PyObject *self)
Py_ssize_t h;
int unbound;
- func = lookup_maybe_method(self, &PyId___hash__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__hash__), &unbound);
if (func == Py_None) {
Py_DECREF(func);
slot_tp_call(PyObject *self, PyObject *args, PyObject *kwds)
{
PyThreadState *tstate = _PyThreadState_GET();
- _Py_IDENTIFIER(__call__);
int unbound;
- PyObject *meth = lookup_method(self, &PyId___call__, &unbound);
+ PyObject *meth = lookup_method(self, &_Py_ID(__call__), &unbound);
if (meth == NULL) {
return NULL;
}
slot_tp_getattro(PyObject *self, PyObject *name)
{
PyObject *stack[2] = {self, name};
- return vectorcall_method(&PyId___getattribute__, stack, 2);
+ return vectorcall_method(&_Py_ID(__getattribute__), stack, 2);
}
static PyObject *
{
PyTypeObject *tp = Py_TYPE(self);
PyObject *getattr, *getattribute, *res;
- _Py_IDENTIFIER(__getattr__);
/* speed hack: we could use lookup_maybe, but that would resolve the
method fully for each attribute lookup for classes with
__getattr__, even when the attribute is present. So we use
_PyType_Lookup and create the method only when needed, with
call_attribute. */
- getattr = _PyType_LookupId(tp, &PyId___getattr__);
+ getattr = _PyType_Lookup(tp, &_Py_ID(__getattr__));
if (getattr == NULL) {
/* No __getattr__ hook: use a simpler dispatcher */
tp->tp_getattro = slot_tp_getattro;
__getattr__, even when self has the default __getattribute__
method. So we use _PyType_Lookup and create the method only when
needed, with call_attribute. */
- getattribute = _PyType_LookupId(tp, &PyId___getattribute__);
+ getattribute = _PyType_Lookup(tp, &_Py_ID(__getattribute__));
if (getattribute == NULL ||
(Py_IS_TYPE(getattribute, &PyWrapperDescr_Type) &&
((PyWrapperDescrObject *)getattribute)->d_wrapped ==
{
PyObject *stack[3];
PyObject *res;
- _Py_IDENTIFIER(__delattr__);
- _Py_IDENTIFIER(__setattr__);
stack[0] = self;
stack[1] = name;
if (value == NULL) {
- res = vectorcall_method(&PyId___delattr__, stack, 2);
+ res = vectorcall_method(&_Py_ID(__delattr__), stack, 2);
}
else {
stack[2] = value;
- res = vectorcall_method(&PyId___setattr__, stack, 3);
+ res = vectorcall_method(&_Py_ID(__setattr__), stack, 3);
}
if (res == NULL)
return -1;
return 0;
}
-static _Py_Identifier name_op[] = {
- _Py_static_string_init("__lt__"),
- _Py_static_string_init("__le__"),
- _Py_static_string_init("__eq__"),
- _Py_static_string_init("__ne__"),
- _Py_static_string_init("__gt__"),
- _Py_static_string_init("__ge__"),
+static PyObject *name_op[] = {
+ &_Py_ID(__lt__),
+ &_Py_ID(__le__),
+ &_Py_ID(__eq__),
+ &_Py_ID(__ne__),
+ &_Py_ID(__gt__),
+ &_Py_ID(__ge__),
};
static PyObject *
PyThreadState *tstate = _PyThreadState_GET();
int unbound;
- PyObject *func = lookup_maybe_method(self, &name_op[op], &unbound);
+ PyObject *func = lookup_maybe_method(self, name_op[op], &unbound);
if (func == NULL) {
PyErr_Clear();
Py_RETURN_NOTIMPLEMENTED;
{
int unbound;
PyObject *func, *res;
- _Py_IDENTIFIER(__iter__);
- func = lookup_maybe_method(self, &PyId___iter__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__iter__), &unbound);
if (func == Py_None) {
Py_DECREF(func);
PyErr_Format(PyExc_TypeError,
}
PyErr_Clear();
- func = lookup_maybe_method(self, &PyId___getitem__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__getitem__), &unbound);
if (func == NULL) {
PyErr_Format(PyExc_TypeError,
"'%.200s' object is not iterable",
static PyObject *
slot_tp_iternext(PyObject *self)
{
- _Py_IDENTIFIER(__next__);
PyObject *stack[1] = {self};
- return vectorcall_method(&PyId___next__, stack, 1);
+ return vectorcall_method(&_Py_ID(__next__), stack, 1);
}
static PyObject *
{
PyTypeObject *tp = Py_TYPE(self);
PyObject *get;
- _Py_IDENTIFIER(__get__);
- get = _PyType_LookupId(tp, &PyId___get__);
+ get = _PyType_Lookup(tp, &_Py_ID(__get__));
if (get == NULL) {
/* Avoid further slowdowns */
if (tp->tp_descr_get == slot_tp_descr_get)
{
PyObject* stack[3];
PyObject *res;
- _Py_IDENTIFIER(__delete__);
- _Py_IDENTIFIER(__set__);
stack[0] = self;
stack[1] = target;
if (value == NULL) {
- res = vectorcall_method(&PyId___delete__, stack, 2);
+ res = vectorcall_method(&_Py_ID(__delete__), stack, 2);
}
else {
stack[2] = value;
- res = vectorcall_method(&PyId___set__, stack, 3);
+ res = vectorcall_method(&_Py_ID(__set__), stack, 3);
}
if (res == NULL)
return -1;
{
PyThreadState *tstate = _PyThreadState_GET();
- _Py_IDENTIFIER(__init__);
int unbound;
- PyObject *meth = lookup_method(self, &PyId___init__, &unbound);
+ PyObject *meth = lookup_method(self, &_Py_ID(__init__), &unbound);
if (meth == NULL) {
return -1;
}
PyThreadState *tstate = _PyThreadState_GET();
PyObject *func, *result;
- func = _PyObject_GetAttrId((PyObject *)type, &PyId___new__);
+ func = PyObject_GetAttr((PyObject *)type, &_Py_ID(__new__));
if (func == NULL) {
return NULL;
}
static void
slot_tp_finalize(PyObject *self)
{
- _Py_IDENTIFIER(__del__);
int unbound;
PyObject *del, *res;
PyObject *error_type, *error_value, *error_traceback;
PyErr_Fetch(&error_type, &error_value, &error_traceback);
/* Execute __del__ method, if any. */
- del = lookup_maybe_method(self, &PyId___del__, &unbound);
+ del = lookup_maybe_method(self, &_Py_ID(__del__), &unbound);
if (del != NULL) {
res = call_unbound_noarg(unbound, del, self);
if (res == NULL)
{
int unbound;
PyObject *func, *res;
- _Py_IDENTIFIER(__await__);
- func = lookup_maybe_method(self, &PyId___await__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__await__), &unbound);
if (func != NULL) {
res = call_unbound_noarg(unbound, func, self);
Py_DECREF(func);
{
int unbound;
PyObject *func, *res;
- _Py_IDENTIFIER(__aiter__);
- func = lookup_maybe_method(self, &PyId___aiter__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__aiter__), &unbound);
if (func != NULL) {
res = call_unbound_noarg(unbound, func, self);
Py_DECREF(func);
{
int unbound;
PyObject *func, *res;
- _Py_IDENTIFIER(__anext__);
- func = lookup_maybe_method(self, &PyId___anext__, &unbound);
+ func = lookup_maybe_method(self, &_Py_ID(__anext__), &unbound);
if (func != NULL) {
res = call_unbound_noarg(unbound, func, self);
Py_DECREF(func);
Py_ssize_t i = 0;
PyObject *key, *value;
while (PyDict_Next(names_to_set, &i, &key, &value)) {
- PyObject *set_name = _PyObject_LookupSpecial(value, &PyId___set_name__);
+ PyObject *set_name = _PyObject_LookupSpecial(value,
+ &_Py_ID(__set_name__));
if (set_name == NULL) {
if (PyErr_Occurred()) {
goto error;
return -1;
}
- PyObject *func = _PyObject_GetAttrId(super, &PyId___init_subclass__);
+ PyObject *func = PyObject_GetAttr(super, &_Py_ID(__init_subclass__));
Py_DECREF(super);
if (func == NULL) {
return -1;
(i.e. super, or a subclass), not the class of su->obj. */
if (PyUnicode_Check(name) &&
PyUnicode_GET_LENGTH(name) == 9 &&
- _PyUnicode_EqualToASCIIId(name, &PyId___class__))
+ _PyUnicode_Equal(name, &_Py_ID(__class__)))
goto skip;
mro = starttype->tp_mro;
/* Try the slow way */
PyObject *class_attr;
- if (_PyObject_LookupAttrId(obj, &PyId___class__, &class_attr) < 0) {
+ if (_PyObject_LookupAttr(obj, &_Py_ID(__class__), &class_attr) < 0) {
return NULL;
}
if (class_attr != NULL &&
assert((_PyLocals_GetKind(co->co_localspluskinds, i) & CO_FAST_FREE) != 0);
PyObject *name = PyTuple_GET_ITEM(co->co_localsplusnames, i);
assert(PyUnicode_Check(name));
- if (_PyUnicode_EqualToASCIIId(name, &PyId___class__)) {
+ if (_PyUnicode_Equal(name, &_Py_ID(__class__))) {
PyObject *cell = _PyFrame_GetLocalsArray(cframe)[i];
if (cell == NULL || !PyCell_Check(cell)) {
PyErr_SetString(PyExc_RuntimeError,
// 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);
}
}
#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)
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);
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();
}
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);
}
}
for (Py_ssize_t i = 0; i < 256; i++) {
Py_CLEAR(state->latin1[i]);
}
- Py_CLEAR(state->empty_string);
}
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;
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) {
}
}
- 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) {
weakref_repr(PyWeakReference *self)
{
PyObject *name, *repr;
- _Py_IDENTIFIER(__name__);
PyObject* obj = PyWeakref_GET_OBJECT(self);
if (obj == Py_None) {
}
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;
}
#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; \
}
fp_setreadl(struct tok_state *tok, const char* enc)
{
PyObject *readline, *io, *stream;
- _Py_IDENTIFIER(open);
- _Py_IDENTIFIER(readline);
int fd;
long pos;
}
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);
}
#ifndef Py_BUILD_CORE_MODULE
# define Py_BUILD_CORE_MODULE
#endif
+#define NEEDS_PY_IDENTIFIER
/* Always enable assertion (even in release mode) */
#undef NDEBUG
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,
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;
}
#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) {
#endif
static PyObject *
-init_filters(void)
+init_filters(PyInterpreterState *interp)
{
#ifdef Py_DEBUG
/* Py_DEBUG builds show all warnings by default */
}
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) {
WarningsState *st = &interp->warnings;
if (st->filters == NULL) {
- st->filters = init_filters();
+ st->filters = init_filters(interp);
if (st->filters == NULL) {
return -1;
}
/*************************************************************************/
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 */
}
/* 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;
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 */
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;
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;
/* 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;
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;
Py_DECREF(tmp_item);
}
- action = get_default_action(st);
+ action = get_default_action(interp);
if (action != NULL) {
Py_INCREF(Py_None);
*item = Py_None;
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)
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;
}
}
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;
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;
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;
}
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;
}
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,
}
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)
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
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)
/* 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;
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,
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) */
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.
}
if (f == NULL) {
- globals = tstate->interp->sysdict;
+ globals = interp->sysdict;
*filename = PyUnicode_FromString("sys");
*lineno = 1;
}
/* 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;
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;
}
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);
}
PyObject *filename, *module, *registry, *res;
int lineno;
+ PyThreadState *tstate = get_current_tstate();
+ if (tstate == NULL) {
+ return NULL;
+ }
+
if (!setup_context(stack_level, &filename, &lineno, &module, ®istry))
return NULL;
- res = warn_explicit(category, message, filename, lineno, module, registry,
+ res = warn_explicit(tstate, category, message, filename, lineno, module, registry,
NULL, source);
Py_DECREF(filename);
Py_DECREF(registry);
}
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;
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;
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);
®istry, &module_globals, &sourceobj))
return NULL;
+ PyThreadState *tstate = get_current_tstate();
+ if (tstate == NULL) {
+ return NULL;
+ }
+
if (module_globals && module_globals != Py_None) {
if (!PyDict_Check(module_globals)) {
PyErr_Format(PyExc_TypeError,
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;
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;
}
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;
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);
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);
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;
}
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;
#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*
}
continue;
}
- if (_PyObject_LookupAttrId(base, &PyId___mro_entries__, &meth) < 0) {
+ if (_PyObject_LookupAttr(base, &_Py_ID(__mro_entries__), &meth) < 0) {
goto error;
}
if (!meth) {
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 */
}
/* 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) {
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;
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;
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;
}
if (flush) {
- PyObject *tmp = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
+ PyObject *tmp = PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (tmp == NULL) {
return NULL;
}
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;
}
/* First of all, flush stderr */
- tmp = _PyObject_CallMethodIdNoArgs(ferr, &PyId_flush);
+ tmp = PyObject_CallMethodNoArgs(ferr, &_Py_ID(flush));
if (tmp == NULL)
PyErr_Clear();
else
/* 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;
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;
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)) {
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
/* 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)) {
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
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,
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;
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");
}
# 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,
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;
}
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;
}
}
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,
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
}
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,
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,
}
TARGET(SETUP_ANNOTATIONS) {
- _Py_IDENTIFIER(__annotations__);
int err;
PyObject *ann_dict;
if (LOCALS() == NULL) {
}
/* 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;
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;
}
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;
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;
}
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,
}
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,
}
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,
}
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,
/* 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)
{
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");
/* 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;
}
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 "
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) {
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;
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);
}
PyObject * _PyCodec_LookupTextEncoding(const char *encoding,
const char *alternate_command)
{
- _Py_IDENTIFIER(_is_text_encoding);
PyObject *codec;
PyObject *attr;
int is_text_codec;
* 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;
}
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);
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;
}
}
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;
}
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;
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
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;
}
}
{
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;
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))
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;
}
{
PyCodeObject *co;
PyObject *qualname;
- identifier name;
Py_ssize_t funcflags;
arguments_ty args = e->v.Lambda.args;
assert(e->kind == Lambda_kind);
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;
}
{
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));
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);
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);
}
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);
}
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);
}
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);
}
{
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);
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);
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,
goto failure;
}
- int r = _PyDict_ContainsId(dict, &PyId___module__);
+ int r = PyDict_Contains(dict, &_Py_ID(__module__));
if (r < 0) {
goto failure;
}
(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)) {
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);
}
}
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;
}
/* Explicitly call file.flush() */
- PyObject *res = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
+ PyObject *res = _PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (!res) {
return -1;
}
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;
}
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;
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 */
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);
_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);
_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);
_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);
}
}
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) {
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);
_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);
}
}
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]*/
}
}
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 */
{
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;
}
}
else if (cpathobj != NULL) {
PyInterpreterState *interp = _PyInterpreterState_GET();
- _Py_IDENTIFIER(_get_sourcefile);
if (interp == NULL) {
Py_FatalError("no current interpreter");
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)
static PyObject *
module_dict_for_exec(PyThreadState *tstate, PyObject *name)
{
- _Py_IDENTIFIER(__builtins__);
PyObject *m, *d;
m = import_add_module(tstate, 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);
{
PyThreadState *tstate = _PyThreadState_GET();
PyObject *d, *external, *res;
- _Py_IDENTIFIER(_fix_up_module);
d = module_dict_for_exec(tstate, name);
if (d == NULL) {
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);
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;
_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;
}
}
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;
}
}
}
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;
}
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,
goto error;
}
- int haspath = _PyDict_ContainsId(globals, &PyId___path__);
+ int haspath = PyDict_Contains(globals, &_Py_ID(__path__));
if (haspath < 0) {
goto error;
}
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;
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),
int level)
{
PyThreadState *tstate = _PyThreadState_GET();
- _Py_IDENTIFIER(_handle_fromlist);
PyObject *abs_name = NULL;
PyObject *final_mod = NULL;
PyObject *mod = NULL;
}
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 {
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;
}
}
- reloaded_module = _PyObject_CallMethodIdOneArg(importlib, &PyId_reload, m);
+ reloaded_module = PyObject_CallMethodOneArg(importlib, &_Py_ID(reload), m);
Py_DECREF(importlib);
return reloaded_module;
}
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;
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;
}
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;
/* 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
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);
}
/* Replace '-' by '_' */
- modname = _PyObject_CallMethodId(encoded, &PyId_replace, "cc", '-', '_');
+ modname = _PyObject_CallMethod(encoded, &_Py_ID(replace), "cc", '-', '_');
if (modname == NULL)
goto error;
read = fread(p->buf, 1, n, p->fp);
}
else {
- _Py_IDENTIFIER(readinto);
PyObject *res, *mview;
Py_buffer buf;
if (mview == NULL)
return NULL;
- res = _PyObject_CallMethodId(p->readable, &PyId_readinto, "N", mview);
+ res = _PyObject_CallMethod(p->readable, &_Py_ID(readinto), "N", mview);
if (res != NULL) {
read = PyNumber_AsSsize_t(res, PyExc_ValueError);
Py_DECREF(res);
/* XXX Quick hack -- need to do this differently */
PyObject *s;
PyObject *res;
- _Py_IDENTIFIER(write);
s = PyMarshal_WriteObjectToString(value, version);
if (s == NULL)
return NULL;
- res = _PyObject_CallMethodIdOneArg(file, &PyId_write, s);
+ res = _PyObject_CallMethodOneArg(file, &_Py_ID(write), s);
Py_DECREF(s);
return res;
}
/*[clinic end generated code: output=f8e5c33233566344 input=c85c2b594cd8124a]*/
{
PyObject *data, *result;
- _Py_IDENTIFIER(read);
RFILE rf;
/*
* This can be removed if we guarantee good error handling
* for r_string()
*/
- data = _PyObject_CallMethodId(file, &PyId_read, "i", 0);
+ data = _PyObject_CallMethod(file, &_Py_ID(read), "i", 0);
if (data == NULL)
return NULL;
if (!PyBytes_Check(data)) {
#include "pycore_pylifecycle.h" // _PyErr_Print()
#include "pycore_pymem.h" // _PyObject_DebugMallocStats()
#include "pycore_pystate.h" // _PyThreadState_GET()
+#include "pycore_runtime.h" // _Py_ID()
#include "pycore_runtime_init.h" // _PyRuntimeState_INIT
#include "pycore_sliceobject.h" // _PySlice_Fini()
-#include "pycore_structseq.h" // _PyStructSequence_InitState()
#include "pycore_symtable.h" // _PySymtable_Fini()
#include "pycore_sysmodule.h" // _PySys_ClearAuditHooks()
#include "pycore_traceback.h" // _Py_DumpTracebackThreads()
#define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str))
-_Py_IDENTIFIER(flush);
-_Py_IDENTIFIER(name);
-_Py_IDENTIFIER(stdin);
-_Py_IDENTIFIER(stdout);
-_Py_IDENTIFIER(stderr);
-_Py_IDENTIFIER(threading);
-
#ifdef __cplusplus
extern "C" {
#endif
{
PyStatus status;
- status = _PyStructSequence_InitState(interp);
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
-
status = _PyTypes_InitState(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
PyDict_Clear(modules);
}
else {
- _Py_IDENTIFIER(clear);
- if (_PyObject_CallMethodIdNoArgs(modules, &PyId_clear) == NULL) {
+ if (PyObject_CallMethodNoArgs(modules, &_Py_ID(clear)) == NULL) {
PyErr_WriteUnraisable(NULL);
}
}
static int
flush_std_files(void)
{
- PyObject *fout = _PySys_GetObjectId(&PyId_stdout);
- PyObject *ferr = _PySys_GetObjectId(&PyId_stderr);
+ PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *fout = _PySys_GetAttr(tstate, &_Py_ID(stdout));
+ PyObject *ferr = _PySys_GetAttr(tstate, &_Py_ID(stderr));
PyObject *tmp;
int status = 0;
if (fout != NULL && fout != Py_None && !file_is_closed(fout)) {
- tmp = _PyObject_CallMethodIdNoArgs(fout, &PyId_flush);
+ tmp = PyObject_CallMethodNoArgs(fout, &_Py_ID(flush));
if (tmp == NULL) {
PyErr_WriteUnraisable(fout);
status = -1;
}
if (ferr != NULL && ferr != Py_None && !file_is_closed(ferr)) {
- tmp = _PyObject_CallMethodIdNoArgs(ferr, &PyId_flush);
+ tmp = PyObject_CallMethodNoArgs(ferr, &_Py_ID(flush));
if (tmp == NULL) {
PyErr_Clear();
status = -1;
const char* newline;
PyObject *line_buffering, *write_through;
int buffering, isatty;
- _Py_IDENTIFIER(open);
- _Py_IDENTIFIER(isatty);
- _Py_IDENTIFIER(TextIOWrapper);
- _Py_IDENTIFIER(mode);
const int buffered_stdio = config->buffered_stdio;
if (!is_valid_fd(fd))
mode = "wb";
else
mode = "rb";
- buf = _PyObject_CallMethodId(io, &PyId_open, "isiOOOO",
- fd, mode, buffering,
- Py_None, Py_None, /* encoding, errors */
- Py_None, Py_False); /* newline, closefd */
+ buf = _PyObject_CallMethod(io, &_Py_ID(open), "isiOOOO",
+ fd, mode, buffering,
+ Py_None, Py_None, /* encoding, errors */
+ Py_None, Py_False); /* newline, closefd */
if (buf == NULL)
goto error;
if (buffering) {
- _Py_IDENTIFIER(raw);
- raw = _PyObject_GetAttrId(buf, &PyId_raw);
+ raw = PyObject_GetAttr(buf, &_Py_ID(raw));
if (raw == NULL)
goto error;
}
#endif
text = PyUnicode_FromString(name);
- if (text == NULL || _PyObject_SetAttrId(raw, &PyId_name, text) < 0)
+ if (text == NULL || PyObject_SetAttr(raw, &_Py_ID(name), text) < 0)
goto error;
- res = _PyObject_CallMethodIdNoArgs(raw, &PyId_isatty);
+ res = PyObject_CallMethodNoArgs(raw, &_Py_ID(isatty));
if (res == NULL)
goto error;
isatty = PyObject_IsTrue(res);
goto error;
}
- stream = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "OOOsOO",
- buf, encoding_str, errors_str,
- newline, line_buffering, write_through);
+ stream = _PyObject_CallMethod(io, &_Py_ID(TextIOWrapper), "OOOsOO",
+ buf, encoding_str, errors_str,
+ newline, line_buffering, write_through);
Py_CLEAR(buf);
Py_CLEAR(encoding_str);
Py_CLEAR(errors_str);
else
mode = "r";
text = PyUnicode_FromString(mode);
- if (!text || _PyObject_SetAttrId(stream, &PyId_mode, text) < 0)
+ if (!text || PyObject_SetAttr(stream, &_Py_ID(mode), text) < 0)
goto error;
Py_CLEAR(text);
return stream;
if (std == NULL)
goto error;
PySys_SetObject("__stdin__", std);
- _PySys_SetObjectId(&PyId_stdin, std);
+ _PySys_SetAttr(&_Py_ID(stdin), std);
Py_DECREF(std);
/* Set sys.stdout */
if (std == NULL)
goto error;
PySys_SetObject("__stdout__", std);
- _PySys_SetObjectId(&PyId_stdout, std);
+ _PySys_SetAttr(&_Py_ID(stdout), std);
Py_DECREF(std);
#if 1 /* Disable this if you have trouble debugging bootstrap stuff */
Py_DECREF(std);
goto error;
}
- if (_PySys_SetObjectId(&PyId_stderr, std) < 0) {
+ if (_PySys_SetAttr(&_Py_ID(stderr), std) < 0) {
Py_DECREF(std);
goto error;
}
return 0;
}
- ferr = _PySys_GetObjectId(&PyId_stderr);
+ ferr = _PySys_GetAttr(tstate, &_Py_ID(stderr));
if (ferr == NULL || ferr == Py_None) {
/* sys.stderr is not set yet or set to None,
no need to try to display the exception */
Py_XDECREF(tb);
/* sys.stderr may be buffered: call sys.stderr.flush() */
- res = _PyObject_CallMethodIdNoArgs(ferr, &PyId_flush);
+ res = PyObject_CallMethodNoArgs(ferr, &_Py_ID(flush));
if (res == NULL) {
_PyErr_Clear(tstate);
}
static void
wait_for_thread_shutdown(PyThreadState *tstate)
{
- _Py_IDENTIFIER(_shutdown);
PyObject *result;
- PyObject *threading = _PyImport_GetModuleId(&PyId_threading);
+ PyObject *threading = PyImport_GetModule(&_Py_ID(threading));
if (threading == NULL) {
if (_PyErr_Occurred(tstate)) {
PyErr_WriteUnraisable(NULL);
/* else: threading not imported */
return;
}
- result = _PyObject_CallMethodIdNoArgs(threading, &PyId__shutdown);
+ result = PyObject_CallMethodNoArgs(threading, &_Py_ID(_shutdown));
if (result == NULL) {
PyErr_WriteUnraisable(threading);
}
#endif
-_Py_IDENTIFIER(__main__);
-_Py_IDENTIFIER(builtins);
-_Py_IDENTIFIER(excepthook);
-_Py_IDENTIFIER(flush);
-_Py_IDENTIFIER(last_traceback);
-_Py_IDENTIFIER(last_type);
-_Py_IDENTIFIER(last_value);
-_Py_IDENTIFIER(ps1);
-_Py_IDENTIFIER(ps2);
-_Py_IDENTIFIER(stdin);
-_Py_IDENTIFIER(stdout);
-_Py_IDENTIFIER(stderr);
-_Py_static_string(PyId_string, "<string>");
-
#ifdef __cplusplus
extern "C" {
#endif
flags = &local_flags;
}
- PyObject *v = _PySys_GetObjectId(&PyId_ps1);
+ PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *v = _PySys_GetAttr(tstate, &_Py_ID(ps1));
if (v == NULL) {
- _PySys_SetObjectId(&PyId_ps1, v = PyUnicode_FromString(">>> "));
+ _PySys_SetAttr(&_Py_ID(ps1), v = PyUnicode_FromString(">>> "));
Py_XDECREF(v);
}
- v = _PySys_GetObjectId(&PyId_ps2);
+ v = _PySys_GetAttr(tstate, &_Py_ID(ps2));
if (v == NULL) {
- _PySys_SetObjectId(&PyId_ps2, v = PyUnicode_FromString("... "));
+ _PySys_SetAttr(&_Py_ID(ps2), v = PyUnicode_FromString("... "));
Py_XDECREF(v);
}
PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
PyCompilerFlags *flags)
{
- PyObject *m, *d, *v, *w, *oenc = NULL, *mod_name;
+ PyObject *m, *d, *v, *w, *oenc = NULL;
mod_ty mod;
PyArena *arena;
const char *ps1 = "", *ps2 = "", *enc = NULL;
int errcode = 0;
- _Py_IDENTIFIER(encoding);
- _Py_IDENTIFIER(__main__);
-
- mod_name = _PyUnicode_FromId(&PyId___main__); /* borrowed */
- if (mod_name == NULL) {
- return -1;
- }
+ PyThreadState *tstate = _PyThreadState_GET();
if (fp == stdin) {
/* Fetch encoding from sys.stdin if possible. */
- v = _PySys_GetObjectId(&PyId_stdin);
+ v = _PySys_GetAttr(tstate, &_Py_ID(stdin));
if (v && v != Py_None) {
- oenc = _PyObject_GetAttrId(v, &PyId_encoding);
+ oenc = PyObject_GetAttr(v, &_Py_ID(encoding));
if (oenc)
enc = PyUnicode_AsUTF8(oenc);
if (!enc)
PyErr_Clear();
}
}
- v = _PySys_GetObjectId(&PyId_ps1);
+ v = _PySys_GetAttr(tstate, &_Py_ID(ps1));
if (v != NULL) {
v = PyObject_Str(v);
if (v == NULL)
}
}
}
- w = _PySys_GetObjectId(&PyId_ps2);
+ w = _PySys_GetAttr(tstate, &_Py_ID(ps2));
if (w != NULL) {
w = PyObject_Str(w);
if (w == NULL)
}
return -1;
}
- m = PyImport_AddModuleObject(mod_name);
+ m = PyImport_AddModuleObject(&_Py_ID(__main__));
if (m == NULL) {
_PyArena_Free(arena);
return -1;
{
Py_ssize_t hold;
PyObject *v;
- _Py_IDENTIFIER(msg);
- _Py_IDENTIFIER(filename);
- _Py_IDENTIFIER(lineno);
- _Py_IDENTIFIER(offset);
- _Py_IDENTIFIER(end_lineno);
- _Py_IDENTIFIER(end_offset);
- _Py_IDENTIFIER(text);
*message = NULL;
*filename = NULL;
/* new style errors. `err' is an instance */
- *message = _PyObject_GetAttrId(err, &PyId_msg);
+ *message = PyObject_GetAttr(err, &_Py_ID(msg));
if (!*message)
goto finally;
- v = _PyObject_GetAttrId(err, &PyId_filename);
+ v = PyObject_GetAttr(err, &_Py_ID(filename));
if (!v)
goto finally;
if (v == Py_None) {
Py_DECREF(v);
- *filename = _PyUnicode_FromId(&PyId_string);
- if (*filename == NULL)
- goto finally;
+ *filename = &_Py_STR(anon_string);
Py_INCREF(*filename);
}
else {
*filename = v;
}
- v = _PyObject_GetAttrId(err, &PyId_lineno);
+ v = PyObject_GetAttr(err, &_Py_ID(lineno));
if (!v)
goto finally;
hold = PyLong_AsSsize_t(v);
goto finally;
*lineno = hold;
- v = _PyObject_GetAttrId(err, &PyId_offset);
+ v = PyObject_GetAttr(err, &_Py_ID(offset));
if (!v)
goto finally;
if (v == Py_None) {
}
if (Py_TYPE(err) == (PyTypeObject*)PyExc_SyntaxError) {
- v = _PyObject_GetAttrId(err, &PyId_end_lineno);
+ v = PyObject_GetAttr(err, &_Py_ID(end_lineno));
if (!v) {
PyErr_Clear();
*end_lineno = *lineno;
*end_lineno = hold;
}
- v = _PyObject_GetAttrId(err, &PyId_end_offset);
+ v = PyObject_GetAttr(err, &_Py_ID(end_offset));
if (!v) {
PyErr_Clear();
*end_offset = -1;
*end_offset = -1;
}
- v = _PyObject_GetAttrId(err, &PyId_text);
+ v = PyObject_GetAttr(err, &_Py_ID(text));
if (!v)
goto finally;
if (v == Py_None) {
if (PyExceptionInstance_Check(value)) {
/* The error code should be in the `code' attribute. */
- _Py_IDENTIFIER(code);
- PyObject *code = _PyObject_GetAttrId(value, &PyId_code);
+ PyObject *code = PyObject_GetAttr(value, &_Py_ID(code));
if (code) {
Py_DECREF(value);
value = code;
exitcode = (int)PyLong_AsLong(value);
}
else {
- PyObject *sys_stderr = _PySys_GetObjectId(&PyId_stderr);
+ PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *sys_stderr = _PySys_GetAttr(tstate, &_Py_ID(stderr));
/* We clear the exception here to avoid triggering the assertion
* in PyObject_Str that ensures it won't silently lose exception
* details.
/* Now we know v != NULL too */
if (set_sys_last_vars) {
- if (_PySys_SetObjectId(&PyId_last_type, exception) < 0) {
+ if (_PySys_SetAttr(&_Py_ID(last_type), exception) < 0) {
_PyErr_Clear(tstate);
}
- if (_PySys_SetObjectId(&PyId_last_value, v) < 0) {
+ if (_PySys_SetAttr(&_Py_ID(last_value), v) < 0) {
_PyErr_Clear(tstate);
}
- if (_PySys_SetObjectId(&PyId_last_traceback, tb) < 0) {
+ if (_PySys_SetAttr(&_Py_ID(last_traceback), tb) < 0) {
_PyErr_Clear(tstate);
}
}
- hook = _PySys_GetObjectId(&PyId_excepthook);
+ hook = _PySys_GetAttr(tstate, &_Py_ID(excepthook));
if (_PySys_Audit(tstate, "sys.excepthook", "OOOO", hook ? hook : Py_None,
exception, v, tb) < 0) {
if (PyErr_ExceptionMatches(PyExc_RuntimeError)) {
{
PyObject *f = ctx->file;
- _Py_IDENTIFIER(print_file_and_line);
PyObject *tmp;
- int res = _PyObject_LookupAttrId(*value_p, &PyId_print_file_and_line, &tmp);
+ int res = _PyObject_LookupAttr(*value_p, &_Py_ID(print_file_and_line), &tmp);
if (res <= 0) {
if (res < 0) {
PyErr_Clear();
{
PyObject *f = ctx->file;
- _Py_IDENTIFIER(__module__);
-
assert(PyExceptionClass_Check(type));
if (write_indented_margin(ctx, f) < 0) {
return -1;
}
- PyObject *modulename = _PyObject_GetAttrId(type, &PyId___module__);
+ PyObject *modulename = PyObject_GetAttr(type, &_Py_ID(__module__));
if (modulename == NULL || !PyUnicode_Check(modulename)) {
Py_XDECREF(modulename);
PyErr_Clear();
}
}
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__)))
{
int res = PyFile_WriteObject(modulename, f, Py_PRINT_RAW);
Py_DECREF(modulename);
return 0;
}
- _Py_IDENTIFIER(__note__);
-
- PyObject *note = _PyObject_GetAttrId(value, &PyId___note__);
+ PyObject *note = PyObject_GetAttr(value, &_Py_ID(__note__));
if (note == NULL) {
return -1;
}
}
if (print_exception_recursive(&ctx, value) < 0) {
PyErr_Clear();
+ _PyObject_Dump(value);
+ fprintf(stderr, "lost sys.stderr\n");
}
Py_XDECREF(ctx.seen);
/* Call file.flush() */
- PyObject *res = _PyObject_CallMethodIdNoArgs(file, &PyId_flush);
+ PyObject *res = _PyObject_CallMethodNoArgs(file, &_Py_ID(flush));
if (!res) {
/* Silently ignore file.flush() error */
PyErr_Clear();
void
PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
{
- PyObject *file = _PySys_GetObjectId(&PyId_stderr);
+ PyThreadState *tstate = _PyThreadState_GET();
+ PyObject *file = _PySys_GetAttr(tstate, &_Py_ID(stderr));
if (file == NULL) {
_PyObject_Dump(value);
fprintf(stderr, "lost sys.stderr\n");
PyObject *ret = NULL;
mod_ty mod;
PyArena *arena;
- PyObject *filename;
-
- filename = _PyUnicode_FromId(&PyId_string); /* borrowed */
- if (filename == NULL)
- return NULL;
arena = _PyArena_New();
if (arena == NULL)
return NULL;
- mod = _PyParser_ASTFromString(str, filename, start, flags, arena);
+ mod = _PyParser_ASTFromString(
+ str, &_Py_STR(anon_string), start, flags, arena);
if (mod != NULL)
- ret = run_mod(mod, filename, globals, locals, flags, arena);
+ ret = run_mod(mod, &_Py_STR(anon_string), globals, locals, flags, arena);
_PyArena_Free(arena);
return ret;
}
/* Save the current exception */
PyErr_Fetch(&type, &value, &traceback);
- f = _PySys_GetObjectId(&PyId_stderr);
+ PyThreadState *tstate = _PyThreadState_GET();
+ f = _PySys_GetAttr(tstate, &_Py_ID(stderr));
if (f != NULL) {
- r = _PyObject_CallMethodIdNoArgs(f, &PyId_flush);
+ r = _PyObject_CallMethodNoArgs(f, &_Py_ID(flush));
if (r)
Py_DECREF(r);
else
PyErr_Clear();
}
- f = _PySys_GetObjectId(&PyId_stdout);
+ f = _PySys_GetAttr(tstate, &_Py_ID(stdout));
if (f != NULL) {
- r = _PyObject_CallMethodIdNoArgs(f, &PyId_flush);
+ r = _PyObject_CallMethodNoArgs(f, &_Py_ID(flush));
if (r)
Py_DECREF(r);
else
#include "Python.h"
#include "pycore_code.h"
#include "pycore_dict.h"
+#include "pycore_global_strings.h" // _Py_ID()
#include "pycore_long.h"
#include "pycore_moduleobject.h"
#include "pycore_object.h"
{
PyModuleObject *m = (PyModuleObject *)owner;
PyObject *value = NULL;
- PyObject *getattr;
- _Py_IDENTIFIER(__getattr__);
assert((owner->ob_type->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0);
PyDictObject *dict = (PyDictObject *)m->md_dict;
if (dict == NULL) {
SPECIALIZATION_FAIL(opcode, SPEC_FAIL_NON_STRING_OR_SPLIT);
return -1;
}
- getattr = _PyUnicode_FromId(&PyId___getattr__); /* borrowed */
- if (getattr == NULL) {
- SPECIALIZATION_FAIL(opcode, SPEC_FAIL_OVERRIDDEN);
- PyErr_Clear();
- return -1;
- }
- Py_ssize_t index = _PyDict_GetItemHint(dict, getattr, -1, &value);
+ Py_ssize_t index = _PyDict_GetItemHint(dict, &_Py_ID(__getattr__), -1,
+ &value);
assert(index != DKIX_ERROR);
if (index != DKIX_EMPTY) {
SPECIALIZATION_FAIL(opcode, SPEC_FAIL_MODULE_ATTR_NOT_FOUND);
}
#endif
-_Py_IDENTIFIER(__getitem__);
#define SIMPLE_FUNCTION 0
goto success;
}
PyTypeObject *cls = Py_TYPE(container);
- PyObject *descriptor = _PyType_LookupId(cls, &PyId___getitem__);
+ PyObject *descriptor = _PyType_Lookup(cls, &_Py_ID(__getitem__));
if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) {
PyFunctionObject *func = (PyFunctionObject *)descriptor;
PyCodeObject *code = (PyCodeObject *)func->func_code;
}
goto fail;
}
- _Py_IDENTIFIER(__setitem__);
- PyObject *descriptor = _PyType_LookupId(container_type, &PyId___setitem__);
+ PyObject *descriptor = _PyType_Lookup(container_type, &_Py_ID(__setitem__));
if (descriptor && Py_TYPE(descriptor) == &PyFunction_Type) {
PyFunctionObject *func = (PyFunctionObject *)descriptor;
PyCodeObject *code = (PyCodeObject *)func->func_code;
#endif
static PyMethodDescrObject *_list_append = NULL;
-_Py_IDENTIFIER(append);
static int
specialize_method_descriptor(
return -1;
}
if (_list_append == NULL) {
- _list_append = (PyMethodDescrObject *)_PyType_LookupId(&PyList_Type, &PyId_append);
+ _list_append = (PyMethodDescrObject *)_PyType_Lookup(&PyList_Type,
+ &_Py_ID(append));
}
assert(_list_append != NULL);
if (nargs == 2 && descr == _list_append) {
#include "clinic/sysmodule.c.h"
-_Py_IDENTIFIER(_);
-_Py_IDENTIFIER(__sizeof__);
-_Py_IDENTIFIER(_xoptions);
-_Py_IDENTIFIER(buffer);
-_Py_IDENTIFIER(builtins);
-_Py_IDENTIFIER(encoding);
-_Py_IDENTIFIER(path);
-_Py_IDENTIFIER(stdout);
-_Py_IDENTIFIER(stderr);
-_Py_IDENTIFIER(warnoptions);
-_Py_IDENTIFIER(write);
+PyObject *
+_PySys_GetAttr(PyThreadState *tstate, PyObject *name)
+{
+ PyObject *sd = tstate->interp->sysdict;
+ if (sd == NULL) {
+ return NULL;
+ }
+ PyObject *exc_type, *exc_value, *exc_tb;
+ _PyErr_Fetch(tstate, &exc_type, &exc_value, &exc_tb);
+ /* XXX Suppress a new exception if it was raised and restore
+ * the old one. */
+ PyObject *value = _PyDict_GetItemWithError(sd, name);
+ _PyErr_Restore(tstate, exc_type, exc_value, exc_tb);
+ return value;
+}
static PyObject *
sys_get_object_id(PyThreadState *tstate, _Py_Identifier *key)
return sys_set_object_id(interp, key, v);
}
+int
+_PySys_SetAttr(PyObject *key, PyObject *v)
+{
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ return sys_set_object(interp, key, v);
+}
+
static int
sys_set_object_str(PyInterpreterState *interp, const char *name, PyObject *v)
{
/* Disallow tracing in hooks unless explicitly enabled */
PyThreadState_EnterTracing(ts);
while ((hook = PyIter_Next(hooks)) != NULL) {
- _Py_IDENTIFIER(__cantrace__);
PyObject *o;
- int canTrace = _PyObject_LookupAttrId(hook, &PyId___cantrace__, &o);
+ int canTrace = _PyObject_LookupAttr(hook, &_Py_ID(__cantrace__), &o);
if (o) {
canTrace = PyObject_IsTrue(o);
Py_DECREF(o);
const char *stdout_encoding_str;
int ret;
- stdout_encoding = _PyObject_GetAttrId(outf, &PyId_encoding);
+ stdout_encoding = PyObject_GetAttr(outf, &_Py_ID(encoding));
if (stdout_encoding == NULL)
goto error;
stdout_encoding_str = PyUnicode_AsUTF8(stdout_encoding);
if (encoded == NULL)
goto error;
- if (_PyObject_LookupAttrId(outf, &PyId_buffer, &buffer) < 0) {
+ if (_PyObject_LookupAttr(outf, &_Py_ID(buffer), &buffer) < 0) {
Py_DECREF(encoded);
goto error;
}
if (buffer) {
- result = _PyObject_CallMethodIdOneArg(buffer, &PyId_write, encoded);
+ result = PyObject_CallMethodOneArg(buffer, &_Py_ID(write), encoded);
Py_DECREF(buffer);
Py_DECREF(encoded);
if (result == NULL)
static PyObject *newline = NULL;
PyThreadState *tstate = _PyThreadState_GET();
- builtins = _PyImport_GetModuleId(&PyId_builtins);
+ builtins = PyImport_GetModule(&_Py_ID(builtins));
if (builtins == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_SetString(tstate, PyExc_RuntimeError,
if (o == Py_None) {
Py_RETURN_NONE;
}
- if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0)
+ if (PyObject_SetAttr(builtins, &_Py_ID(_), Py_None) != 0)
return NULL;
- outf = sys_get_object_id(tstate, &PyId_stdout);
+ outf = _PySys_GetAttr(tstate, &_Py_ID(stdout));
if (outf == NULL || outf == Py_None) {
_PyErr_SetString(tstate, PyExc_RuntimeError, "lost sys.stdout");
return NULL;
}
if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0)
return NULL;
- if (_PyObject_SetAttrId(builtins, &PyId__, o) != 0)
+ if (PyObject_SetAttr(builtins, &_Py_ID(_), o) != 0)
return NULL;
Py_RETURN_NONE;
}
return (size_t)-1;
}
- method = _PyObject_LookupSpecial(o, &PyId___sizeof__);
+ method = _PyObject_LookupSpecial(o, &_Py_ID(__sizeof__));
if (method == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_Format(tstate, PyExc_TypeError,
static PyObject *
get_warnoptions(PyThreadState *tstate)
{
- PyObject *warnoptions = sys_get_object_id(tstate, &PyId_warnoptions);
+ PyObject *warnoptions = _PySys_GetAttr(tstate, &_Py_ID(warnoptions));
if (warnoptions == NULL || !PyList_Check(warnoptions)) {
/* PEP432 TODO: we can reach this if warnoptions is NULL in the main
* interpreter config. When that happens, we need to properly set
if (warnoptions == NULL) {
return NULL;
}
- if (sys_set_object_id(tstate->interp, &PyId_warnoptions, warnoptions)) {
+ if (sys_set_object(tstate->interp, &_Py_ID(warnoptions), warnoptions)) {
Py_DECREF(warnoptions);
return NULL;
}
return;
}
- PyObject *warnoptions = sys_get_object_id(tstate, &PyId_warnoptions);
+ PyObject *warnoptions = _PySys_GetAttr(tstate, &_Py_ID(warnoptions));
if (warnoptions == NULL || !PyList_Check(warnoptions))
return;
PyList_SetSlice(warnoptions, 0, PyList_GET_SIZE(warnoptions), NULL);
PySys_HasWarnOptions(void)
{
PyThreadState *tstate = _PyThreadState_GET();
- PyObject *warnoptions = sys_get_object_id(tstate, &PyId_warnoptions);
+ PyObject *warnoptions = _PySys_GetAttr(tstate, &_Py_ID(warnoptions));
return (warnoptions != NULL && PyList_Check(warnoptions)
&& PyList_GET_SIZE(warnoptions) > 0);
}
static PyObject *
get_xoptions(PyThreadState *tstate)
{
- PyObject *xoptions = sys_get_object_id(tstate, &PyId__xoptions);
+ PyObject *xoptions = _PySys_GetAttr(tstate, &_Py_ID(_xoptions));
if (xoptions == NULL || !PyDict_Check(xoptions)) {
/* PEP432 TODO: we can reach this if xoptions is NULL in the main
* interpreter config. When that happens, we need to properly set
if (xoptions == NULL) {
return NULL;
}
- if (sys_set_object_id(tstate->interp, &PyId__xoptions, xoptions)) {
+ if (sys_set_object(tstate->interp, &_Py_ID(_xoptions), xoptions)) {
Py_DECREF(xoptions);
return NULL;
}
if (pstderr == NULL) {
goto error;
}
- if (_PyDict_SetItemId(sysdict, &PyId_stderr, pstderr) < 0) {
+ if (PyDict_SetItem(sysdict, &_Py_ID(stderr), pstderr) < 0) {
goto error;
}
if (PyDict_SetItemString(sysdict, "__stderr__", pstderr) < 0) {
if ((v = makepathobject(path, DELIM)) == NULL)
Py_FatalError("can't create sys.path");
PyInterpreterState *interp = _PyInterpreterState_GET();
- if (sys_set_object_id(interp, &PyId_path, v) != 0) {
+ if (sys_set_object(interp, &_Py_ID(path), v) != 0) {
Py_FatalError("can't assign sys.path");
}
Py_DECREF(v);
Py_FatalError("can't compute path0 from argv");
}
- PyObject *sys_path = sys_get_object_id(tstate, &PyId_path);
+ PyObject *sys_path = _PySys_GetAttr(tstate, &_Py_ID(path));
if (sys_path != NULL) {
if (PyList_Insert(sys_path, 0, path0) < 0) {
Py_DECREF(path0);
if (file == NULL)
return -1;
assert(unicode != NULL);
- PyObject *result = _PyObject_CallMethodIdOneArg(file, &PyId_write, unicode);
+ PyObject *result = _PyObject_CallMethodOneArg(file, &_Py_ID(write), unicode);
if (result == NULL) {
return -1;
}
*/
static void
-sys_write(_Py_Identifier *key, FILE *fp, const char *format, va_list va)
+sys_write(PyObject *key, FILE *fp, const char *format, va_list va)
{
PyObject *file;
PyObject *error_type, *error_value, *error_traceback;
PyThreadState *tstate = _PyThreadState_GET();
_PyErr_Fetch(tstate, &error_type, &error_value, &error_traceback);
- file = sys_get_object_id(tstate, key);
+ file = _PySys_GetAttr(tstate, key);
written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va);
if (sys_pyfile_write(buffer, file) != 0) {
_PyErr_Clear(tstate);
va_list va;
va_start(va, format);
- sys_write(&PyId_stdout, stdout, format, va);
+ sys_write(&_Py_ID(stdout), stdout, format, va);
va_end(va);
}
va_list va;
va_start(va, format);
- sys_write(&PyId_stderr, stderr, format, va);
+ sys_write(&_Py_ID(stderr), stderr, format, va);
va_end(va);
}
static void
-sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va)
+sys_format(PyObject *key, FILE *fp, const char *format, va_list va)
{
PyObject *file, *message;
PyObject *error_type, *error_value, *error_traceback;
PyThreadState *tstate = _PyThreadState_GET();
_PyErr_Fetch(tstate, &error_type, &error_value, &error_traceback);
- file = sys_get_object_id(tstate, key);
+ file = _PySys_GetAttr(tstate, key);
message = PyUnicode_FromFormatV(format, va);
if (message != NULL) {
if (sys_pyfile_write_unicode(message, file) != 0) {
va_list va;
va_start(va, format);
- sys_format(&PyId_stdout, stdout, format, va);
+ sys_format(&_Py_ID(stdout), stdout, format, va);
va_end(va);
}
va_list va;
va_start(va, format);
- sys_format(&PyId_stderr, stderr, format, va);
+ sys_format(&_Py_ID(stderr), stderr, format, va);
va_end(va);
}
#include "code.h" // PyCode_Addr2Line etc
#include "frameobject.h" // PyFrame_GetBack()
#include "pycore_ast.h" // asdl_seq_*
+#include "pycore_call.h" // _PyObject_CallMethodFormat()
#include "pycore_compile.h" // _PyAST_Optimize
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "pycore_frame.h" // _PyFrame_GetCode()
/* Function from Parser/tokenizer.c */
extern char* _PyTokenizer_FindEncodingFilename(int, PyObject *);
-_Py_IDENTIFIER(TextIOWrapper);
-_Py_IDENTIFIER(close);
-_Py_IDENTIFIER(open);
-_Py_IDENTIFIER(path);
-
/*[clinic input]
class TracebackType "PyTracebackObject *" "&PyTraceback_Type"
[clinic start generated code]*/
const char* filepath;
Py_ssize_t len;
PyObject* result;
+ PyObject *open = NULL;
filebytes = PyUnicode_EncodeFSDefault(filename);
if (filebytes == NULL) {
tail++;
taillen = strlen(tail);
- syspath = _PySys_GetObjectId(&PyId_path);
+ PyThreadState *tstate = _PyThreadState_GET();
+ syspath = _PySys_GetAttr(tstate, &_Py_ID(path));
if (syspath == NULL || !PyList_Check(syspath))
goto error;
npath = PyList_Size(syspath);
+ open = PyObject_GetAttr(io, &_Py_ID(open));
for (i = 0; i < npath; i++) {
v = PyList_GetItem(syspath, i);
if (v == NULL) {
namebuf[len++] = SEP;
strcpy(namebuf+len, tail);
- binary = _PyObject_CallMethodId(io, &PyId_open, "ss", namebuf, "rb");
+ binary = _PyObject_CallMethodFormat(tstate, open, "ss", namebuf, "rb");
if (binary != NULL) {
result = binary;
goto finally;
error:
result = NULL;
finally:
+ Py_XDECREF(open);
Py_DECREF(filebytes);
return result;
}
}
io = PyImport_ImportModule("io");
- if (io == NULL)
+ if (io == NULL) {
return -1;
- binary = _PyObject_CallMethodId(io, &PyId_open, "Os", filename, "rb");
+ }
+ binary = _PyObject_CallMethod(io, &_Py_ID(open), "Os", filename, "rb");
if (binary == NULL) {
PyErr_Clear();
PyMem_Free(found_encoding);
return 0;
}
- fob = _PyObject_CallMethodId(io, &PyId_TextIOWrapper, "Os", binary, encoding);
+ fob = _PyObject_CallMethod(io, &_Py_ID(TextIOWrapper),
+ "Os", binary, encoding);
Py_DECREF(io);
PyMem_Free(found_encoding);
if (fob == NULL) {
PyErr_Clear();
- res = _PyObject_CallMethodIdNoArgs(binary, &PyId_close);
+ res = PyObject_CallMethodNoArgs(binary, &_Py_ID(close));
Py_DECREF(binary);
if (res)
Py_DECREF(res);
break;
}
}
- res = _PyObject_CallMethodIdNoArgs(fob, &PyId_close);
+ res = PyObject_CallMethodNoArgs(fob, &_Py_ID(close));
if (res) {
Py_DECREF(res);
}
Objects/exceptions.c:_check_for_legacy_statements():exec_prefix static PyObject *exec_prefix
Objects/exceptions.c:_check_for_legacy_statements():print_prefix static PyObject *print_prefix
Objects/funcobject.c:PyFunction_NewWithQualName():__name__ static PyObject *__name__
-Objects/typeobject.c:object___reduce_ex___impl():objreduce static PyObject *objreduce
-Objects/typeobject.c:resolve_slotdups():pname static PyObject *pname
Objects/unicodeobject.c:unicode_empty static PyObject *unicode_empty
Objects/unicodeobject.c:unicode_latin1 static PyObject *unicode_latin1[256]
Python/_warnings.c:is_internal_frame():bootstrap_string static PyObject *bootstrap_string
-import argparse
-import ast
-import builtins
-import collections
import contextlib
+import glob
import os.path
+import re
import sys
INTERNAL = os.path.join(ROOT, 'Include', 'internal')
+STRING_LITERALS = {
+ 'empty': '',
+ 'dot': '.',
+ 'comma_sep': ', ',
+ 'percent': '%',
+ 'dbl_percent': '%%',
+
+ '"anonymous" labels': None,
+ 'anon_dictcomp': '<dictcomp>',
+ 'anon_genexpr': '<genexpr>',
+ 'anon_lambda': '<lambda>',
+ 'anon_listcomp': '<listcomp>',
+ 'anon_module': '<module>',
+ 'anon_setcomp': '<setcomp>',
+ 'anon_string': '<string>',
+ 'dot_locals': '.<locals>',
+}
+IDENTIFIERS = [
+ 'Py_Repr',
+ 'TextIOWrapper',
+ 'WarningMessage',
+ '_',
+ '__IOBase_closed',
+ '__abc_tpflags__',
+ '__abs__',
+ '__abstractmethods__',
+ '__add__',
+ '__aenter__',
+ '__aexit__',
+ '__aiter__',
+ '__all__',
+ '__and__',
+ '__anext__',
+ '__annotations__',
+ '__args__',
+ '__await__',
+ '__bases__',
+ '__bool__',
+ '__build_class__',
+ '__builtins__',
+ '__bytes__',
+ '__call__',
+ '__cantrace__',
+ '__class__',
+ '__class_getitem__',
+ '__classcell__',
+ '__complex__',
+ '__contains__',
+ '__copy__',
+ '__del__',
+ '__delattr__',
+ '__delete__',
+ '__delitem__',
+ '__dict__',
+ '__dir__',
+ '__divmod__',
+ '__doc__',
+ '__enter__',
+ '__eq__',
+ '__exit__',
+ '__file__',
+ '__float__',
+ '__floordiv__',
+ '__format__',
+ '__fspath__',
+ '__ge__',
+ '__get__',
+ '__getattr__',
+ '__getattribute__',
+ '__getinitargs__',
+ '__getitem__',
+ '__getnewargs__',
+ '__getnewargs_ex__',
+ '__getstate__',
+ '__gt__',
+ '__hash__',
+ '__iadd__',
+ '__iand__',
+ '__ifloordiv__',
+ '__ilshift__',
+ '__imatmul__',
+ '__imod__',
+ '__import__',
+ '__imul__',
+ '__index__',
+ '__init__',
+ '__init_subclass__',
+ '__instancecheck__',
+ '__int__',
+ '__invert__',
+ '__ior__',
+ '__ipow__',
+ '__irshift__',
+ '__isabstractmethod__',
+ '__isub__',
+ '__iter__',
+ '__itruediv__',
+ '__ixor__',
+ '__le__',
+ '__len__',
+ '__length_hint__',
+ '__loader__',
+ '__lshift__',
+ '__lt__',
+ '__ltrace__',
+ '__main__',
+ '__matmul__',
+ '__missing__',
+ '__mod__',
+ '__module__',
+ '__mro_entries__',
+ '__mul__',
+ '__name__',
+ '__ne__',
+ '__neg__',
+ '__new__',
+ '__newobj__',
+ '__newobj_ex__',
+ '__next__',
+ '__note__',
+ '__or__',
+ '__origin__',
+ '__package__',
+ '__parameters__',
+ '__path__',
+ '__pos__',
+ '__pow__',
+ '__prepare__',
+ '__qualname__',
+ '__radd__',
+ '__rand__',
+ '__rdivmod__',
+ '__reduce__',
+ '__reduce_ex__',
+ '__repr__',
+ '__reversed__',
+ '__rfloordiv__',
+ '__rlshift__',
+ '__rmatmul__',
+ '__rmod__',
+ '__rmul__',
+ '__ror__',
+ '__round__',
+ '__rpow__',
+ '__rrshift__',
+ '__rshift__',
+ '__rsub__',
+ '__rtruediv__',
+ '__rxor__',
+ '__set__',
+ '__set_name__',
+ '__setattr__',
+ '__setitem__',
+ '__setstate__',
+ '__sizeof__',
+ '__slotnames__',
+ '__slots__',
+ '__spec__',
+ '__str__',
+ '__sub__',
+ '__subclasscheck__',
+ '__subclasshook__',
+ '__truediv__',
+ '__trunc__',
+ '__warningregistry__',
+ '__weakref__',
+ '__xor__',
+ '_abc_impl',
+ '_blksize',
+ '_dealloc_warn',
+ '_finalizing',
+ '_find_and_load',
+ '_fix_up_module',
+ '_get_sourcefile',
+ '_handle_fromlist',
+ '_initializing',
+ '_is_text_encoding',
+ '_lock_unlock_module',
+ '_showwarnmsg',
+ '_shutdown',
+ '_slotnames',
+ '_strptime_time',
+ '_uninitialized_submodules',
+ '_warn_unawaited_coroutine',
+ '_xoptions',
+ 'add',
+ 'append',
+ 'big',
+ 'buffer',
+ 'builtins',
+ 'clear',
+ 'close',
+ 'code',
+ 'copy',
+ 'copyreg',
+ 'decode',
+ 'default',
+ 'defaultaction',
+ 'difference_update',
+ 'dispatch_table',
+ 'displayhook',
+ 'enable',
+ 'encoding',
+ 'end_lineno',
+ 'end_offset',
+ 'errors',
+ 'excepthook',
+ 'extend',
+ 'filename',
+ 'fileno',
+ 'fillvalue',
+ 'filters',
+ 'find_class',
+ 'flush',
+ 'get',
+ 'get_source',
+ 'getattr',
+ 'ignore',
+ 'importlib',
+ 'intersection',
+ 'isatty',
+ 'items',
+ 'iter',
+ 'keys',
+ 'last_traceback',
+ 'last_type',
+ 'last_value',
+ 'latin1',
+ 'lineno',
+ 'little',
+ 'match',
+ 'metaclass',
+ 'mode',
+ 'modules',
+ 'mro',
+ 'msg',
+ 'n_fields',
+ 'n_sequence_fields',
+ 'n_unnamed_fields',
+ 'name',
+ 'obj',
+ 'offset',
+ 'onceregistry',
+ 'open',
+ 'parent',
+ 'partial',
+ 'path',
+ 'peek',
+ 'persistent_id',
+ 'persistent_load',
+ 'print_file_and_line',
+ 'ps1',
+ 'ps2',
+ 'raw',
+ 'read',
+ 'read1',
+ 'readable',
+ 'readall',
+ 'readinto',
+ 'readinto1',
+ 'readline',
+ 'reducer_override',
+ 'reload',
+ 'replace',
+ 'reset',
+ 'return',
+ 'reversed',
+ 'seek',
+ 'seekable',
+ 'send',
+ 'setstate',
+ 'sort',
+ 'stderr',
+ 'stdin',
+ 'stdout',
+ 'strict',
+ 'symmetric_difference_update',
+ 'tell',
+ 'text',
+ 'threading',
+ 'throw',
+ 'unraisablehook',
+ 'values',
+ 'version',
+ 'warnings',
+ 'warnoptions',
+ 'writable',
+ 'write',
+ 'zipimporter',
+]
+
+
#######################################
# helpers
END = '/* End auto-generated code */'
+def generate_global_strings():
+ filename = os.path.join(INTERNAL, 'pycore_global_strings.h')
+
+ # Read the non-generated part of the file.
+ with open(filename) as infile:
+ before = ''.join(iter_to_marker(infile, START))[:-1]
+ for _ in iter_to_marker(infile, END):
+ pass
+ after = infile.read()[:-1]
+
+ # Generate the file.
+ with open(filename, 'w', encoding='utf-8') as outfile:
+ printer = Printer(outfile)
+ printer.write(before)
+ printer.write(START)
+ with printer.block('struct _Py_global_strings', ';'):
+ with printer.block('struct', ' literals;'):
+ for name, literal in STRING_LITERALS.items():
+ if literal is None:
+ outfile.write('\n')
+ printer.write(f'// {name}')
+ else:
+ printer.write(f'STRUCT_FOR_STR({name}, "{literal}")')
+ outfile.write('\n')
+ with printer.block('struct', ' identifiers;'):
+ for name in sorted(IDENTIFIERS):
+ assert name.isidentifier(), name
+ printer.write(f'STRUCT_FOR_ID({name})')
+ printer.write(END)
+ printer.write(after)
+
+
def generate_runtime_init():
# First get some info from the declarations.
nsmallposints = None
with printer.block('.bytes_characters =', ','):
for i in range(256):
printer.write(f'_PyBytes_CHAR_INIT({i}),')
+ printer.write('')
+ # Global strings.
+ with printer.block('.strings =', ','):
+ with printer.block('.literals =', ','):
+ for name, literal in STRING_LITERALS.items():
+ if literal is None:
+ printer.write('')
+ else:
+ printer.write(f'INIT_STR({name}, "{literal}"),')
+ with printer.block('.identifiers =', ','):
+ for name in sorted(IDENTIFIERS):
+ assert name.isidentifier(), name
+ printer.write(f'INIT_ID({name}),')
printer.write(END)
printer.write(after)
+#######################################
+# checks
+
+def err(msg):
+ print(msg, file=sys.stderr)
+
+
+GETTER_RE = re.compile(r'''
+ ^
+ .*?
+ (?:
+ (?:
+ _Py_ID
+ [(]
+ ( \w+ ) # <identifier>
+ [)]
+ )
+ |
+ (?:
+ _Py_STR
+ [(]
+ ( \w+ ) # <literal>
+ [)]
+ )
+ )
+''', re.VERBOSE)
+TYPESLOTS_RE = re.compile(r'''
+ ^
+ .*?
+ (?:
+ (?:
+ SLOT0 [(] .*?, \s*
+ ( \w+ ) # <slot0>
+ [)]
+ )
+ |
+ (?:
+ SLOT1 [(] .*?, \s*
+ ( \w+ ) # <slot1>
+ , .* [)]
+ )
+ |
+ (?:
+ SLOT1BIN [(] .*?, .*?, \s*
+ ( \w+ ) # <slot1bin>
+ , \s*
+ ( \w+ ) # <reverse>
+ [)]
+ )
+ |
+ (?:
+ SLOT1BINFULL [(] .*?, .*?, .*?, \s*
+ ( \w+ ) # <slot1binfull>
+ , \s*
+ ( \w+ ) # <fullreverse>
+ [)]
+ )
+ |
+ ( SLOT \d .* [^)] $ ) # <wrapped>
+ )
+''', re.VERBOSE)
+
+def check_orphan_strings():
+ literals = set(n for n, s in STRING_LITERALS.items() if s)
+ identifiers = set(IDENTIFIERS)
+ files = glob.iglob(os.path.join(ROOT, '**', '*.[ch]'), recursive=True)
+ for i, filename in enumerate(files, start=1):
+ print('.', end='')
+ if i % 5 == 0:
+ print(' ', end='')
+ if i % 20 == 0:
+ print()
+ if i % 100 == 0:
+ print()
+ with open(filename) as infile:
+ wrapped = None
+ for line in infile:
+ identifier = literal = reverse = None
+
+ line = line.splitlines()[0]
+ if wrapped:
+ line = f'{wrapped.rstrip()} {line}'
+ wrapped = None
+
+ if os.path.basename(filename) == '_warnings.c':
+ m = re.match(r'^.* = GET_WARNINGS_ATTR[(][^,]*, (\w+),', line)
+ if m:
+ identifier, = m.groups()
+ elif os.path.basename(filename) == 'typeobject.c':
+ m = TYPESLOTS_RE.match(line)
+ if m:
+ (slot0,
+ slot1,
+ slot1bin, reverse,
+ slot1binfull, fullreverse,
+ wrapped,
+ ) = m.groups()
+ identifier = slot0 or slot1 or slot1bin or slot1binfull
+ reverse = reverse or fullreverse
+
+ if not identifier and not literal:
+ m = GETTER_RE.match(line)
+ if not m:
+ continue
+ identifier, literal = m.groups()
+
+ if literal:
+ if literals and literal in literals:
+ literals.remove(literal)
+ if identifier:
+ if identifiers and identifier in identifiers:
+ identifiers.remove(identifier)
+ if reverse:
+ if identifiers and reverse in identifiers:
+ identifiers.remove(reverse)
+ if not literals and not identifiers:
+ break
+ else:
+ continue
+ break
+ if i % 20:
+ print()
+ if not literals and not identifiers:
+ return
+ print('ERROR:', file=sys.stderr)
+ if literals:
+ err(' unused global string literals:')
+ for name in sorted(literals):
+ err(f' {name}')
+ if identifiers:
+ if literals:
+ print()
+ err(' unused global identifiers:')
+ for name in sorted(identifiers):
+ err(f' {name}')
+
+
#######################################
# the script
-def main() -> None:
+def main(*, check=False) -> None:
+ generate_global_strings()
generate_runtime_init()
+ if check:
+ check_orphan_strings()
+
if __name__ == '__main__':
- argv = sys.argv[1:]
- if argv:
- sys.exit(f'ERROR: got unexpected args {argv}')
- main()
+ import argparse
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--check', action='store_true')
+ args = parser.parse_args()
+ main(**vars(args))