Add test for libffi functionality

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@30073 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2010-03-29 10:49:07 +00:00
parent 95aa504b3a
commit 67dd833cc5
4 changed files with 116 additions and 30 deletions

View file

@ -1,3 +1,14 @@
2010-03-29 Richard Frith-Macdonald <rfm@gnu.org>
* config/config.ffi.c: add test for libffi functionality
* configure.ac: use new test
* configure: regenerate
Greg had the good idea of testing libffi version to make sure it
works ... unfortunately I couldn't see an easy way to test the
version, so I added a test for functionality adapted from the
test case I made for the libffi people to demonstrate a bug in
passing floats on 64bit intel.
2010-03-28 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSDecimalNumber.m: override getter methods of superclass

68
config/config.ffi.c Normal file
View file

@ -0,0 +1,68 @@
#include <stdio.h>
#include <stdlib.h>
#include <ffi.h>
typedef struct cls_struct_combined {
float a;
float b;
float c;
float d;
} cls_struct_combined;
void cls_struct_combined_fn(struct cls_struct_combined arg)
{
/*
printf("GOT %g %g %g %g, EXPECTED 4 5 1 8\n",
arg.a, arg.b,
arg.c, arg.d);
fflush(stdout);
*/
if (arg.a != 4 || arg.b != 5 || arg.c != 6 || arg.d != 8) abort();
}
static void
cls_struct_combined_gn(ffi_cif* cif, void* resp, void** args, void* userdata)
{
struct cls_struct_combined a0;
a0 = *(struct cls_struct_combined*)(args[0]);
cls_struct_combined_fn(a0);
}
int main (void)
{
ffi_cif cif;
void *code;
ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
ffi_type* cls_struct_fields0[5];
ffi_type cls_struct_type0;
ffi_type* dbl_arg_types[5];
cls_struct_type0.size = 0;
cls_struct_type0.alignment = 0;
cls_struct_type0.type = FFI_TYPE_STRUCT;
cls_struct_type0.elements = cls_struct_fields0;
struct cls_struct_combined g_dbl = {4.0, 5.0, 1.0, 8.0};
cls_struct_fields0[0] = &ffi_type_float;
cls_struct_fields0[1] = &ffi_type_float;
cls_struct_fields0[2] = &ffi_type_float;
cls_struct_fields0[3] = &ffi_type_float;
cls_struct_fields0[4] = NULL;
dbl_arg_types[0] = &cls_struct_type0;
dbl_arg_types[1] = NULL;
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_void, dbl_arg_types)
!= FFI_OK) abort();
if (ffi_prep_closure_loc(pcl, &cif, cls_struct_combined_gn, NULL, code)
!= FFI_OK) abort();
((void(*)(cls_struct_combined)) (code))(g_dbl);
exit(0);
}

57
configure vendored
View file

@ -18865,56 +18865,61 @@ _ACEOF
WITH_FFI=libffi
LIBS="-lffi $LIBS"
if test "$cross_compiling" = yes; then
ffi_ok="no"
else
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <ffi.h>
int
main ()
{
;
return 0;
}
#include "$srcdir/config/config.ffi.c"
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
rm -f conftest$ac_exeext
if { (ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_link") 2>conftest.er1
(eval "$ac_link") 2>&5
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } && {
test -z "$ac_c_werror_flag" ||
test ! -s conftest.err
} && test -s conftest$ac_exeext &&
$as_test_x conftest$ac_exeext; then
ffi_ok="yes"
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
{ (case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_try") 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
:
else
echo "$as_me: failed program was:" >&5
echo "$as_me: program exited with status $ac_status" >&5
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ffi_ok="no"
( exit $ac_status )
ffi_ok="yes"
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
conftest$ac_exeext conftest.$ac_ext
if test $ffi_ok = yes; then
{ echo "$as_me:$LINENO: result: libffi" >&5
echo "${ECHO_T}libffi" >&6; }
fi
if test $do_broken_libffi = yes; then
{ echo "$as_me:$LINENO: WARNING: ffi may be broken on this system ... try enabling ffcall" >&5
if test $do_broken_libffi = yes; then
{ echo "$as_me:$LINENO: WARNING: ffi may be broken on this system ... try enabling ffcall" >&5
echo "$as_me: WARNING: ffi may be broken on this system ... try enabling ffcall" >&2;}
fi
else
{ { echo "$as_me:$LINENO: error: The ffi library (libffi) does not appear to be working. Perhaps it's missing or you need a more recent version. Version 3.0.9 or later should work, and you can find a link to it n the list of packages for download at http://www.gnustep.org/resources/sources.html" >&5
echo "$as_me: error: The ffi library (libffi) does not appear to be working. Perhaps it's missing or you need a more recent version. Version 3.0.9 or later should work, and you can find a link to it n the list of packages for download at http://www.gnustep.org/resources/sources.html" >&2;}
{ (exit 1); exit 1; }; }
fi
elif test $enable_ffcall = yes; then

View file

@ -1456,12 +1456,14 @@ if test $enable_libffi = yes; then
[Define if using the libffi library for invocations])
WITH_FFI=libffi
LIBS="-lffi $LIBS"
AC_TRY_LINK([#include <ffi.h>], ,ffi_ok="yes", ffi_ok="no")
AC_TRY_RUN([#include "$srcdir/config/config.ffi.c"],,ffi_ok="yes",ffi_ok="no")
if test $ffi_ok = yes; then
AC_MSG_RESULT(libffi)
fi
if test $do_broken_libffi = yes; then
AC_MSG_WARN([ffi may be broken on this system ... try enabling ffcall])
if test $do_broken_libffi = yes; then
AC_MSG_WARN([ffi may be broken on this system ... try enabling ffcall])
fi
else
AC_MSG_ERROR([The ffi library (libffi) does not appear to be working. Perhaps it's missing or you need a more recent version. Version 3.0.9 or later should work, and you can find a link to it n the list of packages for download at http://www.gnustep.org/resources/sources.html])
fi
elif test $enable_ffcall = yes; then
AC_DEFINE(USE_FFCALL,1,