]> granicus.if.org Git - postgresql/blob - src/include/access/tupmacs.h
Change my-function-name-- to my_function_name, and optimizer renames.
[postgresql] / src / include / access / tupmacs.h
1 /*-------------------------------------------------------------------------
2  *
3  * tupmacs.h
4  *        Tuple macros used by both index tuples and heap tuples.
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: tupmacs.h,v 1.8 1999/02/13 23:20:59 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef TUPMACS_H
14 #define TUPMACS_H
15
16 /*
17  * check to see if the ATT'th bit of an array of 8-bit bytes is set.
18  */
19 #define att_isnull(ATT, BITS) (!((BITS)[(ATT) >> 3] & (1 << ((ATT) & 0x07))))
20
21 /*
22  * given a Form_pg_attribute and a pointer into a tuple's data
23  * area, return the correct value or pointer.
24  *
25  * We return a 4 byte (char *) value in all cases.      If the attribute has
26  * "byval" false or has variable length, we return the same pointer
27  * into the tuple data area that we're passed.  Otherwise, we return
28  * the 1, 2, or 4 bytes pointed to by it, properly extended to 4
29  * bytes, depending on the length of the attribute.
30  *
31  * note that T must already be properly LONGALIGN/SHORTALIGN'd for
32  * this to work correctly.
33  *
34  * the double-cast is to stop gcc from (correctly) complaining about
35  * casting integer types with size < sizeof(char *) to (char *).
36  * sign-extension may get weird if you use an integer type that
37  * isn't the same size as (char *) for the first cast.  (on the other
38  * hand, it's safe to use another type for the (foo *)(T).)
39  *
40  * attbyval seems to be fairly redundant.  We have to return a pointer if
41  * the value is longer than 4 bytes or has variable length; returning the
42  * value would be useless.      In fact, for at least the variable length case,
43  * the caller assumes we return a pointer regardless of attbyval.
44  * I would eliminate attbyval altogether, but I don't know how.  -BRYANH.
45  */
46 #define fetchatt(A, T) \
47 ( \
48         (*(A))->attbyval && (*(A))->attlen != -1 ? \
49         ( \
50                 (*(A))->attlen > sizeof(int16) ? \
51                 ( \
52                         (char *) (long) *((int32 *)(T)) \
53                 ) \
54                 : \
55                 ( \
56                         (*(A))->attlen < sizeof(int16) ? \
57                                 (char *) (long) *((char *)(T)) \
58                         : \
59                                 (char *) (long) *((int16 *)(T))) \
60                 ) \
61         : \
62         (char *) (T) \
63 )
64
65 #define att_align(cur_offset, attlen, attalign) \
66 ( \
67         ((attlen) < sizeof(int32)) ? \
68         ( \
69                 ((attlen) == -1) ? \
70                 ( \
71                         ((attalign) == 'd') ?   DOUBLEALIGN(cur_offset) : \
72                                                                         INTALIGN(cur_offset) \
73                 ) \
74                 : \
75                 ( \
76                         ((attlen) == sizeof(char)) ? \
77                         ( \
78                                 (long)(cur_offset) \
79                         ) \
80                         : \
81                         ( \
82                                 AssertMacro((attlen) == sizeof(short)), \
83                                 SHORTALIGN(cur_offset) \
84                         ) \
85                 ) \
86         ) \
87         : \
88         ( \
89                 ((attlen) == sizeof(int32)) ? \
90                 ( \
91                         INTALIGN(cur_offset) \
92                 ) \
93                 : \
94                 ( \
95                         AssertMacro((attlen) > sizeof(int32)), \
96                         ((attalign) == 'd') ?   DOUBLEALIGN(cur_offset) : \
97                                                                         LONGALIGN(cur_offset) \
98                 ) \
99         ) \
100 )
101         
102 #define att_addlength(cur_offset, attlen, attval) \
103 ( \
104         ((attlen) != -1) ? \
105         ( \
106                 (cur_offset) + (attlen) \
107         ) \
108         : \
109         ( \
110                 (cur_offset) + VARSIZE(DatumGetPointer(attval)) \
111         ) \
112 )
113         
114 #endif