Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f58d707

Browse files
committed
Convert macros to static inline functions (tupmacs.h)
Reviewed-by: Amul Sul <sulamul@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/5b558da8-99fb-0a99-83dd-f72f05388517%40enterprisedb.com
1 parent 8cf64d3 commit f58d707

File tree

2 files changed

+58
-98
lines changed

2 files changed

+58
-98
lines changed

src/include/access/itup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap;
114114
) \
115115
: \
116116
( \
117-
(att_isnull((attnum)-1, (char *)(tup) + sizeof(IndexTupleData))) ? \
117+
(att_isnull((attnum)-1, (bits8 *)(tup) + sizeof(IndexTupleData))) ? \
118118
( \
119119
*(isnull) = true, \
120120
(Datum)NULL \

src/include/access/tupmacs.h

Lines changed: 57 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
* Note that a 0 in the null bitmap indicates a null, while 1 indicates
2323
* non-null.
2424
*/
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+
}
2630

31+
#ifndef FRONTEND
2732
/*
2833
* Given a Form_pg_attribute and a pointer into a tuple's data area,
2934
* return the correct value or pointer.
@@ -43,56 +48,32 @@
4348
/*
4449
* Same, but work from byval/len parameters rather than Form_pg_attribute.
4550
*/
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));
4664
#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 */
9677

9778
/*
9879
* att_align_datum aligns the given offset as needed for a datum of alignment
@@ -190,58 +171,37 @@
190171
)) \
191172
)
192173

174+
#ifndef FRONTEND
193175
/*
194176
* store_att_byval is a partial inverse of fetch_att: store a given Datum
195177
* value into a tuple data area at the specified address. However, it only
196178
* 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
198180
* wouldn't be convenient.
199181
*/
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;
200196
#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;
247200
#endif
201+
default:
202+
elog(ERROR, "unsupported byval length: %d", attlen);
203+
}
204+
}
205+
#endif /* FRONTEND */
206+
207+
#endif /* TUPMACS_H */

0 commit comments

Comments
 (0)