From a6198d25683b47837948d8f1e9f60337470d5531 Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Fri, 22 Mar 2013 07:55:54 -0700 Subject: [PATCH] Move folly::symbolizer::systemError() into Exception.h Summary: - This is pretty similar to some stuff that we already have in Exception.h. Move (and rename) it. Test Plan: - Unit tests Reviewed By: simpkins@fb.com FB internal diff: D748313 --- folly/Exception.h | 9 +++++++++ folly/experimental/symbolizer/Elf.cpp | 7 ++++--- folly/experimental/symbolizer/Elf.h | 9 --------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/folly/Exception.h b/folly/Exception.h index 5549c4bd..c2e6eea7 100644 --- a/folly/Exception.h +++ b/folly/Exception.h @@ -22,6 +22,7 @@ #include #include +#include "folly/Conv.h" #include "folly/Likely.h" namespace folly { @@ -38,6 +39,14 @@ inline void throwSystemError(const char* msg) { throwSystemError(errno, msg); } +// Helper to throw std::system_error from errno and components of a string +template +void throwSystemError(Args... args) __attribute__((noreturn)); +template +inline void throwSystemError(Args... args) { + throwSystemError(errno, folly::to(args...)); +} + // Check a Posix return code (0 on success, error number on error), throw // on error. inline void checkPosixError(int err, const char* msg) { diff --git a/folly/experimental/symbolizer/Elf.cpp b/folly/experimental/symbolizer/Elf.cpp index efdea914..d9160018 100644 --- a/folly/experimental/symbolizer/Elf.cpp +++ b/folly/experimental/symbolizer/Elf.cpp @@ -28,6 +28,7 @@ #include #include "folly/Conv.h" +#include "folly/Exception.h" namespace folly { namespace symbolizer { @@ -45,20 +46,20 @@ ElfFile::ElfFile(const char* name) length_(0), baseAddress_(0) { if (fd_ == -1) { - systemError("open ", name); + folly::throwSystemError("open ", name); } struct stat st; int r = fstat(fd_, &st); if (r == -1) { - systemError("fstat"); + folly::throwSystemError("fstat"); } length_ = st.st_size; file_ = static_cast( mmap(nullptr, length_, PROT_READ, MAP_SHARED, fd_, 0)); if (file_ == MAP_FAILED) { - systemError("mmap"); + folly::throwSystemError("mmap"); } init(); } diff --git a/folly/experimental/symbolizer/Elf.h b/folly/experimental/symbolizer/Elf.h index 5274ac0f..88eae5e3 100644 --- a/folly/experimental/symbolizer/Elf.h +++ b/folly/experimental/symbolizer/Elf.h @@ -134,15 +134,6 @@ class ElfFile { uintptr_t baseAddress_; }; -template -void systemError(Args... args) __attribute__((noreturn)); - -template -void systemError(Args... args) { - throw std::system_error(errno, std::system_category(), - folly::to(args...)); -} - template inline void enforce(bool v, Args... args) { if (UNLIKELY(!v)) { -- 2.34.1