Merge pull request #4212 from BrzVlad/fix-ephemeron-leak
[mono.git] / mono / utils / mono-compiler.h
1 #ifndef __UTILS_MONO_COMPILER_H__
2 #define __UTILS_MONO_COMPILER_H__
3
4 /*
5  * This file includes macros used in the runtime to encapsulate different
6  * compiler behaviours.
7  */
8 #include <config.h>
9
10 #ifdef __GNUC__
11 #define MONO_ATTR_USED __attribute__ ((used))
12 #else
13 #define MONO_ATTR_USED
14 #endif
15
16 #ifdef __GNUC__
17 #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos) __attribute__((format(printf,fmt_pos,arg_pos)))
18 #else
19 #define MONO_ATTR_FORMAT_PRINTF(fmt_pos,arg_pos)
20 #endif
21
22 /* Deal with Microsoft C compiler differences */
23 #ifdef _MSC_VER
24
25 #include <math.h>
26
27 #if _MSC_VER < 1800 /* VS 2013 */
28 #define strtoull _strtoui64
29 #endif
30
31 #include <float.h>
32 #define trunc(x)        (((x) < 0) ? ceil((x)) : floor((x)))
33 #if _MSC_VER < 1800 /* VS 2013 */
34 #define isnan(x)        _isnan(x)
35 #define isinf(x)        (_isnan(x) ? 0 : (_fpclass(x) == _FPCLASS_NINF) ? -1 : (_fpclass(x) == _FPCLASS_PINF) ? 1 : 0)
36 #define isnormal(x)     _finite(x)
37 #endif
38
39 #define popen           _popen
40 #define pclose          _pclose
41
42 #include <direct.h>
43 #define mkdir(x)        _mkdir(x)
44
45 #define __func__ __FUNCTION__
46
47 #include <BaseTsd.h>
48 typedef SSIZE_T ssize_t;
49
50 /*
51  * SSIZE_MAX is not defined in MSVC, so define it here.
52  *
53  * These values come from MinGW64, and are public domain.
54  *
55  */
56 #ifndef SSIZE_MAX
57 #ifdef _WIN64
58 #define SSIZE_MAX _I64_MAX
59 #else
60 #define SSIZE_MAX INT_MAX
61 #endif
62 #endif
63
64 #endif /* _MSC_VER */
65
66 #ifdef _MSC_VER
67 // Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty.
68 #define MONO_EMPTY_SOURCE_FILE(x) void __mono_win32_ ## x ## _quiet_lnk4221 (void) {}
69 #else
70 #define MONO_EMPTY_SOURCE_FILE(x)
71 #endif
72
73 #if !defined(_MSC_VER) && !defined(PLATFORM_SOLARIS) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(MONOTOUCH) && HAVE_VISIBILITY_HIDDEN
74 #if MONO_LLVM_LOADED
75 #define MONO_LLVM_INTERNAL MONO_API
76 #else
77 #define MONO_LLVM_INTERNAL
78 #endif
79 #else
80 #define MONO_LLVM_INTERNAL 
81 #endif
82
83 /* Used to mark internal functions used by the profiler modules */
84 #define MONO_PROFILER_API MONO_API
85
86 #ifdef __GNUC__
87 #define MONO_ALWAYS_INLINE __attribute__((always_inline))
88 #elif defined(_MSC_VER)
89 #define MONO_ALWAYS_INLINE __forceinline
90 #else
91 #define MONO_ALWAYS_INLINE
92 #endif
93
94 #ifdef __GNUC__
95 #define MONO_NEVER_INLINE __attribute__((noinline))
96 #elif defined(_MSC_VER)
97 #define MONO_NEVER_INLINE __declspec(noinline)
98 #else
99 #define MONO_NEVER_INLINE
100 #endif
101
102 #ifdef __GNUC__
103 #define MONO_COLD __attribute__((cold))
104 #else
105 #define MONO_COLD
106 #endif
107
108 #if defined (__GNUC__) && defined (__GNUC_MINOR__) && defined (__GNUC_PATCHLEVEL__)
109 #define MONO_GNUC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
110 #endif
111
112 #endif /* __UTILS_MONO_COMPILER_H__*/
113