Murray Cumming wrote:
I can't find any definitive documentation that tells me how I should get
a boost::python::object to wrap an existing PyObject*. I guess that
there's a way to do it that uses an existing reference, and a way that
takes an extra reference.

You can construct a boost::python::object with a boost::python::handle<>. boost::python::handle<> is sort of a "smart" PyObject *. It manages the python object reference count automatically. When you create a boost::python::handle<> you can tell it whether to bump the reference count or not. Given a PyObject *p:

// Use with a "new reference" -- *doesn't* bump ref count.
handle<>(p);

// Use with a "borrowed reference" -- *does* bump ref count.
handle<>(borrowed(p));

Alex
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to