Skip to content

Commit

Permalink
[MDAPI-128] [C++] Split isolated (with GraalVM) entities into multipl…
Browse files Browse the repository at this point in the history
…e translation units.

IsolatedInstrumentProfileUpdateListener
Fix warnings on Win (/W4)
  • Loading branch information
ttldtor committed Sep 13, 2024
1 parent 3d65f74 commit dd5a7cc
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 37 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,13 @@ target_include_directories(${PROJECT_NAME}_static PRIVATE third_party/range-v3-$
target_compile_definitions(${PROJECT_NAME}_static PRIVATE
FMT_HEADER_ONLY=1 _SILENCE_ALL_MS_EXT_DEPRECATION_WARNINGS=1)

set(DXFCXX_MSVC_COMPILE_OPTIONS "/W2")
set(DXFCXX_MSVC_COMPILE_OPTIONS "/W4")
set(DXFCXX_MSVC_DEBUG_LINK_OPTIONS "/PDBALTPATH:$<TARGET_PDB_FILE_NAME:${PROJECT_NAME}>")
set(DXFCXX_GCC_LIKE_COMPILE_OPTIONS -fPIC -Wall -Wextra -pedantic)
set(DXFCXX_GCC_LIKE_LINK_OPTIONS "-fPIC")

#A workaround to fix 'relocation truncated to fit: IMAGE_REL_AMD64_SECREL' error (MinGW + Debug)
set(DXFCXX_MINGW_DEBUG_LINK_OPTIONS "-Wl,--disable-dynamicbase,--disable-high-entropy-va,--default-image-base-low")
set(MINGW_DEBUG_LINK_OPTIONS "-Wl,--disable-dynamicbase,--disable-high-entropy-va,--default-image-base-low")

# https://developercommunity.visualstudio.com/t/Invalid-code-generation-in-release-1940/10678572?sort=newest&viewtype=all
# https://github.com/microsoft/STL/wiki/Changelog#vs-2022-1710
Expand Down
2 changes: 2 additions & 0 deletions include/dxfeed_graal_cpp_api/internal/PrecompiledHeaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251 4996)

#include <utf8.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

#include "Common.hpp"
#include "Handler.hpp"
Expand Down
5 changes: 0 additions & 5 deletions include/dxfeed_graal_cpp_api/isolated/Isolated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ struct InstrumentProfileIterator {
static /* dxfg_instrument_profile_t* */ void *next(/* dxfg_iterable_ip_t * */ void *iterable) noexcept;
};

struct InstrumentProfileUpdateListener {
static /* dxfg_ipf_update_listener_t* */ void *create(/* dxfg_ipf_update_listener_function */ void *userFunc,
void *userData) noexcept;
};

} // namespace ipf

namespace ondemand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4251)

DXFCPP_BEGIN_NAMESPACE

namespace isolated::ipf::live::IsolatedInstrumentProfileCollector {
namespace isolated::ipf::live {

namespace IsolatedInstrumentProfileCollector {

/* dxfg_ipf_collector_t* */ JavaObjectHandle<InstrumentProfileCollector> create();
std::int64_t getLastUpdateTime(
/* dxfg_ipf_collector_t* */ const JavaObjectHandle<InstrumentProfileCollector> &instrumentProfileCollector);
Expand All @@ -30,7 +33,16 @@ bool addUpdateListener(
bool removeUpdateListener(
/* dxfg_ipf_collector_t* */ const JavaObjectHandle<InstrumentProfileCollector> &instrumentProfileCollector,
/* dxfg_ipf_update_listener_t* */ const JavaObjectHandle<dxfcpp::InstrumentProfileUpdateListener> &listener);
} // namespace isolated::ipf::live::IsolatedInstrumentProfileCollector

} // namespace IsolatedInstrumentProfileCollector

namespace IsolatedInstrumentProfileUpdateListener {

/* dxfg_ipf_update_listener_t* */ JavaObjectHandle<dxfcpp::InstrumentProfileUpdateListener>
create(/* dxfg_ipf_update_listener_function */ void *userFunc, void *userData);

}
} // namespace isolated::ipf::live

DXFCPP_END_NAMESPACE

Expand Down
2 changes: 1 addition & 1 deletion include/dxfeed_graal_cpp_api/promise/Promise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ template <typename E, typename P> struct EventsPromiseMixin {
timeout = std::numeric_limits<std::int32_t>::max();
}

static_cast<const P *>(this)->impl.await(timeout);
static_cast<const P *>(this)->impl.await(static_cast<std::int32_t>(timeout));

return getResult();
}
Expand Down
2 changes: 2 additions & 0 deletions samples/cpp/DxFeedConnect/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
#include <mutex>
#include <string>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

