mirror of
https://github.com/boostorg/python.git
synced 2026-01-28 07:22:31 +00:00
Get Cygwin linking again
User-readable type name printing for GCC [SVN r19236]
This commit is contained in:
@@ -14,8 +14,6 @@
|
||||
#include <boost/python/detail/raw_pyobject.hpp>
|
||||
#include <boost/python/cast.hpp>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#include <boost/python/converter/registrations.hpp>
|
||||
#include <boost/python/converter/builtin_converters.hpp>
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -25,7 +23,7 @@ BOOST_PYTHON_DECL PyTypeObject* registration::get_class_object() const
|
||||
::PyErr_Format(
|
||||
PyExc_TypeError
|
||||
, const_cast<char*>("No Python class registered for C++ class %s")
|
||||
, target_type.name());
|
||||
, this->target_type.name());
|
||||
|
||||
throw_error_already_set();
|
||||
}
|
||||
@@ -40,7 +38,9 @@ BOOST_PYTHON_DECL PyObject* registration::to_python(void const volatile* source)
|
||||
handle<> msg(
|
||||
::PyString_FromFormat(
|
||||
"No to_python (by-value) converter found for C++ type: %s"
|
||||
, this->target_type.name()));
|
||||
, this->target_type.name()
|
||||
)
|
||||
);
|
||||
|
||||
PyErr_SetObject(PyExc_TypeError, msg.get());
|
||||
|
||||
|
||||
@@ -6,14 +6,111 @@
|
||||
|
||||
#include <boost/python/type_id.hpp>
|
||||
#include <boost/python/detail/decorated_type_id.hpp>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#if !defined(__GNUC__) || __GNUC__ >= 3 || __SGI_STL_PORT
|
||||
# include <ostream>
|
||||
#else
|
||||
# include <ostream.h>
|
||||
#endif
|
||||
|
||||
|
||||
# ifdef BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
|
||||
# if defined(__GNUC__) && __GNUC__ >= 3
|
||||
# include <cxxabi.h>
|
||||
# endif
|
||||
#include <iostream>
|
||||
# endif
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
# ifdef BOOST_PYTHON_HAVE_GCC_CP_DEMANGLE
|
||||
# ifdef __GNUC__
|
||||
# if __GNUC__ < 3
|
||||
|
||||
namespace cxxabi = :: ;
|
||||
# else
|
||||
namespace cxxabi = ::abi; // GCC 3.1 and later
|
||||
# endif
|
||||
# endif
|
||||
|
||||
namespace
|
||||
{
|
||||
struct compare_first_cstring
|
||||
{
|
||||
template <class T>
|
||||
bool operator()(T const& x, T const& y)
|
||||
{
|
||||
return std::strcmp(x.first,y.first) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct free_mem
|
||||
{
|
||||
free_mem(char*p)
|
||||
: p(p) {}
|
||||
|
||||
~free_mem()
|
||||
{
|
||||
std::free(p);
|
||||
}
|
||||
char* p;
|
||||
};
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
BOOST_PYTHON_DECL char const* gcc_demangle(char const* mangled)
|
||||
{
|
||||
typedef std::vector<
|
||||
std::pair<char const*, char const*>
|
||||
> mangling_map;
|
||||
|
||||
static mangling_map demangler;
|
||||
mangling_map::iterator p
|
||||
= std::lower_bound(
|
||||
demangler.begin(), demangler.end()
|
||||
, std::make_pair(mangled, (char const*)0)
|
||||
, compare_first_cstring());
|
||||
|
||||
if (p == demangler.end() || strcmp(p->first, mangled))
|
||||
{
|
||||
int status;
|
||||
free_mem keeper(
|
||||
cxxabi::__cxa_demangle(mangled, 0, 0, &status)
|
||||
);
|
||||
|
||||
assert(status != -3); // invalid argument error
|
||||
|
||||
if (status == -1)
|
||||
{
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
else
|
||||
{
|
||||
char const* demangled
|
||||
= status == -2
|
||||
// Invalid mangled name. Best we can do is to
|
||||
// return it intact.
|
||||
? mangled
|
||||
: keeper.p;
|
||||
|
||||
std::cout << "demangled name: " << mangled << " as " << demangled << std::endl;
|
||||
p = demangler.insert(p, std::make_pair(mangled, demangled));
|
||||
keeper.p = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return p->second;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
BOOST_PYTHON_DECL std::ostream& operator<<(std::ostream& os, type_info const& x)
|
||||
{
|
||||
return os << x.name();
|
||||
|
||||
@@ -47,6 +47,9 @@ BOOST_PYTHON_DECL void init_module(char const* name, void(*init_function)())
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
BOOST_PYTHON_DECL PyObject* scope::current_scope = 0;
|
||||
namespace detail
|
||||
{
|
||||
BOOST_PYTHON_DECL PyObject* current_scope = 0;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user