From d826424f6049df218b4dd2ec283e8c800c4cd07a Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Mon, 13 Jun 2016 14:49:38 +0200 Subject: [PATCH] YACA: Add helper types/functions for pointer management Change-Id: Iecdd6e8bfc36477a7c20c081a7788073fff66c60 --- src/yaca/yaca-test-common.cpp | 15 +++++++++++++++ src/yaca/yaca-test-common.h | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/yaca/yaca-test-common.cpp b/src/yaca/yaca-test-common.cpp index eee4c27d..edfb971f 100644 --- a/src/yaca/yaca-test-common.cpp +++ b/src/yaca/yaca-test-common.cpp @@ -49,3 +49,18 @@ const char *yaca_error(int error) { return yaca_debug_translate_error(static_cast(error)); } + +KeyPtr wrap_ptr(yaca_key_h key) +{ + return KeyPtr(key, yaca_key_destroy); +} + +CtxPtr wrap_ptr(yaca_context_h ctx) +{ + return CtxPtr(ctx, yaca_context_destroy); +} + +BufPtr wrap_ptr(char* buffer) +{ + return BufPtr(buffer, yaca_free); +} diff --git a/src/yaca/yaca-test-common.h b/src/yaca/yaca-test-common.h index 9b6663de..f05db57f 100644 --- a/src/yaca/yaca-test-common.h +++ b/src/yaca/yaca-test-common.h @@ -26,9 +26,11 @@ #include #include #include +#include #include #include +#include #include #include @@ -94,3 +96,11 @@ do { \ #define YACA_SUCCESS(func) YACA_RESULT(YACA_ERROR_NONE, func); #define YACA_INVALID_PARAM(func) YACA_RESULT(YACA_ERROR_INVALID_PARAMETER, func); + +typedef std::unique_ptr KeyPtr; +typedef std::unique_ptr CtxPtr; +typedef std::unique_ptr BufPtr; + +KeyPtr wrap_ptr(yaca_key_h key); +CtxPtr wrap_ptr(yaca_context_h ctx); +BufPtr wrap_ptr(char* buffer); -- 2.34.1