On Sat, 2010-01-23 at 15:59 +0000, sergun wrote: > I have a problem with storing reference to Python object inside C++. > > The following Boost.Python wrapping class: > > > > #include <boost/python.hpp> > > using namespace boost; > using namespace boost::python; > > namespace cmodule > { > > object y; > > void setY(object y1) { y = y1; } > > } > > using namespace cmodule; > > BOOST_PYTHON_MODULE(cmodule) > { > def("setY",setY); > } > > > > > Crashes with “Segmentation fault” on so simple python fragment. >
This might be a static initialization problem: you declare "y", but it's not clear from your code fragment whether it gets initialized. I would have expected that to result in a linker error, but the way Python does its dynamic loading might have suppressed that. It's probably a good idea to avoid global variables in source files anyhow. Wrapping it in a function: object & getY() { static object y; return y; } void setY(object y1) { getY() = y1; } might eliminate your segfault. Jim Bosch _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig