Commit 3f2a5d5f authored by Tiago Peixoto's avatar Tiago Peixoto

Replace python::detail::gcc_demangle by abi::__cxa_demangle

This fixes issue #318
parent 14e22f79
Pipeline #198 failed with stage
in 4342 minutes and 10 seconds
......@@ -19,6 +19,7 @@ libgraph_tool_core_LTLIBRARIES = libgraph_tool_core.la
libgraph_tool_core_la_SOURCES = \
base64.cc \
demangle.cc \
graph.cc \
graph_exceptions.cc \
graph_bind.cc \
......@@ -49,6 +50,7 @@ libgraph_tool_core_la_includedir = $(MOD_DIR)/include
libgraph_tool_core_la_include_HEADERS = \
../../config.h \
base64.hh \
demangle.hh \
fast_vector_property_map.hh \
gml.hh \
graph.hh \
......
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2016 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "demangle.hh"
#include <cxxabi.h>
std::string name_demangle(std::string name)
{
int status = 0;
char *realname = abi::__cxa_demangle(name.c_str(), 0, 0, &status);
if (status != 0)
return name + " (cannot demangle symbol)";
std::string ret(realname);
free(realname);
return ret;
}
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2006-2016 Tiago de Paula Peixoto <tiago@skewed.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef DEMANGLE_HH
#define DEMANGLE_HH
#include <string>
std::string name_demangle(std::string name);
#endif // DEMANGLE_HH
......@@ -32,6 +32,7 @@
#include <chrono>
#include "hash_map_wrap.hh"
#include "demangle.hh"
#include <cairommconfig.h>
#include <cairomm/context.h>
......@@ -235,8 +236,8 @@ struct Converter
}
catch (bad_lexical_cast&)
{
string name1 = python::detail::gcc_demangle(typeid(Type1).name());
string name2 = python::detail::gcc_demangle(typeid(Type2).name());
string name1 = name_demangle(typeid(Type1).name());
string name2 = name_demangle(typeid(Type2).name());
string val_name;
try
{
......@@ -432,10 +433,8 @@ public:
catch (bad_any_cast&)
{
throw ValueException("Error getting attribute " + lexical_cast<string>(k) +
", wanted: " +
boost::python::detail::gcc_demangle(typeid(Value).name()) +
", got: " +
boost::python::detail::gcc_demangle(_defaults[k].type().name()));
", wanted: " + name_demangle(typeid(Value).name()) +
", got: " + name_demangle(_defaults[k].type().name()));
}
}
......
......@@ -383,8 +383,7 @@ struct graph_type_name
template <class Graph>
void operator()(const Graph&, string& name) const
{
using boost::python::detail::gcc_demangle;
name = string(gcc_demangle(typeid(Graph).name()));
name = name_demangle(typeid(Graph).name());
}
};
......@@ -466,7 +465,7 @@ BOOST_PYTHON_MODULE(libgraph_tool_core)
class_<std::type_info, boost::noncopyable>("type_info", no_init)
.def("name", &std::type_info::name)
.def("hash_code", &std::type_info::hash_code);
def("gcc_demangle", &python::detail::gcc_demangle);
def("name_demangle", &name_demangle);
def("graph_filtering_enabled", &graph_filtering_enabled);
export_openmp();
......
......@@ -16,7 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "graph_filtering.hh"
#include <cxxabi.h>
#include "demangle.hh"
using namespace graph_tool;
using namespace graph_tool::detail;
......@@ -31,27 +31,11 @@ bool graph_tool::graph_filtering_enabled()
#endif
}
namespace graph_tool
{
string name_demangle(string name)
{
int status = 0;
char *realname = abi::__cxa_demangle(name.c_str(), 0, 0, &status);
if (realname == nullptr)
return name + " (cannot demangle symbol)";
string ret(realname);
free(realname);
return ret;
}
}
// Whenever no implementation is called, the following exception is thrown
graph_tool::ActionNotFound::ActionNotFound(const type_info& action,
const vector<const type_info*>& args)
: GraphException(""), _action(action), _args(args)
{
using python::detail::gcc_demangle;
_error =
"No static implementation was found for the desired routine. "
"This is a graph_tool bug. :-( Please submit a bug report at "
......
......@@ -532,9 +532,6 @@ retrieve_graph_view(GraphInterface& gi, Graph& init)
return *gptr;
}
// symbol demangling
string name_demangle(string name);
} //graph_tool namespace
// Overload add_vertex() and add_edge() to filtered graphs, so that the new
......
......@@ -44,6 +44,7 @@ namespace std
#include "graph.hh"
#include "graph_filtering.hh"
#include "graph_selectors.hh"
#include "demangle.hh"
#include "numpy_bind.hh"
#ifdef HAVE_BOOST_COROUTINE
......@@ -271,8 +272,7 @@ public:
std::string get_graph_type() const
{
using boost::python::detail::gcc_demangle;
return gcc_demangle(typeid(Graph).name());
return name_demangle(typeid(Graph).name());
}
template <class OGraph>
......@@ -375,8 +375,7 @@ public:
std::string get_graph_type() const
{
using boost::python::detail::gcc_demangle;
return gcc_demangle(typeid(Graph).name());
return name_demangle(typeid(Graph).name());
}
template <class OGraph>
......@@ -486,10 +485,9 @@ public:
std::string get_type() const
{
using boost::python::detail::gcc_demangle;
if (std::is_same<typename boost::mpl::find<value_types,value_type>::type,
typename boost::mpl::end<value_types>::type>::value)
return gcc_demangle(typeid(value_type).name());
return name_demangle(typeid(value_type).name());
else
return type_names[boost::mpl::find<value_types,
value_type>::type::pos::value];
......
......@@ -18,6 +18,7 @@
#include "graph_filtering.hh"
#include "graph.hh"
#include "graph_python_interface.hh"
#include "demangle.hh"
#include <boost/python.hpp>
#include <boost/lambda/bind.hpp>
......@@ -34,8 +35,6 @@ struct export_vertex_property_map
template <class PropertyMap>
void operator()(PropertyMap) const
{
using boost::python::detail::gcc_demangle;
typedef PythonPropertyMap<PropertyMap> pmap_t;
string type_name;
......@@ -43,7 +42,7 @@ struct export_vertex_property_map
typename pmap_t::value_type>::type,
typename boost::mpl::end<value_types>::type>::value)
type_name =
gcc_demangle(typeid(typename pmap_t::value_type).name());
name_demangle(typeid(typename pmap_t::value_type).name());
else
type_name =
type_names[boost::mpl::find<value_types,typename pmap_t::value_type>
......@@ -118,8 +117,6 @@ struct export_edge_property_map
template <class PropertyMap>
void operator()(PropertyMap) const
{
using boost::python::detail::gcc_demangle;
typedef PythonPropertyMap<PropertyMap> pmap_t;
string type_name;
......@@ -127,7 +124,7 @@ struct export_edge_property_map
typename pmap_t::value_type>::type,
typename boost::mpl::end<value_types>::type>::value)
type_name =
gcc_demangle(typeid(typename pmap_t::value_type).name());
name_demangle(typeid(typename pmap_t::value_type).name());
else
type_name =
type_names[boost::mpl::find<value_types,typename pmap_t::value_type>
......
......@@ -40,6 +40,8 @@
#include <boost/mpl/pair.hpp>
#include <boost/mpl/for_each.hpp>
#include "demangle.hh"
using namespace std;
typedef boost::mpl::map<
......@@ -180,13 +182,12 @@ boost::multi_array_ref<ValueType,dim> get_array(boost::python::object points)
if (boost::mpl::at<numpy_types,ValueType>::type::value != PyArray_DESCR(pa)->type_num)
{
using boost::python::detail::gcc_demangle;
boost::python::handle<> x(boost::python::borrowed((PyObject*) PyArray_DESCR(pa)->typeobj));
boost::python::object dtype(x);
string type_name = boost::python::extract<string>(boost::python::str(dtype));
string error = "invalid array value type: " + type_name;
error += " (id: " + boost::lexical_cast<string>(PyArray_DESCR(pa)->type_num) + ")";
error += ", wanted: " + string(gcc_demangle(typeid(ValueType).name()));
error += ", wanted: " + name_demangle(typeid(ValueType).name());
error += " (id: " + boost::lexical_cast<string>(boost::mpl::at<numpy_types,ValueType>::type::value) + ")";
throw InvalidNumpyConversion(error);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment