Ruby: ext/fiddle/libffi-3.2.1/testsuite/libffi.call/cls_ushort_va.c Source File

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

cls_ushort_va.c
Go to the documentation of this file.
1/* Area: closure_call
2 Purpose: Test anonymous unsigned short argument.
3 Limitations: none.
4 PR: none.
5 Originator: ARM Ltd. */
6
7/* { dg-do run } */
8#include "ffitest.h"
9
10 typedef unsigned short T;
11
12static void cls_ret_T_fn(ffi_cif* cif __UNUSED__, void* resp, void** args,
13 void* userdata __UNUSED__)
14 {
15 *(ffi_arg *)resp = *(T *)args[0];
16
17 printf("%d: %d %d\n", (int)(*(ffi_arg *)resp), *(T *)args[0], *(T *)args[1]);
18 }
19
20 typedef T (*cls_ret_T)(T, ...);
21
22 int main (void)
23{
24 ffi_cif cif;
25 void *code;
26 ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
27 ffi_type * cl_arg_types[3];
28 T res;
29
30 cl_arg_types[0] = &ffi_type_ushort;
31 cl_arg_types[1] = &ffi_type_ushort;
32 cl_arg_types[2] = NULL;
33
34 /* Initialize the cif */
35 CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 2,
36 &ffi_type_ushort, cl_arg_types) == FFI_OK);
37
38 CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_T_fn, NULL, code) == FFI_OK);
39 res = ((((cls_ret_T)code)(67, 4)));
40 /* { dg-output "67: 67 4" } */
41 printf("res: %d\n", res);
42 /* { dg-output "\nres: 67" } */
43 exit(0);
44}
ffi_prep_closure_loc
ffi_status ffi_prep_closure_loc(ffi_closure *closure, ffi_cif *cif, void(*fun)(ffi_cif *, void *, void **, void *), void *user_data, void *codeloc)
Definition: ffi.c:928
ffi_arg
unsigned long ffi_arg
Definition: ffitarget.h:30
FFI_DEFAULT_ABI
@ FFI_DEFAULT_ABI
Definition: ffitarget.h:38
T
unsigned char T
Definition: cls_uchar_va.c:10
main
int main(void)
Definition: cls_ushort_va.c:22
cls_ret_T
T(* cls_ret_T)(T,...)
Definition: cls_ushort_va.c:20
T
unsigned short T
Definition: cls_ushort_va.c:10
CHECK
#define CHECK(sub)
Definition: compile.c:429
ffitest.h
__UNUSED__
#define __UNUSED__
Definition: ffitest.h:23
ffi_prep_cif_var
ffi_status ffi_prep_cif_var(ffi_cif *cif, ffi_abi abi, unsigned int nfixedargs, unsigned int ntotalargs, ffi_type *rtype, ffi_type **atypes)
Definition: prep_cif.c:232
NULL
#define NULL
Definition: regenc.h:69
code
Definition: inftree9.h:24