bpo-45510: Check both types when specializing subtraction (GH-29995)

This commit is contained in:
Brandt Bucher 2021-12-08 17:17:16 -08:00 committed by GitHub
parent 9fe0de28bc
commit 5de39f4b41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1490,6 +1490,10 @@ _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
break;
case NB_SUBTRACT:
case NB_INPLACE_SUBTRACT:
if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
SPECIALIZATION_FAIL(BINARY_OP, SPEC_FAIL_DIFFERENT_TYPES);
goto failure;
}
if (PyLong_CheckExact(lhs)) {
*instr = _Py_MAKECODEUNIT(BINARY_OP_SUBTRACT_INT,
_Py_OPARG(*instr));