Skip to content

Commit 6514479

Browse files
committed
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 <[email protected]>
1 parent c926bdb commit 6514479

File tree

6 files changed

+2
-97
lines changed

6 files changed

+2
-97
lines changed

src/api/baseapi.cpp

-22
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@
6565
#include "environ.h" // for l_uint8
6666
#include "equationdetect.h" // for EquationDetect
6767
#include "errcode.h" // for ASSERT_HOST
68-
#include "globaloc.h" // for SavePixForCrash, signal_exit
6968
#include "helpers.h" // for IntCastRounded, chomp_string
7069
#include "imageio.h" // for IFF_TIFF_G4, IFF_TIFF, IFF_TIFF_G3
7170
#ifndef DISABLED_LEGACY_ENGINE
@@ -254,25 +253,6 @@ size_t TessBaseAPI::getOpenCLDevice(void **data) {
254253
return 0;
255254
}
256255

257-
/**
258-
* Writes the thresholded image to stderr as a PBM file on receipt of a
259-
* SIGSEGV, SIGFPE, or SIGBUS signal. (Linux/Unix only).
260-
*/
261-
void TessBaseAPI::CatchSignals() {
262-
#ifdef __linux__
263-
struct sigaction action;
264-
memset(&action, 0, sizeof(action));
265-
action.sa_handler = &signal_exit;
266-
action.sa_flags = SA_RESETHAND;
267-
sigaction(SIGSEGV, &action, nullptr);
268-
sigaction(SIGFPE, &action, nullptr);
269-
sigaction(SIGBUS, &action, nullptr);
270-
#else
271-
// Warn API users that an implementation is needed.
272-
tprintf("CatchSignals has no non-linux implementation!\n");
273-
#endif
274-
}
275-
276256
/**
277257
* Set the name of the input file. Needed only for training and
278258
* loading a UNLV zone file.
@@ -2027,7 +2007,6 @@ bool TessBaseAPI::Threshold(Pix** pix) {
20272007
thresholder_->GetScaledEstimatedResolution(), estimated_res);
20282008
}
20292009
tesseract_->set_source_resolution(estimated_res);
2030-
SavePixForCrash(estimated_res, *pix);
20312010
return true;
20322011
}
20332012

@@ -2124,7 +2103,6 @@ void TessBaseAPI::ClearResults() {
21242103
delete paragraph_models_;
21252104
paragraph_models_ = nullptr;
21262105
}
2127-
SavePixForCrash(0, nullptr);
21282106
}
21292107

21302108
/**

src/api/baseapi.h

-6
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,6 @@ class TESS_API TessBaseAPI {
107107
*/
108108
static size_t getOpenCLDevice(void **device);
109109

110-
/**
111-
* Writes the thresholded image to stderr as a PBM file on receipt of a
112-
* SIGSEGV, SIGFPE, or SIGBUS signal. (Linux/Unix only).
113-
*/
114-
static void CatchSignals();
115-
116110
/**
117111
* Set the name of the input file. Needed for training and
118112
* reading a UNLV zone file, and for searchable PDF output.

src/ccmain/reject.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/**********************************************************************
22
* File: reject.cpp (Formerly reject.c)
33
* Description: Rejection functions used in tessedit
4-
* Author: Phil Cheatle
5-
* Created: Wed Sep 23 16:50:21 BST 1992
4+
* Author: Phil Cheatle
65
*
76
* (C) Copyright 1992, Hewlett-Packard Ltd.
87
** 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) {
4544
#include "reject.h"
4645
#include "control.h"
4746
#include "docqual.h"
48-
#include "globaloc.h" // For err_exit.
4947
#include "helpers.h"
5048

5149
#include "tesseractclass.h"
5250

53-
5451
CLISTIZEH (STRING) CLISTIZE (STRING)
5552

5653
/*************************************************************************
@@ -161,7 +158,7 @@ void Tesseract::make_reject_map(WERD_RES *word, ROW *row, int16_t pass) {
161158
}
162159
} else {
163160
tprintf("BAD tessedit_reject_mode\n");
164-
err_exit();
161+
ASSERT_HOST("Fatal error encountered!" == nullptr);
165162
}
166163

167164
if (tessedit_image_border > -1)

src/ccutil/errcode.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ const char *format, ... // special message
7474
case TESSLOG:
7575
return; //report only
7676
case TESSEXIT:
77-
//err_exit();
7877
case ABORT:
7978
#if !defined(NDEBUG)
8079
// Create a deliberate abnormal exit as the stack trace is more useful

src/ccutil/globaloc.cpp

-55
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* File: errcode.cpp (Formerly error.c)
33
* Description: Generic error handler function
44
* Author: Ray Smith
5-
* Created: Tue May 1 16:28:39 BST 1990
65
*
76
* (C) Copyright 1989, Hewlett-Packard Ltd.
87
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,64 +17,10 @@
1817
**********************************************************************/
1918

