[C++-sig] Registration order in pyplusplus

Roman Yakovenko roman.yakovenko at gmail.com
Thu Feb 9 06:59:58 CET 2006


On 2/8/06, Niall Douglas <s_sourceforge at nedprod.com> wrote:
> As requested moved onto the python C++ SIG mailing list.

Thanks

> > > 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 ]*/ );

Thank you very much, now I understand the whole problem. See end of the email
for solution.

> 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 will start an other thread. I have simple test case that reproduce the problem

> 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.

I do want but I am not able. pyplusplus generates +- 300 cpp files. It
takes  2.5 minutes
to compile every file on my laptop at home. So in order to compile
TnFOX I need more or
less 12-13 hours. On my work we have compilation farm from 15
computers. So it takes
10 - 15 minutes to compile it. But I do not have time to setup whole
environment.
And the main reason: I want to setup unit test for pyplusplus.

>
> > > > > 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 am sure this solution works. I have only one problem with this
solution: it works
only in case you want to export declarations, from single header file.

Solution for the problem:
function_t and constructor_t code creators has property "use_keywords"
This property is responcible for generation of keyword arguments. If you set
it to False, then keyword arguments will not be generated.

Here is relevant code:

relevant_classes = (code_creators.function_t, code_creators.constructor_t )
calldefs = filter( lambda creator: isinstance( creator, relevant_classes )
                       , code_creators.make_flatten( extmodule.creators ) )
  for calldef in calldefs:
     calldef.use_keywords = False

Your version of pyplusplus already has this functionality, but it has few bug.
Please, use latest CVS version.

> Cheers,
> Niall
>

Thanks.

--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list