[C++-sig] Strange boost python error message (and solution)

David Abrahams dave at boost-consulting.com
Wed May 24 13:30:41 CEST 2006


François Duranleau <duranlef at iro.umontreal.ca> writes:



> Good, but what I actually meant is this: if I'm not mistaken,

> to_python_function_t is a function pointer type. Thus, wouldn't it be

> possible to do the following (highlighted with //****...):

>

> //from libs/python/src/converter/registry.cpp

>

>   void insert(to_python_function_t f, type_info source_t)

>   {

> #  ifdef BOOST_PYTHON_TRACE_REGISTRY

>       std::cout << "inserting to_python " << source_t << "\n";

> #  endif

>       to_python_function_t& slot = get(source_t)->m_to_python;

>

> //      assert(slot == 0); // we have a problem otherwise

>

>       //*************************************************************

>       if (slot == f) // already registered with the same function, do

>                      // nothing?

>       {

>           return;

>       }

>       //*************************************************************

>

>       if (slot != 0)

>       {

>           std::string msg = (

>               std::string("to-Python converter for ")

>               + source_t.name()

>               + " already registered; second conversion method ignored."

>           );

>

>           if ( ::PyErr_Warn( NULL, const_cast<char*>(msg.c_str()) ) )

>           {

>               throw_error_already_set();

>           }

>       }

>       slot = f;

>   }



That's a very nice solution, consistent with other parts of Boost.Python.



-- 

Dave Abrahams

Boost Consulting

www.boost-consulting.com





More information about the Cplusplus-sig mailing list