Subject: [Boost-bugs] [Boost C++ Libraries] #1179: [boost.python] can not export a union in VC2005sp1
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2007-08-14 07:37:49
#1179: [boost.python] can not export a union in VC2005sp1
------------------------------------------+---------------------------------
Reporter: qiaozhiqiang_at_[hidden] | Owner: dave
Type: Bugs | Status: new
Milestone: To Be Determined | Component: Python
Version: release 1.34.0 | Severity: Problem
Keywords: python export union |
------------------------------------------+---------------------------------
// Visual V++ 2005(8.0) sp1, union not is_class.
// because there is BOOST_STATIC_ASSERT(is_class<T>::value) in
make_instance_impl
// can not export union. eg, class_<union my_u>
// can not return_internal_reference<> when not is_class, eg, return
char*, char&, union u&
// delete BOOST_STATIC_ASSERT(is_class<T>::value); of make_instance_impl,
then compile OK, and work not all OK
boost/python/object/make_instance.hpp
template <class T, class Holder, class Derived>
struct make_instance_impl
{
typedef objects::instance<Holder> instance_t;
template <class Arg>
static inline PyObject* execute(Arg& x)
{
// must is_class ?? BOOST_STATIC_ASSERT(is_class<T>::value
|| is_union<T>::value);
BOOST_STATIC_ASSERT(is_class<T>::value);
///////////////////////////////
#include <boost/python.hpp>
using namespace boost::python;
union my_u
{
int a;
char b;
char& get_ref()
{
return b;
}
char* get_ptr()
{
return *b;
}
}
struct my_s
{
my_u u;
my_u& get_ref()
{
return u;
}
my_u* get_ptr()
{
return &u;
}
};
void my_module()
{
//1. compile ERROR: my_u not is_class, my_u is_union, I modify one
line in make_instance.hpp
// BOOST_STATIC_ASSERT(is_class<T>::value) to
BOOST_STATIC_ASSERT(is_class<T>::value || is_union<T>::value)
// and work OK, why not export an union?
class_<my_u > u_class("my_u", init< >());
u_class.def_readwrite("a", &my_u::a);
u_class.def_readwrite("b", &my_u::b);
//2. compile ERROR: char not is_class, delete
BOOST_STATIC_ASSERT(is_class<T>::value), but run error
u_class.def("get_ref", &my_u::get_ref, return_internal_reference<
>());
//3. compile ERROR: char not is_class, delete
BOOST_STATIC_ASSERT(is_class<T>::value), but run error
u_class.def("get_ptr", &my_u::get_ptr, return_internal_reference<
>());
//4. compile OK, but run ERROR, I need it return a char
.def("get_value", &my_u::get_ptr,
return_value_policy<return_by_value>());
//5. compile ERROR, char* is not a reference, I need but have no
copy_non_const_pointer
u_class.def("get_copy", &my_u::get_ptr,
return_value_policy<copy_non_const_reference>());
class_<my_s > s_class("my_s", init< >());
//6. compile OK, buy run ERROR:
// s = my_s()
// s.u.a = 100
// print s.u.a
// but output s.u.a != 100 !!!
// s.u.a = 100 is s.get_u().set_a(100) and get_u() not return
u(is_union) by ref ?
s_class.def_readwrite("u", &my_s::u);
// 7. compile ERROR: my_u not is_class, is_union, modify
BOOST_STATIC_ASSERT(is_class<T>::value) to
// BOOST_STATIC_ASSERT(is_class<T>::value || is_union<T>::value)
s_class.def("get_ptr", &my_s::get_ptr,
return_internal_reference<>());
s_class.def("get_ref", &my_s::get_ref,
return_value_policy<return_by_value>());//compile ok
}
--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1179>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:56 UTC