[C++-sig] Boost.python suggestion + pyste bug

Nicodemus nicodemus at globalite.com.br
Mon Aug 11 01:18:16 CEST 2003


Niall Douglas wrote:

>On 8 Aug 2003 at 0:01, Nicodemus wrote:
>
>
>>>Lastly, am I right in thinking that pyste currently does not use
>>>boost.python's ability to represent C++ class inheritance trees the
>>>same in python classes? I'm thinking that if you were to add support
>>>for this, it kinda works with the fixes necessary for fixing the bugs
>>>above.
>>>
>>What do you mean? It should export classes in the same way as if you
>>were doing it by hand, but automatically. One difference is that it
>>now automatically exports the members of base classes that were not
>>exported themselves, as a feature request here in the list:
>>
>>struct A
>>{
>>    void foo();
>>};
>>
>>struct B: A
>>{
>>    void bar();
>>};
>>
>>If you export only B, you will get A's foo method too, as if you were
>>exporting both A and B.
>>
>
>Firstly my apologies for the late reply, I've been laid up in bed 
>these last few days with what looks like influenza. Odd given it's 
>30C outside!
>
>You're not quite understanding me. I shall illustrate:
>
>If I have classes A, B & C where A inherits B and B inherits C, and I 
>were exporting classes A and C to python, I should write:
>
>class_<C>("C").def(...
>
>class_<A, bases<C> >("A").def(...  // NOT bases<B>
>
>Currently pyste does not generates bases<> for anything. I can 
>understand this because it is complex - you must analyse what classes 
>each interface file exports before being able to say what inherits 
>what *also* *exposed*.
>
>However if you've fixed those bugs I reported with some other method, 
>then cool, I can do without this.
>

Oh, I understand now, sorry. I thought you were talking about methods.

The current way is proposital. The bases<> template must expose the base 
classes that were *exported*:

struct A
{
    void foo(){};
};

struct B: A
{
    void foobar(){};
};

struct C: B
{
    void bar(){};
};

exporting only A and C, you get:

    class_< A >("A", init<  >())
        .def(init< const A& >())
        .def("foo", &A::foo)
    ;

    class_< C, bases< A >  >("C", init<  >())
        .def(init< const C& >())
        .def("bar", &C::bar)
        .def("foobar", &B::foobar)
    ;

Which is correct. If you try to change bases< A > to bases< B >, your 
extension won't work (it will compile, but it will raise an exception 
when you try to import it).

Now, if you are saying that bases<> are always empty, I guess the 
problem is that you're using AllFromHeader, which is broken in the 
current CVS. Try changing from AllFromHeader to Class calls, that should 
make the problem go away.

Regards,
Nicodemus.





More information about the Cplusplus-sig mailing list