-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpg_freespacemap.c.annotated
90 lines (80 loc) · 2.14 KB
/
pg_freespacemap.c.annotated
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*-------------------------------------------------------------------------
*
* pg_freespacemap.c
* display contents of a free space map
*
* $PostgreSQL$
*-------------------------------------------------------------------------
*/
#include "postgres.h"
/* I think only funcapi is necessary here */
#include "access/heapam.h"
#include "funcapi.h"
#include "storage/block.h"
#include "storage/freespace.h"
PG_MODULE_MAGIC;
Datum pg_freespace(PG_FUNCTION_ARGS);
/*
* Returns the amount of free space on a given page, according to the
* free space map.
*
* HASKELL GENERATED:
*
* Mostly static (except synname):
*
* PG_FUNCTION_INFO_V1(symname);
*/
PG_FUNCTION_INFO_V1(pg_freespace);
/*
* HASKELL GENERATED:
*
* (mostly static, except symname)
*
* Datum
* symname(PG_FUNCTION_ARGS)
*/
Datum
pg_freespace(PG_FUNCTION_ARGS)
{
/*
* HASKELL GENERATED:
*
* (May also have to generate the PG_GETARG_CTypeSym Macro)
*
* CTypeSym gensym = PG_GETARG_CTypeSym
*/
Oid relid = PG_GETARG_OID(0);
int64 blkno = PG_GETARG_INT64(1);
/*
* HASKELL GENERATED:
*
* Teach a mapping to the C generator from types like HSInt => postgres
* defined types. This is here just to get a tiny bit of type checking from
* gcc. (Dynamic portion: OutputCTypeSym)
*/
OutputCTypeSym retval;
/*
* HASKELL GENERATED:
*
* Prelude Args can be useful for passing additional interesting
* information or out-parameters like ErrData. Retval may be nonsensical
* should errdata be set. I think it's okay to have a fixed number of
* prelude args that every haskell function gets for free (ex: suppose
* haskell wants to know the current memory context).
*
* mangled_func_name(prelude_arg0, prelude_arg1, gensym_arg0, gensym_argn);
*/
retval = call_my_hs_function(&errdata, relid, blkno, ...);
/* Static C boilerplate, assuming prelude arg0 is the error data structure */
if (prelude_arg0 != NULL) {
/*
* Stuff to raise the error from errdata structures via
* longjmp-wrapping PG Constructs
*/
}
/*
* Must know how to extract a datum from the type involved (generally part
* of the macro)
*/
PG_RETURN_CTypeSym(retval);
}