add TypeError to c10 and fix segfault in error checking in Tensor constructor (#40106)

Summary:
As per title.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/40106

Differential Revision: D22137193

Pulled By: albanD

fbshipit-source-id: 11d059263c00a834211f016bd9a9e18fdc0437ef
This commit is contained in:
Alban Desmaison
2020-06-22 13:39:28 -07:00
committed by Facebook GitHub Bot
parent a8ab78c815
commit 02ae9a1583
6 changed files with 26 additions and 13 deletions

View File

@ -154,7 +154,7 @@ static PyObject* THPVariable_as_subclass(THPVariable* self, PyObject* args, PyOb
auto r = parser.parse(args, kwargs, parsed_args);
PyObject* cls = r.pyobject(0);
if (!PyType_Check(cls)) {
throw TypeError("cls must be a type (got %s)", Py_TYPE(cls)->tp_name);
throw torch::TypeError("cls must be a type (got %s)", Py_TYPE(cls)->tp_name);
}
return THPVariable_NewWithVar((PyTypeObject*)cls, self->cdata.alias());
END_HANDLE_TH_ERRORS
@ -169,7 +169,7 @@ static PyObject* THPVariable_make_subclass(PyObject* _ignored, PyObject* args, P
auto r = parser.parse(args, kwargs, parsed_args);
PyObject* cls = r.pyobject(0);
if (!PyType_Check(cls)) {
throw TypeError("cls must be a type (got %s)", Py_TYPE(cls)->tp_name);
throw torch::TypeError("cls must be a type (got %s)", Py_TYPE(cls)->tp_name);
}
auto data = r.tensor(1).detach();
// We set `data`'s `allow_tensor_metadata_change` to true here, because we want to