From 78ced35a8b0a5b4c400f0d2088601e7f2e2500cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zdenko=20Podobn=C3=BD?= Date: Sun, 16 Jun 2019 21:08:13 +0200 Subject: [PATCH] restore CatchSignals to fix API compatibility --- src/api/baseapi.cpp | 19 +++++++++++++++++++ src/api/baseapi.h | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index 4b97840c..ecb3e62c 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 66d0718d..3724dd92 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.