Skip to content

Commit 41838e9

Browse files
committed
fix review idea
Signed-off-by: Manjusaka <me@manjusaka.me>
1 parent 2841780 commit 41838e9

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,15 +1371,20 @@ def testfunc(n):
13711371
self.assertNotIn("_CHECK_FUNCTION_EXACT_ARGS", uops)
13721372

13731373
def test_method_guards_removed_or_reduced(self):
1374+
class TestObject:
1375+
def test(self, *args, **kwargs):
1376+
return args[0]
1377+
1378+
test_object = TestObject()
1379+
test_bound_method = TestObject.test.__get__(test_object)
13741380

13751381
def testfunc(n):
1382+
result = 0
13761383
for i in range(n):
1377-
test_bound_method(i)
1378-
1379-
1380-
testfunc(TIER2_THRESHOLD)
1381-
1382-
ex = get_first_executor(testfunc)
1384+
result += test_bound_method(i)
1385+
return result
1386+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
1387+
self.assertEqual(res, sum(range(TIER2_THRESHOLD)))
13831388
self.assertIsNotNone(ex)
13841389
uops = get_opnames(ex)
13851390
self.assertIn("_PUSH_FRAME", uops)
@@ -2236,14 +2241,6 @@ def f(n):
22362241
self.assertNotIn("_LOAD_ATTR_METHOD_NO_DICT", uops)
22372242
self.assertNotIn("_LOAD_ATTR_METHOD_LAZY_DICT", uops)
22382243

2239-
class TestObject:
2240-
def test(self, *args, **kwargs):
2241-
return args[0]
2242-
2243-
test_object = TestObject()
2244-
test_bound_method = TestObject.test.__get__(test_object)
2245-
2246-
22472244
def global_identity(x):
22482245
return x
22492246

Python/optimizer_bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ dummy_func(void) {
710710

711711
op(_CHECK_METHOD_VERSION, (func_version/2, callable, null, unused[oparg] -- callable, null, unused[oparg])) {
712712
if (sym_is_const(ctx, callable) && sym_matches_type(callable, &PyMethod_Type)) {
713-
assert(PyMethod_Check(sym_get_const(ctx, callable)));
714713
PyMethodObject *method = (PyMethodObject *)sym_get_const(ctx, callable);
714+
assert(PyMethod_Check(method));
715715
REPLACE_OP(this_instr, _CHECK_FUNCTION_VERSION_INLINE, 0, func_version);
716716
this_instr->operand1 = (uintptr_t)method->im_func;
717717
}

Python/optimizer_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy