[C++-sig] Py++: Memory Ownership Passing

Gustavo Carneiro gjcarneiro at gmail.com
Thu Feb 22 11:50:56 CET 2007


On 2/22/07, Anand, Kumar <kanand at qualcomm.com> wrote:
>
>  Thanks! Registering the implicit converter worked. I am now able to
> transfer the ownership of Derived class object from python to C++ via an
> interface that takes a Base class pointer.
>

  Well, it doesn't work if you transfer ownership _and_  call a C++ method
wich then calls a virtual method on your object that is realized in Python.

  Here, check for yourself by compiling the module in attachment with:

g++ -shared -fPIC -DPIC -I /usr/include/python2.5/ -lboost_python ns3.cpp -o
ns3.so

  Then run the test program; you should get:
$ python test-schedule.py
Notify!
Segmentation fault (core dumped)

  The solution appears to be to INCREF the PyObject*.  I posted yesterday
one possible, albeit hackish, way to do it with boost 1.33.

-- 
Gustavo J. A. M. Carneiro
"The universe is always one step beyond logic."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070222/80dd2e6e/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ns3.cpp
Type: text/x-c++src
Size: 1703 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070222/80dd2e6e/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: simulator.hpp
Type: text/x-c++hdr
Size: 513 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070222/80dd2e6e/attachment.hpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test-schedule.py
Type: text/x-python
Size: 192 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070222/80dd2e6e/attachment.py>


More information about the Cplusplus-sig mailing list