File: ffi-test.c

package info (click to toggle)
squeak-vm 1%3A4.10.2.2614-4.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,284 kB
  • ctags: 15,344
  • sloc: ansic: 75,096; cs: 11,191; objc: 5,494; sh: 3,170; asm: 1,533; cpp: 449; pascal: 372; makefile: 366; awk: 103
file content (155 lines) | stat: -rw-r--r-- 4,996 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* last edited: 2009-08-19 04:24:41 by piumarta on emilia-2.local
 */

#if !defined(NO_FFI_TEST)

#include <stdio.h>
#include <stdlib.h>

#if !defined(LONGLONG)
# define LONGLONG long long
#endif

#if 0
# define debugf(ARGS) printf ARGS
#else
# define debugf(ARGS)
#endif

#include "ffi-test.h"


char ffiTestChars(char c1, char c2, char c3, char c4)
{
  debugf(("4 characters came in as\nc1 = %c (%x)\nc2 = %c (%x)\nc3 = %c (%x)\nc4 = %c (%x)\n", c1, c1, c2, c2, c3, c3, c4, c4));
  return 'C';
}


short ffiTestShorts(short c1, short c2, short c3, short c4)
{
  debugf(("4 shorts came in as\ns1 = %d (%x)\ns2 = %d (%x)\ns3 = %d (%x)\ns4 = %d (%x)\n", c1, c1, c2, c2, c3, c3, c4, c4));
  return -42;
}


int ffiTestInts(int c1, int c2, int c3, int c4)
{
  debugf(("4 ints came in as\ni1 = %d (%x)\ni2 = %d (%x)\ni3 = %d (%x)\ni4 = %d (%x)\n", c1, c1, c2, c2, c3, c3, c4, c4));
  return 42;
}


int ffiTestInts8(int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8)
{
  debugf(("4 ints came in as\ni1 = %d (%x)\ni2 = %d (%x)\ni3 = %d (%x)\ni4 = %d (%x)\ni5 = %d (%x)\ni6 = %d (%x)\ni7 = %d (%x)\ni8 = %d (%x)\n", c1, c1, c2, c2, c3, c3, c4, c4, c5, c5, c6, c6, c7, c7, c8, c8));
  return 42;
}


int ffiTestInts9(int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8, int c9)
{
  debugf(("4 ints came in as\ni1 = %d (%x)\ni2 = %d (%x)\ni3 = %d (%x)\ni4 = %d (%x)\ni5 = %d (%x)\ni6 = %d (%x)\ni7 = %d (%x)\ni8 = %d (%x)\ni9 = %d (%x)\n", c1, c1, c2, c2, c3, c3, c4, c4, c5, c5, c6, c6, c7, c7, c8, c8, c9, c9));
  return 42;
}


float ffiTestFloats(float f1, float f2)
{
  debugf(("The two floats are %f and %f\n", (double)f1, (double)f2));
  return (float) (f1 + f2);
}


float ffiTestFloats7(float f1, float f2, float f3, float f4, float f5, float f6, float f7)
{
  debugf(("The 7 floats are %f %f %f %f %f %f %f\n", (double)f1, (double)f2, (double)f3, (double)f4, (double)f5, (double)f6, (double)f7));
  return (float) (f1 + f2 + f3 + f4 + f5 + f6 + f7);
}


float ffiTestFloats13(float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13)
{
  debugf(("The 13 floats are %f %f %f %f %f %f %f %f %f %f %f %f %f\n", (double)f1, (double)f2, (double)f3, (double)f4, (double)f5, (double)f6, (double)f7, (double)f8, (double)f9, (double)f10, (double)f11, (double)f12, (double)f13));
  return (float) (f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13);
}


float ffiTestFloats15(float f1, float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, float f10, float f11, float f12, float f13, float f14, float f15)
{
  debugf(("The 15 floats are %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", (double)f1, (double)f2, (double)f3, (double)f4, (double)f5, (double)f6, (double)f7, (double)f8, (double)f9, (double)f10, (double)f11, (double)f12, (double)f13, (double)f14, (double)f15));
  return (float) (f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14 + f15);
}


double ffiTestDoubles(double d1, double d2)
{
  debugf(("The two doubles are %f and %f\n", d1, d2));
  return d1+d2;
}


double ffiTestDoubles15(double f1, double f2, double f3, double f4, double f5, double f6, double f7, double f8, double f9, double f10, double f11, double f12, double f13, double f14, double f15)
{
  debugf(("The 15 doubles are %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n", f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15));
  return (double) (f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8 + f9 + f10 + f11 + f12 + f13 + f14 + f15);
}


char *ffiPrintString(char *string)
{
  debugf(("%s\n", string));
  return string;
}


ffiTestPoint2 ffiTestStruct64(ffiTestPoint2 pt1, ffiTestPoint2 pt2)
{
  ffiTestPoint2 result;
  debugf(("pt1.x = %d\npt1.y = %d\npt2.x = %d\npt2.y = %d\n",
	  pt1.x, pt1.y, pt2.x, pt2.y));
  result.x = pt1.x + pt2.x;
  result.y = pt1.y + pt2.y;
  return result;
}


ffiTestPoint4 ffiTestStructBig(ffiTestPoint4 pt1, ffiTestPoint4 pt2)
{
  ffiTestPoint4 result;
  debugf(("pt1.x = %d\npt1.y = %d\npt1.z = %d\npt1.w = %d\n",
	  pt1.x, pt1.y, pt1.z, pt1.w));
  debugf(("pt2.x = %d\npt2.y = %d\npt2.z = %d\npt2.w = %d\n",
	  pt2.x, pt2.y, pt2.z, pt2.w));
  result.x = pt1.x + pt2.x;
  result.y = pt1.y + pt2.y;
  result.z = pt1.z + pt2.z;
  result.w = pt1.w + pt2.w;
  return result;
}


ffiTestPoint4 *ffiTestPointers(ffiTestPoint4 *pt1, ffiTestPoint4 *pt2)
{
  ffiTestPoint4 *result;
  debugf(("pt1.x = %d\npt1.y = %d\npt1.z = %d\npt1.w = %d\n",
	  pt1->x, pt1->y, pt1->z, pt1->w));
  debugf(("pt2.x = %d\npt2.y = %d\npt2.z = %d\npt2.w = %d\n",
	  pt2->x, pt2->y, pt2->z, pt2->w));
  result = (ffiTestPoint4*) malloc(sizeof(ffiTestPoint4));
  result->x = pt1->x + pt2->x;
  result->y = pt1->y + pt2->y;
  result->z = pt1->z + pt2->z;
  result->w = pt1->w + pt2->w;
  return result;
}


LONGLONG ffiTestLongLong(LONGLONG i1, LONGLONG i2)
{
  debugf(("longlong %lld %lld\n", i1, i2));
  return i1 + i2;
}


#endif /* !NO_FFI_TEST */