[C++-sig] Re: register_ptr_to_python and get_pointer

Marc Kwiatkowski Marc.Kwiatkowski at veritas.com
Thu Dec 18 20:17:26 CET 2003


(sorry for the first one, mis-fired)

Thanks for your reply.  With respect to the documentation, I think the biggest simple thing we could do to improve things is to add a keyword and concept index, along the lines of the python library and language index.  Searching for get_pointer from boost.org's search form does not point to the refence documentation you included below, nor does the Reference TOC.  You kind of have to know it's there to find it.  Secondly, now that I've seen it it still isn't clear to me that it's a template the application developer is meant to extend.  They best thing for would be more comprehensive, real-world examples, particularly those emphasing integration the legacy code.  Given that they don't really exist, I'll just report problems I have and submit whatever sample code I can to this list with the hope that others can benefit from it.  Regarding the register_python_to_pointer sample, I will be happy to submit it.

 > Marc Kwiatkowski <Marc.Kwiatkowski at veritas.com> writes:
 > 
 > > I'm trying to integrate Boost::python templates to expose a bunch of
 > > legacy classes.  We have our own reference-counting pointer template,
 > > ref_ptr; the moral equivalent of shared_count.  Having gotten basic
 > > classes, I set out to figure out how to to expose ref_ptr.  Looking at
 > > the notes on this list and the PythonInfoWiki I figured out how to
 > > wrap my classes with shared_ptr using register_ptr_to_python.  I then
 > > attempted to switch from shared_ptr to our own ref_ptr and kept
 > > getting cryptic errors like the following:
 > >
 > >     boost\python\object\make_ptr_instance.hpp(31) : error C2784: 'T
 > > *boost::python::get_pointer(const boost::python::handle<T> &)' : could
 > > not deduce template argument for 'const boost::python::handle<T> &'
 > > from 'const ref_ptr<TRef>'
 > >
 > > I am not a C++ template god by any stretch of the imagination, but I
 > > was determined to try to make this work or at least understand why it
 > > wouldn't.  After dissecting pointee, pointer_holder, make_instance, et
 > > al.
 > 
 > The documentation you need is in the CVS at:
 > 
 >   http://tinyurl.com/ytef5
 > 
 > Unfortunately, register_ptr_to_python doesn't document the
 > Dereferenceable requirement :(
 > 
 > Will fix immediately.
 > 
 > > , I finally realized that my problem was that there was no
 > > get_pointer template function for class instances of my ref_ptr
 > > template.  All I needed to do was the following:
 > >
 > >   namespace boost { namespace python {
 > >
 > >   /* Need to provide get_pointer template function for
 > > SigFoundation::ref_ptr, so that boost holder templates
 > >       can use it to extract values. */
 > >  
 > >   template <class T> T* get_pointer(example::ref_ptr<T> const& p) {
 > >     return p.get();
 > >   }
 > >   }} // namespace boost::python
 > 
 > This is right if you're using a compiler with broken
 > Argument-Dependent Lookup such as msvc6 or 7.  VC7.1 supports ADL so
 > get_pointer should go in the "example" namespace.  I suggest using
 > #ifdefs to ensure that your code will still work when you move to a
 > working compiler.
 > 
 > > With this in place, I was able to get my version of the
 > > register_ptr_to_python sample working.  (It's included below in toto
 > > for your reference.)
 > >
 > > I guess the question I have ism why isn't this documented
 > > anywhere?  
 > 
 > Pure oversight, sorry.
 > 
 > > I have found boost::python to be the best library for getting at C++
 > > stuff from python, but the terseness of the documentation 
 > 
 > We'd love to have more time to spend on making the docs friendlier.
 > Patches are welcome.
 > 
 > > and lack of examples for integrating with legacy code 
 > 
 > I'm not sure what this means.  Are you referring to, for example, the
 > fact that register_ptr_to_python doesn't show how to work with random
 > smart pointers?  I can understand that, if so.  Do you have any other
 > examples?
 > 
 > > is frustrating.  Also, if this isn't the correct way to do this, I'd
 > > be glad to know what is.
 > >
 > >
 > > Here is the register_python_to_pointer sample modified for a
 > > thirdparty ref-counting-pointer template:
 > 
 > Wonderful!  Do you intend to contribute this to the documentation
 > base, and will you agree to have it distributed under the terms of
 > the Boost Software License 1.0
 > (http://www.boost-consulting.com/boost/LICENSE_1_0.txt)?
 > 
 > -- 
 > Dave Abrahams
 > Boost Consulting
 > www.boost-consulting.com
 > 
 > 
 > _______________________________________________
 > C++-sig mailing list
 > C++-sig at python.org
 > http://mail.python.org/mailman/listinfo/c++-sig

-- 
marc.kwiatkowski at veritas.com






More information about the Cplusplus-sig mailing list