Re: [pygccxml-development] Parameter passing, ownership semantics
Brought to you by:
mbaas,
roman_yakovenko
|
From: Roman Y. <rom...@gm...> - 2007-02-22 12:22:46
|
On 2/22/07, Gustavo Carneiro <gjc...@gm...> wrote:
> That wiki entry didn't apply anymore probably due to changing
> boost::python interfaces, but it provided very useful clues. I managed to
> get it working 100% correctly using another hack. Here's the diff of the
> manual changes I made to the wrapper:
>
> --- ns3.cpp 2007-02-21 23:46:44.000000000 +0000
> +++ ns3-working.cpp 2007-02-21 23:44:34.000000000 +0000
> @@ -9,19 +9,32 @@
> namespace bp = boost::python;
>
> struct EventImpl_wrapper : ns3::EventImpl, bp::wrapper< ns3::EventImpl > {
> + ~EventImpl_wrapper() {
> + if (this->pyobj) {
> + Py_DECREF(this->pyobj);
> + this->pyobj = 0;
> + }
> +
> + }
>
> EventImpl_wrapper()
> : ns3::EventImpl()
> - , bp::wrapper< ns3::EventImpl >(){
> - // null constructor
> + , bp::wrapper< ns3::EventImpl > (), pyobj(0) {
>
> }
>
> virtual void Notify( ){
> + if (!this->pyobj) {
> + this->pyobj =
> bp::detail::wrapper_base_::get_owner(*this);
> + Py_INCREF(this->pyobj);
> + }
> bp::override func_Notify = this->get_override( "Notify" );
> func_Notify( );
> }
>
> +protected:
> + PyObject *pyobj;
> +
> };
>
> static void Schedule_b8544467c482930a621aca2e7ac87dca(
> std::auto_ptr< ::ns3::EventImpl > event ){
>
Hi Gustavo. I tested the code you post and it doesn't work for me :-(.
I also doesn't understand how it works for you. You should increment reference
on the object before you pass it "Schedule" member function, otherwise
you get same "Segmentation fault". Am I missing something?
I can avoid it by commenting the destructor code.
Also I added new functionality, which allows you to implement the patch:
http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/transfer_ownership_tester.py?view=markup
http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/data/transfer_ownership_to_be_exported.hpp?view=markup
I attached the generated code.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|