annotate test/sign/sign.c @ 663:127b569978cc default tip

- another tweak handling clang trying to be too smart (see last commit)
author Tassilo Philipp
date Sun, 24 Mar 2024 13:52:44 +0100
parents e2899b4ff713
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: test
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: test/sign/sign.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
410
7608e34098b0 - cleanups, simplifications, some api clarification, ...
Tassilo Philipp
parents: 281
diff changeset
9 Copyright (c) 2011-2021 Daniel Adler <dadler@uni-goettingen.de>,
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 #include "dyncall.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28
465
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
29 /* This program demonstrates the need for 'unsigned' integers and the */
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
30 /* ability to implement zero/sign extensions for small integers. */
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
31 /* This test program indicates failure on powerpc 32-bit with */
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
32 /* compiler optimizations enabled (e.g. '-O2' compilation flags). */
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
33 /* */
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
34 /* A fix to be incorporated in the API is also given. */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 int add1s(unsigned short x) { return x + 1; }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37
465
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
38 /* API BUGFIX: */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39 #define dcArgUShort(vm,x) dcArgInt(vm,(int)(unsigned int)(x))
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40
465
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
41 /* OLD TEST: int add1(unsigned char x) { return x + 1; } */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 int main(int argc, char* argv[])
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 DCCallVM* vm;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 int result;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 int total;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 vm = dcNewCallVM(4096);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 dcArgShort(vm, 0xFFFF );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52 result = dcCallInt( vm, &add1s );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 total = (result == 0x10000);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 printf("result: sign: %d\n", total);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 if (!total) {
465
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
57
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
58 /* TEST BUGFIX: use instead.. */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 dcArgUShort( vm, 0xFFFF );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 result = dcCallInt( vm, &add1s );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 total = (result == 0x10000);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 printf("result: sign (bugfix): %d\n", total);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65
465
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
66 /*result = dcCallInt( vm, &add1s );
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
67 total = (result == 0x10000);*/
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68
465
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
69 /*OLD TEST: updated to using 'short'
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
70 dcArgChar( vm, (char) 255 );
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
71 result = dcCallInt( vm, &add1 );
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
72 total = (result == 256);*/
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73
465
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
74 /*printf("result: sign: %d\n", total); */
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 return 0;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76 }
465
e2899b4ff713 - // -> /* */, mainly for consistency (but also for a few obscure compilers)
Tassilo Philipp
parents: 410
diff changeset
77