Handle exceptions from THPModule_setQEngine (#60073)

Summary:
Prevents Python runtime crashes when `torch._C._set_qengine(2**65)` or `torch.backends.quantized.engine="fbgemm"` if PyTorch was compiled without fbgemm

Pull Request resolved: https://github.com/pytorch/pytorch/pull/60073

Reviewed By: supriyar

Differential Revision: D29156430

Pulled By: malfet

fbshipit-source-id: 95b97352a52a262f1634b72da64a0c950eaf2373
This commit is contained in:
Nikita Shulga
2021-06-16 00:40:00 -07:00
committed by Facebook GitHub Bot
parent 9fbbab88da
commit 36a5647e30

View File

@ -574,9 +574,11 @@ PyObject *THPModule_setQEngine(PyObject */* unused */, PyObject *arg)
{
THPUtils_assert(THPUtils_checkLong(arg), "set_qengine expects an int, "
"but got %s", THPUtils_typename(arg));
HANDLE_TH_ERRORS
auto qengine = static_cast<int>(THPUtils_unpackLong(arg));
at::globalContext().setQEngine(static_cast<at::QEngine>(qengine));
Py_RETURN_NONE;
END_HANDLE_TH_ERRORS
}
PyObject *THPModule_qEngine(PyObject *_unused, PyObject *noargs)