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