From 0687cac4bb74861e28cb8ac4bf46b2a246aef7bd Mon Sep 17 00:00:00 2001 From: actboy168 Date: Tue, 12 Mar 2024 09:59:19 +0800 Subject: [PATCH] add noexcept --- bee/filewatch/filewatch.h | 20 ++++++------- bee/filewatch/filewatch_linux.cpp | 12 ++++---- bee/filewatch/filewatch_osx.cpp | 14 ++++----- bee/filewatch/filewatch_win.cpp | 18 ++++++------ bee/net/socket.cpp | 10 +++---- bee/net/socket.h | 6 ++-- bee/platform/version.cpp | 6 ++-- bee/platform/version.h | 2 +- bee/platform/win/module_version.h | 4 +-- bee/platform/win/module_version_win.cpp | 4 +-- bee/platform/win/unicode.h | 12 ++++---- bee/platform/win/unicode_win.cpp | 12 ++++---- bee/subprocess/process_select.cpp | 2 +- bee/subprocess/process_select.h | 2 +- bee/subprocess/subprocess_posix.cpp | 30 +++++++++---------- bee/subprocess/subprocess_posix.h | 34 +++++++++++----------- bee/subprocess/subprocess_win.cpp | 38 ++++++++++++------------- bee/subprocess/subprocess_win.h | 14 ++++----- bee/thread/setname.cpp | 2 +- bee/thread/setname.h | 2 +- bee/utility/dynarray.h | 8 +++--- bee/utility/path_helper.cpp | 31 +++++++++++--------- bee/utility/path_helper.h | 6 ++-- 23 files changed, 147 insertions(+), 142 deletions(-) diff --git a/bee/filewatch/filewatch.h b/bee/filewatch/filewatch.h index 940c25c9..9f0d9ab5 100644 --- a/bee/filewatch/filewatch.h +++ b/bee/filewatch/filewatch.h @@ -30,7 +30,7 @@ namespace bee::filewatch { }; flag flags; std::string path; - notify(const flag& flags, const std::string& path) + notify(const flag& flags, const std::string& path) noexcept : flags(flags) , path(path) {} }; @@ -47,30 +47,30 @@ namespace bee::filewatch { static inline filter DefaultFilter = [](const char*) { return true; }; watch() noexcept; - ~watch(); + ~watch() noexcept; void stop() noexcept; - void add(const string_type& path); + void add(const string_type& path) noexcept; void set_recursive(bool enable) noexcept; bool set_follow_symlinks(bool enable) noexcept; - bool set_filter(filter f = DefaultFilter); - void update(); - std::optional select(); + bool set_filter(filter f = DefaultFilter) noexcept; + void update() noexcept; + std::optional select() noexcept; private: #if defined(_WIN32) - bool event_update(task& task); + bool event_update(task& task) noexcept; #elif defined(__APPLE__) bool create_stream(CFArrayRef cf_paths) noexcept; void destroy_stream() noexcept; - void update_stream(); + void update_stream() noexcept; public: - void event_update(const char* paths[], const FSEventStreamEventFlags flags[], size_t n); + void event_update(const char* paths[], const FSEventStreamEventFlags flags[], size_t n) noexcept; private: #elif defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) - void event_update(void* event); + void event_update(void* event) noexcept; #endif private: diff --git a/bee/filewatch/filewatch_linux.cpp b/bee/filewatch/filewatch_linux.cpp index f705095c..66aa3b8c 100644 --- a/bee/filewatch/filewatch_linux.cpp +++ b/bee/filewatch/filewatch_linux.cpp @@ -22,7 +22,7 @@ namespace bee::filewatch { assert(m_inotify_fd != -1); } - watch::~watch() { + watch::~watch() noexcept { stop(); } @@ -39,7 +39,7 @@ namespace bee::filewatch { m_inotify_fd = -1; } - void watch::add(const string_type& str) { + void watch::add(const string_type& str) noexcept { if (m_inotify_fd == -1) { return; } @@ -84,12 +84,12 @@ namespace bee::filewatch { return true; } - bool watch::set_filter(filter f) { + bool watch::set_filter(filter f) noexcept { m_filter = f; return true; } - void watch::update() { + void watch::update() noexcept { if (m_inotify_fd == -1) { return; } @@ -113,7 +113,7 @@ namespace bee::filewatch { } } - void watch::event_update(void* e) { + void watch::event_update(void* e) noexcept { inotify_event* event = (inotify_event*)e; if (event->mask & IN_Q_OVERFLOW) { // TODO? @@ -143,7 +143,7 @@ namespace bee::filewatch { } } - std::optional watch::select() { + std::optional watch::select() noexcept { if (m_notify.empty()) { return std::nullopt; } diff --git a/bee/filewatch/filewatch_osx.cpp b/bee/filewatch/filewatch_osx.cpp index ef64f3b1..f9ec2d50 100644 --- a/bee/filewatch/filewatch_osx.cpp +++ b/bee/filewatch/filewatch_osx.cpp @@ -6,7 +6,7 @@ namespace bee::filewatch { return "fsevent"; } - static void event_cb(ConstFSEventStreamRef streamRef, void* info, size_t numEvents, void* eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]) { + static void event_cb(ConstFSEventStreamRef streamRef, void* info, size_t numEvents, void* eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[]) noexcept { (void)streamRef; (void)eventIds; watch* self = (watch*)info; @@ -65,7 +65,7 @@ namespace bee::filewatch { m_stream = NULL; } - void watch::add(const string_type& path) { + void watch::add(const string_type& path) noexcept { m_paths.emplace(path); update_stream(); } @@ -78,11 +78,11 @@ namespace bee::filewatch { return false; } - bool watch::set_filter(filter f) { + bool watch::set_filter(filter f) noexcept { return false; } - void watch::update_stream() { + void watch::update_stream() noexcept { destroy_stream(); if (m_paths.empty()) { return; @@ -106,10 +106,10 @@ namespace bee::filewatch { CFRelease(cf_paths); } - void watch::update() { + void watch::update() noexcept { } - void watch::event_update(const char* paths[], const FSEventStreamEventFlags flags[], size_t n) { + void watch::event_update(const char* paths[], const FSEventStreamEventFlags flags[], size_t n) noexcept { std::unique_lock lock(m_mutex); for (size_t i = 0; i < n; ++i) { const char* path = paths[i]; @@ -125,7 +125,7 @@ namespace bee::filewatch { } } - std::optional watch::select() { + std::optional watch::select() noexcept { std::unique_lock lock(m_mutex); if (m_notify.empty()) { return std::nullopt; diff --git a/bee/filewatch/filewatch_win.cpp b/bee/filewatch/filewatch_win.cpp index 3d97d09d..71ce244a 100644 --- a/bee/filewatch/filewatch_win.cpp +++ b/bee/filewatch/filewatch_win.cpp @@ -17,7 +17,7 @@ namespace bee::filewatch { public: task() noexcept; - ~task(); + ~task() noexcept; enum class result { success, @@ -26,7 +26,7 @@ namespace bee::filewatch { zero, }; - bool open(const std::wstring& path); + bool open(const std::wstring& path) noexcept; bool start(bool recursive) noexcept; void cancel() noexcept; result try_read() noexcept; @@ -47,11 +47,11 @@ namespace bee::filewatch { hEvent = CreateEventW(NULL, TRUE, FALSE, NULL); } - task::~task() { + task::~task() noexcept { assert(m_directory == INVALID_HANDLE_VALUE); } - bool task::open(const std::wstring& path) { + bool task::open(const std::wstring& path) noexcept { if (m_directory != INVALID_HANDLE_VALUE) { return true; } @@ -152,7 +152,7 @@ namespace bee::filewatch { m_tasks.clear(); } - void watch::add(const string_type& path) { + void watch::add(const string_type& path) noexcept { auto& t = m_tasks.emplace_back(); if (t.open(path)) { if (t.start(m_recursive)) { @@ -170,11 +170,11 @@ namespace bee::filewatch { return false; } - bool watch::set_filter(filter f) { + bool watch::set_filter(filter f) noexcept { return false; } - bool watch::event_update(task& task) { + bool watch::event_update(task& task) noexcept { switch (task.try_read()) { case task::result::wait: return true; @@ -213,7 +213,7 @@ namespace bee::filewatch { return task.start(m_recursive); } - void watch::update() { + void watch::update() noexcept { for (auto iter = m_tasks.begin(); iter != m_tasks.end();) { if (event_update(*iter)) { ++iter; @@ -224,7 +224,7 @@ namespace bee::filewatch { } } - std::optional watch::select() { + std::optional watch::select() noexcept { if (m_notify.empty()) { return std::nullopt; } diff --git a/bee/net/socket.cpp b/bee/net/socket.cpp index 0873cefe..de5c378d 100644 --- a/bee/net/socket.cpp +++ b/bee/net/socket.cpp @@ -129,7 +129,7 @@ namespace bee::net::socket { } static WSAPROTOCOL_INFOW UnixProtocol; - static bool supportUnixDomainSocket_() { + static bool supportUnixDomainSocket_() noexcept { static GUID AF_UNIX_PROVIDER_ID = { 0xA00943D9, 0x9C2E, 0x4633, { 0x9B, 0x59, 0x00, 0x57, 0xA3, 0x16, 0x09, 0x94 } }; DWORD len = 0; ::WSAEnumProtocolsW(0, NULL, &len); @@ -152,7 +152,7 @@ namespace bee::net::socket { } return false; } - static bool supportUnixDomainSocket() { + static bool supportUnixDomainSocket() noexcept { static bool support = supportUnixDomainSocket_(); return support; } @@ -499,7 +499,7 @@ namespace bee::net::socket { return status::success; } - expected recvfrom(fd_t s, int& rc, char* buf, int len) { + expected recvfrom(fd_t s, int& rc, char* buf, int len) noexcept { endpoint ep; rc = ::recvfrom(s, buf, len, 0, ep.out_addr(), ep.out_addrlen()); if (rc == 0) { @@ -524,7 +524,7 @@ namespace bee::net::socket { return status::success; } - std::optional getpeername(fd_t s) { + std::optional getpeername(fd_t s) noexcept { endpoint ep; const int ok = ::getpeername(s, ep.out_addr(), ep.out_addrlen()); if (!net_success(ok)) { @@ -533,7 +533,7 @@ namespace bee::net::socket { return ep; } - std::optional getsockname(fd_t s) { + std::optional getsockname(fd_t s) noexcept { endpoint ep; const int ok = ::getsockname(s, ep.out_addr(), ep.out_addrlen()); if (!net_success(ok)) { diff --git a/bee/net/socket.h b/bee/net/socket.h index 4903e193..4924f631 100644 --- a/bee/net/socket.h +++ b/bee/net/socket.h @@ -63,10 +63,10 @@ namespace bee::net::socket { fdstat accept(fd_t s, fd_t& newfd, fd_flags flags = fd_flags::nonblock) noexcept; status recv(fd_t s, int& rc, char* buf, int len) noexcept; status send(fd_t s, int& rc, const char* buf, int len) noexcept; - expected recvfrom(fd_t s, int& rc, char* buf, int len); + expected recvfrom(fd_t s, int& rc, char* buf, int len) noexcept; status sendto(fd_t s, int& rc, const char* buf, int len, const endpoint& ep) noexcept; - std::optional getpeername(fd_t s); - std::optional getsockname(fd_t s); + std::optional getpeername(fd_t s) noexcept; + std::optional getsockname(fd_t s) noexcept; bool unlink(const endpoint& ep); std::error_code errcode(fd_t s) noexcept; fd_t dup(fd_t s) noexcept; diff --git a/bee/platform/version.cpp b/bee/platform/version.cpp index 0721f902..a4d36dc1 100644 --- a/bee/platform/version.cpp +++ b/bee/platform/version.cpp @@ -32,7 +32,7 @@ namespace bee { } # if defined(_WIN32) - static uint32_t toint(std::wstring_view wstr, uint32_t def = 0) { + static uint32_t toint(std::wstring_view wstr, uint32_t def = 0) noexcept { std::string str; str.resize(wstr.size()); for (size_t i = 0; i < wstr.size(); ++i) { @@ -46,7 +46,7 @@ namespace bee { # endif template - static version to_version(std::basic_string_view verstr) { + static version to_version(std::basic_string_view verstr) noexcept { constexpr auto npos = std::basic_string_view::npos; version v { 0, 0, 0 }; size_t pos = 0; @@ -68,7 +68,7 @@ namespace bee { } #endif - version os_version() { + version os_version() noexcept { #if defined(__APPLE__) // id processInfo = [NSProcessInfo processInfo] id processInfo = reinterpret_cast(objc_msgSend)(objc_getClass("NSProcessInfo"), sel_getUid("processInfo")); diff --git a/bee/platform/version.h b/bee/platform/version.h index 4efdd495..e748d12c 100644 --- a/bee/platform/version.h +++ b/bee/platform/version.h @@ -22,5 +22,5 @@ namespace bee { } }; - version os_version(); + version os_version() noexcept; } diff --git a/bee/platform/win/module_version.h b/bee/platform/win/module_version.h index 61c06194..a640aaab 100644 --- a/bee/platform/win/module_version.h +++ b/bee/platform/win/module_version.h @@ -9,9 +9,9 @@ namespace bee::win { class module_version { public: - module_version(const wchar_t* module_path); + module_version(const wchar_t* module_path) noexcept; bool select_language(uint16_t langid) noexcept; - std::wstring_view get_value(const wchar_t* key) const; + std::wstring_view get_value(const wchar_t* key) const noexcept; protected: struct translation { diff --git a/bee/platform/win/module_version_win.cpp b/bee/platform/win/module_version_win.cpp index 0df859a1..9e937a9d 100644 --- a/bee/platform/win/module_version_win.cpp +++ b/bee/platform/win/module_version_win.cpp @@ -4,7 +4,7 @@ namespace bee::win { - module_version::module_version(const wchar_t* module_path) + module_version::module_version(const wchar_t* module_path) noexcept : current_(0) , translation_() , version_info_() { @@ -36,7 +36,7 @@ namespace bee::win { select_language(::GetUserDefaultLangID()); } - std::wstring_view module_version::get_value(const wchar_t* key) const { + std::wstring_view module_version::get_value(const wchar_t* key) const noexcept { if (translation_.empty()) { return L""; } diff --git a/bee/platform/win/unicode.h b/bee/platform/win/unicode.h index 1e4c6cef..a6937089 100644 --- a/bee/platform/win/unicode.h +++ b/bee/platform/win/unicode.h @@ -5,10 +5,10 @@ #include namespace bee::win { - std::wstring u2w(zstring_view str); - std::string w2u(wzstring_view wstr); - std::wstring a2w(zstring_view str); - std::string w2a(wzstring_view wstr); - std::string a2u(zstring_view str); - std::string u2a(zstring_view str); + std::wstring u2w(zstring_view str) noexcept; + std::string w2u(wzstring_view wstr) noexcept; + std::wstring a2w(zstring_view str) noexcept; + std::string w2a(wzstring_view wstr) noexcept; + std::string a2u(zstring_view str) noexcept; + std::string u2a(zstring_view str) noexcept; } diff --git a/bee/platform/win/unicode_win.cpp b/bee/platform/win/unicode_win.cpp index a4a0f87b..dd10f78b 100644 --- a/bee/platform/win/unicode_win.cpp +++ b/bee/platform/win/unicode_win.cpp @@ -2,7 +2,7 @@ #include namespace bee::win { - std::wstring u2w(zstring_view str) { + std::wstring u2w(zstring_view str) noexcept { if (str.empty()) { return L""; } @@ -15,7 +15,7 @@ namespace bee::win { return wresult; } - std::string w2u(wzstring_view wstr) { + std::string w2u(wzstring_view wstr) noexcept { if (wstr.empty()) { return ""; } @@ -28,7 +28,7 @@ namespace bee::win { return result; } - std::wstring a2w(zstring_view str) { + std::wstring a2w(zstring_view str) noexcept { if (str.empty()) { return L""; } @@ -41,7 +41,7 @@ namespace bee::win { return wresult; } - std::string w2a(wzstring_view wstr) { + std::string w2a(wzstring_view wstr) noexcept { if (wstr.empty()) { return ""; } @@ -54,11 +54,11 @@ namespace bee::win { return result; } - std::string a2u(zstring_view str) { + std::string a2u(zstring_view str) noexcept { return w2u(a2w(str)); } - std::string u2a(zstring_view str) { + std::string u2a(zstring_view str) noexcept { return w2a(u2w(str)); } } diff --git a/bee/subprocess/process_select.cpp b/bee/subprocess/process_select.cpp index 16ecd00a..edd06936 100644 --- a/bee/subprocess/process_select.cpp +++ b/bee/subprocess/process_select.cpp @@ -8,7 +8,7 @@ #endif namespace bee::subprocess { - status process_select(const dynarray& set, int timeout) { + status process_select(const dynarray& set, int timeout) noexcept { #if defined(_WIN32) if (set.size() >= MAXIMUM_WAIT_OBJECTS) { SetLastError(ERROR_INVALID_PARAMETER); diff --git a/bee/subprocess/process_select.h b/bee/subprocess/process_select.h index a05ccb58..b4d29881 100644 --- a/bee/subprocess/process_select.h +++ b/bee/subprocess/process_select.h @@ -9,5 +9,5 @@ namespace bee::subprocess { timeout, failed, }; - status process_select(const dynarray& set, int timeout); + status process_select(const dynarray& set, int timeout) noexcept; } diff --git a/bee/subprocess/subprocess_posix.cpp b/bee/subprocess/subprocess_posix.cpp index 04f50f2f..c7f000b0 100644 --- a/bee/subprocess/subprocess_posix.cpp +++ b/bee/subprocess/subprocess_posix.cpp @@ -23,30 +23,30 @@ extern char** environ; namespace bee::subprocess { - args_t::~args_t() { + args_t::~args_t() noexcept { for (size_t i = 0; i < size(); ++i) { delete[] (data_[i]); } } - void args_t::push(char* str) { + void args_t::push(char* str) noexcept { data_.emplace_back(str); } - void args_t::push(zstring_view str) { + void args_t::push(zstring_view str) noexcept { dynarray tmp(str.data(), str.size() + 1); data_.emplace_back(tmp.release()); } - void envbuilder::set(const std::string& key, const std::string& value) { + void envbuilder::set(const std::string& key, const std::string& value) noexcept { set_env_[key] = value; } - void envbuilder::del(const std::string& key) { + void envbuilder::del(const std::string& key) noexcept { set_env_[key] = std::nullopt; } - static void env_append(std::vector& envs, const std::string& k, const std::string& v) { + static void env_append(std::vector& envs, const std::string& k, const std::string& v) noexcept { size_t n = k.size() + v.size() + 2; dynarray tmp(n); memcpy(tmp.data(), k.data(), k.size()); @@ -56,12 +56,12 @@ namespace bee::subprocess { envs.emplace_back(tmp.release()); } - static dynarray env_release(std::vector& envs) { + static dynarray env_release(std::vector& envs) noexcept { envs.emplace_back(nullptr); return { envs }; } - environment envbuilder::release() { + environment envbuilder::release() noexcept { char** es = environ; if (es == 0) { return nullptr; @@ -92,27 +92,27 @@ namespace bee::subprocess { return env_release(envs); } - spawn::spawn() { + spawn::spawn() noexcept { fds_[0] = -1; fds_[1] = -1; fds_[2] = -1; } - void spawn::suspended() { + void spawn::suspended() noexcept { #if defined(POSIX_SPAWN_START_SUSPENDED) // apple extension spawnattr_ |= POSIX_SPAWN_START_SUSPENDED; #endif } - void spawn::detached() { + void spawn::detached() noexcept { #if defined(POSIX_SPAWN_SETSID) // since glibc 2.26 spawnattr_ |= POSIX_SPAWN_SETSID; #endif } - void spawn::redirect(stdio type, file_handle h) { + void spawn::redirect(stdio type, file_handle h) noexcept { switch (type) { case stdio::eInput: fds_[0] = h.value(); @@ -128,7 +128,7 @@ namespace bee::subprocess { } } - void spawn::env(environment&& env) { + void spawn::env(environment&& env) noexcept { env_ = std::move(env); } @@ -141,7 +141,7 @@ namespace bee::subprocess { # define USE_POSIX_SPAWN 1 #endif - bool spawn::exec(args_t& args, const char* cwd) { + bool spawn::exec(args_t& args, const char* cwd) noexcept { if (args.size() == 0) { return false; } @@ -265,7 +265,7 @@ namespace bee::subprocess { return 0 == ::kill(pid, signum); } - static uint32_t make_status(int status) { + static uint32_t make_status(int status) noexcept { if (WIFEXITED(status)) { return WEXITSTATUS(status); } diff --git a/bee/subprocess/subprocess_posix.h b/bee/subprocess/subprocess_posix.h index e624d426..8ddf4ee5 100644 --- a/bee/subprocess/subprocess_posix.h +++ b/bee/subprocess/subprocess_posix.h @@ -11,9 +11,9 @@ namespace bee::subprocess { class envbuilder { public: - void set(const std::string& key, const std::string& value); - void del(const std::string& key); - environment release(); + void set(const std::string& key, const std::string& value) noexcept; + void del(const std::string& key) noexcept; + environment release() noexcept; private: std::map> set_env_; @@ -39,22 +39,22 @@ namespace bee::subprocess { }; struct args_t { - ~args_t(); - void push(char* str); - void push(zstring_view str); - char*& operator[](size_t i) { + ~args_t() noexcept; + void push(char* str) noexcept; + void push(zstring_view str) noexcept; + char*& operator[](size_t i) noexcept { return data_[i]; } - char* const& operator[](size_t i) const { + char* const& operator[](size_t i) const noexcept { return data_[i]; } - char* const* data() const { + char* const* data() const noexcept { return data_.data(); } - char** data() { + char** data() noexcept { return data_.data(); } - size_t size() const { + size_t size() const noexcept { return data_.size(); } @@ -66,12 +66,12 @@ namespace bee::subprocess { friend class process; public: - spawn(); - void suspended(); - void detached(); - void redirect(stdio type, file_handle f); - void env(environment&& env); - bool exec(args_t& args, const char* cwd); + spawn() noexcept; + void suspended() noexcept; + void detached() noexcept; + void redirect(stdio type, file_handle f) noexcept; + void env(environment&& env) noexcept; + bool exec(args_t& args, const char* cwd) noexcept; private: environment env_ = nullptr; diff --git a/bee/subprocess/subprocess_win.cpp b/bee/subprocess/subprocess_win.cpp index baf007e1..2c20e8a6 100644 --- a/bee/subprocess/subprocess_win.cpp +++ b/bee/subprocess/subprocess_win.cpp @@ -16,10 +16,10 @@ #define SIGKILL 9 namespace bee::subprocess { - void args_t::push(zstring_view v) { + void args_t::push(zstring_view v) noexcept { data_.emplace_back(win::u2w(v)); } - void args_t::push(std::wstring&& v) { + void args_t::push(std::wstring&& v) noexcept { data_.emplace_back(std::forward(v)); } @@ -28,7 +28,7 @@ namespace bee::subprocess { struct node { dynarray data; size_t size; - node(size_t maxsize) + node(size_t maxsize) noexcept : data(maxsize) , size(0) {} bool has(size_t n) const noexcept { @@ -40,13 +40,13 @@ namespace bee::subprocess { size += n; } }; - strbuilder(size_t defsize) + strbuilder(size_t defsize) noexcept : deque() , size(0) , defsize(defsize) { deque.emplace_back(defsize); } - void append(const char_t* str, size_t n) { + void append(const char_t* str, size_t n) noexcept { auto& back = deque.back(); if (back.has(n)) { back.append(str, n); @@ -60,15 +60,15 @@ namespace bee::subprocess { size += n; } template - strbuilder& operator+=(T (&str)[n]) { + strbuilder& operator+=(T (&str)[n]) noexcept { append(str, n - 1); return *this; } - strbuilder& operator+=(const std::basic_string_view& s) { + strbuilder& operator+=(const std::basic_string_view& s) noexcept { append(s.data(), s.size()); return *this; } - dynarray string() { + dynarray string() noexcept { dynarray r(size + 1); size_t pos = 0; for (auto& s : deque) { @@ -84,7 +84,7 @@ namespace bee::subprocess { }; struct EnvironmentStrings { - ~EnvironmentStrings() { + ~EnvironmentStrings() noexcept { if (str) { FreeEnvironmentStringsW(str); } @@ -99,7 +99,7 @@ namespace bee::subprocess { }; template - std::basic_string quote_arg(const std::basic_string& source) { + std::basic_string quote_arg(const std::basic_string& source) noexcept { const size_t len = source.size(); if (len == 0) { return { '\"', '\"', '\0' }; @@ -134,7 +134,7 @@ namespace bee::subprocess { return target; } - static dynarray make_args(const args_t& args, std::wstring_view prefix = std::wstring_view()) { + static dynarray make_args(const args_t& args, std::wstring_view prefix = std::wstring_view()) noexcept { strbuilder res(1024); if (!prefix.empty()) { res += prefix; @@ -148,22 +148,22 @@ namespace bee::subprocess { return res.string(); } - void envbuilder::set(const std::wstring& key, const std::wstring& value) { + void envbuilder::set(const std::wstring& key, const std::wstring& value) noexcept { set_env_[key] = value; } - void envbuilder::del(const std::wstring& key) { + void envbuilder::del(const std::wstring& key) noexcept { set_env_[key] = std::nullopt; } - static void env_append(strbuilder& envs, const std::wstring& k, const std::wstring& v) { + static void env_append(strbuilder& envs, const std::wstring& k, const std::wstring& v) noexcept { envs += k; envs += L"="; envs += v; envs += L"\0"; } - environment envbuilder::release() { + environment envbuilder::release() noexcept { EnvironmentStrings es; if (!es) { return nullptr; @@ -246,7 +246,7 @@ namespace bee::subprocess { return wnd; } - static bool hide_taskbar(HWND w) { + static bool hide_taskbar(HWND w) noexcept { ITaskbarList* taskbar = nullptr; if (!SUCCEEDED(::CoInitializeEx(NULL, COINIT_MULTITHREADED))) { return false; @@ -260,7 +260,7 @@ namespace bee::subprocess { return false; } - static void hide_console(process& proc) { + static void hide_console(process& proc) noexcept { std::thread thd([&]() { auto dup_proc = proc.dup(); if (!dup_proc) { @@ -287,7 +287,7 @@ namespace bee::subprocess { fds_[2] = INVALID_HANDLE_VALUE; } - spawn::~spawn() { + spawn::~spawn() noexcept { } void spawn::search_path() noexcept { @@ -354,7 +354,7 @@ namespace bee::subprocess { } } - bool spawn::exec(const args_t& args, const wchar_t* cwd) { + bool spawn::exec(const args_t& args, const wchar_t* cwd) noexcept { if (args.size() == 0) { return false; } diff --git a/bee/subprocess/subprocess_win.h b/bee/subprocess/subprocess_win.h index c55d388b..eafc421a 100644 --- a/bee/subprocess/subprocess_win.h +++ b/bee/subprocess/subprocess_win.h @@ -35,9 +35,9 @@ namespace bee::subprocess { }; class envbuilder { public: - void set(const std::wstring& key, const std::wstring& value); - void del(const std::wstring& key); - environment release(); + void set(const std::wstring& key, const std::wstring& value) noexcept; + void del(const std::wstring& key) noexcept; + environment release() noexcept; private: using less = ignore_case::less; @@ -79,8 +79,8 @@ namespace bee::subprocess { }; struct args_t { - void push(zstring_view v); - void push(std::wstring&& v); + void push(zstring_view v) noexcept; + void push(std::wstring&& v) noexcept; std::wstring& operator[](size_t i) noexcept { return data_[i]; } @@ -100,7 +100,7 @@ namespace bee::subprocess { public: spawn() noexcept; - ~spawn(); + ~spawn() noexcept; void search_path() noexcept; void set_console(console type) noexcept; bool hide_window() noexcept; @@ -108,7 +108,7 @@ namespace bee::subprocess { void detached() noexcept; void redirect(stdio type, file_handle h) noexcept; void env(environment&& env) noexcept; - bool exec(const args_t& args, const wchar_t* cwd); + bool exec(const args_t& args, const wchar_t* cwd) noexcept; private: environment env_ = nullptr; diff --git a/bee/thread/setname.cpp b/bee/thread/setname.cpp index 3726f727..c0cb98b5 100644 --- a/bee/thread/setname.cpp +++ b/bee/thread/setname.cpp @@ -42,7 +42,7 @@ namespace bee { } #endif - void thread_setname(zstring_view name) { + void thread_setname(zstring_view name) noexcept { #if defined(_WIN32) using SetThreadDescriptionProc = HRESULT(WINAPI*)(HANDLE, PCWSTR); if (HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll")) { diff --git a/bee/thread/setname.h b/bee/thread/setname.h index 259c2d9e..e0b039b7 100644 --- a/bee/thread/setname.h +++ b/bee/thread/setname.h @@ -3,5 +3,5 @@ #include namespace bee { - void thread_setname(zstring_view name); + void thread_setname(zstring_view name) noexcept; } diff --git a/bee/utility/dynarray.h b/bee/utility/dynarray.h index 043f12ec..16813de2 100644 --- a/bee/utility/dynarray.h +++ b/bee/utility/dynarray.h @@ -29,19 +29,19 @@ namespace bee { : data_() , size_(0) {} - dynarray(size_type size) + dynarray(size_type size) noexcept : data_(std::make_unique(size)) , size_(size) {} - dynarray(const value_type* data, size_type size) + dynarray(const value_type* data, size_type size) noexcept : dynarray(size) { memcpy(data_.get(), data, sizeof(value_type) * size); } template >> - dynarray(Vec const& vec) + dynarray(Vec const& vec) noexcept : dynarray(vec.data(), vec.size()) {} - ~dynarray() + ~dynarray() noexcept {} dynarray(const dynarray&) = delete; dynarray& operator=(const dynarray&) = delete; diff --git a/bee/utility/path_helper.cpp b/bee/utility/path_helper.cpp index f1c7003c..b57f512f 100644 --- a/bee/utility/path_helper.cpp +++ b/bee/utility/path_helper.cpp @@ -11,7 +11,7 @@ extern "C" IMAGE_DOS_HEADER __ImageBase; namespace bee::path_helper { - static path_expected dll_path(HMODULE module_handle) { + static path_expected dll_path(HMODULE module_handle) noexcept { wchar_t buffer[MAX_PATH]; DWORD path_len = ::GetModuleFileNameW(module_handle, buffer, _countof(buffer)); if (path_len == 0) { @@ -33,11 +33,11 @@ namespace bee::path_helper { return unexpected("::GetModuleFileNameW return too long."); } - path_expected exe_path() { + path_expected exe_path() noexcept { return dll_path(NULL); } - path_expected dll_path() { + path_expected dll_path() noexcept { return dll_path(reinterpret_cast(&__ImageBase)); } } @@ -49,7 +49,7 @@ namespace bee::path_helper { # include namespace bee::path_helper { - path_expected exe_path() { + path_expected exe_path() noexcept { uint32_t path_len = 0; _NSGetExecutablePath(0, &path_len); if (path_len <= 1) { @@ -77,7 +77,7 @@ namespace bee::path_helper { # endif namespace bee::path_helper { - path_expected exe_path() { + path_expected exe_path() noexcept { # if defined(__FreeBSD__) int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; char exe[1024]; @@ -117,10 +117,10 @@ namespace bee::path_helper { # if defined(BEE_DISABLE_DLOPEN) namespace bee::path_helper { - static path_expected dll_path(void* module_handle) { + static path_expected dll_path(void* module_handle) noexcept { return unexpected("disable dl."); } - path_expected dll_path() { + path_expected dll_path() noexcept { return dll_path(nullptr); } } @@ -130,17 +130,22 @@ namespace bee::path_helper { # include namespace bee::path_helper { - static path_expected dll_path(void* module_handle) { + static path_expected dll_path(void* module_handle) noexcept { ::Dl_info dl_info; dl_info.dli_fname = 0; const int ret = ::dladdr(module_handle, &dl_info); if (0 != ret && dl_info.dli_fname != NULL) { - return fs::absolute(dl_info.dli_fname).lexically_normal(); + std::error_code ec; + auto path = fs::absolute(dl_info.dli_fname, ec); + if (ec) { + return unexpected(ec.message()); + } + return path.lexically_normal(); } return unexpected("::dladdr failed."); } - path_expected dll_path() { + path_expected dll_path() noexcept { return dll_path((void*)&exe_path); } } @@ -151,7 +156,7 @@ namespace bee::path_helper { namespace bee::path_helper { #if defined(_WIN32) - bool equal(const fs::path& lhs, const fs::path& rhs) { + bool equal(const fs::path& lhs, const fs::path& rhs) noexcept { fs::path lpath = lhs.lexically_normal(); fs::path rpath = rhs.lexically_normal(); const fs::path::value_type* l(lpath.c_str()); @@ -163,7 +168,7 @@ namespace bee::path_helper { return *l == *r; } #elif defined(__APPLE__) - bool equal(const fs::path& lhs, const fs::path& rhs) { + bool equal(const fs::path& lhs, const fs::path& rhs) noexcept { fs::path lpath = lhs.lexically_normal(); fs::path rpath = rhs.lexically_normal(); const fs::path::value_type* l(lpath.c_str()); @@ -175,7 +180,7 @@ namespace bee::path_helper { return *l == *r; } #else - bool equal(const fs::path& lhs, const fs::path& rhs) { + bool equal(const fs::path& lhs, const fs::path& rhs) noexcept { return lhs.lexically_normal() == rhs.lexically_normal(); } #endif diff --git a/bee/utility/path_helper.h b/bee/utility/path_helper.h index 0b836604..b16fa65d 100644 --- a/bee/utility/path_helper.h +++ b/bee/utility/path_helper.h @@ -5,7 +5,7 @@ namespace bee::path_helper { using path_expected = expected; - path_expected exe_path(); - path_expected dll_path(); - bool equal(const fs::path& lhs, const fs::path& rhs); + path_expected exe_path() noexcept; + path_expected dll_path() noexcept; + bool equal(const fs::path& lhs, const fs::path& rhs) noexcept; }