[C++-sig] with_custodian_and_ward problem

Roman Yakovenko roman.yakovenko at gmail.com
Sat Jun 9 19:56:10 CEST 2007


On 6/8/07, Hans Meine <meine at informatik.uni-hamburg.de> wrote:
> Hi!
>
> I have a typical call policies problem, which I believed to be solvable with
> with_custodian_and_ward, but I cannot get it to compile.  (I am using
> make_constructor, maybe that is relevant?)  I guess that I simply did not
> understand BPL's reference counting policies correctly..
>
> I created a testcase (attached, too):
>
> This is my class which internally stores a reference to an object given to the
> constructor:
> > struct T
> > {
> >     T(int &foo) : foo_(foo) {}
> >     int &foo_;
> > };

The constructor takes immutable type( int ) by reference. You cannot
directly expose this constructor.

> > int someInt;
> >
> > static T *createT()
> > {
> >     return new T(someInt);
> > }
>
> I tried using this export code (and some others), which is obviously wrong:
> >     class_<T, boost::noncopyable>("T", no_init)
> >         .def("__init__", make_constructor(
> >                  &createT,
> >                  with_custodian_and_ward_postcall<0, 1>()));
>
> How can I properly tell BPL to make sure that the object passed to the
> constructor must not be deleted before the "T" instance?

In the example you gave you didn't pass any argument to "createT" function.

>
> PS: I am currently using 1.34.0beta, does that matter?

I don't think so

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



More information about the Cplusplus-sig mailing list