forked from mindspore-Ecosystem/mindspore
!6442 Fix codex for MemGuard::allocate
Merge pull request !6442 from JesseKLee/fix_noexcept
This commit is contained in:
commit
980059eaec
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue