Skip to content

Commit

Permalink
Update interface_value.h
Browse files Browse the repository at this point in the history
  • Loading branch information
walkalone20 authored May 1, 2024
1 parent 7ad02ee commit ae6e00e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions paddle/pir/include/core/interface_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#pragma once

#include <memory>
#include <set>
#include <type_traits>

Expand All @@ -35,7 +36,7 @@ class IR_API InterfaceValue {
InterfaceValue(InterfaceValue &&) noexcept;
InterfaceValue &operator=(const InterfaceValue &) = delete;
InterfaceValue &operator=(InterfaceValue &&) noexcept;
~InterfaceValue();
~InterfaceValue() = default;
void swap(InterfaceValue &&val) {
using std::swap;
swap(type_id_, val.type_id_);
Expand Down Expand Up @@ -65,13 +66,14 @@ InterfaceValue InterfaceValue::Get() {
sizeof(typename Interface::Concept) == sizeof(Model),
"Compared with Concept, Model class shouldn't define new data members");

val.model_ = malloc(sizeof(Model));
if (val.model_ == nullptr) {
void *model_raw = malloc(sizeof(Model));
if (model_raw == nullptr) {
throw("Alloc memory for interface failed.");
}
static_assert(std::is_trivially_destructible<Model>::value,
"interface models must be trivially destructible");
new (val.model_) Model();
new (model_raw) Model();
val.model_.reset(model_raw);
return val;
}

Expand Down

0 comments on commit ae6e00e

Please sign in to comment.