List Info

Thread: Problems passing objects to function by const reference




Problems passing objects to function by const reference
user name
2007-10-16 10:00:58
In our uses of Boost.Python, we have run into a case where
very simple code
fails to compile. The case that we have is that a class type
has no public
destructor and instantiations of that type are passed by
const reference into
a function. The Boost.Python code for exposing the function
that accepts the
objects fail to compile because an attempt is made to call
the non-public
destructor.

The attached code demonstrates what we are trying to do. The
compile error
from GCC 4.1 when compiling against Boost 1.34.1 is as
follows:

destroy_test.h: In static member function 'static void
boost::python::detail::value_destroyer<false>::execute
(const volatile
T*) [with T = C]':
.../boost-1.34.1/include/boost-1_34_1/boost/python/detail/de
stroy.hpp:90:
  instantiated from 'void
boost::python::detail::destroy_referent_impl(void*, T&
(*)()) [with T
= const C]'
.../boost-1.34.1/include/boost-1_34_1/boost/python/detail/de
stroy.hpp:101:
  instantiated from 'void
boost::python::detail::destroy_referent(void*, T (*)())
[with T =
const C&]'
.../boost-1.34.1/include/boost-1_34_1/boost/python/converter
/rvalue_from_python_data.hpp:135:
  instantiated from
'boost::python::converter::rvalue_from_python_data<T>:
:~rvalue_from_python_data()
[with T = const C&]'
.../boost-1.34.1/include/boost-1_34_1/boost/python/converter
/arg_from_python.hpp:108:
  instantiated from 'PyObject*
boost::python::detail::caller_arity<1u>::impl<F,
Policies,
Sig>::operator()(PyObject*, PyObject*) [with F = void
(*)(const C&),
Policies = boost::python::default_call_policies, Sig =
boost::mpl::vector2<void, const C&>]'
.../boost-1.34.1/include/boost-1_34_1/boost/python/object/py
_function.hpp:38:
  instantiated from 'PyObject*
boost::python::objects::caller_py_function_impl<Caller>
;::operator()(PyObject*,
PyObject*) [with Caller =
boost::python::detail::caller<void (*)(const
C&), boost::python::default_call_policies,
boost::mpl::vector2<void,
const C&> >]'
generated.cpp:21:   instantiated from here
destroy_test.h:4: error: 'C::~C()' is protected
.../boost-1.34.1/include/boost-1_34_1/boost/python/detail/de
stroy.hpp:33:
error: within this context

I have tried to understand what Boost.Python is doing
internally, and it
seems like a copy of the object is being made that is later
cleaned up by
calling the destructor explicitly. I could definitely be
wrong about that
assessment, though. Ultimately, what I don't understand is
why anything needs
to be destroyed in this case.

 -Patirck


-- 
Patrick L. Hartling
http://www.137.org/patric
k/

_______________________________________________
C++-sig mailing list
C++-sigpython.org
http:
//mail.python.org/mailman/listinfo/c++-sig

  
  
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )