From f4112b79666ca09d044360840d2068f42792771a Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Wed, 4 Mar 2020 09:29:38 +0100 Subject: [PATCH 1/2] Switch from C++14 to C++17 This would help replace boost::optional with std::optional and completely remove Boost as a dependency of this project. --- CMakeLists.txt | 6 +++--- pkgconfig/libmultiprocess.pc.in | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6423211..04bcbfe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ target_include_directories(multiprocess PUBLIC ${Boost_INCLUDE_DIR}) set_target_properties(multiprocess PROPERTIES PUBLIC_HEADER "${MP_PUBLIC_HEADERS}" - CXX_STANDARD 14 + CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES) install(TARGETS multiprocess EXPORT Multiprocess ARCHIVE DESTINATION lib PUBLIC_HEADER DESTINATION include/mp) @@ -83,7 +83,7 @@ target_link_libraries(mpgen PRIVATE Threads::Threads) target_link_libraries(mpgen PRIVATE multiprocess) set_target_properties(mpgen PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE - CXX_STANDARD 14 + CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES) install(TARGETS mpgen EXPORT Multiprocess RUNTIME DESTINATION bin) @@ -135,7 +135,7 @@ if(BUILD_TESTING AND TARGET CapnProto::kj-test) target_link_libraries(mptest PRIVATE Threads::Threads) target_link_libraries(mptest PRIVATE multiprocess) set_target_properties(mptest PROPERTIES - CXX_STANDARD 14 + CXX_STANDARD 17 CXX_STANDARD_REQUIRED YES) add_test(NAME mptest COMMAND mptest) endif() diff --git a/pkgconfig/libmultiprocess.pc.in b/pkgconfig/libmultiprocess.pc.in index 506e356..d8bda42 100644 --- a/pkgconfig/libmultiprocess.pc.in +++ b/pkgconfig/libmultiprocess.pc.in @@ -9,4 +9,4 @@ Description: Multiprocess IPC library Version: 0.0 Libs: -L${libdir} -lmultiprocess -L${capnp_prefix}/lib -lcapnp-rpc -lcapnp -lkj-async -lkj -pthread -lpthread -Cflags: -std=c++14 -I${includedir} -I${capnp_prefix}/include -pthread +Cflags: -std=c++17 -I${includedir} -I${capnp_prefix}/include -pthread From 10b5c69dbc13282ac3f6d95b77e5ab59fe3990aa Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Wed, 4 Mar 2020 09:30:38 +0100 Subject: [PATCH 2/2] Obliterate Boost * While it may be possible to refactor the code in a way that it does not use any `optional` types, like in a616312, fb73b81, 138ad67, 5724a2c, that would be error prone and would require bigger changes. Instead replace `boost::optional` with `std::optional`, now that we are using C++17. * Removing `boost::current_exception_diagnostic_information()` - if the caught exception is an instance of `std::exception`, use its `what()` method. Otherwise don't provide extra diagnostic information. After all `boost::current_exception_diagnostic_information()` would return "No diagnostic information available." if it is not `std::exception` or `boost::exception`. * Clean up any mentions of Boost from README.md and CMakeLists.txt. --- CMakeLists.txt | 4 +--- README.md | 10 ++++------ include/mp/proxy-io.h | 4 ++-- include/mp/proxy-types.h | 17 +++++++++++------ 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04bcbfe..2ab8536 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,6 @@ project("Libmultiprocess" CXX) include(CMakePushCheckState) include(CTest) include(CheckCXXSourceCompiles) -find_package(Boost) find_package(CapnProto REQUIRED) find_package(Threads REQUIRED) @@ -64,8 +63,7 @@ target_include_directories(multiprocess PUBLIC $ $ $ - ${CAPNP_INCLUDE_DIRECTORY} - ${Boost_INCLUDE_DIR}) + ${CAPNP_INCLUDE_DIRECTORY}) set_target_properties(multiprocess PROPERTIES PUBLIC_HEADER "${MP_PUBLIC_HEADERS}" CXX_STANDARD 17 diff --git a/README.md b/README.md index 75e787e..625a2fd 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,12 @@ _libmultiprocess_ is currently compatible with sandboxing but could add platform ## Installation -Installation currently requires boost[*] and Cap'n Proto: +Installation currently requires Cap'n Proto: ```sh -apt install libboost-dev libcapnp-dev capnproto -brew install boost capnp -dnf install boost-devel capnproto +apt install libcapnp-dev capnproto +brew install capnp +dnf install capnproto Installation steps are: @@ -46,5 +46,3 @@ make make all test make install ``` - -[*] The boost dependency should be eliminated; it is solely for `boost::optional`. diff --git a/include/mp/proxy-io.h b/include/mp/proxy-io.h index cebb2c2..ec5d00a 100644 --- a/include/mp/proxy-io.h +++ b/include/mp/proxy-io.h @@ -10,13 +10,13 @@ #include -#include -#include #include #include #include +#include #include +#include #include namespace mp { diff --git a/include/mp/proxy-types.h b/include/mp/proxy-types.h index 5bb4414..255b702 100644 --- a/include/mp/proxy-types.h +++ b/include/mp/proxy-types.h @@ -6,6 +6,9 @@ #define MP_PROXY_TYPES_H #include + +#include +#include #include #include @@ -178,7 +181,7 @@ class Emplace Value& m_value; template - static T& call(boost::optional& value, Params&&... params) + static T& call(std::optional& value, Params&&... params) { value.emplace(std::forward(params)...); return *value; @@ -227,7 +230,7 @@ class Emplace }; template -void ReadFieldUpdate(TypeList>, +void ReadFieldUpdate(TypeList>, InvokeContext& invoke_context, Input&& input, DestValue&& value) @@ -832,7 +835,7 @@ LocalType BuildPrimitive(InvokeContext& invoke_context, } template -void CustomBuildField(TypeList>, +void CustomBuildField(TypeList>, Priority<1>, InvokeContext& invoke_context, Value&& value, @@ -1038,7 +1041,7 @@ template , ServerContext& server_context, Fn&& fn, Args&&... args) { InvokeContext& invoke_context = server_context; - boost::optional> param; + std::optional> param; const auto& params = server_context.call_context.getParams(); MaybeReadField(std::integral_constant(), TypeList(), invoke_context, Make(params), Emplace(param)); @@ -1434,9 +1437,11 @@ kj::Promise serverInvoke(Server& server, CallContext& call_context, Fn fn) server.m_connection.m_loop.log() << "IPC server send response #" << req << " " << TypeName() << " " << LogEscape(call_context.getResults().toString()); }); + } catch (const std::exception& e) { + server.m_connection.m_loop.log() << "IPC server unhandled exception: " << e.what(); + throw; } catch (...) { - server.m_connection.m_loop.log() - << "IPC server unhandled exception " << boost::current_exception_diagnostic_information(); + server.m_connection.m_loop.log() << "IPC server unhandled exception"; throw; } }