From 832b92a544181b09ac2f3645e1d3574759075bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Bourbonnais?= Date: Fri, 12 May 2023 09:21:03 -0700 Subject: [PATCH] Add a function to free allocated memory (#52) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Managed runtimes like C# P/Invoke requires this in order to be able to correctly free memory in managed code that was allocated by unmanaged code. The method was only defined in copentime because it can be used on it's own but opentimlineio must be used with opentime. Signed-off-by: FĂ©lix Bourbonnais --- include/copentime/util.h | 2 ++ src/copentime/CMakeLists.txt | 1 + src/copentime/util.cpp | 8 ++++++++ 3 files changed, 11 insertions(+) create mode 100644 src/copentime/util.cpp diff --git a/include/copentime/util.h b/include/copentime/util.h index 70925ee..2c02e9f 100644 --- a/include/copentime/util.h +++ b/include/copentime/util.h @@ -39,3 +39,5 @@ inline opentime::TimeTransform CTimeTransform_to_CppTimeTransform(TimeTransform opentime::RationalTime offset = CRationalTime_to_CppRationalTime(timeTransform.offset); return opentime::TimeTransform(offset, timeTransform.scale, timeTransform.rate); } + +OTIO_API void Opentime_Free(void *ptr); \ No newline at end of file diff --git a/src/copentime/CMakeLists.txt b/src/copentime/CMakeLists.txt index 486972b..d5c5104 100644 --- a/src/copentime/CMakeLists.txt +++ b/src/copentime/CMakeLists.txt @@ -11,6 +11,7 @@ add_library(copentime ${COTIO_SHARED_OR_STATIC_LIB} timeRange.cpp timeTransform.cpp optionalOpenTime.cpp + util.cpp ${PROJECT_SOURCE_DIR}/include/copentime/util.h ${COPENTIME_HEADER_FILES}) diff --git a/src/copentime/util.cpp b/src/copentime/util.cpp new file mode 100644 index 0000000..f45dc28 --- /dev/null +++ b/src/copentime/util.cpp @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright Contributors to the OpenTimelineIO project + +#include "copentime/util.h" + +OTIO_API void Opentime_Free(void *ptr){ + free(ptr); +} \ No newline at end of file