~ubuntu-branches/debian/squeeze/ffcall/squeeze

« back to all changes in this revision

Viewing changes to ffcall/trampoline/test2.c

  • Committer: Bazaar Package Importer
  • Author(s): Christoph Egger
  • Date: 2010-06-26 15:29:30 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100626152930-c09y01gk3szcnykn
Tags: 1.10+cvs20100619-2
Ship to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Trampoline accessor test */
2
 
 
3
 
/*
4
 
 * Copyright 1995-1999, 2002, 2005 Bruno Haible, <bruno@clisp.org>
5
 
 *
6
 
 * This is free software distributed under the GNU General Public Licence
7
 
 * described in the file COPYING. Contact the author if you don't have this
8
 
 * or can't live with it. There is ABSOLUTELY NO WARRANTY, explicit or implied,
9
 
 * on this software.
10
 
 */
11
 
 
12
 
#include <stdio.h>
13
 
#include <stdlib.h>
14
 
 
15
 
#include "trampoline.h"
16
 
 
17
 
#ifdef __cplusplus
18
 
typedef int (*function)(...);
19
 
#else
20
 
typedef int (*function)();
21
 
#endif
22
 
 
23
 
int f (int x)
24
 
{ return x; }
25
 
 
26
 
void* variable;
27
 
 
28
 
static int data;
29
 
 
30
 
int main ()
31
 
{
32
 
  function cf = alloc_trampoline((function)&f, &variable, &data);
33
 
  if (is_trampoline((void*)&main))
34
 
    { printf("is_trampoline(&main) returns true!\n"); exit(1); }
35
 
  if (!is_trampoline((void*)cf))
36
 
    { printf("is_trampoline() returns false!\n"); exit(1); }
37
 
  if (trampoline_address((void*)cf) != (function)&f)
38
 
    { printf("trampoline_address() doesn't work!\n"); exit(1); }
39
 
  if (trampoline_variable((void*)cf) != &variable)
40
 
    { printf("trampoline_variable() doesn't work!\n"); exit(1); }
41
 
  if (trampoline_data((void*)cf) != &data)
42
 
    { printf("trampoline_data() doesn't work!\n"); exit(1); }
43
 
  printf("test2 passed.\n");
44
 
  exit(0);
45
 
}