Skip to content

Commit 47a326b

Browse files
stweilzdenop
authored andcommitted
Use POSIX data types for external interfaces (#1358)
Replace the Tesseract specific data types in header files which are part of Debian package libtesseract-dev by POSIX data types. Update also matching cpp files. Signed-off-by: Stefan Weil <[email protected]>
1 parent c6afad0 commit 47a326b

34 files changed

+167
-167
lines changed

ccutil/genericvector.h

+19-19
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ class GenericVector {
346346
// vector are small enough that for efficiency it makes sense
347347
// to start with a larger initial size.
348348
static const int kDefaultVectorSize = 4;
349-
inT32 size_used_;
350-
inT32 size_reserved_;
349+
int32_t size_used_;
350+
int32_t size_reserved_;
351351
T* data_;
352352
TessCallback1<T>* clear_cb_;
353353
// Mutable because Run method is not const
@@ -536,20 +536,20 @@ class PointerVector : public GenericVector<T*> {
536536
// normal GenericVector of those.
537537
// Returns false in case of error.
538538
bool Serialize(FILE* fp) const {
539-
inT32 used = GenericVector<T*>::size_used_;
539+
int32_t used = GenericVector<T*>::size_used_;
540540
if (fwrite(&used, sizeof(used), 1, fp) != 1) return false;
541541
for (int i = 0; i < used; ++i) {
542-
inT8 non_null = GenericVector<T*>::data_[i] != NULL;
542+
int8_t non_null = GenericVector<T*>::data_[i] != NULL;
543543
if (fwrite(&non_null, sizeof(non_null), 1, fp) != 1) return false;
544544
if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
545545
}
546546
return true;
547547
}
548548
bool Serialize(TFile* fp) const {
549-
inT32 used = GenericVector<T*>::size_used_;
549+
int32_t used = GenericVector<T*>::size_used_;
550550
if (fp->FWrite(&used, sizeof(used), 1) != 1) return false;
551551
for (int i = 0; i < used; ++i) {
552-
inT8 non_null = GenericVector<T*>::data_[i] != NULL;
552+
int8_t non_null = GenericVector<T*>::data_[i] != NULL;
553553
if (fp->FWrite(&non_null, sizeof(non_null), 1) != 1) return false;
554554
if (non_null && !GenericVector<T*>::data_[i]->Serialize(fp)) return false;
555555
}
@@ -563,13 +563,13 @@ class PointerVector : public GenericVector<T*> {
563563
// Also needs T::T(), as new T is used in this function.
564564
// Returns false in case of error.
565565
bool DeSerialize(bool swap, FILE* fp) {
566-
inT32 reserved;
566+
int32_t reserved;
567567
if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false;
568568
if (swap) Reverse32(&reserved);
569569
GenericVector<T*>::reserve(reserved);
570570
truncate(0);
571571
for (int i = 0; i < reserved; ++i) {
572-
inT8 non_null;
572+
int8_t non_null;
573573
if (fread(&non_null, sizeof(non_null), 1, fp) != 1) return false;
574574
T* item = NULL;
575575
if (non_null) {
@@ -587,7 +587,7 @@ class PointerVector : public GenericVector<T*> {
587587
return true;
588588
}
589589
bool DeSerialize(TFile* fp) {
590-
inT32 reserved;
590+
int32_t reserved;
591591
if (!DeSerializeSize(fp, &reserved)) return false;
592592
GenericVector<T*>::reserve(reserved);
593593
truncate(0);
@@ -600,12 +600,12 @@ class PointerVector : public GenericVector<T*> {
600600
// retain the integrity of the stream, the caller must call some combination
601601
// of DeSerializeElement and DeSerializeSkip of the exact number returned in
602602
// *size, assuming a true return.
603-
static bool DeSerializeSize(TFile* fp, inT32* size) {
603+
static bool DeSerializeSize(TFile* fp, int32_t* size) {
604604
return fp->FReadEndian(size, sizeof(*size), 1) == 1;
605605
}
606606
// Reads and appends to the vector the next element of the serialization.
607607
bool DeSerializeElement(TFile* fp) {
608-
inT8 non_null;
608+
int8_t non_null;
609609
if (fp->FRead(&non_null, sizeof(non_null), 1) != 1) return false;
610610
T* item = NULL;
611611
if (non_null) {
@@ -623,7 +623,7 @@ class PointerVector : public GenericVector<T*> {
623623
}
624624
// Skips the next element of the serialization.
625625
static bool DeSerializeSkip(TFile* fp) {
626-
inT8 non_null;
626+
int8_t non_null;
627627
if (fp->FRead(&non_null, sizeof(non_null), 1) != 1) return false;
628628
if (non_null) {
629629
if (!T::SkipDeSerialize(fp)) return false;
@@ -906,7 +906,7 @@ bool GenericVector<T>::write(
906906
template <typename T>
907907
bool GenericVector<T>::read(
908908
tesseract::TFile* f, TessResultCallback2<bool, tesseract::TFile*, T*>* cb) {
909-
inT32 reserved;
909+
int32_t reserved;
910910
if (f->FReadEndian(&reserved, sizeof(reserved), 1) != 1) return false;
911911
reserve(reserved);
912912
if (f->FReadEndian(&size_used_, sizeof(size_used_), 1) != 1) return false;
@@ -947,7 +947,7 @@ bool GenericVector<T>::Serialize(tesseract::TFile* fp) const {
947947
// If swap is true, assumes a big/little-endian swap is needed.
948948
template <typename T>
949949
bool GenericVector<T>::DeSerialize(bool swap, FILE* fp) {
950-
inT32 reserved;
950+
int32_t reserved;
951951
if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false;
952952
if (swap) Reverse32(&reserved);
953953
reserve(reserved);
@@ -961,15 +961,15 @@ bool GenericVector<T>::DeSerialize(bool swap, FILE* fp) {
961961
}
962962
template <typename T>
963963
bool GenericVector<T>::DeSerialize(tesseract::TFile* fp) {
964-
inT32 reserved;
964+
int32_t reserved;
965965
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) return false;
966966
reserve(reserved);
967967
size_used_ = reserved;
968968
return fp->FReadEndian(data_, sizeof(T), size_used_) == size_used_;
969969
}
970970
template <typename T>
971971
bool GenericVector<T>::SkipDeSerialize(tesseract::TFile* fp) {
972-
inT32 reserved;
972+
int32_t reserved;
973973
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) return false;
974974
return fp->FRead(NULL, sizeof(T), reserved) == reserved;
975975
}
@@ -1001,7 +1001,7 @@ bool GenericVector<T>::SerializeClasses(tesseract::TFile* fp) const {
10011001
// If swap is true, assumes a big/little-endian swap is needed.
10021002
template <typename T>
10031003
bool GenericVector<T>::DeSerializeClasses(bool swap, FILE* fp) {
1004-
inT32 reserved;
1004+
int32_t reserved;
10051005
if (fread(&reserved, sizeof(reserved), 1, fp) != 1) return false;
10061006
if (swap) Reverse32(&reserved);
10071007
T empty;
@@ -1013,7 +1013,7 @@ bool GenericVector<T>::DeSerializeClasses(bool swap, FILE* fp) {
10131013
}
10141014
template <typename T>
10151015
bool GenericVector<T>::DeSerializeClasses(tesseract::TFile* fp) {
1016-
inT32 reserved;
1016+
int32_t reserved;
10171017
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) return false;
10181018
T empty;
10191019
init_to_size(reserved, empty);
@@ -1024,7 +1024,7 @@ bool GenericVector<T>::DeSerializeClasses(tesseract::TFile* fp) {
10241024
}
10251025
template <typename T>
10261026
bool GenericVector<T>::SkipDeSerializeClasses(tesseract::TFile* fp) {
1027-
inT32 reserved;
1027+
int32_t reserved;
10281028
if (fp->FReadEndian(&reserved, sizeof(reserved), 1) != 1) return false;
10291029
for (int i = 0; i < reserved; ++i) {
10301030
if (!T::SkipDeSerialize(fp)) return false;

ccutil/helpers.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ class TRand {
4242
public:
4343
TRand() : seed_(1) {}
4444
// Sets the seed to the given value.
45-
void set_seed(uinT64 seed) {
45+
void set_seed(uint64_t seed) {
4646
seed_ = seed;
4747
}
4848
// Sets the seed using a hash of a string.
4949
void set_seed(const std::string& str) {
5050
std::hash<std::string> hasher;
51-
set_seed(static_cast<uinT64>(hasher(str)));
51+
set_seed(static_cast<uint64_t>(hasher(str)));
5252
}
5353

5454
// Returns an integer in the range 0 to MAX_INT32.
55-
inT32 IntRand() {
55+
int32_t IntRand() {
5656
Iterate();
5757
return seed_ >> 33;
5858
}
@@ -73,7 +73,7 @@ class TRand {
7373
}
7474

7575
// The current value of the seed.
76-
uinT64 seed_;
76+
uint64_t seed_;
7777
};
7878

7979
} // namespace tesseract

ccutil/host.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ typedef unsigned char BOOL8;
6565
#define MAX_UINT32 0xffffffff
6666
#define MAX_FLOAT32 std::numeric_limits<float>::max()
6767

68-
#define MIN_INT8 static_cast<inT8>(0x80)
69-
#define MIN_INT16 static_cast<inT16>(0x8000)
70-
#define MIN_INT32 static_cast<inT32>(0x80000000)
68+
#define MIN_INT8 static_cast<int8_t>(0x80)
69+
#define MIN_INT16 static_cast<int16_t>(0x8000)
70+
#define MIN_INT32 static_cast<int32_t>(0x80000000)
7171
#define MIN_UINT8 0x00
7272
#define MIN_UINT16 0x0000
7373
#define MIN_UINT32 0x00000000

ccutil/memry.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// TODO(rays) further cleanup by redirecting calls to new and creating proper
2828
// constructors.
2929

30-
char *alloc_string(inT32 count) {
30+
char *alloc_string(int32_t count) {
3131
// Round up the amount allocated to a multiple of 4
3232
return static_cast<char*>(malloc((count + 3) & ~3));
3333
}
@@ -36,7 +36,7 @@ void free_string(char *string) {
3636
free(string);
3737
}
3838

39-
void *alloc_mem(inT32 count) {
39+
void *alloc_mem(int32_t count) {
4040
return malloc(static_cast<size_t>(count));
4141
}
4242

ccutil/memry.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
#include "host.h"
2525

2626
// allocate string
27-
extern char *alloc_string(inT32 count);
27+
extern char *alloc_string(int32_t count);
2828
// free a string.
2929
extern void free_string(char *string);
3030
// get some memory
31-
extern void *alloc_mem(inT32 count);
31+
extern void *alloc_mem(int32_t count);
3232
// free mem from alloc_mem
3333
extern void free_mem(void *oldchunk);
3434

ccutil/ocrclass.h

+17-17
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ typedef struct { /*single character */
8080
// characters sets will need to handle extended characters appropriately, but
8181
// *all* code needs to be prepared to receive UTF8 coded characters for
8282
// characters such as bullet and fancy quotes.
83-
uinT16 char_code; /*character itself */
84-
inT16 left; /*of char (-1) */
85-
inT16 right; /*of char (-1) */
86-
inT16 top; /*of char (-1) */
87-
inT16 bottom; /*of char (-1) */
88-
inT16 font_index; /*what font (0) */
89-
uinT8 confidence; /*0=perfect, 100=reject (0/100) */
90-
uinT8 point_size; /*of char, 72=i inch, (10) */
91-
inT8 blanks; /*no of spaces before this char (1) */
92-
uinT8 formatting; /*char formatting (0) */
83+
uint16_t char_code; /*character itself */
84+
int16_t left; /*of char (-1) */
85+
int16_t right; /*of char (-1) */
86+
int16_t top; /*of char (-1) */
87+
int16_t bottom; /*of char (-1) */
88+
int16_t font_index; /*what font (0) */
89+
uint8_t confidence; /*0=perfect, 100=reject (0/100) */
90+
uint8_t point_size; /*of char, 72=i inch, (10) */
91+
int8_t blanks; /*no of spaces before this char (1) */
92+
uint8_t formatting; /*char formatting (0) */
9393
} EANYCODE_CHAR; /*single character */
9494

9595
/**********************************************************************
@@ -114,14 +114,14 @@ typedef bool (*PROGRESS_FUNC)(int progress, int left, int right, int top,
114114

115115
class ETEXT_DESC { // output header
116116
public:
117-
inT16 count; /// chars in this buffer(0)
118-
inT16 progress; /// percent complete increasing (0-100)
117+
int16_t count; /// chars in this buffer(0)
118+
int16_t progress; /// percent complete increasing (0-100)
119119
/** Progress monitor covers word recognition and it does not cover layout
120120
* analysis.
121121
* See Ray comment in https://github.com/tesseract-ocr/tesseract/pull/27 */
122-
inT8 more_to_come; /// true if not last
123-
volatile inT8 ocr_alive; /// ocr sets to 1, HP 0
124-
inT8 err_code; /// for errcode use
122+
int8_t more_to_come; /// true if not last
123+
volatile int8_t ocr_alive; /// ocr sets to 1, HP 0
124+
int8_t err_code; /// for errcode use
125125
CANCEL_FUNC cancel; /// returns true to cancel
126126
PROGRESS_FUNC progress_callback; /// called whenever progress increases
127127
void* cancel_this; /// this or other data for cancel
@@ -143,9 +143,9 @@ class ETEXT_DESC { // output header
143143
}
144144

145145
// Sets the end time to be deadline_msecs milliseconds from now.
146-
void set_deadline_msecs(inT32 deadline_msecs) {
146+
void set_deadline_msecs(int32_t deadline_msecs) {
147147
gettimeofday(&end_time, NULL);
148-
inT32 deadline_secs = deadline_msecs / 1000;
148+
int32_t deadline_secs = deadline_msecs / 1000;
149149
end_time.tv_sec += deadline_secs;
150150
end_time.tv_usec += (deadline_msecs - deadline_secs * 1000) * 1000;
151151
if (end_time.tv_usec > 1000000) {

ccutil/params.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ bool ParamUtils::GetParamAsString(const char *name,
147147
member_params->int_params);
148148
if (ip) {
149149
char buf[128];
150-
snprintf(buf, sizeof(buf), "%d", inT32(*ip));
150+
snprintf(buf, sizeof(buf), "%d", int32_t(*ip));
151151
*value = buf;
152152
return true;
153153
}
@@ -177,7 +177,7 @@ void ParamUtils::PrintParams(FILE *fp, const ParamsVectors *member_params) {
177177
const ParamsVectors *vec = (v == 0) ? GlobalParams() : member_params;
178178
for (i = 0; i < vec->int_params.size(); ++i) {
179179
fprintf(fp, "%s\t%d\t%s\n", vec->int_params[i]->name_str(),
180-
(inT32)(*vec->int_params[i]), vec->int_params[i]->info_str());
180+
(int32_t)(*vec->int_params[i]), vec->int_params[i]->info_str());
181181
}
182182
for (i = 0; i < vec->bool_params.size(); ++i) {
183183
fprintf(fp, "%s\t%d\t%s\n", vec->bool_params[i]->name_str(),

ccutil/params.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -141,24 +141,24 @@ class Param {
141141

142142
class IntParam : public Param {
143143
public:
144-
IntParam(inT32 value, const char *name, const char *comment, bool init,
144+
IntParam(int32_t value, const char *name, const char *comment, bool init,
145145
ParamsVectors *vec) : Param(name, comment, init) {
146146
value_ = value;
147147
default_ = value;
148148
params_vec_ = &(vec->int_params);
149149
vec->int_params.push_back(this);
150150
}
151151
~IntParam() { ParamUtils::RemoveParam<IntParam>(this, params_vec_); }
152-
operator inT32() const { return value_; }
153-
void operator=(inT32 value) { value_ = value; }
154-
void set_value(inT32 value) { value_ = value; }
152+
operator int32_t() const { return value_; }
153+
void operator=(int32_t value) { value_ = value; }
154+
void set_value(int32_t value) { value_ = value; }
155155
void ResetToDefault() {
156156
value_ = default_;
157157
}
158158

159159
private:
160-
inT32 value_;
161-
inT32 default_;
160+
int32_t value_;
161+
int32_t default_;
162162
// Pointer to the vector that contains this param (not owened by this class).
163163
GenericVector<IntParam *> *params_vec_;
164164
};

ccutil/serialis.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ bool TFile::Open(const char* data, int size) {
6262
return true;
6363
}
6464

65-
bool TFile::Open(FILE* fp, inT64 end_offset) {
65+
bool TFile::Open(FILE* fp, int64_t end_offset) {
6666
offset_ = 0;
67-
inT64 current_pos = ftell(fp);
67+
int64_t current_pos = ftell(fp);
6868
if (end_offset < 0) {
6969
if (fseek(fp, 0, SEEK_END))
7070
return false;

ccutil/serialis.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class TFile {
6060
// From an existing memory buffer.
6161
bool Open(const char* data, int size);
6262
// From an open file and an end offset.
63-
bool Open(FILE* fp, inT64 end_offset);
63+
bool Open(FILE* fp, int64_t end_offset);
6464
// Sets the value of the swap flag, so that FReadEndian does the right thing.
6565
void set_swap(bool value) { swap_ = value; }
6666

0 commit comments

Comments
 (0)