Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-10-24 23:33:12


"Alan Scales" <alans_at_[hidden]> writes:

> boost python vs. 2.0 (boost 1_29_0):
> msvc++ 6.0
> compile problems
> ---------------------------------------------------------
>
> i am having a problem compiling any statement containing a call policy.

Your best bet for Boost.Python questions is the C++-sig:
http://www.python.org/sigs/c++-sig/. People other than me are watching
that list.

> in particular in the reference manual there is the following example:

...which is wrong :( ...

> #include <boost/python/module.hpp>
> #include <boost/python/class.hpp>
> #include <boost/python/reference_existing_object.hpp>
> #include <boost/python/return_value_policy.hpp>
> #include <utility>
>
> // classes to wrap
> struct Singleton
> {
> Singleton() : x(0) {}
> int exchange(int n) // set x and return the old value
> {
> std::swap(n, x);
> return n;
> }
> int x;
> };
>
> Singleton& get_it()
> {
> static Singleton just_one;
> return just_one;
> }
> // Wrapper code
> using namespace boost::python;
> BOOST_PYTHON_MODULE(singleton)
> {
> def("get_it", get_it, reference_existing_object());

should be:

      def("get_it", get_it
          , return_value_policy<reference_existing_object>());

> class_<Singleton>("Singleton")
> .def("exchange", &Singleton::exchange)
> ;
> }
>
> The line
> def("get_it", get_it, reference_existing_object());
> results in the following compiler errors (comment it out and everything compiles)
>
> and a bunch more.

I'll fix that in the CVS. The problem is that
reference_existing_object is actually a ResultConverterGenerator
(http://www.boost.org/libs/python/doc/v2/ResultConverter.html#ResultConverterGenerator-concept),
not a CallPolicy

> I cannot use jam to build my extensions so i am just using visual
> studio (i have done this successfully in the pass with pre 2.0
> versions).

Really, you can't use bjam?

> I assume i am missing a #define or something dumb. if there is an
> faq or something i should be looking at just direct me there.

Nope, it's just my fault.

HTH,

-- 
                    David Abrahams
dave_at_[hidden] * http://www.boost-consulting.com
Building C/C++ Extensions for Python: Dec 9-11, Austin, TX
http://www.enthought.com/training/building_extensions.html

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