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

sashan sashang at ihug.co.nz
Wed Jul 28 05:39:06 CEST 2004

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.

#include <stdio.h>

typedef struct user {
   char *name;
   int number;

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/class.hpp>
using namespace boost::python;

     .def_readwrite("name",   &user::name)
     .def_readwrite("number", &user::number)
To build:
g++ -g -c segfault.cpp -Wall -I/usr/include/python2.3
ld -shared -o segfault.so segfault.o -lboost_python

from segfault import *
u = user()
u.number = 1
Segmentation fault

I'm using the boost package that comes with Gentoo's portage system. 
I've never had any luck building python extensions with it. The only way 
i've been able to build extensions is by downloading the tarball, and 
setting up the boost stuff from there and using bjam to build the extension.

More information about the Cplusplus-sig mailing list