Debian Codegraph @

ext/GOTCHA/src/example/minimal/sampleLib.c

raw symbols SCIP
1 /*
2 This file is part of GOTCHA. For copyright information see the COPYRIGHT
3 file in the top level directory, or at
4 https://github.com/LLNL/gotcha/blob/master/COPYRIGHT
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU Lesser General Public License (as published by the Free
7 Software Foundation) version 2.1 dated February 1999. This program is
8 distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 PURPOSE. See the terms and conditions of the GNU Lesser General Public License
11 for more details. You should have received a copy of the GNU Lesser General
12 Public License along with this program; if not, write to the Free Software
13 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14 */
15
16 #include "sampleLib.h"
17
18 #include <stdio.h>
19
20 // We need a place to store the pointer to the function we've wrapped
21 gotcha_wrappee_handle_t origRetX_handle;
22
23 /**
24 * We need to express our desired wrapping behavior to
25 * GOTCHA. For that we need three things:
26 *
27 * 1) The name of a symbol to wrap
28 * 2) The function we want to wrap it with
29 * 3) Some place to store the original function, if we wish
30 * to call it
31 *
32 * This variable bindings gets filled out with a list of three
33 * element structs containing those things.
34 *
35 * Note that the place to store the original function is passed
36 * by reference, this is required for us to be able to change it
37 */
38 struct gotcha_binding_t bindings[] = {{"retX", dogRetX, &origRetX_handle}};
39
40 // This is like a tool library's initialization function
41 int sample_init() {
42 gotcha_wrap(bindings, 1, "gotcha_internal_sample_tool");
43 return 0;
44 }
45
46 /**
47 * In our example, this is the function we're wrapping.
48 * For convenience, it's in the same library, but this
49 * isn't a requirement imposed by GOTCHA
50 */
51 int retX(int x) { return x; }
52
53 /**
54 * This is our wrapper function. All GOTCHA wrappers *must*
55 * reference dogs somewhere in the code. I didn't write the
56 * rules (yes I did)
57 */
58 int dogRetX(int x) {
59 typeof(&dogRetX) origRetX = gotcha_get_wrappee(origRetX_handle);
60 printf("SO I FOR ONE THINK DOGS SHOULD RETURN %i\n", x);
61 return origRetX ? origRetX(x) + 1 : 0;
62 }