IsoString Filter::ToSource() const { IsoString s; if ( IsValid() ) { if ( IsSeparable() ) { s += "SeparableFilter {\n"; s += " name { " + Separable().Name().ToUTF8() + " }\n"; s += " row-vector { "; SeparableFilter::coefficient_vector H = Separable().RowFilter(); for ( int i = 0; i < H.Length(); ++i ) s.AppendFormat( ( H[i] < 0 ) ? "%.6f " : " %.6f ", H[i] ); s += "}\n"; s += " col-vector { "; SeparableFilter::coefficient_vector V = Separable().ColFilter(); for ( int i = 0; i < V.Length(); ++i ) s.AppendFormat( ( V[i] < 0 ) ? "%.6f " : " %.6f ", V[i] ); s += "}\n"; } else { s += "KernelFilter {\n"; s += " name { " + Kernel().Name().ToUTF8() + " }\n"; s += " coefficients {\n"; KernelFilter::coefficient_matrix M = Kernel().Coefficients(); for ( int i = 0; i < M.Rows(); ++i ) { s += " "; for ( int j = 0; ; ) { s.AppendFormat( ( M[i][j] < 0 ) ? "%.6f " : " %.6f ", M[i][j] ); if ( ++j == M.Cols() ) break; s += ' '; } s += '\n'; } s += " }\n"; } s += "}\n"; } return s; }
static void CriticalSignalHandler( int sig_num ) { sigset_t x; sigemptyset( &x ); sigaddset( &x, SIGSEGV ); sigaddset( &x, SIGBUS ); sigaddset( &x, SIGFPE ); sigaddset( &x, SIGILL ); sigaddset( &x, SIGPIPE ); //sigprocmask( SIG_UNBLOCK, &x, NULL ); pthread_sigmask( SIG_UNBLOCK, &x, NULL ); void* addrList[ STACK_DEPTH ]; size_t addrLen = backtrace( addrList, sizeof( addrList )/sizeof( void* ) ); char** symbolList = backtrace_symbols( addrList, addrLen ); IsoString details; if ( symbolList != NULL ) { if ( symbolList[0] != NULL ) { details = STACK_TRACE_TITLE + IsoString().Format( STACK_TRACE_HEADER, sig_num, symbolList[0] ); for ( size_t i = 1; i < addrLen; ++i ) { if ( symbolList[i] != NULL ) { IsoString addrOffsetStr; IsoString demangledFuncname = GetDemangledFunctionName( symbolList[i], addrOffsetStr ); details.AppendFormat( "%d: ", addrLen-i ); details += demangledFuncname; if ( !addrOffsetStr.IsEmpty() ) { details += "(+"; details += addrOffsetStr; details += ')'; } details += '\n'; } } details += STACK_TRACE_BOTTOM; fprintf( stderr, "%s", details.c_str() ); } // symbolList must be freed free( symbolList ); } switch ( sig_num ) { case SIGSEGV: throw EUnixSegmentationViolation( details ); case SIGBUS: throw EUnixBusError( details ); case SIGFPE: throw EUnixFloatingPointException( details ); case SIGILL: throw EUnixIllegalInstructionException( details ); case SIGPIPE: throw EUnixIBrokenPipeException( details ); default: throw UnixSignalException( sig_num, details ); } }