[C++-sig] bpl_utils update

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Fri Jul 26 00:16:44 CEST 2002


--- David Abrahams <dave at boost-consulting.com> wrote:
> > Idea for a pragmatic approach:
> >
> > We add static constant to the *_registration_adaptor's; e.g.
> >
> > BOOST_STATIC_CONSTANT(bool, check_convertibility_per_element = true);
> >
> > Then in convertible():
> >
> > if (ContainerAdaptor::check_convertibility_per_element == true) {
> >   if (PyObject_Length(obj) < 0) return 0;
> >   // we traverse the sequence and return 0 if any element is not
> convertible
> >   return obj;
> > }
> > if (PyObject_Length(obj) >= 0) return obj;
> > PyErr_Clear();
> > if (handle<>(allow_null(PyObject_GetIter(obj))).get()) return obj;
> > PyErr_Clear();
> > return 0;
> >
> > In construct() we do it the other way round:
> > 1. try PyObject_GetIter() first and use PyIter_Next() on success.
> > 2. if that fails fall back to PySequence_Fast()
> 
> I need to look at your stuff in more detail before I can evaluate these
> ideas.

I have just checked in a new version of bpl_utils.h with the code above pasted
in. This time I've tested with gcc 3.0.4 and cxx 6.5. The accompanying tests
work fine without modification. I've even tested for memory leaks.

Comment 1: I had to use a static function check_convertibility_per_element()
instead of a static bool to avoid warnings about unreachable statements.

Comment 2: In the final version we might want to use

template <bool CheckConvertibilityPerElement>
struct xxx_registration_adaptor { ... };

Comment 3:

This compiles:

          handle<> py_elem_hdl(allow_null(PyIter_Next(obj_iter.get())));
          ...
          extract<container_element_type> elem_proxy(py_elem_obj);
          ContainerAdaptor::set_value(result, i, elem_proxy());
          

But cxx 6.5 was upset about this:

          extract<container_element_type> elem_proxy(object(py_elem_hdl));

The error was that there are not enough function arguments for:
    elem_proxy()
in the following statement.

New code:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cctbx/cctbx/include/cctbx/bpl_utils.h?rev=1.2.2.16&only_with_tag=boost_python_v2_transition&content-type=text/vnd.viewcvs-markup

Ralf


__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com




More information about the Cplusplus-sig mailing list