~bkerensa/ubuntu/raring/valgrind/merge-from-deb

« back to all changes in this revision

Viewing changes to memcheck/tests/wrap3.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-06-26 00:17:17 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20060626001717-qi51nzty57cb12q6
Tags: upstream-3.2.0
Import upstream version 3.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <stdio.h>
 
3
#include "valgrind.h"
 
4
 
 
5
/* Check that function wrapping works for a mutually recursive
 
6
   pair. */
 
7
 
 
8
static int fact1 ( int n );
 
9
static int fact2 ( int n );
 
10
 
 
11
/* This is needed to stop gcc4 turning 'fact' into a loop */
 
12
__attribute__((noinline))
 
13
int mul ( int x, int y ) { return x * y; }
 
14
 
 
15
int fact1 ( int n )
 
16
{
 
17
   if (n == 0) return 1; else return mul(n, fact2(n-1));
 
18
}
 
19
int fact2 ( int n )
 
20
{
 
21
   if (n == 0) return 1; else return mul(n, fact1(n-1));
 
22
}
 
23
 
 
24
 
 
25
int I_WRAP_SONAME_FNNAME_ZU(NONE,fact1) ( int n )
 
26
{
 
27
   int    r;
 
28
   OrigFn fn;
 
29
   VALGRIND_GET_ORIG_FN(fn);
 
30
   printf("in wrapper1-pre:  fact(%d)\n", n);
 
31
   CALL_FN_W_W(r,fn,n);
 
32
   printf("in wrapper1-post: fact(%d) = %d\n", n, r);
 
33
   return r;
 
34
}
 
35
 
 
36
int I_WRAP_SONAME_FNNAME_ZU(NONE,fact2) ( int n )
 
37
{
 
38
   int    r;
 
39
   OrigFn fn;
 
40
   VALGRIND_GET_ORIG_FN(fn);
 
41
   printf("in wrapper2-pre:  fact(%d)\n", n);
 
42
   CALL_FN_W_W(r,fn,n);
 
43
   printf("in wrapper2-post: fact(%d) = %d\n", n, r);
 
44
   return r;
 
45
}
 
46
 
 
47
/* --------------- */
 
48
 
 
49
int main ( void )
 
50
{
 
51
   int r;
 
52
   printf("computing fact1(5)\n");
 
53
   r = fact1(5);
 
54
   printf("fact1(5) = %d\n", r);
 
55
   return 0;
 
56
}