Salome HOME
Static members of CellModel and Units fix. abn/static_fix V9_9_0a1
authorabn <adrien.bruneton@cea.fr>
Thu, 3 Feb 2022 12:28:42 +0000 (13:28 +0100)
committerabn <adrien.bruneton@cea.fr>
Fri, 4 Feb 2022 14:14:05 +0000 (15:14 +0100)
+ static items moved into dedicated methods with local static variables
+ avoid strange crashes in complex code couplings on some compilers.

src/INTERP_KERNEL/CellModel.cxx
src/INTERP_KERNEL/CellModel.hxx
src/INTERP_KERNEL/ExprEval/InterpKernelUnit.cxx
src/INTERP_KERNEL/ExprEval/InterpKernelUnit.hxx
src/INTERP_KERNEL/ExprEval/InterpKernelValue.cxx

index 96b97b2f50b0f13c54c2afddbfef70c8d9b059a5..60029b273409b7bc74efeaba34e0afc367e1a4f7 100644 (file)
@@ -43,14 +43,11 @@ namespace INTERP_KERNEL
                                             "", "", "", "", "",//35->39
                                             "NORM_ERROR"};
 
-  std::map<NormalizedCellType,CellModel> CellModel::_map_of_unique_instance;
-
   const CellModel& CellModel::GetCellModel(NormalizedCellType type)
   {
-    if(_map_of_unique_instance.empty())
-      buildUniqueInstance();
-    const std::map<NormalizedCellType,CellModel>::iterator iter=_map_of_unique_instance.find(type);
-    if(iter==_map_of_unique_instance.end())
+    const std::map<NormalizedCellType,CellModel>& map_unique = GetMapOfUniqueInstance();
+    const std::map<NormalizedCellType,CellModel>::const_iterator iter=map_unique.find(type);
+    if(iter==map_unique.end())
       {
         std::ostringstream stream; stream << "no cellmodel for normalized type " << type;
         throw Exception(stream.str().c_str());
@@ -58,6 +55,14 @@ namespace INTERP_KERNEL
     return (*iter).second;
   }
 
+  const std::map<NormalizedCellType,CellModel>& CellModel::GetMapOfUniqueInstance()
+  {
+    static std::map<NormalizedCellType,CellModel> map_of_unique_instance;
+    if(map_of_unique_instance.empty())
+      BuildUniqueInstance(map_of_unique_instance);
+    return map_of_unique_instance;
+  }
+
   const char *CellModel::getRepr() const
   {
     return CELL_TYPES_REPR[(int)_type];
@@ -82,34 +87,34 @@ namespace INTERP_KERNEL
     return b1 || b2;
   }
 
-  void CellModel::buildUniqueInstance()
+  void CellModel::BuildUniqueInstance(std::map<NormalizedCellType,CellModel>& map_unique)
   {
-    _map_of_unique_instance.insert(std::make_pair(NORM_POINT1,CellModel(NORM_POINT1)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_SEG2,CellModel(NORM_SEG2)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_SEG3,CellModel(NORM_SEG3)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_SEG4,CellModel(NORM_SEG4)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TRI3,CellModel(NORM_TRI3)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_QUAD4,CellModel(NORM_QUAD4)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TRI6,CellModel(NORM_TRI6)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TRI7,CellModel(NORM_TRI7)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_QUAD8,CellModel(NORM_QUAD8)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_QUAD9,CellModel(NORM_QUAD9)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TETRA4,CellModel(NORM_TETRA4)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_HEXA8,CellModel(NORM_HEXA8)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PYRA5,CellModel(NORM_PYRA5)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PENTA6,CellModel(NORM_PENTA6)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_TETRA10,CellModel(NORM_TETRA10)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_HEXGP12,CellModel(NORM_HEXGP12)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PYRA13,CellModel(NORM_PYRA13)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PENTA15,CellModel(NORM_PENTA15)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_PENTA18,CellModel(NORM_PENTA18)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_HEXA20,CellModel(NORM_HEXA20)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_HEXA27,CellModel(NORM_HEXA27)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_POLYGON,CellModel(NORM_POLYGON)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_POLYHED,CellModel(NORM_POLYHED)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_QPOLYG,CellModel(NORM_QPOLYG)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_POLYL,CellModel(NORM_POLYL)));
-    _map_of_unique_instance.insert(std::make_pair(NORM_ERROR,CellModel(NORM_ERROR)));
+    map_unique.insert(std::make_pair(NORM_POINT1,CellModel(NORM_POINT1)));
+    map_unique.insert(std::make_pair(NORM_SEG2,CellModel(NORM_SEG2)));
+    map_unique.insert(std::make_pair(NORM_SEG3,CellModel(NORM_SEG3)));
+    map_unique.insert(std::make_pair(NORM_SEG4,CellModel(NORM_SEG4)));
+    map_unique.insert(std::make_pair(NORM_TRI3,CellModel(NORM_TRI3)));
+    map_unique.insert(std::make_pair(NORM_QUAD4,CellModel(NORM_QUAD4)));
+    map_unique.insert(std::make_pair(NORM_TRI6,CellModel(NORM_TRI6)));
+    map_unique.insert(std::make_pair(NORM_TRI7,CellModel(NORM_TRI7)));
+    map_unique.insert(std::make_pair(NORM_QUAD8,CellModel(NORM_QUAD8)));
+    map_unique.insert(std::make_pair(NORM_QUAD9,CellModel(NORM_QUAD9)));
+    map_unique.insert(std::make_pair(NORM_TETRA4,CellModel(NORM_TETRA4)));
+    map_unique.insert(std::make_pair(NORM_HEXA8,CellModel(NORM_HEXA8)));
+    map_unique.insert(std::make_pair(NORM_PYRA5,CellModel(NORM_PYRA5)));
+    map_unique.insert(std::make_pair(NORM_PENTA6,CellModel(NORM_PENTA6)));
+    map_unique.insert(std::make_pair(NORM_TETRA10,CellModel(NORM_TETRA10)));
+    map_unique.insert(std::make_pair(NORM_HEXGP12,CellModel(NORM_HEXGP12)));
+    map_unique.insert(std::make_pair(NORM_PYRA13,CellModel(NORM_PYRA13)));
+    map_unique.insert(std::make_pair(NORM_PENTA15,CellModel(NORM_PENTA15)));
+    map_unique.insert(std::make_pair(NORM_PENTA18,CellModel(NORM_PENTA18)));
+    map_unique.insert(std::make_pair(NORM_HEXA20,CellModel(NORM_HEXA20)));
+    map_unique.insert(std::make_pair(NORM_HEXA27,CellModel(NORM_HEXA27)));
+    map_unique.insert(std::make_pair(NORM_POLYGON,CellModel(NORM_POLYGON)));
+    map_unique.insert(std::make_pair(NORM_POLYHED,CellModel(NORM_POLYHED)));
+    map_unique.insert(std::make_pair(NORM_QPOLYG,CellModel(NORM_QPOLYG)));
+    map_unique.insert(std::make_pair(NORM_POLYL,CellModel(NORM_POLYL)));
+    map_unique.insert(std::make_pair(NORM_ERROR,CellModel(NORM_ERROR)));
   }
 
   CellModel::CellModel(NormalizedCellType type):_type(type)
@@ -413,7 +418,7 @@ namespace INTERP_KERNEL
           _sons_type[0]=NORM_QUAD9; _sons_type[1]=NORM_QUAD9; _sons_type[2]=NORM_QUAD9; _sons_type[3]=NORM_QUAD9; _sons_type[4]=NORM_QUAD9; _sons_type[5]=NORM_QUAD9;
           _sons_con[0][0]=0; _sons_con[0][1]=1; _sons_con[0][2]=2; _sons_con[0][3]=3; _sons_con[0][4]=8; _sons_con[0][5]=9; _sons_con[0][6]=10; _sons_con[0][7]=11; _sons_con[0][8]=20; _nb_of_sons_con[0]=9;
           _sons_con[1][0]=4; _sons_con[1][1]=7; _sons_con[1][2]=6; _sons_con[1][3]=5; _sons_con[1][4]=15; _sons_con[1][5]=14; _sons_con[1][6]=13; _sons_con[1][7]=12; _sons_con[1][8]=25; _nb_of_sons_con[1]=9;
-          _sons_con[2][0]=0; _sons_con[2][1]=4; _sons_con[2][2]=5; _sons_con[2][3]=1; _sons_con[2][4]=16; _sons_con[2][5]=12; _sons_con[2][6]=17; _sons_con[2][7]=8; _sons_con[2][8]=21; _nb_of_sons_con[2]=9;   
+          _sons_con[2][0]=0; _sons_con[2][1]=4; _sons_con[2][2]=5; _sons_con[2][3]=1; _sons_con[2][4]=16; _sons_con[2][5]=12; _sons_con[2][6]=17; _sons_con[2][7]=8; _sons_con[2][8]=21; _nb_of_sons_con[2]=9;
           _sons_con[3][0]=1; _sons_con[3][1]=5; _sons_con[3][2]=6; _sons_con[3][3]=2; _sons_con[3][4]=17; _sons_con[3][5]=13; _sons_con[3][6]=18; _sons_con[3][7]=9; _sons_con[3][8]=22; _nb_of_sons_con[3]=9;
           _sons_con[4][0]=2; _sons_con[4][1]=6; _sons_con[4][2]=7; _sons_con[4][3]=3; _sons_con[4][4]=18; _sons_con[4][5]=14; _sons_con[4][6]=19; _sons_con[4][7]=10; _sons_con[4][8]=23; _nb_of_sons_con[4]=9;
           _sons_con[5][0]=3; _sons_con[5][1]=7; _sons_con[5][2]=4; _sons_con[5][3]=0; _sons_con[5][4]=19; _sons_con[5][5]=15; _sons_con[5][6]=16; _sons_con[5][7]=11; _sons_con[5][8]=24; _nb_of_sons_con[5]=9;
@@ -475,7 +480,7 @@ namespace INTERP_KERNEL
     else//polyhedron
       return FromIdType<unsigned>(lgth-ToIdType(std::count(conn,conn+lgth,-1)/2));
   }
