summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/htup.h10
-rw-r--r--src/include/access/tupmacs.h2
-rw-r--r--src/include/c.h13
-rw-r--r--src/include/postgres.h26
-rw-r--r--src/include/utils/array.h10
-rw-r--r--src/include/utils/geo_decls.h4
-rw-r--r--src/include/utils/numeric.h4
-rw-r--r--src/include/utils/pg_lzcompress.h4
-rw-r--r--src/include/utils/rel.h2
-rw-r--r--src/include/utils/varbit.h3
10 files changed, 40 insertions, 38 deletions
diff --git a/src/include/access/htup.h b/src/include/access/htup.h
index 54f2c3392a..b19c4164e4 100644
--- a/src/include/access/htup.h
+++ b/src/include/access/htup.h
@@ -115,7 +115,7 @@ typedef struct HeapTupleFields
typedef struct DatumTupleFields
{
- int32 datum_len; /* required to be a varlena type */
+ int32 datum_len_; /* varlena header (do not touch directly!) */
int32 datum_typmod; /* -1, or identifier of a record type */
@@ -260,14 +260,10 @@ do { \
} while (0)
#define HeapTupleHeaderGetDatumLength(tup) \
-( \
- (tup)->t_choice.t_datum.datum_len \
-)
+ VARSIZE(tup)
#define HeapTupleHeaderSetDatumLength(tup, len) \
-( \
- (tup)->t_choice.t_datum.datum_len = (len) \
-)
+ SET_VARSIZE(tup, len)
#define HeapTupleHeaderGetTypeId(tup) \
( \
diff --git a/src/include/access/tupmacs.h b/src/include/access/tupmacs.h
index ad5c279b58..44f832f521 100644
--- a/src/include/access/tupmacs.h
+++ b/src/include/access/tupmacs.h
@@ -118,7 +118,7 @@
) \
: (((attlen) == -1) ? \
( \
- (cur_offset) + VARATT_SIZE(DatumGetPointer(attval)) \
+ (cur_offset) + VARSIZE(DatumGetPointer(attval)) \
) \
: \
( \
diff --git a/src/include/c.h b/src/include/c.h
index 18d116968a..b6733b59e1 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -399,13 +399,16 @@ typedef struct
* NOTE: for TOASTable types, this is an oversimplification, since the value
* may be compressed or moved out-of-line. However datatype-specific routines
* are mostly content to deal with de-TOASTed values only, and of course
- * client-side routines should never see a TOASTed value. See postgres.h for
- * details of the TOASTed form.
+ * client-side routines should never see a TOASTed value. But even in a
+ * de-TOASTed value, beware of touching vl_len_ directly, as its representation
+ * is no longer convenient. It's recommended that code always use the VARDATA,
+ * VARSIZE, and SET_VARSIZE macros instead of relying on direct mentions of
+ * the struct fields. See postgres.h for details of the TOASTed form.
* ----------------
*/
struct varlena
{
- int32 vl_len;
+ int32 vl_len_; /* Do not touch this field directly! */
char vl_dat[1];
};
@@ -433,7 +436,7 @@ typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */
*/
typedef struct
{
- int32 size; /* these fields must match ArrayType! */
+ int32 vl_len_; /* these fields must match ArrayType! */
int ndim; /* always 1 for int2vector */
int32 dataoffset; /* always 0 for int2vector */
Oid elemtype;
@@ -444,7 +447,7 @@ typedef struct
typedef struct
{
- int32 size; /* these fields must match ArrayType! */
+ int32 vl_len_; /* these fields must match ArrayType! */
int ndim; /* always 1 for oidvector */
int32 dataoffset; /* always 0 for oidvector */
Oid elemtype;
diff --git a/src/include/postgres.h b/src/include/postgres.h
index 52a979545d..00c92e7822 100644
--- a/src/include/postgres.h
+++ b/src/include/postgres.h
@@ -56,12 +56,13 @@
/* ----------------
* struct varattrib is the header of a varlena object that may have been
- * TOASTed.
+ * TOASTed. Generally, only the code closely associated with TOAST logic
+ * should mess directly with struct varattrib or use the VARATT_FOO macros.
* ----------------
*/
typedef struct varattrib
{
- int32 va_header; /* External/compressed storage */
+ int32 va_header_; /* External/compressed storage */
/* flags and item size */
union
{
@@ -88,20 +89,21 @@ typedef struct varattrib
#define VARATT_MASK_FLAGS 0xc0000000
#define VARATT_MASK_SIZE 0x3fffffff
-#define VARATT_SIZEP(_PTR) (((varattrib *)(_PTR))->va_header)
-#define VARATT_SIZE(PTR) (VARATT_SIZEP(PTR) & VARATT_MASK_SIZE)
-#define VARATT_DATA(PTR) (((varattrib *)(PTR))->va_content.va_data)
-#define VARATT_CDATA(PTR) (((varattrib *)(PTR))->va_content.va_compressed.va_data)
-
-#define VARSIZE(__PTR) VARATT_SIZE(__PTR)
-#define VARDATA(__PTR) VARATT_DATA(__PTR)
+#define VARATT_SIZEP_DEPRECATED(PTR) (((varattrib *) (PTR))->va_header_)
#define VARATT_IS_EXTENDED(PTR) \
- ((VARATT_SIZEP(PTR) & VARATT_MASK_FLAGS) != 0)
+ ((VARATT_SIZEP_DEPRECATED(PTR) & VARATT_MASK_FLAGS) != 0)
#define VARATT_IS_EXTERNAL(PTR) \
- ((VARATT_SIZEP(PTR) & VARATT_FLAG_EXTERNAL) != 0)
+ ((VARATT_SIZEP_DEPRECATED(PTR) & VARATT_FLAG_EXTERNAL) != 0)
#define VARATT_IS_COMPRESSED(PTR) \
- ((VARATT_SIZEP(PTR) & VARATT_FLAG_COMPRESSED) != 0)
+ ((VARATT_SIZEP_DEPRECATED(PTR) & VARATT_FLAG_COMPRESSED) != 0)
+
+/* These macros are the ones for non-TOAST code to use */
+
+#define VARSIZE(PTR) (VARATT_SIZEP_DEPRECATED(PTR) & VARATT_MASK_SIZE)
+#define VARDATA(PTR) (((varattrib *) (PTR))->va_content.va_data)
+
+#define SET_VARSIZE(PTR,SIZE) (VARATT_SIZEP_DEPRECATED(PTR) = (SIZE))
/* ----------------------------------------------------------------
diff --git a/src/include/utils/array.h b/src/include/utils/array.h
index 155272f3dd..1e685a5d97 100644
--- a/src/include/utils/array.h
+++ b/src/include/utils/array.h
@@ -4,7 +4,7 @@
* Declarations for Postgres arrays.
*
* A standard varlena array has the following internal structure:
- * <size> - total number of bytes (also, TOAST info flags)
+ * <vl_len_> - standard varlena header word
* <ndim> - number of dimensions of the array
* <dataoffset> - offset to stored data, or 0 if no nulls bitmap
* <elemtype> - element type OID
@@ -61,18 +61,22 @@
/*
* Arrays are varlena objects, so must meet the varlena convention that
* the first int32 of the object contains the total object size in bytes.
+ * Be sure to use VARSIZE() and SET_VARSIZE() to access it, though!
*
* CAUTION: if you change the header for ordinary arrays you will also
* need to change the headers for oidvector and int2vector!
*/
typedef struct
{
- int32 size; /* total array size (varlena requirement) */
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int ndim; /* # of dimensions */
int32 dataoffset; /* offset to data, or 0 if no bitmap */
Oid elemtype; /* element type OID */
} ArrayType;
+/*
+ * working state for accumArrayResult() and friends
+ */
typedef struct ArrayBuildState
{
MemoryContext mcontext; /* where all the temp stuff is kept */
@@ -132,7 +136,7 @@ typedef struct ArrayMapState
*
* Unlike C, the default lower bound is 1.
*/
-#define ARR_SIZE(a) ((a)->size)
+#define ARR_SIZE(a) VARSIZE(a)
#define ARR_NDIM(a) ((a)->ndim)
#define ARR_HASNULL(a) ((a)->dataoffset != 0)
#define ARR_ELEMTYPE(a) ((a)->elemtype)
diff --git a/src/include/utils/geo_decls.h b/src/include/utils/geo_decls.h
index f641471ebf..da4275b683 100644
--- a/src/include/utils/geo_decls.h
+++ b/src/include/utils/geo_decls.h
@@ -78,7 +78,7 @@ typedef struct
*-------------------------------------------------------------------*/
typedef struct
{
- int32 size; /* XXX varlena */
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int32 npts;
int32 closed; /* is this a closed polygon? */
int32 dummy; /* padding to make it double align */
@@ -121,7 +121,7 @@ typedef struct
*-------------------------------------------------------------------*/
typedef struct
{
- int32 size; /* XXX varlena */
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int32 npts;
BOX boundbox;
Point p[1]; /* variable length array of POINTs */
diff --git a/src/include/utils/numeric.h b/src/include/utils/numeric.h
index 1408bf0d14..3e02c40b16 100644
--- a/src/include/utils/numeric.h
+++ b/src/include/utils/numeric.h
@@ -62,7 +62,7 @@
*/
typedef struct NumericData
{
- int32 varlen; /* Variable size (std varlena header) */
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int16 n_weight; /* Weight of 1st digit */
uint16 n_sign_dscale; /* Sign + display scale */
char n_data[1]; /* Digits (really array of NumericDigit) */
@@ -70,7 +70,7 @@ typedef struct NumericData
typedef NumericData *Numeric;
-#define NUMERIC_HDRSZ (sizeof(int32) + sizeof(int16) + sizeof(uint16))
+#define NUMERIC_HDRSZ (VARHDRSZ + sizeof(int16) + sizeof(uint16))
/*
diff --git a/src/include/utils/pg_lzcompress.h b/src/include/utils/pg_lzcompress.h
index e712e9d959..11c1ea163e 100644
--- a/src/include/utils/pg_lzcompress.h
+++ b/src/include/utils/pg_lzcompress.h
@@ -15,13 +15,11 @@
* PGLZ_Header -
*
* The information at the top of the compressed data.
- * The varsize must be kept the same data type as the value
- * in front of all variable size data types in PostgreSQL.
* ----------
*/
typedef struct PGLZ_Header
{
- int32 varsize;
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int32 rawsize;
} PGLZ_Header;
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h
index ad830f25e1..f65acf48f1 100644
--- a/src/include/utils/rel.h
+++ b/src/include/utils/rel.h
@@ -222,7 +222,7 @@ typedef Relation *RelationPtr;
*/
typedef struct StdRdOptions
{
- int32 vl_len; /* required to be a bytea */
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int fillfactor; /* page fill factor in percent (0..100) */
} StdRdOptions;
diff --git a/src/include/utils/varbit.h b/src/include/utils/varbit.h
index 16438b04d7..95710dc154 100644
--- a/src/include/utils/varbit.h
+++ b/src/include/utils/varbit.h
@@ -22,8 +22,7 @@
*/
typedef struct
{
- int32 vl_len; /* standard varlena header (total size in
- * bytes) */
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int32 bit_len; /* number of valid bits */
bits8 bit_dat[1]; /* bit string, most sig. byte first */
} VarBit;