moved old instructions for external packages to top-level in preparation for nuking...
[CommonLispStat.git] / external / cffi.darcs / _darcs / pristine / tests / libtest.c
blob71095b15bc40a96a1994803b86c96ebbfaf123dc
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*-
3 * libtest.c --- auxiliary C lib for testing purposes
5 * Copyright (C) 2005-2007, Luis Oliveira <loliveira(@)common-lisp.net>
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use, copy,
11 * modify, merge, publish, distribute, sublicense, and/or sell copies
12 * of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #ifdef WIN32
29 #define DLLEXPORT __declspec(dllexport)
30 #else
31 #define DLLEXPORT
32 #endif
34 #include <stdio.h>
35 #include <limits.h>
36 #include <string.h>
37 #include <stdlib.h>
38 #include <math.h>
39 #include <float.h>
41 /* MSVC doesn't have stdint.h and uses a different syntax for stdcall */
42 #ifndef _MSC_VER
43 #include <stdint.h>
44 #define STDCALL __attribute__((stdcall))
45 #else
46 #define STDCALL __stdcall
47 #endif
50 * Some functions that aren't available on WIN32
53 DLLEXPORT
54 float my_sqrtf(float n)
56 return (float) sqrt((double) n);
59 DLLEXPORT
60 char *my_strdup(const char *str)
62 char *p = malloc(strlen(str) + 1);
63 strcpy(p, str);
64 return p;
67 DLLEXPORT
68 long long my_llabs(long long n)
70 return n < 0 ? -n : n;
74 * Foreign Globals
76 * (var_int is used in MISC-TYPES.EXPAND.3 as well)
79 DLLEXPORT char * dll_version = "20060907";
81 /* TODO: look into signed char vs. unsigned char issue */
82 DLLEXPORT char var_char = -127;
83 DLLEXPORT unsigned char var_unsigned_char = 255;
84 DLLEXPORT short var_short = -32767;
85 DLLEXPORT unsigned short var_unsigned_short = 65535;
86 DLLEXPORT int var_int = -32767;
87 DLLEXPORT unsigned int var_unsigned_int = 65535;
88 DLLEXPORT long var_long = -2147483647L;
89 DLLEXPORT unsigned long var_unsigned_long = 4294967295UL;
90 DLLEXPORT float var_float = 42.0f;
91 DLLEXPORT double var_double = 42.0;
92 DLLEXPORT void * var_pointer = NULL;
93 DLLEXPORT char * var_string = "Hello, foreign world!";
95 DLLEXPORT long long var_long_long = -9223372036854775807LL;
96 DLLEXPORT unsigned long long var_unsigned_long_long = 18446744073709551615ULL;
98 DLLEXPORT float float_max = FLT_MAX;
99 DLLEXPORT float float_min = FLT_MIN;
100 DLLEXPORT double double_max = DBL_MAX;
101 DLLEXPORT double double_min = DBL_MIN;
104 * Callbacks
107 DLLEXPORT
108 int expect_char_sum(char (*f)(char, char))
110 return f('a', 3) == 'd';
113 DLLEXPORT
114 int expect_unsigned_char_sum(unsigned char (*f)(unsigned char, unsigned char))
116 return f(UCHAR_MAX-1, 1) == UCHAR_MAX;
119 DLLEXPORT
120 int expect_short_sum(short (*f)(short a, short b))
122 return f(SHRT_MIN+1, -1) == SHRT_MIN;
125 DLLEXPORT
126 int expect_unsigned_short_sum(unsigned short (*f)(unsigned short,
127 unsigned short))
129 return f(USHRT_MAX-1, 1) == USHRT_MAX;
132 /* used in MISC-TYPES.EXPAND.4 as well */
133 DLLEXPORT
134 int expect_int_sum(int (*f)(int, int))
136 return f(INT_MIN+1, -1) == INT_MIN;
139 DLLEXPORT
140 int expect_unsigned_int_sum(unsigned int (*f)(unsigned int, unsigned int))
142 return f(UINT_MAX-1, 1) == UINT_MAX;
145 DLLEXPORT
146 int expect_long_sum(long (*f)(long, long))
148 return f(LONG_MIN+1, -1) == LONG_MIN;
151 DLLEXPORT
152 int expect_unsigned_long_sum(unsigned long (*f)(unsigned long, unsigned long))
154 return f(ULONG_MAX-1, 1) == ULONG_MAX;
157 DLLEXPORT
158 int expect_long_long_sum(long long (*f)(long long, long long))
160 return f(LLONG_MIN+1, -1) == LLONG_MIN;
163 DLLEXPORT
164 int expect_unsigned_long_long_sum (unsigned long long
165 (*f)(unsigned long long, unsigned long long))
167 return f(ULLONG_MAX-1, 1) == ULLONG_MAX;
170 DLLEXPORT
171 int expect_float_sum(float (*f)(float, float))
173 /*printf("\n>>> FLOAT: %f <<<\n", f(20.0f, 22.0f));*/
174 return f(20.0f, 22.0f) == 42.0f;
177 DLLEXPORT
178 int expect_double_sum(double (*f)(double, double))
180 /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/
181 return f(-20.0, -22.0) == -42.0;
184 DLLEXPORT
185 int expect_long_double_sum(long double (*f)(long double, long double))
187 /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/
188 return f(-20.0, -22.0) == -42.0;
191 DLLEXPORT
192 int expect_pointer_sum(void* (*f)(void*, int))
194 return f(NULL, 0xDEAD) == (void *) 0xDEAD;
197 DLLEXPORT
198 int expect_strcat(char* (*f)(char*, char*))
200 char *ret = f("Hello, ", "C world!");
201 int res = strcmp(ret, "Hello, C world!") == 0;
202 /* commented out as a quick fix on platforms that don't
203 foreign allocate in C malloc space. */
204 /*free(ret);*/ /* is this allowed? */
205 return res;
208 DLLEXPORT
209 void pass_int_ref(void (*f)(int*))
211 int x = 1984;
212 f(&x);
216 * Enums
219 typedef enum {
220 ONE = 1,
221 TWO,
222 THREE,
223 FOUR,
224 FORTY_ONE = 41,
225 FORTY_TWO
226 } numeros;
228 DLLEXPORT
229 int check_enums(numeros one, numeros two, numeros three, numeros four,
230 numeros forty_one, numeros forty_two)
232 if (one == ONE && two == TWO && three == THREE && four == FOUR &&
233 forty_one == FORTY_ONE && forty_two == FORTY_TWO)
234 return 1;
236 return 0;
239 typedef enum { FALSE, TRUE } another_boolean;
241 DLLEXPORT
242 another_boolean return_enum(int x)
244 if (x == 0)
245 return FALSE;
246 else
247 return TRUE;
251 * Booleans
254 DLLEXPORT
255 int equalequal(int a, unsigned int b)
257 return ((unsigned int) a) == b;
260 DLLEXPORT
261 char bool_and(unsigned char a, char b)
263 return a && b;
266 DLLEXPORT
267 unsigned long bool_xor(long a, unsigned long b)
269 return (a && !b) || (!a && b);
273 * Test struct alignment issues. These comments assume the x86 gABI.
274 * Hopefully these tests will spot alignment issues in others archs
275 * too.
279 * STRUCT.ALIGNMENT.1
282 struct s_ch {
283 char a_char;
286 /* This struct's size should be 2 bytes */
287 struct s_s_ch {
288 char another_char;
289 struct s_ch a_s_ch;
292 DLLEXPORT
293 struct s_s_ch the_s_s_ch = { 2, { 1 } };
296 * STRUCT.ALIGNMENT.2
299 /* This one should be alignment should be the same as short's alignment. */
300 struct s_short {
301 char a_char;
302 char another_char;
303 short a_short;
306 struct s_s_short {
307 char yet_another_char;
308 struct s_short a_s_short; /* so this should be 2-byte aligned */
309 }; /* size: 6 bytes */
311 DLLEXPORT
312 struct s_s_short the_s_s_short = { 4, { 1, 2, 3 } };
315 * STRUCT.ALIGNMENT.3
318 /* This test will, among other things, check for the existence tail padding. */
320 struct s_double {
321 char a_char; /* 1 byte */
322 /* padding: 3 bytes */
323 double a_double; /* 8 bytes */
324 char another_char; /* 1 byte */
325 /* padding: 3 bytes */
326 }; /* total size: 16 bytes */
328 struct s_s_double {
329 char yet_another_char; /* 1 byte */
330 /* 3 bytes padding */
331 struct s_double a_s_double; /* 16 bytes */
332 short a_short; /* 2 byte */
333 /* 2 bytes padding */
334 }; /* total size: 24 bytes */
336 DLLEXPORT
337 struct s_s_double the_s_s_double = { 4, { 1, 2.0, 3 }, 5 };
340 * STRUCT.ALIGNMENT.4
342 struct s_s_s_double {
343 short another_short; /* 2 bytes */
344 /* 2 bytes padding */
345 struct s_s_double a_s_s_double; /* 24 bytes */
346 char last_char; /* 1 byte */
347 /* 3 bytes padding */
348 }; /* total size: 32 */
350 DLLEXPORT
351 struct s_s_s_double the_s_s_s_double = { 6, { 4, { 1, 2.0, 3 }, 5 }, 7 };
354 * STRUCT.ALIGNMENT.5
357 /* MacOSX ABI says: "The embedding alignment of the first element in a data
358 structure is equal to the element's natural alignment." and "For subsequent
359 elements that have a natural alignment greater than 4 bytes, the embedding
360 alignment is 4, unless the element is a vector." */
362 /* note: these rules will apply to the structure itself. So, unless it is
363 the first element of another structure, its alignment will be 4. */
365 /* the following offsets and sizes are specific to darwin/ppc32 */
367 struct s_double2 {
368 double a_double; /* 8 bytes (alignment 8) */
369 short a_short; /* 2 bytes */
370 /* 6 bytes padding */
371 }; /* total size: 16 */
373 struct s_s_double2 {
374 char a_char; /* 1 byte */
375 /* 3 bytes padding */
376 struct s_double2 a_s_double2; /* 16 bytes, alignment 4 */
377 short another_short; /* 2 bytes */
378 /* 2 bytes padding */
379 }; /* total size: 24 bytes */
380 /* alignment: 4 */
382 DLLEXPORT
383 struct s_s_double2 the_s_s_double2 = { 3, { 1.0, 2 }, 4 };
386 * STRUCT.ALIGNMENT.6
389 /* Same as STRUCT.ALIGNMENT.5 but with long long. */
391 struct s_long_long {
392 long long a_long_long; /* 8 bytes (alignment 8) */
393 short a_short; /* 2 bytes */
394 /* 6 bytes padding */
395 }; /* total size: 16 */
397 struct s_s_long_long {
398 char a_char; /* 1 byte */
399 /* 3 bytes padding */
400 struct s_long_long a_s_long_long; /* 16 bytes, alignment 4 */
401 short a_short; /* 2 bytes */
402 /* 2 bytes padding */
403 }; /* total size: 24 bytes */
404 /* alignment: 4 */
406 DLLEXPORT
407 struct s_s_long_long the_s_s_long_long = { 3, { 1, 2 }, 4 };
410 * STRUCT.ALIGNMENT.7
413 /* Another test for Darwin's PPC32 ABI. */
415 struct s_s_double3 {
416 struct s_double2 a_s_double2; /* 16 bytes, alignment 8*/
417 short another_short; /* 2 bytes */
418 /* 6 bytes padding */
419 }; /* total size: 24 */
421 struct s_s_s_double3 {
422 struct s_s_double3 a_s_s_double3; /* 24 bytes */
423 char a_char; /* 1 byte */
424 /* 7 bytes padding */
425 }; /* total size: 32 */
427 DLLEXPORT
428 struct s_s_s_double3 the_s_s_s_double3 = { { { 1.0, 2 }, 3 }, 4 };
431 * STRUCT.ALIGNMENT.8
434 /* Same as STRUCT.ALIGNMENT.[56] but with unsigned long long. */
436 struct s_unsigned_long_long {
437 unsigned long long an_unsigned_long_long; /* 8 bytes (alignment 8) */
438 short a_short; /* 2 bytes */
439 /* 6 bytes padding */
440 }; /* total size: 16 */
442 struct s_s_unsigned_long_long {
443 char a_char; /* 1 byte */
444 /* 3 bytes padding */
445 struct s_unsigned_long_long a_s_unsigned_long_long; /* 16 bytes, align 4 */
446 short a_short; /* 2 bytes */
447 /* 2 bytes padding */
448 }; /* total size: 24 bytes */
449 /* alignment: 4 */
451 DLLEXPORT
452 struct s_s_unsigned_long_long the_s_s_unsigned_long_long = { 3, { 1, 2 }, 4 };
454 /* STRUCT.ALIGNMENT.x */
456 /* commented this test out because this is not standard C
457 and MSVC++ (or some versions of it at least) won't compile it. */
460 struct empty_struct {};
462 struct with_empty_struct {
463 struct empty_struct foo;
464 int an_int;
467 DLLEXPORT
468 struct with_empty_struct the_with_empty_struct = { {}, 42 };
472 * DEFCFUN.NOARGS and DEFCFUN.NOOP
475 DLLEXPORT
476 int noargs()
478 return 42;
481 DLLEXPORT
482 void noop()
484 return;
488 * DEFCFUN.BFF.1
490 * (let ((rettype (find-type :long))
491 * (arg-types (n-random-types-no-ll 127)))
492 * (c-function rettype arg-types)
493 * (gen-function-test rettype arg-types))
496 DLLEXPORT long sum_127_no_ll
497 (long a1, unsigned long a2, short a3, unsigned short a4, float a5,
498 double a6, unsigned long a7, float a8, unsigned char a9, unsigned
499 short a10, short a11, unsigned long a12, double a13, long a14,
500 unsigned int a15, void* a16, unsigned int a17, unsigned short a18,
501 long a19, float a20, void* a21, float a22, int a23, int a24, unsigned
502 short a25, long a26, long a27, double a28, unsigned char a29, unsigned
503 int a30, unsigned int a31, int a32, unsigned short a33, unsigned int
504 a34, void* a35, double a36, double a37, long a38, short a39, unsigned
505 short a40, long a41, char a42, long a43, unsigned short a44, void*
506 a45, int a46, unsigned int a47, double a48, unsigned char a49,
507 unsigned char a50, float a51, int a52, unsigned short a53, double a54,
508 short a55, unsigned char a56, unsigned long a57, float a58, float a59,
509 float a60, void* a61, void* a62, unsigned int a63, unsigned long a64,
510 char a65, short a66, unsigned short a67, unsigned long a68, void* a69,
511 float a70, double a71, long a72, unsigned long a73, short a74,
512 unsigned int a75, unsigned short a76, int a77, unsigned short a78,
513 char a79, double a80, short a81, unsigned char a82, float a83, char
514 a84, int a85, double a86, unsigned char a87, int a88, unsigned long
515 a89, double a90, short a91, short a92, unsigned int a93, unsigned char
516 a94, float a95, long a96, float a97, long a98, long a99, int a100, int
517 a101, unsigned int a102, char a103, char a104, unsigned short a105,
518 unsigned int a106, unsigned short a107, unsigned short a108, int a109,
519 long a110, char a111, double a112, unsigned int a113, char a114, short
520 a115, unsigned long a116, unsigned int a117, short a118, unsigned char
521 a119, float a120, void* a121, double a122, int a123, long a124, char
522 a125, unsigned short a126, float a127)
524 return (long) a1 + a2 + a3 + a4 + ((long) a5) + ((long) a6) + a7 +
525 ((long) a8) + a9 + a10 + a11 + a12 + ((long) a13) + a14 + a15 +
526 ((unsigned int) a16) + a17 + a18 + a19 + ((long) a20) +
527 ((unsigned int) a21) + ((long) a22) + a23 + a24 + a25 + a26 + a27 +
528 ((long) a28) + a29 + a30 + a31 + a32 + a33 + a34 + ((unsigned int) a35) +
529 ((long) a36) + ((long) a37) + a38 + a39 + a40 + a41 + a42 + a43 + a44 +
530 ((unsigned int) a45) + a46 + a47 + ((long) a48) + a49 + a50 +
531 ((long) a51) + a52 + a53 + ((long) a54) + a55 + a56 + a57 + ((long) a58) +
532 ((long) a59) + ((long) a60) + ((unsigned int) a61) +
533 ((unsigned int) a62) + a63 + a64 + a65 + a66 + a67 + a68 +
534 ((unsigned int) a69) + ((long) a70) + ((long) a71) + a72 + a73 + a74 +
535 a75 + a76 + a77 + a78 + a79 + ((long) a80) + a81 + a82 + ((long) a83) +
536 a84 + a85 + ((long) a86) + a87 + a88 + a89 + ((long) a90) + a91 + a92 +
537 a93 + a94 + ((long) a95) + a96 + ((long) a97) + a98 + a99 + a100 + a101 +
538 a102 + a103 + a104 + a105 + a106 + a107 + a108 + a109 + a110 + a111 +
539 ((long) a112) + a113 + a114 + a115 + a116 + a117 + a118 + a119 +
540 ((long) a120) + ((unsigned int) a121) + ((long) a122) + a123 + a124 +
541 a125 + a126 + ((long) a127);
545 * DEFCFUN.BFF.2
547 * (let ((rettype (find-type :long-long))
548 * (arg-types (n-random-types 127)))
549 * (c-function rettype arg-types)
550 * (gen-function-test rettype arg-types))
553 DLLEXPORT long long sum_127
554 (void* a1, void* a2, float a3, unsigned long a4, void* a5, long long
555 a6, double a7, double a8, unsigned short a9, int a10, long long a11,
556 long a12, short a13, unsigned int a14, long a15, unsigned char a16,
557 int a17, double a18, short a19, short a20, long long a21, unsigned
558 int a22, unsigned short a23, short a24, void* a25, short a26,
559 unsigned short a27, unsigned short a28, int a29, long long a30,
560 void* a31, int a32, unsigned long a33, unsigned long a34, void* a35,
561 unsigned long long a36, float a37, int a38, short a39, void* a40,
562 unsigned long long a41, long long a42, unsigned long a43, unsigned
563 long a44, unsigned long long a45, unsigned long a46, char a47,
564 double a48, long a49, unsigned int a50, int a51, short a52, void*
565 a53, long a54, unsigned long long a55, int a56, unsigned short a57,
566 unsigned long long a58, float a59, void* a60, float a61, unsigned
567 short a62, unsigned long a63, float a64, unsigned int a65, unsigned
568 long long a66, void* a67, double a68, unsigned long long a69, double
569 a70, double a71, long long a72, void* a73, unsigned short a74, long
570 a75, void* a76, short a77, double a78, long a79, unsigned char a80,
571 void* a81, unsigned char a82, long a83, double a84, void* a85, int
572 a86, double a87, unsigned char a88, double a89, short a90, long a91,
573 int a92, long a93, double a94, unsigned short a95, unsigned int a96,
574 int a97, char a98, long long a99, double a100, float a101, unsigned
575 long a102, short a103, void* a104, float a105, long long a106, int
576 a107, long long a108, long long a109, double a110, unsigned long
577 long a111, double a112, unsigned long a113, char a114, char a115,
578 unsigned long a116, short a117, unsigned char a118, unsigned char
579 a119, int a120, int a121, float a122, unsigned char a123, unsigned
580 char a124, double a125, unsigned long long a126, char a127)
582 return (long long) ((unsigned int) a1) + ((unsigned int) a2) + ((long) a3) +
583 a4 + ((unsigned int) a5) + a6 + ((long) a7) + ((long) a8) + a9 + a10 +
584 a11 + a12 + a13 + a14 + a15 + a16 + a17 + ((long) a18) + a19 + a20 +
585 a21 + a22 + a23 + a24 + ((unsigned int) a25) + a26 + a27 + a28 + a29 +
586 a30 + ((unsigned int) a31) + a32 + a33 + a34 + ((unsigned int) a35) +
587 a36 + ((long) a37) + a38 + a39 + ((unsigned int) a40) + a41 + a42 + a43 +
588 a44 + a45 + a46 + a47 + ((long) a48) + a49 + a50 + a51 + a52 +
589 ((unsigned int) a53) + a54 + a55 + a56 + a57 + a58 + ((long) a59) +
590 ((unsigned int) a60) + ((long) a61) + a62 + a63 + ((long) a64) + a65 + a66
591 + ((unsigned int) a67) + ((long) a68) + a69 + ((long) a70) + ((long) a71) +
592 a72 + ((unsigned int) a73) + a74 + a75 + ((unsigned int) a76) + a77 +
593 ((long) a78) + a79 + a80 + ((unsigned int) a81) + a82 + a83 + ((long) a84)
594 + ((unsigned int) a85) + a86 + ((long) a87) + a88 + ((long) a89) + a90 +
595 a91 + a92 + a93 + ((long) a94) + a95 + a96 + a97 + a98 + a99 +
596 ((long) a100) + ((long) a101) + a102 + a103 + ((unsigned int) a104) +
597 ((long) a105) + a106 + a107 + a108 + a109 + ((long) a110) + a111 +
598 ((long) a112) + a113 + a114 + a115 + a116 + a117 + a118 + a119 + a120 +
599 a121 + ((long) a122) + a123 + a124 + ((long) a125) + a126 + a127;
603 * CALLBACKS.BFF.1 (cb-test :no-long-long t)
606 DLLEXPORT long call_sum_127_no_ll
607 (long (*func)
608 (unsigned long, void*, long, double, unsigned long, float, float,
609 int, unsigned int, double, double, double, void*, unsigned short,
610 unsigned short, void*, long, long, int, short, unsigned short,
611 unsigned short, char, long, void*, void*, char, unsigned char,
612 unsigned long, short, int, int, unsigned char, short, long, long,
613 void*, unsigned short, char, double, unsigned short, void*, short,
614 unsigned long, unsigned short, float, unsigned char, short, float,
615 short, char, unsigned long, unsigned long, char, float, long, void*,
616 short, float, unsigned int, float, unsigned int, double, unsigned int,
617 unsigned char, int, long, char, short, double, int, void*, char,
618 unsigned short, void*, unsigned short, void*, unsigned long, double,
619 void*, long, float, unsigned short, unsigned short, void*, float, int,
620 unsigned int, double, float, long, void*, unsigned short, float,
621 unsigned char, unsigned char, float, unsigned int, float, unsigned
622 short, double, unsigned short, unsigned long, unsigned int, unsigned
623 long, void*, unsigned char, char, char, unsigned short, unsigned long,
624 float, short, void*, long, unsigned short, short, double, short, int,
625 char, unsigned long, long, int, void*, double, unsigned char))
627 return
628 func(948223085, (void *) 803308438, -465723152, 20385,
629 219679466, -10035, 13915, -1193455756, 1265303699, 27935, -18478,
630 -10508, (void *) 215389089, 55561, 55472, (void *) 146070433,
631 -1040819989, -17851453, -1622662247, -19473, 20837, 30216, 79,
632 986800400, (void *) 390281604, (void *) 1178532858, 19, 117,
633 78337699, -5718, -991300738, 872160910, 184, 926, -1487245383,
634 1633973783, (void *) 33738609, 53985, -116, 31645, 27196, (void *)
635 145569903, -6960, 17252220, 47404, -10491, 88, -30438, -21212,
636 -1982, -16, 1175270, 7949380, -121, 8559, -432968526, (void *)
637 293455312, 11894, -8394, 142421516, -25758, 3422998, 4004,
638 15758212, 198, -1071899743, -1284904617, -11, -17219, -30039,
639 311589092, (void *) 541468577, 123, 63517, (void *) 1252504506,
640 39368, (void *) 10057868, 134781408, -7143, (void *) 72825877,
641 -1190798667, -30862, 63757, 14965, (void *) 802391252, 22008,
642 -517289619, 806091099, 1125, 451, -498145176, (void *) 55960931,
643 15379, 4629, 184, 254, 22532, 465856451, -1669, 49416, -16546,
644 2983, 4337541, 65292495, 39253529, (void *) 669025, 211, 85, -19,
645 24298, 65358, 16776, -29957, (void *) 124311, -163231228, 2610,
646 -7806, 26434, -21913, -753615541, 120, 358697932, -1198889034,
647 -2131350926, (void *) 3749492036, -13413, 17);
651 * CALLBACKS.BFF.2 (cb-test)
654 DLLEXPORT long long call_sum_127
655 (long long (*func)
656 (short, char, void*, float, long, double, unsigned long long,
657 unsigned short, unsigned char, char, char, unsigned short, unsigned
658 long long, unsigned short, long long, unsigned short, unsigned long
659 long, unsigned char, unsigned char, unsigned long long, long long,
660 char, float, unsigned int, float, float, unsigned int, float, char,
661 unsigned char, long, long long, unsigned char, double, long,
662 double, unsigned int, unsigned short, long long, unsigned int, int,
663 unsigned long long, long, short, unsigned int, unsigned int,
664 unsigned long long, unsigned int, long, void*, unsigned char, char,
665 long long, unsigned short, unsigned int, float, unsigned char,
666 unsigned long, long long, float, long, float, int, float, unsigned
667 short, unsigned long long, short, unsigned long, long, char,
668 unsigned short, long long, short, double, void*, unsigned int,
669 char, unsigned int, void*, void*, unsigned char, void*, unsigned
670 short, unsigned char, long, void*, char, long, unsigned short,
671 unsigned char, double, unsigned long long, unsigned short, unsigned
672 short, unsigned int, long, char, long, char, short, unsigned short,
673 unsigned long, unsigned long, short, long long, long long, long
674 long, double, unsigned short, unsigned char, short, unsigned char,
675 long, long long, unsigned long long, unsigned int, unsigned long,
676 unsigned char, long long, unsigned char, unsigned long long,
677 double, unsigned char, long long, unsigned char, char, long long))
679 return
680 func(-8573, 14, (void *) 832601021, -32334, -1532040888,
681 -18478, 2793023182591311826, 2740, 230, 103, 97, 13121,
682 5112369026351511084, 7763, -8134147951003417418, 34348,
683 5776613699556468853, 19, 122, 1431603726926527625,
684 439503521880490337, -112, -21557, 1578969190, -22008, -4953,
685 2127745975, -7262, -6, 180, 226352974, -3928775366167459219, 134,
686 -17730, -1175042526, 23868, 3494181009, 57364,
687 3134876875147518682, 104531655, -1286882727, 803577887579693487,
688 1349268803, 24912, 3313099419, 3907347884, 1738833249233805034,
689 2794230885, 1008818752, (void *) 1820044575, 189, 61,
690 -931654560961745071, 57531, 3096859985, 10405, 220, 3631311224,
691 -8531370353478907668, 31258, 678896693, -32150, -1869057813,
692 -19877, 62841, 4161660185772906873, -23869, 4016251006, 610353435,
693 105, 47315, -1051054492535331660, 6846, -15163, (void *)
694 736672359, 2123928476, -122, 3859258652, (void *) 3923394833,
695 (void *) 1265031970, 161, (void *) 1993867800, 55056, 122,
696 1562112760, (void *) 866615125, -79, -1261399547, 31737, 254,
697 -31279, 5462649659172897980, 5202, 7644, 174224940, -337854382,
698 -45, -583502442, -37, -13266, 24520, 2198606699, 2890453969,
699 -8282, -2295716637858246075, -1905178488651598878,
700 -6384652209316714643, 14841, 35443, 132, 15524, 187, 2138878229,
701 -5153032566879951000, 9056545530140684207, 4124632010, 276167701,
702 56, -2307310370663738730, 66, 9113015627153789746, -9618, 167,
703 755753399701306200, 119, -28, -990561962725435433);
707 * CALLBACKS.DOUBLE26
710 DLLEXPORT double call_double26
711 (double (*f)(double, double, double, double, double, double, double, double,
712 double, double, double, double, double, double, double, double,
713 double, double, double, double, double, double, double, double,
714 double, double))
716 return f(3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14,
717 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14,
718 3.14, 3.14, 3.14, 3.14);
722 * DEFCFUN.DOUBLE26 and FUNCALL.DOUBLE26
725 DLLEXPORT
726 double sum_double26(double a1, double a2, double a3, double a4, double a5,
727 double a6, double a7, double a8, double a9, double a10,
728 double a11, double a12, double a13, double a14, double a15,
729 double a16, double a17, double a18, double a19, double a20,
730 double a21, double a22, double a23, double a24, double a25,
731 double a26)
733 return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 +
734 a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22 + a23 + a24 + a25 +
735 a26;
739 * CALLBACKS.FLOAT26
742 DLLEXPORT float call_float26
743 (float (*f)(float, float, float, float, float, float, float, float,
744 float, float, float, float, float, float, float, float,
745 float, float, float, float, float, float, float, float,
746 float, float))
748 return f(5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
749 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
750 5.0, 5.0, 5.0, 5.0);
754 * DEFCFUN.FLOAT26 and FUNCALL.FLOAT26
757 DLLEXPORT
758 float sum_float26(float a1, float a2, float a3, float a4, float a5,
759 float a6, float a7, float a8, float a9, float a10,
760 float a11, float a12, float a13, float a14, float a15,
761 float a16, float a17, float a18, float a19, float a20,
762 float a21, float a22, float a23, float a24, float a25,
763 float a26)
765 return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 +
766 a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22 + a23 + a24 + a25 +
767 a26;
771 * Symbol case.
774 DLLEXPORT int UPPERCASEINT1 = 12345;
775 DLLEXPORT int UPPER_CASE_INT1 = 23456;
776 DLLEXPORT int MiXeDCaSeInT1 = 34567;
777 DLLEXPORT int MiXeD_CaSe_InT1 = 45678;
779 DLLEXPORT int UPPERCASEINT2 = 12345;
780 DLLEXPORT int UPPER_CASE_INT2 = 23456;
781 DLLEXPORT int MiXeDCaSeInT2 = 34567;
782 DLLEXPORT int MiXeD_CaSe_InT2 = 45678;
784 DLLEXPORT int UPPERCASEINT3 = 12345;
785 DLLEXPORT int UPPER_CASE_INT3 = 23456;
786 DLLEXPORT int MiXeDCaSeInT3 = 34567;
787 DLLEXPORT int MiXeD_CaSe_InT3 = 45678;
790 * FOREIGN-SYMBOL-POINTER.1
793 DLLEXPORT int compare_against_abs(intptr_t p)
795 return p == (intptr_t) abs;
799 * FOREIGN-SYMBOL-POINTER.2
802 DLLEXPORT void xpto_fun() {}
804 DLLEXPORT
805 int compare_against_xpto_fun(intptr_t p)
807 return p == (intptr_t) xpto_fun;
811 * [DEFCFUN|FUNCALL].NAMESPACE.1
814 DLLEXPORT
815 int ns_function()
817 return 1;
821 * FOREIGN-GLOBALS.NAMESPACE.*
824 DLLEXPORT int ns_var = 1;
827 * DEFCFUN.STDCALL.1
830 DLLEXPORT
831 int STDCALL stdcall_fun(int a, int b, int c)
833 return a + b + c;
837 * CALLBACKS.STDCALL.1
840 DLLEXPORT
841 int call_stdcall_fun(int (STDCALL *f)(int, int, int))
843 int a = 42;
844 f(1, 2, 3);
845 return a;
848 /* Unlike the one above, this commented test below actually
849 * works. But, alas, it doesn't compile with -std=c99. */
852 DLLEXPORT
853 int call_stdcall_fun(int __attribute__((stdcall)) (*f)(int, int, int))
855 asm("pushl $42");
856 register int ebx asm("%ebx");
857 f(1, 2, 3);
858 asm("popl %ebx");
859 return ebx;
863 /* vim: ts=4 et