1 //===-- runtime/memory.cpp --------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "memory.h" 10 #include "terminator.h" 11 #include <cstdlib> 12 13 namespace Fortran::runtime { 14 AllocateMemoryOrCrash(const Terminator & terminator,std::size_t bytes)15void *AllocateMemoryOrCrash(const Terminator &terminator, std::size_t bytes) { 16 if (void *p{std::malloc(bytes)}) { 17 return p; 18 } 19 if (bytes > 0) { 20 terminator.Crash( 21 "Fortran runtime internal error: out of memory, needed %zd bytes", 22 bytes); 23 } 24 return nullptr; 25 } 26 FreeMemory(void * p)27void FreeMemory(void *p) { std::free(p); } 28 } // namespace Fortran::runtime 29