libtest.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*-
00002  *
00003  * libtest.c --- auxiliary C lib for testing purposes
00004  *
00005  * Copyright (C) 2005-2007, Luis Oliveira  <loliveira(@)common-lisp.net>
00006  *
00007  * Permission is hereby granted, free of charge, to any person
00008  * obtaining a copy of this software and associated documentation
00009  * files (the "Software"), to deal in the Software without
00010  * restriction, including without limitation the rights to use, copy,
00011  * modify, merge, publish, distribute, sublicense, and/or sell copies
00012  * of the Software, and to permit persons to whom the Software is
00013  * furnished to do so, subject to the following conditions:
00014  *
00015  * The above copyright notice and this permission notice shall be
00016  * included in all copies or substantial portions of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00019  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00021  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00022  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00023  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025  * DEALINGS IN THE SOFTWARE.
00026  */
00027 
00028 #ifdef WIN32
00029 #define DLLEXPORT __declspec(dllexport)
00030 #else
00031 #define DLLEXPORT
00032 #endif
00033 
00034 #include <stdio.h>
00035 #include <limits.h>
00036 #include <string.h>
00037 #include <stdlib.h>
00038 #include <math.h>
00039 #include <float.h>
00040 
00041 /* MSVC doesn't have stdint.h and uses a different syntax for stdcall */
00042 #ifndef _MSC_VER
00043 #include <stdint.h>
00044 #endif
00045 
00046 #ifdef WIN32
00047 #ifdef _MSC_VER
00048 #define STDCALL __stdcall
00049 #else
00050 #define STDCALL __attribute__((stdcall))
00051 #endif
00052 #else
00053 #define STDCALL
00054 #endif
00055 
00056 /*
00057  * Some functions that aren't available on WIN32
00058  */
00059 
00060 DLLEXPORT
00061 float my_sqrtf(float n)
00062 {
00063     return (float) sqrt((double) n);
00064 }
00065 
00066 DLLEXPORT
00067 char *my_strdup(const char *str)
00068 {
00069     char *p = malloc(strlen(str) + 1);
00070     strcpy(p, str);
00071     return p;
00072 }
00073 
00074 DLLEXPORT
00075 void my_strfree(const char *str)
00076 {
00077     free(str);
00078 }
00079 
00080 DLLEXPORT
00081 long long my_llabs(long long n)
00082 {
00083     return n < 0 ? -n : n;
00084 }
00085 
00086 /*
00087  * Foreign Globals
00088  *
00089  * (var_int is used in MISC-TYPES.EXPAND.3 as well)
00090  */
00091 
00092 DLLEXPORT char *         dll_version        = "20060907";
00093 
00094 /* TODO: look into signed char vs. unsigned char issue */
00095 DLLEXPORT char           var_char           = -127;
00096 DLLEXPORT unsigned char  var_unsigned_char  = 255;
00097 DLLEXPORT short          var_short          = -32767;
00098 DLLEXPORT unsigned short var_unsigned_short = 65535;
00099 DLLEXPORT int            var_int            = -32767;
00100 DLLEXPORT unsigned int   var_unsigned_int   = 65535;
00101 DLLEXPORT long           var_long           = -2147483647L;
00102 DLLEXPORT unsigned long  var_unsigned_long  = 4294967295UL;
00103 DLLEXPORT float          var_float          = 42.0f;
00104 DLLEXPORT double         var_double         = 42.0;
00105 DLLEXPORT void *         var_pointer        = NULL;
00106 DLLEXPORT char *         var_string         = "Hello, foreign world!";
00107 
00108 DLLEXPORT long long          var_long_long          = -9223372036854775807LL;
00109 DLLEXPORT unsigned long long var_unsigned_long_long = 18446744073709551615ULL;
00110 
00111 DLLEXPORT float float_max = FLT_MAX;
00112 DLLEXPORT float float_min = FLT_MIN;
00113 DLLEXPORT double double_max = DBL_MAX;
00114 DLLEXPORT double double_min = DBL_MIN;
00115 
00116 /*
00117  * Callbacks
00118  */
00119 
00120 DLLEXPORT
00121 int expect_char_sum(char (*f)(char, char))
00122 {
00123     return f('a', 3) == 'd';
00124 }
00125 
00126 DLLEXPORT
00127 int expect_unsigned_char_sum(unsigned char (*f)(unsigned char, unsigned char))
00128 {
00129     return f(UCHAR_MAX-1, 1) == UCHAR_MAX;
00130 }
00131 
00132 DLLEXPORT
00133 int expect_short_sum(short (*f)(short a, short b))
00134 {
00135     return f(SHRT_MIN+1, -1) == SHRT_MIN;
00136 }
00137 
00138 DLLEXPORT
00139 int expect_unsigned_short_sum(unsigned short (*f)(unsigned short,
00140                                                   unsigned short))
00141 {
00142     return f(USHRT_MAX-1, 1) == USHRT_MAX;
00143 }
00144 
00145 /* used in MISC-TYPES.EXPAND.4 as well */
00146 DLLEXPORT
00147 int expect_int_sum(int (*f)(int, int))
00148 {
00149     return f(INT_MIN+1, -1) == INT_MIN;
00150 }
00151 
00152 DLLEXPORT
00153 int expect_unsigned_int_sum(unsigned int (*f)(unsigned int, unsigned int))
00154 {
00155     return f(UINT_MAX-1, 1) == UINT_MAX;
00156 }
00157 
00158 DLLEXPORT
00159 int expect_long_sum(long (*f)(long, long))
00160 {
00161     return f(LONG_MIN+1, -1) == LONG_MIN;
00162 }
00163 
00164 DLLEXPORT
00165 int expect_unsigned_long_sum(unsigned long (*f)(unsigned long, unsigned long))
00166 {
00167     return f(ULONG_MAX-1, 1) == ULONG_MAX;
00168 }
00169 
00170 DLLEXPORT
00171 int expect_long_long_sum(long long (*f)(long long, long long))
00172 {
00173     return f(LLONG_MIN+1, -1) == LLONG_MIN;
00174 }
00175 
00176 DLLEXPORT
00177 int expect_unsigned_long_long_sum (unsigned long long
00178                                    (*f)(unsigned long long, unsigned long long))
00179 {
00180     return f(ULLONG_MAX-1, 1) == ULLONG_MAX;
00181 }
00182 
00183 DLLEXPORT
00184 int expect_float_sum(float (*f)(float, float))
00185 {
00186     /*printf("\n>>> FLOAT: %f <<<\n", f(20.0f, 22.0f));*/
00187     return f(20.0f, 22.0f) == 42.0f;
00188 }
00189 
00190 DLLEXPORT
00191 int expect_double_sum(double (*f)(double, double))
00192 {
00193     /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/
00194     return f(-20.0, -22.0) == -42.0;
00195 }
00196 
00197 DLLEXPORT
00198 int expect_long_double_sum(long double (*f)(long double, long double))
00199 {
00200     /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/
00201     return f(-20.0, -22.0) == -42.0;
00202 }
00203 
00204 DLLEXPORT
00205 int expect_pointer_sum(void* (*f)(void*, int))
00206 {
00207     return f(NULL, 0xDEAD) == (void *) 0xDEAD;
00208 }
00209 
00210 DLLEXPORT
00211 int expect_strcat(char* (*f)(char*, char*))
00212 {
00213     char *ret = f("Hello, ", "C world!");
00214     int res = strcmp(ret, "Hello, C world!") == 0;
00215     /* commented out as a quick fix on platforms that don't
00216        foreign allocate in C malloc space. */
00217     /*free(ret);*/ /* is this allowed? */
00218     return res;
00219 }
00220 
00221 DLLEXPORT
00222 void pass_int_ref(void (*f)(int*))
00223 {
00224     int x = 1984;
00225     f(&x);
00226 }
00227 
00228 /*
00229  * Enums
00230  */
00231 
00232 typedef enum {
00233     ONE = 1,
00234     TWO,
00235     THREE,
00236     FOUR,
00237     FORTY_ONE = 41,
00238     FORTY_TWO
00239 } numeros;
00240 
00241 DLLEXPORT
00242 int check_enums(numeros one, numeros two, numeros three, numeros four,
00243                 numeros forty_one, numeros forty_two)
00244 {
00245     if (one == ONE && two == TWO && three == THREE && four == FOUR &&
00246         forty_one == FORTY_ONE && forty_two == FORTY_TWO)
00247         return 1;
00248 
00249     return 0;
00250 }
00251 
00252 typedef enum { FALSE, TRUE } another_boolean;
00253 
00254 DLLEXPORT
00255 another_boolean return_enum(int x)
00256 {
00257     if (x == 0)
00258         return FALSE;
00259     else
00260         return TRUE;
00261 }
00262 
00263 /*
00264  * Booleans
00265  */
00266 
00267 DLLEXPORT
00268 int equalequal(int a, unsigned int b)
00269 {
00270     return ((unsigned int) a) == b;
00271 }
00272 
00273 DLLEXPORT
00274 char bool_and(unsigned char a, char b)
00275 {
00276     return a && b;
00277 }
00278 
00279 DLLEXPORT
00280 unsigned long bool_xor(long a, unsigned long b)
00281 {
00282     return (a && !b) || (!a && b);
00283 }
00284 
00285 /*
00286  * Test struct alignment issues. These comments assume the x86 gABI.
00287  * Hopefully these tests will spot alignment issues in others archs
00288  * too.
00289  */
00290 
00291 /*
00292  * STRUCT.ALIGNMENT.1
00293  */
00294 
00295 struct s_ch {
00296     char a_char;
00297 };
00298 
00299 /* This struct's size should be 2 bytes */
00300 struct s_s_ch {
00301     char another_char;
00302     struct s_ch a_s_ch;
00303 };
00304 
00305 DLLEXPORT
00306 struct s_s_ch the_s_s_ch = { 2, { 1 } };
00307 
00308 /*
00309  * STRUCT.ALIGNMENT.2
00310  */
00311 
00312 /* This one should be alignment should be the same as short's alignment. */
00313 struct s_short {
00314     char a_char;
00315     char another_char;
00316     short a_short;
00317 };
00318 
00319 struct s_s_short {
00320     char yet_another_char;
00321     struct s_short a_s_short; /* so this should be 2-byte aligned */
00322 };  /* size: 6 bytes */
00323 
00324 DLLEXPORT
00325 struct s_s_short the_s_s_short = { 4, { 1, 2, 3 } };
00326 
00327 /*
00328  * STRUCT.ALIGNMENT.3
00329  */
00330 
00331 /* This test will, among other things, check for the existence tail padding. */
00332 
00333 struct s_double {
00334     char a_char;       /* 1 byte */
00335                        /* padding: 3 bytes */
00336     double a_double;   /* 8 bytes */
00337     char another_char; /* 1 byte */
00338                        /* padding: 3 bytes */
00339 };                     /* total size: 16 bytes */
00340 
00341 struct s_s_double {
00342     char yet_another_char;      /* 1 byte */
00343                                 /* 3 bytes padding */
00344     struct s_double a_s_double; /* 16 bytes */
00345     short a_short;              /* 2 byte */
00346                                 /* 2 bytes padding */
00347 };                              /* total size: 24 bytes */
00348 
00349 DLLEXPORT
00350 struct s_s_double the_s_s_double = { 4, { 1, 2.0, 3 }, 5 };
00351 
00352 /*
00353  * STRUCT.ALIGNMENT.4
00354  */
00355 struct s_s_s_double {
00356     short another_short;            /* 2 bytes */
00357                                     /* 2 bytes padding */
00358     struct s_s_double a_s_s_double; /* 24 bytes */
00359     char last_char;                 /* 1 byte */
00360                                     /* 3 bytes padding */
00361 };                                  /* total size: 32 */
00362 
00363 DLLEXPORT
00364 struct s_s_s_double the_s_s_s_double = { 6, { 4, { 1, 2.0, 3 }, 5 }, 7 };
00365 
00366 /*
00367  * STRUCT.ALIGNMENT.5
00368  */
00369 
00370 /* MacOSX ABI says: "The embedding alignment of the first element in a data
00371    structure is equal to the element's natural alignment." and "For subsequent
00372    elements that have a natural alignment greater than 4 bytes, the embedding
00373    alignment is 4, unless the element is a vector." */
00374 
00375 /* note: these rules will apply to the structure itself. So, unless it is
00376    the first element of another structure, its alignment will be 4. */
00377 
00378 /* the following offsets and sizes are specific to darwin/ppc32 */
00379 
00380 struct s_double2 {
00381     double a_double;            /* 8 bytes (alignment 8) */
00382     short a_short;              /* 2 bytes */
00383                                 /* 6 bytes padding */
00384 };                              /* total size: 16 */
00385 
00386 struct s_s_double2 {
00387     char a_char;                  /* 1 byte */
00388                                   /* 3 bytes padding */
00389     struct s_double2 a_s_double2; /* 16 bytes, alignment 4 */
00390     short another_short;          /* 2 bytes */
00391                                   /* 2 bytes padding */
00392 };                                /* total size: 24 bytes */
00393                                   /* alignment: 4 */
00394 
00395 DLLEXPORT
00396 struct s_s_double2 the_s_s_double2 = { 3, { 1.0, 2 }, 4 };
00397 
00398 /*
00399  * STRUCT.ALIGNMENT.6
00400  */
00401 
00402 /* Same as STRUCT.ALIGNMENT.5 but with long long. */
00403 
00404 struct s_long_long {
00405     long long a_long_long;      /* 8 bytes (alignment 8) */
00406     short a_short;              /* 2 bytes */
00407                                 /* 6 bytes padding */
00408 };                              /* total size: 16 */
00409 
00410 struct s_s_long_long {
00411     char a_char;                      /* 1 byte */
00412                                       /* 3 bytes padding */
00413     struct s_long_long a_s_long_long; /* 16 bytes, alignment 4 */
00414     short a_short;                    /* 2 bytes */
00415                                       /* 2 bytes padding */
00416 };                                    /* total size: 24 bytes */
00417                                       /* alignment: 4 */
00418 
00419 DLLEXPORT
00420 struct s_s_long_long the_s_s_long_long = { 3, { 1, 2 }, 4 };
00421 
00422 /*
00423  * STRUCT.ALIGNMENT.7
00424  */
00425 
00426 /* Another test for Darwin's PPC32 ABI. */
00427 
00428 struct s_s_double3 {
00429     struct s_double2 a_s_double2; /* 16 bytes, alignment 8*/
00430     short another_short;          /* 2 bytes */
00431                                   /* 6 bytes padding */
00432 };                                /* total size: 24 */
00433 
00434 struct s_s_s_double3 {
00435     struct s_s_double3 a_s_s_double3; /* 24 bytes */
00436     char a_char;                      /* 1 byte */
00437                                       /* 7 bytes padding */
00438 };                                    /* total size: 32 */
00439 
00440 DLLEXPORT
00441 struct s_s_s_double3 the_s_s_s_double3 = { { { 1.0, 2 }, 3 }, 4 };
00442 
00443 /*
00444  * STRUCT.ALIGNMENT.8
00445  */
00446 
00447 /* Same as STRUCT.ALIGNMENT.[56] but with unsigned long long. */
00448 
00449 struct s_unsigned_long_long {
00450     unsigned long long an_unsigned_long_long; /* 8 bytes (alignment 8) */
00451     short a_short;                            /* 2 bytes */
00452                                               /* 6 bytes padding */
00453 };                                            /* total size: 16 */
00454 
00455 struct s_s_unsigned_long_long {
00456     char a_char;                                         /* 1 byte */
00457                                                          /* 3 bytes padding */
00458     struct s_unsigned_long_long a_s_unsigned_long_long;  /* 16 bytes, align 4 */
00459     short a_short;                                       /* 2 bytes */
00460                                                          /* 2 bytes padding */
00461 };                                           /* total size: 24 bytes */
00462                                              /*  alignment: 4 */
00463 
00464 DLLEXPORT
00465 struct s_s_unsigned_long_long the_s_s_unsigned_long_long = { 3, { 1, 2 }, 4 };
00466 
00467 /* STRUCT.ALIGNMENT.x */
00468 
00469 /* commented this test out because this is not standard C
00470    and MSVC++ (or some versions of it at least) won't compile it. */
00471 
00472 /*
00473 struct empty_struct {};
00474 
00475 struct with_empty_struct {
00476     struct empty_struct foo;
00477     int an_int;
00478 };
00479 
00480 DLLEXPORT
00481 struct with_empty_struct the_with_empty_struct = { {}, 42 };
00482 */
00483 
00484 /*
00485  * DEFCFUN.NOARGS and DEFCFUN.NOOP
00486  */
00487 
00488 DLLEXPORT
00489 int noargs()
00490 {
00491     return 42;
00492 }
00493 
00494 DLLEXPORT
00495 void noop()
00496 {
00497     return;
00498 }
00499 
00500 /*
00501  * DEFCFUN.BFF.1
00502  *
00503  * (let ((rettype (find-type :long))
00504  *       (arg-types (n-random-types-no-ll 127)))
00505  *   (c-function rettype arg-types)
00506  *   (gen-function-test rettype arg-types))
00507  */
00508 
00509 DLLEXPORT long sum_127_no_ll
00510   (long a1, unsigned long a2, short a3, unsigned short a4, float a5,
00511    double a6, unsigned long a7, float a8, unsigned char a9, unsigned
00512    short a10, short a11, unsigned long a12, double a13, long a14,
00513    unsigned int a15, void* a16, unsigned int a17, unsigned short a18,
00514    long a19, float a20, void* a21, float a22, int a23, int a24, unsigned
00515    short a25, long a26, long a27, double a28, unsigned char a29, unsigned
00516    int a30, unsigned int a31, int a32, unsigned short a33, unsigned int
00517    a34, void* a35, double a36, double a37, long a38, short a39, unsigned
00518    short a40, long a41, char a42, long a43, unsigned short a44, void*
00519    a45, int a46, unsigned int a47, double a48, unsigned char a49,
00520    unsigned char a50, float a51, int a52, unsigned short a53, double a54,
00521    short a55, unsigned char a56, unsigned long a57, float a58, float a59,
00522    float a60, void* a61, void* a62, unsigned int a63, unsigned long a64,
00523    char a65, short a66, unsigned short a67, unsigned long a68, void* a69,
00524    float a70, double a71, long a72, unsigned long a73, short a74,
00525    unsigned int a75, unsigned short a76, int a77, unsigned short a78,
00526    char a79, double a80, short a81, unsigned char a82, float a83, char
00527    a84, int a85, double a86, unsigned char a87, int a88, unsigned long
00528    a89, double a90, short a91, short a92, unsigned int a93, unsigned char
00529    a94, float a95, long a96, float a97, long a98, long a99, int a100, int
00530    a101, unsigned int a102, char a103, char a104, unsigned short a105,
00531    unsigned int a106, unsigned short a107, unsigned short a108, int a109,
00532    long a110, char a111, double a112, unsigned int a113, char a114, short
00533    a115, unsigned long a116, unsigned int a117, short a118, unsigned char
00534    a119, float a120, void* a121, double a122, int a123, long a124, char
00535    a125, unsigned short a126, float a127)
00536 {
00537     return (long) a1 + a2 + a3 + a4 + ((long) a5) + ((long) a6) + a7 +
00538         ((long) a8) + a9 + a10 + a11 + a12 + ((long) a13) + a14 + a15 +
00539         ((intptr_t) a16) + a17 + a18 + a19 + ((long) a20) +
00540         ((intptr_t) a21) + ((long) a22) + a23 + a24 + a25 + a26 + a27 +
00541         ((long) a28) + a29 + a30 + a31 + a32 + a33 + a34 + ((intptr_t) a35) +
00542         ((long) a36) + ((long) a37) + a38 + a39 + a40 + a41 + a42 + a43 + a44 +
00543         ((intptr_t) a45) + a46 + a47 + ((long) a48) + a49 + a50 +
00544         ((long) a51) + a52 + a53 + ((long) a54) + a55 + a56 + a57 + ((long) a58) +
00545         ((long) a59) + ((long) a60) + ((intptr_t) a61) +
00546         ((intptr_t) a62) + a63 + a64 + a65 + a66 + a67 + a68 +
00547         ((intptr_t) a69) + ((long) a70) + ((long) a71) + a72 + a73 + a74 +
00548         a75 + a76 + a77 + a78 + a79 + ((long) a80) + a81 + a82 + ((long) a83) +
00549         a84 + a85 + ((long) a86) + a87 + a88 + a89 + ((long) a90) + a91 + a92 +
00550         a93 + a94 + ((long) a95) + a96 + ((long) a97) + a98 + a99 + a100 + a101 +
00551         a102 + a103 + a104 + a105 + a106 + a107 + a108 + a109 + a110 + a111 +
00552         ((long) a112) + a113 + a114 + a115 + a116 + a117 + a118 + a119 +
00553         ((long) a120) + ((intptr_t) a121) + ((long) a122) + a123 + a124 +
00554         a125 + a126 + ((long) a127);
00555 }
00556 
00557 /*
00558  * DEFCFUN.BFF.2
00559  *
00560  * (let ((rettype (find-type :long-long))
00561  *       (arg-types (n-random-types 127)))
00562  *   (c-function rettype arg-types)
00563  *   (gen-function-test rettype arg-types))
00564  */
00565 
00566 DLLEXPORT long long sum_127
00567   (void* a1, void* a2, float a3, unsigned long a4, void* a5, long long
00568   a6, double a7, double a8, unsigned short a9, int a10, long long a11,
00569   long a12, short a13, unsigned int a14, long a15, unsigned char a16,
00570   int a17, double a18, short a19, short a20, long long a21, unsigned
00571   int a22, unsigned short a23, short a24, void* a25, short a26,
00572   unsigned short a27, unsigned short a28, int a29, long long a30,
00573   void* a31, int a32, unsigned long a33, unsigned long a34, void* a35,
00574   unsigned long long a36, float a37, int a38, short a39, void* a40,
00575   unsigned long long a41, long long a42, unsigned long a43, unsigned
00576   long a44, unsigned long long a45, unsigned long a46, char a47,
00577   double a48, long a49, unsigned int a50, int a51, short a52, void*
00578   a53, long a54, unsigned long long a55, int a56, unsigned short a57,
00579   unsigned long long a58, float a59, void* a60, float a61, unsigned
00580   short a62, unsigned long a63, float a64, unsigned int a65, unsigned
00581   long long a66, void* a67, double a68, unsigned long long a69, double
00582   a70, double a71, long long a72, void* a73, unsigned short a74, long
00583   a75, void* a76, short a77, double a78, long a79, unsigned char a80,
00584   void* a81, unsigned char a82, long a83, double a84, void* a85, int
00585   a86, double a87, unsigned char a88, double a89, short a90, long a91,
00586   int a92, long a93, double a94, unsigned short a95, unsigned int a96,
00587   int a97, char a98, long long a99, double a100, float a101, unsigned
00588   long a102, short a103, void* a104, float a105, long long a106, int
00589   a107, long long a108, long long a109, double a110, unsigned long
00590   long a111, double a112, unsigned long a113, char a114, char a115,
00591   unsigned long a116, short a117, unsigned char a118, unsigned char
00592   a119, int a120, int a121, float a122, unsigned char a123, unsigned
00593   char a124, double a125, unsigned long long a126, char a127)
00594 {
00595     return (long long) ((intptr_t) a1) + ((intptr_t) a2) + ((long) a3) +
00596         a4 + ((intptr_t) a5) + a6 + ((long) a7) + ((long) a8) + a9 + a10 +
00597         a11 + a12 + a13 + a14 + a15 + a16 + a17 + ((long) a18) + a19 + a20 +
00598         a21 + a22 + a23 + a24 + ((intptr_t) a25) + a26 + a27 + a28 + a29 +
00599         a30 + ((intptr_t) a31) + a32 + a33 + a34 + ((intptr_t) a35) +
00600         a36 + ((long) a37) + a38 + a39 + ((intptr_t) a40) + a41 + a42 + a43 +
00601         a44 + a45 + a46 + a47 + ((long) a48) + a49 + a50 + a51 + a52 +
00602         ((intptr_t) a53) + a54 + a55 + a56 + a57 + a58 + ((long) a59) +
00603         ((intptr_t) a60) + ((long) a61) + a62 + a63 + ((long) a64) + a65 + a66
00604         + ((intptr_t) a67) + ((long) a68) + a69 + ((long) a70) + ((long) a71) +
00605         a72 + ((intptr_t) a73) + a74 + a75 + ((intptr_t) a76) + a77 +
00606         ((long) a78) + a79 + a80 + ((intptr_t) a81) + a82 + a83 + ((long) a84)
00607         + ((intptr_t) a85) + a86 + ((long) a87) + a88 + ((long) a89) + a90 +
00608         a91 + a92 + a93 + ((long) a94) + a95 + a96 + a97 + a98 + a99 +
00609         ((long) a100) + ((long) a101) + a102 + a103 + ((intptr_t) a104) +
00610         ((long) a105) + a106 + a107 + a108 + a109 + ((long) a110) + a111 +
00611         ((long) a112) + a113 + a114 + a115 + a116 + a117 + a118 + a119 + a120 +
00612         a121 + ((long) a122) + a123 + a124 + ((long) a125) + a126 + a127;
00613 }
00614 
00615 /*
00616  * CALLBACKS.BFF.1  (cb-test :no-long-long t)
00617  */
00618 
00619 DLLEXPORT long call_sum_127_no_ll
00620   (long (*func)
00621    (unsigned long, void*, long, double, unsigned long, float, float,
00622     int, unsigned int, double, double, double, void*, unsigned short,
00623     unsigned short, void*, long, long, int, short, unsigned short,
00624     unsigned short, char, long, void*, void*, char, unsigned char,
00625     unsigned long, short, int, int, unsigned char, short, long, long,
00626     void*, unsigned short, char, double, unsigned short, void*, short,
00627     unsigned long, unsigned short, float, unsigned char, short, float,
00628     short, char, unsigned long, unsigned long, char, float, long, void*,
00629     short, float, unsigned int, float, unsigned int, double, unsigned int,
00630     unsigned char, int, long, char, short, double, int, void*, char,
00631     unsigned short, void*, unsigned short, void*, unsigned long, double,
00632     void*, long, float, unsigned short, unsigned short, void*, float, int,
00633     unsigned int, double, float, long, void*, unsigned short, float,
00634     unsigned char, unsigned char, float, unsigned int, float, unsigned
00635     short, double, unsigned short, unsigned long, unsigned int, unsigned
00636     long, void*, unsigned char, char, char, unsigned short, unsigned long,
00637     float, short, void*, long, unsigned short, short, double, short, int,
00638     char, unsigned long, long, int, void*, double, unsigned char))
00639 {
00640     return
00641         func(948223085, (void *) 803308438, -465723152, 20385,
00642              219679466, -10035, 13915, -1193455756, 1265303699, 27935, -18478,
00643              -10508, (void *) 215389089, 55561, 55472, (void *) 146070433,
00644              -1040819989, -17851453, -1622662247, -19473, 20837, 30216, 79,
00645              986800400, (void *) 390281604, (void *) 1178532858, 19, 117,
00646              78337699, -5718, -991300738, 872160910, 184, 926, -1487245383,
00647              1633973783, (void *) 33738609, 53985, -116, 31645, 27196, (void *)
00648              145569903, -6960, 17252220, 47404, -10491, 88, -30438, -21212,
00649              -1982, -16, 1175270, 7949380, -121, 8559, -432968526, (void *)
00650              293455312, 11894, -8394, 142421516, -25758, 3422998, 4004,
00651              15758212, 198, -1071899743, -1284904617, -11, -17219, -30039,
00652              311589092, (void *) 541468577, 123, 63517, (void *) 1252504506,
00653              39368, (void *) 10057868, 134781408, -7143, (void *) 72825877,
00654              -1190798667, -30862, 63757, 14965, (void *) 802391252, 22008,
00655              -517289619, 806091099, 1125, 451, -498145176, (void *) 55960931,
00656              15379, 4629, 184, 254, 22532, 465856451, -1669, 49416, -16546,
00657              2983, 4337541, 65292495, 39253529, (void *) 669025, 211, 85, -19,
00658              24298, 65358, 16776, -29957, (void *) 124311, -163231228, 2610,
00659              -7806, 26434, -21913, -753615541, 120, 358697932, -1198889034,
00660              -2131350926, (void *) 3749492036, -13413, 17);
00661 }
00662 
00663 /*
00664  * CALLBACKS.BFF.2  (cb-test)
00665  */
00666 
00667 DLLEXPORT long long call_sum_127
00668   (long long (*func)
00669    (short, char, void*, float, long, double, unsigned long long,
00670     unsigned short, unsigned char, char, char, unsigned short, unsigned
00671     long long, unsigned short, long long, unsigned short, unsigned long
00672     long, unsigned char, unsigned char, unsigned long long, long long,
00673     char, float, unsigned int, float, float, unsigned int, float, char,
00674     unsigned char, long, long long, unsigned char, double, long,
00675     double, unsigned int, unsigned short, long long, unsigned int, int,
00676     unsigned long long, long, short, unsigned int, unsigned int,
00677     unsigned long long, unsigned int, long, void*, unsigned char, char,
00678     long long, unsigned short, unsigned int, float, unsigned char,
00679     unsigned long, long long, float, long, float, int, float, unsigned
00680     short, unsigned long long, short, unsigned long, long, char,
00681     unsigned short, long long, short, double, void*, unsigned int,
00682     char, unsigned int, void*, void*, unsigned char, void*, unsigned
00683     short, unsigned char, long, void*, char, long, unsigned short,
00684     unsigned char, double, unsigned long long, unsigned short, unsigned
00685     short, unsigned int, long, char, long, char, short, unsigned short,
00686     unsigned long, unsigned long, short, long long, long long, long
00687     long, double, unsigned short, unsigned char, short, unsigned char,
00688     long, long long, unsigned long long, unsigned int, unsigned long,
00689     unsigned char, long long, unsigned char, unsigned long long,
00690     double, unsigned char, long long, unsigned char, char, long long))
00691 {
00692     return
00693         func(-8573, 14, (void *) 832601021, -32334, -1532040888,
00694              -18478, 2793023182591311826, 2740, 230, 103, 97, 13121,
00695              5112369026351511084, 7763, -8134147951003417418, 34348,
00696              5776613699556468853, 19, 122, 1431603726926527625,
00697              439503521880490337, -112, -21557, 1578969190, -22008, -4953,
00698              2127745975, -7262, -6, 180, 226352974, -3928775366167459219, 134,
00699              -17730, -1175042526, 23868, 3494181009, 57364,
00700              3134876875147518682, 104531655, -1286882727, 803577887579693487,
00701              1349268803, 24912, 3313099419, 3907347884, 1738833249233805034,
00702              2794230885, 1008818752, (void *) 1820044575, 189, 61,
00703              -931654560961745071, 57531, 3096859985, 10405, 220, 3631311224,
00704              -8531370353478907668, 31258, 678896693, -32150, -1869057813,
00705              -19877, 62841, 4161660185772906873, -23869, 4016251006, 610353435,
00706              105, 47315, -1051054492535331660, 6846, -15163, (void *)
00707              736672359, 2123928476, -122, 3859258652, (void *) 3923394833,
00708              (void *) 1265031970, 161, (void *) 1993867800, 55056, 122,
00709              1562112760, (void *) 866615125, -79, -1261399547, 31737, 254,
00710              -31279, 5462649659172897980, 5202, 7644, 174224940, -337854382,
00711              -45, -583502442, -37, -13266, 24520, 2198606699, 2890453969,
00712              -8282, -2295716637858246075, -1905178488651598878,
00713              -6384652209316714643, 14841, 35443, 132, 15524, 187, 2138878229,
00714              -5153032566879951000, 9056545530140684207, 4124632010, 276167701,
00715              56, -2307310370663738730, 66, 9113015627153789746, -9618, 167,
00716              755753399701306200, 119, -28, -990561962725435433);
00717 }
00718 
00719 /*
00720  * CALLBACKS.DOUBLE26
00721  */
00722 
00723 DLLEXPORT double call_double26
00724   (double (*f)(double, double, double, double, double, double, double, double,
00725                double, double, double, double, double, double, double, double,
00726                double, double, double, double, double, double, double, double,
00727                double, double))
00728 {
00729     return f(3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14,
00730              3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14,
00731              3.14, 3.14, 3.14, 3.14);
00732 }
00733 
00734 /*
00735  * DEFCFUN.DOUBLE26 and FUNCALL.DOUBLE26
00736  */
00737 
00738 DLLEXPORT
00739 double sum_double26(double a1, double a2, double a3, double a4, double a5,
00740                     double a6, double a7, double a8, double a9, double a10,
00741                     double a11, double a12, double a13, double a14, double a15,
00742                     double a16, double a17, double a18, double a19, double a20,
00743                     double a21, double a22, double a23, double a24, double a25,
00744                     double a26)
00745 {
00746     return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 +
00747         a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22 + a23 + a24 + a25 +
00748         a26;
00749 }
00750 
00751 /*
00752  * CALLBACKS.FLOAT26
00753  */
00754 
00755 DLLEXPORT float call_float26
00756   (float (*f)(float, float, float, float, float, float, float, float,
00757               float, float, float, float, float, float, float, float,
00758               float, float, float, float, float, float, float, float,
00759               float, float))
00760 {
00761     return f(5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
00762              5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
00763              5.0, 5.0, 5.0, 5.0);
00764 }
00765 
00766 /*
00767  * DEFCFUN.FLOAT26 and FUNCALL.FLOAT26
00768  */
00769 
00770 DLLEXPORT
00771 float sum_float26(float a1, float a2, float a3, float a4, float a5,
00772                   float a6, float a7, float a8, float a9, float a10,
00773                   float a11, float a12, float a13, float a14, float a15,
00774                   float a16, float a17, float a18, float a19, float a20,
00775                   float a21, float a22, float a23, float a24, float a25,
00776                   float a26)
00777 {
00778     return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 +
00779         a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22 + a23 + a24 + a25 +
00780         a26;
00781 }
00782 
00783 /*
00784  * Symbol case.
00785  */
00786 
00787 DLLEXPORT int UPPERCASEINT1    = 12345;
00788 DLLEXPORT int UPPER_CASE_INT1  = 23456;
00789 DLLEXPORT int MiXeDCaSeInT1    = 34567;
00790 DLLEXPORT int MiXeD_CaSe_InT1  = 45678;
00791 
00792 DLLEXPORT int UPPERCASEINT2    = 12345;
00793 DLLEXPORT int UPPER_CASE_INT2  = 23456;
00794 DLLEXPORT int MiXeDCaSeInT2    = 34567;
00795 DLLEXPORT int MiXeD_CaSe_InT2  = 45678;
00796 
00797 DLLEXPORT int UPPERCASEINT3    = 12345;
00798 DLLEXPORT int UPPER_CASE_INT3  = 23456;
00799 DLLEXPORT int MiXeDCaSeInT3    = 34567;
00800 DLLEXPORT int MiXeD_CaSe_InT3  = 45678;
00801 
00802 /*
00803  * FOREIGN-SYMBOL-POINTER.1
00804  */
00805 
00806 DLLEXPORT int compare_against_abs(intptr_t p)
00807 {
00808     return p == (intptr_t) abs;
00809 }
00810 
00811 /*
00812  * FOREIGN-SYMBOL-POINTER.2
00813  */
00814 
00815 DLLEXPORT void xpto_fun() {}
00816 
00817 DLLEXPORT
00818 int compare_against_xpto_fun(intptr_t p)
00819 {
00820     return p == (intptr_t) xpto_fun;
00821 }
00822 
00823 /*
00824  * [DEFCFUN|FUNCALL].NAMESPACE.1
00825  */
00826 
00827 DLLEXPORT
00828 int ns_function()
00829 {
00830     return 1;
00831 }
00832 
00833 /*
00834  * FOREIGN-GLOBALS.NAMESPACE.*
00835  */
00836 
00837 DLLEXPORT int ns_var = 1;
00838 
00839 /*
00840  * DEFCFUN.STDCALL.1
00841  */
00842 
00843 DLLEXPORT
00844 int STDCALL stdcall_fun(int a, int b, int c)
00845 {
00846     return a + b + c;
00847 }
00848 
00849 /*
00850  * CALLBACKS.STDCALL.1
00851  */
00852 
00853 DLLEXPORT
00854 int call_stdcall_fun(int (STDCALL *f)(int, int, int))
00855 {
00856     int a = 42;
00857     f(1, 2, 3);
00858     return a;
00859 }
00860 
00861 /* Unlike the one above, this commented test below actually
00862  * works. But, alas, it doesn't compile with -std=c99. */
00863 
00864 /*
00865 DLLEXPORT
00866 int call_stdcall_fun(int __attribute__((stdcall)) (*f)(int, int, int))
00867 {
00868     asm("pushl $42");
00869     register int ebx asm("%ebx");
00870     f(1, 2, 3);
00871     asm("popl %ebx");
00872     return ebx;
00873 }
00874 */
00875 
00876 /* vim: ts=4 et
00877 */


cffi
Author(s): James Bielman
autogenerated on Sat Jun 8 2019 19:15:35