Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-04-01 09:49:05


----- Original Message -----
From: "Rainer Deyke" <root_at_[hidden]>
>
> There are cases where 'boost::python::owned_by_arg' is inadequate. For
> example, consider the following:
>
> // Singleton pattern:
> C& get_the_C()
> {
> static C the_C;
> return the_C;
> }

Good point. On the other hand, there's no way to automatically distinguish
between handling this case and handling the "dangerous" one. So the
question: should we make the dangerous case easy? Maybe so, as long as it's
explicit. So, in place of "owned_by_arg(n)", we could also allow
"unmanaged".

> // Object not passed to Python through return value:
> void outer::f() {
> boost::python::callback<void>::call_method(this->self, f,
> this->inner_object);
> }

Good point. With "unmanaged" my prescription would be something like:

// Object not passed to Python through return value:
void outer::f() {
  boost::python::callback<void>::call_method(this->self, f,
    boost::python::to_python(unmanaged, this->inner_object));
}

I can see that this may have some unpleasant interactions with my proposal
to add a 2nd argument to the to_python function. It's just a question of
syntax, but it would be good to work out a nice one.

> // Object retrieved from Python, then passed back through a different
> function:
> class C {
> public:
> set_d(D *d) { this->d = d; }
> D* get_d() const { return this->d; }
> private:
> D *d;
> };

I only see two possible approaches for this case:

1. use "unmanaged", making the Python code dangerous
2. register every managed C++ object in some kind of map so that the
corresponding PyObject can be found. This seems way too expensive to me.

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk