mono-publib.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /**
  2. * \file
  3. */
  4. #ifndef __MONO_PUBLIB_H__
  5. #define __MONO_PUBLIB_H__
  6. /*
  7. * Minimal general purpose header for use in public mono header files.
  8. * We can't include config.h, so we use compiler-specific preprocessor
  9. * directives where needed.
  10. */
  11. #ifdef __cplusplus
  12. #define MONO_BEGIN_DECLS extern "C" {
  13. #define MONO_END_DECLS }
  14. #else
  15. #define MONO_BEGIN_DECLS /* nothing */
  16. #define MONO_END_DECLS /* nothing */
  17. #endif
  18. MONO_BEGIN_DECLS
  19. /* VS 2010 and later have stdint.h */
  20. #if defined(_MSC_VER)
  21. #if _MSC_VER < 1600
  22. typedef __int8 int8_t;
  23. typedef unsigned __int8 uint8_t;
  24. typedef __int16 int16_t;
  25. typedef unsigned __int16 uint16_t;
  26. typedef __int32 int32_t;
  27. typedef unsigned __int32 uint32_t;
  28. typedef __int64 int64_t;
  29. typedef unsigned __int64 uint64_t;
  30. #else
  31. #include <stdint.h>
  32. #endif
  33. #define MONO_API_EXPORT __declspec(dllexport)
  34. #define MONO_API_IMPORT __declspec(dllimport)
  35. #else
  36. #include <stdint.h>
  37. #if defined (__clang__) || defined (__GNUC__)
  38. #define MONO_API_EXPORT __attribute__ ((__visibility__ ("default")))
  39. #else
  40. #define MONO_API_EXPORT
  41. #endif
  42. #define MONO_API_IMPORT
  43. #endif /* end of compiler-specific stuff */
  44. #include <stdlib.h>
  45. #ifdef __cplusplus
  46. #define MONO_EXTERN_C extern "C"
  47. #else
  48. #define MONO_EXTERN_C /* nothing */
  49. #endif
  50. #if defined(MONO_DLL_EXPORT)
  51. #define MONO_API_NO_EXTERN_C MONO_API_EXPORT
  52. #elif defined(MONO_DLL_IMPORT)
  53. #define MONO_API_NO_EXTERN_C MONO_API_IMPORT
  54. #else
  55. #define MONO_API_NO_EXTERN_C /* nothing */
  56. #endif
  57. #define MONO_API MONO_EXTERN_C MONO_API_NO_EXTERN_C
  58. // extern "C" extern int c; // warning: duplicate 'extern' declaration specifier [-Wduplicate-decl-specifier]
  59. //
  60. // Therefore, remove extern on functions as always meaningless/redundant,
  61. // and provide MONO_API_DATA for data, that always has one and only one extern.
  62. #ifdef __cplusplus
  63. #define MONO_API_DATA MONO_API
  64. #else
  65. #define MONO_API_DATA extern MONO_API
  66. #endif
  67. typedef int32_t mono_bool;
  68. typedef uint8_t mono_byte;
  69. typedef mono_byte MonoBoolean;
  70. #ifdef _WIN32
  71. MONO_END_DECLS
  72. #include <wchar.h>
  73. typedef wchar_t mono_unichar2;
  74. MONO_BEGIN_DECLS
  75. #else
  76. typedef uint16_t mono_unichar2;
  77. #endif
  78. typedef uint32_t mono_unichar4;
  79. typedef void (*MonoFunc) (void* data, void* user_data);
  80. typedef void (*MonoHFunc) (void* key, void* value, void* user_data);
  81. MONO_API void mono_free (void *);
  82. #define MONO_ALLOCATOR_VTABLE_VERSION 1
  83. typedef struct {
  84. int version;
  85. void *(*malloc) (size_t size);
  86. void *(*realloc) (void *mem, size_t count);
  87. void (*free) (void *mem);
  88. void *(*calloc) (size_t count, size_t size);
  89. } MonoAllocatorVTable;
  90. MONO_API mono_bool
  91. mono_set_allocator_vtable (MonoAllocatorVTable* vtable);
  92. #define MONO_CONST_RETURN const
  93. /*
  94. * When embedding, you have to define MONO_ZERO_LEN_ARRAY before including any
  95. * other Mono header file if you use a different compiler from the one used to
  96. * build Mono.
  97. */
  98. #ifndef MONO_ZERO_LEN_ARRAY
  99. #ifdef __GNUC__
  100. #define MONO_ZERO_LEN_ARRAY 0
  101. #else
  102. #define MONO_ZERO_LEN_ARRAY 1
  103. #endif
  104. #endif
  105. #if defined (MONO_INSIDE_RUNTIME)
  106. #if defined (__CENTRINEL__)
  107. /* Centrinel is an analyzer that warns about raw pointer to managed objects
  108. * inside Mono.
  109. */
  110. #define MONO_RT_MANAGED_ATTR __CENTRINEL_MANAGED_ATTR
  111. #define MONO_RT_CENTRINEL_SUPPRESS __CENTRINEL_SUPPRESS_ATTR(1)
  112. #else
  113. #define MONO_RT_MANAGED_ATTR
  114. #define MONO_RT_CENTRINEL_SUPPRESS
  115. #endif
  116. #if defined (__clang__) || defined (__GNUC__)
  117. // attribute(deprecated(message)) was introduced in gcc 4.5.
  118. // attribute(deprecated)) was introduced in gcc 4.0.
  119. // Compare: https://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Function-Attributes.html
  120. // https://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/Function-Attributes.html
  121. // https://gcc.gnu.org/onlinedocs/gcc-4.5.0/gcc/Function-Attributes.html
  122. #if defined (__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
  123. #define MONO_RT_EXTERNAL_ONLY \
  124. __attribute__ ((__deprecated__ ("The mono runtime must not call this function."))) \
  125. MONO_RT_CENTRINEL_SUPPRESS
  126. #elif __GNUC__ >= 4
  127. #define MONO_RT_EXTERNAL_ONLY __attribute__ ((__deprecated__)) MONO_RT_CENTRINEL_SUPPRESS
  128. #else
  129. #define MONO_RT_EXTERNAL_ONLY MONO_RT_CENTRINEL_SUPPRESS
  130. #endif
  131. #if defined (__clang__) || (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
  132. // Pragmas for controlling diagnostics appear to be from gcc 4.2.
  133. // This is used in place of configure gcc -Werror=deprecated-declarations:
  134. // 1. To be portable across build systems.
  135. // 2. configure is very sensitive to compiler flags; they break autoconf's probes.
  136. // Though #2 can be mitigated by being late in configure.
  137. #pragma GCC diagnostic error "-Wdeprecated-declarations"
  138. #endif
  139. #else
  140. #define MONO_RT_EXTERNAL_ONLY MONO_RT_CENTRINEL_SUPPRESS
  141. #endif // clang or gcc
  142. #else
  143. #define MONO_RT_EXTERNAL_ONLY
  144. #define MONO_RT_MANAGED_ATTR
  145. #endif /* MONO_INSIDE_RUNTIME */
  146. #if defined (__clang__) || defined (__GNUC__)
  147. #define _MONO_DEPRECATED __attribute__ ((__deprecated__))
  148. #elif defined (_MSC_VER)
  149. #define _MONO_DEPRECATED __declspec (deprecated)
  150. #else
  151. #define _MONO_DEPRECATED
  152. #endif
  153. #define MONO_DEPRECATED MONO_API MONO_RT_EXTERNAL_ONLY _MONO_DEPRECATED
  154. MONO_END_DECLS
  155. #endif /* __MONO_PUBLIB_H__ */