2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-29 19:52:16 +00:00

more implicit conversion work

[SVN r13282]
This commit is contained in:
Dave Abrahams
2002-03-26 17:16:33 +00:00
parent ac34e0e108
commit 576269dae9
8 changed files with 73 additions and 6 deletions

View File

@@ -7,6 +7,8 @@
#include <boost/python/converter/find_from_python.hpp>
#include <boost/python/converter/registrations.hpp>
#include <boost/python/converter/from_python_data.hpp>
#include <vector>
#include <algorithm>
namespace boost { namespace python { namespace converter {
@@ -29,15 +31,38 @@ BOOST_PYTHON_DECL rvalue_stage1_data find(
return data;
}
namespace
{
// Prevent looping in implicit conversions. This could/should be
// much more efficient, but will work for now.
typedef std::vector<rvalue_from_python_registration const*> visited_t;
static visited_t visited;
}
BOOST_PYTHON_DECL rvalue_from_python_registration const* find_chain(
PyObject* source
, rvalue_from_python_registration const* chain)
{
for (;chain != 0; chain = chain->next)
{
visited_t::iterator p = std::lower_bound(visited.begin(), visited.end(), chain);
if (p != visited.end() && *p == chain)
return 0;
visited.insert(p, chain);
try
{
if (chain->convertible(source))
break;
for (;chain != 0; chain = chain->next)
{
if (chain->convertible(source))
break;
}
}
catch(...)
{
visited.erase(p);
throw;
}
p = std::lower_bound(visited.begin(), visited.end(), chain);
visited.erase(p);
return chain;
}

View File

@@ -109,6 +109,22 @@ namespace registry
found->m_rvalue_from_python = registration;
}
// Insert an rvalue from_python converter
void push_back(void* (*convertible)(PyObject*)
, constructor_function construct
, undecorated_type_id_t key)
{
rvalue_from_python_registration** found = &find(key)->m_rvalue_from_python;
while (*found != 0)
found = &(*found)->next;
rvalue_from_python_registration *registration = new rvalue_from_python_registration;
registration->convertible = convertible;
registration->construct = construct;
registration->next = 0;
*found = registration;
}
PyTypeObject*& class_object(undecorated_type_id_t key)
{
return find(key)->m_class_object;