Many changes. Not quite there yet.

This commit is contained in:
green
2001-04-22 18:17:14 +00:00
parent f893d22733
commit a8b0d40ff9
22 changed files with 3627 additions and 524 deletions

View File

@@ -0,0 +1,13 @@
global srcdir subdir
catch "glob -nocomplain ${srcdir}/${subdir}/*.c" srcfiles
verbose "srcfiles are $srcfiles"
set prefix ""
foreach x $srcfiles {
test_libffi $x
}
# Local Variables:
# tcl-indent-level:4
# End:

View File

@@ -0,0 +1,4 @@
#include <ffi.h>
#define CHECK(x) !(x) ? abort() : 0

View File

@@ -0,0 +1,55 @@
#include "ffitest.h"
static int floating(int a, float b, double c, long double d, int e)
{
int i;
i = (int) ((float)a/b + ((float)c/(float)d));
return i;
}
int
main ()
{
ffi_cif cif;
ffi_type *args[5];
void *values[5];
int si1, si2;
float f;
double d;
long double ld;
int rint __attribute__((aligned(8)));
args[0] = &ffi_type_sint;
values[0] = &si1;
args[1] = &ffi_type_float;
values[1] = &f;
args[2] = &ffi_type_double;
values[2] = &d;
args[3] = &ffi_type_longdouble;
values[3] = &ld;
args[4] = &ffi_type_sint;
values[4] = &si2;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 5,
&ffi_type_sint, args) == FFI_OK);
si1 = 6;
f = 3.14159;
d = (double)1.0/(double)3.0;
ld = 2.71828182846L;
si2 = 10;
floating (si1, f, d, ld, si2);
ffi_call(&cif, FFI_FN(floating), &rint, values);
printf ("%d vs %d\n", rint, floating (si1, f, d, ld, si2));
CHECK(rint == floating(si1, f, d, ld, si2));
exit (0);
}

View File

@@ -0,0 +1,63 @@
#include "ffitest.h"
#include <float.h>
static float many(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)
{
#if 0
printf("%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);
#endif
return ((f1/f2+f3/f4+f5/f6+f7/f8+f9/f10+f11/f12) * f13);
}
int
main ()
{
ffi_cif cif;
ffi_type *args[13];
void *values[13];
float fa[13];
float f, ff;
int i;
for (i = 0; i < 13; i++)
{
args[i] = &ffi_type_float;
values[i] = &fa[i];
fa[i] = (float) i;
}
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 13,
&ffi_type_float, args) == FFI_OK);
ffi_call(&cif, FFI_FN(many), &f, values);
ff = many(fa[0], fa[1],
fa[2], fa[3],
fa[4], fa[5],
fa[6], fa[7],
fa[8], fa[9],
fa[10],fa[11],fa[12]);
if (f - ff < FLT_EPSILON)
exit(0);
else
abort();
}

View File

@@ -0,0 +1,38 @@
#include "ffitest.h"
static size_t my_strlen(char *s)
{
return (strlen(s));
}
int
main ()
{
ffi_cif cif;
ffi_type *args[1];
void *values[1];
int rint __attribute__((aligned(8)));
char *s;
args[0] = &ffi_type_pointer;
values[0] = (void*) &s;
/* Initialize the cif */
CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
&ffi_type_sint, args) == FFI_OK);
s = "a";
ffi_call(&cif, FFI_FN(my_strlen), &rint, values);
CHECK(rint == 1);
s = "1234567";
ffi_call(&cif, FFI_FN(my_strlen), &rint, values);
CHECK(rint == 7);
s = "1234567890123456789012345";
ffi_call(&cif, FFI_FN(my_strlen), &rint, values);
CHECK(rint == 25);
exit (0);
}