Mercurial > pub > dyncall > dyncall
comparison test/sign/sign.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/sign/sign.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 | |
27 #include "dyncall.h" | |
28 #include "../common/platformInit.h" | |
29 | |
30 // This program demonstrates the need for 'unsigned' integers and the | |
31 // ability to implement zero/sign extensions for small integers. | |
32 // This test program indicates failure on powerpc 32-bit with | |
33 // compiler optimizations enabled (e.g. '-O2' compilation flags). | |
34 // | |
35 // A fix to be incorporated in the API is also given. | |
36 // | |
37 | |
38 int add1s(unsigned short x) { return x + 1; } | |
39 | |
40 // API BUGFIX: | |
41 #define dcArgUShort(vm,x) dcArgInt(vm,(int)(unsigned int)(x)) | |
42 | |
43 // OLD TEST: int add1(unsigned char x) { return x + 1; } | |
44 | |
45 int main(int argc, char* argv[]) | |
46 { | |
47 DCCallVM* vm; | |
48 int result; | |
49 int total; | |
50 vm = dcNewCallVM(4096); | |
51 dcReset(vm); | |
52 | |
53 dcArgShort(vm, 0xFFFF ); | |
54 result = dcCallInt( vm, &add1s ); | |
55 total = (result == 0x10000); | |
56 printf("result: sign: %d\n", total); | |
57 | |
58 if (!total) { | |
59 // | |
60 // TEST BUGFIX: use instead.. | |
61 // | |
62 dcReset(vm); | |
63 dcArgUShort( vm, 0xFFFF ); | |
64 result = dcCallInt( vm, &add1s ); | |
65 total = (result == 0x10000); | |
66 printf("result: sign (bugfix): %d\n", total); | |
67 } | |
68 | |
69 // result = dcCallInt( vm, &add1s ); | |
70 // total = (result == 0x10000); | |
71 | |
72 // OLD TEST: updated to using 'short' | |
73 // dcArgChar( vm, (char) 255 ); | |
74 // result = dcCallInt( vm, &add1 ); | |
75 // total = (result == 256); | |
76 | |
77 // printf("result: sign: %d\n", total); | |
78 return 0; | |
79 } |