test-ffi-lib.c 5.4 KB

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