Moving repetitive `_Py_IDENTIFIER` instances to a global location helps identify them more easily in regards to sub-interpreter support.
static PyBytesObject *characters[UCHAR_MAX + 1];
static PyBytesObject *nullstring;
+_Py_IDENTIFIER(__bytes__);
+
/* PyBytesObject_SIZE gives the basic size of a string; any memory allocation
for a string of length n should request PyBytesObject_SIZE + n bytes.
format_obj(PyObject *v, const char **pbuf, Py_ssize_t *plen)
{
PyObject *func, *result;
- _Py_IDENTIFIER(__bytes__);
/* is it a bytes object? */
if (PyBytes_Check(v)) {
*pbuf = PyBytes_AS_STRING(v);
PyObject *func;
Py_ssize_t size;
static char *kwlist[] = {"source", "encoding", "errors", 0};
- _Py_IDENTIFIER(__bytes__);
if (type != &PyBytes_Type)
return bytes_subtype_new(type, args, kwds);
#include "pycore_tupleobject.h"
#include "structmember.h" /* Why is this not included in Python.h? */
+_Py_IDENTIFIER(getattr);
+
/*[clinic input]
class mappingproxy "mappingproxyobject *" "&PyDictProxy_Type"
class property "propertyobject *" "&PyProperty_Type"
static PyObject *
descr_reduce(PyDescrObject *descr, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(getattr);
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr),
PyDescr_TYPE(descr), PyDescr_NAME(descr));
}
static PyObject *
wrapper_reduce(wrapperobject *wp, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(getattr);
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_getattr),
wp->self, PyDescr_NAME(wp->descr));
}
extern "C" {
#endif
+_Py_IDENTIFIER(open);
+
/* External C interface */
PyObject *
const char *errors, const char *newline, int closefd)
{
PyObject *io, *stream;
- _Py_IDENTIFIER(open);
/* import _io in case we are being used to open io.py */
io = PyImport_ImportModule("_io");
PyFile_OpenCodeObject(PyObject *path)
{
PyObject *iomod, *f = NULL;
- _Py_IDENTIFIER(open);
if (!PyUnicode_Check(path)) {
PyErr_Format(PyExc_TypeError, "'path' must be 'str', not '%.200s'",
PyObject *it_seq; /* Set to NULL when iterator is exhausted */
} seqiterobject;
+_Py_IDENTIFIER(iter);
+
PyObject *
PySeqIter_New(PyObject *seq)
{
static PyObject *
iter_reduce(seqiterobject *it, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(iter);
if (it->it_seq != NULL)
return Py_BuildValue("N(O)n", _PyEval_GetBuiltinId(&PyId_iter),
it->it_seq, it->it_index);
static PyObject *
calliter_reduce(calliterobject *it, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(iter);
if (it->it_callable != NULL && it->it_sentinel != NULL)
return Py_BuildValue("N(OO)", _PyEval_GetBuiltinId(&PyId_iter),
it->it_callable, it->it_sentinel);
static Py_ssize_t max_module_number;
+_Py_IDENTIFIER(__doc__);
+_Py_IDENTIFIER(__name__);
+_Py_IDENTIFIER(__spec__);
+
typedef struct {
PyObject_HEAD
PyObject *md_dict;
module_init_dict(PyModuleObject *mod, PyObject *md_dict,
PyObject *name, PyObject *doc)
{
- _Py_IDENTIFIER(__name__);
- _Py_IDENTIFIER(__doc__);
_Py_IDENTIFIER(__package__);
_Py_IDENTIFIER(__loader__);
- _Py_IDENTIFIER(__spec__);
if (md_dict == NULL)
return -1;
PyModule_SetDocString(PyObject *m, const char *doc)
{
PyObject *v;
- _Py_IDENTIFIER(__doc__);
v = PyUnicode_FromString(doc);
if (v == NULL || _PyObject_SetAttrId(m, &PyId___doc__, v) != 0) {
PyObject*
PyModule_GetNameObject(PyObject *m)
{
- _Py_IDENTIFIER(__name__);
PyObject *d;
PyObject *name;
if (!PyModule_Check(m)) {
if (getattr) {
return _PyObject_CallOneArg(getattr, name);
}
- _Py_IDENTIFIER(__name__);
mod_name = _PyDict_GetItemId(m->md_dict, &PyId___name__);
if (mod_name && PyUnicode_Check(mod_name)) {
- _Py_IDENTIFIER(__spec__);
Py_INCREF(mod_name);
PyObject *spec = _PyDict_GetItemId(m->md_dict, &PyId___spec__);
Py_XINCREF(spec);
#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)
odict_reduce(register PyODictObject *od, PyObject *Py_UNUSED(ignored))
{
_Py_IDENTIFIER(__dict__);
- _Py_IDENTIFIER(items);
PyObject *dict = NULL, *result = NULL;
PyObject *items_iter, *items, *args = NULL;
odict_repr(PyODictObject *self)
{
int i;
- _Py_IDENTIFIER(items);
PyObject *pieces = NULL, *result = NULL;
if (PyODict_SIZE(self) == 0)
{
int res = 0;
Py_ssize_t len;
- _Py_IDENTIFIER(items);
_Py_IDENTIFIER(keys);
/* first handle args, if any */
PyObject *length;
} rangeobject;
+_Py_IDENTIFIER(iter);
+
/* Helper function for validating step. Always returns a new reference or
NULL on error.
*/
static PyObject *
rangeiter_reduce(rangeiterobject *r, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(iter);
PyObject *start=NULL, *stop=NULL, *step=NULL;
PyObject *range;
static PyObject *
longrangeiter_reduce(longrangeiterobject *r, PyObject *Py_UNUSED(ignored))
{
- _Py_IDENTIFIER(iter);
PyObject *product, *stop=NULL;
PyObject *range;
_Py_IDENTIFIER(__set_name__);
_Py_IDENTIFIER(__setitem__);
_Py_IDENTIFIER(builtins);
+_Py_IDENTIFIER(mro);
static PyObject *
slot_tp_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
return;
if (custom) {
- _Py_IDENTIFIER(mro);
mro_meth = lookup_maybe_method(
(PyObject *)type, &PyId_mro, &unbound);
if (mro_meth == NULL)
int custom = (Py_TYPE(type) != &PyType_Type);
if (custom) {
- _Py_IDENTIFIER(mro);
int unbound;
PyObject *mro_meth = lookup_method((PyObject *)type, &PyId_mro,
&unbound);
/* Forward declaration of the _warnings module definition. */
static struct PyModuleDef warningsmodule;
+_Py_IDENTIFIER(__name__);
+
/* Given a module object, get its per-module state. */
static WarningsState *
_Warnings_GetState()
PyObject *f_stderr;
PyObject *name;
char lineno_str[128];
- _Py_IDENTIFIER(__name__);
PyOS_snprintf(lineno_str, sizeof(lineno_str), ":%d: ", lineno);
PyObject **module, PyObject **registry)
{
_Py_IDENTIFIER(__warningregistry__);
- _Py_IDENTIFIER(__name__);
PyObject *globals;
/* Setup globals, filename and lineno. */
{
_Py_IDENTIFIER(get_source);
_Py_IDENTIFIER(__loader__);
- _Py_IDENTIFIER(__name__);
PyObject *loader;
PyObject *module_name;
PyObject *get_source;
# error "ceval.c must be build with Py_BUILD_CORE define for best performance"
#endif
+_Py_IDENTIFIER(__name__);
/* Forward declarations */
Py_LOCAL_INLINE(PyObject *) call_function(
import_from(PyThreadState *tstate, PyObject *v, PyObject *name)
{
PyObject *x;
- _Py_IDENTIFIER(__name__);
PyObject *fullmodname, *pkgname, *pkgpath, *pkgname_or_unknown, *errmsg;
if (_PyObject_LookupAttr(v, name, &x) != 0) {
{
_Py_IDENTIFIER(__all__);
_Py_IDENTIFIER(__dict__);
- _Py_IDENTIFIER(__name__);
PyObject *all, *dict, *name, *value;
int skip_leading_underscores = 0;
int pos, err;
extern "C" {
#endif
+_Py_IDENTIFIER(__module__);
_Py_IDENTIFIER(builtins);
_Py_IDENTIFIER(stderr);
_Py_IDENTIFIER(flush);
-
/* Forward declarations */
static PyObject *
_PyErr_FormatV(PyThreadState *tstate, PyObject *exception,
PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
{
PyThreadState *tstate = _PyThreadState_GET();
- _Py_IDENTIFIER(__module__);
PyObject *modulename = NULL;
PyObject *classname = NULL;
PyObject *mydict = NULL;
}
}
- _Py_IDENTIFIER(__module__);
PyObject *moduleName = _PyObject_GetAttrId(exc_type, &PyId___module__);
if (moduleName == NULL || !PyUnicode_Check(moduleName)) {
Py_XDECREF(moduleName);
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]*/
PyInterpreterState *interp = tstate->interp;
PyObject *spec;
- _Py_IDENTIFIER(__spec__);
_Py_IDENTIFIER(_lock_unlock_module);
/* Optimization: only call _bootstrap._lock_unlock_module() if
static PyObject *
resolve_name(PyThreadState *tstate, PyObject *name, PyObject *globals, int level)
{
- _Py_IDENTIFIER(__spec__);
_Py_IDENTIFIER(__package__);
- _Py_IDENTIFIER(__path__);
_Py_IDENTIFIER(__name__);
_Py_IDENTIFIER(parent);
PyObject *abs_name;
}
}
else {
- _Py_IDENTIFIER(__path__);
PyObject *path;
if (_PyObject_LookupAttrId(mod, &PyId___path__, &path) < 0) {
goto error;