diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index 4b97840c2421be93df51798290e479f5e03803dc..ecb3e62cdd07f5de930d6dedfc8cebc81db7be01 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -253,6 +253,25 @@ size_t TessBaseAPI::getOpenCLDevice(void **data) { return 0; } +/** + * Writes the thresholded image to stderr as a PBM file on receipt of a + * SIGSEGV, SIGFPE, or SIGBUS signal. (Linux/Unix only). + */ +void TessBaseAPI::CatchSignals() { +#ifdef __linux__ + struct sigaction action; + memset(&action, 0, sizeof(action)); + action.sa_handler = &signal_exit; + action.sa_flags = SA_RESETHAND; + sigaction(SIGSEGV, &action, nullptr); + sigaction(SIGFPE, &action, nullptr); + sigaction(SIGBUS, &action, nullptr); +#else + // Warn API users that an implementation is needed. + tprintf("CatchSignals has no non-linux implementation!\n"); +#endif +} + /** * Set the name of the input file. Needed only for training and * loading a UNLV zone file. diff --git a/src/api/baseapi.h b/src/api/baseapi.h index 66d0718d41db5a641728190c448c9f66e11ac887..3724dd92c43c358346aaaff8a536e68772107817 100644 --- a/src/api/baseapi.h +++ b/src/api/baseapi.h @@ -107,6 +107,12 @@ class TESS_API TessBaseAPI { */ static size_t getOpenCLDevice(void **device); + /** + * Writes the thresholded image to stderr as a PBM file on receipt of a + * SIGSEGV, SIGFPE, or SIGBUS signal. (Linux/Unix only). + */ + static void CatchSignals(); + /** * Set the name of the input file. Needed for training and * reading a UNLV zone file, and for searchable PDF output. diff --git a/src/cutil/oldlist.cpp b/src/cutil/oldlist.cpp index 9882d2f345494c1bc1ff3e9cdb2f087a32171f3f..7a5f0416740693a24b74cfa032c802a68f222e6d 100644 --- a/src/cutil/oldlist.cpp +++ b/src/cutil/oldlist.cpp @@ -61,6 +61,19 @@ #include "errcode.h" // for ASSERT_HOST #include "structures.h" +/********************************************************************** + * c o p y f i r s t + * + * Do the appropriate kind a push operation to copy the first node from + * one list to another. + * + **********************************************************************/ + +#define copy_first(l1,l2) \ +(l2=push(l2, first_node(l1))) + + + /*---------------------------------------------------------------------- F u n c t i o n s ----------------------------------------------------------------------*/