[C++-sig] Registration order in pyplusplus

Niall Douglas s_sourceforge at nedprod.com
Wed Feb 8 18:25:21 CET 2006


As requested moved onto the python C++ SIG mailing list.

> > Tried it with CVS pyplusplus this morning and it's still not ordering
> > registrations correctly. If you try loading in the TnFOX.pyd module
> > you will get the "No to_python (by-value) converter found for C++
> > type: class FX::FXACLEntity" fatal exception because
> > register_FXACL_class() needs register_FXACLEntity_class() before it.
> 
> This is what I don't understand and can not create with simple use case,
> that will reproduce the problem.
> 
> See this mail:
> http://mail.python.org/pipermail/c++-sig/2006-January/010100.html

This email is incorrect. Here is the backtrace for when the exception 
is thrown:

 	TnFOX.dll!boost::python::throw_error_already_set()  Line 61	C++

 	TnFOX.dll!boost::python::converter::registration::to_python(const 
void * source=0x605dc654)  Line 53	C++

TnFOX.dll!boost::python::converter::detail::arg_to_python_base::arg_to
_python_base(const void * source=0x605dc654, const 
boost::python::converter::registration & converters={...})  Line 24 + 
0x13	C++
 	
TnFOX.dll!boost::python::api::object_initializer_impl<0,0>::get<FX::FX
ACLEntity>(const FX::FXACLEntity & x={...}, boost::mpl::bool_<0> 
__formal={...})  Line 368 + 0x12	C++
 	
TnFOX.dll!boost::python::api::object_base_initializer<FX::FXACLEntity>
(const FX::FXACLEntity & x={...})  Line 290 + 0xd	C++
 	
TnFOX.dll!boost::python::detail::keywords<1>::operator=<FX::FXACLEntit
y>()  Line 74 + 0x9	C++

	TnFOX.dll!register_FXACL_class()  Line 285 + 0x54	C++

 	TnFOX.dll!init_module_TnFOX()  + 0x19	C++


This localises the problem code to:

void register_FXACL_class(){
    if( true ){
        typedef bp::class_< FXACL_wrapper > FXACL_exposer_t;
        FXACL_exposer_t FXACL_exposer = FXACL_exposer_t( "FXACL", 
bp::init< FX::FXACL::EntityType, FX::FXACLEntity const & >(( 
bp::arg("type")=::FX::FXACL::Unknown, 
bp::arg("owner")=FX::FXACLEntity::currentUser( ) ))/*[ undefined call 
policies ]*/ );

In other words, the requirement for the FXACLEntity definition to BPL 
is coming from its use in the constructor for FXACL - specifically 
the bit ' bp::arg("owner")= ' - which I am guessing from the 
boost::python::detail::keywords<1>::operator=<FX::FXACLEntity>() just 
above it in the backtrace.

Dave - does boost::python::arg()= require the type of the parameter 
being set to be already registered? I would imagine that it surely 
does.

> I attach test file, can you take a look on them? May be you have some ideas?
> What can cause this error?

Really, the best thing is to build the full TnFOX Python bindings and 
test them. It's probably a little slow on your computer though, so I 
understand if you don't want to do so.

> > > > There's a simple solution - ensure that registrations occur in
> > > > exactly the same order of class definitions in the parsed header. I
> > > > vaguely remember a problem with this as GCCXML doesn't always do what
> > > > one expect here, but you're more an expert here than I.
> > >
> > > pyplusplus has class class_organizer_t that is responsible for order of classes.
> > > It uses topological sort in order to decide it. If needed, I can add
> > > an other condition
> > > to it.
> >
> > If you examine the fx.xml file you will see that FXACLEntity is given
> > id=_27958 and FXACL is given id=_28827. Now I don't know if the id
> > number is incremented linearly, but I do notice that incomplete
> > declarations can happen and these would screw with the correct
> > ordering. You need to order registrations in the same order as
> > *complete* declarations. This may mean running your own counter which
> > is only incremented with every complete declaration, then later
> > ordering in terms of this count.
> 
> Niall, I don't understand what cause the problem. So I can not solve it.
> I need to understand it first. After this I am sure we can find some solution.

I had the same problem with pyste, hence Bruno implemented the 
solution I suggested above and it worked.

> I do not want to prevent you from working. I give you few ideas for
> work around:

It's okay - I have an obscene amount of work on right now (I am 
organising a lecture series in addition to my normal workload, and it 
begins next week).

> 1. exclude those class
>     very simple solution, you can implement this in few minutes,
> 
> 2. change the order of classes: you can find FXACL and FXACLEntity code creators
>    and to adjust their positions. I can implement this solution for
> you. Tell me if you
>    want me to do it for you. If you want to try to implement it
> itself, then take a look
>    on code_creators.compound_t class. It has to members remove_creator and
>    adopt_creator. adopt_creator allows you to place creator to
> specific position.
>    code_creators.creator_finder class provides functionality to find
> code creator
>    base on some criteria.

If you try either of these you run into major problems - there are 
too many dependency issues to do it manually. I did try shuffling 
around the registrations but gave up after I had moved ten.

Cheers,
Niall






More information about the Cplusplus-sig mailing list