2019
#include "globaloc.h"
21-
#include <csignal>
22-
#ifdef __linux__
23-
#include <sys/syscall.h> // For SYS_gettid.
24-
#include <unistd.h> // For syscall itself.
25-
#endif
2620
#include "allheaders.h"
2721
#include "errcode.h"
2822
#include "tprintf.h"
2923

30-
// Size of thread-id array of pixes to keep in case of crash.
31-
const int kMaxNumThreadPixes = 32768;
32-
33-
static Pix* global_crash_pixes[kMaxNumThreadPixes];
34-
35-
void SavePixForCrash(int resolution, Pix* pix) {
36-
#ifdef __linux__
37-
#ifndef ANDROID
38-
int thread_id = syscall(SYS_gettid) % kMaxNumThreadPixes;
39-
#else
40-
int thread_id = gettid() % kMaxNumThreadPixes;
41-
#endif
42-
pixDestroy(&global_crash_pixes[thread_id]);
43-
if (pix != nullptr) {
44-
Pix* clone = pixClone(pix);
45-
pixSetXRes(clone, resolution);
46-
pixSetYRes(clone, resolution);
47-
global_crash_pixes[thread_id] = clone;
48-
}
49-
#endif
50-
}
51-
52-
// CALL ONLY from a signal handler! Writes a crash image to stderr.
53-
void signal_exit(int signal_code) {
54-
tprintf("Received signal %d!\n", signal_code);
55-
#ifdef __linux__
56-
#ifndef ANDROID
57-
int thread_id = syscall(SYS_gettid) % kMaxNumThreadPixes;
58-
#else
59-
int thread_id = gettid() % kMaxNumThreadPixes;
60-
#endif
61-
if (global_crash_pixes[thread_id] != nullptr) {
62-
fprintf(stderr, "Crash caused by image with resolution %d\n",
63-
pixGetYRes(global_crash_pixes[thread_id]));
64-
fprintf(stderr, "<Cut here>\n");
65-
pixWriteStreamPng(stderr, global_crash_pixes[thread_id], 0.0);
66-
fprintf(stderr, "\n<End cut>\n");
67-
}
68-
// Raise an uncaught signal, so as to get a useful stack trace.
69-
raise(SIGILL);
70-
#else
71-
abort();
72-
#endif
73-
}
74-
75-
void err_exit() {
76-
ASSERT_HOST("Fatal error encountered!" == nullptr);
77-
}
78-
7924
// TODO: remove empty function?
8025
void set_global_loc_code(int loc_code) {
8126
// global_loc_code = loc_code;

src/ccutil/globaloc.h

-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919
#ifndef GLOBALOC_H
2020
#define GLOBALOC_H
2121

22-
// Saves a clone of the given pix, and notes its resolution in thread-specific
23-
// data, so that the image can be written prior to a crash.
24-
struct Pix;
25-
void SavePixForCrash(int resolution, Pix* pix);
26-
27-
void signal_exit(int signal_code);
28-
29-
void err_exit();
3022

3123
void set_global_loc_code(int loc_code);
3224

0 commit comments

Comments
 (0)