Loading ...
Sorry, an error occurred while loading the content.
 

BUG: intrusive pointer and weak_ptr

Expand Messages
  • Petr Ferschmann
    ... Hash: SHA1 Hello, I think I found BUG. Let we have this program: - -- cut here -- #include #include #include
    Message 1 of 1 , Oct 1, 2002
      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      Hello,

      I think I found BUG.
      Let we have this program:
      - -- cut here --
      #include <boost/shared_ptr.hpp>
      #include <boost/weak_ptr.hpp>
      #include <boost/intrusive_ptr.hpp>
      #include <cstdio>

      using namespace std;

      #define INTR

      class MujObjekt
      #ifdef INTR
      : public boost::counted_base
      #endif
      {
      public:
      MujObjekt()
      {
      printf( "MujObjekt::MujObjekt()\n" );
      }

      void setThis( boost::shared_ptr<MujObjekt> obj )
      {
      m_this = obj;
      }

      virtual ~MujObjekt()
      {
      printf( "MujObjekt::~MujObjekt()\n" );
      }

      boost::weak_ptr<MujObjekt> m_this;
      };


      int main()
      {
      boost::shared_ptr<MujObjekt> obj( new MujObjekt() );
      obj->setThis( obj );

      return( 0 );
      }
      - --- cut here ---

      But in case of usage of intrusive pointer it doesn't call destructor - because
      there is weak pointer.

      But when I undefine INTR and it uses non-intrusive it works as expected. This
      is only modelling case to simulate bug.

      - --
      Petr "Fers" Ferschmann

      -=[ petr@... ]==[ http://petr.ferschmann.cz/ ]=-
      - -=[ Koukni na http://www.postcard.cz/ ]==[ +420 604/781 009 ]=-

      GPG Fingerprint:
      [83B0 6378 7A9D D993 035E 60BD FEEC F665 D2C8 1B9A]
      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.0.7 (GNU/Linux)

      iD8DBQE9mV9O/uz2ZdLIG5oRArF/AJ9LGfWTXfy69zNTsbiEKThTPQnWcwCeOWgj
      0tX9AxdWJ8u/L1MkdZHjOPk=
      =7A3i
      -----END PGP SIGNATURE-----
    Your message has been successfully submitted and would be delivered to recipients shortly.