1651f58bfSDiana Picus //===-- runtime/memory.cpp ------------------------------------------------===// 2352d347aSAlexis Perry // 3352d347aSAlexis Perry // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4352d347aSAlexis Perry // See https://llvm.org/LICENSE.txt for license information. 5352d347aSAlexis Perry // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6352d347aSAlexis Perry // 7352d347aSAlexis Perry //===----------------------------------------------------------------------===// 8352d347aSAlexis Perry 9*830c0b90SPeter Klausler #include "flang/Runtime/memory.h" 10352d347aSAlexis Perry #include "terminator.h" 11352d347aSAlexis Perry #include <cstdlib> 12352d347aSAlexis Perry 13352d347aSAlexis Perry namespace Fortran::runtime { 14352d347aSAlexis Perry AllocateMemoryOrCrash(const Terminator & terminator,std::size_t bytes)1595696d56Speter klauslervoid *AllocateMemoryOrCrash(const Terminator &terminator, std::size_t bytes) { 16352d347aSAlexis Perry if (void *p{std::malloc(bytes)}) { 17352d347aSAlexis Perry return p; 18352d347aSAlexis Perry } 19352d347aSAlexis Perry if (bytes > 0) { 20352d347aSAlexis Perry terminator.Crash( 21352d347aSAlexis Perry "Fortran runtime internal error: out of memory, needed %zd bytes", 22352d347aSAlexis Perry bytes); 23352d347aSAlexis Perry } 24352d347aSAlexis Perry return nullptr; 25352d347aSAlexis Perry } 26352d347aSAlexis Perry FreeMemory(void * p)27352d347aSAlexis Perryvoid FreeMemory(void *p) { std::free(p); } 281f879005STim Keith } // namespace Fortran::runtime 29