Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-10-10 11:38:08

----- Original Message -----
From: "gideon may" <gideon_at_[hidden]>
> Dear David,
> some time ago I posted these questions to the boost list, but
> unfortunately missed a reply.


> I was hoping that you might be able to shed a light on the questions.
> TIA,
> gideon
> 2 questions:
> 1:I need to get to the wrapper object (PyObject*) which is generated
> for a class within the member function. Is there an easy way
> to get to this ?

Unfortunately, there is no "object registry" or similar mechanism which can
find the Python object associated with an arbitrary object.

> IE given the hello example within the documentation, I would like
> to access the PyObject * for hi within the invite function.
> I know that I can achieve it with the following :
> std::string invite(const hello& w, PyObject * self) {
> return w.greet() + "! Please come soon!";
> }
> >>> hi.invite(hi)
> but is there a way where I don't have to pass the object as parameter?

You could write something like this:

std::string invite(PyObject* w) {
    const hello& w2 = boost::python::from_python(w,
boost::python::type<const hello&>());
    w.greet() + "! Please come soon!";

...and add that to your class instead:

hello_class.def(invite, "invite");

> 2nd: When an object is deleted, would it be possible for the
> destructor of the wrapper object to call an extra function ?
> I have some c++ classes for which I allocate some extra data
> and I need to clean this up when the object is deleted. I don't
> have access to the class destructor directly.

How is that possible? Who allocates the data?

Anyway, I guess you could do it in the destructor of the callback class if
you have virtual functions. Even if you don't have virtual functions, the
technique described for handling them at should work.

> Hope these questions are not too cryptic.

Only a little ;-)

  David Abrahams, C++ library designer for hire

        C++ Booster (
          email: david.abrahams_at_[hidden]

Boost list run by bdawes at, gregod at, cpdaniel at, john at