Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
ec0c931
Add _Py_STRING_LENGTH().
ericsnowcurrently Dec 2, 2021
cea1335
Add PyInterpreterState._preallocated.strings (identifiers-only for now).
ericsnowcurrently Dec 2, 2021
a5513fc
Move the strings to _PyRuntimeState.
ericsnowcurrently Jan 19, 2022
dd084ee
Initialize the global singleton strings (identifiers-only for now).
ericsnowcurrently Dec 2, 2021
472b0a6
Add the global (non-identifier) string literals.
ericsnowcurrently Dec 2, 2021
8a3096b
Add _PyObject_CallMethod().
ericsnowcurrently Dec 2, 2021
38300b3
Get rid of _Py_IDENTIFIER() in tokenizer.c.
ericsnowcurrently Dec 2, 2021
fb9fe24
Add _PyDict_GetItemWithError().
ericsnowcurrently Dec 3, 2021
7fa8e83
Set the hash if not set yet.
ericsnowcurrently Dec 4, 2021
9563c27
Add _PySys_GetAttr().
ericsnowcurrently Dec 3, 2021
674e40b
Get rid of _Py_IDENTIFIER() in _warnings.c.
ericsnowcurrently Dec 3, 2021
e5e7483
_PyObject_LookupSpecial() -> _PyObject_LookupSpecialId().
ericsnowcurrently Dec 4, 2021
07ac6ba
Add _PyObject_LookupSpecial().
ericsnowcurrently Dec 4, 2021
249e830
Get rid of _Py_IDENTIFIER() in bltinmodule.c.
ericsnowcurrently Dec 4, 2021
3ea3c09
Get rid of _Py_IDENTIFIER() in ceval.c.
ericsnowcurrently Dec 4, 2021
5713dab
Add a TODO.
ericsnowcurrently Jan 19, 2022
77a21d6
Get rid of _Py_IDENTIFIER() in specialize.c.
ericsnowcurrently Jan 19, 2022
704d440
Get rid of _Py_IDENTIFIER() in traceback.c.
ericsnowcurrently Jan 19, 2022
2800db6
Get rid of _Py_IDENTIFIER() in codecs.c.
ericsnowcurrently Jan 20, 2022
db72429
Get rid of _Py_IDENTIFIER() in compile.c.
ericsnowcurrently Jan 24, 2022
737391f
Get rid of _Py_IDENTIFIER() in importdl.c.
ericsnowcurrently Jan 24, 2022
9e3ff70
Get rid of _Py_IDENTIFIER() in marshal.c.
ericsnowcurrently Jan 24, 2022
71fc362
Get rid of _Py_IDENTIFIER() in errors.c.
ericsnowcurrently Jan 24, 2022
2046b53
Get rid of _Py_IDENTIFIER() in import.c.
ericsnowcurrently Jan 24, 2022
a4c1aa9
Add _PySys_SetAttr().
ericsnowcurrently Jan 24, 2022
48fcb06
Get rid of _Py_IDENTIFIER() in pylifecycle.c.
ericsnowcurrently Jan 24, 2022
c9bc124
Get rid of _Py_IDENTIFIER() in pythonrun.c.
ericsnowcurrently Jan 24, 2022
816c630
Get rid of _Py_IDENTIFIER() in sysmodule.c.
ericsnowcurrently Jan 24, 2022
ef2b061
Get rid of _Py_IDENTIFIER() in typeobject.c.
ericsnowcurrently Jan 25, 2022
4e03f95
Get rid of _Py_IDENTIFIER() in abstract.c.
ericsnowcurrently Jan 25, 2022
814ec4a
Add _PyEval_GetBuiltin().
ericsnowcurrently Jan 25, 2022
a91fe82
Get rid of _Py_IDENTIFIER() in descrobject.c.
ericsnowcurrently Jan 25, 2022
25a2ec4
Get rid of _Py_IDENTIFIER() in moduleobject.c.
ericsnowcurrently Jan 25, 2022
865cc8a
Get rid of _Py_IDENTIFIER() in object.c.
ericsnowcurrently Jan 25, 2022
e4c2f0d
Get rid of _Py_IDENTIFIER() in bytearrayobject.c.
ericsnowcurrently Jan 25, 2022
f82baa8
Get rid of _Py_IDENTIFIER() in bytesobject.c.
ericsnowcurrently Jan 25, 2022
4b10323
Get rid of _Py_IDENTIFIER() in classobject.c.
ericsnowcurrently Jan 25, 2022
ffd9493
Get rid of _Py_IDENTIFIER() in complexobject.c.
ericsnowcurrently Jan 25, 2022
ddd887b
Get rid of _Py_IDENTIFIER() in dictobject.c.
ericsnowcurrently Jan 25, 2022
0a02936
Get rid of _Py_IDENTIFIER() in enumobject.c.
ericsnowcurrently Jan 25, 2022
d157842
Get rid of _Py_IDENTIFIER() in exceptions.c.
ericsnowcurrently Jan 25, 2022
297240c
Get rid of _Py_IDENTIFIER() in fileobject.c.
ericsnowcurrently Jan 25, 2022
875353d
Get rid of _Py_IDENTIFIER() in frameobject.c.
ericsnowcurrently Jan 25, 2022
9138b2e
Get rid of _Py_IDENTIFIER() in funcobject.c.
ericsnowcurrently Jan 25, 2022
5e576f0
Get rid of _Py_IDENTIFIER() in genericaliasobject.c.
ericsnowcurrently Jan 25, 2022
7591bf1
Get rid of _Py_IDENTIFIER() in genobject.c.
ericsnowcurrently Jan 25, 2022
f27547e
Get rid of _Py_IDENTIFIER() in iterobject.c.
ericsnowcurrently Jan 25, 2022
dd3900f
Get rid of _Py_IDENTIFIER() in listobject.c.
ericsnowcurrently Jan 25, 2022
ecd568d
Get rid of _Py_IDENTIFIER() in longobject.c.
ericsnowcurrently Jan 25, 2022
187133d
Get rid of _Py_IDENTIFIER() in methodobject.c.
ericsnowcurrently Jan 25, 2022
e04947e
Get rid of _Py_IDENTIFIER() in odictobject.c.
ericsnowcurrently Jan 25, 2022
91ef303
Get rid of _Py_IDENTIFIER() in rangeobject.c.
ericsnowcurrently Jan 25, 2022
21c564a
Get rid of _Py_IDENTIFIER() in setobject.c.
ericsnowcurrently Jan 25, 2022
d833719
Get rid of _Py_IDENTIFIER() in structseq.c.
ericsnowcurrently Jan 25, 2022
329f8fd
Get rid of _Py_IDENTIFIER() in tupleobject.c.
ericsnowcurrently Jan 25, 2022
0cbeb2d
Get rid of _Py_IDENTIFIER() in unicodeobject.c.
ericsnowcurrently Jan 25, 2022
972044a
Get rid of _Py_IDENTIFIER() in unionobject.c.
ericsnowcurrently Jan 25, 2022
e55556f
Get rid of _Py_IDENTIFIER() in weakrefobject.c.
ericsnowcurrently Jan 25, 2022
5e32d13
Get rid of _Py_IDENTIFIER() in _pickle.c.
ericsnowcurrently Jan 25, 2022
6081cf1
Add _PyObject_CallMethodObj().
ericsnowcurrently Jan 25, 2022
6aa5674
Use _PyObject_CallMethodObj().
ericsnowcurrently Jan 25, 2022
37c0200
_PyObject_CallMethod() -> _PyObject_CallMethodFormat().
ericsnowcurrently Jan 25, 2022
10f82cd
_PyObject_CallMethodObj() -> _PyObject_CallMethod().
ericsnowcurrently Jan 25, 2022
85f16a4
Get rid of _Py_IDENTIFIER() in the _io module.
ericsnowcurrently Jan 25, 2022
aa641a3
Get rid of _Py_IDENTIFIER() in _threadmodule.c.
ericsnowcurrently Jan 26, 2022
dda08ad
Get rid of _Py_IDENTIFIER() in _abc.c.
ericsnowcurrently Jan 25, 2022
4d75c6b
Get rid of _Py_IDENTIFIER() in faulthandler.c.
ericsnowcurrently Jan 26, 2022
9d36c02
Get rid of _Py_IDENTIFIER() in _collectionsmodule.c.
ericsnowcurrently Jan 26, 2022
1f42649
Get rid of _Py_IDENTIFIER() in itertoolsmodule.c.
ericsnowcurrently Jan 26, 2022
c2f1cfb
Get rid of _Py_IDENTIFIER() in posixmodule.c.
ericsnowcurrently Jan 26, 2022
3ed68a7
Get rid of _Py_IDENTIFIER() in _operator.c.
ericsnowcurrently Jan 26, 2022
d86ceb1
Get rid of _Py_IDENTIFIER() in timemodule.c.
ericsnowcurrently Jan 26, 2022
c0c6777
Get rid of _Py_IDENTIFIER() in main.c.
ericsnowcurrently Jan 26, 2022
c9f4563
Get rid of _Py_static_string() in typeobject.c.
ericsnowcurrently Jan 26, 2022
0796475
Get rid of _Py_static_string() in ast_opt.c.
ericsnowcurrently Jan 26, 2022
3e5fac3
Get rid of _Py_static_string() in compile.c.
ericsnowcurrently Jan 26, 2022
77d423e
Disallow _Py_IDENTIFIER in core.
ericsnowcurrently Jan 26, 2022
308fb9e
Leave all the functions.
ericsnowcurrently Jan 26, 2022
2136577
Auto-generate the global strings.
ericsnowcurrently Jan 27, 2022
b14d0a8
Drop _Py_unicode_state.empty_string.
ericsnowcurrently Jan 27, 2022
61abdab
Do not include the latin-1 characters (for now).
ericsnowcurrently Jan 27, 2022
db9de0a
Use a better prefix for the field names.
ericsnowcurrently Jan 27, 2022
1074b77
Clean up the declarations a little.
ericsnowcurrently Jan 27, 2022
d4f58fd
Add _Py_IS_POINTER_FROM_VAR().
ericsnowcurrently Jan 27, 2022
09c2a51
Consider all global strings as singletons.
ericsnowcurrently Jan 27, 2022
983dda0
_Py_IS_POINTER_FROM_VAR() -> _PyObject_IsSingleton().
ericsnowcurrently Jan 27, 2022
3fbc75f
Add _PyUnicode_InternSafe().
ericsnowcurrently Jan 27, 2022
bd8b74c
Intern the global strings when used.
ericsnowcurrently Jan 27, 2022
b305ded
Limit when we check the global strings for consistency.
ericsnowcurrently Jan 27, 2022
3da2d65
Drop _PyUnicode_InternSafe().
ericsnowcurrently Jan 27, 2022
3673bbd
Add a --check option to generate_global_objects.py.
ericsnowcurrently Jan 28, 2022
9a419a7
Drop unused global strings.
ericsnowcurrently Jan 28, 2022
c6a292d
Check the global objects in CI.
ericsnowcurrently Jan 28, 2022
ffbd515
Fix _PyObject_CallMethod() for size_t.
ericsnowcurrently Jan 31, 2022
878059b
Dump the exception if normal printing fails.
ericsnowcurrently Feb 1, 2022
780e61f
Regenerate test_frozenmain.h.
ericsnowcurrently Feb 1, 2022
876aa77
Add some identifiers that are only used in non-debug builds.
ericsnowcurrently Feb 1, 2022
f0bd78d
Drop _PyObject_CallMethod_SizeT().
ericsnowcurrently Feb 1, 2022
d575057
Merge branch 'main' into global-strings
ericsnowcurrently Feb 1, 2022
db92384
Cast to void* before casting to uint64_t.
ericsnowcurrently Feb 1, 2022
955d26a
Explicitly mark each module that still uses _Py_IDENTIFIER().
ericsnowcurrently Feb 1, 2022
3c66484
_testembed still uses _Py_IDENTIFIER().
ericsnowcurrently Feb 1, 2022
05fd034
Fix name collisions from Windows.
ericsnowcurrently Feb 1, 2022
78482cf
_Py_GET_GLOBAL_IDENTIFIER() -> _Py_ID().
ericsnowcurrently Feb 4, 2022
72316f4
_Py_GET_GLOBAL_STRING() -> _Py_STR().
ericsnowcurrently Feb 4, 2022
75b6a83
Use a simpler field prefix than spamspamspam_.
ericsnowcurrently Feb 4, 2022
7b670c1
ASCII_STR() -> STRUCT_FOR_ASCII_STR().
ericsnowcurrently Feb 4, 2022
144ed0f
LITERAL() -> STRUCT_FOR_STR().
ericsnowcurrently Feb 4, 2022
f3aa225
ID() -> STRUCT_FOR_ID().
ericsnowcurrently Feb 4, 2022
050b34b
Use _PyObject_IMMORTAL_INIT().
ericsnowcurrently Feb 4, 2022
dbec341
Drop _Py_STRING_LENGTH().
ericsnowcurrently Feb 4, 2022
7a075ac
Inline uses of _Py_ID().
ericsnowcurrently Feb 4, 2022
6fdba80
Inline uses of _Py_STR().
ericsnowcurrently Feb 4, 2022
4e00c87
Drop _PyObject_IsSingleton(). (C99 undefined makes it too tricky.)
ericsnowcurrently Feb 4, 2022
fbe8f4a
Drop address-taking from _PY_ID() and _Py_STR().
ericsnowcurrently Feb 4, 2022
f2d9b81
Add a compatibility shim for _PyObject_LookupSpecialId().
ericsnowcurrently Feb 4, 2022
7781025
Merge branch 'main' into global-strings
ericsnowcurrently Feb 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Inline uses of _Py_ID().
  • Loading branch information