-  
+
   /*!
    * \sa fillMicroEdgeNodalConnectivity
    */
@@ -497,7 +502,7 @@ namespace INTERP_KERNEL
     else
       throw INTERP_KERNEL::Exception("CellModel::getNumberOfMacroEdges : not supported by dynamic type !");
   }
-  
+
   NormalizedCellType CellModel::getCorrespondingPolyType() const
   {
     switch(getDimension())
@@ -599,7 +604,7 @@ namespace INTERP_KERNEL
           throw INTERP_KERNEL::Exception("CellModel::fillSonCellNodalConnectivity2 : no sons on NORM_POLYL !");
       }
   }
-  
+
   /*!
    * Equivalent to CellModel::fillSonCellNodalConnectivity2 except for HEXA8 where the order of sub faces is not has MED file numbering for transformation HEXA8->HEXA27
    */
@@ -635,7 +640,7 @@ namespace INTERP_KERNEL
           }
       }
     else
-      throw INTERP_KERNEL::Exception("CellModel::fillSonEdgesNodalConnectivity3D : not implemented yet for NORM_POLYHED !");   
+      throw INTERP_KERNEL::Exception("CellModel::fillSonEdgesNodalConnectivity3D : not implemented yet for NORM_POLYHED !");
   }
 
   /*!
@@ -826,7 +831,7 @@ namespace INTERP_KERNEL
           }
       }
   }
-  
+
   DiameterCalculator *CellModel::buildInstanceOfDiameterCalulator(int spaceDim) const
   {
     switch(_type)
index 5881426ae21a74713a2fd1111607f2c5d7322858..786f5e66490bb0003b5ddfbbf69fdcc0a51eaeec 100644 (file)
@@ -38,7 +38,7 @@ namespace INTERP_KERNEL
 {
   class DiameterCalculator;
   class OrientationInverter;
-  
+
   /*!
    * This class describes all static elements (different from polygons and polyhedron) 3D, 2D and 1D.
    */
