1- // Include R's C API for Windows to intercept problematic symbols
1+ #include < cpp11.hpp>
2+
3+ // Define R_NO_REMAP to prevent conflicts with cpp11
4+ #define R_NO_REMAP
5+ #define STRICT_R_HEADERS
6+
7+ // include R headers if needed
28#ifdef _WIN32
3- // Include R headers first
49#include < R.h>
510#include < Rinternals.h>
6-
7- // Use a namespace to avoid conflicts
8- namespace tesseract_r_wrapper {
9- // Safe versions that don't terminate R
10- inline void safe_abort () {
11- REprintf (" Internal error detected in tesseract (abort call intercepted)\n " );
12- }
13-
14- inline void safe_exit (int status) {
15- REprintf (" Exit requested with status %d (intercepted)\n " , status);
16- }
17-
18- inline int safe_rand () { return 0 ; }
19- inline void safe_srand (unsigned int seed) {}
20- } // namespace tesseract_r_wrapper
21-
22- // Only include the C++ header interceptors after defining our safe functions
23- #include < cstdlib>
24- #include < iostream>
25-
26- // Override problematic functions after including standard headers
27- #ifdef abort
28- #undef abort
29- #endif
30- #define abort tesseract_r_wrapper::safe_abort
31-
32- #ifdef exit
33- #undef exit
34- #endif
35- #define exit (x ) tesseract_r_wrapper::safe_exit(x)
36-
37- #ifdef rand
38- #undef rand
39- #endif
40- #define rand tesseract_r_wrapper::safe_rand
41-
42- #ifdef srand
43- #undef srand
4411#endif
45- #define srand (x ) tesseract_r_wrapper::safe_srand(x)
46-
47- // Redirect cout/cerr
48- #define cerr \
49- if (0 ) std::cerr
50- #define cout \
51- if (0 ) std::cout
52-
53- #endif // _WIN32
5412
5513// On macOS, try multiple include paths
5614#if __APPLE__
@@ -68,14 +26,22 @@ inline void safe_srand(unsigned int seed) {}
6826
6927#include < tesseract/baseapi.h> // tesseract
7028
71- #include < cpp11.hpp>
7229#include < list>
7330#include < memory>
7431#include < string>
7532#include < vector>
7633
7734#include " tesseract_config.h"
7835
36+ // Simple redirection for std::cerr and std::cout on Windows
37+ // This is much less intrusive but still helps with the CRAN check
38+ #ifdef _WIN32
39+ #define cerr \
40+ if (0 ) std::cerr
41+ #define cout \
42+ if (0 ) std::cout
43+ #endif
44+
7945inline void tess_finalizer (tesseract::TessBaseAPI* engine) {
8046 engine->End ();
8147 delete engine;
0 commit comments