1 #include <Python.h> 2 3 #ifdef MS_WIN32 4 #include <windows.h> 5 #endif 6 7 #if defined(MS_WIN32) || defined(__CYGWIN__) 8 #define EXPORT(x) __declspec(dllexport) x 9 #else 10 #define EXPORT(x) x 11 #endif 12 13 /* some functions handy for testing */ 14 15 EXPORT(int) 16 _testfunc_cbk_reg_int(int a, int b, int c, int d, int e, 17 int (*func)(int, int, int, int, int)) 18 { 19 return func(a*a, b*b, c*c, d*d, e*e); 20 } 21 22 EXPORT(double) 23 _testfunc_cbk_reg_double(double a, double b, double c, double d, double e, 24 double (*func)(double, double, double, double, double)) 25 { 26 return func(a*a, b*b, c*c, d*d, e*e); 27 } 28 29 /* 30 * This structure should be the same as in test_callbacks.py and the 31 * method test_callback_large_struct. See issues 17310 and 20160: the 32 * structure must be larger than 8 bytes long. 33 */ 34 35 typedef struct { 36 unsigned long first; 37 unsigned long second; 38 unsigned long third; 39 } Test; 40 41 EXPORT(void) 42 _testfunc_cbk_large_struct(Test in, void (*func)(Test)) 43 { 44 func(in); 45 } 46 47 /* 48 * See issue 29565. Update a structure passed by value; 49 * the caller should not see any change. 50 */ 51 52 EXPORT(void) 53 _testfunc_large_struct_update_value(Test in) 54 { 55 ((volatile Test *)&in)->first = 0x0badf00d; 56 ((volatile Test *)&in)->second = 0x0badf00d; 57 ((volatile Test *)&in)->third = 0x0badf00d; 58 } 59 60 typedef struct { 61 unsigned int first; 62 unsigned int second; 63 } TestReg; 64 65 66 EXPORT(TestReg) last_tfrsuv_arg = {0}; 67 68 69 EXPORT(void) 70 _testfunc_reg_struct_update_value(TestReg in) 71 { 72 last_tfrsuv_arg = in; 73 ((volatile TestReg *)&in)->first = 0x0badf00d; 74 ((volatile TestReg *)&in)->second = 0x0badf00d; 75 } 76 77 78 EXPORT(void)testfunc_array(int values[4]) 79 { 80 printf("testfunc_array %d %d %d %d\n", 81 values[0], 82 values[1], 83 values[2], 84 values[3]); 85 } 86 87 EXPORT(long double)testfunc_Ddd(double a, double b) 88 { 89 long double result = (long double)(a * b); 90 printf("testfunc_Ddd(%p, %p)\n", &a, &b); 91 printf("testfunc_Ddd(%g, %g)\n", a, b); 92 return result; 93 } 94 95 EXPORT(long double)testfunc_DDD(long double a, long double b) 96 { 97 long double result = a * b; 98 printf("testfunc_DDD(%p, %p)\n", &a, &b); 99 printf("testfunc_DDD(%Lg, %Lg)\n", a, b); 100 return result; 101 } 102 103 EXPORT(int)testfunc_iii(int a, int b) 104 { 105 int result = a * b; 106 printf("testfunc_iii(%p, %p)\n", &a, &b); 107 return result; 108 } 109 110 EXPORT(int)myprintf(char *fmt, ...) 111 { 112 int result; 113 va_list argptr; 114 va_start(argptr, fmt); 115 result = vprintf(fmt, argptr); 116 va_end(argptr); 117 return result; 118 } 119 120 EXPORT(char *)my_strtok(char *token, const char *delim) 121 { 122 return strtok(token, delim); 123 } 124 125 EXPORT(char *)my_strchr(const char *s, int c) 126 { 127 return strchr(s, c); 128 } 129 130 131 EXPORT(double) my_sqrt(double a) 132 { 133 return sqrt(a); 134 } 135 136 EXPORT(void) my_qsort(void *base, size_t num, size_t width, int(*compare)(const void*, const void*)) 137 { 138 qsort(base, num, width, compare); 139 } 140 141 EXPORT(int *) _testfunc_ai8(int a[8]) 142 { 143 return a; 144 } 145 146 EXPORT(void) _testfunc_v(int a, int b, int *presult) 147 { 148 *presult = a + b; 149 } 150 151 EXPORT(int) _testfunc_i_bhilfd(signed char b, short h, int i, long l, float f, double d) 152 { 153 /* printf("_testfunc_i_bhilfd got %d %d %d %ld %f %f\n", 154 b, h, i, l, f, d); 155 */ 156 return (int)(b + h + i + l + f + d); 157 } 158 159 EXPORT(float) _testfunc_f_bhilfd(signed char b, short h, int i, long l, float f, double d) 160 { 161 /* printf("_testfunc_f_bhilfd got %d %d %d %ld %f %f\n", 162 b, h, i, l, f, d); 163 */ 164 return (float)(b + h + i + l + f + d); 165 } 166 167 EXPORT(double) _testfunc_d_bhilfd(signed char b, short h, int i, long l, float f, double d) 168 { 169 /* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n", 170 b, h, i, l, f, d); 171 */ 172 return (double)(b + h + i + l + f + d); 173 } 174 175 EXPORT(long double) _testfunc_D_bhilfD(signed char b, short h, int i, long l, float f, long double d) 176 { 177 /* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n", 178 b, h, i, l, f, d); 179 */ 180 return (long double)(b + h + i + l + f + d); 181 } 182 183 EXPORT(char *) _testfunc_p_p(void *s) 184 { 185 return (char *)s; 186 } 187 188 EXPORT(void *) _testfunc_c_p_p(int *argcp, char **argv) 189 { 190 return argv[(*argcp)-1]; 191 } 192 193 EXPORT(void *) get_strchr(void) 194 { 195 return (void *)strchr; 196 } 197 198 EXPORT(char *) my_strdup(char *src) 199 { 200 char *dst = (char *)malloc(strlen(src)+1); 201 if (!dst) 202 return NULL; 203 strcpy(dst, src); 204 return dst; 205 } 206 207 EXPORT(void)my_free(void *ptr) 208 { 209 free(ptr); 210 } 211 212 #ifdef HAVE_WCHAR_H 213 EXPORT(wchar_t *) my_wcsdup(wchar_t *src) 214 { 215 size_t len = wcslen(src); 216 wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); 217 if (ptr == NULL) 218 return NULL; 219 memcpy(ptr, src, (len+1) * sizeof(wchar_t)); 220 return ptr; 221 } 222 223 EXPORT(size_t) my_wcslen(wchar_t *src) 224 { 225 return wcslen(src); 226 } 227 #endif 228 229 #ifndef MS_WIN32 230 # ifndef __stdcall 231 # define __stdcall /* */ 232 # endif 233 #endif 234 235 typedef struct { 236 int (*c)(int, int); 237 int (__stdcall *s)(int, int); 238 } FUNCS; 239 240 EXPORT(int) _testfunc_callfuncp(FUNCS *fp) 241 { 242 fp->c(1, 2); 243 fp->s(3, 4); 244 return 0; 245 } 246 247 EXPORT(int) _testfunc_deref_pointer(int *pi) 248 { 249 return *pi; 250 } 251 252 #ifdef MS_WIN32 253 EXPORT(int) _testfunc_piunk(IUnknown FAR *piunk) 254 { 255 piunk->lpVtbl->AddRef(piunk); 256 return piunk->lpVtbl->Release(piunk); 257 } 258 #endif 259 260 EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *)) 261 { 262 int table[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 263 264 return (*func)(table); 265 } 266 267 EXPORT(long long) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f, 268 double d, long long q) 269 { 270 return (long long)(b + h + i + l + f + d + q); 271 } 272 273 EXPORT(long long) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d) 274 { 275 return (long long)(b + h + i + l + f + d); 276 } 277 278 EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int)) 279 { 280 int sum = 0; 281 while (value != 0) { 282 sum += func(value); 283 value /= 2; 284 } 285 return sum; 286 } 287 288 EXPORT(long long) _testfunc_callback_q_qf(long long value, 289 long long (*func)(long long)) 290 { 291 long long sum = 0; 292 293 while (value != 0) { 294 sum += func(value); 295 value /= 2; 296 } 297 return sum; 298 } 299 300 typedef struct { 301 char *name; 302 char *value; 303 } SPAM; 304 305 typedef struct { 306 char *name; 307 int num_spams; 308 SPAM *spams; 309 } EGG; 310 311 SPAM my_spams[2] = { 312 { "name1", "value1" }, 313 { "name2", "value2" }, 314 }; 315 316 EGG my_eggs[1] = { 317 { "first egg", 1, my_spams } 318 }; 319 320 EXPORT(int) getSPAMANDEGGS(EGG **eggs) 321 { 322 *eggs = my_eggs; 323 return 1; 324 } 325 326 typedef struct tagpoint { 327 int x; 328 int y; 329 } point; 330 331 EXPORT(int) _testfunc_byval(point in, point *pout) 332 { 333 if (pout) { 334 pout->x = in.x; 335 pout->y = in.y; 336 } 337 return in.x + in.y; 338 } 339 340 EXPORT (int) an_integer = 42; 341 342 EXPORT(int) get_an_integer(void) 343 { 344 return an_integer; 345 } 346 347 EXPORT(double) 348 integrate(double a, double b, double (*f)(double), long nstep) 349 { 350 double x, sum=0.0, dx=(b-a)/(double)nstep; 351 for(x=a+0.5*dx; (b-x)*(x-a)>0.0; x+=dx) 352 sum += f(x); 353 return sum/(double)nstep; 354 } 355 356 typedef struct { 357 void (*initialize)(void *(*)(int), void(*)(void *)); 358 } xxx_library; 359 360 static void _xxx_init(void *(*Xalloc)(int), void (*Xfree)(void *)) 361 { 362 void *ptr; 363 364 printf("_xxx_init got %p %p\n", Xalloc, Xfree); 365 printf("calling\n"); 366 ptr = Xalloc(32); 367 Xfree(ptr); 368 printf("calls done, ptr was %p\n", ptr); 369 } 370 371 xxx_library _xxx_lib = { 372 _xxx_init 373 }; 374 375 EXPORT(xxx_library) *library_get(void) 376 { 377 return &_xxx_lib; 378 } 379 380 #ifdef MS_WIN32 381 /* See Don Box (german), pp 79ff. */ 382 EXPORT(void) GetString(BSTR *pbstr) 383 { 384 *pbstr = SysAllocString(L"Goodbye!"); 385 } 386 #endif 387 388 /* 389 * Some do-nothing functions, for speed tests 390 */ 391 PyObject *py_func_si(PyObject *self, PyObject *args) 392 { 393 char *name; 394 int i; 395 if (!PyArg_ParseTuple(args, "si", &name, &i)) 396 return NULL; 397 Py_RETURN_NONE; 398 } 399 400 EXPORT(void) _py_func_si(char *s, int i) 401 { 402 } 403 404 PyObject *py_func(PyObject *self, PyObject *args) 405 { 406 Py_RETURN_NONE; 407 } 408 409 EXPORT(void) _py_func(void) 410 { 411 } 412 413 EXPORT(long long) last_tf_arg_s = 0; 414 EXPORT(unsigned long long) last_tf_arg_u = 0; 415 416 struct BITS { 417 int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9; 418 short M: 1, N: 2, O: 3, P: 4, Q: 5, R: 6, S: 7; 419 }; 420 421 EXPORT(void) set_bitfields(struct BITS *bits, char name, int value) 422 { 423 switch (name) { 424 case 'A': bits->A = value; break; 425 case 'B': bits->B = value; break; 426 case 'C': bits->C = value; break; 427 case 'D': bits->D = value; break; 428 case 'E': bits->E = value; break; 429 case 'F': bits->F = value; break; 430 case 'G': bits->G = value; break; 431 case 'H': bits->H = value; break; 432 case 'I': bits->I = value; break; 433 434 case 'M': bits->M = value; break; 435 case 'N': bits->N = value; break; 436 case 'O': bits->O = value; break; 437 case 'P': bits->P = value; break; 438 case 'Q': bits->Q = value; break; 439 case 'R': bits->R = value; break; 440 case 'S': bits->S = value; break; 441 } 442 } 443 444 EXPORT(int) unpack_bitfields(struct BITS *bits, char name) 445 { 446 switch (name) { 447 case 'A': return bits->A; 448 case 'B': return bits->B; 449 case 'C': return bits->C; 450 case 'D': return bits->D; 451 case 'E': return bits->E; 452 case 'F': return bits->F; 453 case 'G': return bits->G; 454 case 'H': return bits->H; 455 case 'I': return bits->I; 456 457 case 'M': return bits->M; 458 case 'N': return bits->N; 459 case 'O': return bits->O; 460 case 'P': return bits->P; 461 case 'Q': return bits->Q; 462 case 'R': return bits->R; 463 case 'S': return bits->S; 464 } 465 return 0; 466 } 467 468 static PyMethodDef module_methods[] = { 469 /* {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, 470 {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS}, 471 */ 472 {"func_si", py_func_si, METH_VARARGS}, 473 {"func", py_func, METH_NOARGS}, 474 { NULL, NULL, 0, NULL}, 475 }; 476 477 #define S last_tf_arg_s = (long long)c 478 #define U last_tf_arg_u = (unsigned long long)c 479 480 EXPORT(signed char) tf_b(signed char c) { S; return c/3; } 481 EXPORT(unsigned char) tf_B(unsigned char c) { U; return c/3; } 482 EXPORT(short) tf_h(short c) { S; return c/3; } 483 EXPORT(unsigned short) tf_H(unsigned short c) { U; return c/3; } 484 EXPORT(int) tf_i(int c) { S; return c/3; } 485 EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; } 486 EXPORT(long) tf_l(long c) { S; return c/3; } 487 EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; } 488 EXPORT(long long) tf_q(long long c) { S; return c/3; } 489 EXPORT(unsigned long long) tf_Q(unsigned long long c) { U; return c/3; } 490 EXPORT(float) tf_f(float c) { S; return c/3; } 491 EXPORT(double) tf_d(double c) { S; return c/3; } 492 EXPORT(long double) tf_D(long double c) { S; return c/3; } 493 494 #ifdef MS_WIN32 495 EXPORT(signed char) __stdcall s_tf_b(signed char c) { S; return c/3; } 496 EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { U; return c/3; } 497 EXPORT(short) __stdcall s_tf_h(short c) { S; return c/3; } 498 EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { U; return c/3; } 499 EXPORT(int) __stdcall s_tf_i(int c) { S; return c/3; } 500 EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; } 501 EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; } 502 EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; } 503 EXPORT(long long) __stdcall s_tf_q(long long c) { S; return c/3; } 504 EXPORT(unsigned long long) __stdcall s_tf_Q(unsigned long long c) { U; return c/3; } 505 EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; } 506 EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; } 507 EXPORT(long double) __stdcall s_tf_D(long double c) { S; return c/3; } 508 #endif 509 /*******/ 510 511 EXPORT(signed char) tf_bb(signed char x, signed char c) { S; return c/3; } 512 EXPORT(unsigned char) tf_bB(signed char x, unsigned char c) { U; return c/3; } 513 EXPORT(short) tf_bh(signed char x, short c) { S; return c/3; } 514 EXPORT(unsigned short) tf_bH(signed char x, unsigned short c) { U; return c/3; } 515 EXPORT(int) tf_bi(signed char x, int c) { S; return c/3; } 516 EXPORT(unsigned int) tf_bI(signed char x, unsigned int c) { U; return c/3; } 517 EXPORT(long) tf_bl(signed char x, long c) { S; return c/3; } 518 EXPORT(unsigned long) tf_bL(signed char x, unsigned long c) { U; return c/3; } 519 EXPORT(long long) tf_bq(signed char x, long long c) { S; return c/3; } 520 EXPORT(unsigned long long) tf_bQ(signed char x, unsigned long long c) { U; return c/3; } 521 EXPORT(float) tf_bf(signed char x, float c) { S; return c/3; } 522 EXPORT(double) tf_bd(signed char x, double c) { S; return c/3; } 523 EXPORT(long double) tf_bD(signed char x, long double c) { S; return c/3; } 524 EXPORT(void) tv_i(int c) { S; return; } 525 526 #ifdef MS_WIN32 527 EXPORT(signed char) __stdcall s_tf_bb(signed char x, signed char c) { S; return c/3; } 528 EXPORT(unsigned char) __stdcall s_tf_bB(signed char x, unsigned char c) { U; return c/3; } 529 EXPORT(short) __stdcall s_tf_bh(signed char x, short c) { S; return c/3; } 530 EXPORT(unsigned short) __stdcall s_tf_bH(signed char x, unsigned short c) { U; return c/3; } 531 EXPORT(int) __stdcall s_tf_bi(signed char x, int c) { S; return c/3; } 532 EXPORT(unsigned int) __stdcall s_tf_bI(signed char x, unsigned int c) { U; return c/3; } 533 EXPORT(long) __stdcall s_tf_bl(signed char x, long c) { S; return c/3; } 534 EXPORT(unsigned long) __stdcall s_tf_bL(signed char x, unsigned long c) { U; return c/3; } 535 EXPORT(long long) __stdcall s_tf_bq(signed char x, long long c) { S; return c/3; } 536 EXPORT(unsigned long long) __stdcall s_tf_bQ(signed char x, unsigned long long c) { U; return c/3; } 537 EXPORT(float) __stdcall s_tf_bf(signed char x, float c) { S; return c/3; } 538 EXPORT(double) __stdcall s_tf_bd(signed char x, double c) { S; return c/3; } 539 EXPORT(long double) __stdcall s_tf_bD(signed char x, long double c) { S; return c/3; } 540 EXPORT(void) __stdcall s_tv_i(int c) { S; return; } 541 #endif 542 543 /********/ 544 545 #ifndef MS_WIN32 546 547 typedef struct { 548 long x; 549 long y; 550 } POINT; 551 552 typedef struct { 553 long left; 554 long top; 555 long right; 556 long bottom; 557 } RECT; 558 559 #endif 560 561 EXPORT(int) PointInRect(RECT *prc, POINT pt) 562 { 563 if (pt.x < prc->left) 564 return 0; 565 if (pt.x > prc->right) 566 return 0; 567 if (pt.y < prc->top) 568 return 0; 569 if (pt.y > prc->bottom) 570 return 0; 571 return 1; 572 } 573 574 EXPORT(long left = 10); 575 EXPORT(long top = 20); 576 EXPORT(long right = 30); 577 EXPORT(long bottom = 40); 578 579 EXPORT(RECT) ReturnRect(int i, RECT ar, RECT* br, POINT cp, RECT dr, 580 RECT *er, POINT fp, RECT gr) 581 { 582 /*Check input */ 583 if (ar.left + br->left + dr.left + er->left + gr.left != left * 5) 584 { 585 ar.left = 100; 586 return ar; 587 } 588 if (ar.right + br->right + dr.right + er->right + gr.right != right * 5) 589 { 590 ar.right = 100; 591 return ar; 592 } 593 if (cp.x != fp.x) 594 { 595 ar.left = -100; 596 } 597 if (cp.y != fp.y) 598 { 599 ar.left = -200; 600 } 601 switch(i) 602 { 603 case 0: 604 return ar; 605 break; 606 case 1: 607 return dr; 608 break; 609 case 2: 610 return gr; 611 break; 612 613 } 614 return ar; 615 } 616 617 typedef struct { 618 short x; 619 short y; 620 } S2H; 621 622 EXPORT(S2H) ret_2h_func(S2H inp) 623 { 624 inp.x *= 2; 625 inp.y *= 3; 626 return inp; 627 } 628 629 typedef struct { 630 int a, b, c, d, e, f, g, h; 631 } S8I; 632 633 EXPORT(S8I) ret_8i_func(S8I inp) 634 { 635 inp.a *= 2; 636 inp.b *= 3; 637 inp.c *= 4; 638 inp.d *= 5; 639 inp.e *= 6; 640 inp.f *= 7; 641 inp.g *= 8; 642 inp.h *= 9; 643 return inp; 644 } 645 646 EXPORT(int) GetRectangle(int flag, RECT *prect) 647 { 648 if (flag == 0) 649 return 0; 650 prect->left = (int)flag; 651 prect->top = (int)flag + 1; 652 prect->right = (int)flag + 2; 653 prect->bottom = (int)flag + 3; 654 return 1; 655 } 656 657 EXPORT(void) TwoOutArgs(int a, int *pi, int b, int *pj) 658 { 659 *pi += a; 660 *pj += b; 661 } 662 663 #ifdef MS_WIN32 664 665 typedef struct { 666 char f1; 667 } Size1; 668 669 typedef struct { 670 char f1; 671 char f2; 672 } Size2; 673 674 typedef struct { 675 char f1; 676 char f2; 677 char f3; 678 } Size3; 679 680 typedef struct { 681 char f1; 682 char f2; 683 char f3; 684 char f4; 685 } Size4; 686 687 typedef struct { 688 char f1; 689 char f2; 690 char f3; 691 char f4; 692 char f5; 693 } Size5; 694 695 typedef struct { 696 char f1; 697 char f2; 698 char f3; 699 char f4; 700 char f5; 701 char f6; 702 } Size6; 703 704 typedef struct { 705 char f1; 706 char f2; 707 char f3; 708 char f4; 709 char f5; 710 char f6; 711 char f7; 712 } Size7; 713 714 typedef struct { 715 char f1; 716 char f2; 717 char f3; 718 char f4; 719 char f5; 720 char f6; 721 char f7; 722 char f8; 723 } Size8; 724 725 typedef struct { 726 char f1; 727 char f2; 728 char f3; 729 char f4; 730 char f5; 731 char f6; 732 char f7; 733 char f8; 734 char f9; 735 } Size9; 736 737 typedef struct { 738 char f1; 739 char f2; 740 char f3; 741 char f4; 742 char f5; 743 char f6; 744 char f7; 745 char f8; 746 char f9; 747 char f10; 748 } Size10; 749 750 EXPORT(Size1) TestSize1() { 751 Size1 f; 752 f.f1 = 'a'; 753 return f; 754 } 755 756 EXPORT(Size2) TestSize2() { 757 Size2 f; 758 f.f1 = 'a'; 759 f.f2 = 'b'; 760 return f; 761 } 762 763 EXPORT(Size3) TestSize3() { 764 Size3 f; 765 f.f1 = 'a'; 766 f.f2 = 'b'; 767 f.f3 = 'c'; 768 return f; 769 } 770 771 EXPORT(Size4) TestSize4() { 772 Size4 f; 773 f.f1 = 'a'; 774 f.f2 = 'b'; 775 f.f3 = 'c'; 776 f.f4 = 'd'; 777 return f; 778 } 779 780 EXPORT(Size5) TestSize5() { 781 Size5 f; 782 f.f1 = 'a'; 783 f.f2 = 'b'; 784 f.f3 = 'c'; 785 f.f4 = 'd'; 786 f.f5 = 'e'; 787 return f; 788 } 789 790 EXPORT(Size6) TestSize6() { 791 Size6 f; 792 f.f1 = 'a'; 793 f.f2 = 'b'; 794 f.f3 = 'c'; 795 f.f4 = 'd'; 796 f.f5 = 'e'; 797 f.f6 = 'f'; 798 return f; 799 } 800 801 EXPORT(Size7) TestSize7() { 802 Size7 f; 803 f.f1 = 'a'; 804 f.f2 = 'b'; 805 f.f3 = 'c'; 806 f.f4 = 'd'; 807 f.f5 = 'e'; 808 f.f6 = 'f'; 809 f.f7 = 'g'; 810 return f; 811 } 812 813 EXPORT(Size8) TestSize8() { 814 Size8 f; 815 f.f1 = 'a'; 816 f.f2 = 'b'; 817 f.f3 = 'c'; 818 f.f4 = 'd'; 819 f.f5 = 'e'; 820 f.f6 = 'f'; 821 f.f7 = 'g'; 822 f.f8 = 'h'; 823 return f; 824 } 825 826 EXPORT(Size9) TestSize9() { 827 Size9 f; 828 f.f1 = 'a'; 829 f.f2 = 'b'; 830 f.f3 = 'c'; 831 f.f4 = 'd'; 832 f.f5 = 'e'; 833 f.f6 = 'f'; 834 f.f7 = 'g'; 835 f.f8 = 'h'; 836 f.f9 = 'i'; 837 return f; 838 } 839 840 EXPORT(Size10) TestSize10() { 841 Size10 f; 842 f.f1 = 'a'; 843 f.f2 = 'b'; 844 f.f3 = 'c'; 845 f.f4 = 'd'; 846 f.f5 = 'e'; 847 f.f6 = 'f'; 848 f.f7 = 'g'; 849 f.f8 = 'h'; 850 f.f9 = 'i'; 851 f.f10 = 'j'; 852 return f; 853 } 854 855 #endif 856 857 #ifdef MS_WIN32 858 EXPORT(S2H) __stdcall s_ret_2h_func(S2H inp) { return ret_2h_func(inp); } 859 EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); } 860 #endif 861 862 #ifdef MS_WIN32 863 /* Should port this */ 864 #include <stdlib.h> 865 #include <search.h> 866 867 EXPORT (HRESULT) KeepObject(IUnknown *punk) 868 { 869 static IUnknown *pobj; 870 if (punk) 871 punk->lpVtbl->AddRef(punk); 872 if (pobj) 873 pobj->lpVtbl->Release(pobj); 874 pobj = punk; 875 return S_OK; 876 } 877 878 #endif 879 880 881 static struct PyModuleDef _ctypes_testmodule = { 882 PyModuleDef_HEAD_INIT, 883 "_ctypes_test", 884 NULL, 885 -1, 886 module_methods, 887 NULL, 888 NULL, 889 NULL, 890 NULL 891 }; 892 893 PyMODINIT_FUNC 894 PyInit__ctypes_test(void) 895 { 896 return PyModule_Create(&_ctypes_testmodule); 897 } 898