a bug when developing extension module with boost.python

Chen Bin chb_sh at yahoo.com.cn
Fri Jul 2 03:49:16 CEST 2004


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

2. A programmer's design&#65306;
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