Skip to content

Commit 907c5cb

Browse files
partly address code review
1 parent 8a74cff commit 907c5cb

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

Python/specialize.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,28 @@ _Py_Specialize_BinaryMultiply(PyObject *left, PyObject *right, _Py_CODEUNIT *ins
12371237
}
12381238

12391239

1240+
static int
1241+
builtin_call_fail_kind(int ml_flags)
1242+
{
1243+
switch (ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O |
1244+
METH_KEYWORDS | METH_METHOD)) {
1245+
case METH_VARARGS:
1246+
return SPEC_FAIL_PYCFUNCTION;
1247+
case METH_VARARGS | METH_KEYWORDS:
1248+
return SPEC_FAIL_PYCFUNCTION_WITH_KEYWORDS;
1249+
case METH_FASTCALL | METH_KEYWORDS:
1250+
return SPEC_FAIL_PYCFUNCTION_FAST_WITH_KEYWORDS;
1251+
case METH_NOARGS:
1252+
return SPEC_FAIL_PYCFUNCTION_NOARGS;
1253+
/* This case should never happen with PyCFunctionObject -- only
1254+
PyMethodObject. See zlib.compressobj()'s methods for an example.
1255+
*/
1256+
case METH_METHOD | METH_FASTCALL | METH_KEYWORDS:
1257+
default:
1258+
return SPEC_FAIL_BAD_CALL_FLAGS;
1259+
}
1260+
}
1261+
12401262
static int
12411263
specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
12421264
SpecializedCacheEntry *cache, PyObject *builtins)
@@ -1281,35 +1303,17 @@ specialize_c_call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
12811303
_Py_OPARG(*instr));
12821304
return 0;
12831305
}
1284-
case METH_VARARGS:
1285-
SPECIALIZATION_FAIL(CALL_FUNCTION, SPEC_FAIL_PYCFUNCTION);
1286-
return 1;
1287-
case METH_VARARGS | METH_KEYWORDS:
1288-
SPECIALIZATION_FAIL(CALL_FUNCTION,
1289-
SPEC_FAIL_PYCFUNCTION_WITH_KEYWORDS);
1290-
return 1;
1291-
case METH_FASTCALL | METH_KEYWORDS:
1292-
SPECIALIZATION_FAIL(CALL_FUNCTION,
1293-
SPEC_FAIL_PYCFUNCTION_FAST_WITH_KEYWORDS);
1294-
return 1;
1295-
case METH_NOARGS:
1296-
SPECIALIZATION_FAIL(CALL_FUNCTION, SPEC_FAIL_PYCFUNCTION_NOARGS);
1297-
return 1;
1298-
/* This case should never happen with PyCFunctionObject -- only
1299-
PyMethodObject. See zlib.compressobj()'s methods for an example.
1300-
*/
1301-
case METH_METHOD | METH_FASTCALL | METH_KEYWORDS:
13021306
default:
1303-
SPECIALIZATION_FAIL(CALL_FUNCTION, SPEC_FAIL_BAD_CALL_FLAGS);
1307+
SPECIALIZATION_FAIL(CALL_FUNCTION,
1308+
builtin_call_fail_kind(PyCFunction_GET_FLAGS(callable)));
13041309
return 1;
13051310
}
13061311
}
13071312

13081313
#if COLLECT_SPECIALIZATION_STATS_DETAILED
13091314
static int
1310-
c_call_fail_kind(PyObject *callable)
1315+
call_fail_kind(PyObject *callable)
13111316
{
1312-
/* These might be implemented in the future. Collecting stats for now. */
13131317
if (PyFunction_Check(callable)) {
13141318
return SPEC_FAIL_PYTHON_FUNCTION;
13151319
}
@@ -1348,7 +1352,7 @@ _Py_Specialize_CallFunction(
13481352
fail = specialize_c_call(callable, instr, nargs, cache, builtins);
13491353
}
13501354
else {
1351-
SPECIALIZATION_FAIL(CALL_FUNCTION, c_call_fail_kind(callable));
1355+
SPECIALIZATION_FAIL(CALL_FUNCTION, call_fail_kind(callable));
13521356
fail = 1;
13531357
}
13541358
_PyAdaptiveEntry *cache0 = &cache->adaptive;

0 commit comments

Comments
 (0)