[C++-sig] boost::python constructing object from PyObject *

David Abrahams dave at boostpro.com
Wed Oct 29 23:11:04 CET 2008


on Wed Oct 29 2008, "Dan Eloff" <dan.eloff-AT-gmail.com> wrote:

> On Wed, Oct 29, 2008 at 3:55 PM, David Abrahams <dave at boostpro.com> wrote:
>> The above should be a complete guide.  Any questions?
>
> Just two.
>
> 1) Should it be object(handle<>(borrowed(ptr))) or
> object(borrowed(ptr)) ? Both seem to compile.

    * an object can only be constructed from a handle<>.  Other
      interfaces are not for public consumption and thus not
      documented.  Use at your own peril.

I.e., it should be the first.  

Actually, you should follow a logical extension of Peter Dimov's
guideline
(http://www.boost.org/doc/libs/1_36_0/libs/smart_ptr/shared_ptr.htm#BestPractices)
and give the handle<> object a name rather than making it a temporary.

> 2) Can I repost that to a boost::python wiki, givng you credit of
> course. Hopefully it will prevent others from having as many issues
> with this.

Sure thing.

> Thanks for taking the time to explain handle in depth. I fixed my code
> accordingly and all ref-counting issues went away.

Glad to help.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com


More information about the Cplusplus-sig mailing list