0030846: Foundation Classes - StorageInfo violates the C++ One Definition Rule
authorkgv <kgv@opencascade.com>
Wed, 4 Sep 2019 15:42:42 +0000 (18:42 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 6 Sep 2019 15:26:41 +0000 (18:26 +0300)
Local definitions have been put into anonymouse namespace within files
OSD_MAllocHook.cxx and NCollection_BaseAllocator.cxx.

src/NCollection/NCollection_BaseAllocator.cxx
src/OSD/OSD_MAllocHook.cxx

index 0c45258..d536b0b 100644 (file)
@@ -13,9 +13,8 @@
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
 // Alternatively, this file may be used under the terms of Open CASCADE
 // commercial license or contractual agreement.
 
-// Purpose:     Implementation of the BaseAllocator class
-
 #include <NCollection_BaseAllocator.hxx>
 #include <NCollection_BaseAllocator.hxx>
+
 #include <NCollection_IncAllocator.hxx>
 #include <NCollection_DataMap.hxx>
 #include <NCollection_Map.hxx>
 #include <NCollection_IncAllocator.hxx>
 #include <NCollection_DataMap.hxx>
 #include <NCollection_Map.hxx>
@@ -60,62 +59,50 @@ const Handle(NCollection_BaseAllocator)&
   return pAllocator;
 }
 
   return pAllocator;
 }
 
-// global variable to ensure that allocator will be created during loading the library
-static Handle(NCollection_BaseAllocator) theAllocInit = 
-  NCollection_BaseAllocator::CommonBaseAllocator();
-
-//=======================================================================
-/**
- * Structure for collecting statistics about blocks of one size
- */
-//=======================================================================
-struct StorageInfo
+namespace
 {
 {
-  Standard_Size roundSize;
-  int nbAlloc;
-  int nbFree;
-  StorageInfo()
-    : roundSize(0), nbAlloc(0), nbFree(0) {}
-  StorageInfo(Standard_Size theSize)
-    : roundSize(theSize), nbAlloc(0), nbFree(0) {}
-};
+  // global variable to ensure that allocator will be created during loading the library
+  static Handle(NCollection_BaseAllocator) theAllocInit = NCollection_BaseAllocator::CommonBaseAllocator();
 
 
-//=======================================================================
-/**
- * Static data map (block_size -> StorageInfo)
- */
-//=======================================================================
-static NCollection_DataMap<Standard_Size, StorageInfo>& StorageMap()
-{
-  static NCollection_IncAllocator TheAlloc;
-  static NCollection_DataMap<Standard_Size, StorageInfo>
-    TheMap (1, & TheAlloc);
-  return TheMap;
-}
+  //! Structure for collecting statistics about blocks of one size
+  struct StorageInfo
+  {
+    Standard_Size roundSize;
+    int nbAlloc;
+    int nbFree;
+    StorageInfo() : roundSize(0), nbAlloc(0), nbFree(0) {}
+    StorageInfo(Standard_Size theSize) : roundSize(theSize), nbAlloc(0), nbFree(0) {}
+  };
+
+  //! Static data map (block_size -> StorageInfo)
+  static NCollection_DataMap<Standard_Size, StorageInfo>& StorageMap()
+  {
+    static NCollection_IncAllocator TheAlloc;
+    static NCollection_DataMap<Standard_Size, StorageInfo> TheMap (1, & TheAlloc);
+    return TheMap;
+  }
 
 
-//=======================================================================
-/**
- * Static data map (address -> AllocationID)
- */
-//=======================================================================
-static NCollection_DataMap<Standard_Address, Standard_Size>& StorageIDMap()
-{
-  static NCollection_IncAllocator TheAlloc;
-  static NCollection_DataMap<Standard_Address, Standard_Size>
-    TheMap (1, & TheAlloc);
-  return TheMap;
-}
+  //! Static data map (address -> AllocationID)
+  static NCollection_DataMap<Standard_Address, Standard_Size>& StorageIDMap()
+  {
+    static NCollection_IncAllocator TheAlloc;
+    static NCollection_DataMap<Standard_Address, Standard_Size> TheMap (1, & TheAlloc);
+    return TheMap;
+  }
 
 
-//=======================================================================
-/**
- * Static map (AllocationID)
- */
-//=======================================================================
-static NCollection_Map<Standard_Size>& StorageIDSet()
-{
-  static NCollection_IncAllocator TheAlloc;
-  static NCollection_Map<Standard_Size> TheMap (1, & TheAlloc);
-  return TheMap;
+  //! Static map (AllocationID)
+  static NCollection_Map<Standard_Size>& StorageIDSet()
+  {
+    static NCollection_IncAllocator TheAlloc;
+    static NCollection_Map<Standard_Size> TheMap (1, & TheAlloc);
+    return TheMap;
+  }
+
+  // dummy function for break point
+  inline void place_for_break_point () {}
+
+  //! Static value of the current allocation ID. It provides unique numbering of allocation events.
+  static Standard_Size CurrentID = 0;
 }
 
 //=======================================================================
 }
 
 //=======================================================================
