From b9062aeeffa38ca7b7b70ea4683f56863cf952e5 Mon Sep 17 00:00:00 2001 From: xiehan <52160700+Barenboim@users.noreply.github.com> Date: Tue, 7 Jan 2025 01:57:22 +0800 Subject: [PATCH] Fix compiling error when message doesn't have a move constructor. (#1678) * Fix compiling error when message doesn't have a move constructor. * Clear response safely. --- src/factory/RedisTaskImpl.cc | 6 ++++-- src/factory/WFTaskFactory.inl | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/factory/RedisTaskImpl.cc b/src/factory/RedisTaskImpl.cc index b32d339f..0d7f716c 100644 --- a/src/factory/RedisTaskImpl.cc +++ b/src/factory/RedisTaskImpl.cc @@ -367,7 +367,7 @@ public: ProtocolMessage * ComplexRedisSubscribeTask::SubscribeWrapper::next_in(ProtocolMessage *message) { - redis_reply_t *reply = ((RedisResponse *)message)->result_ptr(); + redis_reply_t *reply = task_->resp.result_ptr(); if (reply->type != REDIS_REPLY_TYPE_ARRAY) { @@ -385,7 +385,9 @@ ComplexRedisSubscribeTask::SubscribeWrapper::next_in(ProtocolMessage *message) task_->watching_ = true; task_->extract_(task_); - task_->clear_resp(); + RedisResponse resp; + *(protocol::ProtocolMessage *)&resp = std::move(task_->resp); + task_->resp = std::move(resp); return task_->finished_ ? NULL : &task_->resp; } diff --git a/src/factory/WFTaskFactory.inl b/src/factory/WFTaskFactory.inl index bb8d700f..44d230ce 100644 --- a/src/factory/WFTaskFactory.inl +++ b/src/factory/WFTaskFactory.inl @@ -179,9 +179,10 @@ protected: void clear_resp() { - RESP resp; - *(protocol::ProtocolMessage *)&resp = std::move(this->resp); - this->resp = std::move(resp); + protocol::ProtocolMessage head(std::move(this->resp)); + this->resp.~RESP(); + new(&this->resp) RESP; + *(protocol::ProtocolMessage *)&this->resp = std::move(head); } void disable_retry()