@@ -50,9 +50,10 @@ namespace INTERP_KERNEL
     static const unsigned MAX_NB_OF_LITTLE_SONS=12;
   private:
     CellModel(NormalizedCellType type);
-    static void buildUniqueInstance();
+    static void BuildUniqueInstance(std::map<NormalizedCellType,CellModel>& map);
   public:
     INTERPKERNEL_EXPORT static const CellModel& GetCellModel(NormalizedCellType type);
+    INTERPKERNEL_EXPORT static const std::map<NormalizedCellType,CellModel>& GetMapOfUniqueInstance();
     INTERPKERNEL_EXPORT NormalizedCellType getEnum() const { return _type; }
     INTERPKERNEL_EXPORT const char *getRepr() const;
     INTERPKERNEL_EXPORT bool isExtruded() const { return _is_extruded; }
@@ -108,7 +109,6 @@ namespace INTERP_KERNEL
     unsigned _little_sons_con[MAX_NB_OF_LITTLE_SONS][3];
     unsigned _nb_of_sons_con[MAX_NB_OF_SONS];
     NormalizedCellType _sons_type[MAX_NB_OF_SONS];
-    static std::map<NormalizedCellType,CellModel> _map_of_unique_instance;
     static const char *CELL_TYPES_REPR[];
   };
 }
