[C++-sig] object(PyObject*) ?

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Fri Dec 20 16:31:12 CET 2002


--- Jacek Generowicz <jacek.generowicz at cern.ch> wrote:
> Is there a way of achieving it ?

Use

boost::python::handle<>

e.g.

   boost::python::handle<> h(boost::python::allow_null(PyIter_Next(x)));
   if (!h.get()) break; // end of iteration
   boost::python::object o(h);

If you omit allow_null, e.g.

   boost::python::handle<> h(PyIter_Next(x));

an exception is thrown if PyIter_Next(x) returns NULL.

There is also

boost::python::object o(boost::python::borrowed(x));

to indicate that x is a borrowed reference (i.e. o does not take ownership).

Ralf


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com




More information about the Cplusplus-sig mailing list