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.
29 #define DLLEXPORT __declspec(dllexport)
42 /* MSVC doesn't have stdint.h and uses a different syntax for stdcall */
49 #define STDCALL __stdcall
51 #define STDCALL __attribute__((stdcall))
58 * Some functions that aren't available on WIN32
62 float my_sqrtf(float n
)
64 return (float) sqrt((double) n
);
68 char *my_strdup(const char *str
)
70 char *p
= malloc(strlen(str
) + 1);
76 void my_strfree(char *str
)
82 long long my_llabs(long long n
)
84 return n
< 0 ? -n
: n
;
89 unsigned long long ullong(unsigned long long n
)
91 return n
== ULLONG_MAX
? n
: 42;
97 * (var_int is used in MISC-TYPES.EXPAND.3 as well)
100 DLLEXPORT
char * dll_version
= "20120107";
102 /* TODO: look into signed char vs. unsigned char issue */
103 DLLEXPORT
char var_char
= -127;
104 DLLEXPORT
unsigned char var_unsigned_char
= 255;
105 DLLEXPORT
short var_short
= -32767;
106 DLLEXPORT
unsigned short var_unsigned_short
= 65535;
107 DLLEXPORT
int var_int
= -32767;
108 DLLEXPORT
unsigned int var_unsigned_int
= 65535;
109 DLLEXPORT
long var_long
= -2147483647L;
110 DLLEXPORT
unsigned long var_unsigned_long
= 4294967295UL;
111 DLLEXPORT
float var_float
= 42.0f
;
112 DLLEXPORT
double var_double
= 42.0;
113 DLLEXPORT
void * var_pointer
= NULL
;
114 DLLEXPORT
char * var_string
= "Hello, foreign world!";
116 DLLEXPORT
long long var_long_long
= -9223372036854775807LL;
117 DLLEXPORT
unsigned long long var_unsigned_long_long
= 18446744073709551615ULL;
119 DLLEXPORT
float float_max
= FLT_MAX
;
120 DLLEXPORT
float float_min
= FLT_MIN
;
121 DLLEXPORT
double double_max
= DBL_MAX
;
122 DLLEXPORT
double double_min
= DBL_MIN
;
129 int expect_char_sum(char (*f
)(char, char))
131 return f('a', 3) == 'd';
135 int expect_unsigned_char_sum(unsigned char (*f
)(unsigned char, unsigned char))
137 return f(UCHAR_MAX
-1, 1) == UCHAR_MAX
;
141 int expect_short_sum(short (*f
)(short a
, short b
))
143 return f(SHRT_MIN
+1, -1) == SHRT_MIN
;
147 int expect_unsigned_short_sum(unsigned short (*f
)(unsigned short,
150 return f(USHRT_MAX
-1, 1) == USHRT_MAX
;
153 /* used in MISC-TYPES.EXPAND.4 as well */
155 int expect_int_sum(int (*f
)(int, int))
157 return f(INT_MIN
+1, -1) == INT_MIN
;
161 int expect_unsigned_int_sum(unsigned int (*f
)(unsigned int, unsigned int))
163 return f(UINT_MAX
-1, 1) == UINT_MAX
;
167 int expect_long_sum(long (*f
)(long, long))
169 return f(LONG_MIN
+1, -1) == LONG_MIN
;
173 int expect_unsigned_long_sum(unsigned long (*f
)(unsigned long, unsigned long))
175 return f(ULONG_MAX
-1, 1) == ULONG_MAX
;
179 int expect_long_long_sum(long long (*f
)(long long, long long))
181 return f(LLONG_MIN
+1, -1) == LLONG_MIN
;
185 int expect_unsigned_long_long_sum (unsigned long long
186 (*f
)(unsigned long long, unsigned long long))
188 return f(ULLONG_MAX
-1, 1) == ULLONG_MAX
;
192 int expect_float_sum(float (*f
)(float, float))
194 /*printf("\n>>> FLOAT: %f <<<\n", f(20.0f, 22.0f));*/
195 return f(20.0f
, 22.0f
) == 42.0f
;
199 int expect_double_sum(double (*f
)(double, double))
201 /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/
202 return f(-20.0, -22.0) == -42.0;
206 int expect_long_double_sum(long double (*f
)(long double, long double))
208 /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/
209 return f(-20.0, -22.0) == -42.0;
213 int expect_pointer_sum(void* (*f
)(void*, int))
215 return f(NULL
, 0xDEAD) == (void *) 0xDEAD;
219 int expect_strcat(char* (*f
)(char*, char*))
221 char *ret
= f("Hello, ", "C world!");
222 int res
= strcmp(ret
, "Hello, C world!") == 0;
223 /* commented out as a quick fix on platforms that don't
224 foreign allocate in C malloc space. */
225 /*free(ret);*/ /* is this allowed? */
230 void pass_int_ref(void (*f
)(int*))
250 int check_enums(numeros one
, numeros two
, numeros three
, numeros four
,
251 numeros forty_one
, numeros forty_two
)
253 if (one
== ONE
&& two
== TWO
&& three
== THREE
&& four
== FOUR
&&
254 forty_one
== FORTY_ONE
&& forty_two
== FORTY_TWO
)
260 typedef enum { FALSE
, TRUE
} another_boolean
;
263 another_boolean
return_enum(int x
)
276 int equalequal(int a
, unsigned int b
)
278 return ((unsigned int) a
) == b
;
282 char bool_and(unsigned char a
, char b
)
288 unsigned long bool_xor(long a
, unsigned long b
)
290 return (a
&& !b
) || (!a
&& b
);
294 unsigned sizeof_bool(void)
296 return (unsigned) sizeof(_Bool
);
300 unsigned bool_to_unsigned(_Bool b
)
306 _Bool
unsigned_to_bool(unsigned u
)
312 * Test struct alignment issues. These comments assume the x86 gABI.
313 * Hopefully these tests will spot alignment issues in others archs
325 /* This struct's size should be 2 bytes */
332 struct s_s_ch the_s_s_ch
= { 2, { 1 } };
338 /* This one should be alignment should be the same as short's alignment. */
346 char yet_another_char
;
347 struct s_short a_s_short
; /* so this should be 2-byte aligned */
348 }; /* size: 6 bytes */
351 struct s_s_short the_s_s_short
= { 4, { 1, 2, 3 } };
357 /* This test will, among other things, check for the existence tail padding. */
360 char a_char
; /* 1 byte */
361 /* padding: 3 bytes */
362 double a_double
; /* 8 bytes */
363 char another_char
; /* 1 byte */
364 /* padding: 3 bytes */
365 }; /* total size: 16 bytes */
368 char yet_another_char
; /* 1 byte */
369 /* 3 bytes padding */
370 struct s_double a_s_double
; /* 16 bytes */
371 short a_short
; /* 2 byte */
372 /* 2 bytes padding */
373 }; /* total size: 24 bytes */
376 struct s_s_double the_s_s_double
= { 4, { 1, 2.0, 3 }, 5 };
381 struct s_s_s_double
{
382 short another_short
; /* 2 bytes */
383 /* 2 bytes padding */
384 struct s_s_double a_s_s_double
; /* 24 bytes */
385 char last_char
; /* 1 byte */
386 /* 3 bytes padding */
387 }; /* total size: 32 */
390 struct s_s_s_double the_s_s_s_double
= { 6, { 4, { 1, 2.0, 3 }, 5 }, 7 };
396 /* MacOSX ABI says: "The embedding alignment of the first element in a data
397 structure is equal to the element's natural alignment." and "For subsequent
398 elements that have a natural alignment greater than 4 bytes, the embedding
399 alignment is 4, unless the element is a vector." */
401 /* note: these rules will apply to the structure itself. So, unless it is
402 the first element of another structure, its alignment will be 4. */
404 /* the following offsets and sizes are specific to darwin/ppc32 */
407 double a_double
; /* 8 bytes (alignment 8) */
408 short a_short
; /* 2 bytes */
409 /* 6 bytes padding */
410 }; /* total size: 16 */
413 char a_char
; /* 1 byte */
414 /* 3 bytes padding */
415 struct s_double2 a_s_double2
; /* 16 bytes, alignment 4 */
416 short another_short
; /* 2 bytes */
417 /* 2 bytes padding */
418 }; /* total size: 24 bytes */
422 struct s_s_double2 the_s_s_double2
= { 3, { 1.0, 2 }, 4 };
428 /* Same as STRUCT.ALIGNMENT.5 but with long long. */
431 long long a_long_long
; /* 8 bytes (alignment 8) */
432 short a_short
; /* 2 bytes */
433 /* 6 bytes padding */
434 }; /* total size: 16 */
436 struct s_s_long_long
{
437 char a_char
; /* 1 byte */
438 /* 3 bytes padding */
439 struct s_long_long a_s_long_long
; /* 16 bytes, alignment 4 */
440 short a_short
; /* 2 bytes */
441 /* 2 bytes padding */
442 }; /* total size: 24 bytes */
446 struct s_s_long_long the_s_s_long_long
= { 3, { 1, 2 }, 4 };
452 /* Another test for Darwin's PPC32 ABI. */
455 struct s_double2 a_s_double2
; /* 16 bytes, alignment 8*/
456 short another_short
; /* 2 bytes */
457 /* 6 bytes padding */
458 }; /* total size: 24 */
460 struct s_s_s_double3
{
461 struct s_s_double3 a_s_s_double3
; /* 24 bytes */
462 char a_char
; /* 1 byte */
463 /* 7 bytes padding */
464 }; /* total size: 32 */
467 struct s_s_s_double3 the_s_s_s_double3
= { { { 1.0, 2 }, 3 }, 4 };
473 /* Same as STRUCT.ALIGNMENT.[56] but with unsigned long long. */
475 struct s_unsigned_long_long
{
476 unsigned long long an_unsigned_long_long
; /* 8 bytes (alignment 8) */
477 short a_short
; /* 2 bytes */
478 /* 6 bytes padding */
479 }; /* total size: 16 */
481 struct s_s_unsigned_long_long
{
482 char a_char
; /* 1 byte */
483 /* 3 bytes padding */
484 struct s_unsigned_long_long a_s_unsigned_long_long
; /* 16 bytes, align 4 */
485 short a_short
; /* 2 bytes */
486 /* 2 bytes padding */
487 }; /* total size: 24 bytes */
491 struct s_s_unsigned_long_long the_s_s_unsigned_long_long
= { 3, { 1, 2 }, 4 };
493 /* STRUCT.ALIGNMENT.x */
495 /* commented this test out because this is not standard C
496 and MSVC++ (or some versions of it at least) won't compile it. */
499 struct empty_struct {};
501 struct with_empty_struct {
502 struct empty_struct foo;
507 struct with_empty_struct the_with_empty_struct = { {}, 42 };
514 struct pair
{ int a
, b
; };
517 int pair_sum(struct pair p
)
523 int pair_pointer_sum(struct pair
*p
)
529 struct pair
make_pair(int a
, int b
)
531 return (struct pair
) { a
, b
};
535 struct pair
*alloc_pair(int a
, int b
)
537 struct pair
*p
= malloc(sizeof(struct pair
));
543 struct pair_plus_one
{
549 int pair_plus_one_sum(struct pair_plus_one p
)
551 return p
.p
.a
+ p
.p
.b
+ p
.c
;
555 int pair_plus_one_pointer_sum(struct pair_plus_one
*p
)
557 return p
->p
.a
+ p
->p
.b
+ p
->c
;
561 struct pair_plus_one
make_pair_plus_one(int a
, int b
, int c
)
563 return (struct pair_plus_one
) { { a
, b
}, c
};
567 struct pair_plus_one
*alloc_pair_plus_one(int a
, int b
, int c
)
569 struct pair_plus_one
*p
= malloc(sizeof(struct pair_plus_one
));
577 * DEFCFUN.NOARGS and DEFCFUN.NOOP
595 * (let ((rettype (find-type :long))
596 * (arg-types (n-random-types-no-ll 127)))
597 * (c-function rettype arg-types)
598 * (gen-function-test rettype arg-types))
601 DLLEXPORT
long sum_127_no_ll
602 (long a1
, unsigned long a2
, short a3
, unsigned short a4
, float a5
,
603 double a6
, unsigned long a7
, float a8
, unsigned char a9
, unsigned
604 short a10
, short a11
, unsigned long a12
, double a13
, long a14
,
605 unsigned int a15
, void* a16
, unsigned int a17
, unsigned short a18
,
606 long a19
, float a20
, void* a21
, float a22
, int a23
, int a24
, unsigned
607 short a25
, long a26
, long a27
, double a28
, unsigned char a29
, unsigned
608 int a30
, unsigned int a31
, int a32
, unsigned short a33
, unsigned int
609 a34
, void* a35
, double a36
, double a37
, long a38
, short a39
, unsigned
610 short a40
, long a41
, char a42
, long a43
, unsigned short a44
, void*
611 a45
, int a46
, unsigned int a47
, double a48
, unsigned char a49
,
612 unsigned char a50
, float a51
, int a52
, unsigned short a53
, double a54
,
613 short a55
, unsigned char a56
, unsigned long a57
, float a58
, float a59
,
614 float a60
, void* a61
, void* a62
, unsigned int a63
, unsigned long a64
,
615 char a65
, short a66
, unsigned short a67
, unsigned long a68
, void* a69
,
616 float a70
, double a71
, long a72
, unsigned long a73
, short a74
,
617 unsigned int a75
, unsigned short a76
, int a77
, unsigned short a78
,
618 char a79
, double a80
, short a81
, unsigned char a82
, float a83
, char
619 a84
, int a85
, double a86
, unsigned char a87
, int a88
, unsigned long
620 a89
, double a90
, short a91
, short a92
, unsigned int a93
, unsigned char
621 a94
, float a95
, long a96
, float a97
, long a98
, long a99
, int a100
, int
622 a101
, unsigned int a102
, char a103
, char a104
, unsigned short a105
,
623 unsigned int a106
, unsigned short a107
, unsigned short a108
, int a109
,
624 long a110
, char a111
, double a112
, unsigned int a113
, char a114
, short
625 a115
, unsigned long a116
, unsigned int a117
, short a118
, unsigned char
626 a119
, float a120
, void* a121
, double a122
, int a123
, long a124
, char
627 a125
, unsigned short a126
, float a127
)
629 return (long) a1
+ a2
+ a3
+ a4
+ ((long) a5
) + ((long) a6
) + a7
+
630 ((long) a8
) + a9
+ a10
+ a11
+ a12
+ ((long) a13
) + a14
+ a15
+
631 ((intptr_t) a16
) + a17
+ a18
+ a19
+ ((long) a20
) +
632 ((intptr_t) a21
) + ((long) a22
) + a23
+ a24
+ a25
+ a26
+ a27
+
633 ((long) a28
) + a29
+ a30
+ a31
+ a32
+ a33
+ a34
+ ((intptr_t) a35
) +
634 ((long) a36
) + ((long) a37
) + a38
+ a39
+ a40
+ a41
+ a42
+ a43
+ a44
+
635 ((intptr_t) a45
) + a46
+ a47
+ ((long) a48
) + a49
+ a50
+
636 ((long) a51
) + a52
+ a53
+ ((long) a54
) + a55
+ a56
+ a57
+ ((long) a58
) +
637 ((long) a59
) + ((long) a60
) + ((intptr_t) a61
) +
638 ((intptr_t) a62
) + a63
+ a64
+ a65
+ a66
+ a67
+ a68
+
639 ((intptr_t) a69
) + ((long) a70
) + ((long) a71
) + a72
+ a73
+ a74
+
640 a75
+ a76
+ a77
+ a78
+ a79
+ ((long) a80
) + a81
+ a82
+ ((long) a83
) +
641 a84
+ a85
+ ((long) a86
) + a87
+ a88
+ a89
+ ((long) a90
) + a91
+ a92
+
642 a93
+ a94
+ ((long) a95
) + a96
+ ((long) a97
) + a98
+ a99
+ a100
+ a101
+
643 a102
+ a103
+ a104
+ a105
+ a106
+ a107
+ a108
+ a109
+ a110
+ a111
+
644 ((long) a112
) + a113
+ a114
+ a115
+ a116
+ a117
+ a118
+ a119
+
645 ((long) a120
) + ((intptr_t) a121
) + ((long) a122
) + a123
+ a124
+
646 a125
+ a126
+ ((long) a127
);
652 * (let ((rettype (find-type :long-long))
653 * (arg-types (n-random-types 127)))
654 * (c-function rettype arg-types)
655 * (gen-function-test rettype arg-types))
658 DLLEXPORT
long long sum_127
659 (void* a1
, void* a2
, float a3
, unsigned long a4
, void* a5
, long long
660 a6
, double a7
, double a8
, unsigned short a9
, int a10
, long long a11
,
661 long a12
, short a13
, unsigned int a14
, long a15
, unsigned char a16
,
662 int a17
, double a18
, short a19
, short a20
, long long a21
, unsigned
663 int a22
, unsigned short a23
, short a24
, void* a25
, short a26
,
664 unsigned short a27
, unsigned short a28
, int a29
, long long a30
,
665 void* a31
, int a32
, unsigned long a33
, unsigned long a34
, void* a35
,
666 unsigned long long a36
, float a37
, int a38
, short a39
, void* a40
,
667 unsigned long long a41
, long long a42
, unsigned long a43
, unsigned
668 long a44
, unsigned long long a45
, unsigned long a46
, char a47
,
669 double a48
, long a49
, unsigned int a50
, int a51
, short a52
, void*
670 a53
, long a54
, unsigned long long a55
, int a56
, unsigned short a57
,
671 unsigned long long a58
, float a59
, void* a60
, float a61
, unsigned
672 short a62
, unsigned long a63
, float a64
, unsigned int a65
, unsigned
673 long long a66
, void* a67
, double a68
, unsigned long long a69
, double
674 a70
, double a71
, long long a72
, void* a73
, unsigned short a74
, long
675 a75
, void* a76
, short a77
, double a78
, long a79
, unsigned char a80
,
676 void* a81
, unsigned char a82
, long a83
, double a84
, void* a85
, int
677 a86
, double a87
, unsigned char a88
, double a89
, short a90
, long a91
,
678 int a92
, long a93
, double a94
, unsigned short a95
, unsigned int a96
,
679 int a97
, char a98
, long long a99
, double a100
, float a101
, unsigned
680 long a102
, short a103
, void* a104
, float a105
, long long a106
, int
681 a107
, long long a108
, long long a109
, double a110
, unsigned long
682 long a111
, double a112
, unsigned long a113
, char a114
, char a115
,
683 unsigned long a116
, short a117
, unsigned char a118
, unsigned char
684 a119
, int a120
, int a121
, float a122
, unsigned char a123
, unsigned
685 char a124
, double a125
, unsigned long long a126
, char a127
)
687 return (long long) ((intptr_t) a1
) + ((intptr_t) a2
) + ((long) a3
) +
688 a4
+ ((intptr_t) a5
) + a6
+ ((long) a7
) + ((long) a8
) + a9
+ a10
+
689 a11
+ a12
+ a13
+ a14
+ a15
+ a16
+ a17
+ ((long) a18
) + a19
+ a20
+
690 a21
+ a22
+ a23
+ a24
+ ((intptr_t) a25
) + a26
+ a27
+ a28
+ a29
+
691 a30
+ ((intptr_t) a31
) + a32
+ a33
+ a34
+ ((intptr_t) a35
) +
692 a36
+ ((long) a37
) + a38
+ a39
+ ((intptr_t) a40
) + a41
+ a42
+ a43
+
693 a44
+ a45
+ a46
+ a47
+ ((long) a48
) + a49
+ a50
+ a51
+ a52
+
694 ((intptr_t) a53
) + a54
+ a55
+ a56
+ a57
+ a58
+ ((long) a59
) +
695 ((intptr_t) a60
) + ((long) a61
) + a62
+ a63
+ ((long) a64
) + a65
+ a66
696 + ((intptr_t) a67
) + ((long) a68
) + a69
+ ((long) a70
) + ((long) a71
) +
697 a72
+ ((intptr_t) a73
) + a74
+ a75
+ ((intptr_t) a76
) + a77
+
698 ((long) a78
) + a79
+ a80
+ ((intptr_t) a81
) + a82
+ a83
+ ((long) a84
)
699 + ((intptr_t) a85
) + a86
+ ((long) a87
) + a88
+ ((long) a89
) + a90
+
700 a91
+ a92
+ a93
+ ((long) a94
) + a95
+ a96
+ a97
+ a98
+ a99
+
701 ((long) a100
) + ((long) a101
) + a102
+ a103
+ ((intptr_t) a104
) +
702 ((long) a105
) + a106
+ a107
+ a108
+ a109
+ ((long) a110
) + a111
+
703 ((long) a112
) + a113
+ a114
+ a115
+ a116
+ a117
+ a118
+ a119
+ a120
+
704 a121
+ ((long) a122
) + a123
+ a124
+ ((long) a125
) + a126
+ a127
;
708 * CALLBACKS.BFF.1 (cb-test :no-long-long t)
711 DLLEXPORT
long call_sum_127_no_ll
713 (unsigned long, void*, long, double, unsigned long, float, float,
714 int, unsigned int, double, double, double, void*, unsigned short,
715 unsigned short, void*, long, long, int, short, unsigned short,
716 unsigned short, char, long, void*, void*, char, unsigned char,
717 unsigned long, short, int, int, unsigned char, short, long, long,
718 void*, unsigned short, char, double, unsigned short, void*, short,
719 unsigned long, unsigned short, float, unsigned char, short, float,
720 short, char, unsigned long, unsigned long, char, float, long, void*,
721 short, float, unsigned int, float, unsigned int, double, unsigned int,
722 unsigned char, int, long, char, short, double, int, void*, char,
723 unsigned short, void*, unsigned short, void*, unsigned long, double,
724 void*, long, float, unsigned short, unsigned short, void*, float, int,
725 unsigned int, double, float, long, void*, unsigned short, float,
726 unsigned char, unsigned char, float, unsigned int, float, unsigned
727 short, double, unsigned short, unsigned long, unsigned int, unsigned
728 long, void*, unsigned char, char, char, unsigned short, unsigned long,
729 float, short, void*, long, unsigned short, short, double, short, int,
730 char, unsigned long, long, int, void*, double, unsigned char))
733 func(948223085, (void *) 803308438, -465723152, 20385,
734 219679466, -10035, 13915, -1193455756, 1265303699, 27935, -18478,
735 -10508, (void *) 215389089, 55561, 55472, (void *) 146070433,
736 -1040819989, -17851453, -1622662247, -19473, 20837, 30216, 79,
737 986800400, (void *) 390281604, (void *) 1178532858, 19, 117,
738 78337699, -5718, -991300738, 872160910, 184, 926, -1487245383,
739 1633973783, (void *) 33738609, 53985, -116, 31645, 27196, (void *)
740 145569903, -6960, 17252220, 47404, -10491, 88, -30438, -21212,
741 -1982, -16, 1175270, 7949380, -121, 8559, -432968526, (void *)
742 293455312, 11894, -8394, 142421516, -25758, 3422998, 4004,
743 15758212, 198, -1071899743, -1284904617, -11, -17219, -30039,
744 311589092, (void *) 541468577, 123, 63517, (void *) 1252504506,
745 39368, (void *) 10057868, 134781408, -7143, (void *) 72825877,
746 -1190798667, -30862, 63757, 14965, (void *) 802391252, 22008,
747 -517289619, 806091099, 1125, 451, -498145176, (void *) 55960931,
748 15379, 4629, 184, 254, 22532, 465856451, -1669, 49416, -16546,
749 2983, 4337541, 65292495, 39253529, (void *) 669025, 211, 85, -19,
750 24298, 65358, 16776, -29957, (void *) 124311, -163231228, 2610,
751 -7806, 26434, -21913, -753615541, 120, 358697932, -1198889034,
752 -2131350926, (void *) 3749492036, -13413, 17);
756 * CALLBACKS.BFF.2 (cb-test)
759 DLLEXPORT
long long call_sum_127
761 (short, char, void*, float, long, double, unsigned long long,
762 unsigned short, unsigned char, char, char, unsigned short, unsigned
763 long long, unsigned short, long long, unsigned short, unsigned long
764 long, unsigned char, unsigned char, unsigned long long, long long,
765 char, float, unsigned int, float, float, unsigned int, float, char,
766 unsigned char, long, long long, unsigned char, double, long,
767 double, unsigned int, unsigned short, long long, unsigned int, int,
768 unsigned long long, long, short, unsigned int, unsigned int,
769 unsigned long long, unsigned int, long, void*, unsigned char, char,
770 long long, unsigned short, unsigned int, float, unsigned char,
771 unsigned long, long long, float, long, float, int, float, unsigned
772 short, unsigned long long, short, unsigned long, long, char,
773 unsigned short, long long, short, double, void*, unsigned int,
774 char, unsigned int, void*, void*, unsigned char, void*, unsigned
775 short, unsigned char, long, void*, char, long, unsigned short,
776 unsigned char, double, unsigned long long, unsigned short, unsigned
777 short, unsigned int, long, char, long, char, short, unsigned short,
778 unsigned long, unsigned long, short, long long, long long, long
779 long, double, unsigned short, unsigned char, short, unsigned char,
780 long, long long, unsigned long long, unsigned int, unsigned long,
781 unsigned char, long long, unsigned char, unsigned long long,
782 double, unsigned char, long long, unsigned char, char, long long))
785 func(-8573, 14, (void *) 832601021, -32334, -1532040888,
786 -18478, 2793023182591311826, 2740, 230, 103, 97, 13121,
787 5112369026351511084, 7763, -8134147951003417418, 34348,
788 5776613699556468853, 19, 122, 1431603726926527625,
789 439503521880490337, -112, -21557, 1578969190, -22008, -4953,
790 2127745975, -7262, -6, 180, 226352974, -3928775366167459219, 134,
791 -17730, -1175042526, 23868, 3494181009, 57364,
792 3134876875147518682, 104531655, -1286882727, 803577887579693487,
793 1349268803, 24912, 3313099419, 3907347884, 1738833249233805034,
794 2794230885, 1008818752, (void *) 1820044575, 189, 61,
795 -931654560961745071, 57531, 3096859985, 10405, 220, 3631311224,
796 -8531370353478907668, 31258, 678896693, -32150, -1869057813,
797 -19877, 62841, 4161660185772906873, -23869, 4016251006, 610353435,
798 105, 47315, -1051054492535331660, 6846, -15163, (void *)
799 736672359, 2123928476, -122, 3859258652, (void *) 3923394833,
800 (void *) 1265031970, 161, (void *) 1993867800, 55056, 122,
801 1562112760, (void *) 866615125, -79, -1261399547, 31737, 254,
802 -31279, 5462649659172897980, 5202, 7644, 174224940, -337854382,
803 -45, -583502442, -37, -13266, 24520, 2198606699, 2890453969,
804 -8282, -2295716637858246075, -1905178488651598878,
805 -6384652209316714643, 14841, 35443, 132, 15524, 187, 2138878229,
806 -5153032566879951000, 9056545530140684207, 4124632010, 276167701,
807 56, -2307310370663738730, 66, 9113015627153789746, -9618, 167,
808 755753399701306200, 119, -28, -990561962725435433);
815 DLLEXPORT
double call_double26
816 (double (*f
)(double, double, double, double, double, double, double, double,
817 double, double, double, double, double, double, double, double,
818 double, double, double, double, double, double, double, double,
821 return f(3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14,
822 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14,
823 3.14, 3.14, 3.14, 3.14);
827 * DEFCFUN.DOUBLE26 and FUNCALL.DOUBLE26
831 double sum_double26(double a1
, double a2
, double a3
, double a4
, double a5
,
832 double a6
, double a7
, double a8
, double a9
, double a10
,
833 double a11
, double a12
, double a13
, double a14
, double a15
,
834 double a16
, double a17
, double a18
, double a19
, double a20
,
835 double a21
, double a22
, double a23
, double a24
, double a25
,
838 return a1
+ a2
+ a3
+ a4
+ a5
+ a6
+ a7
+ a8
+ a9
+ a10
+ a11
+ a12
+ a13
+
839 a14
+ a15
+ a16
+ a17
+ a18
+ a19
+ a20
+ a21
+ a22
+ a23
+ a24
+ a25
+
847 DLLEXPORT
float call_float26
848 (float (*f
)(float, float, float, float, float, float, float, float,
849 float, float, float, float, float, float, float, float,
850 float, float, float, float, float, float, float, float,
853 return f(5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
854 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
859 * DEFCFUN.FLOAT26 and FUNCALL.FLOAT26
863 float sum_float26(float a1
, float a2
, float a3
, float a4
, float a5
,
864 float a6
, float a7
, float a8
, float a9
, float a10
,
865 float a11
, float a12
, float a13
, float a14
, float a15
,
866 float a16
, float a17
, float a18
, float a19
, float a20
,
867 float a21
, float a22
, float a23
, float a24
, float a25
,
870 return a1
+ a2
+ a3
+ a4
+ a5
+ a6
+ a7
+ a8
+ a9
+ a10
+ a11
+ a12
+ a13
+
871 a14
+ a15
+ a16
+ a17
+ a18
+ a19
+ a20
+ a21
+ a22
+ a23
+ a24
+ a25
+
879 DLLEXPORT
int UPPERCASEINT1
= 12345;
880 DLLEXPORT
int UPPER_CASE_INT1
= 23456;
881 DLLEXPORT
int MiXeDCaSeInT1
= 34567;
882 DLLEXPORT
int MiXeD_CaSe_InT1
= 45678;
884 DLLEXPORT
int UPPERCASEINT2
= 12345;
885 DLLEXPORT
int UPPER_CASE_INT2
= 23456;
886 DLLEXPORT
int MiXeDCaSeInT2
= 34567;
887 DLLEXPORT
int MiXeD_CaSe_InT2
= 45678;
889 DLLEXPORT
int UPPERCASEINT3
= 12345;
890 DLLEXPORT
int UPPER_CASE_INT3
= 23456;
891 DLLEXPORT
int MiXeDCaSeInT3
= 34567;
892 DLLEXPORT
int MiXeD_CaSe_InT3
= 45678;
895 * FOREIGN-SYMBOL-POINTER.1
898 DLLEXPORT
int compare_against_abs(intptr_t p
)
900 return p
== (intptr_t) abs
;
904 * FOREIGN-SYMBOL-POINTER.2
907 DLLEXPORT
void xpto_fun() {}
910 int compare_against_xpto_fun(intptr_t p
)
912 return p
== (intptr_t) xpto_fun
;
916 * [DEFCFUN|FUNCALL].NAMESPACE.1
926 * FOREIGN-GLOBALS.NAMESPACE.*
929 DLLEXPORT
int ns_var
= 1;
936 int STDCALL
stdcall_fun(int a
, int b
, int c
)
942 * CALLBACKS.STDCALL.1
946 int call_stdcall_fun(int (STDCALL
*f
)(int, int, int))
953 /* Unlike the one above, this commented test below actually
954 * works. But, alas, it doesn't compile with -std=c99. */
958 int call_stdcall_fun(int __attribute__((stdcall)) (*f)(int, int, int))
961 register int ebx asm("%ebx");