[C++-sig] Re: BPL and embedding python

Dave Hawkes daveh at cadlink.com
Wed Jun 12 03:36:15 CEST 2002


----- Original Message -----
From: "David Abrahams" <david.abrahams at rcn.com>
Newsgroups: gmane.comp.python.c++
Sent: Tuesday, June 11, 2002 6:49 PM
Subject: Re: BPL and embedding python


> From: "Dave Hawkes" <daveh at cadlink.com>
>
>
> > I've noticed that more and more people are attempting to embed python in
> > applications and documentation  on how to do this effectively is quite
> > scarce. One of the strengths of boost is the ability to create a c++
> class
> > instance and override some of its members in python, but use the actual
> > class instance from within c++. In fact you can create a class instance,
> > modify some of its members using on the fly generated python code and
> then
> > pass the c++ instance back to yor c++ code.
> >
> > I've done this with with boost V1 along these lines:
>
> Thanks for your post. Just to clarify, what you're demonstrating below is
> how to create a Python instance of your wrapped C++ class from C++.
>
>

That's basically it.

> <snip>
>
> > Remember this is NOT complete code and just an outline of how to
proceed.
> >
> > The fly in the ointment is not being able to directly delete the class
> > instances (Dave, do you have any ideas ?)
>
> Hmm. Unfortunately, no. The class instance itself is a data member of
> another class; that would lead to double-destruction. Why do you want to
> directly delete the class instance?
>
> I've been thinking about a smart pointer type which manages a python
object
> but "points to" some internally-held C++ object for v2, so you could
write:
>
>     lvalue_ptr<MyClass> p(call<PyObject*>(pPyClass));
>
> and then,
>
>     p->some_member_function();
>
> Would that help?
>
> Hmm, lvalue_ptr<> would probably replace back_reference<> in the v2
> interface...
>

Then when the smart pointer is destroyed it just decrements the object
reference. Yes, that sounds like a promising solution.


Dave Hawkes






More information about the Cplusplus-sig mailing list