[C++-sig] Re: Boost::Python for C code -> Segmentation fault

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Wed Jul 28 07:48:35 CEST 2004


--- sashan <sashang at ihug.co.nz> wrote:
> Mario Palomo wrote:
> > It doesn't work. I get the same segfault with the extern "C" and without 
> > the extern "C".
> > 
> > I'll try make_setter and make_getter rather than def_readwrite(). Then 
> > I'll try to run python inside gdb and get a backtrace (bt) of where the 
> > segfault is happening... Can someone reproduce my segfault?
> > 
> 
> For what its worth I can repro it.

There is no segfault under Red Hat 8 when using these commands:

g++ -fPIC -O0 -I/net/worm/scratch1/rwgk/dist/boost -I/usr/include/python2.2 -c
-o segfault.os segfault.cpp
g++ -shared -o segfault.so segfault.os -Llibtbx -lboost_python -lm

from segfault import *
u = user()
u.number = 1
print u.number
u.name = "abc"
print u.name

1
Traceback (most recent call last):
  File "zi", line 6, in ?
    print u.name
TypeError: No to_python (by-value) converter found for C++ type: char*

The TypeError is expected. I don't know why the assignment to u.name doesn't
throw an expection. Ideally the def_readwrite("name", ...) shouldn't even
compile.

Advice:
  - first try to build some simple examples that are known to work.
  - don't wrap assignments to raw pointers if there is nothing
    to manage the lifetime of the pointee. Boost.Python doesn't do
    this for you.

Ralf



		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 



More information about the Cplusplus-sig mailing list