blob: a4c7064bbfbb066e599dd9c23f6a975fc463df4a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
//===- AllocAction.cpp ----------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// AllocAction and related APIs.
//
//===----------------------------------------------------------------------===//
#include "orc-rt/AllocAction.h"
#include "orc-rt/ScopeExit.h"
namespace orc_rt {
Expected<std::vector<AllocAction>>
runFinalizeActions(std::vector<AllocActionPair> AAPs) {
std::vector<AllocAction> DeallocActions;
auto RunDeallocActions = make_scope_exit([&]() {
while (!DeallocActions.empty()) {
// TODO: Log errors from cleanup dealloc actions.
{
[[maybe_unused]] auto B = DeallocActions.back()();
}
DeallocActions.pop_back();
}
});
for (auto &AAP : AAPs) {
if (AAP.Finalize) {
auto B = AAP.Finalize();
if (const char *ErrMsg = B.getOutOfBandError())
return make_error<StringError>(ErrMsg);
}
if (AAP.Dealloc)
DeallocActions.push_back(std::move(AAP.Dealloc));
}
RunDeallocActions.release();
return DeallocActions;
}
void runDeallocActions(std::vector<AllocAction> DAAs) {
while (!DAAs.empty()) {
// TODO: Log errors from cleanup dealloc actions.
{
[[maybe_unused]] auto B = DAAs.back()();
}
DAAs.pop_back();
}
}
} // namespace orc_rt
|