Skip to content

Commit 46bf2e2

Browse files
committed
fix include of <execinfo.h>
1 parent 68a5489 commit 46bf2e2

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2020-03-15 Kevin Ushey <[email protected]>
2+
3+
* inst/include/Rcpp/exceptions_impl.h: Ensure <execinfo.h> is included
4+
into global namespace; refactor detection of demangler support
5+
16
2020-03-13 Dirk Eddelbuettel <[email protected]>
27

38
* DESCRIPTION (Date, Version): Release 1.0.4

inst/include/Rcpp/exceptions_impl.h

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,33 @@
1818
// You should have received a copy of the GNU General Public License
1919
// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
2020

21+
// disable demangler on platforms where we have no support
22+
#ifndef RCPP_DEMANGLER_ENABLED
23+
# if defined(_WIN32) || \
24+
defined(__FreeBSD__) || \
25+
defined(__NetBSD__) || \
26+
defined(__OpenBSD__) || \
27+
defined(__CYGWIN__) || \
28+
defined(__sun) || \
29+
defined(_AIX) || \
30+
defined(__MUSL__) || \
31+
defined(__HAIKU__) || \
32+
defined(__ANDROID__)
33+
# define RCPP_DEMANGLER_ENABLED 0
34+
# elif defined(__GNUC__) || defined(__clang__)
35+
# include <execinfo.h>
36+
# define RCPP_DEMANGLER_ENABLED 1
37+
# endif
38+
#endif
39+
2140
namespace Rcpp {
22-
#if defined(__GNUC__) || defined(__clang__)
23-
#if defined(_WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) || defined(__sun) || defined(_AIX) || defined(__MUSL__) || defined(__HAIKU__) || defined(__ANDROID__)
24-
// do nothing
25-
#else
26-
#include <execinfo.h>
2741

2842
// Extract mangled name e.g. ./test(baz+0x14)[0x400962]
43+
#if RCPP_DEMANGLER_ENABLED
2944
static std::string demangler_one(const char* input) { // #nocov start
45+
3046
static std::string buffer;
47+
3148
buffer = input;
3249
size_t last_open = buffer.find_last_of('(');
3350
size_t last_close = buffer.find_last_of(')');
@@ -42,19 +59,16 @@ namespace Rcpp {
4259
function_name.resize(function_plus);
4360
}
4461
buffer.replace(last_open + 1, function_name.size(), demangle(function_name));
62+
4563
return buffer;
64+
4665
}
47-
#endif
4866
#endif
4967

5068
// thread-safe; invoked prior to throwing the exception
5169
inline void exception::record_stack_trace()
5270
{
53-
#if defined(__GNUC__) || defined(__clang__)
54-
#if defined(_WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) || defined(__sun) || defined(_AIX) || defined(__MUSL__) || defined(__HAIKU__) || defined(__ANDROID__)
55-
// C++ stack not available on this system
56-
#else // ! (defined(_WIN32) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) || defined(__sun) || defined(_AIX) || defined(__ANDROID__)
57-
71+
#if RCPP_DEMANGLER_ENABLED
5872
/* inspired from http://tombarta.wordpress.com/2008/08/01/c-stack-traces-with-gcc/ */
5973
const size_t max_depth = 100;
6074
int stack_depth;
@@ -66,8 +80,7 @@ namespace Rcpp {
6680
std::transform(stack_strings + 1, stack_strings + stack_depth,
6781
std::back_inserter(stack), demangler_one);
6882
free(stack_strings); // malloc()ed by backtrace_symbols
69-
#endif
70-
#endif
83+
#endif
7184
}
7285

7386
// not thread-safe; invoked after catching the exception
@@ -86,4 +99,6 @@ namespace Rcpp {
8699
trace.attr("class") = "Rcpp_stack_trace";
87100
rcpp_set_stack_trace(trace); // #nocov end
88101
}
102+
89103
}
104+

0 commit comments

Comments
 (0)