Use a simple deallocator for backtrace info

Clang doesn't like using the array form of unique_ptr with backtrace
calls for some reason. Less important to figure this out.
This commit is contained in:
Danny Robson 2012-06-13 15:47:39 +10:00
parent 6ff8405c6a
commit f5fa3219b4

View File

@ -1,6 +1,7 @@
#include "backtrace.hpp"
#include "debug.hpp"
#include "types/casts.hpp"
#include <cstdlib>
#include <execinfo.h>
@ -14,7 +15,7 @@ debug::backtrace::backtrace (void):
m_frames (DEFAULT_DEPTH) {
int final;
while ((final = ::backtrace (&m_frames[0], m_frames.size ())) == m_frames.size ())
while ((final = ::backtrace (&m_frames[0], m_frames.size ())) == sign_cast<ssize_t> (m_frames.size ()))
m_frames.resize (m_frames.size () * 2);
CHECK_HARD (final > 0);
@ -26,11 +27,12 @@ ostream&
debug::operator <<(ostream &os, const debug::backtrace &rhs) {
const auto frames = rhs.frames ();
typedef unique_ptr<char *[], decltype(&std::free)> unique_str;
unique_str names (backtrace_symbols (&frames[0], frames.size ()), std::free);
// We don't use the array form of unique_ptr as clang fails on ambigious constructors
typedef unique_ptr<char *, decltype(&std::free)> unique_str;
unique_str names (backtrace_symbols (frames.data (), frames.size ()), ::free);
for (unsigned int i = 0; i < frames.size (); ++i)
os << frames[i] << "\t" << names[i] << "\n";
os << frames[i] << "\t" << names.get()[i] << "\n";
return os;
}