[C++-sig] Re: The "return always existing pointer throws dangling error" problem
Niall Douglas
s_sourceforge at nedprod.com
Sun Oct 26 05:26:15 CET 2003
On 22 Oct 2003 at 19:05, Niall Douglas wrote:
> I'm thinking the best short-term stop-gap solution is an alternate
> call_method which basically disables the dangling pointer check. Then
> you can mark off functions in pyste which would fall foul of this
> particular problem on a case-by-case basis.
Just for reference for anyone searching the archives for a solution
to this problem, mine was to add the following to call_method.hpp:
template <
class R
BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)
>
typename detail::returnable<R>::type
call_method2(PyObject* self, char const* name
BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A,
const& a)
, boost::type<R>* = 0
)
{
PyObject* const result =
PyEval_CallMethod(
self
, const_cast<char*>(name)
, const_cast<char*>("(" BOOST_PP_REPEAT_1ST(N,
BOOST_PYTHON_FIXED, "O") ")")
BOOST_PP_REPEAT_1ST(N,
BOOST_PYTHON_FAST_ARG_TO_PYTHON_GET, nil)
);
object refincfix(handle<>(borrowed(result)));
converter::return_from_python<R> converter;
return converter(result);
}
Then you use call_method2<> instead of call_method when calling
virtual overridable methods in python.
Cheers,
Niall
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 208 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20031026/018996f7/attachment.pgp>
More information about the Cplusplus-sig
mailing list