diff --git a/CMakeLists.txt b/CMakeLists.txt index 3699522b..2df3738a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.8) project("Libmultiprocess" CXX) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED YES) endif() diff --git a/example/calculator.cpp b/example/calculator.cpp index 4290d687..ae69ce8a 100644 --- a/example/calculator.cpp +++ b/example/calculator.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include // NOLINT(misc-include-cleaner) @@ -44,8 +45,12 @@ int main(int argc, char** argv) std::cout << "Usage: mpcalculator \n"; return 1; } + int fd; + if (std::from_chars(argv[1], argv[1] + strlen(argv[1]), fd).ec != std::errc{}) { + std::cerr << argv[1] << " is not a number or is larger than an int\n"; + return 1; + } mp::EventLoop loop("mpcalculator", LogPrint); - const int fd = std::stoi(argv[1]); std::unique_ptr init = std::make_unique(); mp::ServeStream(loop, fd, *init); loop.loop(); diff --git a/example/example.cpp b/example/example.cpp index a4f84c55..878ad4c5 100644 --- a/example/example.cpp +++ b/example/example.cpp @@ -3,6 +3,7 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -25,7 +26,7 @@ static auto Spawn(mp::EventLoop& loop, const std::string& process_argv0, const s fs::path path = process_argv0; path.remove_filename(); path.append(new_exe_name); - return {path.string(), std::to_string(fd)}; + return {path.string(), std::format("{:d}", fd)}; }); return std::make_tuple(mp::ConnectStream(loop, fd), pid); } diff --git a/example/printer.cpp b/example/printer.cpp index ccaed689..9f85d450 100644 --- a/example/printer.cpp +++ b/example/printer.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include #include // NOLINT(misc-include-cleaner) @@ -37,8 +38,12 @@ int main(int argc, char** argv) std::cout << "Usage: mpprinter \n"; return 1; } + int fd; + if (std::from_chars(argv[1], argv[1] + strlen(argv[1]), fd).ec != std::errc{}) { + std::cerr << argv[1] << " is not a number or is larger than an int\n"; + return 1; + } mp::EventLoop loop("mpprinter", LogPrint); - const int fd = std::stoi(argv[1]); std::unique_ptr init = std::make_unique(); mp::ServeStream(loop, fd, *init); loop.loop(); diff --git a/src/mp/gen.cpp b/src/mp/gen.cpp index c4d9a516..267c2837 100644 --- a/src/mp/gen.cpp +++ b/src/mp/gen.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -637,7 +638,7 @@ static void Generate(kj::StringPtr src_prefix, int main(int argc, char** argv) { if (argc < 3) { - fprintf(stderr, "Usage: " PROXY_BIN " SRC_PREFIX INCLUDE_PREFIX SRC_FILE [IMPORT_PATH...]\n"); + std::cerr << "Usage: " << PROXY_BIN << " SRC_PREFIX INCLUDE_PREFIX SRC_FILE [IMPORT_PATH...]\n"; exit(1); } std::vector import_paths; diff --git a/src/mp/util.cpp b/src/mp/util.cpp index 691ae0b3..15c40b33 100644 --- a/src/mp/util.cpp +++ b/src/mp/util.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -85,9 +86,7 @@ std::string LogEscape(const kj::StringTree& string) if (c == '\\') { result.append("\\\\"); } else if (c < 0x20 || c > 0x7e) { - char escape[4]; - snprintf(escape, 4, "\\%02x", c); - result.append(escape); + result.append(std::format("\\{:02x}", c)); } else { result.push_back(c); } diff --git a/test/mp/test/test.cpp b/test/mp/test/test.cpp index 7721d41f..7fc64f67 100644 --- a/test/mp/test/test.cpp +++ b/test/mp/test/test.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,9 @@ KJ_TEST("Call FooInterface methods") std::promise>> foo_promise; std::function disconnect_client; std::thread thread([&]() { - EventLoop loop("mptest", [](bool raise, const std::string& log) { printf("LOG%i: %s\n", raise, log.c_str()); }); + EventLoop loop("mptest", [](bool raise, const std::string& log) { + std::cout << "LOG" << raise << ": " << log << "\n"; + }); auto pipe = loop.m_io_context.provider->newTwoWayPipe(); auto connection_client = std::make_unique(loop, kj::mv(pipe.ends[0]));