From uckelman at nomic.net Thu Jul 5 12:21:32 2012 From: uckelman at nomic.net (Joel Uckelman) Date: Thu, 05 Jul 2012 03:21:32 -0700 Subject: [C++-sig] errors compiling Boost Python example Message-ID: <20120705102132.7B6D83618B5@charybdis.ellipsis.cx> I'm trying to compile the example from the Boost Python docs without success. hello.cpp: #include char const * const greet() { return "hello, world"; } BOOST_PYTHON_MODULE(hello_ext) { using namespace boost::python; def("greet", greet); } I have Boost 1.48, Python 2.7, and gcc 4.7.0. When I do this: g++ -fPIC -I/usr/include/python2.7 -c -o hello.o hello.cpp I get the following errors: In file included from /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:47:0, from /usr/include/boost/python/detail/invoke.hpp:63, from /usr/include/boost/python/detail/caller.hpp:16, from /usr/include/boost/python/object/function_handle.hpp:8, from /usr/include/boost/python/converter/arg_to_python.hpp:19, from /usr/include/boost/python/call.hpp:15, from /usr/include/boost/python/object_core.hpp:14, from /usr/include/boost/python/args.hpp:25, from /usr/include/boost/python.hpp:11, from hello.cpp:1: /usr/include/boost/python/detail/invoke.hpp: In instantiation of ???PyObject* boost::python::detail::invoke(boost::python::detail::invoke_tag_, const RC&, F&) [with RC = boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning; F = const char* const (*)(); PyObject = _object]???: /usr/include/boost/python/detail/caller.hpp:223:13: required from ???PyObject* boost::python::detail::caller_arity<0u>::impl::operator()(PyObject*, PyObject*) [with F = const char* const (*)(); Policies = boost::python::default_call_policies; Sig = boost::mpl::vector1; PyObject = _object]??? /usr/include/boost/python/object/py_function.hpp:38:33: required from ???PyObject* boost::python::objects::caller_py_function_impl::operator()(PyObject*, PyObject*) [with Caller = boost::python::detail::caller >; PyObject = _object]??? hello.cpp:10:1: required from here /usr/include/boost/python/detail/invoke.hpp:75:19: error: no match for call to ???(const boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning) (const char*)??? In file included from /usr/include/boost/python/object/function_handle.hpp:8:0, from /usr/include/boost/python/converter/arg_to_python.hpp:19, from /usr/include/boost/python/call.hpp:15, from /usr/include/boost/python/object_core.hpp:14, from /usr/include/boost/python/args.hpp:25, from /usr/include/boost/python.hpp:11, from hello.cpp:1: /usr/include/boost/python/detail/caller.hpp: In instantiation of ???static const PyTypeObject* boost::python::detail::converter_target_type::get_pytype() [with ResultConverter = boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning; PyTypeObject = _typeobject]???: /usr/include/boost/python/detail/caller.hpp:242:13: required from ???static boost::python::detail::py_func_sig_info boost::python::detail::caller_arity<0u>::impl::signature() [with F = const char* const (*)(); Policies = boost::python::default_call_policies; Sig = boost::mpl::vector1]??? /usr/include/boost/python/object/py_function.hpp:48:35: required from ???boost::python::detail::py_func_sig_info boost::python::objects::caller_py_function_impl::signature() const [with Caller = boost::python::detail::caller >]??? hello.cpp:10:1: required from here /usr/include/boost/python/detail/caller.hpp:102:109: error: ???struct boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning??? has no member named ???get_pytype??? In file included from /usr/include/boost/python/converter/pytype_function.hpp:10:0, from /usr/include/boost/python/to_python_indirect.hpp:16, from /usr/include/boost/python/converter/arg_to_python.hpp:10, from /usr/include/boost/python/call.hpp:15, from /usr/include/boost/python/object_core.hpp:14, from /usr/include/boost/python/args.hpp:25, from /usr/include/boost/python.hpp:11, from hello.cpp:1: /usr/include/boost/python/detail/unwind_type.hpp: In instantiation of ???typename Generator::result_type boost::python::detail::unwind_type(boost::type*, Generator*) [with Generator = boost::python::converter::detail::unwind_type_id_helper; U = const char* const; typename Generator::result_type = boost::python::type_info]???: /usr/include/boost/python/converter/pytype_function.hpp:45:74: required from ???boost::python::type_info boost::python::converter::detail::unwind_type_id_(boost::type*, mpl_::false_*) [with T = const char* const; mpl_::false_ = mpl_::bool_]??? /usr/include/boost/python/converter/pytype_function.hpp:68:13: required from ???static const PyTypeObject* boost::python::converter::expected_pytype_for_arg::get_pytype() [with T = const char* const; PyTypeObject = _typeobject]??? /usr/include/boost/python/detail/signature.hpp:98:13: required from ???static const boost::python::detail::signature_element* boost::python::detail::signature_arity<0u>::impl::elements() [with Sig = boost::mpl::vector1]??? /usr/include/boost/python/detail/caller.hpp:232:78: required from ???static boost::python::detail::py_func_sig_info boost::python::detail::caller_arity<0u>::impl::signature() [with F = const char* const (*)(); Policies = boost::python::default_call_policies; Sig = boost::mpl::vector1]??? /usr/include/boost/python/object/py_function.hpp:48:35: required from ???boost::python::detail::py_func_sig_info boost::python::objects::caller_py_function_impl::signature() const [with Caller = boost::python::detail::caller >]??? hello.cpp:10:1: required from here /usr/include/boost/python/detail/unwind_type.hpp:165:72: error: no matching function for call to ???boost::python::detail::unwind_helper2<1>::execute(const char* const (*)(), boost::python::converter::detail::unwind_type_id_helper*)??? /usr/include/boost/python/detail/unwind_type.hpp:165:72: note: candidate is: In file included from /usr/include/boost/python/converter/pytype_function.hpp:10:0, from /usr/include/boost/python/to_python_indirect.hpp:16, from /usr/include/boost/python/converter/arg_to_python.hpp:10, from /usr/include/boost/python/call.hpp:15, from /usr/include/boost/python/object_core.hpp:14, from /usr/include/boost/python/args.hpp:25, from /usr/include/boost/python.hpp:11, from hello.cpp:1: /usr/include/boost/python/detail/unwind_type.hpp:114:5: note: template static typename Generator::result_type boost::python::detail::unwind_helper2<1>::execute(U* (*)(), Generator*) /usr/include/boost/python/detail/unwind_type.hpp:114:5: note: template argument deduction/substitution failed: In file included from /usr/include/boost/python/converter/pytype_function.hpp:10:0, from /usr/include/boost/python/to_python_indirect.hpp:16, from /usr/include/boost/python/converter/arg_to_python.hpp:10, from /usr/include/boost/python/call.hpp:15, from /usr/include/boost/python/object_core.hpp:14, from /usr/include/boost/python/args.hpp:25, from /usr/include/boost/python.hpp:11, from hello.cpp:1: /usr/include/boost/python/detail/unwind_type.hpp:165:72: note: types ???U*??? and ???const char* const??? have incompatible cv-qualifiers It looks like the salient error is this one: /usr/include/boost/python/detail/invoke.hpp:75:19: error: no match for call to ???(const boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning) (const char*)??? but the Boost Python tutorial didn't mention the need to specify a return value policy for the "hello world" example. So, I suppose this is either a) a bug in Boost Python, b) a bug in the Boost Python tutorial I copied from, or c) a mistake I'm making Does anyone see which? -- J. From redetin at gmail.com Thu Jul 5 12:49:38 2012 From: redetin at gmail.com (Jani Tiainen) Date: Thu, 05 Jul 2012 13:49:38 +0300 Subject: [C++-sig] Instance ownership transfer in constructor. Message-ID: <4FF57142.6030507@gmail.com> Hi, I'm new to python.boost library and I'm trying to use it to wrap a third party library. Everything else I've managed to get working - thanks to excellent library and lot of examples I've found around a net. Only thing I can't get working properly is instance ownership transfer in constructor. So classes in library are defined like follows: class Owner { ... } class Data { Data(Owner *owner); // <-- Here happens ownership transfer. } Python code is like follows: owner = Owner() data_1 = Data(owner) data_2 = Data(owner) So when Python script stops runnning it causes crash due the fact that I've data objects are automatically destroyed by Owner-class but Python deletes them by using Data-class destructor (which shouldn't happen ever). -- Jani Tiainen - Well planned is half done and a half done has been sufficient before... From sybren at stuvel.eu Thu Jul 5 12:55:41 2012 From: sybren at stuvel.eu (=?UTF-8?Q?Sybren_A=2E_St=C3=BCvel?=) Date: Thu, 5 Jul 2012 12:55:41 +0200 Subject: [C++-sig] errors compiling Boost Python example In-Reply-To: <20120705102132.7B6D83618B5@charybdis.ellipsis.cx> References: <20120705102132.7B6D83618B5@charybdis.ellipsis.cx> Message-ID: Hi Joel, On 5 July 2012 12:21, Joel Uckelman wrote: > I'm trying to compile the example from the Boost Python docs without > success. [...] > There are many ways in which you can fix this. I think the easiest one from an I'm-just-starting-so-please-give-me-a-simple-hello-world-program point of view is to replace "char const *" with "std::string". That works on my machine (Python 3.2, VS2010, Boost 1.48). Best, -- Sybren A. St?vel http://stuvel.eu/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From uckelman at nomic.net Thu Jul 5 13:10:07 2012 From: uckelman at nomic.net (Joel Uckelman) Date: Thu, 05 Jul 2012 04:10:07 -0700 Subject: [C++-sig] errors compiling Boost Python example In-Reply-To: References: <20120705102132.7B6D83618B5@charybdis.ellipsis.cx> Message-ID: <20120705111007.9C0793618B6@charybdis.ellipsis.cx> Thus spake Sybren A. St??vel: > > Hi Joel, > > On 5 July 2012 12:21, Joel Uckelman wrote: > > > I'm trying to compile the example from the Boost Python docs without > > success. [...] > > > > There are many ways in which you can fix this. I think the easiest one from > an I'm-just-starting-so-please-give-me-a-simple-hello-world-program point > of view is to replace "char const *" with "std::string". That works on my > machine (Python 3.2, VS2010, Boost 1.48). Yes, I can compile if I switch to std::string as the return type. Thanks for that. Do you know why Boost Python complains about returning a char const*? It's a strange thing to have for the first example in the docs if it won't compile. -- J. From sybren at stuvel.eu Thu Jul 5 13:15:42 2012 From: sybren at stuvel.eu (=?UTF-8?Q?Sybren_A=2E_St=C3=BCvel?=) Date: Thu, 5 Jul 2012 13:15:42 +0200 Subject: [C++-sig] errors compiling Boost Python example In-Reply-To: <20120705111007.9C0793618B6@charybdis.ellipsis.cx> References: <20120705102132.7B6D83618B5@charybdis.ellipsis.cx> <20120705111007.9C0793618B6@charybdis.ellipsis.cx> Message-ID: On 5 July 2012 13:10, Joel Uckelman wrote: > Do you know why Boost Python complains about returning a char const*? > When returning a pointer, you have to tell Boost::Python what to do with it. The most important issue is one of ownership. Once the pointer has been returned as a Python object in the Python world, and that object goes out of scope, what should happen with the pointer? Is it owned by Python and should the pointed-to memory be deallocated too? Or was it still owned by the function that returned it? This is what you have to tell Boost::Python before it allows you to return pointers. And this is also why I looked for a solution that didn't involve pointers - much easier to understand as a first example. > It's a strange thing to have for the first example in the docs if it won't > compile. I agree. Personally I can't do anything about that, though. -- Sybren A. St?vel http://stuvel.eu/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at google.com Thu Jul 5 16:57:28 2012 From: rwgk at google.com (Ralf Grosse-Kunstleve) Date: Thu, 5 Jul 2012 07:57:28 -0700 Subject: [C++-sig] errors compiling Boost Python example In-Reply-To: <20120705102132.7B6D83618B5@charybdis.ellipsis.cx> References: <20120705102132.7B6D83618B5@charybdis.ellipsis.cx> Message-ID: It looks like you inserted an extra const (I don't see it in the current tutorial) ... char const * const greet() { It should work if you remove it. Ralf On Thu, Jul 5, 2012 at 3:21 AM, Joel Uckelman wrote: > I'm trying to compile the example from the Boost Python docs without > success. > > hello.cpp: > > #include > > char const * const greet() { > return "hello, world"; > } > > BOOST_PYTHON_MODULE(hello_ext) { > using namespace boost::python; > def("greet", greet); > } > > I have Boost 1.48, Python 2.7, and gcc 4.7.0. > > When I do this: > > g++ -fPIC -I/usr/include/python2.7 -c -o hello.o hello.cpp > > I get the following errors: > > In file included from > /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:47:0, > from /usr/include/boost/python/detail/invoke.hpp:63, > from /usr/include/boost/python/detail/caller.hpp:16, > from > /usr/include/boost/python/object/function_handle.hpp:8, > from > /usr/include/boost/python/converter/arg_to_python.hpp:19, > from /usr/include/boost/python/call.hpp:15, > from /usr/include/boost/python/object_core.hpp:14, > from /usr/include/boost/python/args.hpp:25, > from /usr/include/boost/python.hpp:11, > from hello.cpp:1: > /usr/include/boost/python/detail/invoke.hpp: In instantiation of > ?PyObject* > boost::python::detail::invoke(boost::python::detail::invoke_tag_ false>, const RC&, F&) [with RC = > boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning char* const>; F = const char* const (*)(); PyObject = _object]?: > /usr/include/boost/python/detail/caller.hpp:223:13: required from > ?PyObject* boost::python::detail::caller_arity<0u>::impl Sig>::operator()(PyObject*, PyObject*) [with F = const char* const (*)(); > Policies = boost::python::default_call_policies; Sig = > boost::mpl::vector1; PyObject = _object]? > /usr/include/boost/python/object/py_function.hpp:38:33: required from > ?PyObject* > boost::python::objects::caller_py_function_impl::operator()(PyObject*, > PyObject*) [with Caller = boost::python::detail::caller (*)(), boost::python::default_call_policies, boost::mpl::vector1 char* const> >; PyObject = _object]? > hello.cpp:10:1: required from here > /usr/include/boost/python/detail/invoke.hpp:75:19: error: no match for > call to ?(const > boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning char* const>) (const char*)? > In file included from > /usr/include/boost/python/object/function_handle.hpp:8:0, > from > /usr/include/boost/python/converter/arg_to_python.hpp:19, > from /usr/include/boost/python/call.hpp:15, > from /usr/include/boost/python/object_core.hpp:14, > from /usr/include/boost/python/args.hpp:25, > from /usr/include/boost/python.hpp:11, > from hello.cpp:1: > /usr/include/boost/python/detail/caller.hpp: In instantiation of ?static > const PyTypeObject* > boost::python::detail::converter_target_type::get_pytype() > [with ResultConverter = > boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning char* const>; PyTypeObject = _typeobject]?: > /usr/include/boost/python/detail/caller.hpp:242:13: required from > ?static boost::python::detail::py_func_sig_info > boost::python::detail::caller_arity<0u>::impl Sig>::signature() [with F = const char* const (*)(); Policies = > boost::python::default_call_policies; Sig = boost::mpl::vector1 const>]? > /usr/include/boost/python/object/py_function.hpp:48:35: required from > ?boost::python::detail::py_func_sig_info > boost::python::objects::caller_py_function_impl::signature() const > [with Caller = boost::python::detail::caller boost::python::default_call_policies, boost::mpl::vector1 const> >]? > hello.cpp:10:1: required from here > /usr/include/boost/python/detail/caller.hpp:102:109: error: ?struct > boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning char* const>? has no member named ?get_pytype? > In file included from > /usr/include/boost/python/converter/pytype_function.hpp:10:0, > from /usr/include/boost/python/to_python_indirect.hpp:16, > from > /usr/include/boost/python/converter/arg_to_python.hpp:10, > from /usr/include/boost/python/call.hpp:15, > from /usr/include/boost/python/object_core.hpp:14, > from /usr/include/boost/python/args.hpp:25, > from /usr/include/boost/python.hpp:11, > from hello.cpp:1: > /usr/include/boost/python/detail/unwind_type.hpp: In instantiation of > ?typename Generator::result_type > boost::python::detail::unwind_type(boost::type*, Generator*) [with > Generator = boost::python::converter::detail::unwind_type_id_helper; U = > const char* const; typename Generator::result_type = > boost::python::type_info]?: > /usr/include/boost/python/converter/pytype_function.hpp:45:74: required > from ?boost::python::type_info > boost::python::converter::detail::unwind_type_id_(boost::type*, > mpl_::false_*) [with T = const char* const; mpl_::false_ = > mpl_::bool_]? > /usr/include/boost/python/converter/pytype_function.hpp:68:13: required > from ?static const PyTypeObject* > boost::python::converter::expected_pytype_for_arg::get_pytype() [with T > = const char* const; PyTypeObject = _typeobject]? > /usr/include/boost/python/detail/signature.hpp:98:13: required from > ?static const boost::python::detail::signature_element* > boost::python::detail::signature_arity<0u>::impl::elements() [with Sig > = boost::mpl::vector1]? > /usr/include/boost/python/detail/caller.hpp:232:78: required from > ?static boost::python::detail::py_func_sig_info > boost::python::detail::caller_arity<0u>::impl Sig>::signature() [with F = const char* const (*)(); Policies = > boost::python::default_call_policies; Sig = boost::mpl::vector1 const>]? > /usr/include/boost/python/object/py_function.hpp:48:35: required from > ?boost::python::detail::py_func_sig_info > boost::python::objects::caller_py_function_impl::signature() const > [with Caller = boost::python::detail::caller boost::python::default_call_policies, boost::mpl::vector1 const> >]? > hello.cpp:10:1: required from here > /usr/include/boost/python/detail/unwind_type.hpp:165:72: error: no > matching function for call to > ?boost::python::detail::unwind_helper2<1>::execute(const char* const (*)(), > boost::python::converter::detail::unwind_type_id_helper*)? > /usr/include/boost/python/detail/unwind_type.hpp:165:72: note: candidate > is: > In file included from > /usr/include/boost/python/converter/pytype_function.hpp:10:0, > from /usr/include/boost/python/to_python_indirect.hpp:16, > from > /usr/include/boost/python/converter/arg_to_python.hpp:10, > from /usr/include/boost/python/call.hpp:15, > from /usr/include/boost/python/object_core.hpp:14, > from /usr/include/boost/python/args.hpp:25, > from /usr/include/boost/python.hpp:11, > from hello.cpp:1: > /usr/include/boost/python/detail/unwind_type.hpp:114:5: note: > template static typename Generator::result_type > boost::python::detail::unwind_helper2<1>::execute(U* (*)(), Generator*) > /usr/include/boost/python/detail/unwind_type.hpp:114:5: note: template > argument deduction/substitution failed: > In file included from > /usr/include/boost/python/converter/pytype_function.hpp:10:0, > from /usr/include/boost/python/to_python_indirect.hpp:16, > from > /usr/include/boost/python/converter/arg_to_python.hpp:10, > from /usr/include/boost/python/call.hpp:15, > from /usr/include/boost/python/object_core.hpp:14, > from /usr/include/boost/python/args.hpp:25, > from /usr/include/boost/python.hpp:11, > from hello.cpp:1: > /usr/include/boost/python/detail/unwind_type.hpp:165:72: note: types > ?U*? and ?const char* const? have incompatible cv-qualifiers > > > > It looks like the salient error is this one: > > /usr/include/boost/python/detail/invoke.hpp:75:19: error: no match for > call to ?(const > boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning char* const>) (const char*)? > > but the Boost Python tutorial didn't mention the need to specify a > return value policy for the "hello world" example. > > So, I suppose this is either > > a) a bug in Boost Python, > b) a bug in the Boost Python tutorial I copied from, or > c) a mistake I'm making > > Does anyone see which? > > -- > J. > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rwgk at google.com Thu Jul 5 16:59:55 2012 From: rwgk at google.com (Ralf Grosse-Kunstleve) Date: Thu, 5 Jul 2012 07:59:55 -0700 Subject: [C++-sig] errors compiling Boost Python example In-Reply-To: References: <20120705102132.7B6D83618B5@charybdis.ellipsis.cx> Message-ID: Oops, I meant to mark the extra const with a color: char const * *const* greet() { On Thu, Jul 5, 2012 at 7:57 AM, Ralf Grosse-Kunstleve wrote: > It looks like you inserted an extra const (I don't see it in the current > tutorial) ... > > char const * const greet() { > > It should work if you remove it. > > Ralf > > > On Thu, Jul 5, 2012 at 3:21 AM, Joel Uckelman wrote: > >> I'm trying to compile the example from the Boost Python docs without >> success. >> >> hello.cpp: >> >> #include >> >> char const * const greet() { >> return "hello, world"; >> } >> >> BOOST_PYTHON_MODULE(hello_ext) { >> using namespace boost::python; >> def("greet", greet); >> } >> >> I have Boost 1.48, Python 2.7, and gcc 4.7.0. >> >> When I do this: >> >> g++ -fPIC -I/usr/include/python2.7 -c -o hello.o hello.cpp >> >> I get the following errors: >> >> In file included from >> /usr/include/boost/preprocessor/iteration/detail/iter/forward1.hpp:47:0, >> from /usr/include/boost/python/detail/invoke.hpp:63, >> from /usr/include/boost/python/detail/caller.hpp:16, >> from >> /usr/include/boost/python/object/function_handle.hpp:8, >> from >> /usr/include/boost/python/converter/arg_to_python.hpp:19, >> from /usr/include/boost/python/call.hpp:15, >> from /usr/include/boost/python/object_core.hpp:14, >> from /usr/include/boost/python/args.hpp:25, >> from /usr/include/boost/python.hpp:11, >> from hello.cpp:1: >> /usr/include/boost/python/detail/invoke.hpp: In instantiation of >> ?PyObject* >> boost::python::detail::invoke(boost::python::detail::invoke_tag_> false>, const RC&, F&) [with RC = >> boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning> char* const>; F = const char* const (*)(); PyObject = _object]?: >> /usr/include/boost/python/detail/caller.hpp:223:13: required from >> ?PyObject* boost::python::detail::caller_arity<0u>::impl> Sig>::operator()(PyObject*, PyObject*) [with F = const char* const (*)(); >> Policies = boost::python::default_call_policies; Sig = >> boost::mpl::vector1; PyObject = _object]? >> /usr/include/boost/python/object/py_function.hpp:38:33: required from >> ?PyObject* >> boost::python::objects::caller_py_function_impl::operator()(PyObject*, >> PyObject*) [with Caller = boost::python::detail::caller> (*)(), boost::python::default_call_policies, boost::mpl::vector1> char* const> >; PyObject = _object]? >> hello.cpp:10:1: required from here >> /usr/include/boost/python/detail/invoke.hpp:75:19: error: no match for >> call to ?(const >> boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning> char* const>) (const char*)? >> In file included from >> /usr/include/boost/python/object/function_handle.hpp:8:0, >> from >> /usr/include/boost/python/converter/arg_to_python.hpp:19, >> from /usr/include/boost/python/call.hpp:15, >> from /usr/include/boost/python/object_core.hpp:14, >> from /usr/include/boost/python/args.hpp:25, >> from /usr/include/boost/python.hpp:11, >> from hello.cpp:1: >> /usr/include/boost/python/detail/caller.hpp: In instantiation of ?static >> const PyTypeObject* >> boost::python::detail::converter_target_type::get_pytype() >> [with ResultConverter = >> boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning> char* const>; PyTypeObject = _typeobject]?: >> /usr/include/boost/python/detail/caller.hpp:242:13: required from >> ?static boost::python::detail::py_func_sig_info >> boost::python::detail::caller_arity<0u>::impl> Sig>::signature() [with F = const char* const (*)(); Policies = >> boost::python::default_call_policies; Sig = boost::mpl::vector1> const>]? >> /usr/include/boost/python/object/py_function.hpp:48:35: required from >> ?boost::python::detail::py_func_sig_info >> boost::python::objects::caller_py_function_impl::signature() const >> [with Caller = boost::python::detail::caller> boost::python::default_call_policies, boost::mpl::vector1> const> >]? >> hello.cpp:10:1: required from here >> /usr/include/boost/python/detail/caller.hpp:102:109: error: ?struct >> boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning> char* const>? has no member named ?get_pytype? >> In file included from >> /usr/include/boost/python/converter/pytype_function.hpp:10:0, >> from /usr/include/boost/python/to_python_indirect.hpp:16, >> from >> /usr/include/boost/python/converter/arg_to_python.hpp:10, >> from /usr/include/boost/python/call.hpp:15, >> from /usr/include/boost/python/object_core.hpp:14, >> from /usr/include/boost/python/args.hpp:25, >> from /usr/include/boost/python.hpp:11, >> from hello.cpp:1: >> /usr/include/boost/python/detail/unwind_type.hpp: In instantiation of >> ?typename Generator::result_type >> boost::python::detail::unwind_type(boost::type*, Generator*) [with >> Generator = boost::python::converter::detail::unwind_type_id_helper; U = >> const char* const; typename Generator::result_type = >> boost::python::type_info]?: >> /usr/include/boost/python/converter/pytype_function.hpp:45:74: required >> from ?boost::python::type_info >> boost::python::converter::detail::unwind_type_id_(boost::type*, >> mpl_::false_*) [with T = const char* const; mpl_::false_ = >> mpl_::bool_]? >> /usr/include/boost/python/converter/pytype_function.hpp:68:13: required >> from ?static const PyTypeObject* >> boost::python::converter::expected_pytype_for_arg::get_pytype() [with T >> = const char* const; PyTypeObject = _typeobject]? >> /usr/include/boost/python/detail/signature.hpp:98:13: required from >> ?static const boost::python::detail::signature_element* >> boost::python::detail::signature_arity<0u>::impl::elements() [with Sig >> = boost::mpl::vector1]? >> /usr/include/boost/python/detail/caller.hpp:232:78: required from >> ?static boost::python::detail::py_func_sig_info >> boost::python::detail::caller_arity<0u>::impl> Sig>::signature() [with F = const char* const (*)(); Policies = >> boost::python::default_call_policies; Sig = boost::mpl::vector1> const>]? >> /usr/include/boost/python/object/py_function.hpp:48:35: required from >> ?boost::python::detail::py_func_sig_info >> boost::python::objects::caller_py_function_impl::signature() const >> [with Caller = boost::python::detail::caller> boost::python::default_call_policies, boost::mpl::vector1> const> >]? >> hello.cpp:10:1: required from here >> /usr/include/boost/python/detail/unwind_type.hpp:165:72: error: no >> matching function for call to >> ?boost::python::detail::unwind_helper2<1>::execute(const char* const (*)(), >> boost::python::converter::detail::unwind_type_id_helper*)? >> /usr/include/boost/python/detail/unwind_type.hpp:165:72: note: candidate >> is: >> In file included from >> /usr/include/boost/python/converter/pytype_function.hpp:10:0, >> from /usr/include/boost/python/to_python_indirect.hpp:16, >> from >> /usr/include/boost/python/converter/arg_to_python.hpp:10, >> from /usr/include/boost/python/call.hpp:15, >> from /usr/include/boost/python/object_core.hpp:14, >> from /usr/include/boost/python/args.hpp:25, >> from /usr/include/boost/python.hpp:11, >> from hello.cpp:1: >> /usr/include/boost/python/detail/unwind_type.hpp:114:5: note: >> template static typename Generator::result_type >> boost::python::detail::unwind_helper2<1>::execute(U* (*)(), Generator*) >> /usr/include/boost/python/detail/unwind_type.hpp:114:5: note: template >> argument deduction/substitution failed: >> In file included from >> /usr/include/boost/python/converter/pytype_function.hpp:10:0, >> from /usr/include/boost/python/to_python_indirect.hpp:16, >> from >> /usr/include/boost/python/converter/arg_to_python.hpp:10, >> from /usr/include/boost/python/call.hpp:15, >> from /usr/include/boost/python/object_core.hpp:14, >> from /usr/include/boost/python/args.hpp:25, >> from /usr/include/boost/python.hpp:11, >> from hello.cpp:1: >> /usr/include/boost/python/detail/unwind_type.hpp:165:72: note: types >> ?U*? and ?const char* const? have incompatible cv-qualifiers >> >> >> >> It looks like the salient error is this one: >> >> /usr/include/boost/python/detail/invoke.hpp:75:19: error: no match for >> call to ?(const >> boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning> char* const>) (const char*)? >> >> but the Boost Python tutorial didn't mention the need to specify a >> return value policy for the "hello world" example. >> >> So, I suppose this is either >> >> a) a bug in Boost Python, >> b) a bug in the Boost Python tutorial I copied from, or >> c) a mistake I'm making >> >> Does anyone see which? >> >> -- >> J. >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From uckelman at nomic.net Thu Jul 5 17:02:33 2012 From: uckelman at nomic.net (Joel Uckelman) Date: Thu, 05 Jul 2012 08:02:33 -0700 Subject: [C++-sig] errors compiling Boost Python example In-Reply-To: References: <20120705102132.7B6D83618B5@charybdis.ellipsis.cx> Message-ID: <20120705150234.294A23609BE@charybdis.ellipsis.cx> Thus spake Ralf Grosse-Kunstleve: > > It looks like you inserted an extra const (I don't see it in the current > tutorial) ... > > char const * const greet() { > > It should work if you remove it. Ha! You're correct. The example program was so short that I just retyped it, and I made the pointer const out of habit without noticing. Now all makes sense. Thanks! -- J. From j.reid at mail.cryst.bbk.ac.uk Thu Jul 5 18:00:19 2012 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Thu, 05 Jul 2012 17:00:19 +0100 Subject: [C++-sig] Instance ownership transfer in constructor. In-Reply-To: <4FF57142.6030507@gmail.com> References: <4FF57142.6030507@gmail.com> Message-ID: On 05/07/12 11:49, Jani Tiainen wrote: > Hi, > > I'm new to python.boost library and I'm trying to use it to wrap a third > party library. Everything else I've managed to get working - thanks to > excellent library and lot of examples I've found around a net. > > Only thing I can't get working properly is instance ownership transfer > in constructor. > > So classes in library are defined like follows: > > class Owner { > ... > } > > class Data { > Data(Owner *owner); // <-- Here happens ownership transfer. > } > > > Python code is like follows: > > owner = Owner() > data_1 = Data(owner) > data_2 = Data(owner) > > So when Python script stops runnning it causes crash due the fact that > I've data objects are automatically destroyed by Owner-class but Python > deletes them by using Data-class destructor (which shouldn't happen ever). > If I understand you correctly then you want the owner object to remain alive at least as long as data_1 and data_2? If so you could use with_custodian_and_ward: http://www.boost.org/doc/libs/1_49_0/libs/python/doc/v2/with_custodian_and_ward.html For example something like the following should work: namespace py = boost::python; py::class_< ... > my_class( "Data", "docstring.", py::init< Owner * >( "Constructor." )[ py::with_custodian_and_ward< 1, 2 >() ] ); From redetin at gmail.com Thu Jul 5 18:47:04 2012 From: redetin at gmail.com (Jani Tiainen) Date: Thu, 5 Jul 2012 19:47:04 +0300 Subject: [C++-sig] Instance ownership transfer in constructor. In-Reply-To: References: <4FF57142.6030507@gmail.com> Message-ID: I want to do it another way around: Instance of Owner should hold reference to data_1 and data_2 as long as owner is alive. Now following happens: owner = Owner() data_1 = Data(owner) # data_1 ownership is transferred to owner object data_2 = Data(owner) # data_2 ownership is transferred to owner object print owner.get_data_objects() , del data_1 del data_2 print owner.get_data_objects() # Crash because data_1 and data_2 are deleted even owner should still hold the reference. I tried to do it like http://www.boost.org/doc/libs/1_49_0/libs/python/test/injected.cpp but it didn't worked for me. On Thu, Jul 5, 2012 at 7:00 PM, John Reid wrote: > On 05/07/12 11:49, Jani Tiainen wrote: > > Hi, > > > > I'm new to python.boost library and I'm trying to use it to wrap a third > > party library. Everything else I've managed to get working - thanks to > > excellent library and lot of examples I've found around a net. > > > > Only thing I can't get working properly is instance ownership transfer > > in constructor. > > > > So classes in library are defined like follows: > > > > class Owner { > > ... > > } > > > > class Data { > > Data(Owner *owner); // <-- Here happens ownership transfer. > > } > > > > > > Python code is like follows: > > > > owner = Owner() > > data_1 = Data(owner) > > data_2 = Data(owner) > > > > So when Python script stops runnning it causes crash due the fact that > > I've data objects are automatically destroyed by Owner-class but Python > > deletes them by using Data-class destructor (which shouldn't happen > ever). > > > > If I understand you correctly then you want the owner object to remain > alive at least as long as data_1 and data_2? If so you could use > with_custodian_and_ward: > > http://www.boost.org/doc/libs/1_49_0/libs/python/doc/v2/with_custodian_and_ward.html > > For example something like the following should work: > > namespace py = boost::python; > py::class_< > ... > > my_class( > "Data", > "docstring.", > py::init< Owner * >( "Constructor." )[ > py::with_custodian_and_ward< 1, 2 >() > ] > ); > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Jani Tiainen - Well planned is half done, and a half done has been sufficient before... -------------- next part -------------- An HTML attachment was scrubbed... URL: From brandsmeier at gmx.de Thu Jul 5 19:44:54 2012 From: brandsmeier at gmx.de (Holger Brandsmeier) Date: Thu, 5 Jul 2012 19:44:54 +0200 Subject: [C++-sig] Instance ownership transfer in constructor. In-Reply-To: References: <4FF57142.6030507@gmail.com> Message-ID: Jani, ok what you want to do is quite a lot more intrusive, so you need some more involved methods, but it should be possible. I would do it by noting the following - data_1 is published to python as a boost::shared_ptr (default holder type) - usually it is difficult for a class member function, to obtain a shared_ptr<> to itself, i.e. something like `this` but not of type Data* but of boost::shared_ptr. - fortunately there is something supported by boost itself, called `enable_shared_from_this`, see http://stackoverflow.com/questions/142391/getting-a-boostshared-ptr-for-this - Now you want `owner` to hold on to this `shared_ptr` which ensures that `data_1` does not get deleted before `owner`, you can do this by owner->setData( shared_from_this() ) in any member function of `Data`. - Note that I _think_ that you are not allowed to use `shared_from_this()` in the constructor itself, so you might have to use boost::pythons `make_constructor` to make an ordinary member / non-member function behave as the constructor in python. Maybe someone has a quicker way of doing this, but remember that this is exactly the use case that `shared_ptr` are made for, Holger On Thu, Jul 5, 2012 at 6:47 PM, Jani Tiainen wrote: > I want to do it another way around: > > Instance of Owner should hold reference to data_1 and data_2 as long as > owner is alive. > > Now following happens: > owner = Owner() > data_1 = Data(owner) # data_1 ownership is transferred to owner object > data_2 = Data(owner) # data_2 ownership is transferred to owner object > > print owner.get_data_objects() > > , > > del data_1 > del data_2 > > print owner.get_data_objects() > # Crash because data_1 and data_2 are deleted even owner should still hold > the reference. > > I tried to do it like > http://www.boost.org/doc/libs/1_49_0/libs/python/test/injected.cpp but it > didn't worked for me. > > > On Thu, Jul 5, 2012 at 7:00 PM, John Reid > wrote: >> >> On 05/07/12 11:49, Jani Tiainen wrote: >> > Hi, >> > >> > I'm new to python.boost library and I'm trying to use it to wrap a third >> > party library. Everything else I've managed to get working - thanks to >> > excellent library and lot of examples I've found around a net. >> > >> > Only thing I can't get working properly is instance ownership transfer >> > in constructor. >> > >> > So classes in library are defined like follows: >> > >> > class Owner { >> > ... >> > } >> > >> > class Data { >> > Data(Owner *owner); // <-- Here happens ownership transfer. >> > } >> > >> > >> > Python code is like follows: >> > >> > owner = Owner() >> > data_1 = Data(owner) >> > data_2 = Data(owner) >> > >> > So when Python script stops runnning it causes crash due the fact that >> > I've data objects are automatically destroyed by Owner-class but Python >> > deletes them by using Data-class destructor (which shouldn't happen >> > ever). >> > >> >> If I understand you correctly then you want the owner object to remain >> alive at least as long as data_1 and data_2? If so you could use >> with_custodian_and_ward: >> >> http://www.boost.org/doc/libs/1_49_0/libs/python/doc/v2/with_custodian_and_ward.html >> >> For example something like the following should work: >> >> namespace py = boost::python; >> py::class_< >> ... >> > my_class( >> "Data", >> "docstring.", >> py::init< Owner * >( "Constructor." )[ >> py::with_custodian_and_ward< 1, 2 >() >> ] >> ); >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > > -- > Jani Tiainen > > - Well planned is half done, and a half done has been sufficient before... > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From redetin at gmail.com Fri Jul 6 08:20:54 2012 From: redetin at gmail.com (Jani Tiainen) Date: Fri, 06 Jul 2012 09:20:54 +0300 Subject: [C++-sig] Instance ownership transfer in constructor. In-Reply-To: References: <4FF57142.6030507@gmail.com> Message-ID: <4FF683C6.5080206@gmail.com> Hi, I'm still strugling with this whole thingy so I came up with more concrete example I'm trying to achieve: http://pastebin.com/dVRfT56x And in python code I do like this: owner = Owner() data = Data(owner) After script is finished I get warning message that Data destructor shouldn't be called directly. And then python crashes due memory corruption. I've tried to make usage of shared_ptr but no luck and I didn't understood how to apply shared_ptr_for_this. (NOTE: in my case all classes are from 3rd party library that I have no control over) 5.7.2012 20:44, Holger Brandsmeier kirjoitti: > Jani, > > ok what you want to do is quite a lot more intrusive, so you need some > more involved methods, but it should be possible. I would do it by > noting the following > - data_1 is published to python as a boost::shared_ptr (default > holder type) > - usually it is difficult for a class member function, to obtain a > shared_ptr<> to itself, i.e. something like `this` but not of type > Data* but of boost::shared_ptr. > - fortunately there is something supported by boost itself, called > `enable_shared_from_this`, see > http://stackoverflow.com/questions/142391/getting-a-boostshared-ptr-for-this > - Now you want `owner` to hold on to this `shared_ptr` which > ensures that `data_1` does not get deleted before `owner`, you can do > this by > owner->setData( shared_from_this() ) > in any member function of `Data`. > - Note that I _think_ that you are not allowed to use > `shared_from_this()` in the constructor itself, so you might have to > use boost::pythons `make_constructor` to make an ordinary member / > non-member function behave as the constructor in python. > > Maybe someone has a quicker way of doing this, but remember that this > is exactly the use case that `shared_ptr` are made for, > Holger > > > On Thu, Jul 5, 2012 at 6:47 PM, Jani Tiainen wrote: >> I want to do it another way around: >> >> Instance of Owner should hold reference to data_1 and data_2 as long as >> owner is alive. >> >> Now following happens: >> owner = Owner() >> data_1 = Data(owner) # data_1 ownership is transferred to owner object >> data_2 = Data(owner) # data_2 ownership is transferred to owner object >> >> print owner.get_data_objects() >> >> , >> >> del data_1 >> del data_2 >> >> print owner.get_data_objects() >> # Crash because data_1 and data_2 are deleted even owner should still hold >> the reference. >> >> I tried to do it like >> http://www.boost.org/doc/libs/1_49_0/libs/python/test/injected.cpp but it >> didn't worked for me. >> >> >> On Thu, Jul 5, 2012 at 7:00 PM, John Reid >> wrote: >>> >>> On 05/07/12 11:49, Jani Tiainen wrote: >>>> Hi, >>>> >>>> I'm new to python.boost library and I'm trying to use it to wrap a third >>>> party library. Everything else I've managed to get working - thanks to >>>> excellent library and lot of examples I've found around a net. >>>> >>>> Only thing I can't get working properly is instance ownership transfer >>>> in constructor. >>>> >>>> So classes in library are defined like follows: >>>> >>>> class Owner { >>>> ... >>>> } >>>> >>>> class Data { >>>> Data(Owner *owner); // <-- Here happens ownership transfer. >>>> } >>>> >>>> >>>> Python code is like follows: >>>> >>>> owner = Owner() >>>> data_1 = Data(owner) >>>> data_2 = Data(owner) >>>> >>>> So when Python script stops runnning it causes crash due the fact that >>>> I've data objects are automatically destroyed by Owner-class but Python >>>> deletes them by using Data-class destructor (which shouldn't happen >>>> ever). >>>> >>> >>> If I understand you correctly then you want the owner object to remain >>> alive at least as long as data_1 and data_2? If so you could use >>> with_custodian_and_ward: >>> >>> http://www.boost.org/doc/libs/1_49_0/libs/python/doc/v2/with_custodian_and_ward.html >>> >>> For example something like the following should work: >>> >>> namespace py = boost::python; >>> py::class_< >>> ... >>> > my_class( >>> "Data", >>> "docstring.", >>> py::init< Owner * >( "Constructor." )[ >>> py::with_custodian_and_ward< 1, 2 >() >>> ] >>> ); >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >> >> >> >> >> -- >> Jani Tiainen >> >> - Well planned is half done, and a half done has been sufficient before... >> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Jani Tiainen - Well planned is half done and a half done has been sufficient before... From brandsmeier at gmx.de Fri Jul 6 11:57:09 2012 From: brandsmeier at gmx.de (Holger Brandsmeier) Date: Fri, 6 Jul 2012 11:57:09 +0200 Subject: [C++-sig] Instance ownership transfer in constructor. In-Reply-To: <4FF683C6.5080206@gmail.com> References: <4FF57142.6030507@gmail.com> <4FF683C6.5080206@gmail.com> Message-ID: Jani, can you try what John Reid proposed but instead of py::with_custodian_and_ward< 1, 2 >() please try to use py::with_custodian_and_ward< 2, 1 >() or (more likely to work) py::with_custodian_and_ward_postcall< 2, 1 >() This should bind the lifetime of `self` to its first argument. I just never tried if this is a legal thing to do in the constructor. -Holger On Fri, Jul 6, 2012 at 8:20 AM, Jani Tiainen wrote: > Hi, > > I'm still strugling with this whole thingy so I came up with more concrete > example I'm trying to achieve: > > http://pastebin.com/dVRfT56x > > > And in python code I do like this: > > owner = Owner() > data = Data(owner) > > After script is finished I get warning message that Data destructor > shouldn't be called directly. And then python crashes due memory corruption. > > I've tried to make usage of shared_ptr but no luck and I didn't understood > how to apply shared_ptr_for_this. > > (NOTE: in my case all classes are from 3rd party library that I have no > control over) > > 5.7.2012 20:44, Holger Brandsmeier kirjoitti: > >> Jani, >> >> ok what you want to do is quite a lot more intrusive, so you need some >> more involved methods, but it should be possible. I would do it by >> noting the following >> - data_1 is published to python as a boost::shared_ptr (default >> holder type) >> - usually it is difficult for a class member function, to obtain a >> shared_ptr<> to itself, i.e. something like `this` but not of type >> Data* but of boost::shared_ptr. >> - fortunately there is something supported by boost itself, called >> `enable_shared_from_this`, see >> >> http://stackoverflow.com/questions/142391/getting-a-boostshared-ptr-for-this >> - Now you want `owner` to hold on to this `shared_ptr` which >> ensures that `data_1` does not get deleted before `owner`, you can do >> this by >> owner->setData( shared_from_this() ) >> in any member function of `Data`. >> - Note that I _think_ that you are not allowed to use >> `shared_from_this()` in the constructor itself, so you might have to >> use boost::pythons `make_constructor` to make an ordinary member / >> non-member function behave as the constructor in python. >> >> Maybe someone has a quicker way of doing this, but remember that this >> is exactly the use case that `shared_ptr` are made for, >> Holger >> >> >> On Thu, Jul 5, 2012 at 6:47 PM, Jani Tiainen wrote: >>> >>> I want to do it another way around: >>> >>> Instance of Owner should hold reference to data_1 and data_2 as long as >>> owner is alive. >>> >>> Now following happens: >>> owner = Owner() >>> data_1 = Data(owner) # data_1 ownership is transferred to owner object >>> data_2 = Data(owner) # data_2 ownership is transferred to owner object >>> >>> print owner.get_data_objects() >>> >>> , >>> >>> del data_1 >>> del data_2 >>> >>> print owner.get_data_objects() >>> # Crash because data_1 and data_2 are deleted even owner should still >>> hold >>> the reference. >>> >>> I tried to do it like >>> http://www.boost.org/doc/libs/1_49_0/libs/python/test/injected.cpp but >>> it >>> didn't worked for me. >>> >>> >>> On Thu, Jul 5, 2012 at 7:00 PM, John Reid >>> wrote: >>>> >>>> >>>> On 05/07/12 11:49, Jani Tiainen wrote: >>>>> >>>>> Hi, >>>>> >>>>> I'm new to python.boost library and I'm trying to use it to wrap a >>>>> third >>>>> party library. Everything else I've managed to get working - thanks to >>>>> excellent library and lot of examples I've found around a net. >>>>> >>>>> Only thing I can't get working properly is instance ownership transfer >>>>> in constructor. >>>>> >>>>> So classes in library are defined like follows: >>>>> >>>>> class Owner { >>>>> ... >>>>> } >>>>> >>>>> class Data { >>>>> Data(Owner *owner); // <-- Here happens ownership transfer. >>>>> } >>>>> >>>>> >>>>> Python code is like follows: >>>>> >>>>> owner = Owner() >>>>> data_1 = Data(owner) >>>>> data_2 = Data(owner) >>>>> >>>>> So when Python script stops runnning it causes crash due the fact that >>>>> I've data objects are automatically destroyed by Owner-class but Python >>>>> deletes them by using Data-class destructor (which shouldn't happen >>>>> ever). >>>>> >>>> >>>> If I understand you correctly then you want the owner object to remain >>>> alive at least as long as data_1 and data_2? If so you could use >>>> with_custodian_and_ward: >>>> >>>> >>>> http://www.boost.org/doc/libs/1_49_0/libs/python/doc/v2/with_custodian_and_ward.html >>>> >>>> For example something like the following should work: >>>> >>>> namespace py = boost::python; >>>> py::class_< >>>> ... >>>> > my_class( >>>> "Data", >>>> "docstring.", >>>> py::init< Owner * >( "Constructor." )[ >>>> py::with_custodian_and_ward< 1, 2 >() >>>> ] >>>> ); >>>> >>>> _______________________________________________ >>>> Cplusplus-sig mailing list >>>> Cplusplus-sig at python.org >>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >>> >>> >>> >>> >>> -- >>> Jani Tiainen >>> >>> - Well planned is half done, and a half done has been sufficient >>> before... >>> >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig >> > > > -- > Jani Tiainen > > - Well planned is half done and a half done has been sufficient before... > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig From redetin at gmail.com Fri Jul 6 12:16:06 2012 From: redetin at gmail.com (Jani Tiainen) Date: Fri, 06 Jul 2012 13:16:06 +0300 Subject: [C++-sig] Instance ownership transfer in constructor. In-Reply-To: References: <4FF57142.6030507@gmail.com> <4FF683C6.5080206@gmail.com> Message-ID: <4FF6BAE6.5090503@gmail.com> Ok, last suggestions were closest I could get: Now I see that data is deleted within owner destructor but still I get error messages that data objects are being deleted directly second time by Python. So now I need some way to say to python that "data" classes are not meant to be deleted by python ever. 6.7.2012 12:57, Holger Brandsmeier kirjoitti: > Jani, > > can you try what John Reid proposed but instead of > py::with_custodian_and_ward< 1, 2 >() > please try to use > py::with_custodian_and_ward< 2, 1 >() > or (more likely to work) > py::with_custodian_and_ward_postcall< 2, 1 >() > > This should bind the lifetime of `self` to its first argument. I just > never tried if this is a legal thing to do in the constructor. > > -Holger > > On Fri, Jul 6, 2012 at 8:20 AM, Jani Tiainen wrote: >> Hi, >> >> I'm still strugling with this whole thingy so I came up with more concrete >> example I'm trying to achieve: >> >> http://pastebin.com/dVRfT56x >> >> >> And in python code I do like this: >> >> owner = Owner() >> data = Data(owner) >> >> After script is finished I get warning message that Data destructor >> shouldn't be called directly. And then python crashes due memory corruption. >> >> I've tried to make usage of shared_ptr but no luck and I didn't understood >> how to apply shared_ptr_for_this. >> >> (NOTE: in my case all classes are from 3rd party library that I have no >> control over) >> >> 5.7.2012 20:44, Holger Brandsmeier kirjoitti: >> >>> Jani, >>> >>> ok what you want to do is quite a lot more intrusive, so you need some >>> more involved methods, but it should be possible. I would do it by >>> noting the following >>> - data_1 is published to python as a boost::shared_ptr (default >>> holder type) >>> - usually it is difficult for a class member function, to obtain a >>> shared_ptr<> to itself, i.e. something like `this` but not of type >>> Data* but of boost::shared_ptr. >>> - fortunately there is something supported by boost itself, called >>> `enable_shared_from_this`, see >>> >>> http://stackoverflow.com/questions/142391/getting-a-boostshared-ptr-for-this >>> - Now you want `owner` to hold on to this `shared_ptr` which >>> ensures that `data_1` does not get deleted before `owner`, you can do >>> this by >>> owner->setData( shared_from_this() ) >>> in any member function of `Data`. >>> - Note that I _think_ that you are not allowed to use >>> `shared_from_this()` in the constructor itself, so you might have to >>> use boost::pythons `make_constructor` to make an ordinary member / >>> non-member function behave as the constructor in python. >>> >>> Maybe someone has a quicker way of doing this, but remember that this >>> is exactly the use case that `shared_ptr` are made for, >>> Holger >>> >>> >>> On Thu, Jul 5, 2012 at 6:47 PM, Jani Tiainen wrote: >>>> >>>> I want to do it another way around: >>>> >>>> Instance of Owner should hold reference to data_1 and data_2 as long as >>>> owner is alive. >>>> >>>> Now following happens: >>>> owner = Owner() >>>> data_1 = Data(owner) # data_1 ownership is transferred to owner object >>>> data_2 = Data(owner) # data_2 ownership is transferred to owner object >>>> >>>> print owner.get_data_objects() >>>> >>>> , >>>> >>>> del data_1 >>>> del data_2 >>>> >>>> print owner.get_data_objects() >>>> # Crash because data_1 and data_2 are deleted even owner should still >>>> hold >>>> the reference. >>>> >>>> I tried to do it like >>>> http://www.boost.org/doc/libs/1_49_0/libs/python/test/injected.cpp but >>>> it >>>> didn't worked for me. >>>> >>>> >>>> On Thu, Jul 5, 2012 at 7:00 PM, John Reid >>>> wrote: >>>>> >>>>> >>>>> On 05/07/12 11:49, Jani Tiainen wrote: >>>>>> >>>>>> Hi, >>>>>> >>>>>> I'm new to python.boost library and I'm trying to use it to wrap a >>>>>> third >>>>>> party library. Everything else I've managed to get working - thanks to >>>>>> excellent library and lot of examples I've found around a net. >>>>>> >>>>>> Only thing I can't get working properly is instance ownership transfer >>>>>> in constructor. >>>>>> >>>>>> So classes in library are defined like follows: >>>>>> >>>>>> class Owner { >>>>>> ... >>>>>> } >>>>>> >>>>>> class Data { >>>>>> Data(Owner *owner); // <-- Here happens ownership transfer. >>>>>> } >>>>>> >>>>>> >>>>>> Python code is like follows: >>>>>> >>>>>> owner = Owner() >>>>>> data_1 = Data(owner) >>>>>> data_2 = Data(owner) >>>>>> >>>>>> So when Python script stops runnning it causes crash due the fact that >>>>>> I've data objects are automatically destroyed by Owner-class but Python >>>>>> deletes them by using Data-class destructor (which shouldn't happen >>>>>> ever). >>>>>> >>>>> >>>>> If I understand you correctly then you want the owner object to remain >>>>> alive at least as long as data_1 and data_2? If so you could use >>>>> with_custodian_and_ward: >>>>> >>>>> >>>>> http://www.boost.org/doc/libs/1_49_0/libs/python/doc/v2/with_custodian_and_ward.html >>>>> >>>>> For example something like the following should work: >>>>> >>>>> namespace py = boost::python; >>>>> py::class_< >>>>> ... >>>>> > my_class( >>>>> "Data", >>>>> "docstring.", >>>>> py::init< Owner * >( "Constructor." )[ >>>>> py::with_custodian_and_ward< 1, 2 >() >>>>> ] >>>>> ); >>>>> >>>>> _______________________________________________ >>>>> Cplusplus-sig mailing list >>>>> Cplusplus-sig at python.org >>>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>>> >>>> >>>> >>>> >>>> >>>> -- >>>> Jani Tiainen >>>> >>>> - Well planned is half done, and a half done has been sufficient >>>> before... >>>> >>>> >>>> _______________________________________________ >>>> Cplusplus-sig mailing list >>>> Cplusplus-sig at python.org >>>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >>> _______________________________________________ >>> Cplusplus-sig mailing list >>> Cplusplus-sig at python.org >>> http://mail.python.org/mailman/listinfo/cplusplus-sig >>> >> >> >> -- >> Jani Tiainen >> >> - Well planned is half done and a half done has been sufficient before... >> >> >> >> _______________________________________________ >> Cplusplus-sig mailing list >> Cplusplus-sig at python.org >> http://mail.python.org/mailman/listinfo/cplusplus-sig > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Jani Tiainen - Well planned is half done and a half done has been sufficient before... From herzog at mpi-cbg.de Wed Jul 18 11:36:33 2012 From: herzog at mpi-cbg.de (Ronny Herzog) Date: Wed, 18 Jul 2012 11:36:33 +0200 Subject: [C++-sig] boost python/example/quickstart does not work Message-ID: Dear all, I am experiencing a problem with the quickstart example from boost for Python. This is what happens: >>> c:\boost_1_50_0\libs\python\example\quickstart>bjam --toolset=msvc --verbose-test test ...patience... ...patience... ...found 1652 targets... ...updating 4 targets... msvc.link bin\test_embed.test\msvc-9.0\debug\threading-multi\test_embed.exe LINK : warning LNK4001: no object files specified; libraries used LINK : error LNK2001: unresolved external symbol _mainCRTStartup bin\test_embed.test\msvc-9.0\debug\threading-multi\test_embed.exe : fatal error LNK1120: 1 unresolved externals call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86 >nul link /NOLOGO /INCREMENTAL:NO /DEBUG /MACHINE:X86 /subsystem:console /out:"bin\te st_embed.test\msvc-9.0\debug\threading-multi\test_embed.exe" /LIBPATH:"c:\Python 26\libs" @"bin\test_embed.test\msvc-9.0\debug\threading-multi\test_embed.exe.rs p" if %ERRORLEVEL% NEQ 0 EXIT %ERRORLEVEL% ...failed msvc.link bin\test_embed.test\msvc-9.0\debug\threading-multi\test_embe d.exe bin\test_embed.test\msvc-9.0\debug\threading-multi\test_embed.pdb... ...removing bin\test_embed.test\msvc-9.0\debug\threading-multi\test_embed.pdb ...skipped test_embed.run f or lack of test_embed.exe.. . ...failed updating 2 targets... ...skipped 2 targets... <<< It somehow does not find the vcvarsall.bat although it is right in the place. I even started it before I run bjam. Any help is appriciated. Ronny From innosam at gmail.com Thu Jul 19 06:10:05 2012 From: innosam at gmail.com (Harkirat Singh) Date: Thu, 19 Jul 2012 09:40:05 +0530 Subject: [C++-sig] unable to build boost.python with gcc 3.3.5 and python2.4 : compilation error Message-ID: While compiling boost.python particularly, i get this error. Is there any workaround on this. * In file included from boost/unordered/detail/emplace_args.hpp:16, from boost/unordered/detail/allocator_helpers.hpp:18, from boost/unordered/unordered_set.hpp:17, from boost/unordered_set.hpp:16, from boost/graph/adjacency_list.hpp:21, from libs/python/src/object/inheritance.cpp:11: boost/move/move.hpp:124: warning: all member functions in class ` boost::move_detail::is_convertible' are private boost/move/move.hpp:254: warning: `class boost::rv' only defines a private destructor and has no friends In file included from boost/range/size.hpp:21, from boost/range/functions.hpp:20, from boost/range/iterator_range_core.hpp:26, from boost/range/iterator_range.hpp:13, from boost/range/irange.hpp:16, from boost/graph/detail/adjacency_list.hpp:20, from boost/graph/adjacency_list.hpp:337, from libs/python/src/object/inheritance.cpp:11: boost/range/size_type.hpp:41: warning: all member functions in class ` boost::detail::has_size_type' are private libs/python/src/object/inheritance.cpp:114: sorry, unimplemented: use of ` enumeral_type' in template type unification * Regards Harkirat Singh -------------- next part -------------- An HTML attachment was scrubbed... URL: From s_sourceforge at nedprod.com Thu Jul 19 12:51:51 2012 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Thu, 19 Jul 2012 11:51:51 +0100 Subject: [C++-sig] unable to build boost.python with gcc 3.3.5 and python2.4 : compilation error In-Reply-To: References: Message-ID: <5007E6C7.9175.9C40157@s_sourceforge.nedprod.com> Use a much older boost, one compatible with an ancient compiler like gcc 3.3.5. Or use a newer gcc. Niall On 19 Jul 2012 at 9:40, Harkirat Singh wrote: > While compiling boost.python particularly, i get this error. Is there any > workaround on this. > > > * > In file included from boost/unordered/detail/emplace_args.hpp:16, > > from boost/unordered/detail/allocator_helpers.hpp:18, from > boost/unordered/unordered_set.hpp:17, from boost/unordered_set.hpp:16, > from boost/graph/adjacency_list.hpp:21, from > libs/python/src/object/inheritance.cpp:11: > > boost/move/move.hpp:124: warning: all member functions in class ` > > boost::move_detail::is_convertible' are private > > boost/move/move.hpp:254: warning: `class boost::rv' only defines a > private > > destructor and has no friends > > In file included from boost/range/size.hpp:21, > > from boost/range/functions.hpp:20, from > boost/range/iterator_range_core.hpp:26, from > boost/range/iterator_range.hpp:13, from boost/range/irange.hpp:16, > from boost/graph/detail/adjacency_list.hpp:20, from > boost/graph/adjacency_list.hpp:337, from > libs/python/src/object/inheritance.cpp:11: > > boost/range/size_type.hpp:41: warning: all member functions in class ` > > boost::detail::has_size_type' are private > > libs/python/src/object/inheritance.cpp:114: sorry, unimplemented: use of ` > > enumeral_type' in template type unification > * > > > Regards > Harkirat Singh > -- Technology & Consulting Services - ned Productions Limited. http://www.nedproductions.biz/. VAT reg: IE 9708311Q. Work Portfolio: http://careers.stackoverflow.com/nialldouglas/ From innosam at gmail.com Thu Jul 19 13:17:00 2012 From: innosam at gmail.com (Harkirat Singh) Date: Thu, 19 Jul 2012 16:47:00 +0530 Subject: [C++-sig] unable to build boost.python with gcc 3.3.5 and python2.4 : compilation error In-Reply-To: <5007E6C7.9175.9C40157@s_sourceforge.nedprod.com> References: <5007E6C7.9175.9C40157@s_sourceforge.nedprod.com> Message-ID: Hi Niall gcc error is documented: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17327 it would be better if there is any work around for resolving the compilation error. Any help would be appreciated. Alternatively, i built the boost.python library using gcc 4.1.2, that compiles fine. But the shared object generated couldn't be imported in the target system. TARGET SYSTEM:- gcc 3.3.5 and python2.4 Error:- import pyplusplus ImportError: /usr/lib/libstdc++.so.6: version `CXXABI_1.3' not found (required by ./pyplusplus.so) Any solution on going in this direction. On Thu, Jul 19, 2012 at 4:21 PM, Niall Douglas wrote: > Use a much older boost, one compatible with an ancient compiler like > gcc 3.3.5. > > Or use a newer gcc. > > Niall > > On 19 Jul 2012 at 9:40, Harkirat Singh wrote: > > > While compiling boost.python particularly, i get this error. Is there any > > workaround on this. > > > > > > * > > In file included from boost/unordered/detail/emplace_args.hpp:16, > > > > from boost/unordered/detail/allocator_helpers.hpp:18, from > > boost/unordered/unordered_set.hpp:17, from boost/unordered_set.hpp:16, > > from boost/graph/adjacency_list.hpp:21, from > > libs/python/src/object/inheritance.cpp:11: > > > > boost/move/move.hpp:124: warning: all member functions in class ` > > > > boost::move_detail::is_convertible' are private > > > > boost/move/move.hpp:254: warning: `class boost::rv' only defines a > > private > > > > destructor and has no friends > > > > In file included from boost/range/size.hpp:21, > > > > from boost/range/functions.hpp:20, from > > boost/range/iterator_range_core.hpp:26, from > > boost/range/iterator_range.hpp:13, from boost/range/irange.hpp:16, > > from boost/graph/detail/adjacency_list.hpp:20, from > > boost/graph/adjacency_list.hpp:337, from > > libs/python/src/object/inheritance.cpp:11: > > > > boost/range/size_type.hpp:41: warning: all member functions in class ` > > > > boost::detail::has_size_type' are private > > > > libs/python/src/object/inheritance.cpp:114: sorry, unimplemented: use of > ` > > > > enumeral_type' in template type unification > > * > > > > > > Regards > > Harkirat Singh > > > > > -- > Technology & Consulting Services - ned Productions Limited. > http://www.nedproductions.biz/. VAT reg: IE 9708311Q. > Work Portfolio: http://careers.stackoverflow.com/nialldouglas/ > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > -- Harkirat Singh -------------- next part -------------- An HTML attachment was scrubbed... URL: From herzog at mpi-cbg.de Fri Jul 20 16:55:34 2012 From: herzog at mpi-cbg.de (Ronny Herzog) Date: Fri, 20 Jul 2012 16:55:34 +0200 Subject: [C++-sig] exporting a boost::python::dict containing a boost::python::list Message-ID: Dear all, I want to export a boost::python::dict containing a boost::python::list. However, when I print this list in Python, I get an unlimited output of some strange numbers: namespace bp = boost::python; class readraw { .... bp::list mk_pyPeak_list() { bp::list py_peak_list; for (int i = 0; i < peak_number; i++) { py_peak_list.append(bp::make_tuple(peak_list[0][i].mz, peak_list[0][i].intensity)); } return py_peak_list; } bp::dict peak_list_info() { bp::dict info; //bp::object pn = peak_number; //info["peakNumber"] = peak_number; //std::cout << bp::extract(mk_pyPeak_list().attr("__len__")(); bp::list l(mk_pyPeak_list()); info["peakList"] = l; return info; } }; BOOST_PYTHON_MODULE(readraw) { bp::class_("readraw", bp::init()) .def("add_peak", &readraw::add_peak) .def("peak_list_info", &readraw::peak_list_info) .def("average_scans", &readraw::average_scans) ; In Python: >>> print rawfilereader.peak_list_info() Results in smth. like: ... (-431602080.0, -6.2774385622041925e+66), (-431602080.0, -6.2774385622041925e+66 ), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, -6.2774385622041925e+ 66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, -6.2774385622041925 e+66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, -6.27743856220419 25e+66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, -6.277438562204 1925e+66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, -6.2774385622 041925e+66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, -6.27743856 ... What am I doing wrong? Thanks for the help, Ronny From rwgk at google.com Fri Jul 20 17:19:59 2012 From: rwgk at google.com (Ralf Grosse-Kunstleve) Date: Fri, 20 Jul 2012 08:19:59 -0700 Subject: [C++-sig] exporting a boost::python::dict containing a boost::python::list In-Reply-To: References: Message-ID: without having looked at your code ... most likely this is a memory issue. run with valgrind (valgrind.org or man valgrind) to pin-point the problem. On Fri, Jul 20, 2012 at 7:55 AM, Ronny Herzog wrote: > > Dear all, > > I want to export a boost::python::dict containing a boost::python::list. > However, when I print this list in Python, I get an unlimited output of > some strange numbers: > > namespace bp = boost::python; > > class readraw > { > .... > > bp::list mk_pyPeak_list() > { > bp::list py_peak_list; > for (int i = 0; i < peak_number; i++) > { > py_peak_list.append(bp::make_**tuple(peak_list[0][i].mz, > peak_list[0][i].intensity)); > } > return py_peak_list; > } > > bp::dict peak_list_info() > { > bp::dict info; > //bp::object pn = peak_number; > //info["peakNumber"] = peak_number; > //std::cout << bp::extract(mk_pyPeak_** > list().attr("__len__")(); > bp::list l(mk_pyPeak_list()); > info["peakList"] = l; > > return info; > } > }; > > BOOST_PYTHON_MODULE(readraw) > { > bp::class_("readraw", bp::init()) > .def("add_peak", &readraw::add_peak) > .def("peak_list_info", &readraw::peak_list_info) > .def("average_scans", &readraw::average_scans) > ; > > In Python: > >>> print rawfilereader.peak_list_info() > > Results in smth. like: > ... > (-431602080.0, -6.2774385622041925e+66), (-431602080.0, > -6.2774385622041925e+66 > ), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, > -6.2774385622041925e+ > 66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, > -6.2774385622041925 > e+66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, > -6.27743856220419 > 25e+66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, > -6.277438562204 > 1925e+66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, > -6.2774385622 > 041925e+66), (-431602080.0, -6.2774385622041925e+66), (-431602080.0, > -6.27743856 > ... > > What am I doing wrong? > > Thanks for the help, > Ronny > > ______________________________**_________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/**mailman/listinfo/cplusplus-sig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From herzog at mpi-cbg.de Sat Jul 21 11:25:30 2012 From: herzog at mpi-cbg.de (Ronny Herzog) Date: Sat, 21 Jul 2012 11:25:30 +0200 Subject: [C++-sig] exporting a boost::python::dict containing a boost::python::list In-Reply-To: References: Message-ID: Thanks for the answer, but I should add that I am using Windows 7 32Bit with Python 2.6. Ronny Am 7/20/2012 5:19 PM, schrieb Ralf Grosse-Kunstleve: > without having looked at your code ... > > most likely this is a memory issue. run with valgrind (valgrind.org > or man valgrind) to pin-point the problem. > > On Fri, Jul 20, 2012 at 7:55 AM, Ronny Herzog > wrote: > > > Dear all, > > I want to export a boost::python::dict containing a > boost::python::list. However, when I print this list in Python, I > get an unlimited output of some strange numbers: > > namespace bp = boost::python; > > class readraw > { > .... > > bp::list mk_pyPeak_list() > { > bp::list py_peak_list; > for (int i = 0; i < peak_number; i++) > { > > py_peak_list.append(bp::make___tuple(peak_list[0][i].mz, > peak_list[0][i].intensity)); > } > return py_peak_list; > } > > bp::dict peak_list_info() > { > bp::dict info; > //bp::object pn = peak_number; > //info["peakNumber"] = peak_number; > //std::cout << > bp::extract(mk_pyPeak___list().attr("__len__")(); > bp::list l(mk_pyPeak_list()); > info["peakList"] = l; > > return info; > } > }; > > BOOST_PYTHON_MODULE(readraw) > { > bp::class_("readraw", bp::init()) > .def("add_peak", &readraw::add_peak) > .def("peak_list_info", &readraw::peak_list_info) > .def("average_scans", &readraw::average_scans) > ; > > In Python: > >>> print rawfilereader.peak_list_info() > > Results in smth. like: > ... > (-431602080.0 , -6.2774385622041925e+66), > (-431602080.0 , -6.2774385622041925e+66 > ), (-431602080.0 , -6.2774385622041925e+66), > (-431602080.0 , -6.2774385622041925e+ > 66), (-431602080.0 , -6.2774385622041925e+66), > (-431602080.0 , -6.2774385622041925 > e+66), (-431602080.0 , > -6.2774385622041925e+66), (-431602080.0 , > -6.27743856220419 > 25e+66), (-431602080.0 , > -6.2774385622041925e+66), (-431602080.0 , > -6.277438562204 > 1925e+66), (-431602080.0 , > -6.2774385622041925e+66), (-431602080.0 , > -6.2774385622 > 041925e+66), (-431602080.0 , > -6.2774385622041925e+66), (-431602080.0 , > -6.27743856 > ... > > What am I doing wrong? > > Thanks for the help, > Ronny > > _________________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/__mailman/listinfo/cplusplus-sig > > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From herzog at mpi-cbg.de Sat Jul 21 11:36:38 2012 From: herzog at mpi-cbg.de (Ronny Herzog) Date: Sat, 21 Jul 2012 11:36:38 +0200 Subject: [C++-sig] exporting a boost::python::dict containing a boost::python::list In-Reply-To: References: Message-ID: Thanks again, you were 100% right. I could spot the problem. Ronny Am 7/20/2012 5:19 PM, schrieb Ralf Grosse-Kunstleve: > without having looked at your code ... > > most likely this is a memory issue. run with valgrind (valgrind.org > or man valgrind) to pin-point the problem. > > On Fri, Jul 20, 2012 at 7:55 AM, Ronny Herzog > wrote: > > > Dear all, > > I want to export a boost::python::dict containing a > boost::python::list. However, when I print this list in Python, I > get an unlimited output of some strange numbers: > > namespace bp = boost::python; > > class readraw > { > .... > > bp::list mk_pyPeak_list() > { > bp::list py_peak_list; > for (int i = 0; i < peak_number; i++) > { > > py_peak_list.append(bp::make___tuple(peak_list[0][i].mz, > peak_list[0][i].intensity)); > } > return py_peak_list; > } > > bp::dict peak_list_info() > { > bp::dict info; > //bp::object pn = peak_number; > //info["peakNumber"] = peak_number; > //std::cout << > bp::extract(mk_pyPeak___list().attr("__len__")(); > bp::list l(mk_pyPeak_list()); > info["peakList"] = l; > > return info; > } > }; > > BOOST_PYTHON_MODULE(readraw) > { > bp::class_("readraw", bp::init()) > .def("add_peak", &readraw::add_peak) > .def("peak_list_info", &readraw::peak_list_info) > .def("average_scans", &readraw::average_scans) > ; > > In Python: > >>> print rawfilereader.peak_list_info() > > Results in smth. like: > ... > (-431602080.0 , -6.2774385622041925e+66), > (-431602080.0 , -6.2774385622041925e+66 > ), (-431602080.0 , -6.2774385622041925e+66), > (-431602080.0 , -6.2774385622041925e+ > 66), (-431602080.0 , -6.2774385622041925e+66), > (-431602080.0 , -6.2774385622041925 > e+66), (-431602080.0 , > -6.2774385622041925e+66), (-431602080.0 , > -6.27743856220419 > 25e+66), (-431602080.0 , > -6.2774385622041925e+66), (-431602080.0 , > -6.277438562204 > 1925e+66), (-431602080.0 , > -6.2774385622041925e+66), (-431602080.0 , > -6.2774385622 > 041925e+66), (-431602080.0 , > -6.2774385622041925e+66), (-431602080.0 , > -6.27743856 > ... > > What am I doing wrong? > > Thanks for the help, > Ronny > > _________________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/__mailman/listinfo/cplusplus-sig > > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig > From s_sourceforge at nedprod.com Sat Jul 21 11:40:59 2012 From: s_sourceforge at nedprod.com (Niall Douglas) Date: Sat, 21 Jul 2012 10:40:59 +0100 Subject: [C++-sig] exporting a boost::python::dict containing a boost::python::list In-Reply-To: References: , , Message-ID: <500A792B.25177.2FC03E4@s_sourceforge.nedprod.com> On windows, the only near equivalent to valgrind is Intel's suite of very expensive tools. If your company already has a licence, they are very good. If not, fire up a copy of Linux on your nearest VM node and port a small example of the problem in your BPL app over to GCC. Niall On 21 Jul 2012 at 11:25, Ronny Herzog wrote: > Thanks for the answer, but I should add that I am using Windows 7 32Bit > with Python 2.6. > > Ronny > > Am 7/20/2012 5:19 PM, schrieb Ralf Grosse-Kunstleve: > > without having looked at your code ... > > > > most likely this is a memory issue. run with valgrind (valgrind.org > > or man valgrind) to pin-point the problem. > > > > On Fri, Jul 20, 2012 at 7:55 AM, Ronny Herzog > > wrote: > > > > > > Dear all, > > > > I want to export a boost::python::dict containing a > > boost::python::list. However, when I print this list in Python, I > > get an unlimited output of some strange numbers: > > > > namespace bp = boost::python; > > > > class readraw > > { > > .... > > > > bp::list mk_pyPeak_list() > > { > > bp::list py_peak_list; > > for (int i = 0; i < peak_number; i++) > > { > > > > py_peak_list.append(bp::make___tuple(peak_list[0][i].mz, > > peak_list[0][i].intensity)); > > } > > return py_peak_list; > > } > > > > bp::dict peak_list_info() > > { > > bp::dict info; > > //bp::object pn = peak_number; > > //info["peakNumber"] = peak_number; > > //std::cout << > > bp::extract(mk_pyPeak___list().attr("__len__")(); > > bp::list l(mk_pyPeak_list()); > > info["peakList"] = l; > > > > return info; > > } > > }; > > > > BOOST_PYTHON_MODULE(readraw) > > { > > bp::class_("readraw", bp::init()) > > .def("add_peak", &readraw::add_peak) > > .def("peak_list_info", &readraw::peak_list_info) > > .def("average_scans", &readraw::average_scans) > > ; > > > > In Python: > > >>> print rawfilereader.peak_list_info() > > > > Results in smth. like: > > ... > > (-431602080.0 , -6.2774385622041925e+66), > > (-431602080.0 , -6.2774385622041925e+66 > > ), (-431602080.0 , -6.2774385622041925e+66), > > (-431602080.0 , -6.2774385622041925e+ > > 66), (-431602080.0 , -6.2774385622041925e+66), > > (-431602080.0 , -6.2774385622041925 > > e+66), (-431602080.0 , > > -6.2774385622041925e+66), (-431602080.0 , > > -6.27743856220419 > > 25e+66), (-431602080.0 , > > -6.2774385622041925e+66), (-431602080.0 , > > -6.277438562204 > > 1925e+66), (-431602080.0 , > > -6.2774385622041925e+66), (-431602080.0 , > > -6.2774385622 > > 041925e+66), (-431602080.0 , > > -6.2774385622041925e+66), (-431602080.0 , > > -6.27743856 > > ... > > > > What am I doing wrong? > > > > Thanks for the help, > > Ronny > > > > _________________________________________________ > > Cplusplus-sig mailing list > > Cplusplus-sig at python.org > > http://mail.python.org/__mailman/listinfo/cplusplus-sig > > > > > > > > > > > > _______________________________________________ > > Cplusplus-sig mailing list > > Cplusplus-sig at python.org > > http://mail.python.org/mailman/listinfo/cplusplus-sig > > > > > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig at python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig -- Technology & Consulting Services - ned Productions Limited. http://www.nedproductions.biz/. VAT reg: IE 9708311Q. Work Portfolio: http://careers.stackoverflow.com/nialldouglas/ From wmamrak at gmail.com Sat Jul 21 17:41:45 2012 From: wmamrak at gmail.com (Wojciech Mamrak) Date: Sat, 21 Jul 2012 17:41:45 +0200 Subject: [C++-sig] Factory using embedded Python interpreter Message-ID: Hello list, I am trying to create C++ objects dynamically (some kind of factory) with use of embedded Python interpreter (i.e. eval). Naive implementation: namespace bp = boost::python; bp::object main_module = ...; bp::object main_namespace = ...; bp::object bpo_ob = bp::eval((type+"()").c_str(), main_namespace); Object* ob = bp::extract(pbo_ob); Simple eval returns bp::object, so after it goes out of scope PyDECREF is called and finally Python's garbage collector wipes Object out. Based on FAQ's entry: http://www.boost.org/doc/libs/1_50_0/libs/python/doc/v2/faq.html#ownership I set held_type to std::auto_ptr in Object definition: BOOST_PYTHON_MODULE(MyModule) { class_>("Object", init<>()); } but I am not sure how to take the ownership over objects created this way. I was thinking about: bp::object bpo_ob = bp::eval((type+"()").c_str(), main_namespace); std::auto_ptr ob = bp::extract>(bpo_ob); Object* o = ob.release(); but I am not sure about its correctness with respect to memory leaks. When run, the program does not crash. Thanks! From innosam at gmail.com Sun Jul 22 10:20:58 2012 From: innosam at gmail.com (Harkirat Singh) Date: Sun, 22 Jul 2012 13:50:58 +0530 Subject: [C++-sig] Boost Python support Python Version. Message-ID: Hi all I will be extending custom libraries to python. My target system uses python2.4.4. I have even tried swig, but it seems there isnt full support for python2.4. It uses some python c++ API not supported in python2.4.4. What is the status of boost python regarding this. Thanks Sam -------------- next part -------------- An HTML attachment was scrubbed... URL: From nat at lindenlab.com Mon Jul 23 15:06:41 2012 From: nat at lindenlab.com (Nat Goodspeed) Date: Mon, 23 Jul 2012 09:06:41 -0400 Subject: [C++-sig] Boost Python support Python Version. In-Reply-To: References: Message-ID: On Jul 22, 2012, at 4:20 AM, Harkirat Singh wrote: > My target system uses python2.4.4. > I have even tried swig, but it seems there isnt full support for python2.4. It uses some python c++ API not supported in > python2.4.4. My advice would be to update your Python version. Quite aside from the mere age of Python 2.4, many useful features have been added to the language since then - perhaps most notably in Python 2.5. But why not use 2.7? From j.reid at mail.cryst.bbk.ac.uk Wed Jul 25 10:03:56 2012 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 25 Jul 2012 09:03:56 +0100 Subject: [C++-sig] Indexing suite v2 multiple module problem Message-ID: Hi, I'm using a version of the indexing suite I believe I copied from Roman's codebase some time ago. I've recently refactored my project into multiple modules and now I'm have some runtime errors when iterating over sequences in python. At runtime I get the cryptic message: RuntimeError: get It is proving a little difficult to track down as it only happens on my server not on my development machine although it is reproducible every time. Not all std::vectors that are exposed trigger the error. If I change the order that my C++ modules are imported then the std::vector that triggers the error changes. I'm building a debug python on my server to try to investigate further but meanwhile I wonder if anyone had any suggestions or had seen this sort of thing before? Also where is the latest version of the indexing suite v2 code that I could use? Thanks, John. From roman.yakovenko at gmail.com Wed Jul 25 10:44:08 2012 From: roman.yakovenko at gmail.com (Roman Yakovenko) Date: Wed, 25 Jul 2012 11:44:08 +0300 Subject: [C++-sig] Indexing suite v2 multiple module problem In-Reply-To: References: Message-ID: On Wed, Jul 25, 2012 at 11:03 AM, John Reid wrote: > Hi, > > I'm using a version of the indexing suite I believe I copied from > Roman's codebase some time ago. I've recently refactored my project into > multiple modules and now I'm have some runtime errors when iterating > over sequences in python. At runtime I get the cryptic message: > > RuntimeError: get > > It is proving a little difficult to track down as it only happens on my > server not on my development machine although it is reproducible every > time. Not all std::vectors that are exposed trigger the error. If I > change the order that my C++ modules are imported then the std::vector > that triggers the error changes. > > I'm building a debug python on my server to try to investigate further > but meanwhile I wonder if anyone had any suggestions or had seen this > sort of thing before? > > Also where is the latest version of the indexing suite v2 code that I > could use? Do you use dlopen? import sys sys.setdlopenflags(RTLD_NOW | RTLD_GLOBAL) In multi-module environment you have to share boost python registry. I would start with this. You can google for "boost python dlopen" and find a lot of information about the subject. If I remember right, Py++ contains (generates) some code that queries the registry and registers the class conditionally. HTH, Roman From j.reid at mail.cryst.bbk.ac.uk Wed Jul 25 11:34:52 2012 From: j.reid at mail.cryst.bbk.ac.uk (John Reid) Date: Wed, 25 Jul 2012 10:34:52 +0100 Subject: [C++-sig] Indexing suite v2 multiple module problem In-Reply-To: References: Message-ID: On 25/07/12 09:44, Roman Yakovenko wrote: > Do you use dlopen? > > import sys > sys.setdlopenflags(RTLD_NOW | RTLD_GLOBAL) > > In multi-module environment you have to share boost python registry. (Sorry if this is a duplicate post, the last one seemed to disappear) Thanks, your advice fixed it: # # Need to set dlopen flags for multi-module boost.python environment # import sys, DLFCN sys.setdlopenflags(DLFCN.RTLD_NOW | DLFCN.RTLD_GLOBAL) From gr at componic.co.nz Tue Jul 31 11:14:34 2012 From: gr at componic.co.nz (Glenn Ramsey) Date: Tue, 31 Jul 2012 21:14:34 +1200 Subject: [C++-sig] How to create a custom exception derived from Exception Message-ID: <5017A1FA.8050502@componic.co.nz> Using boost::python how can I create an a custom exception that is derived from Python's Exception? The functionality I would like to get by doing this is to provide additional methods for the catching code to retrieve information from the exception. I know it is possible to just wrap and throw my own exception class but it seems that because it is not derived from Exception then in certain situations I get the error "SystemError: 'finally' pops bad exception". This example [1] shows how to wrap a C++ exception class... class MyCPPException : public std::exception {...} using namespace boost::python; ... PyObject *myCPPExceptionType=0; void translate(MyCPPException const &e) { PyErr_SetObject(myCPPExceptionType, object(e).ptr()); } BOOST_PYTHON_MODULE(MyModule) { ... class_ myCPPExceptionClass("MyCPPException"...); myCPPExceptionClass .def("get_extra_info", &MyCPPException::get_extra_info); myCPPExceptionType=myCPPExceptionClass.ptr(); register_exception_translator(&translate); ... } But this is not derived from Exception. This example [2] shows how to create an exception that is derived from Exception. PyObject* createExceptionClass(const char* name, PyObject* baseTypeObj = PyExc_Exception) { using std::string; namespace bp = boost::python; string scopeName = bp::extract(bp::scope().attr("__name__")); string qualifiedName0 = scopeName + "." + name; char* qualifiedName1 = const_cast(qualifiedName0.c_str()); PyObject* typeObj = PyErr_NewException(qualifiedName1, baseTypeObj, 0); if(!typeObj) bp::throw_error_already_set(); bp::scope().attr(name) = bp::handle<>(bp::borrowed(typeObj)); return typeObj; } PyObject* myExceptionTypeObj = 0; void translate(MyCPPException const &e) { PyErr_SetObject(myExceptionTypeObj, object(e).ptr()); } BOOST_PYTHON_MODULE(MyModule) { register_exception_translator(&translateFunc); ... myExceptionTypeObj = createExceptionClass("MyException"); ... } But this doesn't have any custom methods to get info from the exception. How can I do both at the same time? Glenn [2] [1] From gr at componic.co.nz Tue Jul 31 12:22:11 2012 From: gr at componic.co.nz (Glenn Ramsey) Date: Tue, 31 Jul 2012 22:22:11 +1200 Subject: [C++-sig] How to create a custom exception derived from Exception In-Reply-To: <5017A1FA.8050502@componic.co.nz> References: <5017A1FA.8050502@componic.co.nz> Message-ID: <5017B1D3.2080602@componic.co.nz> On 31/07/12 21:14, Glenn Ramsey wrote: > > Using boost::python how can I create an a custom exception that is derived from > Python's Exception? The functionality I would like to get by doing this is to > provide additional methods for the catching code to retrieve information from > the exception. > > I know it is possible to just wrap and throw my own exception class but it seems > that because it is not derived from Exception then in certain situations I get > the error "SystemError: 'finally' pops bad exception". > > This example [1] shows how to wrap a C++ exception class... > > class MyCPPException : public std::exception {...} > > using namespace boost::python; > ... > > PyObject *myCPPExceptionType=0; > > void translate(MyCPPException const &e) > { > PyErr_SetObject(myCPPExceptionType, object(e).ptr()); > } > > > BOOST_PYTHON_MODULE(MyModule) > { > ... > > class_ myCPPExceptionClass("MyCPPException"...); > myCPPExceptionClass > .def("get_extra_info", &MyCPPException::get_extra_info); > > myCPPExceptionType=myCPPExceptionClass.ptr(); > > register_exception_translator(&translate); > ... > } > > But this is not derived from Exception. > > This example [2] shows how to create an exception that is derived from Exception. > > PyObject* createExceptionClass(const char* name, PyObject* baseTypeObj = > PyExc_Exception) > { > using std::string; > namespace bp = boost::python; > > string scopeName = bp::extract(bp::scope().attr("__name__")); > string qualifiedName0 = scopeName + "." + name; > char* qualifiedName1 = const_cast(qualifiedName0.c_str()); > > PyObject* typeObj = PyErr_NewException(qualifiedName1, baseTypeObj, 0); > if(!typeObj) bp::throw_error_already_set(); > bp::scope().attr(name) = bp::handle<>(bp::borrowed(typeObj)); > return typeObj; > } > > PyObject* myExceptionTypeObj = 0; > > void translate(MyCPPException const &e) > { > PyErr_SetObject(myExceptionTypeObj, object(e).ptr()); > } > > > BOOST_PYTHON_MODULE(MyModule) > { > register_exception_translator(&translateFunc); > ... > myExceptionTypeObj = createExceptionClass("MyException"); > ... > } > > But this doesn't have any custom methods to get info from the exception. > > How can I do both at the same time? > > Glenn > > [2] > > > [1] > Forgot to mention a couple of things that I tried already... Passing a tuple of PyExc_Exception and my wrapped custom exception to PyErr_NewException, for multiple inheritance, caused an error when attempting to load the module in Python, something about incompatible types. Extracting __dict__ from my wrapped custom exception and passing it to PyErr_NewException also caused an error when attempting load the module. I don't have it in front of me now but it was complaining about wanting dict instead of dictproxy. Glenn From talljimbo at gmail.com Tue Jul 31 12:58:07 2012 From: talljimbo at gmail.com (Jim Bosch) Date: Tue, 31 Jul 2012 19:58:07 +0900 Subject: [C++-sig] How to create a custom exception derived from Exception In-Reply-To: <5017A1FA.8050502@componic.co.nz> References: <5017A1FA.8050502@componic.co.nz> Message-ID: <5017BA3F.6060403@gmail.com> On 07/31/2012 06:14 PM, Glenn Ramsey wrote: > > Using boost::python how can I create an a custom exception that is > derived from Python's Exception? The functionality I would like to get > by doing this is to provide additional methods for the catching code to > retrieve information from the exception. > The approach I've taken in the past (sorry, don't have an example right now) is to raise a true Python exception (from PyErr_NewException), and attach your Boost.Python-wrapped C++ exception to it as an instance variable. Then put a __getattr__ in the true Python exception that forwards to the Boost.Python object it holds. I can try to reconstruct more details if needed, but hopefully that's enough to get you started. Jim