signal.h and swig on MinGW

Issue #611 resolved
Chaffra Affouda created an issue

On MinGW,

The swig wrapping fails with the following. It looks like swig does not know what sigaction is. It builds fine on Linux but something is missing to build on MinGW. I think I have to include signal.h somewhere for swig to get it but I don't know where.

FEniCS/src/dolfin/dorsal_build_dir/dolfin/swig/modules/common/modulePYTHON
_wrap.cxx:4674:24: error: aggregate 'dolfin::dolfin_terminate()::sigaction act' has incomplete type
and cannot be defined
       struct sigaction act;
                        ^
FEniCS/src/dolfin/dorsal_build_dir/dolfin/swig/modules/common/modulePYTHON
_wrap.cxx:4677:36: error: invalid use of incomplete type 'struct dolfin::dolfin_terminate()::sigaction'
       sigaction(SIGABRT, &act, NULL);
                                    ^
FEniCS/src/dolfin/dorsal_build_dir/dolfin/swig/modules/common/modulePYTHON
_wrap.cxx:4674:14: note: forward declaration of 'struct dolfin::dolfin_terminate()::sigaction'
       struct sigaction act;

Comments (7)

  1. Chaffra Affouda reporter

    Thanks Jan,

    I tried that but that did not help. Looks like sigaction does not exist on MinGW. It's not present in my signal.h file. Does this hack seem sensible to you:

    #include <signal.h>
    
      namespace dolfin {
        void dolfin_terminate() noexcept
        {
          #ifdef __MINGW32__
          raise(SIGABRT);
          #else
          // Uninstall signal handlers of OpenMPI cluttering stderr
          struct sigaction act;
          memset(&act, 0, sizeof(act));
          act.sa_handler = SIG_IGN;
          sigaction(SIGABRT, &act, NULL);
          #endif
    
          // We don't bother with MPI_Abort. This would require taking care of
          // MPI state. We just assume mpirun catches SIGABRT and sends SIGTERM
          // to other ranks.
          std::abort();
        }
    
  2. Jan Blechta

    What about being consistent and use std::abort() while just omitting uninstallation of OpenMPI signal handler

    #include <signal.h>
    
      namespace dolfin {
        void dolfin_terminate() noexcept
        {
          // Uninstall signal handlers of OpenMPI cluttering stderr (does not work on MinGW)
          #ifndef __MINGW32__
          struct sigaction act;
          memset(&act, 0, sizeof(act));
          act.sa_handler = SIG_IGN;
          sigaction(SIGABRT, &act, NULL);
          #endif
    
          // We don't bother with MPI_Abort. This would require taking care of
          // MPI state. We just assume mpirun catches SIGABRT and sends SIGTERM
          // to other ranks.
          std::abort();
        }
    
  3. Log in to comment