Notes |
|
(0021192)
|
Hans Johnson
|
2010-06-29 21:27
|
|
Alternate c++ methods:
? Testing/Code/Review/.itkBinaryContourImageFilterTest.cxx.swp
Index: Code/Common/itkTestMain.h
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/Common/itkTestMain.h,v
retrieving revision 1.33
diff -r1.33 itkTestMain.h
44a45
> #include <csignal>
77a79,92
>
> static void sigfpe_handl(int sig)
> {
> printf("Argggh..Division by zero ! (or other fpe): SIGNAL=%d\n",sig);
> //..some more
> exit(-1);
> }
> //void sigint_handl(int sig)
> //{
> // printf("Program is exiting..: SIGNAL=%d\n",sig);
> // exit(0);
> //}
>
>
79a95,96
> //std::signal(SIGFPE,sigfpe_handl);
> //
Index: Testing/Code/Review/itkBinaryContourImageFilterTest.cxx
===================================================================
RCS file: /cvsroot/Insight/Insight/Testing/Code/Review/itkBinaryContourImageFilterTest.cxx,v
retrieving revision 1.4
diff -r1.4 itkBinaryContourImageFilterTest.cxx
39a40,54
> //Try to force a failure due to floating point exception.
> //
> double failure=100;
> double reallybig=1E200L;
> int myint=1000;
> for(int i=10; i >=0 ; i--)
> {
> failure+=failure/static_cast<double>(i);
> //NOTE: the last iteration in this loop i=0.0, and then it should throw a floating point exception.
> //std::cout << "WARNING: failure should thow FPE: " << failure << std::endl;
> myint=myint/i;
> std::cout << "WARNING: failure should thow FPE: " << myint << std::endl;
> //std::cout << reallybig*reallybig*static_cast<double>(i) << std::endl;
> }
> |
|
|
(0021209)
|
Matthew McCormick
|
2010-07-01 15:11
|
|
Cool. Looks like a nice convenient class. Maybe a way to configure which exceptions are enabled in the class would be nice. Also, my preference is to have an exception thrown rather than call abort(). That way I can catch it and ignore it or handle it if needed. You can always get a stack trace if you run 'catch throw' in gdb. |
|
|
(0021363)
|
Hans Johnson
|
2010-07-12 14:39
|
|
The file fe-handling-example.c is a standalone program that seems to display the desired behavior.
The file floatingPointUpdateFiles.tar.gz should be extracted in the Insight code directory, and contains the start of the code necessary to implement this across all tests in ITK. This is a copy of some of the framework from VTK, but does not use the same mechanisms as fe-handling-example.c, and does not catch the same floating point exceptions.
TODO: Merge these two exception handling routinges, and make work on at least one platform type (i.e. it does not need to work under any compiler except the gcc compiler)
TODO: Make a set of tests to ensure that exceptions are actually caught. |
|
|
(0021400)
|
kentwilliams
|
2010-07-15 14:35
|
|
I added a new file ITKFPE-fixes.tar.gz that is a tested fix. It comprises a patchfile to existing files, plus the new files needed. |
|
|
(0021405)
|
Matthew McCormick
|
2010-07-15 23:32
|
|
I needed to
#include <cstring>
for the code to compile.
I some ITK code that I use which throws C++ exceptions in a floating point signal handler. Apparently, further reading indicates that is bad practice because it is not guaranteed to work. Commenting in your exception code the underflow test would fail for whatever reason, though the other tests would pass. Live and learn. |
|
|
(0021408)
|
kentwilliams
|
2010-07-16 10:33
|
|
Matthew -- to what file did you need to add #include <cstring>? What platform were you compiling on? |
|
|
(0021409)
|
Matthew McCormick
|
2010-07-16 11:09
|
|
Sorry for the lack of detail -- a patch is attached. cstring is needed for memset(). This is Linux/gcc-4.4.3. Newer gcc's tend to catch more errors. |
|