]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
CCAR: protect Fortran Calcium calls against unneeded float arguments incorrectly...
authorcaremoli <caremoli>
Wed, 12 Jan 2011 16:12:04 +0000 (16:12 +0000)
committercaremoli <caremoli>
Wed, 12 Jan 2011 16:12:04 +0000 (16:12 +0000)
src/Basics/Basics_Utils.cxx
src/Basics/Basics_Utils.hxx
src/Container/SALOME_Container.cxx
src/DSC/DSC_User/Datastream/Calcium/CalciumMacroCInterface.hxx
src/DSC/DSC_User/Datastream/Calcium/calciumf.c

index 6ff3cf36cdc15c9fa3ce51b3cd00e1d838c0af06..161bc592322ec135b30cbcbf5fa092586e7bd703 100644 (file)
 //
 #include "Basics_Utils.hxx"
 #include <string.h>
+#include <stdlib.h>
 
 #ifndef WIN32
 #include <unistd.h>
 #include <sys/stat.h>
+#include <execinfo.h>
 #else
 #include <winsock2.h>
 #endif
@@ -103,4 +105,24 @@ namespace Kernel_Utils
     return guid;
   }
 
+#ifndef WIN32
+  void print_traceback()
+  {
+    void *array[50];
+    size_t size;
+    char **strings;
+    size_t i;
+
+    size = backtrace (array, 40);
+    strings = backtrace_symbols (array, size);
+
+    for (i = 0; i < size; i++)
+      {
+        std::cerr << strings[i] << std::endl;
+      }
+
+    free (strings);
+  }
+#endif
+
 }
index ce0513c4986c65cf4d3b90db03e8fc742f3a772e..b4aa5e2418c386e8b80491f518fdb4fc136e48d5 100644 (file)
@@ -52,6 +52,9 @@ namespace Kernel_Utils
 
   //! Get predefined GUID
   BASICS_EXPORT std::string GetGUID( GUIDtype );
+#ifndef WIN32
+  BASICS_EXPORT void print_traceback();
+#endif
 }
 
 #define START_TIMING(name) static long name##tcount=0;static long name##cumul;long name##tt0; timeval name##tv; gettimeofday(&name##tv,0); \
index 45ff4e069fb42674ec6b39b37a29beebfdf74d2d..fb89c99f5a5e81c86d10c240e5aec652c035f531 100644 (file)
@@ -106,7 +106,7 @@ void AttachDebugger()
 
 void Handler(int theSigId)
 {
-  std::cerr << "SIGSEGV: "  << std::endl;
+  std::cerr << "Signal= "<< theSigId  << std::endl;
   AttachDebugger();
   //to exit or not to exit
   _exit(1);
@@ -136,6 +136,7 @@ int main(int argc, char* argv[])
   if(getenv ("DEBUGGER"))
     {
       setsig(SIGSEGV,&Handler);
+      setsig(SIGFPE,&Handler);
       std::set_terminate(&terminateHandler);
       std::set_unexpected(&unexpectedHandler);
     }
index 7773759f7343a121040f6d4c07d4c4a527f81a40..0ce1a1844981e2cfa251c773e8d8025fcbfcb2a7 100644 (file)
@@ -65,8 +65,13 @@ Id          : $Id$
                                                          size_t * nRead, _type _qual ** data )                   \
   {                                                                                                              \
     Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);                              \
-    double         _ti=*ti;                                                                                      \
-    double         _tf=*tf;                                                                                      \
+    double         _ti=0.;                                                                                       \
+    double         _tf=0.;                                                                                       \
+    if(dependencyType == CalciumTypes::CP_TEMPS)                                                                               \
+      {                                                                                                          \
+        _ti=*ti;                                                                                                 \
+        _tf=*tf;                                                                                                 \
+      }                                                                                                          \
     size_t         _nRead=0;                                                                                     \
     size_t         _bufferLength=bufferLength;                                                                   \
                                                                                                                  \
@@ -118,7 +123,9 @@ Id          : $Id$
     DEBTRACE( "-------- CalciumInterface(ecriture Inter Part) MARK 0 ------------------" )                \
     Superv_Component_i * _component = static_cast<Superv_Component_i *>(component);                       \
     /* Je ne sais pas pourquoi, je n'arrive pas à passer t par valeur : corruption de la pile*/           \
-    double         _t=*t;                                                                                 \
+    double         _t=0.;                                                                                 \
+    if(dependencyType == CalciumTypes::CP_TEMPS)                                                                        \
+      _t=*t;                                                                                              \
     size_t         _bufferLength=bufferLength;                                                            \
     if ( IsSameType< _porttype , cplx >::value ) _bufferLength=_bufferLength*2;                           \
     DEBTRACE( "-------- CalciumInterface(ecriture Inter Part) MARK 1 ------------------" )                \
index 8986e1c478775fc8022233219dd0eb46a2f8b1e9..6470a87f59ffdce63eddd15166e8c0ceb1ede341 100644 (file)
@@ -63,6 +63,24 @@ static void free_str1(char *nom)
   free(nom);
 }
 
