Add some NODISCARD attributes and uncomment scope_exit utility code

This commit is contained in:
Jeremy Rifkin 2025-02-20 21:43:25 -06:00
parent 6877782d96
commit 9a2ae3c96f
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4
2 changed files with 29 additions and 27 deletions

View File

@ -5,6 +5,8 @@
|| defined(CPPTRACE_GET_SYMBOLS_WITH_DBGHELP) \ || defined(CPPTRACE_GET_SYMBOLS_WITH_DBGHELP) \
|| defined(CPPTRACE_DEMANGLE_WITH_WINAPI) || defined(CPPTRACE_DEMANGLE_WITH_WINAPI)
#include "utils/common.hpp"
#include <unordered_map> #include <unordered_map>
#include <mutex> #include <mutex>
@ -20,8 +22,8 @@ namespace detail {
~dbghelp_syminit_info(); ~dbghelp_syminit_info();
void release(); void release();
static dbghelp_syminit_info make_not_owned(void* handle); NODISCARD static dbghelp_syminit_info make_not_owned(void* handle);
static dbghelp_syminit_info make_owned(void* handle, bool should_close_handle); NODISCARD static dbghelp_syminit_info make_owned(void* handle, bool should_close_handle);
dbghelp_syminit_info(const dbghelp_syminit_info&) = delete; dbghelp_syminit_info(const dbghelp_syminit_info&) = delete;
dbghelp_syminit_info(dbghelp_syminit_info&&); dbghelp_syminit_info(dbghelp_syminit_info&&);
@ -39,7 +41,7 @@ namespace detail {
// - Calls SymInitialize and returns an owning dbghelp_syminit_info which will handle cleanup // - Calls SymInitialize and returns an owning dbghelp_syminit_info which will handle cleanup
dbghelp_syminit_info ensure_syminit(); dbghelp_syminit_info ensure_syminit();
std::unique_lock<std::recursive_mutex> get_dbghelp_lock(); NODISCARD std::unique_lock<std::recursive_mutex> get_dbghelp_lock();
} }
} }

View File

@ -278,31 +278,31 @@ namespace detail {
} }
}; };
// template<typename F> template<typename F>
// class scope_guard { class scope_guard {
// F f; F f;
// bool active; bool active;
// public: public:
// scope_guard(F&& f) : f(std::forward<F>(f)), active(true) {} scope_guard(F&& f) : f(std::forward<F>(f)), active(true) {}
// ~scope_guard() { ~scope_guard() {
// if(active) { if(active) {
// f(); f();
// } }
// } }
// scope_guard(const scope_guard&) = delete; scope_guard(const scope_guard&) = delete;
// scope_guard(scope_guard&& other) : f(std::move(other.f)), active(exchange(other.active, false)) {} scope_guard(scope_guard&& other) : f(std::move(other.f)), active(exchange(other.active, false)) {}
// scope_guard& operator=(const scope_guard&) = delete; scope_guard& operator=(const scope_guard&) = delete;
// scope_guard& operator=(scope_guard&& other) { scope_guard& operator=(scope_guard&& other) {
// f = std::move(other.f); f = std::move(other.f);
// active = exchange(other.active, false); active = exchange(other.active, false);
// return *this; return *this;
// } }
// }; };
// template<typename F> template<typename F>
// auto scope_exit(F&& f) { NODISCARD auto scope_exit(F&& f) {
// return scope_guard<F>(std::forward<F>(f)); return scope_guard<F>(std::forward<F>(f));
// } }
} }
} }