Debian Codegraph @

t/ffi/closure.c

raw
1 #include "libtest.h"
2
3 typedef int (*closure1_t)(void);
4 typedef int (*closure2_t)(int);
5 static closure1_t my_closure1;
6 static closure2_t my_closure2;
7
8 EXTERN void
9 closure_set_closure1(closure1_t closure)
10 {
11 my_closure1 = closure;
12 }
13
14 EXTERN void
15 closure_set_closure2(closure2_t closure)
16 {
17 my_closure2 = closure;
18 }
19
20 EXTERN int
21 closure_call_closure1(void)
22 {
23 return my_closure1();
24 }
25
26 EXTERN int
27 closure_call_closure2(int arg)
28 {
29 return my_closure2(arg);
30 }
31
32 EXTERN int
33 closure_call_closure_immediate(closure2_t closure, int arg)
34 {
35 return closure(arg);
36 }
37
38 typedef struct {
39 const char *one;
40 const char *two;
41 int three;
42 const char *four;
43 int myarray1[2];
44 void *opaque1;
45 void *myarray2[2];
46 char fixedfive[5];
47 } cx_struct_t;
48
49 typedef void (*cx_closure_t)(cx_struct_t *, int);
50 static cx_closure_t my_cx_closure;
51
52 EXTERN void
53 cx_closure_set(cx_closure_t closure)
54 {
55 my_cx_closure = closure;
56 }
57
58 EXTERN void
59 cx_closure_call(cx_struct_t *s, int i)
60 {
61 my_cx_closure(s, i);
62 }
63
64 typedef void (*cxv_closure_t)(cx_struct_t, int);
65 static cxv_closure_t my_cxv_closure;
66
67 EXTERN void
68 cxv_closure_set(cxv_closure_t closure)
69 {
70 my_cxv_closure = closure;
71 }
72
73 EXTERN void
74 cxv_closure_call(cx_struct_t s, int i)
75 {
76 my_cxv_closure(s, i);
77 }
78
79 typedef struct {
80 char foo;
81 short bar;
82 int baz;
83 } cx_struct_simple_t;
84
85 typedef cx_struct_simple_t (*cxv_closure_simple_t)(void);
86
87 EXTERN cx_struct_simple_t*
88 cxv_closure_simple_call(cxv_closure_simple_t closure)
89 {
90 static cx_struct_simple_t simple;
91 simple = closure();
92 return &simple;
93 }