Move folly::symbolizer::systemError() into Exception.h
authorPeter Griess <pgriess@fb.com>
Fri, 22 Mar 2013 14:55:54 +0000 (07:55 -0700)
committerOwen Yamauchi <oyamauchi@fb.com>
Wed, 27 Mar 2013 21:40:32 +0000 (14:40 -0700)
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
folly/experimental/symbolizer/Elf.cpp
folly/experimental/symbolizer/Elf.h

index 5549c4bdcdf83900ce96f34362e8c2125aac6016..c2e6eea787122386c3465a28d8b04b19e13b7129 100644 (file)
@@ -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) {
index efdea9149ccb620ac9631d48abb40e2c3cefb265..d9160018b49670fa4fb5365c11c21c97b2c31a73 100644 (file)
@@ -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();
 }
index 5274ac0ff636bc7c5547cfd24d2725e10184df84..88eae5e39200c400d6749a598385fdeb76bfd09e 100644 (file)
@@ -134,15 +134,6 @@ class ElfFile {
   uintptr_t baseAddress_;
 };
 
-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)) {