From 120bcfa03796e0b242ad18da976b82fa28791cfb Mon Sep 17 00:00:00 2001 From: ttldtor Date: Tue, 31 Oct 2023 21:44:38 +0300 Subject: [PATCH] Fix the resource releasing on Linux --- .../dxfeed_graal_cpp_api/internal/Common.hpp | 30 -------------- src/internal/Isolate.cpp | 40 +++++++++---------- 2 files changed, 19 insertions(+), 51 deletions(-) diff --git a/include/dxfeed_graal_cpp_api/internal/Common.hpp b/include/dxfeed_graal_cpp_api/internal/Common.hpp index 6a0b4dc9..faeaf8e6 100644 --- a/include/dxfeed_graal_cpp_api/internal/Common.hpp +++ b/include/dxfeed_graal_cpp_api/internal/Common.hpp @@ -85,36 +85,6 @@ constexpr To bit_cast(const From &from) return to; } -// final_action allows you to ensure something gets run at the end of a scope -template class final_action { - public: - explicit final_action(const F &ff) noexcept : f{ff} { - } - explicit final_action(F &&ff) noexcept : f{std::move(ff)} { - } - - ~final_action() noexcept { - if (invoke) - f(); - } - - final_action(final_action &&other) noexcept : f(std::move(other.f)), invoke(std::exchange(other.invoke, false)) { - } - - final_action(const final_action &) = delete; - void operator=(const final_action &) = delete; - void operator=(final_action &&) = delete; - - private: - F f; - bool invoke = true; -}; - -// finally() - convenience function to generate a final_action -template auto finally(F &&f) noexcept { - return final_action>{std::forward(f)}; -} - /// Lightweight implementation of "nullable bool" enum class Tristate : std::uint8_t { FALSE = 0, diff --git a/src/internal/Isolate.cpp b/src/internal/Isolate.cpp index 5569a664..2afe0f38 100644 --- a/src/internal/Isolate.cpp +++ b/src/internal/Isolate.cpp @@ -334,11 +334,11 @@ std::string InstrumentProfileReader::resolveSourceURL(const std::string &address }, nullptr, address); - finally([resolvedURL] { - String::release(resolvedURL); - }); + auto result = dxfcpp::toString(resolvedURL); - return dxfcpp::toString(resolvedURL); + String::release(resolvedURL); + + return result; } /* dxfg_ipf_collector_t* */ void *InstrumentProfileCollector::create() noexcept { @@ -429,11 +429,11 @@ std::string InstrumentProfileConnection::getAddress( return dxfcpp::String::EMPTY; } - finally([address] { - String::release(address); - }); + auto result = dxfcpp::toString(address); + + String::release(address); - return dxfcpp::toString(address); + return result; } std::int64_t InstrumentProfileConnection::getUpdatePeriod( @@ -684,11 +684,11 @@ std::string Day::toString(/* dxfg_day_t* */ void *day) noexcept { return dxfcpp::String::EMPTY; } - finally([string] { - String::release(string); - }); + auto result = dxfcpp::toString(string); + + String::release(string); - return dxfcpp::toString(string); + return result; } /* dxfg_session_filter_t* */ void *SessionFilter::getInstance(std::uint32_t code) noexcept { @@ -752,11 +752,11 @@ std::string Session::toString(/* dxfg_session_t* */ void *session) noexcept { return dxfcpp::String::EMPTY; } - finally([string] { - String::release(string); - }); + auto result = dxfcpp::toString(string); + + String::release(string); - return dxfcpp::toString(string); + return result; } /* dxfg_day_filter_t* */ void *DayFilter::getInstance(std::uint32_t code) noexcept { @@ -817,11 +817,7 @@ std::vector Schedule::getTradingVenues(/* dxfg_instrument_profile_t }, nullptr, dxfcpp::bit_cast(instrumentProfile)); - finally([graalStringList] { - StringList::release(graalStringList); - }); - - if (!graalStringList || graalStringList->size == 0) { + if (!graalStringList) { return result; } @@ -829,6 +825,8 @@ std::vector Schedule::getTradingVenues(/* dxfg_instrument_profile_t result.push_back(dxfcpp::toString(graalStringList->elements[i])); } + StringList::release(graalStringList); + return result; };