diff --git a/src/converter/registry.cpp b/src/converter/registry.cpp index 88d96637..d247353c 100644 --- a/src/converter/registry.cpp +++ b/src/converter/registry.cpp @@ -39,35 +39,6 @@ namespace registry { } - namespace // - { - // A UnaryFunction type which deletes its argument - struct delete_item - { - template - void operator()(T* x) const - { - delete x; - } - }; - - // A UnaryFunction type which returns true iff its argument is a - // unwrapper which can convert the given Python object. - struct convertible - { - convertible(PyObject* p) - : m_p(p) - {} - - bool operator()(unwrapper_base* converter) const - { - return converter->convertible(m_p); - } - - PyObject* m_p; - }; - } - entry::~entry() { if (m_wrapper != 0) @@ -79,12 +50,25 @@ namespace registry } } - unwrapper_base* entry::unwrapper(PyObject* p) const + std::pair + entry::unwrapper(PyObject* p) const { - unwrappers::const_iterator q = - std::find_if(m_unwrappers.begin(), m_unwrappers.end(), convertible(p)); + unwrapper_base* body = 0; + void* data = 0; - return q == m_unwrappers.end() ? 0 : *q; + for (unwrappers::const_iterator q = m_unwrappers.begin(), + finish = m_unwrappers.end(); + q != finish; + ++q) + { + data = (*q)->can_convert(p); + if (data != 0) + { + body = *q; + break; + } + } + return std::make_pair(body,data); } wrapper_base* entry::wrapper() const diff --git a/src/converter/unwrap.cpp b/src/converter/unwrap.cpp index e0c09db6..33a7d7ae 100644 --- a/src/converter/unwrap.cpp +++ b/src/converter/unwrap.cpp @@ -13,7 +13,7 @@ namespace struct pyobject_unwrapper : unwrapper_base { pyobject_unwrapper(); - bool convertible(PyObject*) const; + void* can_convert(PyObject*) const; }; pyobject_unwrapper static_unwrapper; @@ -23,13 +23,13 @@ namespace { } - bool pyobject_unwrapper::convertible(PyObject*) const + void* pyobject_unwrapper::can_convert(PyObject*) const { - return true; + return non_null; } } -BOOST_PYTHON_EXPORT unwrapper_base* -unwrap_more_::m_unwrapper = &static_unwrapper; +BOOST_PYTHON_DECL std::pair +unwrap_more_::m_unwrapper(&static_unwrapper,&static_unwrapper); }}} // namespace boost::python::converter diff --git a/src/converter/unwrapper.cpp b/src/converter/unwrapper.cpp index 2b0adbd0..6279febf 100644 --- a/src/converter/unwrapper.cpp +++ b/src/converter/unwrapper.cpp @@ -21,4 +21,11 @@ unwrapper_base::~unwrapper_base() registry::remove(*this); } +namespace +{ + int arbitrary; +} + +void* const unwrapper_base::non_null = &arbitrary; + }}} // namespace boost::python::converter