Skip to content

Commit 957cd3a

Browse files
final fixes
1 parent e29508a commit 957cd3a

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2748,22 +2748,20 @@ def testfunc(n):
27482748
self.assertIn("_CALL_METHOD_DESCRIPTOR_FAST", uops)
27492749
self.assertNotIn("_GUARD_CALLABLE_METHOD_DESCRIPTOR_FAST", uops)
27502750

2751-
# this does not work for some reason todo
2752-
# def test_call_method_descriptor_fast_with_keywords(self):
2753-
# def testfunc(n):
2754-
# x = 0
2755-
# for _ in range(n):
2756-
# y = [3, 1, 2]
2757-
# y.sort()
2758-
# x += y[0]
2759-
# return x
2760-
2761-
# res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2762-
# self.assertEqual(res, TIER2_THRESHOLD)
2763-
# self.assertIsNotNone(ex)
2764-
# uops = get_opnames(ex)
2765-
# self.assertIn("_CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS", uops)
2766-
# self.assertNotIn("_GUARD_CALLABLE_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS", uops)
2751+
def test_call_method_descriptor_fast_with_keywords(self):
2752+
def testfunc(n):
2753+
x = 0
2754+
for _ in range(n):
2755+
y = "hello world"
2756+
a, b = y.split()
2757+
x += len(a)
2758+
return x
2759+
res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD)
2760+
self.assertEqual(res, TIER2_THRESHOLD * 5)
2761+
self.assertIsNotNone(ex)
2762+
uops = get_opnames(ex)
2763+
self.assertIn("_CALL_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS", uops)
2764+
self.assertNotIn("_GUARD_CALLABLE_METHOD_DESCRIPTOR_FAST_WITH_KEYWORDS", uops)
27672765

27682766
def test_call_intrinsic_1(self):
27692767
def testfunc(n):

Python/optimizer_bytecodes.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,12 +1307,15 @@ dummy_func(void) {
13071307
PyObject *callable_o = sym_get_const(ctx, callable);
13081308
if (callable_o && sym_matches_type(callable, &PyMethodDescr_Type)) {
13091309
int total_args = oparg;
1310-
int index = 0;
13111310
if (!sym_is_null(self_or_null)) {
1312-
index--;
13131311
total_args++;
13141312
}
1315-
PyObject *self = sym_get_const(ctx, args[index]);
1313+
PyObject *self = NULL;
1314+
if (!sym_is_null(self_or_null)) {
1315+
self = sym_get_const(ctx, self_or_null);
1316+
} else {
1317+
self = sym_get_const(ctx, args[0]);
1318+
}
13161319
PyTypeObject *d_type = ((PyMethodDescrObject *)callable_o)->d_common.d_type;
13171320
if (total_args != 0 &&
13181321
((PyMethodDescrObject *)callable_o)->d_method->ml_flags == (METH_FASTCALL|METH_KEYWORDS) &&

Python/optimizer_cases.c.h

Lines changed: 6 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)