Mercurial > pub > dyncall > dyncall
comparison test/callback_suite/env.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/callback_suite/env.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 <assert.h> | |
27 #include "_auto_config.h" | |
28 #include "dyncall_signature.h" | |
29 #include "env.h" | |
30 | |
31 DCValueSet ValueMatrix[CONFIG_MAXARGS]; | |
32 DCValue Args[CONFIG_MAXARGS]; | |
33 DCValue Result; | |
34 | |
35 DCValueSet K; | |
36 | |
37 void GetReferenceArg(DCValue* output, char ch, int pos) | |
38 { | |
39 /* | |
40 static const int Ki = 134; | |
41 static const double Kd = 1.012356; | |
42 static const float Kf = 1.20432545f; | |
43 static const int Kp = 0x1020345; | |
44 static const DClonglong Kl = 24534543; | |
45 */ | |
46 | |
47 output->L = 0xCAFEBABEDEADC0DELL; | |
48 pos = pos + 2; | |
49 switch(ch) { | |
50 case DC_SIGCHAR_BOOL: output->B = ( (pos*K.i) % 2) ? DC_TRUE : DC_FALSE ; break; | |
51 case DC_SIGCHAR_CHAR: output->c = pos*K.c; break; | |
52 case DC_SIGCHAR_UCHAR: output->C = pos*K.C; break; | |
53 case DC_SIGCHAR_SHORT: output->s = pos*K.s; break; | |
54 case DC_SIGCHAR_USHORT: output->S = pos*K.S; break; | |
55 case DC_SIGCHAR_INT: output->i = pos*K.i; break; | |
56 case DC_SIGCHAR_UINT: output->I = pos*K.I; break; | |
57 case DC_SIGCHAR_LONG: output->j = pos*K.j; break; | |
58 case DC_SIGCHAR_ULONG: output->J = pos*K.J; break; | |
59 case DC_SIGCHAR_LONGLONG: output->l = ( (long long) pos ) * K.l; break; | |
60 case DC_SIGCHAR_ULONGLONG:output->L = pos*K.L; break; | |
61 case DC_SIGCHAR_FLOAT: output->f = ( (float) pos ) * K.f; break; | |
62 case DC_SIGCHAR_DOUBLE: output->d = ( (double) pos ) * K.d; break; | |
63 case DC_SIGCHAR_POINTER: output->p = (DCpointer) (unsigned long) (pos* ( (unsigned long) K.p ) ); break; | |
64 default: assert(0); | |
65 } | |
66 } | |
67 | |
68 void GetReferenceResult(DCValue* output, char ch) | |
69 { | |
70 GetReferenceArg(output, ch, -1); | |
71 } | |
72 | |
73 void InitEnv() | |
74 { | |
75 int pos; | |
76 | |
77 K.B = DC_TRUE; | |
78 K.c = 13; | |
79 K.C = 19; | |
80 K.s = -23; | |
81 K.S = 41; | |
82 K.i = 134; | |
83 K.I = 257; | |
84 K.j = -12357; | |
85 K.J = 356; | |
86 K.l = -1234556687721LL; | |
87 K.L = 23564634576581ULL; | |
88 K.f = 1.20432545f; | |
89 K.d = 1.0123456; | |
90 K.p = (void*) 0x1020345; | |
91 | |
92 for(pos = 0 ;pos < CONFIG_MAXARGS ;++pos) { | |
93 DCValue ref; | |
94 GetReferenceArg( &ref, DC_SIGCHAR_BOOL , pos); ValueMatrix[pos].B = ref.B; | |
95 GetReferenceArg( &ref, DC_SIGCHAR_CHAR , pos); ValueMatrix[pos].c = ref.c; | |
96 GetReferenceArg( &ref, DC_SIGCHAR_UCHAR , pos); ValueMatrix[pos].C = ref.C; | |
97 GetReferenceArg( &ref, DC_SIGCHAR_SHORT , pos); ValueMatrix[pos].s = ref.s; | |
98 GetReferenceArg( &ref, DC_SIGCHAR_USHORT , pos); ValueMatrix[pos].S = ref.S; | |
99 GetReferenceArg( &ref, DC_SIGCHAR_INT , pos); ValueMatrix[pos].i = ref.i; | |
100 GetReferenceArg( &ref, DC_SIGCHAR_UINT , pos); ValueMatrix[pos].I = ref.I; | |
101 GetReferenceArg( &ref, DC_SIGCHAR_LONG , pos); ValueMatrix[pos].j = ref.j; | |
102 GetReferenceArg( &ref, DC_SIGCHAR_ULONG , pos); ValueMatrix[pos].J = ref.J; | |
103 GetReferenceArg( &ref, DC_SIGCHAR_LONGLONG , pos); ValueMatrix[pos].l = ref.l; | |
104 GetReferenceArg( &ref, DC_SIGCHAR_ULONGLONG, pos); ValueMatrix[pos].L = ref.L; | |
105 GetReferenceArg( &ref, DC_SIGCHAR_FLOAT , pos); ValueMatrix[pos].f = ref.f; | |
106 GetReferenceArg( &ref, DC_SIGCHAR_DOUBLE , pos); ValueMatrix[pos].d = ref.d; | |
107 GetReferenceArg( &ref, DC_SIGCHAR_POINTER , pos); ValueMatrix[pos].p = ref.p; | |
108 } | |
109 } | |
110 | |
111 /* Global Options. */ | |
112 int OptionVerbose = 0; | |
113 |