Radoslaw Nawrot Posted February 20, 2015 Report Share Posted February 20, 2015 Hi All, I'm new at this forum. I encounter problem with circular_buffer. Let me explain it on simple example (code is from circular_buffer.h): I have a circular_buffer with few elements . After read one of them element is destroyed: template < typename T >Tcircular_buffer<T>::read(){ T t = read_data(); buf_clear( m_buf, m_ri ); increment_read_pos(); return t;} template < typename T > inline void circular_buffer<T>::buf_clear( void* buf, int n ) { (static_cast<T*>(buf) + n)->~T(); } } // namespace tlm ... but In dectructor all elements are destroyed ... again template < typename T >circular_buffer<T>::~circular_buffer(){ for( int i=0; i < used(); i++ ) { buf_clear( m_buf, i ); //!!!! } buf_free( m_buf );} This case GPF's randomly. I notice that when I change desctructor code to for( int i=m_ri; i < used() % m_size; i++ ) { problem disappears I'm using SystemC 2.3.0 Is this a bug in TLM sources or I'm doing something wrong ? Radek Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted February 20, 2015 Report Share Posted February 20, 2015 AFAICS, this is another symptom of a known issue and fixed in 2.3.1. You should upgrade. Quoting the RELEASENOTES: The implementation-defined tlm::circular_buffer class has been updated with the following changes now provides a "clear()" member function to drop the current contents, fix a segmentation fault due to freeing invalid memory in "resize()", which could happen in some cases, work around a parsing error on some EDG-based C++ frontends. Greetings from Duisburg, Philipp Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted February 20, 2015 Report Share Posted February 20, 2015 Oh, there seems to be still an issue in 2.3.1, you should change the circular_buffer::clear function to template < typename T > void circular_buffer<T>::clear() { for( int i=0; i < used(); i++ ) { // buf_clear( m_buf, i ); // << BUG HERE buf_clear( m_buf, (m_ri + i) % m_size ); // This should(tm) be correct } m_free = m_size; m_used = m_ri = m_wi = 0; } Thanks for reporting. I'll take this to the Language Working Group to make sure a fix will be included in the next release of the proof-of-concept simulator.(I would still recommend to upgrade to 2.3.1... )Greetings from Duisburg, Philipp maehne, Radoslaw Nawrot and karandeep963 3 Quote Link to comment Share on other sites More sharing options...
Radoslaw Nawrot Posted February 23, 2015 Author Report Share Posted February 23, 2015 Philipp, Thanks for fast answer. I 'll upgrade to 2.3.1 and make a correction in sources , Thanks, Radek Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.