[C++-sig] same to_python_converter in multiple modules?

David Abrahams david.abrahams at rcn.com
Thu May 30 15:42:51 CEST 2002


----- Original Message -----
From: "Ralf W. Grosse-Kunstleve" <rwgk at yahoo.com>


> Here is less contrived example for doc/v2/to_python_converter.html:
>
>   template <typename ElementType, std::size_t N>
>   struct boost_array_to_tuple
>   {
>     static PyObject* convert(boost::array<ElementType, N> const& a)
>     {
>       boost::python::tuple result(a.size());
>       for(std::size_t i=0;i<a.size();i++) {
>         result.set_item(i, boost::python::make_ref(a[i]));
>       }
>       return result.reference().release();
>     }
>   };
>
>   boost::python::to_python_converter<
>     boost::array<int, 3>, boost_array_to_tuple<int, 3> >();
>
> If I have two independent modules that both need this converter,
> where would I put the last statement. In both modules? What happens
> if both modules are loaded at the same time? What if I have 30 modules
> that need this converter (this will happen in our application)?

These are all good questions. Right now, I think the behavior is to assert
if you supply two to_python converters for the same type. Since conversions
go into a global registry and since there are no criteria upon which to
choose a to_python conversion other than the source type, it is treated as
an error to register two converters for the same type. What would the
most-useful behavior be? You can of course avoid multiple registrations by
creating a common shared library (or Python module if need be) which
registers the converter and sets a global variable to prevent multiple
registration.

-Dave







More information about the Cplusplus-sig mailing list