aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-01-30 04:43:30 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-01-30 04:43:30 +0000
commit34d8622d7d5843cb0691adf7627b954314e2b644 (patch)
tree5e49118312f8236f9e1aa38fb77a637c4081b4fd
parent5fd056e42249508b9db23c1e75b3566a4da6c2ee (diff)
downloadpaludis-34d8622d7d5843cb0691adf7627b954314e2b644.tar.gz
paludis-34d8622d7d5843cb0691adf7627b954314e2b644.tar.xz
Use abi::__cxa_demangle where available
-rw-r--r--configure.ac19
-rw-r--r--paludis/util/exception.cc35
-rw-r--r--paludis/util/exception.hh9
3 files changed, 56 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index 59817e7..bdd547b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -261,6 +261,25 @@ AC_COMPILE_IFELSE([
AC_MSG_ERROR([libwrapiter version must be at least 1.0])])
dnl }}}
+dnl {{{ we can use abi::__cxa_demangle
+AC_MSG_CHECKING([for abi::__cxa_demangle])
+AC_COMPILE_IFELSE([
+#include <cxxabi.h>
+int main(int, char *[])
+{
+ int status(0);
+ char * const name(abi::__cxa_demangle(
+ "_ZN7paludis21CategoryNamePartErrorE", 0, 0, &status));
+}
+],
+ [have_cxa_demangle=yes],
+ [have_cxa_demangle=no])
+AC_MSG_RESULT([$have_cxa_demangle])
+if test "x$have_cxa_demangle" = "xyes"; then
+ AC_DEFINE([HAVE_CXA_DEMANGLE], [1], [Include abi::__cxa_demangle support])
+fi
+dnl}}}
+
dnl {{{ check for various misc functions.
dnl It's probably possible to make many of these optional rather than
dnl hard requirements. If any of these fail for you, send patches.
diff --git a/paludis/util/exception.cc b/paludis/util/exception.cc
index f9c7548..055e151 100644
--- a/paludis/util/exception.cc
+++ b/paludis/util/exception.cc
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -19,12 +19,11 @@
#include <paludis/util/exception.hh>
#include <libebt/libebt.hh>
+#include "config.h"
-/** \file
- * Exception class implementations.
- *
- * \ingroup grpexceptions
- */
+#ifdef HAVE_CXA_DEMANGLE
+# include <cxxabi.h>
+#endif
using namespace paludis;
@@ -125,3 +124,27 @@ ConfigurationError::ConfigurationError(const std::string & msg) throw () :
{
}
+const char *
+Exception::what() const throw ()
+{
+#ifdef HAVE_CXA_DEMANGLE
+ if (_what_str.empty())
+ {
+ int status(0);
+ char * const name(abi::__cxa_demangle(
+ ("_Z" + stringify(std::exception::what())).c_str(), 0, 0, &status));
+
+ if (0 == status)
+ {
+ _what_str = name;
+ std::free(name);
+ }
+ }
+#endif
+
+ if (_what_str.empty())
+ _what_str = stringify(std::exception::what());
+
+ return _what_str.c_str();
+}
+
diff --git a/paludis/util/exception.hh b/paludis/util/exception.hh
index 2e8b649..a7504f1 100644
--- a/paludis/util/exception.hh
+++ b/paludis/util/exception.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2005, 2006 Ciaran McCreesh <ciaranm@ciaranm.org>
+ * Copyright (c) 2005, 2006, 2007 Ciaran McCreesh <ciaranm@ciaranm.org>
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -21,6 +21,7 @@
#define PALUDIS_GUARD_PALUDIS_EXCEPTION_HH 1
#include <paludis/util/attributes.hh>
+#include <paludis/util/stringify.hh>
#include <libwrapiter/libwrapiter_forward_iterator.hh>
#include <string>
#include <exception>
@@ -77,6 +78,7 @@ namespace paludis
{
private:
const std::string _message;
+ mutable std::string _what_str;
struct ContextData;
ContextData * const _context_data;
@@ -114,6 +116,11 @@ namespace paludis
* Is our backtrace empty?
*/
bool empty() const;
+
+ /**
+ * A better what, if possible.
+ */
+ const char * what() const throw ();
};
/**