libtest.c - clic - Clic is an command line interactive client for gopher written in Common LISP (HTM) git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/clic/ (DIR) Log (DIR) Files (DIR) Refs (DIR) Tags (DIR) README (DIR) LICENSE --- libtest.c (31242B) --- 1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil -*- 2 * 3 * libtest.c --- auxiliary C lib for testing purposes 4 * 5 * Copyright (C) 2005-2007, Luis Oliveira <loliveira(@)common-lisp.net> 6 * 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: 14 * 15 * The above copyright notice and this permission notice shall be 16 * included in all copies or substantial portions of the Software. 17 * 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. 26 */ 27 28 #ifdef WIN32 29 #define DLLEXPORT __declspec(dllexport) 30 #else 31 #define DLLEXPORT 32 #endif 33 34 #include <stdio.h> 35 #include <limits.h> 36 #include <string.h> 37 #include <stdlib.h> 38 #include <math.h> 39 #include <float.h> 40 #include <stdbool.h> 41 #include <stdarg.h> 42 43 /* MSVC doesn't have stdint.h and uses a different syntax for stdcall */ 44 #ifndef _MSC_VER 45 #include <stdint.h> 46 #endif 47 48 #ifdef WIN32 49 #ifdef _MSC_VER 50 #define STDCALL __stdcall 51 #else 52 #define STDCALL __attribute__((stdcall)) 53 #endif 54 #else 55 #define STDCALL 56 #endif 57 58 /* 59 * Some functions that aren't available on WIN32 60 */ 61 62 DLLEXPORT 63 float my_sqrtf(float n) 64 { 65 return (float) sqrt((double) n); 66 } 67 68 DLLEXPORT 69 char *my_strdup(const char *str) 70 { 71 char *p = malloc(strlen(str) + 1); 72 strcpy(p, str); 73 return p; 74 } 75 76 DLLEXPORT 77 void my_strfree(char *str) 78 { 79 free(str); 80 } 81 82 DLLEXPORT 83 long long my_llabs(long long n) 84 { 85 return n < 0 ? -n : n; 86 } 87 88 89 DLLEXPORT 90 unsigned long long ullong(unsigned long long n) 91 { 92 return n == ULLONG_MAX ? n : 42; 93 } 94 95 /* 96 * Foreign Globals 97 * 98 * (var_int is used in MISC-TYPES.EXPAND.3 as well) 99 */ 100 101 DLLEXPORT char * dll_version = "20120107"; 102 103 /* TODO: look into signed char vs. unsigned char issue */ 104 DLLEXPORT char var_char = -127; 105 DLLEXPORT unsigned char var_unsigned_char = 255; 106 DLLEXPORT short var_short = -32767; 107 DLLEXPORT unsigned short var_unsigned_short = 65535; 108 DLLEXPORT int var_int = -32767; 109 DLLEXPORT unsigned int var_unsigned_int = 65535; 110 DLLEXPORT long var_long = -2147483647L; 111 DLLEXPORT unsigned long var_unsigned_long = 4294967295UL; 112 DLLEXPORT float var_float = 42.0f; 113 DLLEXPORT double var_double = 42.0; 114 DLLEXPORT void * var_pointer = NULL; 115 DLLEXPORT char * var_string = "Hello, foreign world!"; 116 117 DLLEXPORT long long var_long_long = -9223372036854775807LL; 118 DLLEXPORT unsigned long long var_unsigned_long_long = 18446744073709551615ULL; 119 120 DLLEXPORT float float_max = FLT_MAX; 121 DLLEXPORT float float_min = FLT_MIN; 122 DLLEXPORT double double_max = DBL_MAX; 123 DLLEXPORT double double_min = DBL_MIN; 124 125 /* 126 * Callbacks 127 */ 128 129 DLLEXPORT 130 int expect_char_sum(char (*f)(char, char)) 131 { 132 return f('a', 3) == 'd'; 133 } 134 135 DLLEXPORT 136 int expect_unsigned_char_sum(unsigned char (*f)(unsigned char, unsigned char)) 137 { 138 return f(UCHAR_MAX-1, 1) == UCHAR_MAX; 139 } 140 141 DLLEXPORT 142 int expect_short_sum(short (*f)(short a, short b)) 143 { 144 return f(SHRT_MIN+1, -1) == SHRT_MIN; 145 } 146 147 DLLEXPORT 148 int expect_unsigned_short_sum(unsigned short (*f)(unsigned short, 149 unsigned short)) 150 { 151 return f(USHRT_MAX-1, 1) == USHRT_MAX; 152 } 153 154 /* used in MISC-TYPES.EXPAND.4 as well */ 155 DLLEXPORT 156 int expect_int_sum(int (*f)(int, int)) 157 { 158 return f(INT_MIN+1, -1) == INT_MIN; 159 } 160 161 DLLEXPORT 162 int expect_unsigned_int_sum(unsigned int (*f)(unsigned int, unsigned int)) 163 { 164 return f(UINT_MAX-1, 1) == UINT_MAX; 165 } 166 167 DLLEXPORT 168 int expect_long_sum(long (*f)(long, long)) 169 { 170 return f(LONG_MIN+1, -1) == LONG_MIN; 171 } 172 173 DLLEXPORT 174 int expect_unsigned_long_sum(unsigned long (*f)(unsigned long, unsigned long)) 175 { 176 return f(ULONG_MAX-1, 1) == ULONG_MAX; 177 } 178 179 DLLEXPORT 180 int expect_long_long_sum(long long (*f)(long long, long long)) 181 { 182 return f(LLONG_MIN+1, -1) == LLONG_MIN; 183 } 184 185 DLLEXPORT 186 int expect_unsigned_long_long_sum (unsigned long long 187 (*f)(unsigned long long, unsigned long long)) 188 { 189 return f(ULLONG_MAX-1, 1) == ULLONG_MAX; 190 } 191 192 DLLEXPORT 193 int expect_float_sum(float (*f)(float, float)) 194 { 195 /*printf("\n>>> FLOAT: %f <<<\n", f(20.0f, 22.0f));*/ 196 return f(20.0f, 22.0f) == 42.0f; 197 } 198 199 DLLEXPORT 200 int expect_double_sum(double (*f)(double, double)) 201 { 202 /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/ 203 return f(-20.0, -22.0) == -42.0; 204 } 205 206 DLLEXPORT 207 int expect_long_double_sum(long double (*f)(long double, long double)) 208 { 209 /*printf("\n>>> DOUBLE: %f<<<\n", f(-20.0, -22.0));*/ 210 return f(-20.0, -22.0) == -42.0; 211 } 212 213 DLLEXPORT 214 int expect_pointer_sum(void* (*f)(void*, int)) 215 { 216 return f(NULL, 0xDEAD) == (void *) 0xDEAD; 217 } 218 219 DLLEXPORT 220 int expect_strcat(char* (*f)(char*, char*)) 221 { 222 char *ret = f("Hello, ", "C world!"); 223 int res = strcmp(ret, "Hello, C world!") == 0; 224 /* commented out as a quick fix on platforms that don't 225 foreign allocate in C malloc space. */ 226 /*free(ret);*/ /* is this allowed? */ 227 return res; 228 } 229 230 DLLEXPORT 231 void pass_int_ref(void (*f)(int*)) 232 { 233 int x = 1984; 234 f(&x); 235 } 236 237 /* 238 * Enums 239 */ 240 241 typedef enum { 242 ONE = 1, 243 TWO, 244 THREE, 245 FOUR, 246 FORTY_ONE = 41, 247 FORTY_TWO 248 } numeros; 249 250 DLLEXPORT 251 int check_enums(numeros one, numeros two, numeros three, numeros four, 252 numeros forty_one, numeros forty_two) 253 { 254 if (one == ONE && two == TWO && three == THREE && four == FOUR && 255 forty_one == FORTY_ONE && forty_two == FORTY_TWO) 256 return 1; 257 258 return 0; 259 } 260 261 typedef enum { FALSE, TRUE } another_boolean; 262 263 DLLEXPORT 264 another_boolean return_enum(int x) 265 { 266 if (x == 0) 267 return FALSE; 268 else 269 return TRUE; 270 } 271 272 /* 273 * Booleans 274 */ 275 276 DLLEXPORT 277 int equalequal(int a, unsigned int b) 278 { 279 return ((unsigned int) a) == b; 280 } 281 282 DLLEXPORT 283 char bool_and(unsigned char a, char b) 284 { 285 return a && b; 286 } 287 288 DLLEXPORT 289 unsigned long bool_xor(long a, unsigned long b) 290 { 291 return (a && !b) || (!a && b); 292 } 293 294 DLLEXPORT 295 unsigned sizeof_bool(void) 296 { 297 return (unsigned) sizeof(_Bool); 298 } 299 300 DLLEXPORT 301 unsigned bool_to_unsigned(_Bool b) 302 { 303 return (unsigned) b; 304 } 305 306 DLLEXPORT 307 _Bool unsigned_to_bool(unsigned u) 308 { 309 return (_Bool) u; 310 } 311 312 /* 313 * Test struct alignment issues. These comments assume the x86 gABI. 314 * Hopefully these tests will spot alignment issues in others archs 315 * too. 316 */ 317 318 /* 319 * STRUCT.ALIGNMENT.1 320 */ 321 322 struct s_ch { 323 char a_char; 324 }; 325 326 /* This struct's size should be 2 bytes */ 327 struct s_s_ch { 328 char another_char; 329 struct s_ch a_s_ch; 330 }; 331 332 DLLEXPORT 333 struct s_s_ch the_s_s_ch = { 2, { 1 } }; 334 335 /* 336 * STRUCT.ALIGNMENT.2 337 */ 338 339 /* This one should be alignment should be the same as short's alignment. */ 340 struct s_short { 341 char a_char; 342 char another_char; 343 short a_short; 344 }; 345 346 struct s_s_short { 347 char yet_another_char; 348 struct s_short a_s_short; /* so this should be 2-byte aligned */ 349 }; /* size: 6 bytes */ 350 351 DLLEXPORT 352 struct s_s_short the_s_s_short = { 4, { 1, 2, 3 } }; 353 354 /* 355 * STRUCT.ALIGNMENT.3 356 */ 357 358 /* This test will, among other things, check for the existence tail padding. */ 359 360 struct s_double { 361 char a_char; /* 1 byte */ 362 /* padding: 3 bytes */ 363 double a_double; /* 8 bytes */ 364 char another_char; /* 1 byte */ 365 /* padding: 3 bytes */ 366 }; /* total size: 16 bytes */ 367 368 struct s_s_double { 369 char yet_another_char; /* 1 byte */ 370 /* 3 bytes padding */ 371 struct s_double a_s_double; /* 16 bytes */ 372 short a_short; /* 2 byte */ 373 /* 2 bytes padding */ 374 }; /* total size: 24 bytes */ 375 376 DLLEXPORT 377 struct s_s_double the_s_s_double = { 4, { 1, 2.0, 3 }, 5 }; 378 379 /* 380 * STRUCT.ALIGNMENT.4 381 */ 382 struct s_s_s_double { 383 short another_short; /* 2 bytes */ 384 /* 2 bytes padding */ 385 struct s_s_double a_s_s_double; /* 24 bytes */ 386 char last_char; /* 1 byte */ 387 /* 3 bytes padding */ 388 }; /* total size: 32 */ 389 390 DLLEXPORT 391 struct s_s_s_double the_s_s_s_double = { 6, { 4, { 1, 2.0, 3 }, 5 }, 7 }; 392 393 /* 394 * STRUCT.ALIGNMENT.5 395 */ 396 397 /* MacOSX ABI says: "The embedding alignment of the first element in a data 398 structure is equal to the element's natural alignment." and "For subsequent 399 elements that have a natural alignment greater than 4 bytes, the embedding 400 alignment is 4, unless the element is a vector." */ 401 402 /* note: these rules will apply to the structure itself. So, unless it is 403 the first element of another structure, its alignment will be 4. */ 404 405 /* the following offsets and sizes are specific to darwin/ppc32 */ 406 407 struct s_double2 { 408 double a_double; /* 8 bytes (alignment 8) */ 409 short a_short; /* 2 bytes */ 410 /* 6 bytes padding */ 411 }; /* total size: 16 */ 412 413 struct s_s_double2 { 414 char a_char; /* 1 byte */ 415 /* 3 bytes padding */ 416 struct s_double2 a_s_double2; /* 16 bytes, alignment 4 */ 417 short another_short; /* 2 bytes */ 418 /* 2 bytes padding */ 419 }; /* total size: 24 bytes */ 420 /* alignment: 4 */ 421 422 DLLEXPORT 423 struct s_s_double2 the_s_s_double2 = { 3, { 1.0, 2 }, 4 }; 424 425 /* 426 * STRUCT.ALIGNMENT.6 427 */ 428 429 /* Same as STRUCT.ALIGNMENT.5 but with long long. */ 430 431 struct s_long_long { 432 long long a_long_long; /* 8 bytes (alignment 8) */ 433 short a_short; /* 2 bytes */ 434 /* 6 bytes padding */ 435 }; /* total size: 16 */ 436 437 struct s_s_long_long { 438 char a_char; /* 1 byte */ 439 /* 3 bytes padding */ 440 struct s_long_long a_s_long_long; /* 16 bytes, alignment 4 */ 441 short a_short; /* 2 bytes */ 442 /* 2 bytes padding */ 443 }; /* total size: 24 bytes */ 444 /* alignment: 4 */ 445 446 DLLEXPORT 447 struct s_s_long_long the_s_s_long_long = { 3, { 1, 2 }, 4 }; 448 449 /* 450 * STRUCT.ALIGNMENT.7 451 */ 452 453 /* Another test for Darwin's PPC32 ABI. */ 454 455 struct s_s_double3 { 456 struct s_double2 a_s_double2; /* 16 bytes, alignment 8*/ 457 short another_short; /* 2 bytes */ 458 /* 6 bytes padding */ 459 }; /* total size: 24 */ 460 461 struct s_s_s_double3 { 462 struct s_s_double3 a_s_s_double3; /* 24 bytes */ 463 char a_char; /* 1 byte */ 464 /* 7 bytes padding */ 465 }; /* total size: 32 */ 466 467 DLLEXPORT 468 struct s_s_s_double3 the_s_s_s_double3 = { { { 1.0, 2 }, 3 }, 4 }; 469 470 /* 471 * STRUCT.ALIGNMENT.8 472 */ 473 474 /* Same as STRUCT.ALIGNMENT.[56] but with unsigned long long. */ 475 476 struct s_unsigned_long_long { 477 unsigned long long an_unsigned_long_long; /* 8 bytes (alignment 8) */ 478 short a_short; /* 2 bytes */ 479 /* 6 bytes padding */ 480 }; /* total size: 16 */ 481 482 struct s_s_unsigned_long_long { 483 char a_char; /* 1 byte */ 484 /* 3 bytes padding */ 485 struct s_unsigned_long_long a_s_unsigned_long_long; /* 16 bytes, align 4 */ 486 short a_short; /* 2 bytes */ 487 /* 2 bytes padding */ 488 }; /* total size: 24 bytes */ 489 /* alignment: 4 */ 490 491 DLLEXPORT 492 struct s_s_unsigned_long_long the_s_s_unsigned_long_long = { 3, { 1, 2 }, 4 }; 493 494 /* STRUCT.ALIGNMENT.x */ 495 496 /* commented this test out because this is not standard C 497 and MSVC++ (or some versions of it at least) won't compile it. */ 498 499 /* 500 struct empty_struct {}; 501 502 struct with_empty_struct { 503 struct empty_struct foo; 504 int an_int; 505 }; 506 507 DLLEXPORT 508 struct with_empty_struct the_with_empty_struct = { {}, 42 }; 509 */ 510 511 /* 512 * STRUCT-VALUES.* 513 */ 514 515 struct pair { int a, b; }; 516 517 DLLEXPORT 518 int pair_sum(struct pair p) 519 { 520 return p.a + p.b; 521 } 522 523 DLLEXPORT 524 int pair_pointer_sum(struct pair *p) 525 { 526 return p->a + p->b; 527 } 528 529 DLLEXPORT 530 struct pair make_pair(int a, int b) 531 { 532 return (struct pair) { a, b }; 533 } 534 535 DLLEXPORT 536 struct pair *alloc_pair(int a, int b) 537 { 538 struct pair *p = malloc(sizeof(struct pair)); 539 p->a = a; 540 p->b = b; 541 return p; 542 } 543 544 struct pair_plus_one { 545 struct pair p; 546 int c; 547 }; 548 549 DLLEXPORT 550 int pair_plus_one_sum(struct pair_plus_one p) 551 { 552 return p.p.a + p.p.b + p.c; 553 } 554 555 DLLEXPORT 556 int pair_plus_one_pointer_sum(struct pair_plus_one *p) 557 { 558 return p->p.a + p->p.b + p->c; 559 } 560 561 DLLEXPORT 562 struct pair_plus_one make_pair_plus_one(int a, int b, int c) 563 { 564 return (struct pair_plus_one) { { a, b }, c }; 565 } 566 567 DLLEXPORT 568 struct pair_plus_one *alloc_pair_plus_one(int a, int b, int c) 569 { 570 struct pair_plus_one *p = malloc(sizeof(struct pair_plus_one)); 571 p->p.a = a; 572 p->p.b = b; 573 p->c = c; 574 return p; 575 } 576 577 /* 578 * DEFCFUN.NOARGS and DEFCFUN.NOOP 579 */ 580 581 DLLEXPORT 582 int noargs() 583 { 584 return 42; 585 } 586 587 DLLEXPORT 588 void noop() 589 { 590 return; 591 } 592 593 /* 594 * DEFCFUN.BFF.1 595 * 596 * (let ((rettype (find-type :long)) 597 * (arg-types (n-random-types-no-ll 127))) 598 * (c-function rettype arg-types) 599 * (gen-function-test rettype arg-types)) 600 */ 601 602 DLLEXPORT long sum_127_no_ll 603 (long a1, unsigned long a2, short a3, unsigned short a4, float a5, 604 double a6, unsigned long a7, float a8, unsigned char a9, unsigned 605 short a10, short a11, unsigned long a12, double a13, long a14, 606 unsigned int a15, void* a16, unsigned int a17, unsigned short a18, 607 long a19, float a20, void* a21, float a22, int a23, int a24, unsigned 608 short a25, long a26, long a27, double a28, unsigned char a29, unsigned 609 int a30, unsigned int a31, int a32, unsigned short a33, unsigned int 610 a34, void* a35, double a36, double a37, long a38, short a39, unsigned 611 short a40, long a41, char a42, long a43, unsigned short a44, void* 612 a45, int a46, unsigned int a47, double a48, unsigned char a49, 613 unsigned char a50, float a51, int a52, unsigned short a53, double a54, 614 short a55, unsigned char a56, unsigned long a57, float a58, float a59, 615 float a60, void* a61, void* a62, unsigned int a63, unsigned long a64, 616 char a65, short a66, unsigned short a67, unsigned long a68, void* a69, 617 float a70, double a71, long a72, unsigned long a73, short a74, 618 unsigned int a75, unsigned short a76, int a77, unsigned short a78, 619 char a79, double a80, short a81, unsigned char a82, float a83, char 620 a84, int a85, double a86, unsigned char a87, int a88, unsigned long 621 a89, double a90, short a91, short a92, unsigned int a93, unsigned char 622 a94, float a95, long a96, float a97, long a98, long a99, int a100, int 623 a101, unsigned int a102, char a103, char a104, unsigned short a105, 624 unsigned int a106, unsigned short a107, unsigned short a108, int a109, 625 long a110, char a111, double a112, unsigned int a113, char a114, short 626 a115, unsigned long a116, unsigned int a117, short a118, unsigned char 627 a119, float a120, void* a121, double a122, int a123, long a124, char 628 a125, unsigned short a126, float a127) 629 { 630 return (long) a1 + a2 + a3 + a4 + ((long) a5) + ((long) a6) + a7 + 631 ((long) a8) + a9 + a10 + a11 + a12 + ((long) a13) + a14 + a15 + 632 ((intptr_t) a16) + a17 + a18 + a19 + ((long) a20) + 633 ((intptr_t) a21) + ((long) a22) + a23 + a24 + a25 + a26 + a27 + 634 ((long) a28) + a29 + a30 + a31 + a32 + a33 + a34 + ((intptr_t) a35) + 635 ((long) a36) + ((long) a37) + a38 + a39 + a40 + a41 + a42 + a43 + a44 + 636 ((intptr_t) a45) + a46 + a47 + ((long) a48) + a49 + a50 + 637 ((long) a51) + a52 + a53 + ((long) a54) + a55 + a56 + a57 + ((long) a58) + 638 ((long) a59) + ((long) a60) + ((intptr_t) a61) + 639 ((intptr_t) a62) + a63 + a64 + a65 + a66 + a67 + a68 + 640 ((intptr_t) a69) + ((long) a70) + ((long) a71) + a72 + a73 + a74 + 641 a75 + a76 + a77 + a78 + a79 + ((long) a80) + a81 + a82 + ((long) a83) + 642 a84 + a85 + ((long) a86) + a87 + a88 + a89 + ((long) a90) + a91 + a92 + 643 a93 + a94 + ((long) a95) + a96 + ((long) a97) + a98 + a99 + a100 + a101 + 644 a102 + a103 + a104 + a105 + a106 + a107 + a108 + a109 + a110 + a111 + 645 ((long) a112) + a113 + a114 + a115 + a116 + a117 + a118 + a119 + 646 ((long) a120) + ((intptr_t) a121) + ((long) a122) + a123 + a124 + 647 a125 + a126 + ((long) a127); 648 } 649 650 /* 651 * DEFCFUN.BFF.2 652 * 653 * (let ((rettype (find-type :long-long)) 654 * (arg-types (n-random-types 127))) 655 * (c-function rettype arg-types) 656 * (gen-function-test rettype arg-types)) 657 */ 658 659 DLLEXPORT long long sum_127 660 (void* a1, void* a2, float a3, unsigned long a4, void* a5, long long 661 a6, double a7, double a8, unsigned short a9, int a10, long long a11, 662 long a12, short a13, unsigned int a14, long a15, unsigned char a16, 663 int a17, double a18, short a19, short a20, long long a21, unsigned 664 int a22, unsigned short a23, short a24, void* a25, short a26, 665 unsigned short a27, unsigned short a28, int a29, long long a30, 666 void* a31, int a32, unsigned long a33, unsigned long a34, void* a35, 667 unsigned long long a36, float a37, int a38, short a39, void* a40, 668 unsigned long long a41, long long a42, unsigned long a43, unsigned 669 long a44, unsigned long long a45, unsigned long a46, char a47, 670 double a48, long a49, unsigned int a50, int a51, short a52, void* 671 a53, long a54, unsigned long long a55, int a56, unsigned short a57, 672 unsigned long long a58, float a59, void* a60, float a61, unsigned 673 short a62, unsigned long a63, float a64, unsigned int a65, unsigned 674 long long a66, void* a67, double a68, unsigned long long a69, double 675 a70, double a71, long long a72, void* a73, unsigned short a74, long 676 a75, void* a76, short a77, double a78, long a79, unsigned char a80, 677 void* a81, unsigned char a82, long a83, double a84, void* a85, int 678 a86, double a87, unsigned char a88, double a89, short a90, long a91, 679 int a92, long a93, double a94, unsigned short a95, unsigned int a96, 680 int a97, char a98, long long a99, double a100, float a101, unsigned 681 long a102, short a103, void* a104, float a105, long long a106, int 682 a107, long long a108, long long a109, double a110, unsigned long 683 long a111, double a112, unsigned long a113, char a114, char a115, 684 unsigned long a116, short a117, unsigned char a118, unsigned char 685 a119, int a120, int a121, float a122, unsigned char a123, unsigned 686 char a124, double a125, unsigned long long a126, char a127) 687 { 688 return (long long) ((intptr_t) a1) + ((intptr_t) a2) + ((long) a3) + 689 a4 + ((intptr_t) a5) + a6 + ((long) a7) + ((long) a8) + a9 + a10 + 690 a11 + a12 + a13 + a14 + a15 + a16 + a17 + ((long) a18) + a19 + a20 + 691 a21 + a22 + a23 + a24 + ((intptr_t) a25) + a26 + a27 + a28 + a29 + 692 a30 + ((intptr_t) a31) + a32 + a33 + a34 + ((intptr_t) a35) + 693 a36 + ((long) a37) + a38 + a39 + ((intptr_t) a40) + a41 + a42 + a43 + 694 a44 + a45 + a46 + a47 + ((long) a48) + a49 + a50 + a51 + a52 + 695 ((intptr_t) a53) + a54 + a55 + a56 + a57 + a58 + ((long) a59) + 696 ((intptr_t) a60) + ((long) a61) + a62 + a63 + ((long) a64) + a65 + a66 697 + ((intptr_t) a67) + ((long) a68) + a69 + ((long) a70) + ((long) a71) + 698 a72 + ((intptr_t) a73) + a74 + a75 + ((intptr_t) a76) + a77 + 699 ((long) a78) + a79 + a80 + ((intptr_t) a81) + a82 + a83 + ((long) a84) 700 + ((intptr_t) a85) + a86 + ((long) a87) + a88 + ((long) a89) + a90 + 701 a91 + a92 + a93 + ((long) a94) + a95 + a96 + a97 + a98 + a99 + 702 ((long) a100) + ((long) a101) + a102 + a103 + ((intptr_t) a104) + 703 ((long) a105) + a106 + a107 + a108 + a109 + ((long) a110) + a111 + 704 ((long) a112) + a113 + a114 + a115 + a116 + a117 + a118 + a119 + a120 + 705 a121 + ((long) a122) + a123 + a124 + ((long) a125) + a126 + a127; 706 } 707 708 /* 709 * CALLBACKS.BFF.1 (cb-test :no-long-long t) 710 */ 711 712 DLLEXPORT long call_sum_127_no_ll 713 (long (*func) 714 (unsigned long, void*, long, double, unsigned long, float, float, 715 int, unsigned int, double, double, double, void*, unsigned short, 716 unsigned short, void*, long, long, int, short, unsigned short, 717 unsigned short, char, long, void*, void*, char, unsigned char, 718 unsigned long, short, int, int, unsigned char, short, long, long, 719 void*, unsigned short, char, double, unsigned short, void*, short, 720 unsigned long, unsigned short, float, unsigned char, short, float, 721 short, char, unsigned long, unsigned long, char, float, long, void*, 722 short, float, unsigned int, float, unsigned int, double, unsigned int, 723 unsigned char, int, long, char, short, double, int, void*, char, 724 unsigned short, void*, unsigned short, void*, unsigned long, double, 725 void*, long, float, unsigned short, unsigned short, void*, float, int, 726 unsigned int, double, float, long, void*, unsigned short, float, 727 unsigned char, unsigned char, float, unsigned int, float, unsigned 728 short, double, unsigned short, unsigned long, unsigned int, unsigned 729 long, void*, unsigned char, char, char, unsigned short, unsigned long, 730 float, short, void*, long, unsigned short, short, double, short, int, 731 char, unsigned long, long, int, void*, double, unsigned char)) 732 { 733 return 734 func(948223085, (void *) 803308438, -465723152, 20385, 735 219679466, -10035, 13915, -1193455756, 1265303699, 27935, -18478, 736 -10508, (void *) 215389089, 55561, 55472, (void *) 146070433, 737 -1040819989, -17851453, -1622662247, -19473, 20837, 30216, 79, 738 986800400, (void *) 390281604, (void *) 1178532858, 19, 117, 739 78337699, -5718, -991300738, 872160910, 184, 926, -1487245383, 740 1633973783, (void *) 33738609, 53985, -116, 31645, 27196, (void *) 741 145569903, -6960, 17252220, 47404, -10491, 88, -30438, -21212, 742 -1982, -16, 1175270, 7949380, -121, 8559, -432968526, (void *) 743 293455312, 11894, -8394, 142421516, -25758, 3422998, 4004, 744 15758212, 198, -1071899743, -1284904617, -11, -17219, -30039, 745 311589092, (void *) 541468577, 123, 63517, (void *) 1252504506, 746 39368, (void *) 10057868, 134781408, -7143, (void *) 72825877, 747 -1190798667, -30862, 63757, 14965, (void *) 802391252, 22008, 748 -517289619, 806091099, 1125, 451, -498145176, (void *) 55960931, 749 15379, 4629, 184, 254, 22532, 465856451, -1669, 49416, -16546, 750 2983, 4337541, 65292495, 39253529, (void *) 669025, 211, 85, -19, 751 24298, 65358, 16776, -29957, (void *) 124311, -163231228, 2610, 752 -7806, 26434, -21913, -753615541, 120, 358697932, -1198889034, 753 -2131350926, (void *) 3749492036, -13413, 17); 754 } 755 756 /* 757 * CALLBACKS.BFF.2 (cb-test) 758 */ 759 760 DLLEXPORT long long call_sum_127 761 (long long (*func) 762 (short, char, void*, float, long, double, unsigned long long, 763 unsigned short, unsigned char, char, char, unsigned short, unsigned 764 long long, unsigned short, long long, unsigned short, unsigned long 765 long, unsigned char, unsigned char, unsigned long long, long long, 766 char, float, unsigned int, float, float, unsigned int, float, char, 767 unsigned char, long, long long, unsigned char, double, long, 768 double, unsigned int, unsigned short, long long, unsigned int, int, 769 unsigned long long, long, short, unsigned int, unsigned int, 770 unsigned long long, unsigned int, long, void*, unsigned char, char, 771 long long, unsigned short, unsigned int, float, unsigned char, 772 unsigned long, long long, float, long, float, int, float, unsigned 773 short, unsigned long long, short, unsigned long, long, char, 774 unsigned short, long long, short, double, void*, unsigned int, 775 char, unsigned int, void*, void*, unsigned char, void*, unsigned 776 short, unsigned char, long, void*, char, long, unsigned short, 777 unsigned char, double, unsigned long long, unsigned short, unsigned 778 short, unsigned int, long, char, long, char, short, unsigned short, 779 unsigned long, unsigned long, short, long long, long long, long 780 long, double, unsigned short, unsigned char, short, unsigned char, 781 long, long long, unsigned long long, unsigned int, unsigned long, 782 unsigned char, long long, unsigned char, unsigned long long, 783 double, unsigned char, long long, unsigned char, char, long long)) 784 { 785 return 786 func(-8573, 14, (void *) 832601021, -32334, -1532040888, 787 -18478, 2793023182591311826, 2740, 230, 103, 97, 13121, 788 5112369026351511084, 7763, -8134147951003417418, 34348, 789 5776613699556468853, 19, 122, 1431603726926527625, 790 439503521880490337, -112, -21557, 1578969190, -22008, -4953, 791 2127745975, -7262, -6, 180, 226352974, -3928775366167459219, 134, 792 -17730, -1175042526, 23868, 3494181009, 57364, 793 3134876875147518682, 104531655, -1286882727, 803577887579693487, 794 1349268803, 24912, 3313099419, 3907347884, 1738833249233805034, 795 2794230885, 1008818752, (void *) 1820044575, 189, 61, 796 -931654560961745071, 57531, 3096859985, 10405, 220, 3631311224, 797 -8531370353478907668, 31258, 678896693, -32150, -1869057813, 798 -19877, 62841, 4161660185772906873, -23869, 4016251006, 610353435, 799 105, 47315, -1051054492535331660, 6846, -15163, (void *) 800 736672359, 2123928476, -122, 3859258652, (void *) 3923394833, 801 (void *) 1265031970, 161, (void *) 1993867800, 55056, 122, 802 1562112760, (void *) 866615125, -79, -1261399547, 31737, 254, 803 -31279, 5462649659172897980, 5202, 7644, 174224940, -337854382, 804 -45, -583502442, -37, -13266, 24520, 2198606699, 2890453969, 805 -8282, -2295716637858246075, -1905178488651598878, 806 -6384652209316714643, 14841, 35443, 132, 15524, 187, 2138878229, 807 -5153032566879951000, 9056545530140684207, 4124632010, 276167701, 808 56, -2307310370663738730, 66, 9113015627153789746, -9618, 167, 809 755753399701306200, 119, -28, -990561962725435433); 810 } 811 812 /* 813 * CALLBACKS.DOUBLE26 814 */ 815 816 DLLEXPORT double call_double26 817 (double (*f)(double, double, double, double, double, double, double, double, 818 double, double, double, double, double, double, double, double, 819 double, double, double, double, double, double, double, double, 820 double, double)) 821 { 822 return f(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, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 3.14, 824 3.14, 3.14, 3.14, 3.14); 825 } 826 827 /* 828 * DEFCFUN.DOUBLE26 and FUNCALL.DOUBLE26 829 */ 830 831 DLLEXPORT 832 double sum_double26(double a1, double a2, double a3, double a4, double a5, 833 double a6, double a7, double a8, double a9, double a10, 834 double a11, double a12, double a13, double a14, double a15, 835 double a16, double a17, double a18, double a19, double a20, 836 double a21, double a22, double a23, double a24, double a25, 837 double a26) 838 { 839 return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + 840 a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22 + a23 + a24 + a25 + 841 a26; 842 } 843 844 /* 845 * DEFCFUN.VARARGS.NOSTDLIB and FUNCALL.VARARGS.NOSTDLIB 846 */ 847 DLLEXPORT 848 double sum_double_arbitrary(int n, ...) 849 { 850 va_list ap; 851 double sum = 0; 852 va_start(ap, n); 853 for(int j=0; j<n; j++) 854 sum += va_arg(ap, double); 855 va_end(ap); 856 return sum; 857 } 858 859 /* 860 * CALLBACKS.FLOAT26 861 */ 862 863 DLLEXPORT float call_float26 864 (float (*f)(float, float, float, float, float, float, float, float, 865 float, float, float, float, float, float, float, float, 866 float, float, float, float, float, float, float, float, 867 float, float)) 868 { 869 return f(5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 870 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 871 5.0, 5.0, 5.0, 5.0); 872 } 873 874 /* 875 * DEFCFUN.FLOAT26 and FUNCALL.FLOAT26 876 */ 877 878 DLLEXPORT 879 float sum_float26(float a1, float a2, float a3, float a4, float a5, 880 float a6, float a7, float a8, float a9, float a10, 881 float a11, float a12, float a13, float a14, float a15, 882 float a16, float a17, float a18, float a19, float a20, 883 float a21, float a22, float a23, float a24, float a25, 884 float a26) 885 { 886 return a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 + a11 + a12 + a13 + 887 a14 + a15 + a16 + a17 + a18 + a19 + a20 + a21 + a22 + a23 + a24 + a25 + 888 a26; 889 } 890 891 /* 892 * Symbol case. 893 */ 894 895 DLLEXPORT int UPPERCASEINT1 = 12345; 896 DLLEXPORT int UPPER_CASE_INT1 = 23456; 897 DLLEXPORT int MiXeDCaSeInT1 = 34567; 898 DLLEXPORT int MiXeD_CaSe_InT1 = 45678; 899 900 DLLEXPORT int UPPERCASEINT2 = 12345; 901 DLLEXPORT int UPPER_CASE_INT2 = 23456; 902 DLLEXPORT int MiXeDCaSeInT2 = 34567; 903 DLLEXPORT int MiXeD_CaSe_InT2 = 45678; 904 905 DLLEXPORT int UPPERCASEINT3 = 12345; 906 DLLEXPORT int UPPER_CASE_INT3 = 23456; 907 DLLEXPORT int MiXeDCaSeInT3 = 34567; 908 DLLEXPORT int MiXeD_CaSe_InT3 = 45678; 909 910 /* 911 * FOREIGN-SYMBOL-POINTER.1 912 */ 913 914 DLLEXPORT int compare_against_abs(intptr_t p) 915 { 916 return p == (intptr_t) abs; 917 } 918 919 /* 920 * FOREIGN-SYMBOL-POINTER.2 921 */ 922 923 DLLEXPORT void xpto_fun() {} 924 925 DLLEXPORT 926 int compare_against_xpto_fun(intptr_t p) 927 { 928 return p == (intptr_t) xpto_fun; 929 } 930 931 /* 932 * [DEFCFUN|FUNCALL].NAMESPACE.1 933 */ 934 935 DLLEXPORT 936 int ns_function() 937 { 938 return 1; 939 } 940 941 /* 942 * FOREIGN-GLOBALS.NAMESPACE.* 943 */ 944 945 DLLEXPORT int ns_var = 1; 946 947 /* 948 * DEFCFUN.STDCALL.1 949 */ 950 951 DLLEXPORT 952 int STDCALL stdcall_fun(int a, int b, int c) 953 { 954 return a + b + c; 955 } 956 957 /* 958 * CALLBACKS.STDCALL.1 959 */ 960 961 DLLEXPORT 962 int call_stdcall_fun(int (STDCALL *f)(int, int, int)) 963 { 964 int a = 42; 965 f(1, 2, 3); 966 return a; 967 } 968 969 /* Unlike the one above, this commented test below actually 970 * works. But, alas, it doesn't compile with -std=c99. */ 971 972 /* 973 DLLEXPORT 974 int call_stdcall_fun(int __attribute__((stdcall)) (*f)(int, int, int)) 975 { 976 asm("pushl $42"); 977 register int ebx asm("%ebx"); 978 f(1, 2, 3); 979 asm("popl %ebx"); 980 return ebx; 981 } 982 */ 983 984 /* vim: ts=4 et 985 */