test-ffi-lib.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* Copyright 2010-2011,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. #include <string.h>
  19. #include <libguile.h>
  20. void test_ffi_v_ (void);
  21. void test_ffi_v_ (void)
  22. {
  23. return;
  24. }
  25. void test_ffi_v_u8 (uint8_t a);
  26. void test_ffi_v_u8 (uint8_t a)
  27. {
  28. return;
  29. }
  30. void test_ffi_v_s64 (int64_t a);
  31. void test_ffi_v_s64 (int64_t a)
  32. {
  33. return;
  34. }
  35. int8_t test_ffi_s8_ (void);
  36. int8_t test_ffi_s8_ (void)
  37. {
  38. return -100;
  39. }
  40. int8_t test_ffi_s8_u8 (uint8_t a);
  41. int8_t test_ffi_s8_u8 (uint8_t a)
  42. {
  43. return -100 + a;
  44. }
  45. int8_t test_ffi_s8_s64 (int64_t a);
  46. int8_t test_ffi_s8_s64 (int64_t a)
  47. {
  48. return -100 + a;
  49. }
  50. uint8_t test_ffi_u8_ (void);
  51. uint8_t test_ffi_u8_ (void)
  52. {
  53. return 200;
  54. }
  55. uint8_t test_ffi_u8_u8 (uint8_t a);
  56. uint8_t test_ffi_u8_u8 (uint8_t a)
  57. {
  58. return 200 + a;
  59. }
  60. uint8_t test_ffi_u8_s64 (int64_t a);
  61. uint8_t test_ffi_u8_s64 (int64_t a)
  62. {
  63. return 200 + a;
  64. }
  65. int16_t test_ffi_s16_ (void);
  66. int16_t test_ffi_s16_ (void)
  67. {
  68. return -20000;
  69. }
  70. int16_t test_ffi_s16_u8 (uint8_t a);
  71. int16_t test_ffi_s16_u8 (uint8_t a)
  72. {
  73. return -20000 + a;
  74. }
  75. int16_t test_ffi_s16_s64 (int64_t a);
  76. int16_t test_ffi_s16_s64 (int64_t a)
  77. {
  78. return -20000 + a;
  79. }
  80. uint16_t test_ffi_u16_ (void);
  81. uint16_t test_ffi_u16_ (void)
  82. {
  83. return 40000;
  84. }
  85. uint16_t test_ffi_u16_u8 (uint8_t a);
  86. uint16_t test_ffi_u16_u8 (uint8_t a)
  87. {
  88. return 40000 + a;
  89. }
  90. uint16_t test_ffi_u16_s64 (int64_t a);
  91. uint16_t test_ffi_u16_s64 (int64_t a)
  92. {
  93. return 40000 + a;
  94. }
  95. int32_t test_ffi_s32_ (void);
  96. int32_t test_ffi_s32_ (void)
  97. {
  98. return -2000000000;
  99. }
  100. int32_t test_ffi_s32_u8 (uint8_t a);
  101. int32_t test_ffi_s32_u8 (uint8_t a)
  102. {
  103. return -2000000000 + a;
  104. }
  105. int32_t test_ffi_s32_s64 (int64_t a);
  106. int32_t test_ffi_s32_s64 (int64_t a)
  107. {
  108. return -2000000000 + a;
  109. }
  110. uint32_t test_ffi_u32_ (void);
  111. uint32_t test_ffi_u32_ (void)
  112. {
  113. return 4000000000U;
  114. }
  115. uint32_t test_ffi_u32_u8 (uint8_t a);
  116. uint32_t test_ffi_u32_u8 (uint8_t a)
  117. {
  118. return 4000000000U + a;
  119. }
  120. uint32_t test_ffi_u32_s64 (int64_t a);
  121. uint32_t test_ffi_u32_s64 (int64_t a)
  122. {
  123. return 4000000000U + a;
  124. }
  125. /* FIXME: use 64-bit literals */
  126. int64_t test_ffi_s64_ (void);
  127. int64_t test_ffi_s64_ (void)
  128. {
  129. return -2000000000;
  130. }
  131. int64_t test_ffi_s64_u8 (uint8_t a);
  132. int64_t test_ffi_s64_u8 (uint8_t a)
  133. {
  134. return -2000000000 + a;
  135. }
  136. int64_t test_ffi_s64_s64 (int64_t a);
  137. int64_t test_ffi_s64_s64 (int64_t a)
  138. {
  139. return -2000000000 + a;
  140. }
  141. uint64_t test_ffi_u64_ (void);
  142. uint64_t test_ffi_u64_ (void)
  143. {
  144. return 4000000000UL;
  145. }
  146. uint64_t test_ffi_u64_u8 (uint8_t a);
  147. uint64_t test_ffi_u64_u8 (uint8_t a)
  148. {
  149. return 4000000000UL + a;
  150. }
  151. uint64_t test_ffi_u64_s64 (int64_t a);
  152. uint64_t test_ffi_u64_s64 (int64_t a)
  153. {
  154. return 4000000000UL + a;
  155. }
  156. int64_t test_ffi_sum (int8_t a, int16_t b,
  157. int32_t c, int64_t d);
  158. int64_t test_ffi_sum (int8_t a, int16_t b,
  159. int32_t c, int64_t d)
  160. {
  161. return d + c + b + a;
  162. }
  163. int64_t test_ffi_sum_many (uint8_t a, uint16_t b,
  164. uint32_t c, uint64_t d,
  165. int8_t e, int16_t f,
  166. int32_t g, int64_t h,
  167. int8_t i, int16_t j,
  168. int32_t k, int64_t l);
  169. int64_t test_ffi_sum_many (uint8_t a, uint16_t b,
  170. uint32_t c, uint64_t d,
  171. int8_t e, int16_t f,
  172. int32_t g, int64_t h,
  173. int8_t i, int16_t j,
  174. int32_t k, int64_t l)
  175. {
  176. return l + k + j + i + h + g + f + e + d + c + b + a;
  177. }
  178. struct foo
  179. {
  180. int8_t a;
  181. int16_t b;
  182. int32_t c;
  183. int64_t d;
  184. };
  185. int64_t test_ffi_sum_struct (struct foo foo);
  186. int64_t test_ffi_sum_struct (struct foo foo)
  187. {
  188. return foo.d + foo.c + foo.b + foo.a;
  189. }
  190. void* test_ffi_memcpy (void *dest, void *src, int32_t n);
  191. void* test_ffi_memcpy (void *dest, void *src, int32_t n)
  192. {
  193. return memcpy (dest, src, n);
  194. }
  195. int test_ffi_callback_1 (int (*f) (int), int x);
  196. int test_ffi_callback_1 (int (*f) (int), int x)
  197. {
  198. return f (x) + 7;
  199. }
  200. double test_ffi_callback_2 (double (*f) (float, int, double),
  201. float x, int y, double z);
  202. double test_ffi_callback_2 (double (*f) (float, int, double),
  203. float x, int y, double z)
  204. {
  205. return f (x, y, z);
  206. }