!6442 Fix codex for MemGuard::allocate

Merge pull request !6442 from JesseKLee/fix_noexcept
This commit is contained in:
mindspore-ci-bot 2020-09-18 09:47:55 +08:00 committed by Gitee
commit 980059eaec
1 changed files with 19 additions and 13 deletions

View File

@ -92,6 +92,7 @@ template <typename T, typename... Args>
Status MakeUnique(std::unique_ptr<T[], std::function<void(T *)>> *out, Allocator<T> alloc, size_t n, Args &&... args) {
RETURN_UNEXPECTED_IF_NULL(out);
CHECK_FAIL_RETURN_UNEXPECTED(n > 0, "size must be positive");
try {
T *data = alloc.allocate(n);
if (!std::is_arithmetic<T>::value) {
for (auto i = 0; i < n; i++) {
@ -107,6 +108,11 @@ Status MakeUnique(std::unique_ptr<T[], std::function<void(T *)>> *out, Allocator
f_alloc.deallocate(p, f_n);
};
*out = std::unique_ptr<T[], std::function<void(T *)>>(data, std::bind(deleter, std::placeholders::_1, alloc, n));
} catch (const std::bad_alloc &e) {
return Status(StatusCode::kOutOfMemory);
} catch (const std::exception &e) {
RETURN_STATUS_UNEXPECTED(e.what());
}
return Status::OK();
}