using namespace dxfcpp;
using namespace dxfcpp::literals;
Expand Down
2 changes: 2 additions & 0 deletions samples/cpp/PublishProfiles/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

#include <string>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

using namespace dxfcpp;
using namespace dxfcpp::literals;
Expand Down
16 changes: 0 additions & 16 deletions src/internal/Isolate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,22 +373,6 @@ InstrumentProfileIterator::next(/* dxfg_iterable_ip_t * */ void *iterable) noexc
nullptr, static_cast<dxfg_iterable_ip_t *>(iterable)));
}

/* dxfg_ipf_update_listener_t* */ void *
InstrumentProfileUpdateListener::create(/* dxfg_ipf_update_listener_function */ void *userFunc,
void *userData) noexcept {
if (!userFunc) {
// TODO: Improve error handling
return nullptr;
}

return static_cast<void *>(runIsolatedOrElse(
[](auto threadHandle, auto &&userFunc, auto &&userData) {
return dxfg_InstrumentProfileUpdateListener_new(static_cast<graal_isolatethread_t *>(threadHandle),
userFunc, userData);
},
nullptr, dxfcpp::bit_cast<dxfg_ipf_update_listener_function>(userFunc), userData));
}

} // namespace ipf

namespace ondemand {
Expand Down
18 changes: 13 additions & 5 deletions src/internal/utils/CmdArgsUtils.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Copyright (c) 2024 Devexperts LLC.
// SPDX-License-Identifier: MPL-2.0

#define _CRT_SECURE_NO_WARNINGS

#include <dxfg_api.h>

#include <dxfeed_graal_c_api/api.h>
#include <dxfeed_graal_cpp_api/api.hpp>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4996)

#include <chrono>
#include <cstring>
#include <ctime>
Expand All @@ -22,7 +26,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

#if !defined(__cpp_lib_chrono) || (__cpp_lib_chrono < 201907L)
# include <date/date.h>
Expand All @@ -47,15 +53,15 @@ decltype(ranges::views::transform([](auto &&s) {
return s | ranges::to<std::string>();
})) transformToString{};

decltype(ranges::views::transform([](const std::string &s) {
return trimStr(s);
})) trim{};

auto splitAndTrim = [](auto &&symbols, char sep = ',') noexcept {
decltype(ranges::views::transform([](const std::string &s) {
return trimStr(s);
})) trim{};

return symbols | ranges::views::split(sep) | filterNonEmpty | transformToString | trim;
};

auto toUpper = [](auto&& s) {
auto toUpper = [](auto &&s) {
auto locale = std::locale{};

return s | ranges::views::transform([&locale](auto c) {
Expand Down Expand Up @@ -232,3 +238,5 @@ std::unordered_map<std::string, std::string> CmdArgsUtils::parseProperties(const
}

DXFCPP_END_NAMESPACE

DXFCXX_DISABLE_MSC_WARNINGS_POP()
2 changes: 2 additions & 0 deletions src/internal/utils/EnumUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

using namespace std::literals;

Expand Down
2 changes: 2 additions & 0 deletions src/internal/utils/StringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

DXFCPP_BEGIN_NAMESPACE

Expand Down
4 changes: 2 additions & 2 deletions src/ipf/live/InstrumentProfileCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ void InstrumentProfileCollector::addListenerHandle(std::size_t id) {
}

listenerHandles_.emplace(
id, JavaObjectHandle<InstrumentProfileUpdateListener>(isolated::ipf::InstrumentProfileUpdateListener::create(
id, isolated::ipf::live::IsolatedInstrumentProfileUpdateListener::create(
dxfcpp::bit_cast<void *>(&InstrumentProfileCollector::Impl::onInstrumentProfilesUpdate),
dxfcpp::bit_cast<void *>(dxfcpp::pack(id_.getValue(), id)))));
dxfcpp::bit_cast<void *>(dxfcpp::pack(id_.getValue(), id))));

if (!listenerHandles_[id]) {
return;
Expand Down
24 changes: 22 additions & 2 deletions src/isolated/ipf/live/IsolatedInstrumentProfileCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

DXFCPP_BEGIN_NAMESPACE

namespace isolated::ipf::live::IsolatedInstrumentProfileCollector {
namespace isolated::ipf::live {

namespace IsolatedInstrumentProfileCollector {
/* dxfg_ipf_collector_t* */ JavaObjectHandle<InstrumentProfileCollector> create() {
return JavaObjectHandle<InstrumentProfileCollector>{
runGraalFunctionAndThrowIfNullptr(dxfg_InstrumentProfileCollector_new)};
Expand Down Expand Up @@ -79,6 +81,24 @@ bool removeUpdateListener(
static_cast<dxfg_ipf_update_listener_t *>(listener.get())) == 0;
}

} // namespace isolated::ipf::live::IsolatedInstrumentProfileCollector
} // namespace IsolatedInstrumentProfileCollector

namespace IsolatedInstrumentProfileUpdateListener {

/* dxfg_ipf_update_listener_t* */ JavaObjectHandle<dxfcpp::InstrumentProfileUpdateListener>
create(/* dxfg_ipf_update_listener_function */ void *userFunc, void *userData) {
if (!userFunc) {
throw InvalidArgumentException("Unable to execute function `dxfg_InstrumentProfileUpdateListener_new`. The "
"`userFunc` is nullptr");
}

return JavaObjectHandle<dxfcpp::InstrumentProfileUpdateListener>{
runGraalFunctionAndThrowIfNullptr(dxfg_InstrumentProfileUpdateListener_new,
dxfcpp::bit_cast<dxfg_ipf_update_listener_function>(userFunc), userData)};
}

} // namespace IsolatedInstrumentProfileUpdateListener

} // namespace isolated::ipf::live

DXFCPP_END_NAMESPACE
5 changes: 3 additions & 2 deletions tests/api/DXEndpointTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ TEST_CASE("Test DXEndpoint + multi-thread setProperty") {
auto endpoint = DXEndpoint::create();

for (int i = 0; i < 1000; ++i) {
std::thread t{[] {
std::thread t2{[] {
System::setProperty("test", "test");
}};
t.join();

t2.join();
}

endpoint->close();
Expand Down
2 changes: 2 additions & 0 deletions tests/schedule/ScheduleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include <dxfeed_graal_c_api/api.h>
#include <dxfeed_graal_cpp_api/api.hpp>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

#include <doctest.h>

Expand Down
2 changes: 2 additions & 0 deletions tools/Tools/src/Args/Args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

namespace dxfcpp::tools {

Expand Down
2 changes: 2 additions & 0 deletions tools/Tools/src/Connect/ConnectTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

namespace dxfcpp::tools {

Expand Down
2 changes: 2 additions & 0 deletions tools/Tools/src/Dump/DumpTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

namespace dxfcpp::tools {

Expand Down
2 changes: 2 additions & 0 deletions tools/Tools/src/Help/HelpTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

#include <console/console.hpp>

Expand Down
2 changes: 2 additions & 0 deletions tools/Tools/src/LatencyTest/LatencyTestTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

namespace dxfcpp::tools {

Expand Down
2 changes: 2 additions & 0 deletions tools/Tools/src/PerfTest/PerfTestTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

namespace dxfcpp::tools {

Expand Down
2 changes: 2 additions & 0 deletions tools/Tools/src/Qds/QdsTool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

#include "../Args/Args.hpp"

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

namespace dxfcpp::tools {

Expand Down
2 changes: 2 additions & 0 deletions tools/Tools/src/Tools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#include <fmt/ostream.h>
#include <fmt/std.h>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

namespace dxfcpp::tools {

Expand Down
2 changes: 2 additions & 0 deletions tools/Tools/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

#include <process/process.hpp>

DXFCXX_DISABLE_MSC_WARNINGS_PUSH(4702)
#include <range/v3/all.hpp>
DXFCXX_DISABLE_MSC_WARNINGS_POP()

template <class... Ts> struct overloaded : Ts... {
using Ts::operator()...;
Expand Down

0 comments on commit dd5a7cc

Please sign in to comment.