[C++-sig] boost.python crush

Max Khesin MKhesin at liquidnet.com
Fri Jun 25 15:54:19 CEST 2004


I have the following sample class exposed via boost.python:

class String
{
public:
    String(const std::string& v):m_val(v){}
    bool lessThan(const std::string& other)                  const{return
this->m_val<other;}
    bool greaterThan(const std::string& other)               const{return
this->m_val>other;}
    bool equals(const std::string& other)                    const{return
this->m_val==other;}
    bool regexMatch(const std::string& other)                const{return
this->m_val==other;}
    bool withinDistance(const std::string& other, int dist)  const{return
distance(this->m_val, other)<=dist;}       
private:
    std::string m_val;
};


BOOST_PYTHON_MODULE(test)
{
    class_<String>("String", init<const std::string&>())
        .def("lessThan",        &String::lessThan)
        .def("greaterThan",     &String::greaterThan)
        .def("equals",          &String::equals)
        .def("regexMatch",      &String::regexMatch)
        .def("withinDistance",  &String::withinDistance)
        ;
}

I am calling this from python:

>> import test
>> s = test.String('hallo')
>> s.lessThen('hello')   #### <<< CRUSH

the debugger seems to point to an access violation in std::string dtor. I
palyed around with making the argument a plain std::string (instead of const
std::string&) and const char* - both of those crush, albeit in a different
place (also dtors, from the looks of it)

Any idea?

thanks,

max
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail.




More information about the Cplusplus-sig mailing list