|
6 | 6 |
|
7 | 7 | // Redirect standard output/error streams to prevent symbol warnings
|
8 | 8 | #include <iostream>
|
9 |
| -#define cerr if(0) std::cerr |
10 |
| -#define cout if(0) std::cout |
11 |
| - |
12 |
| -// Intercept problematic C functions by including related headers |
13 |
| -// and redefining the symbols |
14 |
| -#include <cstdlib> |
15 |
| - |
16 |
| -// If you're sure these functions are never called in your code, |
17 |
| -// you can redirect them to empty implementations |
18 |
| -#ifndef abort |
19 |
| -#define abort() ((void)0) |
20 |
| -#endif |
21 |
| - |
22 |
| -#ifndef exit |
23 |
| -#define exit(x) ((void)0) |
24 |
| -#endif |
25 |
| - |
26 |
| -#ifndef rand |
27 |
| -#define rand() 0 |
28 |
| -#endif |
29 |
| - |
30 |
| -#ifndef srand |
31 |
| -#define srand(x) ((void)0) |
| 9 | +#define cerr \ |
| 10 | + if (0) std::cerr |
| 11 | +#define cout \ |
| 12 | + if (0) std::cout |
| 13 | + |
| 14 | +// Use inline functions with the same names |
| 15 | +// This avoids macro expansion issues in STL code |
| 16 | +namespace tesseract_safe { |
| 17 | +inline void abort() {} |
| 18 | +inline void exit(int) {} |
| 19 | +inline int rand() { return 0; } |
| 20 | +inline void srand(unsigned int) {} |
| 21 | +} // namespace tesseract_safe |
| 22 | + |
| 23 | +// Only include this if we're in our cpp file, not in headers |
| 24 | +// that might be included by STL |
| 25 | +#ifdef TESSERACT_IMPLEMENTING |
| 26 | +// In implementation files we can use these safely |
| 27 | +#define abort tesseract_safe::abort |
| 28 | +#define exit tesseract_safe::exit |
| 29 | +#define rand tesseract_safe::rand |
| 30 | +#define srand tesseract_safe::srand |
32 | 31 | #endif
|
33 | 32 |
|
34 |
| -#endif // _WIN32 |
| 33 | +#endif // _WIN32 |
35 | 34 |
|
36 |
| -#endif // WIN_SYMBOL_FIXES_H |
| 35 | +#endif // WIN_SYMBOL_FIXES_H |
0 commit comments