@@ -147,14 +134,6 @@ Standard_EXPORT Standard_Size& StandardCallBack_CatchID()
   return Value;
 }
 
   return Value;
 }
 
-//=======================================================================
-/**
- * Static value of the current allocation ID. It provides unique
- * numbering of allocation events.
- */
-//=======================================================================
-static Standard_Size CurrentID = 0;
-
 //=======================================================================
 /**
  * Exported function to reset the callback system to the initial state
 //=======================================================================
 /**
  * Exported function to reset the callback system to the initial state
@@ -170,11 +149,6 @@ Standard_EXPORT void StandardCallBack_Reset()
   StandardCallBack_CatchID() = 0;
 }
 
   StandardCallBack_CatchID() = 0;
 }
 
-namespace {
-  // dummy function for break point
-  inline void place_for_break_point () {}
-}
-
 //=======================================================================
 //function : StandardCallBack
 //purpose  : Callback function to register alloc/free calls
 //=======================================================================
 //function : StandardCallBack
 //purpose  : Callback function to register alloc/free calls
index 6905f2f..f1f61e8 100644 (file)
@@ -246,29 +246,31 @@ void OSD_MAllocHook::LogFileHandler::Close()
 //function : LogFileHandler::MakeReport
 //purpose  :
 //=======================================================================
 //function : LogFileHandler::MakeReport
 //purpose  :
 //=======================================================================
-
-struct StorageInfo
+namespace
 {
 {
-  Standard_Size           size;
-  Standard_Integer        nbAlloc;
-  Standard_Integer        nbFree;
-  Standard_Integer        nbLeftPeak;
-  std::set<unsigned long> alive;
-
-  StorageInfo(Standard_Size theSize = 0)
-  : size      (theSize),
-    nbAlloc   (0),
-    nbFree    (0),
-    nbLeftPeak(0),
-    alive()
+  struct StorageInfo
   {
   {
-  }
+    Standard_Size           size;
+    Standard_Integer        nbAlloc;
+    Standard_Integer        nbFree;
+    Standard_Integer        nbLeftPeak;
+    std::set<unsigned long> alive;
+
+    StorageInfo(Standard_Size theSize = 0)
+    : size      (theSize),
+      nbAlloc   (0),
+      nbFree    (0),
+      nbLeftPeak(0),
+      alive()
+    {
+    }
 
 
-  bool operator < (const StorageInfo& theOther) const
-  {
-    return size < theOther.size;
-  }
-};
+    bool operator < (const StorageInfo& theOther) const
+    {
+      return size < theOther.size;
+    }
+  };
+}
 
 Standard_Boolean OSD_MAllocHook::LogFileHandler::MakeReport
                    (const char* theLogFile,
 
 Standard_Boolean OSD_MAllocHook::LogFileHandler::MakeReport
                    (const char* theLogFile,