+#define FLOAT_OK              0
+#define POS_INFINITY          1
+#define NEG_INFINITY          2
+#define QUIET_NAN             3
+#define SIGNALING_NAN         4
+
+int CheckFloat(float* value)
+{
+   unsigned long L1 = *(unsigned long*)value;
+   unsigned long L2 = L1 & 0x7fffffff;
+   if (L2 < 0x7f800000) return (FLOAT_OK); // Short circuit for most values
+   if (L1 == 0x7f800000) return (POS_INFINITY);
+   else if (L1 == 0xff800000) return (NEG_INFINITY);
+   else if (L2 >= 0x7fc00000) return (QUIET_NAN);
+   else if ((L2 >= 0x7f800001) && (L2 <= 0x7fbfffff)) return (SIGNALING_NAN);
+   else return (FLOAT_OK);
+}
+
 /**********************************************/
 /*  INTERFACES DE DÉBUT ET DE FIN DE COUPLAGE */
 /**********************************************/
@@ -284,6 +302,8 @@ void F_FUNC(cpech,CPECH)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS
   char ** tabChaine=NULL;
   cal_int     index=0,index2=0;
   char*   cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
+  float tti=0.;
+  if(*dep == CP_TEMPS)tti=*ti;
 
   tabChaine = (char **) malloc(sizeof(char *) * *n);
   for (index = 0; index < *n; index++)
@@ -298,7 +318,7 @@ void F_FUNC(cpech,CPECH)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS
         }
     }
 
-  *err=cp_ech_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tabChaine,STR_LEN(tab) );
+  *err=cp_ech_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tabChaine,STR_LEN(tab) );
 
   if (tabChaine != (char **) NULL)
     {
@@ -311,34 +331,41 @@ void F_FUNC(cpech,CPECH)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS
 
 void F_FUNC(cpedb,CPEDB)(long *compo,cal_int *dep,double *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, double *tab,cal_int *err STR_PLEN(nom))
 {
+  double tti=0.;
+  if(*dep == CP_TEMPS)tti=*ti;
   char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
-  *err=cp_edb_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab);
+  *err=cp_edb_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
   free_str1(cnom);
 }
 
 void F_FUNC(cpere,CPERE)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, float *tab,cal_int *err STR_PLEN(nom))
 {
+  float tti=0.;
+  if(*dep == CP_TEMPS)tti=*ti;
   char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
-  *err=cp_ere_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab);
+  *err=cp_ere_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
   free_str1(cnom);
 }
 
 void F_FUNC(cpecp,CPECP)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, float *tab,cal_int *err STR_PLEN(nom))
 {
+  float tti=0.;
+  if(*dep == CP_TEMPS)tti=*ti;
   char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
-  *err=cp_ecp_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab);
+  *err=cp_ecp_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
   free_str1(cnom);
 }
 
 
 void F_FUNC(cpein,CPEIN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, int *tab,cal_int *err STR_PLEN(nom))
 {
-
+  float tti=0.;
+  if(*dep == CP_TEMPS)tti=*ti;
   char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
 #if   !SIZEOF_INT
 #error "The macro SIZEOF_INT must be defined."
 #elif SIZEOF_INT == 4
-  *err=cp_ein_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab);
+  *err=cp_ein_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
 #else
   fprintf(stderr,"CPEIN: %s %f %d : Can't use fortran INTEGER*4 because int C is not 32bits long on this machine.\n",
           cnom, *ti,*iter);
@@ -348,12 +375,13 @@ void F_FUNC(cpein,CPEIN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS
 
 void F_FUNC(cpelg,CPELG)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, long *tab,cal_int *err STR_PLEN(nom))
 {
-
+  float tti=0.;
+  if(*dep == CP_TEMPS)tti=*ti;
   char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
 #if   !SIZEOF_LONG
 #error "The macro SIZEOF_LONG must be defined."
 #elif SIZEOF_LONG == 8
-  *err=cp_elg_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab);
+  *err=cp_elg_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
 #else
   fprintf(stderr,"CPELG: %s %f %d : Can't use fortran INTEGER*8 because long C is not 64bits long on this machine.\n",
           cnom, *ti,*iter);
@@ -363,12 +391,13 @@ void F_FUNC(cpelg,CPELG)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS
 
 void F_FUNC(cpeln,CPELN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, long *tab,cal_int *err STR_PLEN(nom))
 {
-
+  float tti=0.;
+  if(*dep == CP_TEMPS)tti=*ti;
   char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
 #if   !SIZEOF_LONG
 #error "The macro SIZEOF_LONG must be defined."
 #elif SIZEOF_LONG == 8
-  *err=cp_eln_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab);
+  *err=cp_eln_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
 #else
   fprintf(stderr,"CPELN: %s %f %d : Can't use fortran INTEGER*8 because long C is not 64bits long on this machine.\n",
           cnom, *ti,*iter);
@@ -379,15 +408,19 @@ void F_FUNC(cpeln,CPELN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PS
 
 void F_FUNC(cpeen,CPEEN)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, cal_int *tab,cal_int *err STR_PLEN(nom))
 {
+  float tti=0.;
+  if(*dep == CP_TEMPS)tti=*ti;
   char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
-  *err=cp_een_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab);
+  *err=cp_een_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
   free_str1(cnom);
 }
 
 void F_FUNC(cpelo,CPELO)(long *compo,cal_int *dep,float *ti,cal_int *iter,STR_PSTR(nom),cal_int *n, int *tab,cal_int *err STR_PLEN(nom))
 {
+  float tti=0.;
+  if(*dep == CP_TEMPS)tti=*ti;
   char* cnom=fstr1(STR_PTR(nom),STR_LEN(nom));
-  *err=cp_elo_fort_((void *)*compo,*dep,*ti,*iter,cnom,*n,tab);
+  *err=cp_elo_fort_((void *)*compo,*dep,tti,*iter,cnom,*n,tab);
   free_str1(cnom);
 }