瀏覽代碼

HPCC-11954 Remove unused SIGNAL_TO_EXCEPTION code

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 11 年之前
父節點
當前提交
404e27044d
共有 2 個文件被更改,包括 0 次插入250 次删除
  1. 0 165
      system/jlib/jexcept.cpp
  2. 0 85
      system/jlib/jexcept.hpp

+ 0 - 165
system/jlib/jexcept.cpp

@@ -1334,168 +1334,3 @@ void PrintStackReport()
 #endif
     queryLogMsgManager()->flushQueue(10*1000);
 }
-
-
-#ifdef SIGNAL_TO_EXCEPTION
-
-/*static*/jmp_buf SignalToException::s_jmpbuf;
-/*static*/bool SignalToException::s_bUnixTrapHandlerSet = false;
-
-SignalToException::SignalToException()
-{ 
-    if (!s_bUnixTrapHandlerSet)
-        setUnixTrapHandler();
-    
-    memcpy(&m_old_jmpbuf,&s_jmpbuf,sizeof(jmp_buf)); 
-}
-
-SignalToException::~SignalToException()  
-{ 
-    memcpy(&s_jmpbuf,&m_old_jmpbuf,sizeof(jmp_buf)); 
-}
-
-
-/*static*/
-void SignalToException::UnixTrapHandler(int sig)
-{
-    longjmp(SignalToException::s_jmpbuf, sig);
-}
-
-/*static*/
-void SignalToException::setUnixTrapHandler()
-{
-    struct sigaction action;
-    sigemptyset(&action.sa_mask);
-    action.sa_flags = 0;
-    action.sa_handler = UnixTrapHandler;
-    
-    int signals[] = {SIGSEGV, SIGILL, SIGFPE, SIGPIPE, SIGSYS};
-    for (int i = 0; i < sizeof(signals)/sizeof(signals[0]); i++)
-        if ( sigaction(signals[i], &action, NULL) == -1)
-            perror("sigaction failed while setting UnixTrapHandler");
-        
-    s_bUnixTrapHandlerSet = true;
-}
-
-/*static*/
-void SignalToException::processSetJmpResult(int res)
-{
-    if (res != 0) 
-    {
-        StringBuffer buf("throwing SIG");
-        switch (res)
-        {
-        case SIGSEGV: buf.append("SEGV"); 
-            break;
-        case SIGILL : buf.append("ILL" ); 
-            break;
-        case SIGFPE : buf.append("FPE" ); 
-            break;
-        case SIGPIPE: buf.append("PIPE"); 
-            break;
-        case SIGSYS : buf.append("SYS" ); 
-            break;
-        default:      buf.append("NAL ").append(res); 
-            break;
-        }
-        buf.append(" as exception");
-        throw MakeStringException(res, "%s", buf.toCharArray());
-    }
-}
-
-#ifdef TEST_SIGNAL_TO_EXCEPTION
-
-int main(int argc, char**argv)
-{
-    
-    TRY 
-    {
-        TRY 
-        {
-            //generate SIGSEGV
-            int* p=0;
-            *p = 0;
-            cout << "Next stmt in inner block!" << endl;
-        }
-        CATCH(...)
-        {
-            cout << "inner catch (...)" << endl;
-        }
-        ENDCATCH;
-        
-        //generate SIGFPE
-        int p=0;
-        int q=2/p;
-        cout << "Next stmt in outer block!" << endl;
-    }
-    CATCH (char*)
-    {
-    }
-    AND_CATCH(...)
-    {
-        cout << "outer catch (...)" << endl;
-    }
-    END_CATCH
-        
-    return 0;
-}
-#endif //TEST_SIGNAL_TO_EXCEPTION
-#endif //SIGNAL_TO_EXCEPTION
-
-#ifdef _TEST
-
-void raise1()
-{
-    throw MakeStringException(-1,"test 1");
-}
-
-void raise2()
-{
-    throw MakeOsException(3);
-}
-
-class DefaultExceptionHandler
-{
-    unexpected_handler old;
-public:
-    static void handler()
-    {
-        try {
-            throw;
-        }
-        catch (IException *e) {
-            StringBuffer s;
-            e->errorMessage(s);
-            printf("Unhandled Exception (%d): %s\n",e->errorCode(),(const char *)s.toCharArray());
-            e->Release();
-        }   
-    }
-    DefaultExceptionHandler()  { old = set_terminate(handler); }
-    ~DefaultExceptionHandler() { set_terminate(old); }
-} _DefaultExceptionHandler;
-
-int main()
-{
-    try {
-        raise1();
-    }
-    catch (IException *e) {
-        StringBuffer s;
-        e->errorMessage(s);
-        printf("exception %d '%s'\n",e->errorCode(),(const char *)s.toCharArray());
-        e->Release();
-    }
-    try {
-        raise2();
-    }
-    catch (IException *e) {
-        StringBuffer s;
-        e->errorMessage(s);
-        printf("exception %d '%s'\n",e->errorCode(),(const char *)s.toCharArray());
-        e->Release();
-    }
-    raise1();
-    return 0;
-}
-
-#endif

