1 | n/a | #include <Python.h> |
---|
2 | n/a | |
---|
3 | n/a | #ifdef MS_WIN32 |
---|
4 | n/a | #include <windows.h> |
---|
5 | n/a | #endif |
---|
6 | n/a | |
---|
7 | n/a | #if defined(MS_WIN32) || defined(__CYGWIN__) |
---|
8 | n/a | #define EXPORT(x) __declspec(dllexport) x |
---|
9 | n/a | #else |
---|
10 | n/a | #define EXPORT(x) x |
---|
11 | n/a | #endif |
---|
12 | n/a | |
---|
13 | n/a | /* some functions handy for testing */ |
---|
14 | n/a | |
---|
15 | n/a | EXPORT(int) |
---|
16 | n/a | _testfunc_cbk_reg_int(int a, int b, int c, int d, int e, |
---|
17 | n/a | int (*func)(int, int, int, int, int)) |
---|
18 | n/a | { |
---|
19 | n/a | return func(a*a, b*b, c*c, d*d, e*e); |
---|
20 | n/a | } |
---|
21 | n/a | |
---|
22 | n/a | EXPORT(double) |
---|
23 | n/a | _testfunc_cbk_reg_double(double a, double b, double c, double d, double e, |
---|
24 | n/a | double (*func)(double, double, double, double, double)) |
---|
25 | n/a | { |
---|
26 | n/a | return func(a*a, b*b, c*c, d*d, e*e); |
---|
27 | n/a | } |
---|
28 | n/a | |
---|
29 | n/a | /* |
---|
30 | n/a | * This structure should be the same as in test_callbacks.py and the |
---|
31 | n/a | * method test_callback_large_struct. See issues 17310 and 20160: the |
---|
32 | n/a | * structure must be larger than 8 bytes long. |
---|
33 | n/a | */ |
---|
34 | n/a | |
---|
35 | n/a | typedef struct { |
---|
36 | n/a | unsigned long first; |
---|
37 | n/a | unsigned long second; |
---|
38 | n/a | unsigned long third; |
---|
39 | n/a | } Test; |
---|
40 | n/a | |
---|
41 | n/a | EXPORT(void) |
---|
42 | n/a | _testfunc_cbk_large_struct(Test in, void (*func)(Test)) |
---|
43 | n/a | { |
---|
44 | n/a | func(in); |
---|
45 | n/a | } |
---|
46 | n/a | |
---|
47 | n/a | EXPORT(void)testfunc_array(int values[4]) |
---|
48 | n/a | { |
---|
49 | n/a | printf("testfunc_array %d %d %d %d\n", |
---|
50 | n/a | values[0], |
---|
51 | n/a | values[1], |
---|
52 | n/a | values[2], |
---|
53 | n/a | values[3]); |
---|
54 | n/a | } |
---|
55 | n/a | |
---|
56 | n/a | EXPORT(long double)testfunc_Ddd(double a, double b) |
---|
57 | n/a | { |
---|
58 | n/a | long double result = (long double)(a * b); |
---|
59 | n/a | printf("testfunc_Ddd(%p, %p)\n", &a, &b); |
---|
60 | n/a | printf("testfunc_Ddd(%g, %g)\n", a, b); |
---|
61 | n/a | return result; |
---|
62 | n/a | } |
---|
63 | n/a | |
---|
64 | n/a | EXPORT(long double)testfunc_DDD(long double a, long double b) |
---|
65 | n/a | { |
---|
66 | n/a | long double result = a * b; |
---|
67 | n/a | printf("testfunc_DDD(%p, %p)\n", &a, &b); |
---|
68 | n/a | printf("testfunc_DDD(%Lg, %Lg)\n", a, b); |
---|
69 | n/a | return result; |
---|
70 | n/a | } |
---|
71 | n/a | |
---|
72 | n/a | EXPORT(int)testfunc_iii(int a, int b) |
---|
73 | n/a | { |
---|
74 | n/a | int result = a * b; |
---|
75 | n/a | printf("testfunc_iii(%p, %p)\n", &a, &b); |
---|
76 | n/a | return result; |
---|
77 | n/a | } |
---|
78 | n/a | |
---|
79 | n/a | EXPORT(int)myprintf(char *fmt, ...) |
---|
80 | n/a | { |
---|
81 | n/a | int result; |
---|
82 | n/a | va_list argptr; |
---|
83 | n/a | va_start(argptr, fmt); |
---|
84 | n/a | result = vprintf(fmt, argptr); |
---|
85 | n/a | va_end(argptr); |
---|
86 | n/a | return result; |
---|
87 | n/a | } |
---|
88 | n/a | |
---|
89 | n/a | EXPORT(char *)my_strtok(char *token, const char *delim) |
---|
90 | n/a | { |
---|
91 | n/a | return strtok(token, delim); |
---|
92 | n/a | } |
---|
93 | n/a | |
---|
94 | n/a | EXPORT(char *)my_strchr(const char *s, int c) |
---|
95 | n/a | { |
---|
96 | n/a | return strchr(s, c); |
---|
97 | n/a | } |
---|
98 | n/a | |
---|
99 | n/a | |
---|
100 | n/a | EXPORT(double) my_sqrt(double a) |
---|
101 | n/a | { |
---|
102 | n/a | return sqrt(a); |
---|
103 | n/a | } |
---|
104 | n/a | |
---|
105 | n/a | EXPORT(void) my_qsort(void *base, size_t num, size_t width, int(*compare)(const void*, const void*)) |
---|
106 | n/a | { |
---|
107 | n/a | qsort(base, num, width, compare); |
---|
108 | n/a | } |
---|
109 | n/a | |
---|
110 | n/a | EXPORT(int *) _testfunc_ai8(int a[8]) |
---|
111 | n/a | { |
---|
112 | n/a | return a; |
---|
113 | n/a | } |
---|
114 | n/a | |
---|
115 | n/a | EXPORT(void) _testfunc_v(int a, int b, int *presult) |
---|
116 | n/a | { |
---|
117 | n/a | *presult = a + b; |
---|
118 | n/a | } |
---|
119 | n/a | |
---|
120 | n/a | EXPORT(int) _testfunc_i_bhilfd(signed char b, short h, int i, long l, float f, double d) |
---|
121 | n/a | { |
---|
122 | n/a | /* printf("_testfunc_i_bhilfd got %d %d %d %ld %f %f\n", |
---|
123 | n/a | b, h, i, l, f, d); |
---|
124 | n/a | */ |
---|
125 | n/a | return (int)(b + h + i + l + f + d); |
---|
126 | n/a | } |
---|
127 | n/a | |
---|
128 | n/a | EXPORT(float) _testfunc_f_bhilfd(signed char b, short h, int i, long l, float f, double d) |
---|
129 | n/a | { |
---|
130 | n/a | /* printf("_testfunc_f_bhilfd got %d %d %d %ld %f %f\n", |
---|
131 | n/a | b, h, i, l, f, d); |
---|
132 | n/a | */ |
---|
133 | n/a | return (float)(b + h + i + l + f + d); |
---|
134 | n/a | } |
---|
135 | n/a | |
---|
136 | n/a | EXPORT(double) _testfunc_d_bhilfd(signed char b, short h, int i, long l, float f, double d) |
---|
137 | n/a | { |
---|
138 | n/a | /* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n", |
---|
139 | n/a | b, h, i, l, f, d); |
---|
140 | n/a | */ |
---|
141 | n/a | return (double)(b + h + i + l + f + d); |
---|
142 | n/a | } |
---|
143 | n/a | |
---|
144 | n/a | EXPORT(long double) _testfunc_D_bhilfD(signed char b, short h, int i, long l, float f, long double d) |
---|
145 | n/a | { |
---|
146 | n/a | /* printf("_testfunc_d_bhilfd got %d %d %d %ld %f %f\n", |
---|
147 | n/a | b, h, i, l, f, d); |
---|
148 | n/a | */ |
---|
149 | n/a | return (long double)(b + h + i + l + f + d); |
---|
150 | n/a | } |
---|
151 | n/a | |
---|
152 | n/a | EXPORT(char *) _testfunc_p_p(void *s) |
---|
153 | n/a | { |
---|
154 | n/a | return (char *)s; |
---|
155 | n/a | } |
---|
156 | n/a | |
---|
157 | n/a | EXPORT(void *) _testfunc_c_p_p(int *argcp, char **argv) |
---|
158 | n/a | { |
---|
159 | n/a | return argv[(*argcp)-1]; |
---|
160 | n/a | } |
---|
161 | n/a | |
---|
162 | n/a | EXPORT(void *) get_strchr(void) |
---|
163 | n/a | { |
---|
164 | n/a | return (void *)strchr; |
---|
165 | n/a | } |
---|
166 | n/a | |
---|
167 | n/a | EXPORT(char *) my_strdup(char *src) |
---|
168 | n/a | { |
---|
169 | n/a | char *dst = (char *)malloc(strlen(src)+1); |
---|
170 | n/a | if (!dst) |
---|
171 | n/a | return NULL; |
---|
172 | n/a | strcpy(dst, src); |
---|
173 | n/a | return dst; |
---|
174 | n/a | } |
---|
175 | n/a | |
---|
176 | n/a | EXPORT(void)my_free(void *ptr) |
---|
177 | n/a | { |
---|
178 | n/a | free(ptr); |
---|
179 | n/a | } |
---|
180 | n/a | |
---|
181 | n/a | #ifdef HAVE_WCHAR_H |
---|
182 | n/a | EXPORT(wchar_t *) my_wcsdup(wchar_t *src) |
---|
183 | n/a | { |
---|
184 | n/a | size_t len = wcslen(src); |
---|
185 | n/a | wchar_t *ptr = (wchar_t *)malloc((len + 1) * sizeof(wchar_t)); |
---|
186 | n/a | if (ptr == NULL) |
---|
187 | n/a | return NULL; |
---|
188 | n/a | memcpy(ptr, src, (len+1) * sizeof(wchar_t)); |
---|
189 | n/a | return ptr; |
---|
190 | n/a | } |
---|
191 | n/a | |
---|
192 | n/a | EXPORT(size_t) my_wcslen(wchar_t *src) |
---|
193 | n/a | { |
---|
194 | n/a | return wcslen(src); |
---|
195 | n/a | } |
---|
196 | n/a | #endif |
---|
197 | n/a | |
---|
198 | n/a | #ifndef MS_WIN32 |
---|
199 | n/a | # ifndef __stdcall |
---|
200 | n/a | # define __stdcall /* */ |
---|
201 | n/a | # endif |
---|
202 | n/a | #endif |
---|
203 | n/a | |
---|
204 | n/a | typedef struct { |
---|
205 | n/a | int (*c)(int, int); |
---|
206 | n/a | int (__stdcall *s)(int, int); |
---|
207 | n/a | } FUNCS; |
---|
208 | n/a | |
---|
209 | n/a | EXPORT(int) _testfunc_callfuncp(FUNCS *fp) |
---|
210 | n/a | { |
---|
211 | n/a | fp->c(1, 2); |
---|
212 | n/a | fp->s(3, 4); |
---|
213 | n/a | return 0; |
---|
214 | n/a | } |
---|
215 | n/a | |
---|
216 | n/a | EXPORT(int) _testfunc_deref_pointer(int *pi) |
---|
217 | n/a | { |
---|
218 | n/a | return *pi; |
---|
219 | n/a | } |
---|
220 | n/a | |
---|
221 | n/a | #ifdef MS_WIN32 |
---|
222 | n/a | EXPORT(int) _testfunc_piunk(IUnknown FAR *piunk) |
---|
223 | n/a | { |
---|
224 | n/a | piunk->lpVtbl->AddRef(piunk); |
---|
225 | n/a | return piunk->lpVtbl->Release(piunk); |
---|
226 | n/a | } |
---|
227 | n/a | #endif |
---|
228 | n/a | |
---|
229 | n/a | EXPORT(int) _testfunc_callback_with_pointer(int (*func)(int *)) |
---|
230 | n/a | { |
---|
231 | n/a | int table[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; |
---|
232 | n/a | |
---|
233 | n/a | return (*func)(table); |
---|
234 | n/a | } |
---|
235 | n/a | |
---|
236 | n/a | EXPORT(long long) _testfunc_q_bhilfdq(signed char b, short h, int i, long l, float f, |
---|
237 | n/a | double d, long long q) |
---|
238 | n/a | { |
---|
239 | n/a | return (long long)(b + h + i + l + f + d + q); |
---|
240 | n/a | } |
---|
241 | n/a | |
---|
242 | n/a | EXPORT(long long) _testfunc_q_bhilfd(signed char b, short h, int i, long l, float f, double d) |
---|
243 | n/a | { |
---|
244 | n/a | return (long long)(b + h + i + l + f + d); |
---|
245 | n/a | } |
---|
246 | n/a | |
---|
247 | n/a | EXPORT(int) _testfunc_callback_i_if(int value, int (*func)(int)) |
---|
248 | n/a | { |
---|
249 | n/a | int sum = 0; |
---|
250 | n/a | while (value != 0) { |
---|
251 | n/a | sum += func(value); |
---|
252 | n/a | value /= 2; |
---|
253 | n/a | } |
---|
254 | n/a | return sum; |
---|
255 | n/a | } |
---|
256 | n/a | |
---|
257 | n/a | EXPORT(long long) _testfunc_callback_q_qf(long long value, |
---|
258 | n/a | long long (*func)(long long)) |
---|
259 | n/a | { |
---|
260 | n/a | long long sum = 0; |
---|
261 | n/a | |
---|
262 | n/a | while (value != 0) { |
---|
263 | n/a | sum += func(value); |
---|
264 | n/a | value /= 2; |
---|
265 | n/a | } |
---|
266 | n/a | return sum; |
---|
267 | n/a | } |
---|
268 | n/a | |
---|
269 | n/a | typedef struct { |
---|
270 | n/a | char *name; |
---|
271 | n/a | char *value; |
---|
272 | n/a | } SPAM; |
---|
273 | n/a | |
---|
274 | n/a | typedef struct { |
---|
275 | n/a | char *name; |
---|
276 | n/a | int num_spams; |
---|
277 | n/a | SPAM *spams; |
---|
278 | n/a | } EGG; |
---|
279 | n/a | |
---|
280 | n/a | SPAM my_spams[2] = { |
---|
281 | n/a | { "name1", "value1" }, |
---|
282 | n/a | { "name2", "value2" }, |
---|
283 | n/a | }; |
---|
284 | n/a | |
---|
285 | n/a | EGG my_eggs[1] = { |
---|
286 | n/a | { "first egg", 1, my_spams } |
---|
287 | n/a | }; |
---|
288 | n/a | |
---|
289 | n/a | EXPORT(int) getSPAMANDEGGS(EGG **eggs) |
---|
290 | n/a | { |
---|
291 | n/a | *eggs = my_eggs; |
---|
292 | n/a | return 1; |
---|
293 | n/a | } |
---|
294 | n/a | |
---|
295 | n/a | typedef struct tagpoint { |
---|
296 | n/a | int x; |
---|
297 | n/a | int y; |
---|
298 | n/a | } point; |
---|
299 | n/a | |
---|
300 | n/a | EXPORT(int) _testfunc_byval(point in, point *pout) |
---|
301 | n/a | { |
---|
302 | n/a | if (pout) { |
---|
303 | n/a | pout->x = in.x; |
---|
304 | n/a | pout->y = in.y; |
---|
305 | n/a | } |
---|
306 | n/a | return in.x + in.y; |
---|
307 | n/a | } |
---|
308 | n/a | |
---|
309 | n/a | EXPORT (int) an_integer = 42; |
---|
310 | n/a | |
---|
311 | n/a | EXPORT(int) get_an_integer(void) |
---|
312 | n/a | { |
---|
313 | n/a | return an_integer; |
---|
314 | n/a | } |
---|
315 | n/a | |
---|
316 | n/a | EXPORT(double) |
---|
317 | n/a | integrate(double a, double b, double (*f)(double), long nstep) |
---|
318 | n/a | { |
---|
319 | n/a | double x, sum=0.0, dx=(b-a)/(double)nstep; |
---|
320 | n/a | for(x=a+0.5*dx; (b-x)*(x-a)>0.0; x+=dx) |
---|
321 | n/a | sum += f(x); |
---|
322 | n/a | return sum/(double)nstep; |
---|
323 | n/a | } |
---|
324 | n/a | |
---|
325 | n/a | typedef struct { |
---|
326 | n/a | void (*initialize)(void *(*)(int), void(*)(void *)); |
---|
327 | n/a | } xxx_library; |
---|
328 | n/a | |
---|
329 | n/a | static void _xxx_init(void *(*Xalloc)(int), void (*Xfree)(void *)) |
---|
330 | n/a | { |
---|
331 | n/a | void *ptr; |
---|
332 | n/a | |
---|
333 | n/a | printf("_xxx_init got %p %p\n", Xalloc, Xfree); |
---|
334 | n/a | printf("calling\n"); |
---|
335 | n/a | ptr = Xalloc(32); |
---|
336 | n/a | Xfree(ptr); |
---|
337 | n/a | printf("calls done, ptr was %p\n", ptr); |
---|
338 | n/a | } |
---|
339 | n/a | |
---|
340 | n/a | xxx_library _xxx_lib = { |
---|
341 | n/a | _xxx_init |
---|
342 | n/a | }; |
---|
343 | n/a | |
---|
344 | n/a | EXPORT(xxx_library) *library_get(void) |
---|
345 | n/a | { |
---|
346 | n/a | return &_xxx_lib; |
---|
347 | n/a | } |
---|
348 | n/a | |
---|
349 | n/a | #ifdef MS_WIN32 |
---|
350 | n/a | /* See Don Box (german), pp 79ff. */ |
---|
351 | n/a | EXPORT(void) GetString(BSTR *pbstr) |
---|
352 | n/a | { |
---|
353 | n/a | *pbstr = SysAllocString(L"Goodbye!"); |
---|
354 | n/a | } |
---|
355 | n/a | #endif |
---|
356 | n/a | |
---|
357 | n/a | /* |
---|
358 | n/a | * Some do-nothing functions, for speed tests |
---|
359 | n/a | */ |
---|
360 | n/a | PyObject *py_func_si(PyObject *self, PyObject *args) |
---|
361 | n/a | { |
---|
362 | n/a | char *name; |
---|
363 | n/a | int i; |
---|
364 | n/a | if (!PyArg_ParseTuple(args, "si", &name, &i)) |
---|
365 | n/a | return NULL; |
---|
366 | n/a | Py_RETURN_NONE; |
---|
367 | n/a | } |
---|
368 | n/a | |
---|
369 | n/a | EXPORT(void) _py_func_si(char *s, int i) |
---|
370 | n/a | { |
---|
371 | n/a | } |
---|
372 | n/a | |
---|
373 | n/a | PyObject *py_func(PyObject *self, PyObject *args) |
---|
374 | n/a | { |
---|
375 | n/a | Py_RETURN_NONE; |
---|
376 | n/a | } |
---|
377 | n/a | |
---|
378 | n/a | EXPORT(void) _py_func(void) |
---|
379 | n/a | { |
---|
380 | n/a | } |
---|
381 | n/a | |
---|
382 | n/a | EXPORT(long long) last_tf_arg_s; |
---|
383 | n/a | EXPORT(unsigned long long) last_tf_arg_u; |
---|
384 | n/a | |
---|
385 | n/a | struct BITS { |
---|
386 | n/a | int A: 1, B:2, C:3, D:4, E: 5, F: 6, G: 7, H: 8, I: 9; |
---|
387 | n/a | short M: 1, N: 2, O: 3, P: 4, Q: 5, R: 6, S: 7; |
---|
388 | n/a | }; |
---|
389 | n/a | |
---|
390 | n/a | EXPORT(void) set_bitfields(struct BITS *bits, char name, int value) |
---|
391 | n/a | { |
---|
392 | n/a | switch (name) { |
---|
393 | n/a | case 'A': bits->A = value; break; |
---|
394 | n/a | case 'B': bits->B = value; break; |
---|
395 | n/a | case 'C': bits->C = value; break; |
---|
396 | n/a | case 'D': bits->D = value; break; |
---|
397 | n/a | case 'E': bits->E = value; break; |
---|
398 | n/a | case 'F': bits->F = value; break; |
---|
399 | n/a | case 'G': bits->G = value; break; |
---|
400 | n/a | case 'H': bits->H = value; break; |
---|
401 | n/a | case 'I': bits->I = value; break; |
---|
402 | n/a | |
---|
403 | n/a | case 'M': bits->M = value; break; |
---|
404 | n/a | case 'N': bits->N = value; break; |
---|
405 | n/a | case 'O': bits->O = value; break; |
---|
406 | n/a | case 'P': bits->P = value; break; |
---|
407 | n/a | case 'Q': bits->Q = value; break; |
---|
408 | n/a | case 'R': bits->R = value; break; |
---|
409 | n/a | case 'S': bits->S = value; break; |
---|
410 | n/a | } |
---|
411 | n/a | } |
---|
412 | n/a | |
---|
413 | n/a | EXPORT(int) unpack_bitfields(struct BITS *bits, char name) |
---|
414 | n/a | { |
---|
415 | n/a | switch (name) { |
---|
416 | n/a | case 'A': return bits->A; |
---|
417 | n/a | case 'B': return bits->B; |
---|
418 | n/a | case 'C': return bits->C; |
---|
419 | n/a | case 'D': return bits->D; |
---|
420 | n/a | case 'E': return bits->E; |
---|
421 | n/a | case 'F': return bits->F; |
---|
422 | n/a | case 'G': return bits->G; |
---|
423 | n/a | case 'H': return bits->H; |
---|
424 | n/a | case 'I': return bits->I; |
---|
425 | n/a | |
---|
426 | n/a | case 'M': return bits->M; |
---|
427 | n/a | case 'N': return bits->N; |
---|
428 | n/a | case 'O': return bits->O; |
---|
429 | n/a | case 'P': return bits->P; |
---|
430 | n/a | case 'Q': return bits->Q; |
---|
431 | n/a | case 'R': return bits->R; |
---|
432 | n/a | case 'S': return bits->S; |
---|
433 | n/a | } |
---|
434 | n/a | return 0; |
---|
435 | n/a | } |
---|
436 | n/a | |
---|
437 | n/a | static PyMethodDef module_methods[] = { |
---|
438 | n/a | /* {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, |
---|
439 | n/a | {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS}, |
---|
440 | n/a | */ |
---|
441 | n/a | {"func_si", py_func_si, METH_VARARGS}, |
---|
442 | n/a | {"func", py_func, METH_NOARGS}, |
---|
443 | n/a | { NULL, NULL, 0, NULL}, |
---|
444 | n/a | }; |
---|
445 | n/a | |
---|
446 | n/a | #define S last_tf_arg_s = (long long)c |
---|
447 | n/a | #define U last_tf_arg_u = (unsigned long long)c |
---|
448 | n/a | |
---|
449 | n/a | EXPORT(signed char) tf_b(signed char c) { S; return c/3; } |
---|
450 | n/a | EXPORT(unsigned char) tf_B(unsigned char c) { U; return c/3; } |
---|
451 | n/a | EXPORT(short) tf_h(short c) { S; return c/3; } |
---|
452 | n/a | EXPORT(unsigned short) tf_H(unsigned short c) { U; return c/3; } |
---|
453 | n/a | EXPORT(int) tf_i(int c) { S; return c/3; } |
---|
454 | n/a | EXPORT(unsigned int) tf_I(unsigned int c) { U; return c/3; } |
---|
455 | n/a | EXPORT(long) tf_l(long c) { S; return c/3; } |
---|
456 | n/a | EXPORT(unsigned long) tf_L(unsigned long c) { U; return c/3; } |
---|
457 | n/a | EXPORT(long long) tf_q(long long c) { S; return c/3; } |
---|
458 | n/a | EXPORT(unsigned long long) tf_Q(unsigned long long c) { U; return c/3; } |
---|
459 | n/a | EXPORT(float) tf_f(float c) { S; return c/3; } |
---|
460 | n/a | EXPORT(double) tf_d(double c) { S; return c/3; } |
---|
461 | n/a | EXPORT(long double) tf_D(long double c) { S; return c/3; } |
---|
462 | n/a | |
---|
463 | n/a | #ifdef MS_WIN32 |
---|
464 | n/a | EXPORT(signed char) __stdcall s_tf_b(signed char c) { S; return c/3; } |
---|
465 | n/a | EXPORT(unsigned char) __stdcall s_tf_B(unsigned char c) { U; return c/3; } |
---|
466 | n/a | EXPORT(short) __stdcall s_tf_h(short c) { S; return c/3; } |
---|
467 | n/a | EXPORT(unsigned short) __stdcall s_tf_H(unsigned short c) { U; return c/3; } |
---|
468 | n/a | EXPORT(int) __stdcall s_tf_i(int c) { S; return c/3; } |
---|
469 | n/a | EXPORT(unsigned int) __stdcall s_tf_I(unsigned int c) { U; return c/3; } |
---|
470 | n/a | EXPORT(long) __stdcall s_tf_l(long c) { S; return c/3; } |
---|
471 | n/a | EXPORT(unsigned long) __stdcall s_tf_L(unsigned long c) { U; return c/3; } |
---|
472 | n/a | EXPORT(long long) __stdcall s_tf_q(long long c) { S; return c/3; } |
---|
473 | n/a | EXPORT(unsigned long long) __stdcall s_tf_Q(unsigned long long c) { U; return c/3; } |
---|
474 | n/a | EXPORT(float) __stdcall s_tf_f(float c) { S; return c/3; } |
---|
475 | n/a | EXPORT(double) __stdcall s_tf_d(double c) { S; return c/3; } |
---|
476 | n/a | EXPORT(long double) __stdcall s_tf_D(long double c) { S; return c/3; } |
---|
477 | n/a | #endif |
---|
478 | n/a | /*******/ |
---|
479 | n/a | |
---|
480 | n/a | EXPORT(signed char) tf_bb(signed char x, signed char c) { S; return c/3; } |
---|
481 | n/a | EXPORT(unsigned char) tf_bB(signed char x, unsigned char c) { U; return c/3; } |
---|
482 | n/a | EXPORT(short) tf_bh(signed char x, short c) { S; return c/3; } |
---|
483 | n/a | EXPORT(unsigned short) tf_bH(signed char x, unsigned short c) { U; return c/3; } |
---|
484 | n/a | EXPORT(int) tf_bi(signed char x, int c) { S; return c/3; } |
---|
485 | n/a | EXPORT(unsigned int) tf_bI(signed char x, unsigned int c) { U; return c/3; } |
---|
486 | n/a | EXPORT(long) tf_bl(signed char x, long c) { S; return c/3; } |
---|
487 | n/a | EXPORT(unsigned long) tf_bL(signed char x, unsigned long c) { U; return c/3; } |
---|
488 | n/a | EXPORT(long long) tf_bq(signed char x, long long c) { S; return c/3; } |
---|
489 | n/a | EXPORT(unsigned long long) tf_bQ(signed char x, unsigned long long c) { U; return c/3; } |
---|
490 | n/a | EXPORT(float) tf_bf(signed char x, float c) { S; return c/3; } |
---|
491 | n/a | EXPORT(double) tf_bd(signed char x, double c) { S; return c/3; } |
---|
492 | n/a | EXPORT(long double) tf_bD(signed char x, long double c) { S; return c/3; } |
---|
493 | n/a | EXPORT(void) tv_i(int c) { S; return; } |
---|
494 | n/a | |
---|
495 | n/a | #ifdef MS_WIN32 |
---|
496 | n/a | EXPORT(signed char) __stdcall s_tf_bb(signed char x, signed char c) { S; return c/3; } |
---|
497 | n/a | EXPORT(unsigned char) __stdcall s_tf_bB(signed char x, unsigned char c) { U; return c/3; } |
---|
498 | n/a | EXPORT(short) __stdcall s_tf_bh(signed char x, short c) { S; return c/3; } |
---|
499 | n/a | EXPORT(unsigned short) __stdcall s_tf_bH(signed char x, unsigned short c) { U; return c/3; } |
---|
500 | n/a | EXPORT(int) __stdcall s_tf_bi(signed char x, int c) { S; return c/3; } |
---|
501 | n/a | EXPORT(unsigned int) __stdcall s_tf_bI(signed char x, unsigned int c) { U; return c/3; } |
---|
502 | n/a | EXPORT(long) __stdcall s_tf_bl(signed char x, long c) { S; return c/3; } |
---|
503 | n/a | EXPORT(unsigned long) __stdcall s_tf_bL(signed char x, unsigned long c) { U; return c/3; } |
---|
504 | n/a | EXPORT(long long) __stdcall s_tf_bq(signed char x, long long c) { S; return c/3; } |
---|
505 | n/a | EXPORT(unsigned long long) __stdcall s_tf_bQ(signed char x, unsigned long long c) { U; return c/3; } |
---|
506 | n/a | EXPORT(float) __stdcall s_tf_bf(signed char x, float c) { S; return c/3; } |
---|
507 | n/a | EXPORT(double) __stdcall s_tf_bd(signed char x, double c) { S; return c/3; } |
---|
508 | n/a | EXPORT(long double) __stdcall s_tf_bD(signed char x, long double c) { S; return c/3; } |
---|
509 | n/a | EXPORT(void) __stdcall s_tv_i(int c) { S; return; } |
---|
510 | n/a | #endif |
---|
511 | n/a | |
---|
512 | n/a | /********/ |
---|
513 | n/a | |
---|
514 | n/a | #ifndef MS_WIN32 |
---|
515 | n/a | |
---|
516 | n/a | typedef struct { |
---|
517 | n/a | long x; |
---|
518 | n/a | long y; |
---|
519 | n/a | } POINT; |
---|
520 | n/a | |
---|
521 | n/a | typedef struct { |
---|
522 | n/a | long left; |
---|
523 | n/a | long top; |
---|
524 | n/a | long right; |
---|
525 | n/a | long bottom; |
---|
526 | n/a | } RECT; |
---|
527 | n/a | |
---|
528 | n/a | #endif |
---|
529 | n/a | |
---|
530 | n/a | EXPORT(int) PointInRect(RECT *prc, POINT pt) |
---|
531 | n/a | { |
---|
532 | n/a | if (pt.x < prc->left) |
---|
533 | n/a | return 0; |
---|
534 | n/a | if (pt.x > prc->right) |
---|
535 | n/a | return 0; |
---|
536 | n/a | if (pt.y < prc->top) |
---|
537 | n/a | return 0; |
---|
538 | n/a | if (pt.y > prc->bottom) |
---|
539 | n/a | return 0; |
---|
540 | n/a | return 1; |
---|
541 | n/a | } |
---|
542 | n/a | |
---|
543 | n/a | EXPORT(long left = 10); |
---|
544 | n/a | EXPORT(long top = 20); |
---|
545 | n/a | EXPORT(long right = 30); |
---|
546 | n/a | EXPORT(long bottom = 40); |
---|
547 | n/a | |
---|
548 | n/a | EXPORT(RECT) ReturnRect(int i, RECT ar, RECT* br, POINT cp, RECT dr, |
---|
549 | n/a | RECT *er, POINT fp, RECT gr) |
---|
550 | n/a | { |
---|
551 | n/a | /*Check input */ |
---|
552 | n/a | if (ar.left + br->left + dr.left + er->left + gr.left != left * 5) |
---|
553 | n/a | { |
---|
554 | n/a | ar.left = 100; |
---|
555 | n/a | return ar; |
---|
556 | n/a | } |
---|
557 | n/a | if (ar.right + br->right + dr.right + er->right + gr.right != right * 5) |
---|
558 | n/a | { |
---|
559 | n/a | ar.right = 100; |
---|
560 | n/a | return ar; |
---|
561 | n/a | } |
---|
562 | n/a | if (cp.x != fp.x) |
---|
563 | n/a | { |
---|
564 | n/a | ar.left = -100; |
---|
565 | n/a | } |
---|
566 | n/a | if (cp.y != fp.y) |
---|
567 | n/a | { |
---|
568 | n/a | ar.left = -200; |
---|
569 | n/a | } |
---|
570 | n/a | switch(i) |
---|
571 | n/a | { |
---|
572 | n/a | case 0: |
---|
573 | n/a | return ar; |
---|
574 | n/a | break; |
---|
575 | n/a | case 1: |
---|
576 | n/a | return dr; |
---|
577 | n/a | break; |
---|
578 | n/a | case 2: |
---|
579 | n/a | return gr; |
---|
580 | n/a | break; |
---|
581 | n/a | |
---|
582 | n/a | } |
---|
583 | n/a | return ar; |
---|
584 | n/a | } |
---|
585 | n/a | |
---|
586 | n/a | typedef struct { |
---|
587 | n/a | short x; |
---|
588 | n/a | short y; |
---|
589 | n/a | } S2H; |
---|
590 | n/a | |
---|
591 | n/a | EXPORT(S2H) ret_2h_func(S2H inp) |
---|
592 | n/a | { |
---|
593 | n/a | inp.x *= 2; |
---|
594 | n/a | inp.y *= 3; |
---|
595 | n/a | return inp; |
---|
596 | n/a | } |
---|
597 | n/a | |
---|
598 | n/a | typedef struct { |
---|
599 | n/a | int a, b, c, d, e, f, g, h; |
---|
600 | n/a | } S8I; |
---|
601 | n/a | |
---|
602 | n/a | EXPORT(S8I) ret_8i_func(S8I inp) |
---|
603 | n/a | { |
---|
604 | n/a | inp.a *= 2; |
---|
605 | n/a | inp.b *= 3; |
---|
606 | n/a | inp.c *= 4; |
---|
607 | n/a | inp.d *= 5; |
---|
608 | n/a | inp.e *= 6; |
---|
609 | n/a | inp.f *= 7; |
---|
610 | n/a | inp.g *= 8; |
---|
611 | n/a | inp.h *= 9; |
---|
612 | n/a | return inp; |
---|
613 | n/a | } |
---|
614 | n/a | |
---|
615 | n/a | EXPORT(int) GetRectangle(int flag, RECT *prect) |
---|
616 | n/a | { |
---|
617 | n/a | if (flag == 0) |
---|
618 | n/a | return 0; |
---|
619 | n/a | prect->left = (int)flag; |
---|
620 | n/a | prect->top = (int)flag + 1; |
---|
621 | n/a | prect->right = (int)flag + 2; |
---|
622 | n/a | prect->bottom = (int)flag + 3; |
---|
623 | n/a | return 1; |
---|
624 | n/a | } |
---|
625 | n/a | |
---|
626 | n/a | EXPORT(void) TwoOutArgs(int a, int *pi, int b, int *pj) |
---|
627 | n/a | { |
---|
628 | n/a | *pi += a; |
---|
629 | n/a | *pj += b; |
---|
630 | n/a | } |
---|
631 | n/a | |
---|
632 | n/a | #ifdef MS_WIN32 |
---|
633 | n/a | EXPORT(S2H) __stdcall s_ret_2h_func(S2H inp) { return ret_2h_func(inp); } |
---|
634 | n/a | EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); } |
---|
635 | n/a | #endif |
---|
636 | n/a | |
---|
637 | n/a | #ifdef MS_WIN32 |
---|
638 | n/a | /* Should port this */ |
---|
639 | n/a | #include <stdlib.h> |
---|
640 | n/a | #include <search.h> |
---|
641 | n/a | |
---|
642 | n/a | EXPORT (HRESULT) KeepObject(IUnknown *punk) |
---|
643 | n/a | { |
---|
644 | n/a | static IUnknown *pobj; |
---|
645 | n/a | if (punk) |
---|
646 | n/a | punk->lpVtbl->AddRef(punk); |
---|
647 | n/a | if (pobj) |
---|
648 | n/a | pobj->lpVtbl->Release(pobj); |
---|
649 | n/a | pobj = punk; |
---|
650 | n/a | return S_OK; |
---|
651 | n/a | } |
---|
652 | n/a | |
---|
653 | n/a | #endif |
---|
654 | n/a | |
---|
655 | n/a | |
---|
656 | n/a | static struct PyModuleDef _ctypes_testmodule = { |
---|
657 | n/a | PyModuleDef_HEAD_INIT, |
---|
658 | n/a | "_ctypes_test", |
---|
659 | n/a | NULL, |
---|
660 | n/a | -1, |
---|
661 | n/a | module_methods, |
---|
662 | n/a | NULL, |
---|
663 | n/a | NULL, |
---|
664 | n/a | NULL, |
---|
665 | n/a | NULL |
---|
666 | n/a | }; |
---|
667 | n/a | |
---|
668 | n/a | PyMODINIT_FUNC |
---|
669 | n/a | PyInit__ctypes_test(void) |
---|
670 | n/a | { |
---|
671 | n/a | return PyModule_Create(&_ctypes_testmodule); |
---|
672 | n/a | } |
---|