mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
bpo-46541: Replace core use of _Py_IDENTIFIER() with statically initialized global objects. (gh-30928)
We're no longer using _Py_IDENTIFIER() (or _Py_static_string()) in any core CPython code. It is still used in a number of non-builtin stdlib modules. The replacement is: PyUnicodeObject (not pointer) fields under _PyRuntimeState, statically initialized as part of _PyRuntime. A new _Py_GET_GLOBAL_IDENTIFIER() macro facilitates lookup of the fields (along with _Py_GET_GLOBAL_STRING() for non-identifier strings). https://bugs.python.org/issue46541#msg411799 explains the rationale for this change. The core of the change is in: * (new) Include/internal/pycore_global_strings.h - the declarations for the global strings, along with the macros * Include/internal/pycore_runtime_init.h - added the static initializers for the global strings * Include/internal/pycore_global_objects.h - where the struct in pycore_global_strings.h is hooked into _PyRuntimeState * Tools/scripts/generate_global_objects.py - added generation of the global string declarations and static initializers I've also added a --check flag to generate_global_objects.py (along with make check-global-objects) to check for unused global strings. That check is added to the PR CI config. The remainder of this change updates the core code to use _Py_GET_GLOBAL_IDENTIFIER() instead of _Py_IDENTIFIER() and the related _Py*Id functions (likewise for _Py_GET_GLOBAL_STRING() instead of _Py_static_string()). This includes adding a few functions where there wasn't already an alternative to _Py*Id(), replacing the _Py_Identifier * parameter with PyObject *. The following are not changed (yet): * stop using _Py_IDENTIFIER() in the stdlib modules * (maybe) get rid of _Py_IDENTIFIER(), etc. entirely -- this may not be doable as at least one package on PyPI using this (private) API * (maybe) intern the strings during runtime init https://bugs.python.org/issue46541
This commit is contained in:
parent
c018d3037b
commit
81c72044a1
108 changed files with 2282 additions and 1573 deletions
|
@ -92,7 +92,6 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
|
|||
{
|
||||
PyObject *hint, *result;
|
||||
Py_ssize_t res;
|
||||
_Py_IDENTIFIER(__length_hint__);
|
||||
if (_PyObject_HasLen(o)) {
|
||||
res = PyObject_Length(o);
|
||||
if (res < 0) {
|
||||
|
@ -107,7 +106,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
|
|||
return res;
|
||||
}
|
||||
}
|
||||
hint = _PyObject_LookupSpecial(o, &PyId___length_hint__);
|
||||
hint = _PyObject_LookupSpecial(o, &_Py_ID(__length_hint__));
|
||||
if (hint == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
return -1;
|
||||
|
@ -177,14 +176,13 @@ PyObject_GetItem(PyObject *o, PyObject *key)
|
|||
|
||||
if (PyType_Check(o)) {
|
||||
PyObject *meth, *result;
|
||||
_Py_IDENTIFIER(__class_getitem__);
|
||||
|
||||
// Special case type[int], but disallow other types so str[int] fails
|
||||
if ((PyTypeObject*)o == &PyType_Type) {
|
||||
return Py_GenericAlias(o, key);
|
||||
}
|
||||
|
||||
if (_PyObject_LookupAttrId(o, &PyId___class_getitem__, &meth) < 0) {
|
||||
if (_PyObject_LookupAttr(o, &_Py_ID(__class_getitem__), &meth) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (meth) {
|
||||
|
@ -770,7 +768,6 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
|
|||
PyObject *meth;
|
||||
PyObject *empty = NULL;
|
||||
PyObject *result = NULL;
|
||||
_Py_IDENTIFIER(__format__);
|
||||
|
||||
if (format_spec != NULL && !PyUnicode_Check(format_spec)) {
|
||||
PyErr_Format(PyExc_SystemError,
|
||||
|
@ -797,7 +794,7 @@ PyObject_Format(PyObject *obj, PyObject *format_spec)
|
|||
}
|
||||
|
||||
/* Find the (unbound!) __format__ method */
|
||||
meth = _PyObject_LookupSpecial(obj, &PyId___format__);
|
||||
meth = _PyObject_LookupSpecial(obj, &_Py_ID(__format__));
|
||||
if (meth == NULL) {
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
if (!_PyErr_Occurred(tstate)) {
|
||||
|
@ -1520,7 +1517,6 @@ PyNumber_Long(PyObject *o)
|
|||
PyNumberMethods *m;
|
||||
PyObject *trunc_func;
|
||||
Py_buffer view;
|
||||
_Py_IDENTIFIER(__trunc__);
|
||||
|
||||
if (o == NULL) {
|
||||
return null_error();
|
||||
|
@ -1562,7 +1558,7 @@ PyNumber_Long(PyObject *o)
|
|||
if (m && m->nb_index) {
|
||||
return PyNumber_Index(o);
|
||||
}
|
||||
trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__);
|
||||
trunc_func = _PyObject_LookupSpecial(o, &_Py_ID(__trunc__));
|
||||
if (trunc_func) {
|
||||
if (PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"The delegation of int() to __trunc__ is deprecated.", 1)) {
|
||||
|
@ -2406,12 +2402,12 @@ PyMapping_HasKey(PyObject *o, PyObject *key)
|
|||
a helper for PyMapping_Keys(), PyMapping_Items() and PyMapping_Values().
|
||||
*/
|
||||
static PyObject *
|
||||
method_output_as_list(PyObject *o, _Py_Identifier *meth_id)
|
||||
method_output_as_list(PyObject *o, PyObject *meth)
|
||||
{
|
||||
PyObject *it, *result, *meth_output;
|
||||
|
||||
assert(o != NULL);
|
||||
meth_output = _PyObject_CallMethodIdNoArgs(o, meth_id);
|
||||
meth_output = PyObject_CallMethodNoArgs(o, meth);
|
||||
if (meth_output == NULL || PyList_CheckExact(meth_output)) {
|
||||
return meth_output;
|
||||
}
|
||||
|
@ -2422,7 +2418,7 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id)
|
|||
_PyErr_Format(tstate, PyExc_TypeError,
|
||||
"%.200s.%U() returned a non-iterable (type %.200s)",
|
||||
Py_TYPE(o)->tp_name,
|
||||
_PyUnicode_FromId(meth_id),
|
||||
meth,
|
||||
Py_TYPE(meth_output)->tp_name);
|
||||
}
|
||||
Py_DECREF(meth_output);
|
||||
|
@ -2437,43 +2433,37 @@ method_output_as_list(PyObject *o, _Py_Identifier *meth_id)
|
|||
PyObject *
|
||||
PyMapping_Keys(PyObject *o)
|
||||
{
|
||||
_Py_IDENTIFIER(keys);
|
||||
|
||||
if (o == NULL) {
|
||||
return null_error();
|
||||
}
|
||||
if (PyDict_CheckExact(o)) {
|
||||
return PyDict_Keys(o);
|
||||
}
|
||||
return method_output_as_list(o, &PyId_keys);
|
||||
return method_output_as_list(o, &_Py_ID(keys));
|
||||
}
|
||||
|
||||
PyObject *
|
||||
PyMapping_Items(PyObject *o)
|
||||
{
|
||||
_Py_IDENTIFIER(items);
|
||||
|
||||
if (o == NULL) {
|
||||
return null_error();
|
||||
}
|
||||
if (PyDict_CheckExact(o)) {
|
||||
return PyDict_Items(o);
|
||||
}
|
||||
return method_output_as_list(o, &PyId_items);
|
||||
return method_output_as_list(o, &_Py_ID(items));
|
||||
}
|
||||
|
||||
PyObject *
|
||||
PyMapping_Values(PyObject *o)
|
||||
{
|
||||
_Py_IDENTIFIER(values);
|
||||
|
||||
if (o == NULL) {
|
||||
return null_error();
|
||||
}
|
||||
if (PyDict_CheckExact(o)) {
|
||||
return PyDict_Values(o);
|
||||
}
|
||||
return method_output_as_list(o, &PyId_values);
|
||||
return method_output_as_list(o, &_Py_ID(values));
|
||||
}
|
||||
|
||||
/* isinstance(), issubclass() */
|
||||
|
@ -2505,10 +2495,9 @@ PyMapping_Values(PyObject *o)
|
|||
static PyObject *
|
||||
abstract_get_bases(PyObject *cls)
|
||||
{
|
||||
_Py_IDENTIFIER(__bases__);
|
||||
PyObject *bases;
|
||||
|
||||
(void)_PyObject_LookupAttrId(cls, &PyId___bases__, &bases);
|
||||
(void)_PyObject_LookupAttr(cls, &_Py_ID(__bases__), &bases);
|
||||
if (bases != NULL && !PyTuple_Check(bases)) {
|
||||
Py_DECREF(bases);
|
||||
return NULL;
|
||||
|
@ -2589,11 +2578,10 @@ object_isinstance(PyObject *inst, PyObject *cls)
|
|||
{
|
||||
PyObject *icls;
|
||||
int retval;
|
||||
_Py_IDENTIFIER(__class__);
|
||||
if (PyType_Check(cls)) {
|
||||
retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
|
||||
if (retval == 0) {
|
||||
retval = _PyObject_LookupAttrId(inst, &PyId___class__, &icls);
|
||||
retval = _PyObject_LookupAttr(inst, &_Py_ID(__class__), &icls);
|
||||
if (icls != NULL) {
|
||||
if (icls != (PyObject *)(Py_TYPE(inst)) && PyType_Check(icls)) {
|
||||
retval = PyType_IsSubtype(
|
||||
|
@ -2611,7 +2599,7 @@ object_isinstance(PyObject *inst, PyObject *cls)
|
|||
if (!check_class(cls,
|
||||
"isinstance() arg 2 must be a type, a tuple of types, or a union"))
|
||||
return -1;
|
||||
retval = _PyObject_LookupAttrId(inst, &PyId___class__, &icls);
|
||||
retval = _PyObject_LookupAttr(inst, &_Py_ID(__class__), &icls);
|
||||
if (icls != NULL) {
|
||||
retval = abstract_issubclass(icls, cls);
|
||||
Py_DECREF(icls);
|
||||
|
@ -2624,8 +2612,6 @@ object_isinstance(PyObject *inst, PyObject *cls)
|
|||
static int
|
||||
object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls)
|
||||
{
|
||||
_Py_IDENTIFIER(__instancecheck__);
|
||||
|
||||
/* Quick test for an exact match */
|
||||
if (Py_IS_TYPE(inst, (PyTypeObject *)cls)) {
|
||||
return 1;
|
||||
|
@ -2656,7 +2642,7 @@ object_recursive_isinstance(PyThreadState *tstate, PyObject *inst, PyObject *cls
|
|||
return r;
|
||||
}
|
||||
|
||||
PyObject *checker = _PyObject_LookupSpecial(cls, &PyId___instancecheck__);
|
||||
PyObject *checker = _PyObject_LookupSpecial(cls, &_Py_ID(__instancecheck__));
|
||||
if (checker != NULL) {
|
||||
if (_Py_EnterRecursiveCall(tstate, " in __instancecheck__")) {
|
||||
Py_DECREF(checker);
|
||||
|
@ -2715,7 +2701,6 @@ recursive_issubclass(PyObject *derived, PyObject *cls)
|
|||
static int
|
||||
object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls)
|
||||
{
|
||||
_Py_IDENTIFIER(__subclasscheck__);
|
||||
PyObject *checker;
|
||||
|
||||
/* We know what type's __subclasscheck__ does. */
|
||||
|
@ -2744,7 +2729,7 @@ object_issubclass(PyThreadState *tstate, PyObject *derived, PyObject *cls)
|
|||
return r;
|
||||
}
|
||||
|
||||
checker = _PyObject_LookupSpecial(cls, &PyId___subclasscheck__);
|
||||
checker = _PyObject_LookupSpecial(cls, &_Py_ID(__subclasscheck__));
|
||||
if (checker != NULL) {
|
||||
int ok = -1;
|
||||
if (_Py_EnterRecursiveCall(tstate, " in __subclasscheck__")) {
|
||||
|
@ -2879,7 +2864,6 @@ PyIter_Next(PyObject *iter)
|
|||
PySendResult
|
||||
PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result)
|
||||
{
|
||||
_Py_IDENTIFIER(send);
|
||||
assert(arg != NULL);
|
||||
assert(result != NULL);
|
||||
if (Py_TYPE(iter)->tp_as_async && Py_TYPE(iter)->tp_as_async->am_send) {
|
||||
|
@ -2891,7 +2875,7 @@ PyIter_Send(PyObject *iter, PyObject *arg, PyObject **result)
|
|||
*result = Py_TYPE(iter)->tp_iternext(iter);
|
||||
}
|
||||
else {
|
||||
*result = _PyObject_CallMethodIdOneArg(iter, &PyId_send, arg);
|
||||
*result = PyObject_CallMethodOneArg(iter, &_Py_ID(send), arg);
|
||||
}
|
||||
if (*result != NULL) {
|
||||
return PYGEN_NEXT;
|
||||
|
|
|
@ -2112,10 +2112,9 @@ static PyObject *
|
|||
_common_reduce(PyByteArrayObject *self, int proto)
|
||||
{
|
||||
PyObject *dict;
|
||||
_Py_IDENTIFIER(__dict__);
|
||||
char *buf;
|
||||
|
||||
if (_PyObject_LookupAttrId((PyObject *)self, &PyId___dict__, &dict) < 0) {
|
||||
if (_PyObject_LookupAttr((PyObject *)self, &_Py_ID(__dict__), &dict) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (dict == NULL) {
|
||||
|
@ -2428,12 +2427,11 @@ PyDoc_STRVAR(length_hint_doc,
|
|||
static PyObject *
|
||||
bytearrayiter_reduce(bytesiterobject *it, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(iter);
|
||||
if (it->it_seq != NULL) {
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
|
||||
it->it_seq, it->it_index);
|
||||
} else {
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,6 @@ class bytes "PyBytesObject *" "&PyBytes_Type"
|
|||
|
||||
#include "clinic/bytesobject.c.h"
|
||||
|
||||
_Py_IDENTIFIER(__bytes__);
|
||||
|
||||
/* PyBytesObject_SIZE gives the basic size of a bytes object; any memory allocation
|
||||
for a bytes object of length n should request PyBytesObject_SIZE + n bytes.
|
||||
|
||||
|
@ -530,7 +528,7 @@ format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
|
|||
return v;
|
||||
}
|
||||
/* does it support __bytes__? */
|
||||
func = _PyObject_LookupSpecial(v, &PyId___bytes__);
|
||||
func = _PyObject_LookupSpecial(v, &_Py_ID(__bytes__));
|
||||
if (func != NULL) {
|
||||
result = _PyObject_CallNoArgs(func);
|
||||
Py_DECREF(func);
|
||||
|
@ -2582,7 +2580,7 @@ bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
|
|||
/* We'd like to call PyObject_Bytes here, but we need to check for an
|
||||
integer argument before deferring to PyBytes_FromObject, something
|
||||
PyObject_Bytes doesn't do. */
|
||||
else if ((func = _PyObject_LookupSpecial(x, &PyId___bytes__)) != NULL) {
|
||||
else if ((func = _PyObject_LookupSpecial(x, &_Py_ID(__bytes__))) != NULL) {
|
||||
bytes = _PyObject_CallNoArgs(func);
|
||||
Py_DECREF(func);
|
||||
if (bytes == NULL)
|
||||
|
@ -3122,12 +3120,11 @@ PyDoc_STRVAR(length_hint_doc,
|
|||
static PyObject *
|
||||
striter_reduce(striterobject *it, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(iter);
|
||||
if (it->it_seq != NULL) {
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
|
||||
it->it_seq, it->it_index);
|
||||
} else {
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -607,7 +607,6 @@ callmethod(PyThreadState *tstate, PyObject* callable, const char *format, va_lis
|
|||
return _PyObject_CallFunctionVa(tstate, callable, format, va, is_size_t);
|
||||
}
|
||||
|
||||
|
||||
PyObject *
|
||||
PyObject_CallMethod(PyObject *obj, const char *name, const char *format, ...)
|
||||
{
|
||||
|
@ -658,6 +657,30 @@ PyEval_CallMethod(PyObject *obj, const char *name, const char *format, ...)
|
|||
}
|
||||
|
||||
|
||||
PyObject *
|
||||
_PyObject_CallMethod(PyObject *obj, PyObject *name,
|
||||
const char *format, ...)
|
||||
{
|
||||
PyThreadState *tstate = _PyThreadState_GET();
|
||||
if (obj == NULL || name == NULL) {
|
||||
return null_error(tstate);
|
||||
}
|
||||
|
||||
PyObject *callable = PyObject_GetAttr(obj, name);
|
||||
if (callable == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
PyObject *retval = callmethod(tstate, callable, format, va, 1);
|
||||
va_end(va);
|
||||
|
||||
Py_DECREF(callable);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
PyObject *
|
||||
_PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name,
|
||||
const char *format, ...)
|
||||
|
@ -682,6 +705,17 @@ _PyObject_CallMethodId(PyObject *obj, _Py_Identifier *name,
|
|||
}
|
||||
|
||||
|
||||
PyObject * _PyObject_CallMethodFormat(PyThreadState *tstate, PyObject *callable,
|
||||
const char *format, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
PyObject *retval = callmethod(tstate, callable, format, va, 0);
|
||||
va_end(va);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
PyObject *
|
||||
_PyObject_CallMethod_SizeT(PyObject *obj, const char *name,
|
||||
const char *format, ...)
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
|
||||
#define TP_DESCR_GET(t) ((t)->tp_descr_get)
|
||||
|
||||
_Py_IDENTIFIER(__name__);
|
||||
_Py_IDENTIFIER(__qualname__);
|
||||
|
||||
PyObject *
|
||||
PyMethod_Function(PyObject *im)
|
||||
|
@ -123,14 +121,13 @@ method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored))
|
|||
PyObject *self = PyMethod_GET_SELF(im);
|
||||
PyObject *func = PyMethod_GET_FUNCTION(im);
|
||||
PyObject *funcname;
|
||||
_Py_IDENTIFIER(getattr);
|
||||
|
||||
funcname = _PyObject_GetAttrId(func, &PyId___name__);
|
||||
funcname = PyObject_GetAttr(func, &_Py_ID(__name__));
|
||||
if (funcname == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return Py_BuildValue("N(ON)", _PyEval_GetBuiltinId(&PyId_getattr),
|
||||
self, funcname);
|
||||
return Py_BuildValue(
|
||||
"N(ON)", _PyEval_GetBuiltin(&_Py_ID(getattr)), self, funcname);
|
||||
}
|
||||
|
||||
static PyMethodDef method_methods[] = {
|
||||
|
@ -280,9 +277,9 @@ method_repr(PyMethodObject *a)
|
|||
PyObject *funcname, *result;
|
||||
const char *defname = "?";
|
||||
|
||||
if (_PyObject_LookupAttrId(func, &PyId___qualname__, &funcname) < 0 ||
|
||||
if (_PyObject_LookupAttr(func, &_Py_ID(__qualname__), &funcname) < 0 ||
|
||||
(funcname == NULL &&
|
||||
_PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0))
|
||||
_PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
@ -515,7 +512,7 @@ instancemethod_repr(PyObject *self)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (_PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0) {
|
||||
if (_PyObject_LookupAttr(func, &_Py_ID(__name__), &funcname) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (funcname != NULL && !PyUnicode_Check(funcname)) {
|
||||
|
|
|
@ -281,9 +281,8 @@ static PyObject *
|
|||
try_complex_special_method(PyObject *op)
|
||||
{
|
||||
PyObject *f;
|
||||
_Py_IDENTIFIER(__complex__);
|
||||
|
||||
f = _PyObject_LookupSpecial(op, &PyId___complex__);
|
||||
f = _PyObject_LookupSpecial(op, &_Py_ID(__complex__));
|
||||
if (f) {
|
||||
PyObject *res = _PyObject_CallNoArgs(f);
|
||||
Py_DECREF(f);
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
#include "pycore_tuple.h" // _PyTuple_ITEMS()
|
||||
#include "structmember.h" // PyMemberDef
|
||||
|
||||
_Py_IDENTIFIER(getattr);
|
||||
|
||||
/*[clinic input]
|
||||
class mappingproxy "mappingproxyobject *" "&PyDictProxy_Type"
|
||||
class property "propertyobject *" "&PyProperty_Type"
|
||||
|
@ -571,7 +569,6 @@ static PyObject *
|
|||
calculate_qualname(PyDescrObject *descr)
|
||||
{
|
||||
PyObject *type_qualname, *res;
|
||||
_Py_IDENTIFIER(__qualname__);
|
||||
|
||||
if (descr->d_name == NULL || !PyUnicode_Check(descr->d_name)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
|
@ -579,8 +576,8 @@ calculate_qualname(PyDescrObject *descr)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
type_qualname = _PyObject_GetAttrId((PyObject *)descr->d_type,
|
||||
&PyId___qualname__);
|
||||
type_qualname = PyObject_GetAttr(
|
||||
(PyObject *)descr->d_type, &_Py_ID(__qualname__));
|
||||
if (type_qualname == NULL)
|
||||
return NULL;
|
||||
|
||||
|
@ -608,7 +605,7 @@ descr_get_qualname(PyDescrObject *descr, void *Py_UNUSED(ignored))
|
|||
static PyObject *
|
||||
descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr),
|
||||
return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(&_Py_ID(getattr)),
|
||||
PyDescr_TYPE(descr), PyDescr_NAME(descr));
|
||||
}
|
||||
|
||||
|
@ -1086,8 +1083,7 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
_Py_IDENTIFIER(get);
|
||||
return _PyObject_VectorcallMethodId(&PyId_get, newargs,
|
||||
return _PyObject_VectorcallMethod(&_Py_ID(get), newargs,
|
||||
3 | PY_VECTORCALL_ARGUMENTS_OFFSET,
|
||||
NULL);
|
||||
}
|
||||
|
@ -1095,36 +1091,31 @@ mappingproxy_get(mappingproxyobject *pp, PyObject *const *args, Py_ssize_t nargs
|
|||
static PyObject *
|
||||
mappingproxy_keys(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(keys);
|
||||
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_keys);
|
||||
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(keys));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
mappingproxy_values(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(values);
|
||||
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_values);
|
||||
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(values));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
mappingproxy_items(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(items);
|
||||
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_items);
|
||||
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(items));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
mappingproxy_copy(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(copy);
|
||||
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId_copy);
|
||||
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(copy));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
mappingproxy_reversed(mappingproxyobject *pp, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(__reversed__);
|
||||
return _PyObject_CallMethodIdNoArgs(pp->mapping, &PyId___reversed__);
|
||||
return PyObject_CallMethodNoArgs(pp->mapping, &_Py_ID(__reversed__));
|
||||
}
|
||||
|
||||
/* WARNING: mappingproxy methods must not give access
|
||||
|
@ -1321,7 +1312,7 @@ wrapper_repr(wrapperobject *wp)
|
|||
static PyObject *
|
||||
wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr),
|
||||
return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(&_Py_ID(getattr)),
|
||||
wp->self, PyDescr_NAME(wp->descr));
|
||||
}
|
||||
|
||||
|
@ -1756,9 +1747,8 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
|
|||
|
||||
/* if no docstring given and the getter has one, use that one */
|
||||
if ((doc == NULL || doc == Py_None) && fget != NULL) {
|
||||
_Py_IDENTIFIER(__doc__);
|
||||
PyObject *get_doc;
|
||||
int rc = _PyObject_LookupAttrId(fget, &PyId___doc__, &get_doc);
|
||||
int rc = _PyObject_LookupAttr(fget, &_Py_ID(__doc__), &get_doc);
|
||||
if (rc <= 0) {
|
||||
return rc;
|
||||
}
|
||||
|
@ -1770,7 +1760,8 @@ property_init_impl(propertyobject *self, PyObject *fget, PyObject *fset,
|
|||
in dict of the subclass instance instead,
|
||||
otherwise it gets shadowed by __doc__ in the
|
||||
class's dict. */
|
||||
int err = _PyObject_SetAttrId((PyObject *)self, &PyId___doc__, get_doc);
|
||||
int err = PyObject_SetAttr(
|
||||
(PyObject *)self, &_Py_ID(__doc__), get_doc);
|
||||
Py_DECREF(get_doc);
|
||||
if (err < 0)
|
||||
return -1;
|
||||
|
|
|
@ -1484,6 +1484,17 @@ PyDict_GetItemWithError(PyObject *op, PyObject *key)
|
|||
return value;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_PyDict_GetItemWithError(PyObject *dp, PyObject *kv)
|
||||
{
|
||||
assert(PyUnicode_CheckExact(kv));
|
||||
Py_hash_t hash = kv->ob_type->tp_hash(kv);
|
||||
if (hash == -1) {
|
||||
return NULL;
|
||||
}
|
||||
return _PyDict_GetItem_KnownHash(dp, kv, hash);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
_PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key)
|
||||
{
|
||||
|
@ -2166,8 +2177,8 @@ dict_subscript(PyDictObject *mp, PyObject *key)
|
|||
if (!PyDict_CheckExact(mp)) {
|
||||
/* Look up __missing__ method if we're a subclass. */
|
||||
PyObject *missing, *res;
|
||||
_Py_IDENTIFIER(__missing__);
|
||||
missing = _PyObject_LookupSpecial((PyObject *)mp, &PyId___missing__);
|
||||
missing = _PyObject_LookupSpecial(
|
||||
(PyObject *)mp, &_Py_ID(__missing__));
|
||||
if (missing != NULL) {
|
||||
res = PyObject_CallOneArg(missing, key);
|
||||
Py_DECREF(missing);
|
||||
|
@ -2369,9 +2380,8 @@ dict_update_arg(PyObject *self, PyObject *arg)
|
|||
if (PyDict_CheckExact(arg)) {
|
||||
return PyDict_Merge(self, arg, 1);
|
||||
}
|
||||
_Py_IDENTIFIER(keys);
|
||||
PyObject *func;
|
||||
if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) {
|
||||
if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (func != NULL) {
|
||||
|
@ -4128,7 +4138,6 @@ dict___reversed___impl(PyDictObject *self)
|
|||
static PyObject *
|
||||
dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(iter);
|
||||
/* copy the iterator state */
|
||||
dictiterobject tmp = *di;
|
||||
Py_XINCREF(tmp.di_dict);
|
||||
|
@ -4138,7 +4147,7 @@ dictiter_reduce(dictiterobject *di, PyObject *Py_UNUSED(ignored))
|
|||
if (list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list);
|
||||
}
|
||||
|
||||
PyTypeObject PyDictRevIterItem_Type = {
|
||||
|
@ -4408,9 +4417,8 @@ dictviews_sub(PyObject *self, PyObject *other)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
_Py_IDENTIFIER(difference_update);
|
||||
PyObject *tmp = _PyObject_CallMethodIdOneArg(
|
||||
result, &PyId_difference_update, other);
|
||||
PyObject *tmp = PyObject_CallMethodOneArg(
|
||||
result, &_Py_ID(difference_update), other);
|
||||
if (tmp == NULL) {
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
|
@ -4446,8 +4454,8 @@ _PyDictView_Intersect(PyObject* self, PyObject *other)
|
|||
/* if other is a set and self is smaller than other,
|
||||
reuse set intersection logic */
|
||||
if (PySet_CheckExact(other) && len_self <= PyObject_Size(other)) {
|
||||
_Py_IDENTIFIER(intersection);
|
||||
return _PyObject_CallMethodIdObjArgs(other, &PyId_intersection, self, NULL);
|
||||
return PyObject_CallMethodObjArgs(
|
||||
other, &_Py_ID(intersection), self, NULL);
|
||||
}
|
||||
|
||||
/* if other is another dict view, and it is bigger than self,
|
||||
|
@ -4587,9 +4595,8 @@ dictitems_xor(PyObject *self, PyObject *other)
|
|||
}
|
||||
key = val1 = val2 = NULL;
|
||||
|
||||
_Py_IDENTIFIER(items);
|
||||
PyObject *remaining_pairs = _PyObject_CallMethodIdNoArgs(temp_dict,
|
||||
&PyId_items);
|
||||
PyObject *remaining_pairs = PyObject_CallMethodNoArgs(
|
||||
temp_dict, &_Py_ID(items));
|
||||
if (remaining_pairs == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
@ -4621,9 +4628,8 @@ dictviews_xor(PyObject* self, PyObject *other)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
_Py_IDENTIFIER(symmetric_difference_update);
|
||||
PyObject *tmp = _PyObject_CallMethodIdOneArg(
|
||||
result, &PyId_symmetric_difference_update, other);
|
||||
PyObject *tmp = PyObject_CallMethodOneArg(
|
||||
result, &_Py_ID(symmetric_difference_update), other);
|
||||
if (tmp == NULL) {
|
||||
Py_DECREF(result);
|
||||
return NULL;
|
||||
|
|
|
@ -356,9 +356,8 @@ reversed_new_impl(PyTypeObject *type, PyObject *seq)
|
|||
Py_ssize_t n;
|
||||
PyObject *reversed_meth;
|
||||
reversedobject *ro;
|
||||
_Py_IDENTIFIER(__reversed__);
|
||||
|
||||
reversed_meth = _PyObject_LookupSpecial(seq, &PyId___reversed__);
|
||||
reversed_meth = _PyObject_LookupSpecial(seq, &_Py_ID(__reversed__));
|
||||
if (reversed_meth == Py_None) {
|
||||
Py_DECREF(reversed_meth);
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
|
|
@ -1499,16 +1499,14 @@ ImportError_getstate(PyImportErrorObject *self)
|
|||
{
|
||||
PyObject *dict = ((PyBaseExceptionObject *)self)->dict;
|
||||
if (self->name || self->path) {
|
||||
_Py_IDENTIFIER(name);
|
||||
_Py_IDENTIFIER(path);
|
||||
dict = dict ? PyDict_Copy(dict) : PyDict_New();
|
||||
if (dict == NULL)
|
||||
return NULL;
|
||||
if (self->name && _PyDict_SetItemId(dict, &PyId_name, self->name) < 0) {
|
||||
if (self->name && PyDict_SetItem(dict, &_Py_ID(name), self->name) < 0) {
|
||||
Py_DECREF(dict);
|
||||
return NULL;
|
||||
}
|
||||
if (self->path && _PyDict_SetItemId(dict, &PyId_path, self->path) < 0) {
|
||||
if (self->path && PyDict_SetItem(dict, &_Py_ID(path), self->path) < 0) {
|
||||
Py_DECREF(dict);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
_Py_IDENTIFIER(open);
|
||||
|
||||
/* External C interface */
|
||||
|
||||
PyObject *
|
||||
|
@ -40,9 +38,9 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c
|
|||
io = PyImport_ImportModule("_io");
|
||||
if (io == NULL)
|
||||
return NULL;
|
||||
stream = _PyObject_CallMethodId(io, &PyId_open, "isisssO", fd, mode,
|
||||
buffering, encoding, errors,
|
||||
newline, closefd ? Py_True : Py_False);
|
||||
stream = _PyObject_CallMethod(io, &_Py_ID(open), "isisssO", fd, mode,
|
||||
buffering, encoding, errors,
|
||||
newline, closefd ? Py_True : Py_False);
|
||||
Py_DECREF(io);
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
|
@ -54,7 +52,6 @@ PyFile_FromFd(int fd, const char *name, const char *mode, int buffering, const c
|
|||
PyObject *
|
||||
PyFile_GetLine(PyObject *f, int n)
|
||||
{
|
||||
_Py_IDENTIFIER(readline);
|
||||
PyObject *result;
|
||||
|
||||
if (f == NULL) {
|
||||
|
@ -63,10 +60,10 @@ PyFile_GetLine(PyObject *f, int n)
|
|||
}
|
||||
|
||||
if (n <= 0) {
|
||||
result = _PyObject_CallMethodIdNoArgs(f, &PyId_readline);
|
||||
result = PyObject_CallMethodNoArgs(f, &_Py_ID(readline));
|
||||
}
|
||||
else {
|
||||
result = _PyObject_CallMethodId(f, &PyId_readline, "i", n);
|
||||
result = _PyObject_CallMethod(f, &_Py_ID(readline), "i", n);
|
||||
}
|
||||
if (result != NULL && !PyBytes_Check(result) &&
|
||||
!PyUnicode_Check(result)) {
|
||||
|
@ -120,13 +117,12 @@ int
|
|||
PyFile_WriteObject(PyObject *v, PyObject *f, int flags)
|
||||
{
|
||||
PyObject *writer, *value, *result;
|
||||
_Py_IDENTIFIER(write);
|
||||
|
||||
if (f == NULL) {
|
||||
PyErr_SetString(PyExc_TypeError, "writeobject with NULL file");
|
||||
return -1;
|
||||
}
|
||||
writer = _PyObject_GetAttrId(f, &PyId_write);
|
||||
writer = PyObject_GetAttr(f, &_Py_ID(write));
|
||||
if (writer == NULL)
|
||||
return -1;
|
||||
if (flags & Py_PRINT_RAW) {
|
||||
|
@ -182,12 +178,11 @@ PyObject_AsFileDescriptor(PyObject *o)
|
|||
{
|
||||
int fd;
|
||||
PyObject *meth;
|
||||
_Py_IDENTIFIER(fileno);
|
||||
|
||||
if (PyLong_Check(o)) {
|
||||
fd = _PyLong_AsInt(o);
|
||||
}
|
||||
else if (_PyObject_LookupAttrId(o, &PyId_fileno, &meth) < 0) {
|
||||
else if (_PyObject_LookupAttr(o, &_Py_ID(fileno), &meth) < 0) {
|
||||
return -1;
|
||||
}
|
||||
else if (meth != NULL) {
|
||||
|
@ -509,8 +504,7 @@ PyFile_OpenCodeObject(PyObject *path)
|
|||
} else {
|
||||
iomod = PyImport_ImportModule("_io");
|
||||
if (iomod) {
|
||||
f = _PyObject_CallMethodId(iomod, &PyId_open, "Os",
|
||||
path, "rb");
|
||||
f = _PyObject_CallMethod(iomod, &_Py_ID(open), "Os", path, "rb");
|
||||
Py_DECREF(iomod);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -770,8 +770,6 @@ PyTypeObject PyFrame_Type = {
|
|||
0, /* tp_dict */
|
||||
};
|
||||
|
||||
_Py_IDENTIFIER(__builtins__);
|
||||
|
||||
static void
|
||||
init_frame(InterpreterFrame *frame, PyFunctionObject *func, PyObject *locals)
|
||||
{
|
||||
|
@ -1074,7 +1072,7 @@ PyFrame_GetBack(PyFrameObject *frame)
|
|||
PyObject*
|
||||
_PyEval_BuiltinsFromGlobals(PyThreadState *tstate, PyObject *globals)
|
||||
{
|
||||
PyObject *builtins = _PyDict_GetItemIdWithError(globals, &PyId___builtins__);
|
||||
PyObject *builtins = PyDict_GetItemWithError(globals, &_Py_ID(__builtins__));
|
||||
if (builtins) {
|
||||
if (PyModule_Check(builtins)) {
|
||||
builtins = _PyModule_GetDict(builtins);
|
||||
|
|
|
@ -79,8 +79,7 @@ PyFunction_NewWithQualName(PyObject *code, PyObject *globals, PyObject *qualname
|
|||
Py_INCREF(doc);
|
||||
|
||||
// __module__: Use globals['__name__'] if it exists, or NULL.
|
||||
_Py_IDENTIFIER(__name__);
|
||||
PyObject *module = _PyDict_GetItemIdWithError(globals, &PyId___name__);
|
||||
PyObject *module = PyDict_GetItemWithError(globals, &_Py_ID(__name__));
|
||||
PyObject *builtins = NULL;
|
||||
if (module == NULL && _PyErr_Occurred(tstate)) {
|
||||
goto error;
|
||||
|
@ -808,12 +807,7 @@ functools_wraps(PyObject *wrapper, PyObject *wrapped)
|
|||
{
|
||||
#define COPY_ATTR(ATTR) \
|
||||
do { \
|
||||
_Py_IDENTIFIER(ATTR); \
|
||||
PyObject *attr = _PyUnicode_FromId(&PyId_ ## ATTR); \
|
||||
if (attr == NULL) { \
|
||||
return -1; \
|
||||
} \
|
||||
if (functools_copy_attr(wrapper, wrapped, attr) < 0) { \
|
||||
if (functools_copy_attr(wrapper, wrapped, &_Py_ID(ATTR)) < 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
} while (0) \
|
||||
|
|
|
@ -41,10 +41,6 @@ ga_traverse(PyObject *self, visitproc visit, void *arg)
|
|||
static int
|
||||
ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
||||
{
|
||||
_Py_IDENTIFIER(__module__);
|
||||
_Py_IDENTIFIER(__qualname__);
|
||||
_Py_IDENTIFIER(__origin__);
|
||||
_Py_IDENTIFIER(__args__);
|
||||
PyObject *qualname = NULL;
|
||||
PyObject *module = NULL;
|
||||
PyObject *r = NULL;
|
||||
|
@ -57,12 +53,12 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
|||
goto done;
|
||||
}
|
||||
|
||||
if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) {
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (tmp != NULL) {
|
||||
Py_DECREF(tmp);
|
||||
if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) {
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (tmp != NULL) {
|
||||
|
@ -72,13 +68,13 @@ ga_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
|||
}
|
||||
}
|
||||
|
||||
if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) {
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__qualname__), &qualname) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (qualname == NULL) {
|
||||
goto use_repr;
|
||||
}
|
||||
if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) {
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (module == NULL || module == Py_None) {
|
||||
|
@ -218,9 +214,9 @@ _Py_make_parameters(PyObject *args)
|
|||
iparam += tuple_add(parameters, iparam, t);
|
||||
}
|
||||
else {
|
||||
_Py_IDENTIFIER(__parameters__);
|
||||
PyObject *subparams;
|
||||
if (_PyObject_LookupAttrId(t, &PyId___parameters__, &subparams) < 0) {
|
||||
if (_PyObject_LookupAttr(t, &_Py_ID(__parameters__),
|
||||
&subparams) < 0) {
|
||||
Py_DECREF(parameters);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -260,9 +256,8 @@ _Py_make_parameters(PyObject *args)
|
|||
static PyObject *
|
||||
subs_tvars(PyObject *obj, PyObject *params, PyObject **argitems)
|
||||
{
|
||||
_Py_IDENTIFIER(__parameters__);
|
||||
PyObject *subparams;
|
||||
if (_PyObject_LookupAttrId(obj, &PyId___parameters__, &subparams) < 0) {
|
||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__parameters__), &subparams) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (subparams && PyTuple_Check(subparams) && PyTuple_GET_SIZE(subparams)) {
|
||||
|
|
|
@ -320,7 +320,6 @@ static int
|
|||
gen_close_iter(PyObject *yf)
|
||||
{
|
||||
PyObject *retval = NULL;
|
||||
_Py_IDENTIFIER(close);
|
||||
|
||||
if (PyGen_CheckExact(yf) || PyCoro_CheckExact(yf)) {
|
||||
retval = gen_close((PyGenObject *)yf, NULL);
|
||||
|
@ -329,7 +328,7 @@ gen_close_iter(PyObject *yf)
|
|||
}
|
||||
else {
|
||||
PyObject *meth;
|
||||
if (_PyObject_LookupAttrId(yf, &PyId_close, &meth) < 0) {
|
||||
if (_PyObject_LookupAttr(yf, &_Py_ID(close), &meth) < 0) {
|
||||
PyErr_WriteUnraisable(yf);
|
||||
}
|
||||
if (meth) {
|
||||
|
@ -417,7 +416,6 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
|
|||
PyObject *typ, PyObject *val, PyObject *tb)
|
||||
{
|
||||
PyObject *yf = _PyGen_yf(gen);
|
||||
_Py_IDENTIFIER(throw);
|
||||
|
||||
if (yf) {
|
||||
InterpreterFrame *frame = (InterpreterFrame *)gen->gi_iframe;
|
||||
|
@ -462,7 +460,7 @@ _gen_throw(PyGenObject *gen, int close_on_genexit,
|
|||
} else {
|
||||
/* `yf` is an iterator or a coroutine-like object. */
|
||||
PyObject *meth;
|
||||
if (_PyObject_LookupAttrId(yf, &PyId_throw, &meth) < 0) {
|
||||
if (_PyObject_LookupAttr(yf, &_Py_ID(throw), &meth) < 0) {
|
||||
Py_DECREF(yf);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ typedef struct {
|
|||
PyObject *it_seq; /* Set to NULL when iterator is exhausted */
|
||||
} seqiterobject;
|
||||
|
||||
_Py_IDENTIFIER(iter);
|
||||
|
||||
PyObject *
|
||||
PySeqIter_New(PyObject *seq)
|
||||
{
|
||||
|
@ -106,10 +104,10 @@ static PyObject *
|
|||
iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
if (it->it_seq != NULL)
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
|
||||
it->it_seq, it->it_index);
|
||||
else
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
|
||||
|
@ -245,10 +243,10 @@ static PyObject *
|
|||
calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
if (it->it_callable != NULL && it->it_sentinel != NULL)
|
||||
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
return Py_BuildValue("N(OO)", _PyEval_GetBuiltin(&_Py_ID(iter)),
|
||||
it->it_callable, it->it_sentinel);
|
||||
else
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
|
||||
}
|
||||
|
||||
static PyMethodDef calliter_methods[] = {
|
||||
|
|
|
@ -3505,25 +3505,25 @@ listreviter_setstate(listreviterobject *it, PyObject *state)
|
|||
static PyObject *
|
||||
listiter_reduce_general(void *_it, int forward)
|
||||
{
|
||||
_Py_IDENTIFIER(iter);
|
||||
_Py_IDENTIFIER(reversed);
|
||||
PyObject *list;
|
||||
|
||||
/* the objects are not the same, index is of different types! */
|
||||
if (forward) {
|
||||
listiterobject *it = (listiterobject *)_it;
|
||||
if (it->it_seq)
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
if (it->it_seq) {
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
|
||||
it->it_seq, it->it_index);
|
||||
}
|
||||
} else {
|
||||
listreviterobject *it = (listreviterobject *)_it;
|
||||
if (it->it_seq)
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_reversed),
|
||||
if (it->it_seq) {
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(reversed)),
|
||||
it->it_seq, it->it_index);
|
||||
}
|
||||
}
|
||||
/* empty iterator, create an empty list */
|
||||
list = PyList_New(0);
|
||||
if (list == NULL)
|
||||
return NULL;
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list);
|
||||
}
|
||||
|
|
|
@ -22,9 +22,6 @@ class int "PyObject *" "&PyLong_Type"
|
|||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ec0275e3422a36e3]*/
|
||||
|
||||
_Py_IDENTIFIER(little);
|
||||
_Py_IDENTIFIER(big);
|
||||
|
||||
/* Is this PyLong of size 1, 0 or -1? */
|
||||
#define IS_MEDIUM_VALUE(x) (((size_t)Py_SIZE(x)) + 1U < 3U)
|
||||
|
||||
|
@ -5775,9 +5772,9 @@ int_to_bytes_impl(PyObject *self, Py_ssize_t length, PyObject *byteorder,
|
|||
|
||||
if (byteorder == NULL)
|
||||
little_endian = 0;
|
||||
else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_little))
|
||||
else if (_PyUnicode_Equal(byteorder, &_Py_ID(little)))
|
||||
little_endian = 1;
|
||||
else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_big))
|
||||
else if (_PyUnicode_Equal(byteorder, &_Py_ID(big)))
|
||||
little_endian = 0;
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
@ -5837,9 +5834,9 @@ int_from_bytes_impl(PyTypeObject *type, PyObject *bytes_obj,
|
|||
|
||||
if (byteorder == NULL)
|
||||
little_endian = 0;
|
||||
else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_little))
|
||||
else if (_PyUnicode_Equal(byteorder, &_Py_ID(little)))
|
||||
little_endian = 1;
|
||||
else if (_PyUnicode_EqualToASCIIId(byteorder, &PyId_big))
|
||||
else if (_PyUnicode_Equal(byteorder, &_Py_ID(big)))
|
||||
little_endian = 0;
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
|
|
|
@ -179,12 +179,10 @@ meth_dealloc(PyCFunctionObject *m)
|
|||
static PyObject *
|
||||
meth_reduce(PyCFunctionObject *m, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(getattr);
|
||||
|
||||
if (m->m_self == NULL || PyModule_Check(m->m_self))
|
||||
return PyUnicode_FromString(m->m_ml->ml_name);
|
||||
|
||||
return Py_BuildValue("N(Os)", _PyEval_GetBuiltinId(&PyId_getattr),
|
||||
return Py_BuildValue("N(Os)", _PyEval_GetBuiltin(&_Py_ID(getattr)),
|
||||
m->m_self, m->m_ml->ml_name);
|
||||
}
|
||||
|
||||
|
@ -223,14 +221,13 @@ meth_get__qualname__(PyCFunctionObject *m, void *closure)
|
|||
Otherwise return type(m.__self__).__qualname__ + '.' + m.__name__
|
||||
(e.g. [].append.__qualname__ == 'list.append') */
|
||||
PyObject *type, *type_qualname, *res;
|
||||
_Py_IDENTIFIER(__qualname__);
|
||||
|
||||
if (m->m_self == NULL || PyModule_Check(m->m_self))
|
||||
return PyUnicode_FromString(m->m_ml->ml_name);
|
||||
|
||||
type = PyType_Check(m->m_self) ? m->m_self : (PyObject*)Py_TYPE(m->m_self);
|
||||
|
||||
type_qualname = _PyObject_GetAttrId(type, &PyId___qualname__);
|
||||
type_qualname = PyObject_GetAttr(type, &_Py_ID(__qualname__));
|
||||
if (type_qualname == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
|
@ -10,13 +10,6 @@
|
|||
|
||||
static Py_ssize_t max_module_number;
|
||||
|
||||
_Py_IDENTIFIER(__doc__);
|
||||
_Py_IDENTIFIER(__name__);
|
||||
_Py_IDENTIFIER(__spec__);
|
||||
_Py_IDENTIFIER(__dict__);
|
||||
_Py_IDENTIFIER(__dir__);
|
||||
_Py_IDENTIFIER(__annotations__);
|
||||
|
||||
static PyMemberDef module_members[] = {
|
||||
{"__dict__", T_OBJECT, offsetof(PyModuleObject, md_dict), READONLY},
|
||||
{0}
|
||||
|
@ -61,22 +54,19 @@ static int
|
|||
module_init_dict(PyModuleObject *mod, PyObject *md_dict,
|
||||
PyObject *name, PyObject *doc)
|
||||
{
|
||||
_Py_IDENTIFIER(__package__);
|
||||
_Py_IDENTIFIER(__loader__);
|
||||
|
||||
assert(md_dict != NULL);
|
||||
if (doc == NULL)
|
||||
doc = Py_None;
|
||||
|
||||
if (_PyDict_SetItemId(md_dict, &PyId___name__, name) != 0)
|
||||
if (PyDict_SetItem(md_dict, &_Py_ID(__name__), name) != 0)
|
||||
return -1;
|
||||
if (_PyDict_SetItemId(md_dict, &PyId___doc__, doc) != 0)
|
||||
if (PyDict_SetItem(md_dict, &_Py_ID(__doc__), doc) != 0)
|
||||
return -1;
|
||||
if (_PyDict_SetItemId(md_dict, &PyId___package__, Py_None) != 0)
|
||||
if (PyDict_SetItem(md_dict, &_Py_ID(__package__), Py_None) != 0)
|
||||
return -1;
|
||||
if (_PyDict_SetItemId(md_dict, &PyId___loader__, Py_None) != 0)
|
||||
if (PyDict_SetItem(md_dict, &_Py_ID(__loader__), Py_None) != 0)
|
||||
return -1;
|
||||
if (_PyDict_SetItemId(md_dict, &PyId___spec__, Py_None) != 0)
|
||||
if (PyDict_SetItem(md_dict, &_Py_ID(__spec__), Py_None) != 0)
|
||||
return -1;
|
||||
if (PyUnicode_CheckExact(name)) {
|
||||
Py_INCREF(name);
|
||||
|
@ -474,7 +464,7 @@ PyModule_SetDocString(PyObject *m, const char *doc)
|
|||
PyObject *v;
|
||||
|
||||
v = PyUnicode_FromString(doc);
|
||||
if (v == NULL || _PyObject_SetAttrId(m, &PyId___doc__, v) != 0) {
|
||||
if (v == NULL || PyObject_SetAttr(m, &_Py_ID(__doc__), v) != 0) {
|
||||
Py_XDECREF(v);
|
||||
return -1;
|
||||
}
|
||||
|
@ -503,7 +493,7 @@ PyModule_GetNameObject(PyObject *m)
|
|||
}
|
||||
d = ((PyModuleObject *)m)->md_dict;
|
||||
if (d == NULL || !PyDict_Check(d) ||
|
||||
(name = _PyDict_GetItemIdWithError(d, &PyId___name__)) == NULL ||
|
||||
(name = PyDict_GetItemWithError(d, &_Py_ID(__name__))) == NULL ||
|
||||
!PyUnicode_Check(name))
|
||||
{
|
||||
if (!PyErr_Occurred()) {
|
||||
|
@ -528,7 +518,6 @@ PyModule_GetName(PyObject *m)
|
|||
PyObject*
|
||||
PyModule_GetFilenameObject(PyObject *m)
|
||||
{
|
||||
_Py_IDENTIFIER(__file__);
|
||||
PyObject *d;
|
||||
PyObject *fileobj;
|
||||
if (!PyModule_Check(m)) {
|
||||
|
@ -537,7 +526,7 @@ PyModule_GetFilenameObject(PyObject *m)
|
|||
}
|
||||
d = ((PyModuleObject *)m)->md_dict;
|
||||
if (d == NULL ||
|
||||
(fileobj = _PyDict_GetItemIdWithError(d, &PyId___file__)) == NULL ||
|
||||
(fileobj = PyDict_GetItemWithError(d, &_Py_ID(__file__))) == NULL ||
|
||||
!PyUnicode_Check(fileobj))
|
||||
{
|
||||
if (!PyErr_Occurred()) {
|
||||
|
@ -726,8 +715,7 @@ int
|
|||
_PyModuleSpec_IsInitializing(PyObject *spec)
|
||||
{
|
||||
if (spec != NULL) {
|
||||
_Py_IDENTIFIER(_initializing);
|
||||
PyObject *value = _PyObject_GetAttrId(spec, &PyId__initializing);
|
||||
PyObject *value = PyObject_GetAttr(spec, &_Py_ID(_initializing));
|
||||
if (value != NULL) {
|
||||
int initializing = PyObject_IsTrue(value);
|
||||
Py_DECREF(value);
|
||||
|
@ -750,8 +738,7 @@ _PyModuleSpec_IsUninitializedSubmodule(PyObject *spec, PyObject *name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
_Py_IDENTIFIER(_uninitialized_submodules);
|
||||
PyObject *value = _PyObject_GetAttrId(spec, &PyId__uninitialized_submodules);
|
||||
PyObject *value = PyObject_GetAttr(spec, &_Py_ID(_uninitialized_submodules));
|
||||
if (value == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -774,18 +761,17 @@ module_getattro(PyModuleObject *m, PyObject *name)
|
|||
}
|
||||
PyErr_Clear();
|
||||
assert(m->md_dict != NULL);
|
||||
_Py_IDENTIFIER(__getattr__);
|
||||
getattr = _PyDict_GetItemIdWithError(m->md_dict, &PyId___getattr__);
|
||||
getattr = PyDict_GetItemWithError(m->md_dict, &_Py_ID(__getattr__));
|
||||
if (getattr) {
|
||||
return PyObject_CallOneArg(getattr, name);
|
||||
}
|
||||
if (PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
mod_name = _PyDict_GetItemIdWithError(m->md_dict, &PyId___name__);
|
||||
mod_name = PyDict_GetItemWithError(m->md_dict, &_Py_ID(__name__));
|
||||
if (mod_name && PyUnicode_Check(mod_name)) {
|
||||
Py_INCREF(mod_name);
|
||||
PyObject *spec = _PyDict_GetItemIdWithError(m->md_dict, &PyId___spec__);
|
||||
PyObject *spec = PyDict_GetItemWithError(m->md_dict, &_Py_ID(__spec__));
|
||||
if (spec == NULL && PyErr_Occurred()) {
|
||||
Py_DECREF(mod_name);
|
||||
return NULL;
|
||||
|
@ -861,11 +847,11 @@ static PyObject *
|
|||
module_dir(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *result = NULL;
|
||||
PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__);
|
||||
PyObject *dict = PyObject_GetAttr(self, &_Py_ID(__dict__));
|
||||
|
||||
if (dict != NULL) {
|
||||
if (PyDict_Check(dict)) {
|
||||
PyObject *dirfunc = _PyDict_GetItemIdWithError(dict, &PyId___dir__);
|
||||
PyObject *dirfunc = PyDict_GetItemWithError(dict, &_Py_ID(__dir__));
|
||||
if (dirfunc) {
|
||||
result = _PyObject_CallNoArgs(dirfunc);
|
||||
}
|
||||
|
@ -891,7 +877,7 @@ static PyMethodDef module_methods[] = {
|
|||
static PyObject *
|
||||
module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored))
|
||||
{
|
||||
PyObject *dict = _PyObject_GetAttrId((PyObject *)m, &PyId___dict__);
|
||||
PyObject *dict = PyObject_GetAttr((PyObject *)m, &_Py_ID(__dict__));
|
||||
|
||||
if ((dict == NULL) || !PyDict_Check(dict)) {
|
||||
PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary");
|
||||
|
@ -901,8 +887,8 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored))
|
|||
|
||||
PyObject *annotations;
|
||||
/* there's no _PyDict_GetItemId without WithError, so let's LBYL. */
|
||||
if (_PyDict_ContainsId(dict, &PyId___annotations__)) {
|
||||
annotations = _PyDict_GetItemIdWithError(dict, &PyId___annotations__);
|
||||
if (PyDict_Contains(dict, &_Py_ID(__annotations__))) {
|
||||
annotations = PyDict_GetItemWithError(dict, &_Py_ID(__annotations__));
|
||||
/*
|
||||
** _PyDict_GetItemIdWithError could still fail,
|
||||
** for instance with a well-timed Ctrl-C or a MemoryError.
|
||||
|
@ -914,7 +900,8 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored))
|
|||
} else {
|
||||
annotations = PyDict_New();
|
||||
if (annotations) {
|
||||
int result = _PyDict_SetItemId(dict, &PyId___annotations__, annotations);
|
||||
int result = PyDict_SetItem(
|
||||
dict, &_Py_ID(__annotations__), annotations);
|
||||
if (result) {
|
||||
Py_CLEAR(annotations);
|
||||
}
|
||||
|
@ -928,7 +915,7 @@ static int
|
|||
module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignored))
|
||||
{
|
||||
int ret = -1;
|
||||
PyObject *dict = _PyObject_GetAttrId((PyObject *)m, &PyId___dict__);
|
||||
PyObject *dict = PyObject_GetAttr((PyObject *)m, &_Py_ID(__dict__));
|
||||
|
||||
if ((dict == NULL) || !PyDict_Check(dict)) {
|
||||
PyErr_Format(PyExc_TypeError, "<module>.__dict__ is not a dictionary");
|
||||
|
@ -937,17 +924,17 @@ module_set_annotations(PyModuleObject *m, PyObject *value, void *Py_UNUSED(ignor
|
|||
|
||||
if (value != NULL) {
|
||||
/* set */
|
||||
ret = _PyDict_SetItemId(dict, &PyId___annotations__, value);
|
||||
ret = PyDict_SetItem(dict, &_Py_ID(__annotations__), value);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* delete */
|
||||
if (!_PyDict_ContainsId(dict, &PyId___annotations__)) {
|
||||
if (!PyDict_Contains(dict, &_Py_ID(__annotations__))) {
|
||||
PyErr_Format(PyExc_AttributeError, "__annotations__");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = _PyDict_DelItemId(dict, &PyId___annotations__);
|
||||
ret = PyDict_DelItem(dict, &_Py_ID(__annotations__));
|
||||
|
||||
exit:
|
||||
Py_XDECREF(dict);
|
||||
|
|
|
@ -31,11 +31,6 @@ extern "C" {
|
|||
/* Defined in tracemalloc.c */
|
||||
extern void _PyMem_DumpTraceback(int fd, const void *ptr);
|
||||
|
||||
_Py_IDENTIFIER(Py_Repr);
|
||||
_Py_IDENTIFIER(__bytes__);
|
||||
_Py_IDENTIFIER(__dir__);
|
||||
_Py_IDENTIFIER(__isabstractmethod__);
|
||||
|
||||
|
||||
int
|
||||
_PyObject_CheckConsistency(PyObject *op, int check_content)
|
||||
|
@ -562,7 +557,7 @@ PyObject_Bytes(PyObject *v)
|
|||
return v;
|
||||
}
|
||||
|
||||
func = _PyObject_LookupSpecial(v, &PyId___bytes__);
|
||||
func = _PyObject_LookupSpecial(v, &_Py_ID(__bytes__));
|
||||
if (func != NULL) {
|
||||
result = _PyObject_CallNoArgs(func);
|
||||
Py_DECREF(func);
|
||||
|
@ -600,12 +595,9 @@ def _PyObject_FunctionStr(x):
|
|||
PyObject *
|
||||
_PyObject_FunctionStr(PyObject *x)
|
||||
{
|
||||
_Py_IDENTIFIER(__module__);
|
||||
_Py_IDENTIFIER(__qualname__);
|
||||
_Py_IDENTIFIER(builtins);
|
||||
assert(!PyErr_Occurred());
|
||||
PyObject *qualname;
|
||||
int ret = _PyObject_LookupAttrId(x, &PyId___qualname__, &qualname);
|
||||
int ret = _PyObject_LookupAttr(x, &_Py_ID(__qualname__), &qualname);
|
||||
if (qualname == NULL) {
|
||||
if (ret < 0) {
|
||||
return NULL;
|
||||
|
@ -614,13 +606,9 @@ _PyObject_FunctionStr(PyObject *x)
|
|||
}
|
||||
PyObject *module;
|
||||
PyObject *result = NULL;
|
||||
ret = _PyObject_LookupAttrId(x, &PyId___module__, &module);
|
||||
ret = _PyObject_LookupAttr(x, &_Py_ID(__module__), &module);
|
||||
if (module != NULL && module != Py_None) {
|
||||
PyObject *builtinsname = _PyUnicode_FromId(&PyId_builtins);
|
||||
if (builtinsname == NULL) {
|
||||
goto done;
|
||||
}
|
||||
ret = PyObject_RichCompareBool(module, builtinsname, Py_NE);
|
||||
ret = PyObject_RichCompareBool(module, &_Py_ID(builtins), Py_NE);
|
||||
if (ret < 0) {
|
||||
// error
|
||||
goto done;
|
||||
|
@ -858,7 +846,7 @@ _PyObject_IsAbstract(PyObject *obj)
|
|||
if (obj == NULL)
|
||||
return 0;
|
||||
|
||||
res = _PyObject_LookupAttrId(obj, &PyId___isabstractmethod__, &isabstract);
|
||||
res = _PyObject_LookupAttr(obj, &_Py_ID(__isabstractmethod__), &isabstract);
|
||||
if (res > 0) {
|
||||
res = PyObject_IsTrue(isabstract);
|
||||
Py_DECREF(isabstract);
|
||||
|
@ -892,8 +880,6 @@ static inline int
|
|||
set_attribute_error_context(PyObject* v, PyObject* name)
|
||||
{
|
||||
assert(PyErr_Occurred());
|
||||
_Py_IDENTIFIER(name);
|
||||
_Py_IDENTIFIER(obj);
|
||||
// Intercept AttributeError exceptions and augment them to offer
|
||||
// suggestions later.
|
||||
if (PyErr_ExceptionMatches(PyExc_AttributeError)){
|
||||
|
@ -901,8 +887,8 @@ set_attribute_error_context(PyObject* v, PyObject* name)
|
|||
PyErr_Fetch(&type, &value, &traceback);
|
||||
PyErr_NormalizeException(&type, &value, &traceback);
|
||||
if (PyErr_GivenExceptionMatches(value, PyExc_AttributeError) &&
|
||||
(_PyObject_SetAttrId(value, &PyId_name, name) ||
|
||||
_PyObject_SetAttrId(value, &PyId_obj, v))) {
|
||||
(PyObject_SetAttr(value, &_Py_ID(name), name) ||
|
||||
PyObject_SetAttr(value, &_Py_ID(obj), v))) {
|
||||
return 1;
|
||||
}
|
||||
PyErr_Restore(type, value, traceback);
|
||||
|
@ -1569,7 +1555,7 @@ static PyObject *
|
|||
_dir_object(PyObject *obj)
|
||||
{
|
||||
PyObject *result, *sorted;
|
||||
PyObject *dirfunc = _PyObject_LookupSpecial(obj, &PyId___dir__);
|
||||
PyObject *dirfunc = _PyObject_LookupSpecial(obj, &_Py_ID(__dir__));
|
||||
|
||||
assert(obj != NULL);
|
||||
if (dirfunc == NULL) {
|
||||
|
@ -2148,7 +2134,7 @@ Py_ReprEnter(PyObject *obj)
|
|||
early on startup. */
|
||||
if (dict == NULL)
|
||||
return 0;
|
||||
list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr);
|
||||
list = PyDict_GetItemWithError(dict, &_Py_ID(Py_Repr));
|
||||
if (list == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
return -1;
|
||||
|
@ -2156,7 +2142,7 @@ Py_ReprEnter(PyObject *obj)
|
|||
list = PyList_New(0);
|
||||
if (list == NULL)
|
||||
return -1;
|
||||
if (_PyDict_SetItemId(dict, &PyId_Py_Repr, list) < 0)
|
||||
if (PyDict_SetItem(dict, &_Py_ID(Py_Repr), list) < 0)
|
||||
return -1;
|
||||
Py_DECREF(list);
|
||||
}
|
||||
|
@ -2184,7 +2170,7 @@ Py_ReprLeave(PyObject *obj)
|
|||
if (dict == NULL)
|
||||
goto finally;
|
||||
|
||||
list = _PyDict_GetItemIdWithError(dict, &PyId_Py_Repr);
|
||||
list = PyDict_GetItemWithError(dict, &_Py_ID(Py_Repr));
|
||||
if (list == NULL || !PyList_Check(list))
|
||||
goto finally;
|
||||
|
||||
|
|
|
@ -525,8 +525,6 @@ struct _odictnode {
|
|||
#define _odict_FOREACH(od, node) \
|
||||
for (node = _odict_FIRST(od); node != NULL; node = _odictnode_NEXT(node))
|
||||
|
||||
_Py_IDENTIFIER(items);
|
||||
|
||||
/* Return the index into the hash table, regardless of a valid node. */
|
||||
static Py_ssize_t
|
||||
_odict_get_index_raw(PyODictObject *od, PyObject *key, Py_hash_t hash)
|
||||
|
@ -949,12 +947,11 @@ PyDoc_STRVAR(odict_reduce__doc__, "Return state information for pickling");
|
|||
static PyObject *
|
||||
odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(__dict__);
|
||||
PyObject *dict = NULL, *result = NULL;
|
||||
PyObject *items_iter, *items, *args = NULL;
|
||||
|
||||
/* capture any instance state */
|
||||
dict = _PyObject_GetAttrId((PyObject *)od, &PyId___dict__);
|
||||
dict = PyObject_GetAttr((PyObject *)od, &_Py_ID(__dict__));
|
||||
if (dict == NULL)
|
||||
goto Done;
|
||||
else {
|
||||
|
@ -973,7 +970,7 @@ odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored))
|
|||
if (args == NULL)
|
||||
goto Done;
|
||||
|
||||
items = _PyObject_CallMethodIdNoArgs((PyObject *)od, &PyId_items);
|
||||
items = PyObject_CallMethodNoArgs((PyObject *)od, &_Py_ID(items));
|
||||
if (items == NULL)
|
||||
goto Done;
|
||||
|
||||
|
@ -1431,8 +1428,8 @@ odict_repr(PyODictObject *self)
|
|||
}
|
||||
}
|
||||
else {
|
||||
PyObject *items = _PyObject_CallMethodIdNoArgs((PyObject *)self,
|
||||
&PyId_items);
|
||||
PyObject *items = PyObject_CallMethodNoArgs(
|
||||
(PyObject *)self, &_Py_ID(items));
|
||||
if (items == NULL)
|
||||
goto Done;
|
||||
pieces = PySequence_List(items);
|
||||
|
@ -1808,7 +1805,6 @@ PyDoc_STRVAR(reduce_doc, "Return state information for pickling");
|
|||
static PyObject *
|
||||
odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(iter);
|
||||
/* copy the iterator state */
|
||||
odictiterobject tmp = *di;
|
||||
Py_XINCREF(tmp.di_odict);
|
||||
|
@ -1821,7 +1817,7 @@ odictiter_reduce(odictiterobject *di, PyObject *Py_UNUSED(ignored))
|
|||
if (list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list);
|
||||
}
|
||||
|
||||
static PyMethodDef odictiter_methods[] = {
|
||||
|
@ -2217,9 +2213,8 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg)
|
|||
Py_DECREF(items);
|
||||
return res;
|
||||
}
|
||||
_Py_IDENTIFIER(keys);
|
||||
PyObject *func;
|
||||
if (_PyObject_LookupAttrId(arg, &PyId_keys, &func) < 0) {
|
||||
if (_PyObject_LookupAttr(arg, &_Py_ID(keys), &func) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (func != NULL) {
|
||||
|
@ -2251,7 +2246,7 @@ mutablemapping_update_arg(PyObject *self, PyObject *arg)
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
if (_PyObject_LookupAttrId(arg, &PyId_items, &func) < 0) {
|
||||
if (_PyObject_LookupAttr(arg, &_Py_ID(items), &func) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (func != NULL) {
|
||||
|
|
|
@ -21,8 +21,6 @@ typedef struct {
|
|||
PyObject *length;
|
||||
} rangeobject;
|
||||
|
||||
_Py_IDENTIFIER(iter);
|
||||
|
||||
/* Helper function for validating step. Always returns a new reference or
|
||||
NULL on error.
|
||||
*/
|
||||
|
@ -813,8 +811,8 @@ rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored))
|
|||
if (range == NULL)
|
||||
goto err;
|
||||
/* return the result */
|
||||
return Py_BuildValue("N(N)l", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
range, r->index);
|
||||
return Py_BuildValue(
|
||||
"N(N)l", _PyEval_GetBuiltin(&_Py_ID(iter)), range, r->index);
|
||||
err:
|
||||
Py_XDECREF(start);
|
||||
Py_XDECREF(stop);
|
||||
|
@ -967,8 +965,8 @@ longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored))
|
|||
}
|
||||
|
||||
/* return the result */
|
||||
return Py_BuildValue("N(N)O", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
range, r->index);
|
||||
return Py_BuildValue(
|
||||
"N(N)O", _PyEval_GetBuiltin(&_Py_ID(iter)), range, r->index);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
|
@ -770,7 +770,6 @@ static PyObject *setiter_iternext(setiterobject *si);
|
|||
static PyObject *
|
||||
setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(iter);
|
||||
/* copy the iterator state */
|
||||
setiterobject tmp = *si;
|
||||
Py_XINCREF(tmp.si_set);
|
||||
|
@ -781,7 +780,7 @@ setiter_reduce(setiterobject *si, PyObject *Py_UNUSED(ignored))
|
|||
if (list == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), list);
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), list);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
|
||||
|
@ -1906,7 +1905,6 @@ static PyObject *
|
|||
set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
PyObject *keys=NULL, *args=NULL, *result=NULL, *dict=NULL;
|
||||
_Py_IDENTIFIER(__dict__);
|
||||
|
||||
keys = PySequence_List((PyObject *)so);
|
||||
if (keys == NULL)
|
||||
|
@ -1914,7 +1912,7 @@ set_reduce(PySetObject *so, PyObject *Py_UNUSED(ignored))
|
|||
args = PyTuple_Pack(1, keys);
|
||||
if (args == NULL)
|
||||
goto done;
|
||||
if (_PyObject_LookupAttrId((PyObject *)so, &PyId___dict__, &dict) < 0) {
|
||||
if (_PyObject_LookupAttr((PyObject *)so, &_Py_ID(__dict__), &dict) < 0) {
|
||||
goto done;
|
||||
}
|
||||
if (dict == NULL) {
|
||||
|
|
|
@ -23,17 +23,9 @@ static const char match_args_key[] = "__match_args__";
|
|||
They are only allowed for indices < n_visible_fields. */
|
||||
const char * const PyStructSequence_UnnamedField = "unnamed field";
|
||||
|
||||
_Py_IDENTIFIER(n_sequence_fields);
|
||||
_Py_IDENTIFIER(n_fields);
|
||||
_Py_IDENTIFIER(n_unnamed_fields);
|
||||
|
||||
static Py_ssize_t
|
||||
get_type_attr_as_size(PyTypeObject *tp, _Py_Identifier *id)
|
||||
get_type_attr_as_size(PyTypeObject *tp, PyObject *name)
|
||||
{
|
||||
PyObject *name = _PyUnicode_FromId(id);
|
||||
if (name == NULL) {
|
||||
return -1;
|
||||
}
|
||||
PyObject *v = PyDict_GetItemWithError(tp->tp_dict, name);
|
||||
if (v == NULL && !PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
|
@ -44,11 +36,14 @@ get_type_attr_as_size(PyTypeObject *tp, _Py_Identifier *id)
|
|||
}
|
||||
|
||||
#define VISIBLE_SIZE(op) Py_SIZE(op)
|
||||
#define VISIBLE_SIZE_TP(tp) get_type_attr_as_size(tp, &PyId_n_sequence_fields)
|
||||
#define REAL_SIZE_TP(tp) get_type_attr_as_size(tp, &PyId_n_fields)
|
||||
#define VISIBLE_SIZE_TP(tp) \
|
||||
get_type_attr_as_size(tp, &_Py_ID(n_sequence_fields))
|
||||
#define REAL_SIZE_TP(tp) \
|
||||
get_type_attr_as_size(tp, &_Py_ID(n_fields))
|
||||
#define REAL_SIZE(op) REAL_SIZE_TP(Py_TYPE(op))
|
||||
|
||||
#define UNNAMED_FIELDS_TP(tp) get_type_attr_as_size(tp, &PyId_n_unnamed_fields)
|
||||
#define UNNAMED_FIELDS_TP(tp) \
|
||||
get_type_attr_as_size(tp, &_Py_ID(n_unnamed_fields))
|
||||
#define UNNAMED_FIELDS(op) UNNAMED_FIELDS_TP(Py_TYPE(op))
|
||||
|
||||
|
||||
|
@ -622,21 +617,3 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc)
|
|||
{
|
||||
return _PyStructSequence_NewType(desc, 0);
|
||||
}
|
||||
|
||||
|
||||
/* runtime lifecycle */
|
||||
|
||||
PyStatus _PyStructSequence_InitState(PyInterpreterState *interp)
|
||||
{
|
||||
if (!_Py_IsMainInterpreter(interp)) {
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
if (_PyUnicode_FromId(&PyId_n_sequence_fields) == NULL
|
||||
|| _PyUnicode_FromId(&PyId_n_fields) == NULL
|
||||
|| _PyUnicode_FromId(&PyId_n_unnamed_fields) == NULL)
|
||||
{
|
||||
return _PyStatus_ERR("can't initialize structseq state");
|
||||
}
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
|
|
@ -1193,12 +1193,11 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(
|
|||
static PyObject *
|
||||
tupleiter_reduce(tupleiterobject *it, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(iter);
|
||||
if (it->it_seq)
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
|
||||
it->it_seq, it->it_index);
|
||||
else
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltinId(&PyId_iter));
|
||||
return Py_BuildValue("N(())", _PyEval_GetBuiltin(&_Py_ID(iter)));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -260,11 +260,7 @@ get_unicode_state(void)
|
|||
// Return a borrowed reference to the empty string singleton.
|
||||
static inline PyObject* unicode_get_empty(void)
|
||||
{
|
||||
struct _Py_unicode_state *state = get_unicode_state();
|
||||
// unicode_get_empty() must not be called before _PyUnicode_Init()
|
||||
// or after _PyUnicode_Fini()
|
||||
assert(state->empty_string != NULL);
|
||||
return state->empty_string;
|
||||
return &_Py_STR(empty);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1388,25 +1384,6 @@ _PyUnicode_Dump(PyObject *op)
|
|||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
unicode_create_empty_string_singleton(struct _Py_unicode_state *state)
|
||||
{
|
||||
// Use size=1 rather than size=0, so PyUnicode_New(0, maxchar) can be
|
||||
// optimized to always use state->empty_string without having to check if
|
||||
// it is NULL or not.
|
||||
PyObject *empty = PyUnicode_New(1, 0);
|
||||
if (empty == NULL) {
|
||||
return -1;
|
||||
}
|
||||
PyUnicode_1BYTE_DATA(empty)[0] = 0;
|
||||
_PyUnicode_LENGTH(empty) = 0;
|
||||
assert(_PyUnicode_CheckConsistency(empty, 1));
|
||||
|
||||
assert(state->empty_string == NULL);
|
||||
state->empty_string = empty;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PyObject *
|
||||
PyUnicode_New(Py_ssize_t size, Py_UCS4 maxchar)
|
||||
|
@ -2009,10 +1986,11 @@ unicode_dealloc(PyObject *unicode)
|
|||
static int
|
||||
unicode_is_singleton(PyObject *unicode)
|
||||
{
|
||||
struct _Py_unicode_state *state = get_unicode_state();
|
||||
if (unicode == state->empty_string) {
|
||||
if (unicode == &_Py_STR(empty)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct _Py_unicode_state *state = get_unicode_state();
|
||||
PyASCIIObject *ascii = (PyASCIIObject *)unicode;
|
||||
if (ascii->state.kind != PyUnicode_WCHAR_KIND && ascii->length == 1) {
|
||||
Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, 0);
|
||||
|
@ -15551,11 +15529,14 @@ _PyUnicode_InitState(PyInterpreterState *interp)
|
|||
PyStatus
|
||||
_PyUnicode_InitGlobalObjects(PyInterpreterState *interp)
|
||||
{
|
||||
struct _Py_unicode_state *state = &interp->unicode;
|
||||
if (unicode_create_empty_string_singleton(state) < 0) {
|
||||
return _PyStatus_NO_MEMORY();
|
||||
if (!_Py_IsMainInterpreter(interp)) {
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
#ifdef Py_DEBUG
|
||||
assert(_PyUnicode_CheckConsistency(&_Py_STR(empty), 1));
|
||||
#endif
|
||||
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
|
@ -15798,15 +15779,14 @@ PyDoc_STRVAR(length_hint_doc, "Private method returning an estimate of len(list(
|
|||
static PyObject *
|
||||
unicodeiter_reduce(unicodeiterobject *it, PyObject *Py_UNUSED(ignored))
|
||||
{
|
||||
_Py_IDENTIFIER(iter);
|
||||
if (it->it_seq != NULL) {
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
|
||||
return Py_BuildValue("N(O)n", _PyEval_GetBuiltin(&_Py_ID(iter)),
|
||||
it->it_seq, it->it_index);
|
||||
} else {
|
||||
PyObject *u = (PyObject *)_PyUnicode_New(0);
|
||||
if (u == NULL)
|
||||
return NULL;
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltinId(&PyId_iter), u);
|
||||
return Py_BuildValue("N(N)", _PyEval_GetBuiltin(&_Py_ID(iter)), u);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16137,7 +16117,6 @@ _PyUnicode_Fini(PyInterpreterState *interp)
|
|||
for (Py_ssize_t i = 0; i < 256; i++) {
|
||||
Py_CLEAR(state->latin1[i]);
|
||||
}
|
||||
Py_CLEAR(state->empty_string);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -255,10 +255,6 @@ _Py_union_type_or(PyObject* self, PyObject* other)
|
|||
static int
|
||||
union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
||||
{
|
||||
_Py_IDENTIFIER(__module__);
|
||||
_Py_IDENTIFIER(__qualname__);
|
||||
_Py_IDENTIFIER(__origin__);
|
||||
_Py_IDENTIFIER(__args__);
|
||||
PyObject *qualname = NULL;
|
||||
PyObject *module = NULL;
|
||||
PyObject *tmp;
|
||||
|
@ -269,13 +265,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
|||
return _PyUnicodeWriter_WriteASCIIString(writer, "None", 4);
|
||||
}
|
||||
|
||||
if (_PyObject_LookupAttrId(p, &PyId___origin__, &tmp) < 0) {
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__origin__), &tmp) < 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (tmp) {
|
||||
Py_DECREF(tmp);
|
||||
if (_PyObject_LookupAttrId(p, &PyId___args__, &tmp) < 0) {
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__args__), &tmp) < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (tmp) {
|
||||
|
@ -285,13 +281,13 @@ union_repr_item(_PyUnicodeWriter *writer, PyObject *p)
|
|||
}
|
||||
}
|
||||
|
||||
if (_PyObject_LookupAttrId(p, &PyId___qualname__, &qualname) < 0) {
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__qualname__), &qualname) < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (qualname == NULL) {
|
||||
goto use_repr;
|
||||
}
|
||||
if (_PyObject_LookupAttrId(p, &PyId___module__, &module) < 0) {
|
||||
if (_PyObject_LookupAttr(p, &_Py_ID(__module__), &module) < 0) {
|
||||
goto exit;
|
||||
}
|
||||
if (module == NULL || module == Py_None) {
|
||||
|
|
|
@ -163,7 +163,6 @@ static PyObject *
|
|||
weakref_repr(PyWeakReference *self)
|
||||
{
|
||||
PyObject *name, *repr;
|
||||
_Py_IDENTIFIER(__name__);
|
||||
PyObject* obj = PyWeakref_GET_OBJECT(self);
|
||||
|
||||
if (obj == Py_None) {
|
||||
|
@ -171,7 +170,7 @@ weakref_repr(PyWeakReference *self)
|
|||
}
|
||||
|
||||
Py_INCREF(obj);
|
||||
if (_PyObject_LookupAttrId(obj, &PyId___name__, &name) < 0) {
|
||||
if (_PyObject_LookupAttr(obj, &_Py_ID(__name__), &name) < 0) {
|
||||
Py_DECREF(obj);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -462,10 +461,9 @@ proxy_checkref(PyWeakReference *proxy)
|
|||
#define WRAP_METHOD(method, special) \
|
||||
static PyObject * \
|
||||
method(PyObject *proxy, PyObject *Py_UNUSED(ignored)) { \
|
||||
_Py_IDENTIFIER(special); \
|
||||
UNWRAP(proxy); \
|
||||
Py_INCREF(proxy); \
|
||||
PyObject* res = _PyObject_CallMethodIdNoArgs(proxy, &PyId_##special); \
|
||||
PyObject* res = PyObject_CallMethodNoArgs(proxy, &_Py_ID(special)); \
|
||||
Py_DECREF(proxy); \
|
||||
return res; \
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue