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
2
8
#ifdef _WIN32
3
- // Include R headers first
4
9
#include < R.h>
5
10
#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
44
11
#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
54
12
55
13
// On macOS, try multiple include paths
56
14
#if __APPLE__
@@ -68,14 +26,22 @@ inline void safe_srand(unsigned int seed) {}
68
26
69
27
#include < tesseract/baseapi.h> // tesseract
70
28
71
- #include < cpp11.hpp>
72
29
#include < list>
73
30
#include < memory>
74
31
#include < string>
75
32
#include < vector>
76
33
77
34
#include " tesseract_config.h"
78
35
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
+
79
45
inline void tess_finalizer (tesseract::TessBaseAPI* engine) {
80
46
engine->End ();
81
47
delete engine;
0 commit comments