Skip to content

Commit 2ca6333

Browse files
authored
pythongh-148380: remove all uses of _PyType_LookupByVersion in optimizer_bytecodes.c (pythonGH-148394)
1 parent efcac6f commit 2ca6333

5 files changed

Lines changed: 43 additions & 39 deletions

File tree

Include/internal/pycore_opcode_metadata.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.

Python/bytecodes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2984,14 +2984,15 @@ dummy_func(
29842984

29852985
macro(LOAD_ATTR_CLASS) =
29862986
unused/1 +
2987+
_RECORD_TOS +
29872988
_CHECK_ATTR_CLASS +
29882989
unused/2 +
29892990
_LOAD_ATTR_CLASS +
29902991
_PUSH_NULL_CONDITIONAL;
29912992

29922993
macro(LOAD_ATTR_CLASS_WITH_METACLASS_CHECK) =
29932994
unused/1 +
2994-
_RECORD_TOS_TYPE +
2995+
_RECORD_TOS +
29952996
_GUARD_TYPE_VERSION +
29962997
_CHECK_ATTR_CLASS +
29972998
_LOAD_ATTR_CLASS +

Python/optimizer_bytecodes.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ dummy_func(void) {
229229
}
230230

231231
op(_CHECK_ATTR_CLASS, (type_version/2, owner -- owner)) {
232-
PyObject *type = (PyObject *)_PyType_LookupByVersion(type_version);
233-
if (type) {
232+
PyObject *type = sym_get_probable_value(owner);
233+
if (type != NULL && ((PyTypeObject *)type)->tp_version_tag == type_version) {
234234
if (type == sym_get_const(ctx, owner)) {
235235
ADD_OP(_NOP, 0, 0);
236236
}
@@ -246,7 +246,7 @@ dummy_func(void) {
246246

247247
op(_GUARD_TYPE_VERSION, (type_version/2, owner -- owner)) {
248248
assert(type_version);
249-
assert(this_instr[-1].opcode == _RECORD_TOS_TYPE);
249+
assert(this_instr[-1].opcode == _RECORD_TOS_TYPE || this_instr[-1].opcode == _RECORD_TOS);
250250
if (sym_matches_type_version(owner, type_version)) {
251251
ADD_OP(_NOP, 0, 0);
252252
}

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.

Python/record_functions.c.h

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

0 commit comments

Comments
 (0)