mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
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:
parent
95aa504b3a
commit
67dd833cc5
4 changed files with 116 additions and 30 deletions
68
config/config.ffi.c
Normal file
68
config/config.ffi.c
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue