a bug when developing extension module with boost.python

Chen Bin chb_sh at yahoo.com.cn
Thu Jul 1 21:49:16 EDT 2004


1. We need a trace class CLog like:
...
CLog()<<"err msg"<<"anything you like"<<endl;
...

2. A programmer's design:
CLog:public ostringstream{
    ~CLog() 
     { 
       cout<<str().c_str()<<endl;
     }
}


It crashes when python use this module. The key point is that in
CLog's destructor str().c_str() is kind of rubbish data.

3. Another programmer's design:
CLog:public ostringstream{
    template<typename T>
    ostream& operator<<(T &userdefined)
    {
       return _temp<<userdefined<<endl;
     }

    ~CLog() 
     { 
       cout<<str().c_str()<<endl;
     }

private:
     ostringstream _temp;
}

This version works well.

3. My quesition
how could solution in .2 fail?

I have googled and got nothing helpful

BTW:
My development environment is

Win2000Pro
VC6 SP5
VC7.1
Python2.3(windows)



More information about the Python-list mailing list