|
22 | 22 | * Note that a 0 in the null bitmap indicates a null, while 1 indicates
|
23 | 23 | * non-null.
|
24 | 24 | */
|
25 |
| -#define att_isnull(ATT, BITS) (!((BITS)[(ATT) >> 3] & (1 << ((ATT) & 0x07)))) |
| 25 | +static inline bool |
| 26 | +att_isnull(int ATT, const bits8 *BITS) |
| 27 | +{ |
| 28 | + return !(BITS[ATT >> 3] & (1 << (ATT & 0x07))); |
| 29 | +} |
26 | 30 |
|
| 31 | +#ifndef FRONTEND |
27 | 32 | /*
|
28 | 33 | * Given a Form_pg_attribute and a pointer into a tuple's data area,
|
29 | 34 | * return the correct value or pointer.
|
|
43 | 48 | /*
|
44 | 49 | * Same, but work from byval/len parameters rather than Form_pg_attribute.
|
45 | 50 | */
|
| 51 | +static inline Datum |
| 52 | +fetch_att(const void *T, bool attbyval, int attlen) |
| 53 | +{ |
| 54 | + if (attbyval) |
| 55 | + { |
| 56 | + switch (attlen) |
| 57 | + { |
| 58 | + case sizeof(char): |
| 59 | + return CharGetDatum(*((const char *) T)); |
| 60 | + case sizeof(int16): |
| 61 | + return Int16GetDatum(*((const int16 *) T)); |
| 62 | + case sizeof(int32): |
| 63 | + return Int32GetDatum(*((const int32 *) T)); |
46 | 64 | #if SIZEOF_DATUM == 8
|
47 |
| - |
48 |
| -#define fetch_att(T,attbyval,attlen) \ |
49 |
| -( \ |
50 |
| - (attbyval) ? \ |
51 |
| - ( \ |
52 |
| - (attlen) == (int) sizeof(Datum) ? \ |
53 |
| - *((Datum *)(T)) \ |
54 |
| - : \ |
55 |
| - ( \ |
56 |
| - (attlen) == (int) sizeof(int32) ? \ |
57 |
| - Int32GetDatum(*((int32 *)(T))) \ |
58 |
| - : \ |
59 |
| - ( \ |
60 |
| - (attlen) == (int) sizeof(int16) ? \ |
61 |
| - Int16GetDatum(*((int16 *)(T))) \ |
62 |
| - : \ |
63 |
| - ( \ |
64 |
| - AssertMacro((attlen) == 1), \ |
65 |
| - CharGetDatum(*((char *)(T))) \ |
66 |
| - ) \ |
67 |
| - ) \ |
68 |
| - ) \ |
69 |
| - ) \ |
70 |
| - : \ |
71 |
| - PointerGetDatum((char *) (T)) \ |
72 |
| -) |
73 |
| -#else /* SIZEOF_DATUM != 8 */ |
74 |
| - |
75 |
| -#define fetch_att(T,attbyval,attlen) \ |
76 |
| -( \ |
77 |
| - (attbyval) ? \ |
78 |
| - ( \ |
79 |
| - (attlen) == (int) sizeof(int32) ? \ |
80 |
| - Int32GetDatum(*((int32 *)(T))) \ |
81 |
| - : \ |
82 |
| - ( \ |
83 |
| - (attlen) == (int) sizeof(int16) ? \ |
84 |
| - Int16GetDatum(*((int16 *)(T))) \ |
85 |
| - : \ |
86 |
| - ( \ |
87 |
| - AssertMacro((attlen) == 1), \ |
88 |
| - CharGetDatum(*((char *)(T))) \ |
89 |
| - ) \ |
90 |
| - ) \ |
91 |
| - ) \ |
92 |
| - : \ |
93 |
| - PointerGetDatum((char *) (T)) \ |
94 |
| -) |
95 |
| -#endif /* SIZEOF_DATUM == 8 */ |
| 65 | + case sizeof(Datum): |
| 66 | + return *((const Datum *) T); |
| 67 | +#endif |
| 68 | + default: |
| 69 | + elog(ERROR, "unsupported byval length: %d", attlen); |
| 70 | + return 0; |
| 71 | + } |
| 72 | + } |
| 73 | + else |
| 74 | + return PointerGetDatum(T); |
| 75 | +} |
| 76 | +#endif /* FRONTEND */ |
96 | 77 |
|
97 | 78 | /*
|
98 | 79 | * att_align_datum aligns the given offset as needed for a datum of alignment
|
|
190 | 171 | )) \
|
191 | 172 | )
|
192 | 173 |
|
| 174 | +#ifndef FRONTEND |
193 | 175 | /*
|
194 | 176 | * store_att_byval is a partial inverse of fetch_att: store a given Datum
|
195 | 177 | * value into a tuple data area at the specified address. However, it only
|
196 | 178 | * handles the byval case, because in typical usage the caller needs to
|
197 |
| - * distinguish by-val and by-ref cases anyway, and so a do-it-all macro |
| 179 | + * distinguish by-val and by-ref cases anyway, and so a do-it-all function |
198 | 180 | * wouldn't be convenient.
|
199 | 181 | */
|
| 182 | +static inline void |
| 183 | +store_att_byval(void *T, Datum newdatum, int attlen) |
| 184 | +{ |
| 185 | + switch (attlen) |
| 186 | + { |
| 187 | + case sizeof(char): |
| 188 | + *(char *) T = DatumGetChar(newdatum); |
| 189 | + break; |
| 190 | + case sizeof(int16): |
| 191 | + *(int16 *) T = DatumGetInt16(newdatum); |
| 192 | + break; |
| 193 | + case sizeof(int32): |
| 194 | + *(int32 *) T = DatumGetInt32(newdatum); |
| 195 | + break; |
200 | 196 | #if SIZEOF_DATUM == 8
|
201 |
| - |
202 |
| -#define store_att_byval(T,newdatum,attlen) \ |
203 |
| - do { \ |
204 |
| - switch (attlen) \ |
205 |
| - { \ |
206 |
| - case sizeof(char): \ |
207 |
| - *(char *) (T) = DatumGetChar(newdatum); \ |
208 |
| - break; \ |
209 |
| - case sizeof(int16): \ |
210 |
| - *(int16 *) (T) = DatumGetInt16(newdatum); \ |
211 |
| - break; \ |
212 |
| - case sizeof(int32): \ |
213 |
| - *(int32 *) (T) = DatumGetInt32(newdatum); \ |
214 |
| - break; \ |
215 |
| - case sizeof(Datum): \ |
216 |
| - *(Datum *) (T) = (newdatum); \ |
217 |
| - break; \ |
218 |
| - default: \ |
219 |
| - elog(ERROR, "unsupported byval length: %d", \ |
220 |
| - (int) (attlen)); \ |
221 |
| - break; \ |
222 |
| - } \ |
223 |
| - } while (0) |
224 |
| -#else /* SIZEOF_DATUM != 8 */ |
225 |
| - |
226 |
| -#define store_att_byval(T,newdatum,attlen) \ |
227 |
| - do { \ |
228 |
| - switch (attlen) \ |
229 |
| - { \ |
230 |
| - case sizeof(char): \ |
231 |
| - *(char *) (T) = DatumGetChar(newdatum); \ |
232 |
| - break; \ |
233 |
| - case sizeof(int16): \ |
234 |
| - *(int16 *) (T) = DatumGetInt16(newdatum); \ |
235 |
| - break; \ |
236 |
| - case sizeof(int32): \ |
237 |
| - *(int32 *) (T) = DatumGetInt32(newdatum); \ |
238 |
| - break; \ |
239 |
| - default: \ |
240 |
| - elog(ERROR, "unsupported byval length: %d", \ |
241 |
| - (int) (attlen)); \ |
242 |
| - break; \ |
243 |
| - } \ |
244 |
| - } while (0) |
245 |
| -#endif /* SIZEOF_DATUM == 8 */ |
246 |
| - |
| 197 | + case sizeof(Datum): |
| 198 | + *(Datum *) T = newdatum; |
| 199 | + break; |
247 | 200 | #endif
|
| 201 | + default: |
| 202 | + elog(ERROR, "unsupported byval length: %d", attlen); |
| 203 | + } |
| 204 | +} |
| 205 | +#endif /* FRONTEND */ |
| 206 | + |
| 207 | +#endif /* TUPMACS_H */ |
0 commit comments