// Copyright David Abrahams 2001.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include
#include
#include
#include
#include
#if defined(__APPLE__) && defined(__MACH__) && defined(__GNUC__) \
&& __GNUC__ == 3 && __GNUC_MINOR__ m_class_object != 0)
return this->m_class_object;
std::set pool;
for(rvalue_from_python_chain* r = rvalue_chain; r ; r=r->next)
if(r->expected_pytype)
pool.insert(r->expected_pytype());
//for now I skip the search for common base
if (pool.size()==1)
return *pool.begin();
return 0;
}
BOOST_PYTHON_DECL PyTypeObject const* registration::to_python_target_type() const
{
if (this->m_class_object != 0)
return this->m_class_object;
if (this->m_to_python_target_type != 0)
return this->m_to_python_target_type();
return 0;
}
BOOST_PYTHON_DECL PyTypeObject* registration::get_class_object() const
{
if (this->m_class_object == 0)
{
::PyErr_Format(
PyExc_TypeError
, const_cast("No Python class registered for C++ class %s")
, this->target_type.name());
throw_error_already_set();
}
return this->m_class_object;
}
BOOST_PYTHON_DECL PyObject* registration::to_python(void const volatile* source) const
{
if (this->m_to_python == 0)
{
handle msg(
#if PY_VERSION_HEX >= 0x3000000
::PyUnicode_FromFormat
#else
::PyString_FromFormat
#endif
(
"No to_python (by-value) converter found for C++ type: %s"
, this->target_type.name()
)
);
PyErr_SetObject(PyExc_TypeError, msg.get());
throw_error_already_set();
}
return source == 0
? incref(Py_None)
: this->m_to_python(const_cast(source));
}
namespace
{
template< typename T >
void delete_node( T* node )
{
if( !!node && !!node->next )
delete_node( node->next );
delete node;
}
}
registration::~registration()
{
delete_node(lvalue_chain);
delete_node(rvalue_chain);
}
namespace //
{
typedef registration entry;
typedef std::set registry_t;
#ifndef BOOST_PYTHON_CONVERTER_REGISTRY_APPLE_MACH_WORKAROUND
registry_t& entries()
{
static registry_t registry;
# ifndef BOOST_PYTHON_SUPPRESS_REGISTRY_INITIALIZATION
static bool builtin_converters_initialized = false;
if (!builtin_converters_initialized)
{
// Make this true early because registering the builtin
// converters will cause recursion.
builtin_converters_initialized = true;
initialize_builtin_converters();
}
# ifdef BOOST_PYTHON_TRACE_REGISTRY
std::cout