Skip to content

Commit

Permalink
Make Result_i64/MethodMeta trivial copy-assignable
Browse files Browse the repository at this point in the history
  • Loading branch information
barakugav committed Aug 23, 2024
1 parent b796972 commit bb212b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 2 additions & 8 deletions executorch-sys/cpp/executorch_rs_ext/api_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ namespace executorch_rs
// static_assert(offsetof(Result_i64, hasValue_) == offsetof(torch::executor::Result<int64_t>, hasValue_), "Result_i64 hasValue_ offset mismatch");
Result_i64 crate_Result_i64(const torch::executor::Result<int64_t> &result)
{
Result_i64 result2{
.error_ = torch::executor::Error::Ok,
.hasValue_ = false,
};
Result_i64 result2;
memcpy(&result2, &result, sizeof(Result_i64));
return result2;
}
Expand All @@ -53,10 +50,7 @@ namespace executorch_rs
// static_assert(offsetof(Result_MethodMeta, hasValue_) == offsetof(torch::executor::Result<torch::executor::MethodMeta>, hasValue_), "Result_MethodMeta hasValue_ offset mismatch");
Result_MethodMeta crate_Result_MethodMeta(const torch::executor::Result<torch::executor::MethodMeta> &result)
{
Result_MethodMeta result2{
.error_ = torch::executor::Error::Ok,
.hasValue_ = false,
};
Result_MethodMeta result2;
memcpy(&result2, &result, sizeof(Result_MethodMeta));
return result2;
}
Expand Down
10 changes: 10 additions & 0 deletions executorch-sys/cpp/executorch_rs_ext/api_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ namespace executorch_rs

/// True if the Result contains a value.
const bool hasValue_;

Result_i64() : error_(torch::executor::Error::Ok), hasValue_(false) {}
Result_i64(const Result_i64 &) = default;
Result_i64 &operator=(const Result_i64 &) = default;
~Result_i64() = default;
};
struct Result_MethodMeta
{
Expand All @@ -68,6 +73,11 @@ namespace executorch_rs

/// True if the Result contains a value.
const bool hasValue_;

Result_MethodMeta() : error_(torch::executor::Error::Ok), hasValue_(false) {}
Result_MethodMeta(const Result_MethodMeta &) = default;
Result_MethodMeta &operator=(const Result_MethodMeta &) = default;
~Result_MethodMeta() = default;
};

Result_MethodMeta Program_method_meta(const torch::executor::Program *self, const char *method_name);
Expand Down

0 comments on commit bb212b2

Please sign in to comment.