| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1378,28 +1378,39 @@ def dummy(): | |||
| 1378 | 1378 | ||
| 1379 | 1379 | class Test_Pep523API(unittest.TestCase): | |
| 1380 | 1380 | ||
| 1381 | - def do_test(self, func): | ||
| 1382 | - calls = [] | ||
| 1381 | + def do_test(self, func, names): | ||
| 1382 | + actual_calls = [] | ||
| 1383 | 1383 | start = SUFFICIENT_TO_DEOPT_AND_SPECIALIZE | |
| 1384 | 1384 | count = start + SUFFICIENT_TO_DEOPT_AND_SPECIALIZE | |
| 1385 | - for i in range(count): | ||
| 1386 | - if i == start: | ||
| 1387 | - _testinternalcapi.set_eval_frame_record(calls) | ||
| 1388 | - func() | ||
| 1389 | - _testinternalcapi.set_eval_frame_default() | ||
| 1390 | - self.assertEqual(len(calls), SUFFICIENT_TO_DEOPT_AND_SPECIALIZE) | ||
| 1391 | - for name in calls: | ||
| 1392 | - self.assertEqual(name, func.__name__) | ||
| 1393 | - | ||
| 1394 | - def test_pep523_with_specialization_simple(self): | ||
| 1395 | - def func1(): | ||
| 1396 | - pass | ||
| 1397 | - self.do_test(func1) | ||
| 1385 | + try: | ||
| 1386 | + for i in range(count): | ||
| 1387 | + if i == start: | ||
| 1388 | + _testinternalcapi.set_eval_frame_record(actual_calls) | ||
| 1389 | + func() | ||
| 1390 | + finally: | ||
| 1391 | + _testinternalcapi.set_eval_frame_default() | ||
| 1392 | + expected_calls = names * SUFFICIENT_TO_DEOPT_AND_SPECIALIZE | ||
| 1393 | + self.assertEqual(len(expected_calls), len(actual_calls)) | ||
| 1394 | + for expected, actual in zip(expected_calls, actual_calls, strict=True): | ||
| 1395 | + self.assertEqual(expected, actual) | ||
| 1396 | + | ||
| 1397 | + def test_inlined_binary_subscr(self): | ||
| 1398 | + class C: | ||
| 1399 | + def __getitem__(self, other): | ||
| 1400 | + return None | ||
| 1401 | + def func(): | ||
| 1402 | + C()[42] | ||
| 1403 | + names = ["func", "__getitem__"] | ||
| 1404 | + self.do_test(func, names) | ||
| 1398 | 1405 | ||
| 1399 | - def test_pep523_with_specialization_with_default(self): | ||
| 1400 | - def func2(x=None): | ||
| 1406 | + def test_inlined_call(self): | ||
| 1407 | + def inner(x=42): | ||
| 1401 | 1408 | pass | |
| 1402 | - self.do_test(func2) | ||
| 1409 | + def func(): | ||
| 1410 | + inner() | ||
| 1411 | + inner(42) | ||
| 1412 | + names = ["func", "inner", "inner"] | ||
| 1413 | + self.do_test(func, names) | ||
| 1403 | 1414 | ||
| 1404 | 1415 | ||
| 1405 | 1416 | if __name__ == "__main__": | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix an issue where some :term:`bytecode` instructions could ignore | ||
| 2 | + :pep:`523` when "inlining" calls. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2233,6 +2233,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int | |||
| 2233 | 2233 | } | |
| 2234 | 2234 | ||
| 2235 | 2235 | TARGET(BINARY_SUBSCR_GETITEM) { | |
| 2236 | + DEOPT_IF(tstate->interp->eval_frame, BINARY_SUBSCR); | ||
| 2236 | 2237 | PyObject *sub = TOP(); | |
| 2237 | 2238 | PyObject *container = SECOND(); | |
| 2238 | 2239 | _PyBinarySubscrCache *cache = (_PyBinarySubscrCache *)next_instr; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1238,6 +1238,10 @@ _Py_Specialize_BinarySubscr( | |||
| 1238 | 1238 | SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OUT_OF_VERSIONS); | |
| 1239 | 1239 | goto fail; | |
| 1240 | 1240 | } | |
| 1241 | + if (_PyInterpreterState_GET()->eval_frame) { | ||
| 1242 | + SPECIALIZATION_FAIL(BINARY_SUBSCR, SPEC_FAIL_OTHER); | ||
| 1243 | + goto fail; | ||
| 1244 | + } | ||
| 1241 | 1245 | cache->func_version = version; | |
| 1242 | 1246 | ((PyHeapTypeObject *)container_type)->_spec_cache.getitem = descriptor; | |
| 1243 | 1247 | _Py_SET_OPCODE(*instr, BINARY_SUBSCR_GETITEM); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments