gh-136125: Use `_PyObject_GetMethodStackRef` for `LOAD_ATTR` (GH-136… · python/cpython@e0d6500 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit e0d6500

Browse files
gh-136125: Use _PyObject_GetMethodStackRef for LOAD_ATTR (GH-136127)
1 parent 17cf0a3 commit e0d6500

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

Include/internal/pycore_object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ extern PyObject *_PyType_LookupRefAndVersion(PyTypeObject *, PyObject *,
918918
extern unsigned int
919919
_PyType_LookupStackRefAndVersion(PyTypeObject *type, PyObject *name, _PyStackRef *out);
920920

921-
extern int _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
921+
PyAPI_FUNC(int) _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
922922
PyObject *name, _PyStackRef *method);
923923

924924
// Cache the provided init method in the specialization cache of type if the

Python/bytecodes.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,19 +2327,18 @@ dummy_func(
23272327
#endif /* ENABLE_SPECIALIZATION_FT */
23282328
}
23292329

2330-
op(_LOAD_ATTR, (owner -- attr, self_or_null[oparg&1])) {
2330+
op(_LOAD_ATTR, (owner -- attr[1], self_or_null[oparg&1])) {
23312331
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg >> 1);
2332-
PyObject *attr_o;
23332332
if (oparg & 1) {
23342333
/* Designed to work in tandem with CALL, pushes two values. */
2335-
attr_o = NULL;
2336-
int is_meth = _PyObject_GetMethod(PyStackRef_AsPyObjectBorrow(owner), name, &attr_o);
2334+
*attr = PyStackRef_NULL;
2335+
int is_meth = _PyObject_GetMethodStackRef(tstate, PyStackRef_AsPyObjectBorrow(owner), name, attr);
23372336
if (is_meth) {
23382337
/* We can bypass temporary bound method object.
23392338
meth is unbound method and obj is self.
23402339
meth | self | arg1 | ... | argN
23412340
*/
2342-
assert(attr_o != NULL); // No errors on this branch
2341+
assert(!PyStackRef_IsNull(*attr)); // No errors on this branch
23432342
self_or_null[0] = owner; // Transfer ownership
23442343
DEAD(owner);
23452344
}
@@ -2351,17 +2350,17 @@ dummy_func(
23512350
meth | NULL | arg1 | ... | argN
23522351
*/
23532352
PyStackRef_CLOSE(owner);
2354-
ERROR_IF(attr_o == NULL);
2353+
ERROR_IF(PyStackRef_IsNull(*attr));
23552354
self_or_null[0] = PyStackRef_NULL;
23562355
}
23572356
}
23582357
else {
23592358
/* Classic, pushes one value. */
2360-
attr_o = PyObject_GetAttr(PyStackRef_AsPyObjectBorrow(owner), name);
2359+
PyObject *attr_o = PyObject_GetAttr(PyStackRef_AsPyObjectBorrow(owner), name);
23612360
PyStackRef_CLOSE(owner);
23622361
ERROR_IF(attr_o == NULL);
2362+
*attr = PyStackRef_FromPyObjectSteal(attr_o);
23632363
}
2364-
attr = PyStackRef_FromPyObjectSteal(attr_o);
23652364
}
23662365

23672366
macro(LOAD_ATTR) =

Python/executor_cases.c.h

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 8 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_bytecodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ dummy_func(void) {
590590
}
591591
}
592592

593-
op(_LOAD_ATTR, (owner -- attr, self_or_null[oparg&1])) {
593+
op(_LOAD_ATTR, (owner -- attr[1], self_or_null[oparg&1])) {
594594
(void)owner;
595-
attr = sym_new_not_null(ctx);
595+
*attr = sym_new_not_null(ctx);
596596
if (oparg & 1) {
597597
self_or_null[0] = sym_new_unknown(ctx);
598598
}

Python/optimizer_cases.c.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.