[C++-sig] Re: passing a dynamic PyObject * from C++ to Python

David Abrahams dave at boost-consulting.com
Wed Jun 25 20:33:57 CEST 2003


"F. Oliver Gathmann" <gathmann at cenix-bioscience.com> writes:

> With Boost.Python v2, I have not been able to find an equivalent
> solution; I tried various approaches gathered from the Boost.Python
> FAQ and documentation, e.g.

Nicodemus has nearly finished building/documenting a function which
allows you to register conversions from any smart pointer to Python.
See recent posts to this list.  You could use that.


>   template <class T> T identity(T x) {   return x; } template <class
>   T> object get_pointer_reference(T x) {   object f =
>   make_function(&identity<T>,
>   return_value_policy<manage_new_object>()
> 			     );   return f(x); }

Hmm, *nasty* formatting!

  template <class T> 
  T identity(T x) {
     return x;
  }

  template <class T> 
  object get_pointer_reference(T x)
  {   
      object f = make_function(
        &identity<T>, return_value_policy<manage_new_object>());

      return f(x);
  }

Hmm, looks OK to me.

> which compiles fine but crashes at runtime (using gcc 3.2.2 on Linux
> with a recent CVS version of Boost). Any hints that might help me
> solving this mystery would be much appreciated!

Any hints about the condition of the program at the time of crash
would be a big help in helping you.  A reproducible test case would
be even better.


-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list