Mercurial > pub > dyncall > dyncall
comparison test/call_suite/invoke.c @ 0:3e629dc19168
initial from svn dyncall-1745
author | Daniel Adler |
---|---|
date | Thu, 19 Mar 2015 22:24:28 +0100 |
parents | |
children | f5577f6bf97a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3e629dc19168 |
---|---|
1 /* | |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/call_suite/invoke.c | |
6 Description: | |
7 License: | |
8 | |
9 Copyright (c) 2011-2015 Daniel Adler <dadler@uni-goettingen.de>, | |
10 Tassilo Philipp <tphilipp@potion-studios.com> | |
11 | |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
26 #include "dyncall.h" | |
27 #include "globals.h" | |
28 #include "../common/platformInit.h" | |
29 | |
30 int invoke(char const* signature, void* t) | |
31 { | |
32 DCCallVM * p = (DCCallVM*) G_callvm; | |
33 char const * sig = signature; | |
34 char rtype; | |
35 char atype; | |
36 int pos = 0; | |
37 int s = 0; | |
38 | |
39 clear_V(); | |
40 | |
41 rtype = *sig++; | |
42 dcReset(p); | |
43 | |
44 while ( (atype = *sig++) != '\0') { | |
45 pos++; | |
46 switch(atype) { | |
47 case 'c': dcArgChar (p,K_c[pos]); break; | |
48 case 's': dcArgShort (p,K_s[pos]); break; | |
49 case 'i': dcArgInt (p,K_i[pos]); break; | |
50 case 'j': dcArgLong (p,K_j[pos]); break; | |
51 case 'l': dcArgLongLong(p,K_l[pos]); break; | |
52 case 'p': dcArgPointer (p,K_p[pos]); break; | |
53 case 'f': dcArgFloat (p,K_f[pos]); break; | |
54 case 'd': dcArgDouble (p,K_d[pos]); break; | |
55 default: printf("unknown atype '%c' (1) ;", atype); return 0; | |
56 } | |
57 } | |
58 | |
59 switch(rtype) | |
60 { | |
61 case 'v': dcCallVoid(p,t); s=1; /*TODO:check that no return-arg was touched.*/ break; | |
62 case 'c': s = (dcCallChar (p,t) == K_c[pos]) ; break; | |
63 case 's': s = (dcCallShort (p,t) == K_s[pos]) ; break; | |
64 case 'i': s = (dcCallInt (p,t) == K_i[pos]) ; break; | |
65 case 'j': s = (dcCallLong (p,t) == K_j[pos]) ; break; | |
66 case 'l': s = (dcCallLongLong(p,t) == K_l[pos]) ; break; | |
67 case 'p': s = (dcCallPointer (p,t) == K_p[pos]) ; break; | |
68 case 'f': s = (dcCallFloat (p,t) == K_f[pos]) ; break; | |
69 case 'd': s = (dcCallDouble (p,t) == K_d[pos]) ; break; | |
70 default: printf("unknown rtype '%c'", rtype); return 0; | |
71 } | |
72 | |
73 if (!s) { printf("rval wrong;"); return 0; } | |
74 /* test: */ | |
75 sig = signature+1; | |
76 pos = 1; | |
77 while ( (atype = *sig++) != '\0') { | |
78 switch(atype) { | |
79 #if 0 | |
80 #define X(CH,T,QCH) case QCH: s = (V_##CH[pos] == K_##CH[pos]); break; | |
81 DEF_TYPES | |
82 #undef X | |
83 #endif | |
84 case 'c': s = ( V_c[pos] == K_c[pos] ); if (!s) printf("'c':%d: %d != %d ; ", pos, V_c[pos], K_c[pos]); break; | |
85 case 's': s = ( V_s[pos] == K_s[pos] ); if (!s) printf("'s':%d: %d != %d ; ", pos, V_s[pos], K_s[pos]); break; | |
86 case 'i': s = ( V_i[pos] == K_i[pos] ); if (!s) printf("'i':%d: %d != %d ; ", pos, V_i[pos], K_i[pos]); break; | |
87 case 'j': s = ( V_j[pos] == K_j[pos] ); if (!s) printf("'j':%d: %ld != %ld ; ", pos, V_j[pos], K_j[pos]); break; | |
88 case 'l': s = ( V_l[pos] == K_l[pos] ); if (!s) printf("'l':%d: %lld != %lld ; ", pos, V_l[pos], K_l[pos]); break; | |
89 case 'p': s = ( V_p[pos] == K_p[pos] ); if (!s) printf("'p':%d: %lld != %lld ; ", pos, (long long) V_p[pos], (long long) K_p[pos]); break; | |
90 case 'f': s = ( V_f[pos] == K_f[pos] ); if (!s) printf("'f':%d: %f != %f ; ", pos, V_f[pos], K_f[pos]); break; | |
91 case 'd': s = ( V_d[pos] == K_d[pos] ); if (!s) printf("'d':%d: %f != %f ; ", pos, V_d[pos], K_d[pos]); break; | |
92 default: printf("unknown atype '%c' ; ", atype); return 0; | |
93 } | |
94 if (!s) { | |
95 printf("arg mismatch at %d ; ", pos); | |
96 return 0; | |
97 } | |
98 pos++; | |
99 } | |
100 return 1; | |
101 } | |
102 |