1 /*-------------------------------------------------------------------------
4 * Tuple macros used by both index tuples and heap tuples.
7 * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $Id: tupmacs.h,v 1.13 2000/01/26 05:57:51 momjian Exp $
12 *-------------------------------------------------------------------------
17 #include "utils/memutils.h"
20 * check to see if the ATT'th bit of an array of 8-bit bytes is set.
22 #define att_isnull(ATT, BITS) (!((BITS)[(ATT) >> 3] & (1 << ((ATT) & 0x07))))
25 * given a Form_pg_attribute and a pointer into a tuple's data
26 * area, return the correct value or pointer.
28 * We return a 4 byte (char *) value in all cases. If the attribute has
29 * "byval" false or has variable length, we return the same pointer
30 * into the tuple data area that we're passed. Otherwise, we return
31 * the 1, 2, or 4 bytes pointed to by it, properly extended to 4
32 * bytes, depending on the length of the attribute.
34 * note that T must already be properly LONGALIGN/SHORTALIGN'd for
35 * this to work correctly.
37 * the double-cast is to stop gcc from (correctly) complaining about
38 * casting integer types with size < sizeof(char *) to (char *).
39 * sign-extension may get weird if you use an integer type that
40 * isn't the same size as (char *) for the first cast. (on the other
41 * hand, it's safe to use another type for the (foo *)(T).)
43 * attbyval seems to be fairly redundant. We have to return a pointer if
44 * the value is longer than 4 bytes or has variable length; returning the
45 * value would be useless. In fact, for at least the variable length case,
46 * the caller assumes we return a pointer regardless of attbyval.
47 * I would eliminate attbyval altogether, but I don't know how. -BRYANH.
49 #define fetchatt(A, T) \
51 (*(A))->attbyval && (*(A))->attlen != -1 ? \
53 (*(A))->attlen > sizeof(int16) ? \
55 (char *) (long) *((int32 *)(T)) \
59 (*(A))->attlen < sizeof(int16) ? \
60 (char *) (long) *((char *)(T)) \
62 (char *) (long) *((int16 *)(T))) \
68 /* att_align aligns the given offset as needed for a datum of length attlen
69 * and alignment requirement attalign. In practice we don't need the length.
70 * The attalign cases are tested in what is hopefully something like their
71 * frequency of occurrence.
73 #define att_align(cur_offset, attlen, attalign) \
75 ((attalign) == 'i') ? INTALIGN(cur_offset) : \
76 (((attalign) == 'c') ? ((long)(cur_offset)) : \
77 (((attalign) == 'd') ? DOUBLEALIGN(cur_offset) : \
79 AssertMacro((attalign) == 's'), \
80 SHORTALIGN(cur_offset) \
84 #define att_addlength(cur_offset, attlen, attval) \
88 (cur_offset) + (attlen) \
92 (cur_offset) + VARATT_SIZE(DatumGetPointer(attval)) \