ericsnowcurrently committed Feb 4, 2022
commit 7a075acd2e7e6215213cad47bbcad478f2012dde
41 changes: 19 additions & 22 deletions Modules/_abc.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ static _abc_data *
_get_impl(PyObject *module, PyObject *self)
{
_abcmodule_state *state = get_abc_state(module);
PyObject *attr = _Py_ID(_abc_impl);
PyObject *impl = PyObject_GetAttr(self, attr);
PyObject *impl = PyObject_GetAttr(self, _Py_ID(_abc_impl));
if (impl == NULL) {
return NULL;
}
Expand Down Expand Up @@ -304,8 +303,7 @@ compute_abstract_methods(PyObject *self)
PyObject *ns = NULL, *items = NULL, *bases = NULL; // Py_XDECREF()ed on error.

/* Stage 1: direct abstract methods. */
PyObject *attr = _Py_ID(__dict__);
ns = PyObject_GetAttr(self, attr);
ns = PyObject_GetAttr(self, _Py_ID(__dict__));
if (!ns) {
goto error;
}
Expand Down Expand Up @@ -349,8 +347,7 @@ compute_abstract_methods(PyObject *self)
}

/* Stage 2: inherited abstract methods. */
attr = _Py_ID(__bases__);
bases = PyObject_GetAttr(self, attr);
bases = PyObject_GetAttr(self, _Py_ID(__bases__));
if (!bases) {
goto error;
}
Expand All @@ -359,12 +356,12 @@ compute_abstract_methods(PyObject *self)
goto error;
}

