[C++-sig] Pyplusplus: Support for anonymous structs?

Hans Meine meine at informatik.uni-hamburg.de
Mon Jun 2 14:01:00 CEST 2008


Hi Roman,

after reporting to Gustavo that pybindgen does not support unnamed structs, I 
tried pyplusplus and found the same (OK, not the same - pyplusplus gracefully 
skips the members with the two warnings "Py++ can not export unnamed 
variables" and "Py++ can not export unnamed classes").  Actually, there are 
two problems:

1) py++ generates the following code, which does not mention the "low" 
and "high" members wrapped in the struct:

    bp::class_< Word >( "Word" )
        .def_readwrite( "word", &Word::word );

This should be "easy to fix" - py++ would need to descend into the struct and 
add 
        .def_readwrite( "low", &Word::low )
        .def_readwrite( "high", &Word::high )

However, the next problem is fatal:

2) boost::python::class_ only works for structs and classes, but not for 
unions.  I am getting an error from is_polymorphic:

/software/boost-1.34.1/include/boost-1_34/boost/type_traits/is_polymorphic.hpp: 
At global scope:
/software/boost-1.34.1/include/boost-1_34/boost/type_traits/is_polymorphic.hpp: 
In instantiation of 'boost::detail::is_polymorphic_imp1<Word>::d1':
/software/boost-1.34.1/include/boost-1_34/boost/type_traits/is_polymorphic.hpp:56:   
instantiated from 'const bool 
boost::detail::is_polymorphic_imp1<Word>::value'
/software/boost-1.34.1/include/boost-1_34/boost/type_traits/is_polymorphic.hpp:91:   
instantiated from 'const bool boost::detail::is_polymorphic_imp<Word>::value'
/software/boost-1.34.1/include/boost-1_34/boost/type_traits/is_polymorphic.hpp:96:   
instantiated from 'boost::is_polymorphic<Word>'
/software/boost-1.34.1/include/boost-1_34/boost/mpl/if.hpp:67:   instantiated 
from 'boost::mpl::if_<boost::is_polymorphic<Word>, 
boost::python::objects::polymorphic_id_generator<Word>, 
boost::python::objects::non_polymorphic_id_generator<Word> >'
/software/boost-1.34.1/include/boost-1_34/boost/python/object/inheritance.hpp:65:   
instantiated from 'boost::python::objects::dynamic_id_generator<Word>'
/software/boost-1.34.1/include/boost-1_34/boost/python/object/inheritance.hpp:72:   
instantiated from 'void boost::python::objects::register_dynamic_id(T*) [with 
T = Word]'
/software/boost-1.34.1/include/boost-1_34/boost/python/object/class_metadata.hpp:97:   
instantiated from 'void 
boost::python::objects::register_shared_ptr_from_python_and_casts(T*, Bases) 
[with T = Word, Bases = boost::python::bases<mpl_::void_, mpl_::void_, 
mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, 
mpl_::void_, mpl_::void_>]'
/software/boost-1.34.1/include/boost-1_34/boost/python/object/class_metadata.hpp:225:   
instantiated from 'static void boost::python::objects::class_metadata<T, X1, 
X2, X3>::register_aux2(T2*, Callback) [with T2 = Word, Callback = 
boost::integral_constant<bool, false>, T = Word, X1 = 
boost::python::detail::not_specified, X2 = 
boost::python::detail::not_specified, X3 = 
boost::python::detail::not_specified]'
/software/boost-1.34.1/include/boost-1_34/boost/python/object/class_metadata.hpp:219:   
instantiated from 'static void boost::python::objects::class_metadata<T, X1, 
X2, X3>::register_aux(void*) [with T = Word, X1 = 
boost::python::detail::not_specified, X2 = 
boost::python::detail::not_specified, X3 = 
boost::python::detail::not_specified]'
/software/boost-1.34.1/include/boost-1_34/boost/python/object/class_metadata.hpp:205:   
instantiated from 'static void boost::python::objects::class_metadata<T, X1, 
X2, X3>::register_() [with T = Word, X1 = 
boost::python::detail::not_specified, X2 = 
boost::python::detail::not_specified, X3 = 
boost::python::detail::not_specified]'
/software/boost-1.34.1/include/boost-1_34/boost/python/class.hpp:496:   
instantiated from 'void boost::python::class_<T, X1, X2, 
X3>::initialize(const DefVisitor&) [with DefVisitor = 
boost::python::init<mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, 
mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, 
mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_, mpl_::void_>, W = Word, 
X1 = boost::python::detail::not_specified, X2 = 
boost::python::detail::not_specified, X3 = 
boost::python::detail::not_specified]'
/software/boost-1.34.1/include/boost-1_34/boost/python/class.hpp:629:   
instantiated from 'boost::python::class_<T, X1, X2, X3>::class_(const char*, 
const char*) [with W = Word, X1 = boost::python::detail::not_specified, X2 = 
boost::python::detail::not_specified, X3 = 
boost::python::detail::not_specified]'
foomodule.cxx:26:   instantiated from here
/software/boost-1.34.1/include/boost-1_34/boost/type_traits/is_polymorphic.hpp:28: 
error: base type 'Word' fails to be a struct or class type

-- 
Ciao, /  /
     /--/
    /  / ANS



More information about the Cplusplus-sig mailing list