index 785461f44a270a9722ce9572e9193b61991a59ee..f270623474353e3512fe9e806a68fa72342dd28a 100644 (file)
 
 using namespace INTERP_KERNEL;
 
-UnitDataBase UnitDataBase::_uniqueMapForExpr;
+const UnitDataBase& UnitDataBase::GetUniqueMapForExpr()
+{
+  static UnitDataBase db;
+  return db;
+}
 
 static const char InterpKernelMuAscii[2]={-0x4B,0x0};
 
index e75ed09a9daeb9ff6b10eded5306387c7ba0101d..40c1466a503a066b97944ba65f39ed11430aad57 100644 (file)
@@ -34,7 +34,7 @@ namespace INTERP_KERNEL
   public:
     INTERPKERNEL_EXPORT UnitDataBase();
     INTERPKERNEL_EXPORT const short *getInfoForUnit(const std::string& unit, double& addFact, double& mFact) const;
-    INTERPKERNEL_EXPORT static UnitDataBase _uniqueMapForExpr;
+    INTERPKERNEL_EXPORT static const UnitDataBase& GetUniqueMapForExpr();
     INTERPKERNEL_EXPORT static const int SIZE_OF_UNIT_BASE=5;
   private:
     std::map<std::string,double> _prefix_pow_10;
index eb29f17bc8aac46f71c8a37bbae7cc93e8b673bd..e7d264a60b2ebfedd5de7fb3de63e28403147a69 100644 (file)
@@ -226,7 +226,7 @@ void ValueUnit::setDouble(double val)
 void ValueUnit::setVarname(int fastPos, const std::string& var)
 {
   double add,mul;
-  const short *projInBase=UnitDataBase::_uniqueMapForExpr.getInfoForUnit(var,add,mul);
+  const short *projInBase=UnitDataBase::GetUniqueMapForExpr().getInfoForUnit(var,add,mul);
   _data.setInfo(projInBase,add,mul);
 }
 
@@ -567,7 +567,7 @@ Value *ValueDoubleExpr::pow(const Value *other) const
   if(it!=_dest_data+_sz_dest_data)
     throw INTERP_KERNEL::Exception("Trying to operate pow(a,b) with a<0. !");
   ValueDoubleExpr *ret=new ValueDoubleExpr(_sz_dest_data,_src_data);
-  std::transform(_dest_data,_dest_data+_sz_dest_data,ret->getData(),std::bind([](double x, double y){return std::pow(x,y);},std::placeholders::_1,p)); 
+  std::transform(_dest_data,_dest_data+_sz_dest_data,ret->getData(),std::bind([](double x, double y){return std::pow(x,y);},std::placeholders::_1,p));
   return ret;
 }