7
#if defined(MS_WIN32) || defined(__CYGWIN__)
8
#define EXPORT(x) __declspec(dllexport) x
13
/* some functions handy for testing */
15
EXPORT(void)testfunc_array(int values[4])
17
printf("testfunc_array %d %d %d %d\n",
24
EXPORT(long double)testfunc_Ddd(double a, double b)
26
long double result = (long double)(a * b);
27
printf("testfunc_Ddd(%p, %p)\n", &a, &b);
28
printf("testfunc_Ddd(%g, %g)\n", a, b);
32
EXPORT(long double)testfunc_DDD(long double a, long double b)
34
long double result = a * b;
35
printf("testfunc_DDD(%p, %p)\n", &a, &b);
36
printf("testfunc_DDD(%Lg, %Lg)\n", a, b);
40
EXPORT(int)testfunc_iii(int a, int b)
43
printf("testfunc_iii(%p, %p)\n", &a, &b);
47
EXPORT(int)myprintf(char *fmt, ...)
51
va_start(argptr, fmt);
52
result = vprintf(fmt, argptr);
57
EXPORT(char *)my_strtok(char *token, const char *delim)
59
return strtok(token, delim);
62
EXPORT(char *)my_strchr(const char *s, int c)
68
EXPORT(double) my_sqrt(double a)
73
EXPORT(void) my_qsort(void *base, size_t num, size_t width, int(*compare)(const void*, const void*))
75
qsort(base, num, width, compare);
78
EXPORT(int *) _testfunc_ai8(int a[8])
83
EXPORT(void) _testfunc_v(int a, int b, int *presult)
88
EXPORT(int) _testfunc_i_bhilfd(signed char b, short h, int i, long l, float f, double d)
90
/* printf("_testfunc_i_bhilfd got %d %d %d %ld %f %f\n",
93
return (int)(b + h + i + l + f + d);
96
EXPORT(float) _testfunc_f_bhilfd(signed char b, short h, int i, long l, float f, double d)
98
/* printf("_testfunc_f_bhilfd got %d %d %d %ld %f %f\n",
101
return (float)(b + h + i + l + f + d);
104
EXPORT(double) _testfunc_d_bhilfd(signed char b, short h, int i, long l, float f, double d)
106
/* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n",
109
return (double)(b + h + i + l + f + d);
112
EXPORT(long double) _testfunc_D_bhilfD(signed char b, short h, int i, long l, float f, long double d)
114
/* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n",
117
return (long double)(b + h + i + l + f + d);
120
EXPORT(char *) _testfunc_p_p(void *s)
125
EXPORT(void *) _testfunc_c_p_p(int *argcp, char **argv)
127
return argv[(*argcp)-1];
130
EXPORT(void *) get_strchr(void)
132
return (void *)strchr;
135
EXPORT(char *) my_strdup(char *src)
137
char *dst = (char *)malloc(strlen(src)+1);
144
EXPORT(void)my_free(void *ptr)
150
EXPORT(wchar_t *) my_wcsdup(wchar_t *src)
152
size_t len = wcslen(src);
153
wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t));
156
memcpy(ptr, src, (len+1) * sizeof(wchar_t));
160
EXPORT(size_t) my_wcslen(wchar_t *src)
168
# define __stdcall /* */
174
int (__stdcall *s)(int, int);
177
EXPORT(int) _testfunc_callfuncp(FUNCS *fp)
184
EXPORT(int) _testfunc_deref_pointer(int *pi)
190
EXPORT(int) _testfunc_piunk(IUnknown FAR *piunk)
192
piunk->lpVtbl->AddRef(piunk);
193
return piunk->lpVtbl->Release(piunk);
197
EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *))
199
int table[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
201
return (*func)(table);
204
#ifdef HAVE_LONG_LONG
205
EXPORT(PY_LONG_LONG) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f,
206
double d, PY_LONG_LONG q)
208
return (PY_LONG_LONG)(b + h + i + l + f + d + q);
211
EXPORT(PY_LONG_LONG) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d)
213
return (PY_LONG_LONG)(b + h + i + l + f + d);
216
EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int))
226
EXPORT(PY_LONG_LONG) _testfunc_callback_q_qf(PY_LONG_LONG value,
227
PY_LONG_LONG (*func)(PY_LONG_LONG))
229
PY_LONG_LONG sum = 0;
252
{ "name1", "value1" },
253
{ "name2", "value2" },
257
{ "first egg", 1, my_spams }
260
EXPORT(int) getSPAMANDEGGS(EGG **eggs)
266
typedef struct tagpoint {
271
EXPORT(int) _testfunc_byval(point in, point *pout)
280
EXPORT (int) an_integer = 42;
282
EXPORT(int) get_an_integer(void)
288
integrate(double a, double b, double (*f)(double), long nstep)
290
double x, sum=0.0, dx=(b-a)/(double)nstep;
291
for(x=a+0.5*dx; (b-x)*(x-a)>0.0; x+=dx)
293
return sum/(double)nstep;
297
void (*initialize)(void *(*)(int), void(*)(void *));
300
static void _xxx_init(void *(*Xalloc)(int), void (*Xfree)(void *))
304
printf("_xxx_init got %p %p\n", Xalloc, Xfree);
308
printf("calls done, ptr was %p\n", ptr);
311
xxx_library _xxx_lib = {
315
EXPORT(xxx_library) *library_get(void)
321
/* See Don Box (german), pp 79ff. */
322
EXPORT(void) GetString(BSTR *pbstr)
324
*pbstr = SysAllocString(L"Goodbye!");
329
* Some do-nothing functions, for speed tests
331
PyObject *py_func_si(PyObject *self, PyObject *args)
335
if (!PyArg_ParseTuple(args, "si", &name, &i))
341
EXPORT(void) _py_func_si(char *s, int i)
345
PyObject *py_func(PyObject *self, PyObject *args)
351
EXPORT(void) _py_func(void)
355
EXPORT(PY_LONG_LONG) last_tf_arg_s;
356
EXPORT(unsigned PY_LONG_LONG) last_tf_arg_u;
359
int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9;
360
short M: 1, N: 2, O: 3, P: 4, Q: 5, R: 6, S: 7;
363
EXPORT(void) set_bitfields(struct BITS *bits, char name, int value)
366
case 'A': bits->A = value; break;
367
case 'B': bits->B = value; break;
368
case 'C': bits->C = value; break;
369
case 'D': bits->D = value; break;
370
case 'E': bits->E = value; break;
371
case 'F': bits->F = value; break;
372
case 'G': bits->G = value; break;
373
case 'H': bits->H = value; break;
374
case 'I': bits->I = value; break;
376
case 'M': bits->M = value; break;
377
case 'N': bits->N = value; break;
378
case 'O': bits->O = value; break;
379
case 'P': bits->P = value; break;
380
case 'Q': bits->Q = value; break;
381
case 'R': bits->R = value; break;
382
case 'S': bits->S = value; break;
386
EXPORT(int) unpack_bitfields(struct BITS *bits, char name)
389
case 'A': return bits->A;
390
case 'B': return bits->B;
391
case 'C': return bits->C;
392
case 'D': return bits->D;
393
case 'E': return bits->E;
394
case 'F': return bits->F;
395
case 'G': return bits->G;
396
case 'H': return bits->H;
397
case 'I': return bits->I;
399
case 'M': return bits->M;
400
case 'N': return bits->N;
401
case 'O': return bits->O;
402
case 'P': return bits->P;
403
case 'Q': return bits->Q;
404
case 'R': return bits->R;
405
case 'S': return bits->S;
410
static PyMethodDef module_methods[] = {
411
/* {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS},
412
{"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS},
414
{"func_si", py_func_si, METH_VARARGS},
415
{"func", py_func, METH_NOARGS},
416
{ NULL, NULL, 0, NULL},
419
#define S last_tf_arg_s = (PY_LONG_LONG)c
420
#define U last_tf_arg_u = (unsigned PY_LONG_LONG)c
422
EXPORT(signed char) tf_b(signed char c) { S; return c/3; }
423
EXPORT(unsigned char) tf_B(unsigned char c) { U; return c/3; }
424
EXPORT(short) tf_h(short c) { S; return c/3; }
425
EXPORT(unsigned short) tf_H(unsigned short c) { U; return c/3; }
426
EXPORT(int) tf_i(int c) { S; return c/3; }
427
EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; }
428
EXPORT(long) tf_l(long c) { S; return c/3; }
429
EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; }
430
EXPORT(PY_LONG_LONG) tf_q(PY_LONG_LONG c) { S; return c/3; }
431
EXPORT(unsigned PY_LONG_LONG) tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; }
432
EXPORT(float) tf_f(float c) { S; return c/3; }
433
EXPORT(double) tf_d(double c) { S; return c/3; }
434
EXPORT(long double) tf_D(long double c) { S; return c/3; }
437
EXPORT(signed char) __stdcall s_tf_b(signed char c) { S; return c/3; }
438
EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { U; return c/3; }
439
EXPORT(short) __stdcall s_tf_h(short c) { S; return c/3; }
440
EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { U; return c/3; }
441
EXPORT(int) __stdcall s_tf_i(int c) { S; return c/3; }
442
EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; }
443
EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; }
444
EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; }
445
EXPORT(PY_LONG_LONG) __stdcall s_tf_q(PY_LONG_LONG c) { S; return c/3; }
446
EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_Q(unsigned PY_LONG_LONG c) { U; return c/3; }
447
EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; }
448
EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; }
449
EXPORT(long double) __stdcall s_tf_D(long double c) { S; return c/3; }
453
EXPORT(signed char) tf_bb(signed char x, signed char c) { S; return c/3; }
454
EXPORT(unsigned char) tf_bB(signed char x, unsigned char c) { U; return c/3; }
455
EXPORT(short) tf_bh(signed char x, short c) { S; return c/3; }
456
EXPORT(unsigned short) tf_bH(signed char x, unsigned short c) { U; return c/3; }
457
EXPORT(int) tf_bi(signed char x, int c) { S; return c/3; }
458
EXPORT(unsigned int) tf_bI(signed char x, unsigned int c) { U; return c/3; }
459
EXPORT(long) tf_bl(signed char x, long c) { S; return c/3; }
460
EXPORT(unsigned long) tf_bL(signed char x, unsigned long c) { U; return c/3; }
461
EXPORT(PY_LONG_LONG) tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; }
462
EXPORT(unsigned PY_LONG_LONG) tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; }
463
EXPORT(float) tf_bf(signed char x, float c) { S; return c/3; }
464
EXPORT(double) tf_bd(signed char x, double c) { S; return c/3; }
465
EXPORT(long double) tf_bD(signed char x, long double c) { S; return c/3; }
466
EXPORT(void) tv_i(int c) { S; return; }
469
EXPORT(signed char) __stdcall s_tf_bb(signed char x, signed char c) { S; return c/3; }
470
EXPORT(unsigned char) __stdcall s_tf_bB(signed char x, unsigned char c) { U; return c/3; }
471
EXPORT(short) __stdcall s_tf_bh(signed char x, short c) { S; return c/3; }
472
EXPORT(unsigned short) __stdcall s_tf_bH(signed char x, unsigned short c) { U; return c/3; }
473
EXPORT(int) __stdcall s_tf_bi(signed char x, int c) { S; return c/3; }
474
EXPORT(unsigned int) __stdcall s_tf_bI(signed char x, unsigned int c) { U; return c/3; }
475
EXPORT(long) __stdcall s_tf_bl(signed char x, long c) { S; return c/3; }
476
EXPORT(unsigned long) __stdcall s_tf_bL(signed char x, unsigned long c) { U; return c/3; }
477
EXPORT(PY_LONG_LONG) __stdcall s_tf_bq(signed char x, PY_LONG_LONG c) { S; return c/3; }
478
EXPORT(unsigned PY_LONG_LONG) __stdcall s_tf_bQ(signed char x, unsigned PY_LONG_LONG c) { U; return c/3; }
479
EXPORT(float) __stdcall s_tf_bf(signed char x, float c) { S; return c/3; }
480
EXPORT(double) __stdcall s_tf_bd(signed char x, double c) { S; return c/3; }
481
EXPORT(long double) __stdcall s_tf_bD(signed char x, long double c) { S; return c/3; }
482
EXPORT(void) __stdcall s_tv_i(int c) { S; return; }
503
EXPORT(int) PointInRect(RECT *prc, POINT pt)
505
if (pt.x < prc->left)
507
if (pt.x > prc->right)
511
if (pt.y > prc->bottom)
521
EXPORT(S2H) ret_2h_func(S2H inp)
529
int a, b, c, d, e, f, g, h;
532
EXPORT(S8I) ret_8i_func(S8I inp)
545
EXPORT(int) GetRectangle(int flag, RECT *prect)
549
prect->left = (int)flag;
550
prect->top = (int)flag + 1;
551
prect->right = (int)flag + 2;
552
prect->bottom = (int)flag + 3;
556
EXPORT(void) TwoOutArgs(int a, int *pi, int b, int *pj)
563
EXPORT(S2H) __stdcall s_ret_2h_func(S2H inp) { return ret_2h_func(inp); }
564
EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); }
568
/* Should port this */
572
EXPORT (HRESULT) KeepObject(IUnknown *punk)
574
static IUnknown *pobj;
576
punk->lpVtbl->AddRef(punk);
578
pobj->lpVtbl->Release(pobj);
586
static struct PyModuleDef _ctypes_testmodule = {
587
PyModuleDef_HEAD_INIT,
599
PyInit__ctypes_test(void)
601
return PyModule_Create(&_ctypes_testmodule);