Skip to content

Commit

Permalink
Use TESS_API for every public symbol. Public symbol is exported from …
Browse files Browse the repository at this point in the history
…the library. This also applies to unit test and training symbols. Users will be limited to public api, but set of exported symbols will be wider still.

Remove TESS_LOCAL.
Fix several symbol issues that made visible with these changes.

All build systems must set -fvisibility-hidden for *nix systems.
  • Loading branch information
egorpugin committed Dec 31, 2020
1 parent 4d817d0 commit c86325e
Show file tree
Hide file tree
Showing 116 changed files with 324 additions and 223 deletions.
12 changes: 6 additions & 6 deletions include/tesseract/baseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ class TESS_API TessBaseAPI {
protected:
/** Common code for setting the image. Returns true if Init has been called.
*/
TESS_LOCAL bool InternalSetImage();
bool InternalSetImage();

/**
* Run the thresholder to make the thresholded image. If pix is not nullptr,
Expand All @@ -748,7 +748,7 @@ class TESS_API TessBaseAPI {
* Find lines from the image making the BLOCK_LIST.
* @return 0 on success.
*/
TESS_LOCAL int FindLines();
int FindLines();

/** Delete the pageres and block list ready for a new page. */
void ClearResults();
Expand All @@ -758,20 +758,20 @@ class TESS_API TessBaseAPI {
* to ignore all BiDi smarts at that point.
* delete once you're done with it.
*/
TESS_LOCAL LTRResultIterator* GetLTRIterator();
LTRResultIterator* GetLTRIterator();

/**
* Return the length of the output text string, as UTF8, assuming
* one newline per line and one per block, with a terminator,
* and assuming a single character reject marker for each rejected character.
* Also return the number of recognized blobs in blob_count.
*/
TESS_LOCAL int TextLength(int* blob_count);
int TextLength(int* blob_count);

//// paragraphs.cpp ////////////////////////////////////////////////////
TESS_LOCAL void DetectParagraphs(bool after_text_recognition);
void DetectParagraphs(bool after_text_recognition);

TESS_LOCAL const PAGE_RES* GetPageRes() const {
const PAGE_RES* GetPageRes() const {
return page_res_;
}

Expand Down
2 changes: 1 addition & 1 deletion include/tesseract/ltrresultiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class TESS_API LTRResultIterator : public PageIterator {
};

// Class to iterate over the classifier choices for a single RIL_SYMBOL.
class ChoiceIterator {
class TESS_API ChoiceIterator {
public:
// Construction is from a LTRResultIterator that points to the symbol of
// interest. The ChoiceIterator allows a one-shot iteration over the
Expand Down
2 changes: 1 addition & 1 deletion include/tesseract/pageiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class TESS_API PageIterator {
* Sets up the internal data for iterating the blobs of a new word, then
* moves the iterator to the given offset.
*/
TESS_LOCAL void BeginWord(int offset);
void BeginWord(int offset);

/** Pointer to the page_res owned by the API. */
PAGE_RES* page_res_;
Expand Down
24 changes: 8 additions & 16 deletions include/tesseract/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,23 @@
//
///////////////////////////////////////////////////////////////////////

#ifndef TESSERACT_CCUTIL_PLATFORM_H_
#define TESSERACT_CCUTIL_PLATFORM_H_
#ifndef TESSERACT_PLATFORM_H_
#define TESSERACT_PLATFORM_H_

#if defined(_WIN32) || defined(__CYGWIN__)
#ifndef TESS_API
# if defined(_WIN32) || defined(__CYGWIN__)
# if defined(TESS_EXPORTS)
# define TESS_API __declspec(dllexport)
# elif defined(TESS_IMPORTS)
# define TESS_API __declspec(dllimport)
# else
# define TESS_API
# endif
# define TESS_LOCAL
#else
# if __GNUC__ >= 4
# if defined(TESS_EXPORTS) || defined(TESS_IMPORTS)
# else
# if defined(TESS_EXPORTS) || defined(TESS_IMPORTS)
# define TESS_API __attribute__((visibility("default")))
# define TESS_LOCAL __attribute__((visibility("hidden")))
# else
# define TESS_API
# define TESS_LOCAL
# endif
# else
# define TESS_API
# define TESS_LOCAL
# endif
# endif
#endif

#endif // TESSERACT_CCUTIL_PLATFORM_H_
#endif // TESSERACT_PLATFORM_H_
2 changes: 1 addition & 1 deletion include/tesseract/resultiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class TESS_API ResultIterator : public LTRResultIterator {
* it resets to the beginning of the paragraph instead of staying wherever
* resit might have pointed.
*/
TESS_LOCAL explicit ResultIterator(const LTRResultIterator& resit);
explicit ResultIterator(const LTRResultIterator& resit);

private:
/**
Expand Down
4 changes: 2 additions & 2 deletions include/tesseract/unichar.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ using char32 = signed int;
// a single Unicode character (stored as between 1 and 4 utf8 bytes) or
// multiple Unicode characters representing the NFKC expansion of a ligature
// such as fi, ffl etc. These are also stored as utf8.
class UNICHAR {
class TESS_API UNICHAR {
public:
UNICHAR() {
memset(chars, 0, UNICHAR_LEN);
Expand Down Expand Up @@ -105,7 +105,7 @@ class UNICHAR {
// int char_len = it.get_utf8(buf); buf[char_len] = '\0';
// tprintf("Char = %s\n", buf);
// }
class const_iterator {
class TESS_API const_iterator {
using CI = const_iterator;

public:
Expand Down
10 changes: 5 additions & 5 deletions src/arch/intsimdmatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GenericVector;
// NOTE that, although the subclasses execute on different SIMD hardware, no
// virtual methods are needed, as the constructor sets up everything that
// is required to allow the base class implementation to do all the work.
struct IntSimdMatrix {
struct TESS_API IntSimdMatrix {
// Computes a reshaped copy of the weight matrix w.
void Init(const GENERIC_2D_ARRAY<int8_t>& w,
std::vector<int8_t>& shaped_w,
Expand Down Expand Up @@ -115,12 +115,12 @@ struct IntSimdMatrix {
// Number of groups of inputs to be broadcast.
// num_input_groups_ = num_inputs_per_register_ / num_inputs_per_group_

static TESS_API const IntSimdMatrix* intSimdMatrix;
static const IntSimdMatrix* intSimdMatrix;
// Only available with NEON.
static TESS_API const IntSimdMatrix intSimdMatrixNEON;
static const IntSimdMatrix intSimdMatrixNEON;
// Only available with AVX2 / SSE.
static TESS_API const IntSimdMatrix intSimdMatrixAVX2;
static TESS_API const IntSimdMatrix intSimdMatrixSSE;
static const IntSimdMatrix intSimdMatrixAVX2;
static const IntSimdMatrix intSimdMatrixSSE;
};

} // namespace tesseract
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/equationdetect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ColPartition;
class ColPartitionGrid;
class ColPartitionSet;

class EquationDetect : public EquationDetectBase {
class TESS_API EquationDetect : public EquationDetectBase {
public:
EquationDetect(const char* equ_datapath,
const char* equ_language);
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/mutableiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Tesseract;
// ResultIterator adds text-specific methods for access to OCR output.
// MutableIterator adds access to internal data structures.

class MutableIterator : public ResultIterator {
class TESS_API MutableIterator : public ResultIterator {
public:
// See argument descriptions in ResultIterator()
MutableIterator(PAGE_RES* page_res, Tesseract* tesseract,
Expand Down
2 changes: 2 additions & 0 deletions src/ccmain/paragraphs.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class RowInfo {
// paragraphs - this is the actual list of PARA objects.
// models - the list of paragraph models referenced by the PARA objects.
// caller is responsible for deleting the models.
TESS_API
void DetectParagraphs(int debug_level,
std::vector<RowInfo> *row_infos,
GenericVector<PARA *> *row_owners,
Expand All @@ -98,6 +99,7 @@ void DetectParagraphs(int debug_level,
// saving the ParagraphModels in models. Caller owns the models.
// We use unicharset during the function to answer questions such as "is the
// first letter of this word upper case?"
TESS_API
void DetectParagraphs(int debug_level,
bool after_text_recognition,
const MutableIterator *block_start,
Expand Down
3 changes: 3 additions & 0 deletions src/ccmain/paragraphs_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ class UNICHARSET;
class WERD_CHOICE;

// Return whether the given word is likely to be a list item start word.
TESS_API
bool AsciiLikelyListItem(const STRING &word);

// Return the first Unicode Codepoint from werd[pos].
int UnicodeFor(const UNICHARSET *u, const WERD_CHOICE *werd, int pos);

// Set right word attributes given either a unicharset and werd or a utf8
// string.
TESS_API
void RightWordAttributes(const UNICHARSET *unicharset, const WERD_CHOICE *werd,
const STRING &utf8,
bool *is_list, bool *starts_idea, bool *ends_idea);

// Set left word attributes given either a unicharset and werd or a utf8 string.
TESS_API
void LeftWordAttributes(const UNICHARSET *unicharset, const WERD_CHOICE *werd,
const STRING &utf8,
bool *is_list, bool *starts_idea, bool *ends_idea);
Expand Down
2 changes: 1 addition & 1 deletion src/ccmain/tesseractclass.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct WordData {
using WordRecognizer = void (Tesseract::*)(const WordData&, WERD_RES**,
PointerVector<WERD_RES>*);

class Tesseract : public Wordrec {
class TESS_API Tesseract : public Wordrec {
public:
Tesseract();
~Tesseract() override;
Expand Down
6 changes: 6 additions & 0 deletions src/ccstruct/boxread.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const int kBoxReadBufSize = 1024;

// Open the boxfile based on the given image filename.
// Returns nullptr if the box file cannot be opened.
TESS_API
FILE* OpenBoxFile(const char* filename);

// Reads all boxes from the given filename.
Expand All @@ -51,6 +52,7 @@ bool ReadAllBoxes(int target_page, bool skip_blanks, const char* filename,
// continue_on_failure allows reading to continue even if an invalid box is
// encountered and will return true if it succeeds in reading some boxes.
// It otherwise gives up and returns false on encountering an invalid box.
TESS_API
bool ReadMemBoxes(int target_page, bool skip_blanks, const char* box_data,
bool continue_on_failure,
std::vector<TBOX>* boxes,
Expand All @@ -66,20 +68,24 @@ bool ReadMemBoxes(int target_page, bool skip_blanks, const char* box_data,
// for valid utf-8 and allows space or tab between fields.
// utf8_str is set with the unichar string, and bounding box with the box.
// If there are page numbers in the file, it reads them all.
TESS_API
bool ReadNextBox(int *line_number, FILE* box_file,
STRING* utf8_str, TBOX* bounding_box);
// As ReadNextBox above, but get a specific page number. (0-based)
// Use -1 to read any page number. Files without page number all
// read as if they are page 0.
TESS_API
bool ReadNextBox(int target_page, int *line_number, FILE* box_file,
STRING* utf8_str, TBOX* bounding_box);

// Parses the given box file string into a page_number, utf8_str, and
// bounding_box. Returns true on a successful parse.
TESS_API
bool ParseBoxFileStr(const char* boxfile_str, int* page_number,
STRING* utf8_str, TBOX* bounding_box);

// Creates a box file string from a unichar string, TBOX and page number.
TESS_API
void MakeBoxFileStr(const char* unichar_str, const TBOX& box, int page_num,
STRING* box_str);

Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/ccstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "ccutil.h" // for CCUtil

namespace tesseract {
class CCStruct : public CCUtil {
class TESS_API CCStruct : public CCUtil {
public:
CCStruct() = default;
~CCStruct() override;
Expand Down
8 changes: 8 additions & 0 deletions src/ccstruct/fontinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,34 @@ struct FontSet {
// are replaced.
class FontInfoTable : public GenericVector<FontInfo> {
public:
TESS_API // when you remove inheritance from GenericVector, move this on class level
FontInfoTable();
TESS_API
~FontInfoTable();

// Writes to the given file. Returns false in case of error.
TESS_API
bool Serialize(FILE* fp) const;
// Reads from the given file. Returns false in case of error.
// If swap is true, assumes a big/little-endian swap is needed.
TESS_API
bool DeSerialize(TFile* fp);

// Returns true if the given set of fonts includes one with the same
// properties as font_id.
TESS_API
bool SetContainsFontProperties(
int font_id, const GenericVector<ScoredFont>& font_set) const;
// Returns true if the given set of fonts includes multiple properties.
TESS_API
bool SetContainsMultipleFontProperties(
const GenericVector<ScoredFont>& font_set) const;

// Moves any non-empty FontSpacingInfo entries from other to this.
TESS_API
void MoveSpacingInfoFrom(FontInfoTable* other);
// Moves this to the target unicity table.
TESS_API
void MoveTo(UnicityTable<FontInfo>* target);
};

Expand Down
14 changes: 13 additions & 1 deletion src/ccstruct/imagedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct FloatWordFeature {
// The text transcription is the ground truth UTF-8 text for the image.
// Character boxes are optional and indicate the desired segmentation of
// the text into recognition units.
class ImageData {
class TESS_API ImageData {
public:
ImageData();
// Takes ownership of the pix.
Expand Down Expand Up @@ -213,19 +213,24 @@ class ImageData {
// A collection of ImageData that knows roughly how much memory it is using.
class DocumentData {
public:
TESS_API
explicit DocumentData(const STRING& name);
TESS_API
~DocumentData();

// Reads all the pages in the given lstmf filename to the cache. The reader
// is used to read the file.
TESS_API
bool LoadDocument(const char* filename, int start_page, int64_t max_memory,
FileReader reader);
// Sets up the document, without actually loading it.
void SetDocument(const char* filename, int64_t max_memory, FileReader reader);
// Writes all the pages to the given filename. Returns false on error.
TESS_API
bool SaveDocument(const char* filename, FileWriter writer);

// Adds the given page data to this document, counting up memory.
TESS_API
void AddPageToDocument(ImageData* page);

const STRING& document_name() const {
Expand Down Expand Up @@ -257,6 +262,7 @@ class DocumentData {
void LoadPageInBackground(int index);
// Returns a pointer to the page with the given index, modulo the total
// number of pages. Blocks until the background load is completed.
TESS_API
const ImageData* GetPage(int index);
// Returns true if the requested page is available, and provides a pointer,
// which may be nullptr if the document is empty. May block, even though it
Expand Down Expand Up @@ -325,7 +331,9 @@ class DocumentData {
// content.
class DocumentCache {
public:
TESS_API
explicit DocumentCache(int64_t max_memory);
TESS_API
~DocumentCache();

// Deletes all existing documents from the cache.
Expand All @@ -335,6 +343,7 @@ class DocumentCache {
}
// Adds all the documents in the list of filenames, counting memory.
// The reader is used to read the files.
TESS_API
bool LoadDocuments(const std::vector<STRING>& filenames,
CachingStrategy cache_strategy, FileReader reader);

Expand All @@ -358,16 +367,19 @@ class DocumentCache {
}
// Returns the total number of pages in an epoch. For CS_ROUND_ROBIN cache
// strategy, could take a long time.
TESS_API
int TotalPages();

private:
// Returns a page by serial number, selecting them in a round-robin fashion
// from all the documents. Highly disk-intensive, but doesn't need samples
// to be shuffled between files to begin with.
TESS_API
const ImageData* GetPageRoundRobin(int serial);
// Returns a page by serial number, selecting them in sequence from each file.
// Requires the samples to be shuffled between the files to give a random or
// uniform distribution of data. Less disk-intensive than GetPageRoundRobin.
TESS_API
const ImageData* GetPageSequential(int serial);

// Helper counts the number of adjacent cached neighbour documents_ of index
Expand Down
2 changes: 1 addition & 1 deletion src/ccstruct/linlsq.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace tesseract {

template <typename T> class GenericVector;

class LLSQ {
class TESS_API LLSQ {
public:
LLSQ() { // constructor
clear(); // set to zeros
Expand Down
Loading

0 comments on commit c86325e

Please sign in to comment.