[C++-sig] wrapper & HeldType

Roman Yakovenko roman.yakovenko at gmail.com
Tue Oct 11 07:48:08 CEST 2005


Sorry, I pushed the wrong button.

Hi. I think I found bug in treatment of held type.
Consider next code:

struct data{
    virtual int f();
}

There are 2 way to "override" f in Python.
The first one is:
struct data_wrapper : data, wrapper<data>{...}

And the second one:

struct data_wrapper : data{
    data_wrapper( PyObject* self,...)

private:
    PyObject* m_self;
}

The problem is that if I want HeldType to be smart pointer, in my
specific case is shared_ptr, then I can not use the first way as is.

class_< data, data_wrapper, shared_ptr<data> >(...) will not compile.
The message, compiler gives, is too long to post, but it say something
that data_wrapper does not have
constructor that takes PyObject* as first argument. If I add PyObject*
as first argument to
data_wrapper constructor then all works as expected.

There are a few things, that I think, are wrong here:
1. wrapper<data> already has access to self. So the data_wrapper does
not have to
    keep reference to self:
    struct data_wrapper : data, wrapper< data >{
        data_wrapper( PyObject* self )
        : data(), wrapper<data>(){
             //unused first argument
        }
    }

2. If I use first approach to wrap classes, then I write
    class_< data_wrapper >(...)
    in order to use custom HeldType I should switch to
   class_< data, data_wrapper, shared_ptr<data> > syntax. I thing that
this interface
    is not perfect. The better one is
    class_< data_wrapper, shared_ptr<data> >. I think that
Boost.Python can find out
    needed information about HeldType from HeldType itself.

Hope I was clear.

P.S.
I tried to find out the place where fix should be done, but lost in
ppl and mpl and
recursive includes.

Thanks

Roman Yakovenko



More information about the Cplusplus-sig mailing list