On Wed, 20 Mar 2013 15:54:45 -0000, Jaedyn K. Draper <jaedyn.cpp...@jaedyn.co> wrote:Can you send the C++ code of MyObj? Kind of hard to diagnose a C++-side crash without any C++ code. Sure. Sorry, thought previous email was getting long and it might have been an obvious fix for someone... Just writing a smaller example for here now, so apologies if it doesn't compile or repreoduce the problem exactly... General info about the classes in this file: one's for parsing command line arguments (with argc and argv); the other for parsing environment variables from the "classical C environment pointer" envp. Both are seg-faulting, but for brevity, just writing out the Environment class.. -------------------------------- -- 3rd party library classes --- // in libraryenv.hpp namespace library { class Environment { public: Environment(void); /// Constructor with the envp parameter. Environment(const char* const* envp); /// Destructor. virtual ~CNcbiEnvironment(void); /// Reset environment. /// /// Delete all cached entries, load new ones from "envp" (if not NULL). void Reset(const char* const* envp = 0); /// Get environment value by name. /// /// If environmnent value is not cached then call "Load(name)" to load /// the environmnent value. The loaded name/value pair will then be /// cached, too, after the call to "Get()". const string& Get(const string& name) const; /// Set an environment variable by name /// /// This will throw an exception if setting the variable fails void Set(const string& name, const string& value); /// Delete an environment variable by name void Unset(const string& name); protected: /// Load value of specified environment variable. virtual string Load(const string& name) const; private: // .... } } // in libraryenv.cpp extern char **environ; Environment::Environment(void) { Reset(environ); } Environment::Environment(const char* const* envp) { Reset(envp); } /// ..... ----------------------- -- My wrapper class --- // in pyenv.hpp class PyEnv : public library::Environment { public: PyEnv(void); /// Construct from a list or a dict. PyEnv(const boost::python::list& envp); PyEnv(const boost::python::dict& envp); virtual ~PyEnv(void); void ResetPyList(const boost::python::list& envp); void ResetPyDict(const boost::python::dict& envp); std::list<std::string> Filter(const std::string& prefix); std::list<std::string> Enumerate(void); boost::python::object Iterate(void); /* Need to wrap member functions locking pthreads mutex */ const std::string& Get(const std::string& name) const; void Set(const std::string& name, const std::string& value); void Unset(const std::string& name); }; // in pyenv.cpp PyEnv::PyEnv(void) : Environment() { } PyEnv::PyEnv(const boost::python::list& envp) { MakeThreadSafe scope; ResetPyList(envp) } PyEnv::PyEnv(const boost::python::dict& envp) { MakeThreadSafe scope; ResetPyDict(dict) } // other member functions.. void RegisterEnv(void) { boost::python::class_<PyEnv, boost::noncopyable> ("Environment", boost::python::init<>() ) .def("boost::python::init<const boost::python::list&>() ) .def("boost::python::init<const boost::python::dict&>() ) .def("reset", &PyEnv::ResetList ) .def("reset", &PyEnv::ResetDict ) .def("__getitem__", &PyEnv::Get ) .def("__setitem__", &PyEnv::Set ) .def("__delitem__", &PyEnv::Unset ) .def("__iter__", &PyEnv::Iterate ) .def("enumerate", &PyEnv::Enumerate ) .def("filter", &PyEnv::Filter ) ; } --------------------------------------- Hope that helps. I'm guessing that the problem might be fixed if I inherit from boost::shared_ptr, but I have no idea why I would need to do that here and not elsewhere. Or perhaps I've done something wrong. I'm sure the iterator and enumerator methods will be broken - haven't got around to testing them yet - but I don't see why destroying the object would cause segfaults on these classes.. Any clues?? Cheers, Alex |
_______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig