Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cel-c/arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <stddef.h>
#include <string.h>

#ifdef __cplusplus
#include <memory>
#endif

#include "cel-c/alloc.h"
#include "cel-c/assert.h"
#include "cel-c/config.h"
Expand Down Expand Up @@ -176,4 +180,18 @@ CEL_INLINE bool cel_Arena_PrintF(CEL_NONNULL(cel_Arena*) arena,

CEL_END_DECLS

#ifdef __cplusplus
struct cel_ArenaDeleter {
CEL_INLINE void operator()(
cel_Arena* cel_nullable activation) const noexcept {
cel_Arena_Delete(activation);
}
CEL_INLINE void operator()(
const cel_Arena* cel_nullable activation) const noexcept {
(*this)(const_cast<cel_Arena*>(activation));
}
};
using cel_ArenaPtr = std::unique_ptr<cel_Arena, cel_ArenaDeleter>;
#endif

#endif // THIRD_PARTY_CEL_C_ARENA_H_
11 changes: 5 additions & 6 deletions cel-c/internal/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ class RuntimeHarness {
public:
void SetUp() {
cel_Status_Construct(&status_);
arena_ = ABSL_DIE_IF_NULL(cel_Arena_New(alloc()));
arena_ = cel_ArenaPtr(ABSL_DIE_IF_NULL(cel_Arena_New(alloc())));
rt_ = NewRuntime(nullptr);
parser_ = _cel_TestingParserPtr(_cel_TestingParser_New());
compiler_ = _cel_TestingCompilerPtr(_cel_TestingCompiler_New());
std::memset(&context_, 0, sizeof(context_));
context_.alloc = alloc();
context_.arena = arena_;
context_.arena = arena_.get();
context_.def_pool = cel_Runtime_DefPool(rt_.get());
context_.well_known_types = cel_Runtime_WellKnownTypes(rt_.get());
}
Expand All @@ -144,8 +144,7 @@ class RuntimeHarness {
compiler_.reset();
parser_.reset();
rt_.reset();
cel_Arena_Delete(arena_);
arena_ = nullptr;
arena_.reset();
cel_Status_Destruct(&status_);
}

Expand Down Expand Up @@ -182,7 +181,7 @@ class RuntimeHarness {

cel_Allocator* alloc() { return cel_DefaultAllocator; }

cel_Arena* arena() { return ABSL_DIE_IF_NULL(arena_); }
cel_Arena* arena() { return ABSL_DIE_IF_NULL(arena_.get()); }

cel_Status* status() { return &status_; }

Expand Down Expand Up @@ -248,7 +247,7 @@ class RuntimeHarness {

private:
cel_Status status_;
cel_Arena* arena_ = nullptr;
cel_ArenaPtr arena_;
cel_RuntimePtr rt_;
_cel_TestingParserPtr parser_;
_cel_TestingCompilerPtr compiler_;
Expand Down
Loading