Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d346c32

Browse files
committed
Add CALL_NON_PY_GENERAL call specialization
1 parent 6acb968 commit d346c32

7 files changed

Lines changed: 19 additions & 34 deletions

File tree

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

Lib/test/test_call.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@ def test_frames_are_popped_after_failed_calls(self):
4646
# recovering from failed calls:
4747
def f():
4848
pass
49-
for _ in range(1000):
50-
try:
51-
f(None)
52-
except TypeError:
49+
class C:
50+
def m(self):
5351
pass
52+
callables = [ f, C.m, [].__len__ ]
53+
for c in callables:
54+
for _ in range(1000):
55+
try:
56+
c(None)
57+
except TypeError:
58+
pass
5459
# BOOM!
5560

5661

Python/bytecodes.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,6 +3196,7 @@ dummy_func(
31963196
}
31973197

31983198
op(_CALL_NON_PY_GENERAL, (callable, self_or_null, args[oparg] -- res)) {
3199+
assert(opcode != INSTRUMENTED_CALL);
31993200
int total_args = oparg;
32003201
if (self_or_null != NULL) {
32013202
args--;
@@ -3206,7 +3207,6 @@ dummy_func(
32063207
callable, args,
32073208
total_args | PY_VECTORCALL_ARGUMENTS_OFFSET,
32083209
NULL);
3209-
assert(opcode != INSTRUMENTED_CALL);
32103210
assert((res != NULL) ^ (_PyErr_Occurred(tstate) != NULL));
32113211
Py_DECREF(callable);
32123212
for (int i = 0; i < total_args; i++) {
@@ -3219,7 +3219,6 @@ dummy_func(
32193219
unused/1 + // Skip over the counter
32203220
unused/2 +
32213221
_CHECK_IS_NOT_PY_CALLABLE +
3222-
_EXPAND_METHOD +
32233222
_CALL_NON_PY_GENERAL +
32243223
_CHECK_PERIODIC;
32253224

Python/executor_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.

Python/generated_cases.c.h

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

Python/specialize.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,9 +1979,8 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs)
19791979
return 0;
19801980
}
19811981
default:
1982-
SPECIALIZATION_FAIL(CALL,
1983-
builtin_call_fail_kind(PyCFunction_GET_FLAGS(callable)));
1984-
return 1;
1982+
instr->op.code = CALL_NON_PY_GENERAL;
1983+
return 0;
19851984
}
19861985
}
19871986

@@ -2043,8 +2042,8 @@ _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr, int nargs)
20432042
}
20442043
}
20452044
else {
2046-
SPECIALIZATION_FAIL(CALL, call_fail_kind(callable));
2047-
fail = -1;
2045+
instr->op.code = CALL_NON_PY_GENERAL;
2046+
fail = 0;
20482047
}
20492048
if (fail) {
20502049
STAT_INC(CALL, failure);

Tools/cases_generator/analyzer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ def compute_properties(op: parser.InstDef) -> Properties:
532532
exits_if = variable_used(op, "EXIT_IF")
533533
if deopts_if and exits_if:
534534
tkn = op.tokens[0]
535-
print(op.tokens)
536535
raise lexer.make_syntax_error(
537536
"Op cannot contain both EXIT_IF and DEOPT_IF",
538537
tkn.filename,

0 commit comments

Comments
 (0)