Skip to content
Browse files

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
  • Loading branch information...
1 parent 5d43d2a commit a6198d25683b47837948d8f1e9f60337470d5531 @pgriess pgriess committed with Owen Yamauchi Mar 22, 2013
Showing with 13 additions and 12 deletions.
  1. +9 −0 folly/Exception.h
  2. +4 −3 folly/experimental/symbolizer/Elf.cpp
  3. +0 −9 folly/experimental/symbolizer/Elf.h
View
9 folly/Exception.h
@@ -22,6 +22,7 @@
#include <stdexcept>
#include <system_error>
+#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 <class... Args>
+void throwSystemError(Args... args) __attribute__((noreturn));
+template <class... Args>
+inline void throwSystemError(Args... args) {
+ throwSystemError(errno, folly::to<std::string>(args...));
+}
+
// Check a Posix return code (0 on success, error number on error), throw
// on error.
inline void checkPosixError(int err, const char* msg) {
View
7 folly/experimental/symbolizer/Elf.cpp
@@ -28,6 +28,7 @@
#include <glog/logging.h>
#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<char*>(
mmap(nullptr, length_, PROT_READ, MAP_SHARED, fd_, 0));
if (file_ == MAP_FAILED) {
- systemError("mmap");
+ folly::throwSystemError("mmap");
}
init();
}
View
9 folly/experimental/symbolizer/Elf.h
@@ -135,15 +135,6 @@ class ElfFile {
};
template <class... Args>
-void systemError(Args... args) __attribute__((noreturn));
-
-template <class... Args>
-void systemError(Args... args) {
- throw std::system_error(errno, std::system_category(),
- folly::to<std::string>(args...));
-}
-
-template <class... Args>
inline void enforce(bool v, Args... args) {
if (UNLIKELY(!v)) {
throw std::runtime_error(folly::to<std::string>(args...));

0 comments on commit a6198d2

Please sign in to comment.
Something went wrong with that request. Please try again.