[C++-sig] Lifetime of Python object for a pointer argument

David Abrahams david.abrahams at rcn.com
Sat Feb 16 22:45:55 CET 2002


----- Original Message -----
From: "Min Xu" <minxu at sci.ccny.cuny.edu>
To: <c++-sig at python.org>
Sent: Saturday, February 16, 2002 4:03 PM
Subject: Re: [C++-sig] Lifetime of Python object for a pointer argument


> On Sat, 2002-02-16 at 13:19, David Abrahams wrote:
> >
> > ----- Original Message -----
> > From: "Min Xu" <minxu at sci.ccny.cuny.edu>
> > To: <c++-sig at python.org>
> > Sent: Saturday, February 16, 2002 12:51 PM
> > Subject: Re: [C++-sig] Lifetime of Python object for a pointer argument
> >
> >
> > > Thank you for the nice and quick reply. I downloaded the v2. However
in
> > > <boost_root>/libs/python
> > > # jam -sBOOST_ROOT=/usr/local/src/boost -sTOOLS="gcc" -sBUILD=debug
> > > unknown target type for <libs!python>libbpl.a
> > >
> > > The machine is a linux box with gcc and python2.1. How can I compile
it?
> >
> > Firstly, Python 2.2 is required for Boost.Python V2 (so you'll
> > need -sPYTHON_VERSION=2.2 in the command-line)
> >
> > Secondly, I've seen that bug, but I just fixed it and tested it on linux
> > with gcc last night.
> > Are you sure you are using the current CVS state?
> >
> I deleted my old tree (downloaded yesterday) and reget the source:
>
>  cvs -z3 -d:pserver:anonymous at cvs.boost.sourceforge.net:/cvsroot/boost
> co boost
>
> and then in boost-root:
>  cvs update -dRP -rmpl-development boost/mpl
>
> This time it works. And m1.so m2.so etc are also ok.
>
> Howerver, I have enum and operators (op_add, op_sub etc) in the library
> which are handled correctly in boost.python v1. What is the right way in
> v2 for them?

Unfortunately, those features aren't specifically implemented in v2 yet.
Operators are supported in the usual Python way (i.e. you can expose an
__add__ function), but the automatic wrapping features of v1 are not yet
available. I have not yet decided where this fits in the development plan.
If you wanted to contribute some code it would be very much appreciated, of
course.

Enums can be exposed as ints using the techniques with which scalars are
exposed in libs/python/src/converter/builtin_converters.cpp, but that code
was mostly written to be implementation detail. I guess I need to clean up
and document most of those classes so that users can take advantage of them.

However, I think I've come to *yet another* realization about how the
low-level from_python conversion mechanism should work, so I guess I will be
re-engineering most of what's in builtin_converters.cpp at some point in the
next month or so; you might not want to invest in understanding that.

Finally, <redfaced>I just realized that I haven't yet implemented the use of
CallPolicies in __init__ functions</redfaced>, so this won't compile:

              .def_init(args<const grid*>()
              // Keep the grid alive as long as the geometry is.
                        , python::with_custodian_and_ward<1,2>())

Give me at least until Monday to take care of that.

Anyway, thanks for looking at v2. ;-)

-Dave






More information about the Cplusplus-sig mailing list