[C++-sig] Boost.Python v2: reference-counting and user-friendly conversions
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Fri Jun 14 01:46:22 CEST 2002
> The interface for causing the reference count to be incremented has
> changed: now one passes the argument through the borrow() function,
> signaling that we are getting a borrowed reference:
>
> handle<> x(borrow(PyTuple_GetItem(t, n)));
"borrow" sounds like we are about to borrow something, when indeed
we are "signaling that we are getting a borrowed reference."
Therefore ^^
handle<> x(borrowed(PyTuple_GetItem(t, n)));
seems much more intuitive to me.
> Now, on to user-friendly conversions. It seems to me that the best way to
> spell to_python(x) would be simply:
>
> object(x)
Cool.
> So, what's the behavior when the user passes a raw PyObject*? It seems to
> me that we'd like the following to work:
>
> object(PyObject_GetAttrString(some_PyObject_pointer,
>"some_attribute_name"))
Considering all the questions that follow, are you sure it is worth it?
I'd only expect to be able to do this:
object(handle<>(PyObject_GetAttrString(
some_PyObject_pointer, "some_attribute_name")))
If I understand correctly, eventually there will be a wrapper for
PyObject_GetAttrString anyway, so being able to construct an object()
from PyObject* directly as a convenience will not be interesting.
> Right now, if you pass a PyObject* as an argument to call<>, we first check
> for NULL (in which case we manufacture a reference to None) then the
> reference count is incremented before the arg_to_python converter takes
> possession.
If you'd make handle<> the only interface that accepts PyObject* you
could avoid many of your questions. You could make the NULL -> None
conversion explicit: in addition to borrowed() and allow_null() you
could supply null_to_none().
Ralf
__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com
More information about the Cplusplus-sig
mailing list