[C++-sig] Problems splitting up a library

Roman Yakovenko roman.yakovenko at gmail.com
Fri Sep 14 19:51:49 CEST 2007


On 9/14/07, Pertti Kellomäki <pertti.kellomaki at tut.fi> wrote:
>
> I am exposing a largish library using Py++ and Boost.Python, and I'm
> running into a bit of a problem when I try to expose it in manageable
> parts. I've tried to condense the problem below.
>
> One module contains class NIT:
>
> ==================================================
> class NIT : public IT {
> public:
>      static NIT& instance();
> //...
> }
> ==================================================
>
> which is exposed by Py++ as follows:
>
> ==================================================
> struct NIT_wrapper : TT::NIT, bp::wrapper< TT::NIT > {
> //...
> };
>
> BOOST_PYTHON_MODULE(mach){
>      bp::class_< NIT_wrapper,
>                  bp::bases< TT::IT >,
>                  boost::noncopyable >
>      ( "NIT", bp::no_init )
>          .def("instance"
>              , (::TT::NIT & (*)(  ))
>                   ( &::TT::NIT::instance )
>              , bp::return_value_policy< bp::reference_existing_object
> >() )
>          .staticmethod( "instance" );
>      //...
> ==================================================
>
> In another module, there is a member function that uses NIT as a default
> value:
>
> ==================================================
> class I {
> public:
>      I(const TT::IT& iT = TT::NIT::instance());
>      //...
> }
> ==================================================
>
> This is exposed by Py++ as follows:
>
> ==================================================
> BOOST_PYTHON_MODULE(program){
>      bp::class_< TTAProgram::I,
>                  boost::noncopyable >
>           ( "I",
>             bp::init< bp::optional< TT::IT const & > >
>                  (( bp::arg("iT")
>                      =TT::NIT::instance( ) )) )
>      //...
> ==================================================
>
> Importing the "mach" Python extension as
>
>         import TCE.base.mach
>
> succeeds, but
>
>         import TCE.base.program
>
> results in the error message
>
>         Traceback (most recent call last):
>           File "<stdin>", line 1, in <module>
>         TypeError: No to_python (by-value) converter found
>         for C++ type: TTAMachine::NullInstructionTemplate
>
> If I remove the default value from the signature, the problem
> disappears. Any ideas how to fix this?


This is a Boost.Python limitation: you can't register function with default
argument - it requires the type of the argument to be already registered. By
importing the module TCE.base.mach you register the relevant class.

Take a look on next link:
http://language-binding.net/pyplusplus/documentation/functions/default_args.html

HTH



-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070914/713d2472/attachment.htm>


More information about the Cplusplus-sig mailing list