Fix handle serialization error (#131871)

This is a bug to try serialise std::string in C API
Co-authored-by: Aaron Gokaslan <aaronGokaslan@gmail.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/131871
Approved by: https://github.com/Skylion007
This commit is contained in:
cyy
2024-07-28 00:33:20 +00:00
committed by PyTorch MergeBot
parent 3e0ccb3a9f
commit 7be0ce51b6

View File

@ -156,15 +156,16 @@ static PyObject* THPEvent_from_ipc_handle(
END_HANDLE_TH_ERRORS
}
static PyObject* THPEvent_ipc_handle(PyObject* _self, PyObject* noargs) {
static PyObject* THPEvent_ipc_handle(
PyObject* _self [[maybe_unused]],
PyObject* noargs) {
HANDLE_TH_ERRORS
auto self = (THPEvent*)_self;
(void)self;
TORCH_CHECK_NOT_IMPLEMENTED(
false,
"torch.Event ipc is not supported yet, please open an issue if you need this!");
std::string handle = "0";
return PyBytes_FromStringAndSize((const char*)&handle, sizeof(handle));
constexpr const char* handle = "0";
return PyBytes_FromStringAndSize(
handle, std::char_traits<char>::length(handle));
END_HANDLE_TH_ERRORS
}