[C++-sig] self_ns:: necessary when exposing stringification?

Andreas Kloeckner ak at ixion.net
Sat Feb 14 15:37:32 CET 2004


Hey everybody,

when writing a wrapper recently, I wanted to expose stringification by
writing

8<-----------------------------------------------------------------------------
using namespace boost::pyton;

BOOST_PYTHON_MODULE(...)
{
  class_<...>(...)
    .def(str(self));
}
8<-----------------------------------------------------------------------------

which resulted in the following error message:

8<-----------------------------------------------------------------------------
... instantiated from various points... (see below for complete error
message)
/home/ak/work/boost/boost/python/def_visitor.hpp:32: error: no matching
   function for call to `boost::python::api::object::visit(
   boost::python::class_<LLMatWrapper<double>,
   boost::python::bases<spmatrix::MatrixOperator<double>, boost::mpl::void_,
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>,
   boost::python::detail::not_specified, boost::python::detail::not_specified>&
   ) const'
8<-----------------------------------------------------------------------------

So, the compiler must have picked up the "str" function from the object
API, and then class_ tries to apply its visitor magic and fails
miserably.

This theory is confirmed by the fact that 

8<-----------------------------------------------------------------------------
  class_<...>(...)
    .def(self_ns::str(self));
8<-----------------------------------------------------------------------------

actually works. Same thing happens with the BPL test case "operators".
This strikes me as odd since the unit test sheet published on boost.org
says that this should work with 3.2.3. (which it doesn't, at least not
with Debian's)

Do you want me to try any other solutions besides adding self_ns? 
Is there a good reason for this behavior besides 
"gcc's function lookup is broken"?  What can I do to help you 
provide a general solution?

Andreas

-------------------------------------------------------------------------------
My version dump:
-------------------------------------------------------------------------------
Boost.Python 1.31.0, self-compiled with g++ below

g++ (GCC) 3.3.3 20040125 (prerelease) (Debian)
  (also occurs with Debian-released g++ 3.2.3)

Python 2.3.3 (#2, Jan 13 2004, 00:47:05)
[GCC 3.3.3 20040110 (prerelease) (Debian)] on linux2

-------------------------------------------------------------------------------
Complete error message
-------------------------------------------------------------------------------
/home/ak/work/boost/boost/python/def_visitor.hpp: In static member function `
   static void boost::python::def_visitor_access::visit(const V&, classT&)
   [with V = boost::python::def_visitor<boost::python::api::object>, classT =
   boost::python::class_<LLMatWrapper<double>,
   boost::python::bases<spmatrix::MatrixOperator<double>, boost::mpl::void_,
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>,
   boost::python::detail::not_specified, boost::python::detail::not_specified>]
   ':
/home/ak/work/boost/boost/python/def_visitor.hpp:68:   instantiated from `void boost::python::def_visitor<DerivedVisitor>::visit(classT&) const [with classT = boost::python::class_<LLMatWrapper<double>, boost::python::bases<spmatrix::MatrixOperator<double>, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, boost::python::detail::not_specified, boost::python::detail::not_specified>, DerivedVisitor = boost::python::api::object]'
/home/ak/work/boost/boost/python/class.hpp:294:   instantiated from `boost::python::class_<T, X1, X2, X3>& boost::python::class_<T, X1, X2, X3>::def(const boost::python::def_visitor<Derived>&) [with Derived = boost::python::api::object, T = LLMatWrapper<double>, X1 = boost::python::bases<spmatrix::MatrixOperator<double>, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>, X2 = boost::python::detail::not_specified, X3 = boost::python::detail::not_specified]'
py_matrices.cc:105:   instantiated from here
/home/ak/work/boost/boost/python/def_visitor.hpp:32: error: no matching
   function for call to `boost::python::api::object::visit(
   boost::python::class_<LLMatWrapper<double>,
   boost::python::bases<spmatrix::MatrixOperator<double>, boost::mpl::void_,
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_,
   boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, boost::mpl::void_>,
   boost::python::detail::not_specified, boost::python::detail::not_specified>&
   ) const'





More information about the Cplusplus-sig mailing list