attr = _Py_ID(__abstractmethods__);
for (Py_ssize_t pos = 0; pos < PyTuple_GET_SIZE(bases); pos++) {
PyObject *item = PyTuple_GET_ITEM(bases, pos); // borrowed
PyObject *base_abstracts, *iter;

if (_PyObject_LookupAttr(item, attr, &base_abstracts) < 0) {
if (_PyObject_LookupAttr(item, _Py_ID(__abstractmethods__),
&base_abstracts) < 0) {
goto error;
}
if (base_abstracts == NULL) {
Expand Down Expand Up @@ -404,7 +401,7 @@ compute_abstract_methods(PyObject *self)
}
}

if (PyObject_SetAttr(self, attr, abstracts) < 0) {
if (PyObject_SetAttr(self, _Py_ID(__abstractmethods__), abstracts) < 0) {
goto error;
}

Expand Down Expand Up @@ -443,8 +440,7 @@ _abc__abc_init(PyObject *module, PyObject *self)
if (data == NULL) {
return NULL;
}
PyObject *attr = _Py_ID(_abc_impl);
if (PyObject_SetAttr(self, attr, data) < 0) {
if (PyObject_SetAttr(self, _Py_ID(_abc_impl), data) < 0) {
Py_DECREF(data);
return NULL;
}
Expand All @@ -455,8 +451,8 @@ _abc__abc_init(PyObject *module, PyObject *self)
* their special status w.r.t. pattern matching. */
if (PyType_Check(self)) {
PyTypeObject *cls = (PyTypeObject *)self;
PyObject *attr = _Py_ID(__abc_tpflags__);
PyObject *flags = PyDict_GetItemWithError(cls->tp_dict, attr);
PyObject *flags = PyDict_GetItemWithError(cls->tp_dict,
_Py_ID(__abc_tpflags__));
if (flags == NULL) {
if (PyErr_Occurred()) {
return NULL;
Expand All @@ -474,7 +470,7 @@ _abc__abc_init(PyObject *module, PyObject *self)
}
((PyTypeObject *)self)->tp_flags |= (val & COLLECTION_FLAGS);
}
if (PyDict_DelItem(cls->tp_dict, attr) < 0) {
if (PyDict_DelItem(cls->tp_dict, _Py_ID(__abc_tpflags__)) < 0) {
return NULL;
}
}
Expand Down Expand Up @@ -590,8 +586,7 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self,
return NULL;
}

PyObject *attr = _Py_ID(__class__);
subclass = PyObject_GetAttr(instance, attr);
subclass = PyObject_GetAttr(instance, _Py_ID(__class__));
if (subclass == NULL) {
Py_DECREF(impl);
return NULL;
Expand All @@ -607,7 +602,6 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self,
goto end;
}
subtype = (PyObject *)Py_TYPE(instance);
attr = _Py_ID(__subclasscheck__);
if (subtype == subclass) {
if (impl->_abc_negative_cache_version == get_abc_state(module)->abc_invalidation_counter) {
incache = _in_weak_set(impl->_abc_negative_cache, subclass);
Expand All @@ -621,10 +615,12 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self,
}
}
/* Fall back to the subclass check. */
result = PyObject_CallMethodOneArg(self, attr, subclass);
result = PyObject_CallMethodOneArg(self, _Py_ID(__subclasscheck__),
subclass);
goto end;
}
result = PyObject_CallMethodOneArg(self, attr, subclass);
result = PyObject_CallMethodOneArg(self, _Py_ID(__subclasscheck__),
subclass);
if (result == NULL) {
goto end;
}
Expand All @@ -636,7 +632,8 @@ _abc__abc_instancecheck_impl(PyObject *module, PyObject *self,
break;
case 0:
Py_DECREF(result);
result = PyObject_CallMethodOneArg(self, attr, subtype);
result = PyObject_CallMethodOneArg(self, _Py_ID(__subclasscheck__),
subtype);
break;
case 1: // Nothing to do.
break;
Expand Down Expand Up @@ -719,8 +716,8 @@ _abc__abc_subclasscheck_impl(PyObject *module, PyObject *self,
}

/* 3. Check the subclass hook. */
PyObject *attr = _Py_ID(__subclasshook__);
ok = PyObject_CallMethodOneArg((PyObject *)self, attr, subclass);
ok = PyObject_CallMethodOneArg(
(PyObject *)self, _Py_ID(__subclasshook__), subclass);
if (ok == NULL) {
goto end;
}
Expand Down
20 changes: 7 additions & 13 deletions Modules/_collectionsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1349,8 +1349,7 @@ deque_reduce(dequeobject *deque, PyObject *Py_UNUSED(ignored))
{
PyObject *dict, *it;

PyObject *attr = _Py_ID(__dict__);
if (_PyObject_LookupAttr((PyObject *)deque, attr, &dict) < 0) {
if (_PyObject_LookupAttr((PyObject *)deque, _Py_ID(__dict__), &dict) < 0) {
return NULL;
}
if (dict == NULL) {
Expand Down Expand Up @@ -2071,8 +2070,7 @@ defdict_reduce(defdictobject *dd, PyObject *Py_UNUSED(ignored))
args = PyTuple_Pack(1, dd->default_factory);
if (args == NULL)
return NULL;
PyObject *attr = _Py_ID(items);
items = PyObject_CallMethodNoArgs((PyObject *)dd, attr);
items = PyObject_CallMethodNoArgs((PyObject *)dd, _Py_ID(items));
if (items == NULL) {
Py_DECREF(args);
return NULL;
Expand Down Expand Up @@ -2327,13 +2325,10 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
/* Only take the fast path when get() and __setitem__()
* have not been overridden.
*/
PyObject *attr = _Py_ID(get);
mapping_get = _PyType_Lookup(Py_TYPE(mapping), attr);
dict_get = _PyType_Lookup(&PyDict_Type, attr);
attr = _Py_ID(__setitem__);
mapping_setitem = _PyType_Lookup(Py_TYPE(mapping), attr);
attr = _Py_ID(__setitem__);
dict_setitem = _PyType_Lookup(&PyDict_Type, attr);
mapping_get = _PyType_Lookup(Py_TYPE(mapping), _Py_ID(get));
dict_get = _PyType_Lookup(&PyDict_Type, _Py_ID(get));
mapping_setitem = _PyType_Lookup(Py_TYPE(mapping), _Py_ID(__setitem__));
dict_setitem = _PyType_Lookup(&PyDict_Type, _Py_ID(__setitem__));

if (mapping_get != NULL && mapping_get == dict_get &&
mapping_setitem != NULL && mapping_setitem == dict_setitem &&
Expand Down Expand Up @@ -2382,8 +2377,7 @@ _collections__count_elements_impl(PyObject *module, PyObject *mapping,
}
}
else {
attr = _Py_ID(get);
bound_get = PyObject_GetAttr(mapping, attr);
bound_get = PyObject_GetAttr(mapping, _Py_ID(get));
if (bound_get == NULL)
goto done;

Expand Down
13 changes: 4 additions & 9 deletions Modules/_io/_iomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
long isatty = 0;

PyObject *raw, *modeobj = NULL, *buffer, *wrapper, *result = NULL, *path_or_fd = NULL;
PyObject *attr;

is_number = PyNumber_Check(file);

Expand Down Expand Up @@ -377,8 +376,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,

/* buffering */
if (buffering < 0) {
attr = _Py_ID(isatty);
PyObject *res = PyObject_CallMethodNoArgs(raw, attr);
PyObject *res = PyObject_CallMethodNoArgs(raw, _Py_ID(isatty));
if (res == NULL)
goto error;
isatty = PyLong_AsLong(res);
Expand All @@ -396,8 +394,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,

if (buffering < 0) {
PyObject *blksize_obj;
attr = _Py_ID(_blksize);
blksize_obj = PyObject_GetAttr(raw, attr);
blksize_obj = PyObject_GetAttr(raw, _Py_ID(_blksize));
if (blksize_obj == NULL)
goto error;
buffering = PyLong_AsLong(blksize_obj);
Expand Down Expand Up @@ -464,8 +461,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
result = wrapper;
Py_DECREF(buffer);

attr = _Py_ID(mode);
if (PyObject_SetAttr(wrapper, attr, modeobj) < 0)
if (PyObject_SetAttr(wrapper, _Py_ID(mode), modeobj) < 0)
goto error;
Py_DECREF(modeobj);
return result;
Expand All @@ -474,8 +470,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode,
if (result != NULL) {
PyObject *exc, *val, *tb, *close_result;
PyErr_Fetch(&exc, &val, &tb);
attr = _Py_ID(close);
close_result = PyObject_CallMethodNoArgs(result, attr);
close_result = PyObject_CallMethodNoArgs(result, _Py_ID(close));
_PyErr_ChainExceptions(exc, val, tb);
Py_XDECREF(close_result);
Py_DECREF(result);
Expand Down
51 changes: 17 additions & 34 deletions Modules/_io/bufferedio.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ buffered_dealloc_warn(buffered *self, PyObject *source)
{
if (self->ok && self->raw) {
PyObject *r;
PyObject *attr = _Py_ID(_dealloc_warn);
r = PyObject_CallMethodOneArg(self->raw, attr, source);
r = PyObject_CallMethodOneArg(self->raw, _Py_ID(_dealloc_warn), source);
if (r)
Py_DECREF(r);
else
Expand Down Expand Up @@ -569,16 +568,14 @@ static PyObject *
buffered_name_get(buffered *self, void *context)
{
CHECK_INITIALIZED(self)
PyObject *attr = _Py_ID(name);
return PyObject_GetAttr(self->raw, attr);
return PyObject_GetAttr(self->raw, _Py_ID(name));
}

static PyObject *
buffered_mode_get(buffered *self, void *context)
{
CHECK_INITIALIZED(self)
PyObject *attr = _Py_ID(mode);
return PyObject_GetAttr(self->raw, attr);
return PyObject_GetAttr(self->raw, _Py_ID(mode));
}

/* Lower-level APIs */
Expand Down Expand Up @@ -1369,8 +1366,7 @@ buffered_repr(buffered *self)
{
PyObject *nameobj, *res;

PyObject *attr = _Py_ID(name);
if (_PyObject_LookupAttr((PyObject *) self, attr, &nameobj) < 0) {
if (_PyObject_LookupAttr((PyObject *) self, _Py_ID(name), &nameobj) < 0) {
if (!PyErr_ExceptionMatches(PyExc_ValueError)) {
return NULL;
}
Expand Down Expand Up @@ -2165,78 +2161,67 @@ _forward_call(buffered *self, PyObject *name, PyObject *args)
static PyObject *
bufferedrwpair_read(rwpair *self, PyObject *args)
{
PyObject *attr = _Py_ID(read);
return _forward_call(self->reader, attr, args);
return _forward_call(self->reader, _Py_ID(read), args);
}

static PyObject *
bufferedrwpair_peek(rwpair *self, PyObject *args)
{
PyObject *attr = _Py_ID(peek);
return _forward_call(self->reader, attr, args);
return _forward_call(self->reader, _Py_ID(peek), args);
}

static PyObject *
bufferedrwpair_read1(rwpair *self, PyObject *args)
{
PyObject *attr = _Py_ID(read1);
return _forward_call(self->reader, attr, args);
return _forward_call(self->reader, _Py_ID(read1), args);
}

static PyObject *
bufferedrwpair_readinto(rwpair *self, PyObject *args)
{
PyObject *attr = _Py_ID(readinto);
return _forward_call(self->reader, attr, args);
return _forward_call(self->reader, _Py_ID(readinto), args);
}

static PyObject *
bufferedrwpair_readinto1(rwpair *self, PyObject *args)
{
PyObject *attr = _Py_ID(readinto1);
return _forward_call(self->reader, attr, args);
return _forward_call(self->reader, _Py_ID(readinto1), args);
}

static PyObject *
bufferedrwpair_write(rwpair *self, PyObject *args)
{
PyObject *attr = _Py_ID(write);
return _forward_call(self->writer, attr, args);
return _forward_call(self->writer, _Py_ID(write), args);
}

static PyObject *
bufferedrwpair_flush(rwpair *self, PyObject *Py_UNUSED(ignored))
{
PyObject *attr = _Py_ID(flush);
return _forward_call(self->writer, attr, NULL);
return _forward_call(self->writer, _Py_ID(flush), NULL);
}

static PyObject *
bufferedrwpair_readable(rwpair *self, PyObject *Py_UNUSED(ignored))
{
PyObject *attr = _Py_ID(readable);
return _forward_call(self->reader, attr, NULL);
return _forward_call(self->reader, _Py_ID(readable), NULL);
}

static PyObject *
bufferedrwpair_writable(rwpair *self, PyObject *Py_UNUSED(ignored))
{
PyObject *attr = _Py_ID(writable);
return _forward_call(self->writer, attr, NULL);
return _forward_call(self->writer, _Py_ID(writable), NULL);
}

static PyObject *
bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored))
{
PyObject *exc = NULL, *val, *tb;
PyObject *attr = _Py_ID(close);
PyObject *ret = _forward_call(self->writer, attr, NULL);
PyObject *ret = _forward_call(self->writer, _Py_ID(close), NULL);
if (ret == NULL)
PyErr_Fetch(&exc, &val, &tb);
else
Py_DECREF(ret);
attr = _Py_ID(close);
ret = _forward_call(self->reader, attr, NULL);
ret = _forward_call(self->reader, _Py_ID(close), NULL);
if (exc != NULL) {
_PyErr_ChainExceptions(exc, val, tb);
Py_CLEAR(ret);
Expand All @@ -2247,17 +2232,15 @@ bufferedrwpair_close(rwpair *self, PyObject *Py_UNUSED(ignored))
static PyObject *
bufferedrwpair_isatty(rwpair *self, PyObject *Py_UNUSED(ignored))
{
PyObject *attr = _Py_ID(isatty);
PyObject *ret = _forward_call(self->writer, attr, NULL);
PyObject *ret = _forward_call(self->writer, _Py_ID(isatty), NULL);

if (ret != Py_False) {
/* either True or exception */
return ret;
}
Py_DECREF(ret);

attr = _Py_ID(isatty);
return _forward_call(self->reader, attr, NULL);
return _forward_call(self->reader, _Py_ID(isatty), NULL);
}

static PyObject *
Expand Down
Loading