2021-09-02 16:14:01 +08:00
|
|
|
//===-- runtime/memory.cpp ------------------------------------------------===//
|
2020-01-17 05:51:25 +08:00
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2021-09-02 07:00:53 +08:00
|
|
|
#include "flang/Runtime/memory.h"
|
2020-01-17 05:51:25 +08:00
|
|
|
#include "terminator.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
namespace Fortran::runtime {
|
|
|
|
|
2020-02-05 08:55:45 +08:00
|
|
|
void *AllocateMemoryOrCrash(const Terminator &terminator, std::size_t bytes) {
|
2020-01-17 05:51:25 +08:00
|
|
|
if (void *p{std::malloc(bytes)}) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
if (bytes > 0) {
|
|
|
|
terminator.Crash(
|
|
|
|
"Fortran runtime internal error: out of memory, needed %zd bytes",
|
|
|
|
bytes);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeMemory(void *p) { std::free(p); }
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::runtime
|