[C++-sig] How to return handle<PyObject>?

Neal Becker ndbecker2 at gmail.com
Fri Jan 4 22:48:40 CET 2008


Roman Yakovenko wrote:

> On Jan 4, 2008 7:51 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
>> I have a function that returns handle<some PyObject>.  What is the best
>> return policy?
> 
> I think the default one. I think it's better to create
> boost::python::object and return it.
> 
> 

Both seem to work OK.

FYI, neither compiles until after I added this:

namespace boost { namespace python { namespace converter {
template<>
struct pyobject_traits<PyArrayObject> : public pyobject_traits<PyObject> {};
}}}

FYI, here is the code in question:

inline handle<PyArrayObject> test_new () {
  numpy_1d_array<long> a (10, 2); << this contains a handle<PyArrayObject> member (a.arr) 
  return a.arr;
}

inline object test_new2 () {
  numpy_1d_array<long> a (10, 2);
  return object(a.arr);
}





More information about the Cplusplus-sig mailing list