ffi_common.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* -----------------------------------------------------------------------
  2. ffi_common.h - Copyright (C) 2011, 2012, 2013 Anthony Green
  3. Copyright (C) 2007 Free Software Foundation, Inc
  4. Copyright (c) 1996 Red Hat, Inc.
  5. Common internal definitions and macros. Only necessary for building
  6. libffi.
  7. ----------------------------------------------------------------------- */
  8. #ifndef FFI_COMMON_H
  9. #define FFI_COMMON_H
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #include <fficonfig.h>
  14. /* Do not move this. Some versions of AIX are very picky about where
  15. this is positioned. */
  16. #ifdef __GNUC__
  17. # if HAVE_ALLOCA_H
  18. # include <alloca.h>
  19. # else
  20. /* mingw64 defines this already in malloc.h. */
  21. # ifndef alloca
  22. # define alloca __builtin_alloca
  23. # endif
  24. # endif
  25. # define MAYBE_UNUSED __attribute__((__unused__))
  26. #else
  27. # define MAYBE_UNUSED
  28. # if HAVE_ALLOCA_H
  29. # include <alloca.h>
  30. # else
  31. # ifdef _AIX
  32. # pragma alloca
  33. # else
  34. # ifndef alloca /* predefined by HP cc +Olibcalls */
  35. # ifdef _MSC_VER
  36. # define alloca _alloca
  37. # else
  38. char *alloca ();
  39. # endif
  40. # endif
  41. # endif
  42. # endif
  43. #endif
  44. /* Check for the existence of memcpy. */
  45. #if STDC_HEADERS
  46. # include <string.h>
  47. #else
  48. # ifndef HAVE_MEMCPY
  49. # define memcpy(d, s, n) bcopy ((s), (d), (n))
  50. # endif
  51. #endif
  52. #if defined(FFI_DEBUG)
  53. #include <stdio.h>
  54. #endif
  55. #ifdef FFI_DEBUG
  56. void ffi_assert(char *expr, char *file, int line);
  57. void ffi_stop_here(void);
  58. void ffi_type_test(ffi_type *a, char *file, int line);
  59. #define FFI_ASSERT(x) ((x) ? (void)0 : ffi_assert(#x, __FILE__,__LINE__))
  60. #define FFI_ASSERT_AT(x, f, l) ((x) ? 0 : ffi_assert(#x, (f), (l)))
  61. #define FFI_ASSERT_VALID_TYPE(x) ffi_type_test (x, __FILE__, __LINE__)
  62. #else
  63. #define FFI_ASSERT(x)
  64. #define FFI_ASSERT_AT(x, f, l)
  65. #define FFI_ASSERT_VALID_TYPE(x)
  66. #endif
  67. #define ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
  68. #define ALIGN_DOWN(v, a) (((size_t) (v)) & -a)
  69. /* Perform machine dependent cif processing */
  70. ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
  71. ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
  72. unsigned int nfixedargs, unsigned int ntotalargs);
  73. /* Extended cif, used in callback from assembly routine */
  74. typedef struct
  75. {
  76. ffi_cif *cif;
  77. void *rvalue;
  78. void **avalue;
  79. } extended_cif;
  80. /* Terse sized type definitions. */
  81. #if defined(_MSC_VER) || defined(__sgi) || defined(__SUNPRO_C)
  82. typedef unsigned char UINT8;
  83. typedef signed char SINT8;
  84. typedef unsigned short UINT16;
  85. typedef signed short SINT16;
  86. typedef unsigned int UINT32;
  87. typedef signed int SINT32;
  88. # ifdef _MSC_VER
  89. typedef unsigned __int64 UINT64;
  90. typedef signed __int64 SINT64;
  91. # else
  92. # include <inttypes.h>
  93. typedef uint64_t UINT64;
  94. typedef int64_t SINT64;
  95. # endif
  96. #else
  97. typedef unsigned int UINT8 __attribute__((__mode__(__QI__)));
  98. typedef signed int SINT8 __attribute__((__mode__(__QI__)));
  99. typedef unsigned int UINT16 __attribute__((__mode__(__HI__)));
  100. typedef signed int SINT16 __attribute__((__mode__(__HI__)));
  101. typedef unsigned int UINT32 __attribute__((__mode__(__SI__)));
  102. typedef signed int SINT32 __attribute__((__mode__(__SI__)));
  103. typedef unsigned int UINT64 __attribute__((__mode__(__DI__)));
  104. typedef signed int SINT64 __attribute__((__mode__(__DI__)));
  105. #endif
  106. typedef float FLOAT32;
  107. #ifndef __GNUC__
  108. #define __builtin_expect(x, expected_value) (x)
  109. #endif
  110. #define LIKELY(x) __builtin_expect(!!(x),1)
  111. #define UNLIKELY(x) __builtin_expect((x)!=0,0)
  112. #ifdef __cplusplus
  113. }
  114. #endif
  115. #endif