PostgreSQL Source Code: src/include/utils/relptr.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef RELPTR_H
15#define RELPTR_H
16
17
18
19
20
21
22
23
24
25
26
27
28
29#define relptr(type) union { type *relptr_type; Size relptr_off; }
30
31
32
33
34
35
36
37
38#define relptr_declare(type, relptrtype) \
39 typedef relptr(type) relptrtype
40
41#ifdef HAVE_TYPEOF
42#define relptr_access(base, rp) \
43 (StaticAssertVariableIsOfTypeMacro(base, char *), \
44 (typeof((rp).relptr_type)) ((rp).relptr_off == 0 ? NULL : \
45 (base) + (rp).relptr_off - 1))
46#else
47#define relptr_access(base, rp) \
48 (StaticAssertVariableIsOfTypeMacro(base, char *), \
49 (void *) ((rp).relptr_off == 0 ? NULL : (base) + (rp).relptr_off - 1))
50#endif
51
52#define relptr_is_null(rp) \
53 ((rp).relptr_off == 0)
54
55#define relptr_offset(rp) \
56 ((rp).relptr_off - 1)
57
58
59static inline Size
61{
63 return 0;
64 else
65 {
67 return val - base + 1;
68 }
69}
70
71#ifdef HAVE_TYPEOF
72#define relptr_store(base, rp, val) \
73 (StaticAssertVariableIsOfTypeMacro(base, char *), \
74 StaticAssertVariableIsOfTypeMacro(val, typeof((rp).relptr_type)), \
75 (rp).relptr_off = relptr_store_eval((base), (char *) (val)))
76#else
77#define relptr_store(base, rp, val) \
78 (StaticAssertVariableIsOfTypeMacro(base, char *), \
79 (rp).relptr_off = relptr_store_eval((base), (char *) (val)))
80#endif
81
82#define relptr_copy(rp1, rp2) \
83 ((rp1).relptr_off = (rp2).relptr_off)
84
85#endif
#define Assert(condition)
static Size relptr_store_eval(char *base, char *val)