[C++-sig] stuffing a PyObject into a object
David Abrahams
dave at boost-consulting.com
Tue Oct 30 00:39:17 CET 2007
on Fri Oct 19 2007, "Matthew Scouten" <matthew.scouten-AT-gmail.com> wrote:
> I can understand this except for a couple of things,
>
> What is the PyIter_Next there for? demonstration purposes? or is it an
> essential part of the conversion? Same question for that whole second
> line.
I think it's a mistake.
> will 'allow_null' make a 'None' out of a null pointer? or do some
> other crazy thing?
No, it makes a null handle. It seems superfluous, since the object
ctor will throw an exception anyway if its argument is null.
> more to the point, will this code work:
>
> object foo(void* callbackID == NULL)
> {
> boost::python::handle<> h(boost::python::allow_null((PyObject*)callbackID))
> return boost::python::object o(h);
> }
If the is not pre-incremented for you, then
boost::python::handle<> h((PyObject*)callbackID));
return boost::python::object o(h);
would be correct. Otherwise, you need
boost::python::handle<> h(boost::python::borrowed((PyObject*)callbackID)));
return boost::python::object o(h);
> I am trying to understand what is going on, and not just fall into
> guess and check programming.
Good call.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
More information about the Cplusplus-sig
mailing list