[C++-sig] Getting object for PyObject (reference counting)

Murray Cumming murrayc at murrayc.com
Thu Feb 11 13:18:46 CET 2010


On Fri, 2009-02-27 at 15:18 -0800, Alex Mohr wrote:
[snip]
>  If you have a PyObject *p and you want a bp::object, 
> construct it via:
> 
> object(handle<>(p))           // when p's a new reference

I find that I have to split the handle and object over two lines. If I
do this
  boost::python::object cppobject(boost::python::handle<>(cObject));
and then something like this:
  if(!cppobject.ptr())
    doSomething()

then I get this weird compiler error on the if() line:

glom/python_embed/glom_python.cc:229: error: request for member ‘ptr’ in
‘cppobject’, which is of non-class type
‘boost::python::api::object(boost::python::handle<_object>)’

It's as if doing it on one line has changed the type. Maybe I've
discovered some weird bug with g++ 4.4

> object(handle<>(borrowed(p))) // when p's a borrowed reference

However, this works fine, when it's what I want.

-- 
murrayc at murrayc.com
www.murrayc.com
www.openismus.com



More information about the Cplusplus-sig mailing list