1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include <fwd/mod.h>
long fwdmalloc(fwd_extern_args_t args)
{
assert(args.argc == 1);
size_t n = FWD_ARG_T(args, 0, size_t);
FWD_RET(FWD_PTR, malloc(n));
return 0;
}
long fwdrealloc(fwd_extern_args_t args)
{
assert(args.argc == 2);
void *ptr = FWD_ARG(args, 0, void *, FWD_PTR);
size_t n = FWD_ARG_T(args, 1, size_t);
FWD_RET(FWD_PTR, realloc(ptr, n));
return 0;
}
long fwdfree(fwd_extern_args_t args)
{
assert(args.argc == 1);
void *ptr = FWD_ARG(args, 0, void *, FWD_PTR);
return 0;
}
int fwdopen(fwd_state_t *state)
{
FWD_REGISTER(state, fwdmalloc,
FWD_PTR, FWD_T(size_t));
FWD_REGISTER(state, fwdrealloc,
FWD_PTR, FWD_PTR, FWD_T(size_t));
FWD_REGISTER(state, fwdfree,
FWD_VOID, FWD_PTR);
return 0;
}
|