From dcfc2f5c7a9372d8301435fa67b5dec09369d9b9 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 10 Dec 2020 19:27:18 -0500 Subject: [PATCH] Add `src/cpp-common/bt2/internal/utils.hpp` (validateCreatedObjPtr()) This patch adds `src/cpp-common/bt2/internal/utils.hpp`, that is, internal utils for the libbabeltrace2 C++ interface. Currently, the new file only contains validateCreatedObjPtr() which throws a memory error if a pointer is `nullptr`. Signed-off-by: Philippe Proulx Change-Id: Iba8428da517bbeb0714cd554cb69758a3f7c62c7 Reviewed-on: https://review.lttng.org/c/babeltrace/+/4536 --- src/cpp-common/bt2/internal/utils.hpp | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/cpp-common/bt2/internal/utils.hpp diff --git a/src/cpp-common/bt2/internal/utils.hpp b/src/cpp-common/bt2/internal/utils.hpp new file mode 100644 index 00000000..d429f3bc --- /dev/null +++ b/src/cpp-common/bt2/internal/utils.hpp @@ -0,0 +1,28 @@ +/* + * Copyright 2019-2020 (c) Philippe Proulx + * + * SPDX-License-Identifier: MIT + */ + +#ifndef BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP +#define BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP + +#include + +#include "../lib-error.hpp" + +namespace bt2 { +namespace internal { + +template +void validateCreatedObjPtr(const LibObjPtrT libOjbPtr) +{ + if (!libOjbPtr) { + throw LibMemoryError {}; + } +} + +} // namespace internal +} // namespace bt2 + +#endif // BABELTRACE_CPP_COMMON_BT2_INTERNAL_UTILS_HPP -- 2.34.1