On Mittwoch 29 Oktober 2008, Dan Eloff wrote:
> When creating an object from a PyObject *, how do you distinguish
> between a PyObject pointer that is a new reference (must not be
> increfed, but must be decrefed) versus a PyObject * that is a borrowed
> reference? (should be increfed and decrefed)
>
> A very simple question for which there is no documented answer,
> conflicting answers in the archives of this mailing list, and hours of
> googling has turned up conflicting information.
>
> The best I could find was object(borrowed(ptr)) for new references and
> object(handle<>(ptr)) for borrowed pointers. I'm not sure if that is
> accurate, but if so that deserves a nomination for a terrible
> interface award.
>
> Please someone put me out of my misery. What's the interface for this?

IIRC I have complained about this in the past, too.  I think it was actually 
discussed in the BPL tutorial (and only there AFAIK), but was eventually 
deleted (probably because it was not the best place for that kind of 
information).

Actually, I have the same question as you, and the same impression that the 
above two ways are the "correct" ways.  Err, no - you did swap the two, 
right?

Looking back at my code, I think I used boost::python::detail::new_reference.

And for turning a Foo* pointer to an object of an exported class Foo, I used 
something as ugly as:
bp::detail::new_reference(typename manage_new_object::apply<T *>::type()(p)

AFAICS, I repeated my questions a total of three times (in the "How about 
class_<...>.enable_copy() ?" thead), but nobody answered so far.

-- 
Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo

Attachment: signature.asc
Description: This is a digitally signed message part.

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

Reply via email to