I have several modules which define converters for some trivial types (such as list of ints as std::vector<int>); they are parts of independent modules, but they are sometimes both used in one script, which leads to
RuntimeWarning: to-Python converter for std::vector<int, std::allocator<int> > already registered; second conversion method ignored.
How can I check that converter for some type is already define and skip the second registration?
boost::python::type_info info = boost::python::type_id<YourType>();
const boost::python::converter::registration* reg = boost::python::converter::registry::query(info);
if (reg == NULL) {
//register YourType
} else if ((*reg).m_to_python == NULL) {
//register YourType
}
Note that you need to check also for ((*reg).m_to_python == NULL) otherwise you risk, in some architectures, that the registration does not happen as a default constructor because registration has been called assigning a NULL converter to YourType. In this case query(info) does return the address of the empty registration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With