|
22 | 22 | * Note that a 0 in the null bitmap indicates a null, while 1 indicates |
23 | 23 | * non-null. |
24 | 24 | */ |
25 | | -#defineatt_isnull(ATT,BITS) (!((BITS)[(ATT) >> 3] & (1 << ((ATT) & 0x07)))) |
| 25 | +staticinlinebool |
| 26 | +att_isnull(intATT,constbits8*BITS) |
| 27 | +{ |
| 28 | +return !(BITS[ATT >>3]& (1 << (ATT&0x07))); |
| 29 | +} |
26 | 30 |
|
| 31 | +#ifndefFRONTEND |
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 | +staticinlineDatum |
| 52 | +fetch_att(constvoid*T,boolattbyval,intattlen) |
| 53 | +{ |
| 54 | +if (attbyval) |
| 55 | +{ |
| 56 | +switch (attlen) |
| 57 | +{ |
| 58 | +casesizeof(char): |
| 59 | +returnCharGetDatum(*((constchar*)T)); |
| 60 | +casesizeof(int16): |
| 61 | +returnInt16GetDatum(*((constint16*)T)); |
| 62 | +casesizeof(int32): |
| 63 | +returnInt32GetDatum(*((constint32*)T)); |
46 | 64 | #ifSIZEOF_DATUM==8 |
47 | | - |
48 | | -#definefetch_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 | | -#definefetch_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 | +casesizeof(Datum): |
| 66 | +return*((constDatum*)T); |
| 67 | +#endif |
| 68 | +default: |
| 69 | +elog(ERROR,"unsupported byval length: %d",attlen); |
| 70 | +return0; |
| 71 | +} |
| 72 | +} |
| 73 | +else |
| 74 | +returnPointerGetDatum(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 | +#ifndefFRONTEND |
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-allmacro |
| 179 | + * distinguish by-val and by-ref cases anyway, and so a do-it-allfunction |
198 | 180 | * wouldn't be convenient. |
199 | 181 | */ |
| 182 | +staticinlinevoid |
| 183 | +store_att_byval(void*T,Datumnewdatum,intattlen) |
| 184 | +{ |
| 185 | +switch (attlen) |
| 186 | +{ |
| 187 | +casesizeof(char): |
| 188 | +*(char*)T=DatumGetChar(newdatum); |
| 189 | +break; |
| 190 | +casesizeof(int16): |
| 191 | +*(int16*)T=DatumGetInt16(newdatum); |
| 192 | +break; |
| 193 | +casesizeof(int32): |
| 194 | +*(int32*)T=DatumGetInt32(newdatum); |
| 195 | +break; |
200 | 196 | #ifSIZEOF_DATUM==8 |
201 | | - |
202 | | -#definestore_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 | | -#definestore_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 | +casesizeof(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 */ |