1 /* Trampoline test */
2 
3 /*
4  * Copyright 1995-2017 Bruno Haible <bruno@clisp.org>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #include "config.h"  /* Define __${host_cpu}__ */
21 
22 #include <stdio.h>
23 #include <stdlib.h>
24 
25 #include "callback.h"
26 
27 #define MAGIC1  0x9db9af42
28 #define MAGIC2  0xa2f9d045
29 #define MAGIC3  0x7aff3cb4
30 
f(int x)31 int f (int x)
32 {
33   return x + MAGIC3;
34 }
35 
vf(void * data,va_alist alist)36 void vf (void* data, va_alist alist)
37 {
38   if (data != (void*)MAGIC1) { printf("wrong data\n"); exit(1); }
39   va_start_int(alist);
40  {int a = va_arg_int(alist);
41   int r = f(a);
42   va_return_int(alist, r);
43 }}
44 
main()45 int main ()
46 {
47   callback_t cf = alloc_callback(&vf, (void*)MAGIC1);
48   if ((*cf)(MAGIC2) == MAGIC2+MAGIC3)
49     { free_callback(cf); printf("Works, test1 passed.\n"); exit(0); }
50   else
51     { printf("Doesn't work!\n"); exit(1); }
52 }
53