From 26f05b11970fe4c6e0d3cc5730ef26053d843d42 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Tue, 21 May 2019 08:12:21 +0200 Subject: [PATCH] Remove SavePixForCrash and related code That debugging code uses very much memory and is no longer useful. text data bss dec hex filename 815 0 262144 262959 4032f src/ccutil/globaloc.o Remove also the function err_exit which was only used in ccmain/reject.cpp. Signed-off-by: Stefan Weil --- src/api/baseapi.cpp | 22 ----------------- src/api/baseapi.h | 6 ----- src/ccmain/reject.cpp | 7 ++---- src/ccutil/errcode.cpp | 1 - src/ccutil/globaloc.cpp | 55 ----------------------------------------- src/ccutil/globaloc.h | 8 ------ 6 files changed, 2 insertions(+), 97 deletions(-) diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index a29119fc..f22c0f82 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -65,7 +65,6 @@ #include "environ.h" // for l_uint8 #include "equationdetect.h" // for EquationDetect #include "errcode.h" // for ASSERT_HOST -#include "globaloc.h" // for SavePixForCrash, signal_exit #include "helpers.h" // for IntCastRounded, chomp_string #include "imageio.h" // for IFF_TIFF_G4, IFF_TIFF, IFF_TIFF_G3 #ifndef DISABLED_LEGACY_ENGINE @@ -254,25 +253,6 @@ 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. @@ -2027,7 +2007,6 @@ bool TessBaseAPI::Threshold(Pix** pix) { thresholder_->GetScaledEstimatedResolution(), estimated_res); } tesseract_->set_source_resolution(estimated_res); - SavePixForCrash(estimated_res, *pix); return true; } @@ -2124,7 +2103,6 @@ void TessBaseAPI::ClearResults() { delete paragraph_models_; paragraph_models_ = nullptr; } - SavePixForCrash(0, nullptr); } /** diff --git a/src/api/baseapi.h b/src/api/baseapi.h index 3724dd92..66d0718d 100644 --- a/src/api/baseapi.h +++ b/src/api/baseapi.h @@ -107,12 +107,6 @@ 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/ccmain/reject.cpp b/src/ccmain/reject.cpp index fc2d4142..1df83309 100644 --- a/src/ccmain/reject.cpp +++ b/src/ccmain/reject.cpp @@ -1,8 +1,7 @@ /********************************************************************** * File: reject.cpp (Formerly reject.c) * Description: Rejection functions used in tessedit - * Author: Phil Cheatle - * Created: Wed Sep 23 16:50:21 BST 1992 + * Author: Phil Cheatle * * (C) Copyright 1992, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -45,12 +44,10 @@ int16_t Tesseract::safe_dict_word(const WERD_RES *werd_res) { #include "reject.h" #include "control.h" #include "docqual.h" -#include "globaloc.h" // For err_exit. #include "helpers.h" #include "tesseractclass.h" - CLISTIZEH (STRING) CLISTIZE (STRING) /************************************************************************* @@ -161,7 +158,7 @@ void Tesseract::make_reject_map(WERD_RES *word, ROW *row, int16_t pass) { } } else { tprintf("BAD tessedit_reject_mode\n"); - err_exit(); + ASSERT_HOST("Fatal error encountered!" == nullptr); } if (tessedit_image_border > -1) diff --git a/src/ccutil/errcode.cpp b/src/ccutil/errcode.cpp index 43244a52..7789ca8e 100644 --- a/src/ccutil/errcode.cpp +++ b/src/ccutil/errcode.cpp @@ -74,7 +74,6 @@ const char *format, ... // special message case TESSLOG: return; //report only case TESSEXIT: - //err_exit(); case ABORT: #if !defined(NDEBUG) // Create a deliberate abnormal exit as the stack trace is more useful diff --git a/src/ccutil/globaloc.cpp b/src/ccutil/globaloc.cpp index 36475448..053dec40 100644 --- a/src/ccutil/globaloc.cpp +++ b/src/ccutil/globaloc.cpp @@ -2,7 +2,6 @@ * File: errcode.cpp (Formerly error.c) * Description: Generic error handler function * Author: Ray Smith - * Created: Tue May 1 16:28:39 BST 1990 * * (C) Copyright 1989, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,64 +17,10 @@ **********************************************************************/ #include "globaloc.h" -#include -#ifdef __linux__ -#include // For SYS_gettid. -#include // For syscall itself. -#endif #include "allheaders.h" #include "errcode.h" #include "tprintf.h" -// Size of thread-id array of pixes to keep in case of crash. -const int kMaxNumThreadPixes = 32768; - -static Pix* global_crash_pixes[kMaxNumThreadPixes]; - -void SavePixForCrash(int resolution, Pix* pix) { -#ifdef __linux__ -#ifndef ANDROID - int thread_id = syscall(SYS_gettid) % kMaxNumThreadPixes; -#else - int thread_id = gettid() % kMaxNumThreadPixes; -#endif - pixDestroy(&global_crash_pixes[thread_id]); - if (pix != nullptr) { - Pix* clone = pixClone(pix); - pixSetXRes(clone, resolution); - pixSetYRes(clone, resolution); - global_crash_pixes[thread_id] = clone; - } -#endif -} - -// CALL ONLY from a signal handler! Writes a crash image to stderr. -void signal_exit(int signal_code) { - tprintf("Received signal %d!\n", signal_code); -#ifdef __linux__ -#ifndef ANDROID - int thread_id = syscall(SYS_gettid) % kMaxNumThreadPixes; -#else - int thread_id = gettid() % kMaxNumThreadPixes; -#endif - if (global_crash_pixes[thread_id] != nullptr) { - fprintf(stderr, "Crash caused by image with resolution %d\n", - pixGetYRes(global_crash_pixes[thread_id])); - fprintf(stderr, "\n"); - pixWriteStreamPng(stderr, global_crash_pixes[thread_id], 0.0); - fprintf(stderr, "\n\n"); - } - // Raise an uncaught signal, so as to get a useful stack trace. - raise(SIGILL); -#else - abort(); -#endif -} - -void err_exit() { - ASSERT_HOST("Fatal error encountered!" == nullptr); -} - // TODO: remove empty function? void set_global_loc_code(int loc_code) { // global_loc_code = loc_code; diff --git a/src/ccutil/globaloc.h b/src/ccutil/globaloc.h index 67c760e1..a826c827 100644 --- a/src/ccutil/globaloc.h +++ b/src/ccutil/globaloc.h @@ -19,14 +19,6 @@ #ifndef GLOBALOC_H #define GLOBALOC_H -// Saves a clone of the given pix, and notes its resolution in thread-specific -// data, so that the image can be written prior to a crash. -struct Pix; -void SavePixForCrash(int resolution, Pix* pix); - -void signal_exit(int signal_code); - -void err_exit(); void set_global_loc_code(int loc_code);