Fixed mog format warning on 64 Bits architecture. Might get the warnings again for...
authorEbersold Andre <aebersol@md2p7zxc.ad001.siemens.net>
Tue, 17 May 2022 09:03:19 +0000 (11:03 +0200)
committerEbersold Andre <aebersol@md2p7zxc.ad001.siemens.net>
Tue, 17 May 2022 09:03:19 +0000 (11:03 +0200)
aeb/pointer/shared_ptr.h

index 8ce1c294d4d1efca23844d07ae41a87f47c78af3..e3b36af05674126faecf33d6b34f1292b8779e6f 100644 (file)
@@ -32,7 +32,7 @@ class ref_counted
     {
         if (m_ref == 0) 
         {
-            std::cerr<<"HAI"<<std::endl;
+            std::cerr<<"ref_counter::release HAI"<<std::endl;
             return false;
         }
         if (!--m_ref)
@@ -70,49 +70,58 @@ class shared_ptr
   public:
     shared_ptr(T *p = NULL) : m_ptr(p) ,m_counter(NULL) {
        m_counter = new ref_counted<T>((p == NULL)?0:1,p);
-       LOG_SP_DEBUG_FMT("shared_ptr(%0x)::shared_ptr NULL count=%d %x",this,m_counter->count(),m_ptr);
+       LOG_SP_DEBUG_FMT("shared_ptr(%0lx)::shared_ptr NULL count=%d m_ptr=%lx",(unsigned long)this,m_counter->count(),(unsigned long)m_ptr);
        //m_counter->add_ref();
     }
 
     ~shared_ptr() {
-        LOG_SP_DEBUG_FMT("shared_ptr(%0x)::~shared_ptr count=%d %x",this,m_counter->count(),m_ptr);
-        if ( m_counter->release() && m_ptr)
+        LOG_SP_DEBUG_FMT("shared_ptr(%0lx)::~shared_ptr count=%d pointer=%lx",(unsigned long)this,m_counter->count(),(unsigned long)m_ptr);
+        if ( m_ptr && m_counter->release() )
         {
-            LOG_SP_DEBUG_FMT("shared_ptr(%0x)::~shared_ptr 1 delete m_counter %0x" ,this,m_ptr);
-            delete m_counter;
-            LOG_SP_DEBUG_FMT("shared_ptr(%0x)::~shared_ptr 1 delete m_ptr %0x" ,this,m_ptr);
+            LOG_SP_DEBUG_FMT("shared_ptr(%0lx)::~shared_ptr 1 delete m_counter %0lx" ,(unsigned long)this,(unsigned long)m_ptr);
+            delete m_counter; m_counter = NULL;
+            LOG_SP_DEBUG_FMT("shared_ptr(%0lx)::~shared_ptr 1 delete m_ptr %0lx" ,(unsigned long)this,(unsigned long)m_ptr);
             delete m_ptr;
         }
+        if (m_counter)
+        {
+            delete m_counter ;  m_counter = NULL;
+        }
+
     }
     // Copy constructor
     shared_ptr(const shared_ptr<T> &c) : m_counter(c.m_counter) ,m_ptr(c.m_ptr) {
-       LOG_SP_DEBUG_FMT("shared_ptr(%0x)::shared_ptr copy count=%d %x",this,m_counter->count(),m_ptr);
+       LOG_SP_DEBUG_FMT("shared_ptr(%0lx)::shared_ptr copy count=%d %lx",(unsigned long)this,m_counter->count(),(unsigned long)m_ptr);
 #if 1
-       if (m_ptr) 
+       if (m_ptr)
+       {
          m_counter->add_ref();
+       } else
+       { // Copy of null pointer ! Should I do sompething with m_counter
+       }
 #endif
     }
     // Copy operator
     shared_ptr<T> &operator =(const shared_ptr<T> &rhs) {
-      LOG_SP_DEBUG_FMT("shared_ptr(%0x)::operator =  count=%d m_ptr=%x",this,m_counter->count(),m_ptr);
-      LOG_SP_DEBUG_FMT("shared_ptr(%0x)::operator = rsh  count=%d m_ptr=%x",this,rhs.m_counter->count(),rhs.m_ptr);
+      LOG_SP_DEBUG_FMT("shared_ptr(%0lx)::operator =  count=%d m_ptr=%lx",(unsigned long)this,m_counter->count(),(unsigned long)m_ptr);
+      LOG_SP_DEBUG_FMT("shared_ptr(%0lx)::operator = rsh  count=%d m_ptr=%lx",(unsigned long)this,rhs.m_counter->count(),(unsigned long)rhs.m_ptr);
       if (this != &rhs)
       {
-        LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0x) != &rhs(%0x)" ,this,&rhs);
+        LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0lx) != &rhs(%0lx)" ,(unsigned long)this,(unsigned long)&rhs);
         // Free pointer I owned
         if ( m_counter->count() && m_counter->release() )
         {
-          LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0x) delete counter %0x" ,this,m_counter);
+          LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0lx) delete counter %0lx" ,(unsigned long)this,(unsigned long)m_counter);
           delete m_counter;
-          LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0x) delete m_ptr %0x" ,this,m_ptr);
+          LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0lx) delete m_ptr %0lx" ,(unsigned long)this,(unsigned long)m_ptr);
           delete m_ptr; m_ptr = NULL;
         }  else {
-          LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0x) delete m_counter %0x" ,this,m_counter);
+          LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0lx) delete m_counter %0lx" ,(unsigned long)this,(unsigned long)m_counter);
           delete m_counter;
           // Not sure if this is needed
          if (m_ptr != NULL) 
          {
-              LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0x) 1 delete m_ptr %0x" ,this,m_ptr);
+              LOG_SP_DEBUG_FMT("shared_ptr::operator = this(%0lx) 1 delete m_ptr %0lx" ,(unsigned long)this,(unsigned long)m_ptr);
              delete m_ptr;
              m_ptr = NULL;
          }