2 Purpose: Check different structures.
5 Originator: Ronald Oussoren <oussoren@cistron.nl> 20030824 */
10 typedef struct Point {
25 int doit(int o, char* s, Point p, Rect r, int last)
27 printf("CALLED WITH %d %s {%f %f} {{%f %f} {%f %f}} %d\n",
28 o, s, p.x, p.y, r.o.x, r.o.y, r.s.h, r.s.w, last);
44 * First set up FFI types for the 3 struct types
47 point_type.size = 0; /*sizeof(Point);*/
48 point_type.alignment = 0; /*__alignof__(Point);*/
49 point_type.type = FFI_TYPE_STRUCT;
50 point_type.elements = malloc(3 * sizeof(ffi_type*));
51 point_type.elements[0] = &ffi_type_float;
52 point_type.elements[1] = &ffi_type_float;
53 point_type.elements[2] = NULL;
55 size_type.size = 0;/* sizeof(Size);*/
56 size_type.alignment = 0;/* __alignof__(Size);*/
57 size_type.type = FFI_TYPE_STRUCT;
58 size_type.elements = malloc(3 * sizeof(ffi_type*));
59 size_type.elements[0] = &ffi_type_float;
60 size_type.elements[1] = &ffi_type_float;
61 size_type.elements[2] = NULL;
63 rect_type.size = 0;/*sizeof(Rect);*/
64 rect_type.alignment =0;/* __alignof__(Rect);*/
65 rect_type.type = FFI_TYPE_STRUCT;
66 rect_type.elements = malloc(3 * sizeof(ffi_type*));
67 rect_type.elements[0] = &point_type;
68 rect_type.elements[1] = &size_type;
69 rect_type.elements[2] = NULL;
74 arglist[0] = &ffi_type_sint;
75 arglist[1] = &ffi_type_pointer;
76 arglist[2] = &point_type;
77 arglist[3] = &rect_type;
78 arglist[4] = &ffi_type_sint;
81 r = ffi_prep_cif(&cif, FFI_DEFAULT_ABI,
82 5, &ffi_type_sint, arglist);
88 /* And call the function through the CIF */
91 Point p = { 1.0, 2.0 };
92 Rect r = { { 9.0, 10.0}, { -1.0, -2.0 } };
105 printf("CALLING WITH %d %s {%f %f} {{%f %f} {%f %f}} %d\n",
106 o, m, p.x, p.y, r.o.x, r.o.y, r.s.h, r.s.w, l);
108 ffi_call(&cif, FFI_FN(doit), &result, values);
110 printf ("The result is %d\n", (int)result);