+ 0 - 85
system/jlib/jexcept.hpp

@@ -142,90 +142,5 @@ void  jlib_decl PrintStackReport();
 #define throwError3(x,a,b,c)                    ThrowStringException(x, (x ## _Text), a, b, c)
 #define throwError4(x,a,b,c,d)                  ThrowStringException(x, (x ## _Text), a, b, c, d)
 
-#ifndef _WIN32
-#define SIGNAL_TO_EXCEPTION
-#endif
-
-#ifdef SIGNAL_TO_EXCEPTION
-#include <setjmp.h>
-/******************************************************************************
- * !! NOTE: the following only works for single threaded programs at present !!
- *
- * Visual C++ intercepts hardware traps like segmentation violation, 
- * floating point exception as C++ exceptions in catch(...).
- * Unfortunately, this does not work in Linux and causes program to 
- * trap.  This class attempts to implement Visual C++ functionality
- * using signal handlers, setjmp/longjmp and works in conjunction 
- * with the TRY, CATCH, CATCH_ALL, END_CATCH macros as defined below.
- *
- * The first invocation of constructor sets up a signal handler for 
- * SIGSEGV, SIGILL, SIGFPE, SIGPIPE and SIGSYS. TRY macro instantiates
- * an object of this class on stack, which saves the current value 
- * of static class member jmp_buf, s_jmpbuf, in data member m_old_jmpbuf
- * with the intention to restore it upon destruction.  The TRY macro
- * also invokes setjmp to save the CPU state in the static member. If
- * an exception occurs within the TRY block, the signal handler is invoked
- * and simply invokes longjmp on the static jmpbuf oblivious to the 
- * current context.  It so happens that this static jmpbuf member always 
- * points to the current TRY block.  The program control resumes at the 
- * setjmp call, that now returns signal number due to the longjmp call
- * from the signal handler.  This results in a C++ exception to be thrown
- * which gets intercepted in the corresponding catch block.
- */
-class jlib_thrown_decl SignalToException
-{
-public:
-   SignalToException();
-    virtual ~SignalToException();
-
-    static void processSetJmpResult(int res);
-    static jmp_buf s_jmpbuf;
-
-private:
-   static void UnixTrapHandler(int sig);
-   static void setUnixTrapHandler();
-
-    static bool s_bUnixTrapHandlerSet;
-   jmp_buf m_old_jmpbuf;
-};
-
-#define TRY \
-try \
-{\
-   SignalToException _signalToException;\
-   /* note that setjmp needs to be invoked in this context \
-     * or else it traps on longjmp from signal handler */\
-    SignalToException::processSetJmpResult( setjmp(SignalToException::s_jmpbuf) );
-
-#define CATCH   } catch
-#define AND_CATCH catch
-#define END_CATCH /*optional*/
-
-/* use these macros as follows:
- *
- * TRY { 
- * } 
- * CATCH(exception type) {
- * } 
- * AND_CATCH(exception type) {
- * }
- * ...
- * END_CATCH
- *
- */
-
-#else //SIGNAL_TO_EXCEPTION defined
-
-#ifndef __AFX_H__
-
-#define TRY       try
-#define CATCH     catch
-#define AND_CATCH catch
-#define END_CATCH /*optional*/
-
-#endif
-
-#endif //SIGNAL_TO_EXCEPTION not defined
-
 #endif