Fork me on GitHub

Changeset 273e668 in git for external/fastjet/Error.cc


Ignore:
Timestamp:
Oct 15, 2014, 10:55:55 AM (10 years ago)
Author:
Pavel Demin <pavel.demin@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
35b9204, b25d4cf
Parents:
f14bd6a
git-author:
Pavel Demin <pavel.demin@…> (10/10/14 08:56:40)
git-committer:
Pavel Demin <pavel.demin@…> (10/15/14 10:55:55)
Message:

upgrade FastJet to version 3.1.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • external/fastjet/Error.cc

    rf14bd6a r273e668  
    11//FJSTARTHEADER
    2 // $Id: Error.cc 3433 2014-07-23 08:17:03Z salam $
     2// $Id: Error.cc 3695 2014-09-18 13:57:56Z cacciari $
    33//
    44// Copyright (c) 2005-2014, Matteo Cacciari, Gavin P. Salam and Gregory Soyez
     
    3333#include <sstream>
    3434
     35#ifndef __FJCORE__
    3536// printing the stack would need execinfo
    3637#ifdef FASTJET_HAVE_EXECINFO_H
    3738#include <execinfo.h>
    3839#include <cstdlib>
    39 #endif
     40#ifdef FASTJET_HAVE_DEMANGLING_SUPPORT
     41#include <cstdio>
     42#include <cxxabi.h>
     43#endif // FASTJET_HAVE_DEMANGLING_SUPPORT
     44#endif // FASTJET_HAVE_EXECINFO_H
     45#endif  // __FJCORE__
    4046
    4147FASTJET_BEGIN_NAMESPACE      // defined in fastjet/internal/base.hh
     
    4652bool Error::_print_backtrace = false;
    4753ostream * Error::_default_ostr = & cerr;
     54#if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__)
     55  LimitedWarning Error::_execinfo_undefined;
     56#endif
    4857
     58//----------------------------------------------------------------------
     59#ifndef __FJCORE__
     60
     61// demangling only is included, i.e. --enable-demangling is specified
     62// at configure time, execinfo.h is present and the GNU C++ ABI is
     63// supported
     64#if defined(FASTJET_HAVE_EXECINFO_H) && defined(FASTJET_HAVE_DEMANGLING_SUPPORT)
     65// demangle a given backtrace symbol
     66//
     67// Notes:
     68//  - at the moment, only the symbol is parsed.
     69//  - one can get the offset by using
     70//      "%*[^(]%*[^_]%127[^+)]%64[+x0123456789abcdef]", symbol, offset
     71//    and checking if sscanf returns 0, 1 or 2
     72//    (offset includes the leading +)
     73//  - Similarly one could exctract the address and try to convert it
     74//    into a filename+line number like addr2line does but this seems
     75//    to require exteral dependencies. If we want to go down that
     76//    route, one could look into the inplementation o faddr2line(.c)
     77//    and/or dladdr.
     78string Error::_demangle(const char* symbol) {
     79  size_t size;
     80  int status;
     81  char temp[128];
     82  char* demangled;
     83  // first, try to demangle a c++ name
     84  // decryption:
     85  //   %*[^(]  matches any number of characters different from "("
     86  //           the * tells not to store in input var
     87  //   %*[^_]  matches any number of characters different from "_"
     88  //           the * tells not to store in input var
     89  //   %127[^)+]  matches at most 127 characters different from "+"
     90  //              match is stored
     91  if (1 == sscanf(symbol, "%*[^(]%*[^_]%127[^)+]", temp)) {
     92    //cout << symbol << " -> " << temp << endl;
     93    if (NULL != (demangled = abi::__cxa_demangle(temp, NULL, &size, &status))) {
     94      string result(demangled);
     95      free(demangled);
     96      return result;
     97    }
     98  }
     99  //if that didn't work, try to get a regular c symbol
     100  if (1 == sscanf(symbol, "%127s", temp)) {
     101    return temp;
     102  }
     103 
     104  //if all else fails, just return the symbol
     105  return symbol;
     106}
     107#endif  // FASTJET_HAVE_DEMANGLING_SUPPORT && FASTJET_HAVE_EXECINFO_H
     108#endif  // __FJCORE__
     109
     110
     111//----------------------------------------------------------------------
    49112Error::Error(const std::string & message_in) {
    50113  _message = message_in;
     114
    51115  if (_print_errors && _default_ostr){
    52116    ostringstream oss;
    53117    oss << "fastjet::Error:  "<< message_in << endl;
    54118
     119#ifndef __FJCORE__
    55120    // only print the stack if execinfo is available and stack enabled
    56121#ifdef FASTJET_HAVE_EXECINFO_H
     
    64129      oss << "stack:" << endl;
    65130      for (int i = 1; i < size && messages != NULL; ++i){
     131#ifdef FASTJET_HAVE_DEMANGLING_SUPPORT
     132        oss << "  #" << i << ": " << _demangle(messages[i])
     133            << " [" << messages[i]  << "]" << endl;
     134#else
    66135        oss << "  #" << i << ": " << messages[i] << endl;
     136#endif
    67137      }
    68138      free(messages);
    69139    }
    70 #endif
     140#endif  // FASTJET_HAVE_EXECINFO_H
     141#endif  // __FJCORE__
    71142
    72143    *_default_ostr << oss.str();
     
    85156}
    86157
     158//----------------------------------------------------------------------
     159void Error::set_print_backtrace(bool enabled) {
     160#if (!defined(FASTJET_HAVE_EXECINFO_H)) || defined(__FJCORE__)
     161  if (enabled) {
     162    _execinfo_undefined.warn("Error::set_print_backtrace(true) will not work with this build of FastJet");
     163  }
     164#endif   
     165  _print_backtrace = enabled;
     166}
     167
    87168FASTJET_END_NAMESPACE
    88169
Note: See TracChangeset for help on using the changeset viewer.