mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-136125: Use _PyObject_GetMethodStackRef
for LOAD_ATTR
(GH-136127)
This commit is contained in:
parent
17cf0a343b
commit
e0d6500b2d
6 changed files with 29 additions and 32 deletions
|
@ -2327,19 +2327,18 @@ dummy_func(
|
|||
#endif /* ENABLE_SPECIALIZATION_FT */
|
||||
}
|
||||
|
||||
op(_LOAD_ATTR, (owner -- attr, self_or_null[oparg&1])) {
|
||||
op(_LOAD_ATTR, (owner -- attr[1], self_or_null[oparg&1])) {
|
||||
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 1);
|
||||
PyObject *attr_o;
|
||||
if (oparg & 1) {
|
||||
/* Designed to work in tandem with CALL, pushes two values. */
|
||||
attr_o = NULL;
|
||||
int is_meth = _PyObject_GetMethod(PyStackRef_AsPyObjectBorrow(owner), name, &attr_o);
|
||||
*attr = PyStackRef_NULL;
|
||||
int is_meth = _PyObject_GetMethodStackRef(tstate, PyStackRef_AsPyObjectBorrow(owner), name, attr);
|
||||
if (is_meth) {
|
||||
/* We can bypass temporary bound method object.
|
||||
meth is unbound method and obj is self.
|
||||
meth | self | arg1 | ... | argN
|
||||
*/
|
||||
assert(attr_o != NULL); // No errors on this branch
|
||||
assert(!PyStackRef_IsNull(*attr)); // No errors on this branch
|
||||
self_or_null[0] = owner; // Transfer ownership
|
||||
DEAD(owner);
|
||||
}
|
||||
|
@ -2351,17 +2350,17 @@ dummy_func(
|
|||
meth | NULL | arg1 | ... | argN
|
||||
*/
|
||||
PyStackRef_CLOSE(owner);
|
||||
ERROR_IF(attr_o == NULL);
|
||||
ERROR_IF(PyStackRef_IsNull(*attr));
|
||||
self_or_null[0] = PyStackRef_NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* Classic, pushes one value. */
|
||||
attr_o = PyObject_GetAttr(PyStackRef_AsPyObjectBorrow(owner), name);
|
||||
PyObject *attr_o = PyObject_GetAttr(PyStackRef_AsPyObjectBorrow(owner), name);
|
||||
PyStackRef_CLOSE(owner);
|
||||
ERROR_IF(attr_o == NULL);
|
||||
*attr = PyStackRef_FromPyObjectSteal(attr_o);
|
||||
}
|
||||
attr = PyStackRef_FromPyObjectSteal(attr_o);
|
||||
}
|
||||
|
||||
macro(LOAD_ATTR) =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue