Bug 292 - no way to perform a helper container deep copy
no way to perform a helper container deep copy
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: python bindings
pre-release
All All
: P3 normal
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-08-18 15:48 UTC by Mathieu Lacage
Modified: 2008-08-19 12:42 UTC (History)
1 user (show)

See Also:


Attachments
patch (2.87 KB, patch)
2008-08-19 10:50 UTC, Gustavo J. A. M. Carneiro
Details | Diff
patch v2 (1.83 KB, patch)
2008-08-19 12:26 UTC, Gustavo J. A. M. Carneiro
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mathieu Lacage 2008-08-18 15:48:45 UTC
Using our python bindings, I can't figure out how we can perform a deep copy of a helper container (a node or a device container for example)
Comment 1 Mathieu Lacage 2008-08-18 15:53:48 UTC
I should point out that I tried this:
import copy
mobileAdhocNodes.Create (adhocCount - 1)
adhocNodes = copy.copy (mobileAdhocNodes)
adhocNodes.Add (gateway)


and get a segfault:
#0  0x00002acd183e82d2 in std::vector<ns3::Ptr<ns3::Node>, std::allocator<ns3::Ptr<ns3::Node> > >::push_back (this=0x0, 
    __x=@0x7fff940bbd80) at /usr/include/c++/4.1.3/bits/stl_vector.h:604
#1  0x00002acd18622651 in ns3::NodeContainer::Add (this=0x0, node=@0x7fff940bbd80) at ../src/helper/node-container.cc:93
#2  0x00002acd17a2aae7 in _wrap_PyNs3NodeContainer_Add__1 (self=0xd1b3f0, args=0x881f10, kwargs=0x0, 
    return_exception=0x7fff940bbde8) at debug/bindings/python/ns3_module_helper.cc:1678
#3  0x00002acd17a2ad5d in _wrap_PyNs3NodeContainer_Add (self=0xd1b3f0, args=0x881f10, kwargs=0x0)
    at debug/bindings/python/ns3_module_helper.cc:1693
#4  0x0000000000488af7 in PyEval_EvalFrameEx ()
#5  0x0000000000488c3e in PyEval_EvalFrameEx ()
#6  0x0000000000489d60 in PyEval_EvalCodeEx ()
#7  0x0000000000489da2 in PyEval_EvalCode ()
#8  0x00000000004ab4fe in PyRun_FileExFlags ()
#9  0x00000000004ab790 in PyRun_SimpleFileExFlags ()
#10 0x0000000000414725 in Py_Main ()
#11 0x00002acd174c9b44 in __libc_start_main () from /lib/libc.so.6
#12 0x0000000000413c69 in _start ()
(gdb) 

Comment 2 Mathieu Lacage 2008-08-18 15:56:30 UTC
I ended up doing this:
    mobileAdhocNodes.Create (adhocCount - 1)
    adhocNodes = NodeContainer ()
    adhocNodes.Add (mobileAdhocNodes)
    adhocNodes.Add (gateway)
Comment 3 Gustavo J. A. M. Carneiro 2008-08-18 18:09:38 UTC
This is clearly an upstream pybindgen bug.  Can you please file generic pybindgen bugs where they belong?

-> https://bugs.launchpad.net/pybindgen/+bug/259215
Comment 4 Gustavo J. A. M. Carneiro 2008-08-19 10:48:20 UTC
I have a fix in pybindgen, but unfortunately ns-3 headers are too weird even for pybindgen:

debug/ns3/ptr.h: In destructor ‘ns3::Ptr<T>::~Ptr() [with T = ns3::DcaTxop]’:
debug/ns3/nqap-wifi-mac.h:54:   instantiated from here
debug/ns3/ptr.h:407: error: invalid use of incomplete type ‘struct ns3::DcaTxop’
debug/ns3/adhoc-wifi-mac.h:30: error: forward declaration of ‘struct ns3::DcaTxop’
debug/ns3/ptr.h: In destructor ‘ns3::Ptr<T>::~Ptr() [with T = ns3::MacLow]’:
debug/ns3/nqap-wifi-mac.h:54:   instantiated from here
debug/ns3/ptr.h:407: error: invalid use of incomplete type ‘struct ns3::MacLow’
debug/ns3/adhoc-wifi-mac.h:35: error: forward declaration of ‘struct ns3::MacLow’
debug/ns3/ptr.h: In member function ‘void ns3::Ptr<T>::Acquire() const [with T = ns3::DcaTxop]’:
debug/ns3/ptr.h:392:   instantiated from ‘ns3::Ptr<T>::Ptr(const ns3::Ptr<T>&) [with T = ns3::DcaTxop]’
debug/ns3/nqap-wifi-mac.h:54:   instantiated from here
debug/ns3/ptr.h:362: error: invalid use of incomplete type ‘struct ns3::DcaTxop’
debug/ns3/adhoc-wifi-mac.h:30: error: forward declaration of ‘struct ns3::DcaTxop’

The reason is that default copy constructors are reported by gccxml for these classes, and so pybindgen generates code to use them.  However, the incomplete types are killing the build.
Comment 5 Gustavo J. A. M. Carneiro 2008-08-19 10:50:15 UTC
Created attachment 230 [details]
patch

This patch makes the problematic copy constructors private, thereby preventing pybindgen from using them.  OK to commit?
Comment 6 Mathieu Lacage 2008-08-19 12:13:06 UTC
1) If the copy constructors are used, their implementation is not valid
2) If the copy constructors are not used, there is no need to provide an implementation. Just declare them private.

Finally, don't add a new private section to the class declaration: use the one at the bottom of the class and add the constructors at the end.
Comment 7 Gustavo J. A. M. Carneiro 2008-08-19 12:26:56 UTC
Created attachment 231 [details]
patch v2

How about now?
Comment 8 Mathieu Lacage 2008-08-19 12:30:34 UTC
looks good to me.
Comment 9 Gustavo J. A. M. Carneiro 2008-08-19 12:42:21 UTC
Committed patch.  Bug fixed.
Now we can copy objects in two different ways:
  1. newobj = Class(oldobj)
  2. newobj = copy.copy(oldobj)