6 static const char *tccdir
= NULL
;
8 typedef int (*callback_type
) (void*);
11 * Compile source code and call a callback with a pointer to the symbol "f".
13 static int run_callback(const char *src
, callback_type callback
) {
22 tcc_set_lib_path(s
, tccdir
);
23 if (tcc_set_output_type(s
, TCC_OUTPUT_MEMORY
) == -1)
25 if (tcc_compile_string(s
, src
) == -1)
27 if (tcc_relocate(s
, TCC_RELOCATE_AUTO
) == -1)
30 ptr
= tcc_get_symbol(s
, "f");
33 result
= callback(ptr
);
40 typedef struct test1_type_s
{int x
, y
;} test1_type
;
41 typedef test1_type (*test1_function_type
) ();
43 static int test1_callback(void *ptr
) {
45 r
= ((test1_function_type
)ptr
)();
46 return ((r
.x
== 10) && (r
.y
== 35)) ? 0 : -1;
51 "typedef struct test1_type_s {int x, y;} test1_type;"
53 " test1_type r = {10, 35};\n"
57 return run_callback(src
, test1_callback
);
62 fputs(#t "... ", stdout); \
65 fputs("success\n", stdout); \
67 fputs("failure\n", stdout); \
68 retval = EXIT_FAILURE; \
72 int main(int argc
, char **argv
) {
73 int retval
= EXIT_SUCCESS
;
74 /* if tcclib.h and libtcc1.a are not installed, where can we find them */
75 if (argc
== 2 && !memcmp(argv
[1], "lib_path=",9))