summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2007-02-27 23:48:10 +0000
committerTom Lane2007-02-27 23:48:10 +0000
commit3d53833d64743d79383abfd8bee061ad2f5ec2fb (patch)
treeede671f752e430aa89c4ac0e663260b8190abd1b
parent9f5fadc09d4bb13b616e981486009874ae0f4e03 (diff)
Replace direct assignments to VARATT_SIZEP(x) with SET_VARSIZE(x, len).
Get rid of VARATT_SIZE and VARATT_DATA, which were simply redundant with VARSIZE and VARDATA, and as a consequence almost no code was using the longer names. Rename the length fields of struct varlena and various derived structures to catch anyplace that was accessing them directly; and clean up various places so caught. In itself this patch doesn't change any behavior at all, but it is necessary infrastructure if we hope to play any games with the representation of varlena headers. Greg Stark and Tom Lane
-rw-r--r--contrib/btree_gist/btree_bit.c2
-rw-r--r--contrib/btree_gist/btree_utils_var.c35
-rw-r--r--contrib/chkpass/chkpass.c24
-rw-r--r--contrib/cube/cube.c64
-rw-r--r--contrib/cube/cubedata.h3
-rw-r--r--contrib/cube/cubeparse.y10
-rw-r--r--contrib/fuzzystrmatch/dmetaphone.c10
-rw-r--r--contrib/hstore/hstore_op.c14
-rw-r--r--contrib/intagg/int_aggregate.c8
-rw-r--r--contrib/intarray/_int_bool.c4
-rw-r--r--contrib/intarray/_int_tool.c4
-rw-r--r--contrib/ltree/ltree_op.c2
-rw-r--r--contrib/pg_trgm/trgm_op.c2
-rw-r--r--contrib/pgcrypto/pgcrypto.c20
-rw-r--r--contrib/pgcrypto/pgp-pgsql.c12
-rw-r--r--contrib/sslinfo/sslinfo.c9
-rw-r--r--contrib/tsearch2/common.c2
-rw-r--r--contrib/tsearch2/ginidx.c4
-rw-r--r--contrib/tsearch2/query.c6
-rw-r--r--contrib/tsearch2/rank.c4
-rw-r--r--contrib/tsearch2/ts_cfg.c2
-rw-r--r--contrib/tsearch2/ts_stat.c12
-rw-r--r--contrib/tsearch2/ts_stat.h4
-rw-r--r--contrib/tsearch2/tsvector.c20
-rw-r--r--contrib/tsearch2/tsvector.h6
-rw-r--r--contrib/tsearch2/tsvector_op.c16
-rw-r--r--contrib/xml2/xpath.c4
-rw-r--r--contrib/xml2/xslt_proc.c2
-rw-r--r--doc/src/sgml/xfunc.sgml8
-rw-r--r--src/backend/access/common/heaptuple.c4
-rw-r--r--src/backend/access/common/indextuple.c2
-rw-r--r--src/backend/access/common/reloptions.c14
-rw-r--r--src/backend/access/heap/tuptoaster.c71
-rw-r--r--src/backend/catalog/pg_conversion.c2
-rw-r--r--src/backend/executor/execQual.c4
-rw-r--r--src/backend/libpq/be-fsstubs.c2
-rw-r--r--src/backend/libpq/pqformat.c2
-rw-r--r--src/backend/storage/large_object/inv_api.c6
-rw-r--r--src/backend/utils/adt/acl.c7
-rw-r--r--src/backend/utils/adt/array_userfuncs.c2
-rw-r--r--src/backend/utils/adt/arrayfuncs.c18
-rw-r--r--src/backend/utils/adt/cash.c2
-rw-r--r--src/backend/utils/adt/char.c4
-rw-r--r--src/backend/utils/adt/date.c12
-rw-r--r--src/backend/utils/adt/datum.c2
-rw-r--r--src/backend/utils/adt/dbsize.c2
-rw-r--r--src/backend/utils/adt/encode.c4
-rw-r--r--src/backend/utils/adt/float.c4
-rw-r--r--src/backend/utils/adt/formatting.c8
-rw-r--r--src/backend/utils/adt/genfile.c4
-rw-r--r--src/backend/utils/adt/geo_ops.c18
-rw-r--r--src/backend/utils/adt/int.c8
-rw-r--r--src/backend/utils/adt/int8.c2
-rw-r--r--src/backend/utils/adt/like.c2
-rw-r--r--src/backend/utils/adt/like_match.c2
-rw-r--r--src/backend/utils/adt/mac.c4
-rw-r--r--src/backend/utils/adt/nabstime.c4
-rw-r--r--src/backend/utils/adt/network.c48
-rw-r--r--src/backend/utils/adt/numeric.c34
-rw-r--r--src/backend/utils/adt/oid.c6
-rw-r--r--src/backend/utils/adt/oracle_compat.c24
-rw-r--r--src/backend/utils/adt/pg_lzcompress.c8
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c2
-rw-r--r--src/backend/utils/adt/quote.c4
-rw-r--r--src/backend/utils/adt/regexp.c2
-rw-r--r--src/backend/utils/adt/ruleutils.c2
-rw-r--r--src/backend/utils/adt/selfuncs.c2
-rw-r--r--src/backend/utils/adt/timestamp.c12
-rw-r--r--src/backend/utils/adt/varbit.c34
-rw-r--r--src/backend/utils/adt/varchar.c12
-rw-r--r--src/backend/utils/adt/varlena.c18
-rw-r--r--src/backend/utils/adt/version.c2
-rw-r--r--src/backend/utils/adt/xml.c12
-rw-r--r--src/backend/utils/cache/relcache.c4
-rw-r--r--src/backend/utils/mb/mbutils.c2
-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
-rw-r--r--src/tutorial/funcs.c4
-rw-r--r--src/tutorial/funcs_new.c4
87 files changed, 414 insertions, 429 deletions
diff --git a/contrib/btree_gist/btree_bit.c b/contrib/btree_gist/btree_bit.c
index d8e401acfc..534c9af813 100644
--- a/contrib/btree_gist/btree_bit.c
+++ b/contrib/btree_gist/btree_bit.c
@@ -70,7 +70,7 @@ gbt_bit_xfrm(bytea *leaf)
int s = INTALIGN(VARBITBYTES(leaf) + VARHDRSZ);
out = palloc(s);
- VARATT_SIZEP(out) = s;
+ SET_VARSIZE(out, s);
memcpy((void *) VARDATA(out), (void *) VARBITS(leaf), VARBITBYTES(leaf));
return out;
}
diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c
index ae44e75491..1ad5c0d99b 100644
--- a/contrib/btree_gist/btree_utils_var.c
+++ b/contrib/btree_gist/btree_utils_var.c
@@ -51,42 +51,34 @@ gbt_var_key_readable(const GBT_VARKEY * k)
GBT_VARKEY *
gbt_var_key_copy(const GBT_VARKEY_R * u, bool force_node)
{
-
GBT_VARKEY *r = NULL;
if (u->lower == u->upper && !force_node)
{ /* leaf key mode */
-
r = (GBT_VARKEY *) palloc(VARSIZE(u->lower) + VARHDRSZ);
- memcpy((void *) VARDATA(r), (void *) u->lower, VARSIZE(u->lower));
- r->vl_len = VARSIZE(u->lower) + VARHDRSZ;
-
+ memcpy(VARDATA(r), u->lower, VARSIZE(u->lower));
+ SET_VARSIZE(r, VARSIZE(u->lower) + VARHDRSZ);
}
else
{ /* node key mode */
-
r = (GBT_VARKEY *) palloc(INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ);
- memcpy((void *) VARDATA(r), (void *) u->lower, VARSIZE(u->lower));
- memcpy((void *) &(((char *) r)[VARHDRSZ + INTALIGN(VARSIZE(u->lower))]), (void *) u->upper, VARSIZE(u->upper));
- r->vl_len = INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ;
-
+ memcpy(VARDATA(r), u->lower, VARSIZE(u->lower));
+ memcpy(VARDATA(r) + INTALIGN(VARSIZE(u->lower)), u->upper, VARSIZE(u->upper));
+ SET_VARSIZE(r, INTALIGN(VARSIZE(u->lower)) + VARSIZE(u->upper) + VARHDRSZ);
}
return r;
-
}
static GBT_VARKEY *
gbt_var_leaf2node(GBT_VARKEY * leaf, const gbtree_vinfo * tinfo)
{
-
GBT_VARKEY *out = leaf;
if (tinfo->f_l2n)
out = (*tinfo->f_l2n) (leaf);
return out;
-
}
@@ -212,19 +204,22 @@ gbt_var_node_truncate(const GBT_VARKEY * node, int32 cpf_length, const gbtree_vi
GBT_VARKEY_R r = gbt_var_key_readable(node);
int32 len1 = VARSIZE(r.lower) - VARHDRSZ;
int32 len2 = VARSIZE(r.upper) - VARHDRSZ;
- int32 si = 0;
+ int32 si;
+ char *out2;
len1 = Min(len1, (cpf_length + 1));
len2 = Min(len2, (cpf_length + 1));
- si = 2 * VARHDRSZ + INTALIGN(VARHDRSZ + len1) + len2;
+ si = 2 * VARHDRSZ + INTALIGN(len1 + VARHDRSZ) + len2;
out = (GBT_VARKEY *) palloc(si);
- out->vl_len = si;
- memcpy((void *) &(((char *) out)[VARHDRSZ]), (void *) r.lower, len1 + VARHDRSZ);
- memcpy((void *) &(((char *) out)[VARHDRSZ + INTALIGN(VARHDRSZ + len1)]), (void *) r.upper, len2 + VARHDRSZ);
+ SET_VARSIZE(out, si);
+
+ memcpy(VARDATA(out), r.lower, len1 + VARHDRSZ);
+ SET_VARSIZE(VARDATA(out), len1 + VARHDRSZ);
- *((int32 *) &(((char *) out)[VARHDRSZ])) = len1 + VARHDRSZ;
- *((int32 *) &(((char *) out)[VARHDRSZ + INTALIGN(VARHDRSZ + len1)])) = len2 + VARHDRSZ;
+ out2 = VARDATA(out) + INTALIGN(len1 + VARHDRSZ);
+ memcpy(out2, r.upper, len2 + VARHDRSZ);
+ SET_VARSIZE(out2, len2 + VARHDRSZ);
return out;
}
diff --git a/contrib/chkpass/chkpass.c b/contrib/chkpass/chkpass.c
index 2103ca1c03..d9e65f2103 100644
--- a/contrib/chkpass/chkpass.c
+++ b/contrib/chkpass/chkpass.c
@@ -125,10 +125,12 @@ chkpass_rout(PG_FUNCTION_ARGS)
{
chkpass *password = (chkpass *) PG_GETARG_POINTER(0);
text *result;
+ int slen;
- result = (text *) palloc(VARHDRSZ + 16);
- result->vl_len = VARHDRSZ + strlen(password->password);
- memcpy(result->vl_dat, password->password, strlen(password->password));
+ slen = strlen(password->password);
+ result = (text *) palloc(VARHDRSZ + slen);
+ SET_VARSIZE(result, VARHDRSZ + slen);
+ memcpy(VARDATA(result), password->password, slen);
PG_RETURN_TEXT_P(result);
}
@@ -145,11 +147,11 @@ chkpass_eq(PG_FUNCTION_ARGS)
chkpass *a1 = (chkpass *) PG_GETARG_POINTER(0);
text *a2 = (text *) PG_GETARG_TEXT_P(1);
char str[10];
- int sz = 8;
+ int sz;
- if (a2->vl_len < 12)
- sz = a2->vl_len - 4;
- strlcpy(str, a2->vl_dat, sz + 1);
+ sz = Min(VARSIZE(a2) - VARHDRSZ, 8);
+ memcpy(str, VARDATA(a2), sz);
+ str[sz] = '\0';
PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) == 0);
}
@@ -160,10 +162,10 @@ chkpass_ne(PG_FUNCTION_ARGS)
chkpass *a1 = (chkpass *) PG_GETARG_POINTER(0);
text *a2 = (text *) PG_GETARG_TEXT_P(1);
char str[10];
- int sz = 8;
+ int sz;
- if (a2->vl_len < 12)
- sz = a2->vl_len - 4;
- strlcpy(str, a2->vl_dat, sz + 1);
+ sz = Min(VARSIZE(a2) - VARHDRSZ, 8);
+ memcpy(str, VARDATA(a2), sz);
+ str[sz] = '\0';
PG_RETURN_BOOL(strcmp(a1->password, crypt(str, a1->password)) != 0);
}
diff --git a/contrib/cube/cube.c b/contrib/cube/cube.c
index 7cc1b2c2a2..6cc9e94135 100644
--- a/contrib/cube/cube.c
+++ b/contrib/cube/cube.c
@@ -223,9 +223,8 @@ cube_a_f8_f8(PG_FUNCTION_ARGS)
dll = ARRPTR(ll);
size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
- result = (NDBOX *) palloc(size);
- memset(result, 0, size);
- result->size = size;
+ result = (NDBOX *) palloc0(size);
+ SET_VARSIZE(result, size);
result->dim = dim;
for (i = 0; i < dim; i++)
@@ -264,9 +263,8 @@ cube_a_f8(PG_FUNCTION_ARGS)
dur = ARRPTR(ur);
size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
- result = (NDBOX *) palloc(size);
- memset(result, 0, size);
- result->size = size;
+ result = (NDBOX *) palloc0(size);
+ SET_VARSIZE(result, size);
result->dim = dim;
for (i = 0; i < dim; i++)
@@ -303,9 +301,8 @@ cube_subset(PG_FUNCTION_ARGS)
dim = ARRNELEMS(idx);
size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
- result = (NDBOX *) palloc(size);
- memset(result, 0, size);
- result->size = size;
+ result = (NDBOX *) palloc0(size);
+ SET_VARSIZE(result, size);
result->dim = dim;
for (i = 0; i < dim; i++)
@@ -432,7 +429,7 @@ g_cube_union(PG_FUNCTION_ARGS)
/*
* sizep = sizeof(NDBOX); -- NDBOX has variable size
*/
- *sizep = tmp->size;
+ *sizep = VARSIZE(tmp);
for (i = 1; i < entryvec->n; i++)
{
@@ -744,7 +741,7 @@ g_cube_binary_union(NDBOX * r1, NDBOX * r2, int *sizep)
NDBOX *retval;
retval = cube_union_v0(r1, r2);
- *sizep = retval->size;
+ *sizep = VARSIZE(retval);
return (retval);
}
@@ -759,16 +756,14 @@ cube_union_v0(NDBOX * a, NDBOX * b)
if (a->dim >= b->dim)
{
- result = palloc(a->size);
- memset(result, 0, a->size);
- result->size = a->size;
+ result = palloc0(VARSIZE(a));
+ SET_VARSIZE(result, VARSIZE(a));
result->dim = a->dim;
}
else
{
- result = palloc(b->size);
- memset(result, 0, b->size);
- result->size = b->size;
+ result = palloc0(VARSIZE(b));
+ SET_VARSIZE(result, VARSIZE(b));
result->dim = b->dim;
}
@@ -834,16 +829,14 @@ cube_inter(PG_FUNCTION_ARGS)
if (a->dim >= b->dim)
{
- result = palloc(a->size);
- memset(result, 0, a->size);
- result->size = a->size;
+ result = palloc0(VARSIZE(a));
+ SET_VARSIZE(result, VARSIZE(a));
result->dim = a->dim;
}
else
{
- result = palloc(b->size);
- memset(result, 0, b->size);
- result->size = b->size;
+ result = palloc0(VARSIZE(b));
+ SET_VARSIZE(result, VARSIZE(b));
result->dim = b->dim;
}
@@ -1371,9 +1364,8 @@ cube_enlarge(PG_FUNCTION_ARGS)
if (a->dim > dim)
dim = a->dim;
size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2;
- result = (NDBOX *) palloc(size);
- memset(result, 0, size);
- result->size = size;
+ result = (NDBOX *) palloc0(size);
+ SET_VARSIZE(result, size);
result->dim = dim;
for (i = 0, j = dim, k = a->dim; i < a->dim; i++, j++, k++)
{
@@ -1411,9 +1403,8 @@ cube_f8(PG_FUNCTION_ARGS)
int size;
size = offsetof(NDBOX, x[0]) + sizeof(double) * 2;
- result = (NDBOX *) palloc(size);
- memset(result, 0, size);
- result->size = size;
+ result = (NDBOX *) palloc0(size);
+ SET_VARSIZE(result, size);
result->dim = 1;
result->x[0] = PG_GETARG_FLOAT8(0);
result->x[1] = result->x[0];
@@ -1429,9 +1420,8 @@ cube_f8_f8(PG_FUNCTION_ARGS)
int size;
size = offsetof(NDBOX, x[0]) + sizeof(double) * 2;
- result = (NDBOX *) palloc(size);
- memset(result, 0, size);
- result->size = size;
+ result = (NDBOX *) palloc0(size);
+ SET_VARSIZE(result, size);
result->dim = 1;
result->x[0] = PG_GETARG_FLOAT8(0);
result->x[1] = PG_GETARG_FLOAT8(1);
@@ -1454,9 +1444,8 @@ cube_c_f8(PG_FUNCTION_ARGS)
x = PG_GETARG_FLOAT8(1);
size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) *2;
- result = (NDBOX *) palloc(size);
- memset(result, 0, size);
- result->size = size;
+ result = (NDBOX *) palloc0(size);
+ SET_VARSIZE(result, size);
result->dim = c->dim + 1;
for (i = 0; i < c->dim; i++)
{
@@ -1485,9 +1474,8 @@ cube_c_f8_f8(PG_FUNCTION_ARGS)
x2 = PG_GETARG_FLOAT8(2);
size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) *2;
- result = (NDBOX *) palloc(size);
- memset(result, 0, size);
- result->size = size;
+ result = (NDBOX *) palloc0(size);
+ SET_VARSIZE(result, size);
result->dim = c->dim + 1;
for (i = 0; i < c->dim; i++)
{
diff --git a/contrib/cube/cubedata.h b/contrib/cube/cubedata.h
index ed5203da17..8d31778990 100644
--- a/contrib/cube/cubedata.h
+++ b/contrib/cube/cubedata.h
@@ -1,9 +1,10 @@
/* $PostgreSQL$ */
#define CUBE_MAX_DIM (100)
+
typedef struct NDBOX
{
- unsigned int size; /* required to be a Postgres varlena type */
+ int32 vl_len_; /* varlena header (do not touch directly!) */
unsigned int dim;
double x[1];
} NDBOX;
diff --git a/contrib/cube/cubeparse.y b/contrib/cube/cubeparse.y
index 4f7ad841a6..26a97810fa 100644
--- a/contrib/cube/cubeparse.y
+++ b/contrib/cube/cubeparse.y
@@ -165,9 +165,8 @@ write_box(unsigned int dim, char *str1, char *str2)
int i;
int size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2;
- bp = palloc(size);
- memset(bp, 0, size);
- bp->size = size;
+ bp = palloc0(size);
+ SET_VARSIZE(bp, size);
bp->dim = dim;
s = str1;
@@ -198,9 +197,8 @@ write_point_as_box(char *str, int dim)
size = offsetof(NDBOX, x[0]) + sizeof(double) * dim * 2;
- bp = palloc(size);
- memset(bp, 0, size);
- bp->size = size;
+ bp = palloc0(size);
+ SET_VARSIZE(bp, size);
bp->dim = dim;
i = 0;
diff --git a/contrib/fuzzystrmatch/dmetaphone.c b/contrib/fuzzystrmatch/dmetaphone.c
index 4f4fa18f4f..53c2e26d0e 100644
--- a/contrib/fuzzystrmatch/dmetaphone.c
+++ b/contrib/fuzzystrmatch/dmetaphone.c
@@ -165,10 +165,9 @@ dmetaphone(PG_FUNCTION_ARGS)
code = "";
rsize = VARHDRSZ + strlen(code);
result = (text *) palloc(rsize);
- memset(result, 0, rsize);
rptr = VARDATA(result);
- memcpy(rptr, code, strlen(code));
- VARATT_SIZEP(result) = rsize;
+ memcpy(rptr, code, rsize - VARHDRSZ);
+ SET_VARSIZE(result, rsize);
PG_RETURN_TEXT_P(result);
}
@@ -206,10 +205,9 @@ dmetaphone_alt(PG_FUNCTION_ARGS)
code = "";
rsize = VARHDRSZ + strlen(code);
result = (text *) palloc(rsize);
- memset(result, 0, rsize);
rptr = VARDATA(result);
- memcpy(rptr, code, strlen(code));
- VARATT_SIZEP(result) = rsize;
+ memcpy(rptr, code, rsize - VARHDRSZ);
+ SET_VARSIZE(result, rsize);
PG_RETURN_TEXT_P(result);
}
diff --git a/contrib/hstore/hstore_op.c b/contrib/hstore/hstore_op.c
index 915436c3d1..f16a58988e 100644
--- a/contrib/hstore/hstore_op.c
+++ b/contrib/hstore/hstore_op.c
@@ -54,7 +54,7 @@ fetchval(PG_FUNCTION_ARGS)
out = palloc(VARHDRSZ + entry->vallen);
memcpy(VARDATA(out), STRPTR(hs) + entry->pos + entry->keylen, entry->vallen);
- VARATT_SIZEP(out) = VARHDRSZ + entry->vallen;
+ SET_VARSIZE(out, VARHDRSZ + entry->vallen);
PG_FREE_IF_COPY(hs, 0);
PG_FREE_IF_COPY(key, 1);
@@ -310,7 +310,7 @@ akeys(PG_FUNCTION_ARGS)
{
text *item = (text *) palloc(VARHDRSZ + ptr->keylen);
- VARATT_SIZEP(item) = VARHDRSZ + ptr->keylen;
+ SET_VARSIZE(item, VARHDRSZ + ptr->keylen);
memcpy(VARDATA(item), base + ptr->pos, ptr->keylen);
d[ptr - ARRPTR(hs)] = PointerGetDatum(item);
ptr++;
@@ -355,7 +355,7 @@ avals(PG_FUNCTION_ARGS)
int vallen = (ptr->valisnull) ? 0 : ptr->vallen;
text *item = (text *) palloc(VARHDRSZ + vallen);
- VARATT_SIZEP(item) = VARHDRSZ + vallen;
+ SET_VARSIZE(item, VARHDRSZ + vallen);
memcpy(VARDATA(item), base + ptr->pos + ptr->keylen, vallen);
d[ptr - ARRPTR(hs)] = PointerGetDatum(item);
ptr++;
@@ -431,7 +431,7 @@ skeys(PG_FUNCTION_ARGS)
HEntry *ptr = &(ARRPTR(st->hs)[st->i]);
text *item = (text *) palloc(VARHDRSZ + ptr->keylen);
- VARATT_SIZEP(item) = VARHDRSZ + ptr->keylen;
+ SET_VARSIZE(item, VARHDRSZ + ptr->keylen);
memcpy(VARDATA(item), STRPTR(st->hs) + ptr->pos, ptr->keylen);
st->i++;
@@ -483,7 +483,7 @@ svals(PG_FUNCTION_ARGS)
int vallen = ptr->vallen;
text *item = (text *) palloc(VARHDRSZ + vallen);
- VARATT_SIZEP(item) = VARHDRSZ + vallen;
+ SET_VARSIZE(item, VARHDRSZ + vallen);
memcpy(VARDATA(item), STRPTR(st->hs) + ptr->pos + ptr->keylen, vallen);
st->i++;
@@ -593,7 +593,7 @@ each(PG_FUNCTION_ARGS)
HeapTuple tuple;
item = (text *) palloc(VARHDRSZ + ptr->keylen);
- VARATT_SIZEP(item) = VARHDRSZ + ptr->keylen;
+ SET_VARSIZE(item, VARHDRSZ + ptr->keylen);
memcpy(VARDATA(item), STRPTR(st->hs) + ptr->pos, ptr->keylen);
dvalues[0] = PointerGetDatum(item);
@@ -607,7 +607,7 @@ each(PG_FUNCTION_ARGS)
int vallen = ptr->vallen;
item = (text *) palloc(VARHDRSZ + vallen);
- VARATT_SIZEP(item) = VARHDRSZ + vallen;
+ SET_VARSIZE(item, VARHDRSZ + vallen);
memcpy(VARDATA(item), STRPTR(st->hs) + ptr->pos + ptr->keylen, vallen);
dvalues[1] = PointerGetDatum(item);
}
diff --git a/contrib/intagg/int_aggregate.c b/contrib/intagg/int_aggregate.c
index af9135d9de..b32f674599 100644
--- a/contrib/intagg/int_aggregate.c
+++ b/contrib/intagg/int_aggregate.c
@@ -88,7 +88,7 @@ GetPGArray(PGARRAY * p, AggState *aggstate, bool fAdd)
int cb = PGARRAY_SIZE(START_NUM);
p = (PGARRAY *) MemoryContextAlloc(aggstate->aggcontext, cb);
- p->a.size = cb;
+ SET_VARSIZE(p, cb);
p->a.ndim = 1;
p->a.dataoffset = 0; /* we don't support nulls, for now */
p->a.elemtype = INT4OID;
@@ -105,8 +105,8 @@ GetPGArray(PGARRAY * p, AggState *aggstate, bool fAdd)
int cbNew = PGARRAY_SIZE(n);
pn = (PGARRAY *) MemoryContextAlloc(aggstate->aggcontext, cbNew);
- memcpy(pn, p, p->a.size);
- pn->a.size = cbNew;
+ memcpy(pn, p, VARSIZE(p));
+ SET_VARSIZE(pn, cbNew);
pn->lower = n;
/* do not pfree(p), because nodeAgg.c will */
p = pn;
@@ -132,7 +132,7 @@ ShrinkPGArray(PGARRAY * p)
memcpy(pnew, p, cb);
/* fix up the fields in the new array to match normal conventions */
- pnew->a.size = cb;
+ SET_VARSIZE(pnew, cb);
pnew->lower = 1;
/* do not pfree(p), because nodeAgg.c will */
diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c
index 23ee8f1dad..b6a5d1b1e8 100644
--- a/contrib/intarray/_int_bool.c
+++ b/contrib/intarray/_int_bool.c
@@ -766,7 +766,7 @@ querytree(PG_FUNCTION_ARGS)
if (len == 0)
{
res = (text *) palloc(1 + VARHDRSZ);
- VARATT_SIZEP(res) = 1 + VARHDRSZ;
+ SET_VARSIZE(res, 1 + VARHDRSZ);
*((char *) VARDATA(res)) = 'T';
}
else
@@ -778,7 +778,7 @@ querytree(PG_FUNCTION_ARGS)
infix(&nrm, true);
res = (text *) palloc(nrm.cur - nrm.buf + VARHDRSZ);
- VARATT_SIZEP(res) = nrm.cur - nrm.buf + VARHDRSZ;
+ SET_VARSIZE(res, nrm.cur - nrm.buf + VARHDRSZ);
memcpy(VARDATA(res), nrm.buf, nrm.cur - nrm.buf);
}
pfree(q);
diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c
index 2ad0ef0cc0..fead4ff30d 100644
--- a/contrib/intarray/_int_tool.c
+++ b/contrib/intarray/_int_tool.c
@@ -226,7 +226,7 @@ new_intArrayType(int num)
r = (ArrayType *) palloc0(nbytes);
- ARR_SIZE(r) = nbytes;
+ SET_VARSIZE(r, nbytes);
ARR_NDIM(r) = NDIM;
r->dataoffset = 0; /* marker for no null bitmap */
ARR_ELEMTYPE(r) = INT4OID;
@@ -246,7 +246,7 @@ resize_intArrayType(ArrayType *a, int num)
a = (ArrayType *) repalloc(a, nbytes);
- a->size = nbytes;
+ SET_VARSIZE(a, nbytes);
*((int *) ARR_DIMS(a)) = num;
return a;
}
diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c
index a4ad847458..bcaab27e00 100644
--- a/contrib/ltree/ltree_op.c
+++ b/contrib/ltree/ltree_op.c
@@ -557,7 +557,7 @@ ltree2text(PG_FUNCTION_ARGS)
curlevel = LEVEL_NEXT(curlevel);
}
- VARATT_SIZEP(out) = VARHDRSZ + (ptr - VARDATA(out));
+ SET_VARSIZE(out, ptr - ((char *) out));
PG_FREE_IF_COPY(in, 0);
PG_RETURN_POINTER(out);
diff --git a/contrib/pg_trgm/trgm_op.c b/contrib/pg_trgm/trgm_op.c
index f31b9bf572..e247756a39 100644
--- a/contrib/pg_trgm/trgm_op.c
+++ b/contrib/pg_trgm/trgm_op.c
@@ -203,7 +203,7 @@ show_trgm(PG_FUNCTION_ARGS)
{
text *item = (text *) palloc(VARHDRSZ + 3);
- VARATT_SIZEP(item) = VARHDRSZ + 3;
+ SET_VARSIZE(item, VARHDRSZ + 3);
CPTRGM(VARDATA(item), ptr);
d[ptr - GETARR(trg)] = PointerGetDatum(item);
ptr++;
diff --git a/contrib/pgcrypto/pgcrypto.c b/contrib/pgcrypto/pgcrypto.c
index 96dc3af81a..70e04bcada 100644
--- a/contrib/pgcrypto/pgcrypto.c
+++ b/contrib/pgcrypto/pgcrypto.c
@@ -68,7 +68,7 @@ pg_digest(PG_FUNCTION_ARGS)
hlen = px_md_result_size(md);
res = (text *) palloc(hlen + VARHDRSZ);
- VARATT_SIZEP(res) = hlen + VARHDRSZ;
+ SET_VARSIZE(res, hlen + VARHDRSZ);
arg = PG_GETARG_BYTEA_P(0);
len = VARSIZE(arg) - VARHDRSZ;
@@ -106,7 +106,7 @@ pg_hmac(PG_FUNCTION_ARGS)
hlen = px_hmac_result_size(h);
res = (text *) palloc(hlen + VARHDRSZ);
- VARATT_SIZEP(res) = hlen + VARHDRSZ;
+ SET_VARSIZE(res, hlen + VARHDRSZ);
arg = PG_GETARG_BYTEA_P(0);
key = PG_GETARG_BYTEA_P(1);
@@ -150,7 +150,7 @@ pg_gen_salt(PG_FUNCTION_ARGS)
errmsg("gen_salt: %s", px_strerror(len))));
res = (text *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(res) = len + VARHDRSZ;
+ SET_VARSIZE(res, len + VARHDRSZ);
memcpy(VARDATA(res), buf, len);
PG_FREE_IF_COPY(arg0, 0);
@@ -184,7 +184,7 @@ pg_gen_salt_rounds(PG_FUNCTION_ARGS)
errmsg("gen_salt: %s", px_strerror(len))));
res = (text *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(res) = len + VARHDRSZ;
+ SET_VARSIZE(res, len + VARHDRSZ);
memcpy(VARDATA(res), buf, len);
PG_FREE_IF_COPY(arg0, 0);
@@ -238,7 +238,7 @@ pg_crypt(PG_FUNCTION_ARGS)
clen = strlen(cres);
res = (text *) palloc(clen + VARHDRSZ);
- VARATT_SIZEP(res) = clen + VARHDRSZ;
+ SET_VARSIZE(res, clen + VARHDRSZ);
memcpy(VARDATA(res), cres, clen);
pfree(resbuf);
@@ -293,7 +293,7 @@ pg_encrypt(PG_FUNCTION_ARGS)
errmsg("encrypt error: %s", px_strerror(err))));
}
- VARATT_SIZEP(res) = VARHDRSZ + rlen;
+ SET_VARSIZE(res, VARHDRSZ + rlen);
PG_RETURN_BYTEA_P(res);
}
@@ -336,7 +336,7 @@ pg_decrypt(PG_FUNCTION_ARGS)
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("decrypt error: %s", px_strerror(err))));
- VARATT_SIZEP(res) = VARHDRSZ + rlen;
+ SET_VARSIZE(res, VARHDRSZ + rlen);
PG_FREE_IF_COPY(data, 0);
PG_FREE_IF_COPY(key, 1);
@@ -389,7 +389,7 @@ pg_encrypt_iv(PG_FUNCTION_ARGS)
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("encrypt_iv error: %s", px_strerror(err))));
- VARATT_SIZEP(res) = VARHDRSZ + rlen;
+ SET_VARSIZE(res, VARHDRSZ + rlen);
PG_FREE_IF_COPY(data, 0);
PG_FREE_IF_COPY(key, 1);
@@ -443,7 +443,7 @@ pg_decrypt_iv(PG_FUNCTION_ARGS)
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("decrypt_iv error: %s", px_strerror(err))));
- VARATT_SIZEP(res) = VARHDRSZ + rlen;
+ SET_VARSIZE(res, VARHDRSZ + rlen);
PG_FREE_IF_COPY(data, 0);
PG_FREE_IF_COPY(key, 1);
@@ -469,7 +469,7 @@ pg_random_bytes(PG_FUNCTION_ARGS)
errmsg("Length not in range")));
res = palloc(VARHDRSZ + len);
- VARATT_SIZEP(res) = VARHDRSZ + len;
+ SET_VARSIZE(res, VARHDRSZ + len);
/* generate result */
err = px_get_random_bytes((uint8 *) VARDATA(res), len);
diff --git a/contrib/pgcrypto/pgp-pgsql.c b/contrib/pgcrypto/pgp-pgsql.c
index 8a0b0727ab..acfd151e55 100644
--- a/contrib/pgcrypto/pgp-pgsql.c
+++ b/contrib/pgcrypto/pgp-pgsql.c
@@ -152,7 +152,7 @@ convert_charset(text *src, int cset_from, int cset_to)
dst_len = strlen((char *) dst);
res = palloc(dst_len + VARHDRSZ);
memcpy(VARDATA(res), dst, dst_len);
- VARATT_SIZEP(res) = VARHDRSZ + dst_len;
+ SET_VARSIZE(res, dst_len + VARHDRSZ);
pfree(dst);
return res;
}
@@ -514,7 +514,7 @@ encrypt_internal(int is_pubenc, int is_text,
/* res_len includes VARHDRSZ */
res_len = mbuf_steal_data(dst, &restmp);
res = (bytea *) restmp;
- VARATT_SIZEP(res) = res_len;
+ SET_VARSIZE(res, res_len);
if (tmp_data)
clear_and_pfree(tmp_data);
@@ -615,7 +615,7 @@ out:
/* res_len includes VARHDRSZ */
res = (bytea *) restmp;
- VARATT_SIZEP(res) = res_len;
+ SET_VARSIZE(res, res_len);
if (need_text && got_unicode)
{
@@ -858,7 +858,7 @@ pg_armor(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("Overflow - encode estimate too small")));
- VARATT_SIZEP(res) = VARHDRSZ + res_len;
+ SET_VARSIZE(res, VARHDRSZ + res_len);
PG_FREE_IF_COPY(data, 0);
PG_RETURN_TEXT_P(res);
@@ -889,7 +889,7 @@ pg_dearmor(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("Overflow - decode estimate too small")));
- VARATT_SIZEP(res) = VARHDRSZ + res_len;
+ SET_VARSIZE(res, VARHDRSZ + res_len);
PG_FREE_IF_COPY(data, 0);
PG_RETURN_TEXT_P(res);
@@ -917,7 +917,7 @@ pgp_key_id_w(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
errmsg("%s", px_strerror(res_len))));
- VARATT_SIZEP(res) = VARHDRSZ + res_len;
+ SET_VARSIZE(res, VARHDRSZ + res_len);
PG_FREE_IF_COPY(data, 0);
PG_RETURN_TEXT_P(res);
diff --git a/contrib/sslinfo/sslinfo.c b/contrib/sslinfo/sslinfo.c
index 4bd8f2838b..e103b02305 100644
--- a/contrib/sslinfo/sslinfo.c
+++ b/contrib/sslinfo/sslinfo.c
@@ -136,11 +136,12 @@ ASN1_STRING_to_text(ASN1_STRING *str)
outlen = strlen(dp);
result = palloc(VARHDRSZ + outlen);
memcpy(VARDATA(result), dp, outlen);
+ SET_VARSIZE(result, VARHDRSZ + outlen);
+
if (dp != sp)
pfree(dp);
-
BIO_free(membuf);
- VARATT_SIZEP(result) = outlen + VARHDRSZ;
+
PG_RETURN_TEXT_P(result);
}
@@ -312,9 +313,11 @@ X509_NAME_to_text(X509_NAME *name)
PG_UTF8,
GetDatabaseEncoding());
BIO_free(membuf);
+
outlen = strlen(dp);
result = palloc(VARHDRSZ + outlen);
memcpy(VARDATA(result), dp, outlen);
+ SET_VARSIZE(result, VARHDRSZ + outlen);
/*
* pg_do_encoding_conversion has annoying habit of returning source
@@ -322,7 +325,7 @@ X509_NAME_to_text(X509_NAME *name)
*/
if (dp != sp)
pfree(dp);
- VARATT_SIZEP(result) = outlen + VARHDRSZ;
+
PG_RETURN_TEXT_P(result);
}
diff --git a/contrib/tsearch2/common.c b/contrib/tsearch2/common.c
index 3ff3fad1bf..983399a438 100644
--- a/contrib/tsearch2/common.c
+++ b/contrib/tsearch2/common.c
@@ -36,7 +36,7 @@ charl2text(char *in, int len)
text *out = (text *) palloc(len + VARHDRSZ);
memcpy(VARDATA(out), in, len);
- VARATT_SIZEP(out) = len + VARHDRSZ;
+ SET_VARSIZE(out, len + VARHDRSZ);
return out;
}
diff --git a/contrib/tsearch2/ginidx.c b/contrib/tsearch2/ginidx.c
index 01766923c1..d77ee9bb9f 100644
--- a/contrib/tsearch2/ginidx.c
+++ b/contrib/tsearch2/ginidx.c
@@ -37,7 +37,7 @@ gin_extract_tsvector(PG_FUNCTION_ARGS)
{
text *txt = (text *) palloc(VARHDRSZ + we->len);
- VARATT_SIZEP(txt) = VARHDRSZ + we->len;
+ SET_VARSIZE(txt, VARHDRSZ + we->len);
memcpy(VARDATA(txt), STRPTR(vector) + we->pos, we->len);
entries[i] = PointerGetDatum(txt);
@@ -89,7 +89,7 @@ gin_extract_tsquery(PG_FUNCTION_ARGS)
txt = (text *) palloc(VARHDRSZ + item[i].length);
- VARATT_SIZEP(txt) = VARHDRSZ + item[i].length;
+ SET_VARSIZE(txt, VARHDRSZ + item[i].length);
memcpy(VARDATA(txt), GETOPERAND(query) + item[i].distance, item[i].length);
entries[j++] = PointerGetDatum(txt);
diff --git a/contrib/tsearch2/query.c b/contrib/tsearch2/query.c
index ea8790df25..eb2d30e159 100644
--- a/contrib/tsearch2/query.c
+++ b/contrib/tsearch2/query.c
@@ -907,7 +907,7 @@ tsquerytree(PG_FUNCTION_ARGS)
if (query->size == 0)
{
res = (text *) palloc(VARHDRSZ);
- VARATT_SIZEP(res) = VARHDRSZ;
+ SET_VARSIZE(res, VARHDRSZ);
PG_RETURN_POINTER(res);
}
@@ -916,7 +916,7 @@ tsquerytree(PG_FUNCTION_ARGS)
if (!q)
{
res = (text *) palloc(1 + VARHDRSZ);
- VARATT_SIZEP(res) = 1 + VARHDRSZ;
+ SET_VARSIZE(res, 1 + VARHDRSZ);
*((char *) VARDATA(res)) = 'T';
}
else
@@ -929,7 +929,7 @@ tsquerytree(PG_FUNCTION_ARGS)
infix(&nrm, true);
res = (text *) palloc(nrm.cur - nrm.buf + VARHDRSZ);
- VARATT_SIZEP(res) = nrm.cur - nrm.buf + VARHDRSZ;
+ SET_VARSIZE(res, nrm.cur - nrm.buf + VARHDRSZ);
memcpy(VARDATA(res), nrm.buf, nrm.cur - nrm.buf);
pfree(q);
}
diff --git a/contrib/tsearch2/rank.c b/contrib/tsearch2/rank.c
index 36fc259400..b6960c3bf3 100644
--- a/contrib/tsearch2/rank.c
+++ b/contrib/tsearch2/rank.c
@@ -839,7 +839,7 @@ get_covers(PG_FUNCTION_ARGS)
if (!doc)
{
out = palloc(VARHDRSZ);
- VARATT_SIZEP(out) = VARHDRSZ;
+ SET_VARSIZE(out, VARHDRSZ);
PG_FREE_IF_COPY(txt, 0);
PG_FREE_IF_COPY(query, 1);
PG_RETURN_POINTER(out);
@@ -910,7 +910,7 @@ get_covers(PG_FUNCTION_ARGS)
dwptr++;
}
- VARATT_SIZEP(out) = cptr - ((char *) out);
+ SET_VARSIZE(out, cptr - ((char *) out));
pfree(dw);
for (i = 0; i < rlen; i++)
diff --git a/contrib/tsearch2/ts_cfg.c b/contrib/tsearch2/ts_cfg.c
index 0526ce9879..d62d49a249 100644
--- a/contrib/tsearch2/ts_cfg.c
+++ b/contrib/tsearch2/ts_cfg.c
@@ -555,7 +555,7 @@ genhl(HLPRSTEXT * prs)
wrd++;
}
- VARATT_SIZEP(out) = ptr - ((char *) out);
+ SET_VARSIZE(out, ptr - ((char *) out));
return out;
}
diff --git a/contrib/tsearch2/ts_stat.c b/contrib/tsearch2/ts_stat.c
index 17d1ccb050..d728dd5796 100644
--- a/contrib/tsearch2/ts_stat.c
+++ b/contrib/tsearch2/ts_stat.c
@@ -17,7 +17,7 @@ tsstat_in(PG_FUNCTION_ARGS)
{
tsstat *stat = palloc(STATHDRSIZE);
- stat->len = STATHDRSIZE;
+ SET_VARSIZE(stat, STATHDRSIZE);
stat->size = 0;
stat->weight = 0;
PG_RETURN_POINTER(stat);
@@ -100,7 +100,7 @@ formstat(tsstat * stat, tsvector * txt, WordEntry ** entry, uint32 len)
slen += STATSTRSIZE(stat);
totallen = CALCSTATSIZE(nentry, slen);
newstat = palloc(totallen);
- newstat->len = totallen;
+ SET_VARSIZE(newstat, totallen);
newstat->weight = stat->weight;
newstat->size = nentry;
@@ -200,7 +200,7 @@ ts_accum(PG_FUNCTION_ARGS)
if (stat == NULL || PG_ARGISNULL(0))
{ /* Init in first */
stat = palloc(STATHDRSIZE);
- stat->len = STATHDRSIZE;
+ SET_VARSIZE(stat, STATHDRSIZE);
stat->size = 0;
stat->weight = 0;
}
@@ -341,8 +341,8 @@ ts_setup_firstcall(FunctionCallInfo fcinfo, FuncCallContext *funcctx,
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
st = palloc(sizeof(StatStorage));
st->cur = 0;
- st->stat = palloc(stat->len);
- memcpy(st->stat, stat, stat->len);
+ st->stat = palloc(VARSIZE(stat));
+ memcpy(st->stat, stat, VARSIZE(stat));
funcctx->user_fctx = (void *) st;
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
@@ -466,7 +466,7 @@ ts_stat_sql(text *txt, text *ws)
elog(ERROR, "column isn't of tsvector type");
stat = palloc(STATHDRSIZE);
- stat->len = STATHDRSIZE;
+ SET_VARSIZE(stat, STATHDRSIZE);
stat->size = 0;
stat->weight = 0;
diff --git a/contrib/tsearch2/ts_stat.h b/contrib/tsearch2/ts_stat.h
index 358b68c808..e1ba14b99b 100644
--- a/contrib/tsearch2/ts_stat.h
+++ b/contrib/tsearch2/ts_stat.h
@@ -19,7 +19,7 @@ typedef struct
typedef struct
{
- int4 len;
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int4 size;
int4 weight;
char data[1];
@@ -29,6 +29,6 @@ typedef struct
#define CALCSTATSIZE(x, lenstr) ( (x) * sizeof(StatEntry) + STATHDRSIZE + (lenstr) )
#define STATPTR(x) ( (StatEntry*) ( (char*)(x) + STATHDRSIZE ) )
#define STATSTRPTR(x) ( (char*)(x) + STATHDRSIZE + ( sizeof(StatEntry) * ((tsvector*)(x))->size ) )
-#define STATSTRSIZE(x) ( ((tsvector*)(x))->len - STATHDRSIZE - ( sizeof(StatEntry) * ((tsvector*)(x))->size ) )
+#define STATSTRSIZE(x) ( VARSIZE((tsvector*)(x)) - STATHDRSIZE - ( sizeof(StatEntry) * ((tsvector*)(x))->size ) )
#endif
diff --git a/contrib/tsearch2/tsvector.c b/contrib/tsearch2/tsvector.c
index f4e83ec149..dfbdacd345 100644
--- a/contrib/tsearch2/tsvector.c
+++ b/contrib/tsearch2/tsvector.c
@@ -476,9 +476,8 @@ tsvector_in(PG_FUNCTION_ARGS)
else
buflen = 0;
totallen = CALCDATASIZE(len, buflen);
- in = (tsvector *) palloc(totallen);
- memset(in, 0, totallen);
- in->len = totallen;
+ in = (tsvector *) palloc0(totallen);
+ SET_VARSIZE(in, totallen);
in->size = len;
cur = STRPTR(in);
inarr = ARRPTR(in);
@@ -699,9 +698,8 @@ makevalue(PRSTEXT * prs)
}
totallen = CALCDATASIZE(prs->curwords, lenstr);
- in = (tsvector *) palloc(totallen);
- memset(in, 0, totallen);
- in->len = totallen;
+ in = (tsvector *) palloc0(totallen);
+ SET_VARSIZE(in, totallen);
in->size = prs->curwords;
ptr = ARRPTR(in);
@@ -746,7 +744,7 @@ to_tsvector(PG_FUNCTION_ARGS)
{
text *in = PG_GETARG_TEXT_P(1);
PRSTEXT prs;
- tsvector *out = NULL;
+ tsvector *out;
TSCfgInfo *cfg;
SET_FUNCOID();
@@ -766,7 +764,7 @@ to_tsvector(PG_FUNCTION_ARGS)
{
pfree(prs.words);
out = palloc(CALCDATASIZE(0, 0));
- out->len = CALCDATASIZE(0, 0);
+ SET_VARSIZE(out, CALCDATASIZE(0, 0));
out->size = 0;
}
PG_RETURN_POINTER(out);
@@ -957,7 +955,7 @@ tsearch2(PG_FUNCTION_ARGS)
{
tsvector *out = palloc(CALCDATASIZE(0, 0));
- out->len = CALCDATASIZE(0, 0);
+ SET_VARSIZE(out, CALCDATASIZE(0, 0));
out->size = 0;
datum = PointerGetDatum(out);
pfree(prs.words);
@@ -975,9 +973,9 @@ tsearch2(PG_FUNCTION_ARGS)
static int
silly_cmp_tsvector(const tsvector * a, const tsvector * b)
{
- if (a->len < b->len)
+ if (VARSIZE(a) < VARSIZE(b))
return -1;
- else if (a->len > b->len)
+ else if (VARSIZE(a) > VARSIZE(b))
return 1;
else if (a->size < b->size)
return -1;
diff --git a/contrib/tsearch2/tsvector.h b/contrib/tsearch2/tsvector.h
index 48bae42de0..e006a1dcbd 100644
--- a/contrib/tsearch2/tsvector.h
+++ b/contrib/tsearch2/tsvector.h
@@ -49,7 +49,7 @@ typedef uint16 WordEntryPos;
/*
* Structure of tsvector datatype:
- * 1) int4 len - varlena's length
+ * 1) standard varlena header
* 2) int4 size - number of lexemes or WordEntry array, which is the same
* 3) Array of WordEntry - sorted array, comparison based on word's length
* and strncmp(). WordEntry->pos points number of
@@ -63,12 +63,12 @@ typedef uint16 WordEntryPos;
typedef struct
{
- int4 len;
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int4 size;
char data[1];
} tsvector;
-#define DATAHDRSIZE (sizeof(int4) * 2)
+#define DATAHDRSIZE (VARHDRSZ + sizeof(int4))
#define CALCDATASIZE(x, lenstr) ( (x) * sizeof(WordEntry) + DATAHDRSIZE + (lenstr) )
#define ARRPTR(x) ( (WordEntry*) ( (char*)(x) + DATAHDRSIZE ) )
#define STRPTR(x) ( (char*)(x) + DATAHDRSIZE + ( sizeof(WordEntry) * ((tsvector*)(x))->size ) )
diff --git a/contrib/tsearch2/tsvector_op.c b/contrib/tsearch2/tsvector_op.c
index 7d4113edff..e8d8e16db4 100644
--- a/contrib/tsearch2/tsvector_op.c
+++ b/contrib/tsearch2/tsvector_op.c
@@ -44,9 +44,8 @@ strip(PG_FUNCTION_ARGS)
len += SHORTALIGN(arrin[i].len);
len = CALCDATASIZE(in->size, len);
- out = (tsvector *) palloc(len);
- memset(out, 0, len);
- out->len = len;
+ out = (tsvector *) palloc0(len);
+ SET_VARSIZE(out, len);
out->size = in->size;
arrout = ARRPTR(out);
cur = STRPTR(out);
@@ -98,8 +97,8 @@ setweight(PG_FUNCTION_ARGS)
elog(ERROR, "unrecognized weight");
}
- out = (tsvector *) palloc(in->len);
- memcpy(out, in, in->len);
+ out = (tsvector *) palloc(VARSIZE(in));
+ memcpy(out, in, VARSIZE(in));
entry = ARRPTR(out);
i = out->size;
while (i--)
@@ -203,9 +202,8 @@ concat(PG_FUNCTION_ARGS)
data2 = STRPTR(in2);
i1 = in1->size;
i2 = in2->size;
- out = (tsvector *) palloc(in1->len + in2->len);
- memset(out, 0, in1->len + in2->len);
- out->len = in1->len + in2->len;
+ out = (tsvector *) palloc0(VARSIZE(in1) + VARSIZE(in2));
+ SET_VARSIZE(out, VARSIZE(in1) + VARSIZE(in2));
out->size = in1->size + in2->size;
data = cur = STRPTR(out);
ptr = ARRPTR(out);
@@ -322,7 +320,7 @@ concat(PG_FUNCTION_ARGS)
}
out->size = ptr - ARRPTR(out);
- out->len = CALCDATASIZE(out->size, cur - data);
+ SET_VARSIZE(out, CALCDATASIZE(out->size, cur - data));
if (data != STRPTR(out))
memmove(STRPTR(out), data, cur - data);
diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c
index 11349eff0b..c5c9bd2f78 100644
--- a/contrib/xml2/xpath.c
+++ b/contrib/xml2/xpath.c
@@ -212,7 +212,7 @@ xml_encode_special_chars(PG_FUNCTION_ARGS)
ressize = strlen(tt);
tout = (text *) palloc(ressize + VARHDRSZ);
memcpy(VARDATA(tout), tt, ressize);
- VARATT_SIZEP(tout) = ressize + VARHDRSZ;
+ SET_VARSIZE(tout, ressize + VARHDRSZ);
xmlFree(tt);
@@ -612,7 +612,7 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
ressize = strlen(xpresstr);
xpres = (text *) palloc(ressize + VARHDRSZ);
memcpy(VARDATA(xpres), xpresstr, ressize);
- VARATT_SIZEP(xpres) = ressize + VARHDRSZ;
+ SET_VARSIZE(xpres, ressize + VARHDRSZ);
/* Free various storage */
xmlCleanupParser();
diff --git a/contrib/xml2/xslt_proc.c b/contrib/xml2/xslt_proc.c
index 433030ead9..3e6de5a97d 100644
--- a/contrib/xml2/xslt_proc.c
+++ b/contrib/xml2/xslt_proc.c
@@ -129,7 +129,7 @@ xslt_process(PG_FUNCTION_ARGS)
tres = palloc(reslen + VARHDRSZ);
memcpy(VARDATA(tres), resstr, reslen);
- VARATT_SIZEP(tres) = reslen + VARHDRSZ;
+ SET_VARSIZE(tres, reslen + VARHDRSZ);
PG_RETURN_TEXT_P(tres);
}
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index dac5668eb4..bc289650dc 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -1645,7 +1645,7 @@ copytext(text *t)
* VARSIZE is the total size of the struct in bytes.
*/
text *new_t = (text *) palloc(VARSIZE(t));
- VARATT_SIZEP(new_t) = VARSIZE(t);
+ SET_VARSIZE(new_t, VARSIZE(t));
/*
* VARDATA is a pointer to the data region of the struct.
*/
@@ -1661,7 +1661,7 @@ concat_text(text *arg1, text *arg2)
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
- VARATT_SIZEP(new_text) = new_text_size;
+ SET_VARSIZE(new_text, new_text_size);
memcpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1) - VARHDRSZ);
memcpy(VARDATA(new_text) + (VARSIZE(arg1) - VARHDRSZ),
VARDATA(arg2), VARSIZE(arg2) - VARHDRSZ);
@@ -1831,7 +1831,7 @@ copytext(PG_FUNCTION_ARGS)
* VARSIZE is the total size of the struct in bytes.
*/
text *new_t = (text *) palloc(VARSIZE(t));
- VARATT_SIZEP(new_t) = VARSIZE(t);
+ SET_VARSIZE(new_t, VARSIZE(t));
/*
* VARDATA is a pointer to the data region of the struct.
*/
@@ -1851,7 +1851,7 @@ concat_text(PG_FUNCTION_ARGS)
int32 new_text_size = VARSIZE(arg1) + VARSIZE(arg2) - VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
- VARATT_SIZEP(new_text) = new_text_size;
+ SET_VARSIZE(new_text, new_text_size);
memcpy(VARDATA(new_text), VARDATA(arg1), VARSIZE(arg1) - VARHDRSZ);
memcpy(VARDATA(new_text) + (VARSIZE(arg1) - VARHDRSZ),
VARDATA(arg2), VARSIZE(arg2) - VARHDRSZ);
diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index 439e4723af..84f447ef87 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -162,7 +162,7 @@ heap_fill_tuple(TupleDesc tupleDesc,
*infomask |= HEAP_HASEXTERNAL;
if (VARATT_IS_COMPRESSED(values[i]))
*infomask |= HEAP_HASCOMPRESSED;
- data_length = VARATT_SIZE(DatumGetPointer(values[i]));
+ data_length = VARSIZE(DatumGetPointer(values[i]));
memcpy(data, DatumGetPointer(values[i]), data_length);
}
else if (att[i]->attlen == -2)
@@ -261,7 +261,7 @@ DataFill(char *data,
*infomask |= HEAP_HASEXTERNAL;
if (VARATT_IS_COMPRESSED(values[i]))
*infomask |= HEAP_HASCOMPRESSED;
- data_length = VARATT_SIZE(DatumGetPointer(values[i]));
+ data_length = VARSIZE(DatumGetPointer(values[i]));
memcpy(data, DatumGetPointer(values[i]), data_length);
}
else if (att[i]->attlen == -2)
diff --git a/src/backend/access/common/indextuple.c b/src/backend/access/common/indextuple.c
index 85c4661806..bbe3e944e3 100644
--- a/src/backend/access/common/indextuple.c
+++ b/src/backend/access/common/indextuple.c
@@ -84,7 +84,7 @@ index_form_tuple(TupleDesc tupleDescriptor,
* If value is above size target, and is of a compressible datatype,
* try to compress it in-line.
*/
- if (VARATT_SIZE(untoasted_values[i]) > TOAST_INDEX_TARGET &&
+ if (VARSIZE(untoasted_values[i]) > TOAST_INDEX_TARGET &&
!VARATT_IS_EXTENDED(untoasted_values[i]) &&
(att->attstorage == 'x' || att->attstorage == 'm'))
{
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c
index 50ac998855..0b0cdc86f6 100644
--- a/src/backend/access/common/reloptions.c
+++ b/src/backend/access/common/reloptions.c
@@ -72,8 +72,8 @@ transformRelOptions(Datum oldOptions, List *defList,
for (i = 0; i < noldoptions; i++)
{
text *oldoption = DatumGetTextP(oldoptions[i]);
- char *text_str = (char *) VARATT_DATA(oldoption);
- int text_len = VARATT_SIZE(oldoption) - VARHDRSZ;
+ char *text_str = VARDATA(oldoption);
+ int text_len = VARSIZE(oldoption) - VARHDRSZ;
/* Search for a match in defList */
foreach(cell, defList)
@@ -131,8 +131,8 @@ transformRelOptions(Datum oldOptions, List *defList,
len = VARHDRSZ + strlen(def->defname) + 1 + strlen(value);
/* +1 leaves room for sprintf's trailing null */
t = (text *) palloc(len + 1);
- VARATT_SIZEP(t) = len;
- sprintf((char *) VARATT_DATA(t), "%s=%s", def->defname, value);
+ SET_VARSIZE(t, len);
+ sprintf(VARDATA(t), "%s=%s", def->defname, value);
astate = accumArrayResult(astate, PointerGetDatum(t),
false, TEXTOID,
@@ -188,8 +188,8 @@ parseRelOptions(Datum options, int numkeywords, const char *const * keywords,
for (i = 0; i < noptions; i++)
{
text *optiontext = DatumGetTextP(optiondatums[i]);
- char *text_str = (char *) VARATT_DATA(optiontext);
- int text_len = VARATT_SIZE(optiontext) - VARHDRSZ;
+ char *text_str = VARDATA(optiontext);
+ int text_len = VARSIZE(optiontext) - VARHDRSZ;
int j;
/* Search for a match in keywords */
@@ -267,7 +267,7 @@ default_reloptions(Datum reloptions, bool validate,
}
result = (StdRdOptions *) palloc(sizeof(StdRdOptions));
- VARATT_SIZEP(result) = sizeof(StdRdOptions);
+ SET_VARSIZE(result, sizeof(StdRdOptions));
result->fillfactor = fillfactor;
diff --git a/src/backend/access/heap/tuptoaster.c b/src/backend/access/heap/tuptoaster.c
index 1c37ca7b13..2b794f7d50 100644
--- a/src/backend/access/heap/tuptoaster.c
+++ b/src/backend/access/heap/tuptoaster.c
@@ -104,8 +104,8 @@ heap_tuple_untoast_attr(varattrib *attr)
tmp = (PGLZ_Header *) toast_fetch_datum(attr);
result = (varattrib *) palloc(PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
- VARATT_SIZEP(result) = PGLZ_RAW_SIZE(tmp) + VARHDRSZ;
- pglz_decompress(tmp, VARATT_DATA(result));
+ SET_VARSIZE(result, PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
+ pglz_decompress(tmp, VARDATA(result));
pfree(tmp);
}
else
@@ -124,8 +124,8 @@ heap_tuple_untoast_attr(varattrib *attr)
PGLZ_Header *tmp = (PGLZ_Header *) attr;
result = (varattrib *) palloc(PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
- VARATT_SIZEP(result) = PGLZ_RAW_SIZE(tmp) + VARHDRSZ;
- pglz_decompress(tmp, VARATT_DATA(result));
+ SET_VARSIZE(result, PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
+ pglz_decompress(tmp, VARDATA(result));
}
else
@@ -162,8 +162,8 @@ heap_tuple_untoast_attr_slice(varattrib *attr, int32 sliceoffset, int32 slicelen
tmp = (PGLZ_Header *) attr; /* compressed in main tuple */
preslice = (varattrib *) palloc(PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
- VARATT_SIZEP(preslice) = PGLZ_RAW_SIZE(tmp) + VARHDRSZ;
- pglz_decompress(tmp, VARATT_DATA(preslice));
+ SET_VARSIZE(preslice, PGLZ_RAW_SIZE(tmp) + VARHDRSZ);
+ pglz_decompress(tmp, VARDATA(preslice));
if (tmp != (PGLZ_Header *) attr)
pfree(tmp);
@@ -193,7 +193,7 @@ heap_tuple_untoast_attr_slice(varattrib *attr, int32 sliceoffset, int32 slicelen
slicelength = attrsize - sliceoffset;
result = (varattrib *) palloc(slicelength + VARHDRSZ);
- VARATT_SIZEP(result) = slicelength + VARHDRSZ;
+ SET_VARSIZE(result, slicelength + VARHDRSZ);
memcpy(VARDATA(result), VARDATA(preslice) + sliceoffset, slicelength);
@@ -435,7 +435,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
* tuple.
*/
toast_action[i] = 'p';
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
continue;
}
}
@@ -486,7 +486,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
/*
* Remember the size of this attribute
*/
- toast_sizes[i] = VARATT_SIZE(new_value);
+ toast_sizes[i] = VARSIZE(new_value);
}
else
{
@@ -564,7 +564,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
pfree(DatumGetPointer(old_value));
toast_values[i] = new_value;
toast_free[i] = true;
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
}
@@ -623,7 +623,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
pfree(DatumGetPointer(old_value));
toast_free[i] = true;
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
@@ -676,7 +676,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
pfree(DatumGetPointer(old_value));
toast_values[i] = new_value;
toast_free[i] = true;
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
}
@@ -734,7 +734,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup, bool us
pfree(DatumGetPointer(old_value));
toast_free[i] = true;
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
need_change = true;
need_free = true;
@@ -949,15 +949,15 @@ Datum
toast_compress_datum(Datum value)
{
varattrib *tmp;
- int32 valsize = VARATT_SIZE(value) - VARHDRSZ;
+ int32 valsize = VARSIZE(value) - VARHDRSZ;
tmp = (varattrib *) palloc(PGLZ_MAX_OUTPUT(valsize));
- if (pglz_compress(VARATT_DATA(value), valsize,
+ if (pglz_compress(VARDATA(value), valsize,
(PGLZ_Header *) tmp, PGLZ_strategy_default) &&
- VARATT_SIZE(tmp) < VARATT_SIZE(value))
+ VARSIZE(tmp) < VARSIZE(value))
{
/* successful compression */
- VARATT_SIZEP(tmp) |= VARATT_FLAG_COMPRESSED;
+ VARATT_SIZEP_DEPRECATED(tmp) |= VARATT_FLAG_COMPRESSED;
return PointerGetDatum(tmp);
}
else
@@ -1010,18 +1010,19 @@ toast_save_datum(Relation rel, Datum value, bool use_wal)
*/
result = (varattrib *) palloc(sizeof(varattrib));
- result->va_header = sizeof(varattrib) | VARATT_FLAG_EXTERNAL;
+ SET_VARSIZE(result, sizeof(varattrib));
+ VARATT_SIZEP_DEPRECATED(result) |= VARATT_FLAG_EXTERNAL;
if (VARATT_IS_COMPRESSED(value))
{
- result->va_header |= VARATT_FLAG_COMPRESSED;
+ VARATT_SIZEP_DEPRECATED(result) |= VARATT_FLAG_COMPRESSED;
result->va_content.va_external.va_rawsize =
((varattrib *) value)->va_content.va_compressed.va_rawsize;
}
else
- result->va_content.va_external.va_rawsize = VARATT_SIZE(value);
+ result->va_content.va_external.va_rawsize = VARSIZE(value);
result->va_content.va_external.va_extsize =
- VARATT_SIZE(value) - VARHDRSZ;
+ VARSIZE(value) - VARHDRSZ;
result->va_content.va_external.va_valueid =
GetNewOidWithIndex(toastrel, toastidx);
result->va_content.va_external.va_toastrelid =
@@ -1039,8 +1040,8 @@ toast_save_datum(Relation rel, Datum value, bool use_wal)
/*
* Get the data to process
*/
- data_p = VARATT_DATA(value);
- data_todo = VARATT_SIZE(value) - VARHDRSZ;
+ data_p = VARDATA(value);
+ data_todo = VARSIZE(value) - VARHDRSZ;
/*
* Split up the item into chunks
@@ -1056,8 +1057,8 @@ toast_save_datum(Relation rel, Datum value, bool use_wal)
* Build a tuple and store it
*/
t_values[1] = Int32GetDatum(chunk_seq++);
- VARATT_SIZEP(&chunk_data) = chunk_size + VARHDRSZ;
- memcpy(VARATT_DATA(&chunk_data), data_p, chunk_size);
+ SET_VARSIZE(&chunk_data, chunk_size + VARHDRSZ);
+ memcpy(VARDATA(&chunk_data), data_p, chunk_size);
toasttup = heap_form_tuple(toasttupDesc, t_values, t_isnull);
if (!HeapTupleIsValid(toasttup))
elog(ERROR, "failed to build TOAST tuple");
@@ -1184,9 +1185,9 @@ toast_fetch_datum(varattrib *attr)
numchunks = ((ressize - 1) / TOAST_MAX_CHUNK_SIZE) + 1;
result = (varattrib *) palloc(ressize + VARHDRSZ);
- VARATT_SIZEP(result) = ressize + VARHDRSZ;
+ SET_VARSIZE(result, ressize + VARHDRSZ);
if (VARATT_IS_COMPRESSED(attr))
- VARATT_SIZEP(result) |= VARATT_FLAG_COMPRESSED;
+ VARATT_SIZEP_DEPRECATED(result) |= VARATT_FLAG_COMPRESSED;
/*
* Open the toast relation and its index
@@ -1224,7 +1225,7 @@ toast_fetch_datum(varattrib *attr)
Assert(!isnull);
chunk = DatumGetPointer(fastgetattr(ttup, 3, toasttupDesc, &isnull));
Assert(!isnull);
- chunksize = VARATT_SIZE(chunk) - VARHDRSZ;
+ chunksize = VARSIZE(chunk) - VARHDRSZ;
/*
* Some checks on the data we've found
@@ -1255,8 +1256,8 @@ toast_fetch_datum(varattrib *attr)
/*
* Copy the data into proper place in our result
*/
- memcpy(((char *) VARATT_DATA(result)) + residx * TOAST_MAX_CHUNK_SIZE,
- VARATT_DATA(chunk),
+ memcpy(VARDATA(result) + residx * TOAST_MAX_CHUNK_SIZE,
+ VARDATA(chunk),
chunksize);
nextidx++;
@@ -1326,10 +1327,10 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length)
length = attrsize - sliceoffset;
result = (varattrib *) palloc(length + VARHDRSZ);
- VARATT_SIZEP(result) = length + VARHDRSZ;
+ SET_VARSIZE(result, length + VARHDRSZ);
if (VARATT_IS_COMPRESSED(attr))
- VARATT_SIZEP(result) |= VARATT_FLAG_COMPRESSED;
+ VARATT_SIZEP_DEPRECATED(result) |= VARATT_FLAG_COMPRESSED;
if (length == 0)
return result; /* Can save a lot of work at this point! */
@@ -1399,7 +1400,7 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length)
Assert(!isnull);
chunk = DatumGetPointer(fastgetattr(ttup, 3, toasttupDesc, &isnull));
Assert(!isnull);
- chunksize = VARATT_SIZE(chunk) - VARHDRSZ;
+ chunksize = VARSIZE(chunk) - VARHDRSZ;
/*
* Some checks on the data we've found
@@ -1433,9 +1434,9 @@ toast_fetch_datum_slice(varattrib *attr, int32 sliceoffset, int32 length)
if (residx == endchunk)
chcpyend = endoffset;
- memcpy(((char *) VARATT_DATA(result)) +
+ memcpy(VARDATA(result) +
(residx * TOAST_MAX_CHUNK_SIZE - sliceoffset) + chcpystrt,
- VARATT_DATA(chunk) + chcpystrt,
+ VARDATA(chunk) + chcpystrt,
(chcpyend - chcpystrt) + 1);
nextidx++;
diff --git a/src/backend/catalog/pg_conversion.c b/src/backend/catalog/pg_conversion.c
index 99dd651838..33eb209186 100644
--- a/src/backend/catalog/pg_conversion.c
+++ b/src/backend/catalog/pg_conversion.c
@@ -338,7 +338,7 @@ pg_convert_using(PG_FUNCTION_ARGS)
*/
len = strlen(result) + VARHDRSZ;
retval = palloc(len);
- VARATT_SIZEP(retval) = len;
+ SET_VARSIZE(retval, len);
memcpy(VARDATA(retval), result, len - VARHDRSZ);
pfree(result);
diff --git a/src/backend/executor/execQual.c b/src/backend/executor/execQual.c
index 8d64a0f701..db6f363f9d 100644
--- a/src/backend/executor/execQual.c
+++ b/src/backend/executor/execQual.c
@@ -2533,7 +2533,7 @@ ExecEvalArray(ArrayExprState *astate, ExprContext *econtext,
}
result = (ArrayType *) palloc(nbytes);
- result->size = nbytes;
+ SET_VARSIZE(result, nbytes);
result->ndim = ndims;
result->dataoffset = dataoffset;
result->elemtype = element_type;
@@ -2967,7 +2967,7 @@ ExecEvalXml(XmlExprState *xmlExpr, ExprContext *econtext,
int len = buf.len + VARHDRSZ;
result = palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), buf.data, buf.len);
}
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index ec11767bcb..d9b94bf609 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -304,7 +304,7 @@ loread(PG_FUNCTION_ARGS)
retval = (bytea *) palloc(VARHDRSZ + len);
totalread = lo_read(fd, VARDATA(retval), len);
- VARATT_SIZEP(retval) = totalread + VARHDRSZ;
+ SET_VARSIZE(retval, totalread + VARHDRSZ);
PG_RETURN_BYTEA_P(retval);
}
diff --git a/src/backend/libpq/pqformat.c b/src/backend/libpq/pqformat.c
index ec164a6d65..a48f259230 100644
--- a/src/backend/libpq/pqformat.c
+++ b/src/backend/libpq/pqformat.c
@@ -386,7 +386,7 @@ pq_endtypsend(StringInfo buf)
/* Insert correct length into bytea length word */
Assert(buf->len >= VARHDRSZ);
- VARATT_SIZEP(result) = buf->len;
+ SET_VARSIZE(result, buf->len);
return result;
}
diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c
index 727829f70c..5ca906b26e 100644
--- a/src/backend/storage/large_object/inv_api.c
+++ b/src/backend/storage/large_object/inv_api.c
@@ -507,7 +507,7 @@ inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
bytea hdr;
char data[LOBLKSIZE];
} workbuf;
- char *workb = VARATT_DATA(&workbuf.hdr);
+ char *workb = VARDATA(&workbuf.hdr);
HeapTuple newtup;
Datum values[Natts_pg_largeobject];
char nulls[Natts_pg_largeobject];
@@ -607,7 +607,7 @@ inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
off += n;
/* compute valid length of new page */
len = (len >= off) ? len : off;
- VARATT_SIZEP(&workbuf.hdr) = len + VARHDRSZ;
+ SET_VARSIZE(&workbuf.hdr, len + VARHDRSZ);
/*
* Form and insert updated tuple
@@ -651,7 +651,7 @@ inv_write(LargeObjectDesc *obj_desc, const char *buf, int nbytes)
obj_desc->offset += n;
/* compute valid length of new page */
len = off + n;
- VARATT_SIZEP(&workbuf.hdr) = len + VARHDRSZ;
+ SET_VARSIZE(&workbuf.hdr, len + VARHDRSZ);
/*
* Form and insert updated tuple
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c
index c4abcd5173..1815740798 100644
--- a/src/backend/utils/adt/acl.c
+++ b/src/backend/utils/adt/acl.c
@@ -353,7 +353,7 @@ allocacl(int n)
elog(ERROR, "invalid size: %d", n);
size = ACL_N_SIZE(n);
new_acl = (Acl *) palloc0(size);
- new_acl->size = size;
+ SET_VARSIZE(new_acl, size);
new_acl->ndim = 1;
new_acl->dataoffset = 0; /* we never put in any nulls */
new_acl->elemtype = ACLITEMOID;
@@ -716,8 +716,9 @@ aclupdate(const Acl *old_acl, const AclItem *mod_aip,
memmove(new_aip + dst,
new_aip + dst + 1,
(num - dst - 1) * sizeof(AclItem));
+ /* Adjust array size to be 'num - 1' items */
ARR_DIMS(new_acl)[0] = num - 1;
- ARR_SIZE(new_acl) -= sizeof(AclItem);
+ SET_VARSIZE(new_acl, ACL_N_SIZE(num - 1));
}
/*
@@ -830,7 +831,7 @@ aclnewowner(const Acl *old_acl, Oid oldOwnerId, Oid newOwnerId)
}
/* Adjust array size to be 'dst' items */
ARR_DIMS(new_acl)[0] = dst;
- ARR_SIZE(new_acl) = ACL_N_SIZE(dst);
+ SET_VARSIZE(new_acl, ACL_N_SIZE(dst));
}
return new_acl;
diff --git a/src/backend/utils/adt/array_userfuncs.c b/src/backend/utils/adt/array_userfuncs.c
index 3b9ea6bdcf..1009419b3c 100644
--- a/src/backend/utils/adt/array_userfuncs.c
+++ b/src/backend/utils/adt/array_userfuncs.c
@@ -376,7 +376,7 @@ array_cat(PG_FUNCTION_ARGS)
nbytes = ndatabytes + ARR_OVERHEAD_NONULLS(ndims);
}
result = (ArrayType *) palloc(nbytes);
- result->size = nbytes;
+ SET_VARSIZE(result, nbytes);
result->ndim = ndims;
result->dataoffset = dataoffset;
result->elemtype = element_type;
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index ffae541d19..d991c5167b 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -324,7 +324,7 @@ array_in(PG_FUNCTION_ARGS)
nbytes += ARR_OVERHEAD_NONULLS(ndim);
}
retval = (ArrayType *) palloc(nbytes);
- retval->size = nbytes;
+ SET_VARSIZE(retval, nbytes);
retval->ndim = ndim;
retval->dataoffset = dataoffset;
retval->elemtype = element_type;
@@ -1279,7 +1279,7 @@ array_recv(PG_FUNCTION_ARGS)
nbytes += ARR_OVERHEAD_NONULLS(ndim);
}
retval = (ArrayType *) palloc(nbytes);
- retval->size = nbytes;
+ SET_VARSIZE(retval, nbytes);
retval->ndim = ndim;
retval->dataoffset = dataoffset;
retval->elemtype = element_type;
@@ -1573,7 +1573,7 @@ array_dims(PG_FUNCTION_ARGS)
sprintf(p, "[%d:%d]", lb[i], dimv[i] + lb[i] - 1);
p += strlen(p);
}
- VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ;
+ SET_VARSIZE(result, strlen(VARDATA(result)) + VARHDRSZ);
PG_RETURN_TEXT_P(result);
}
@@ -1879,7 +1879,7 @@ array_get_slice(ArrayType *array,
}
newarray = (ArrayType *) palloc(bytes);
- newarray->size = bytes;
+ SET_VARSIZE(newarray, bytes);
newarray->ndim = ndim;
newarray->dataoffset = dataoffset;
newarray->elemtype = elemtype;
@@ -2132,7 +2132,7 @@ array_set(ArrayType *array,
* OK, create the new array and fill in header/dimensions
*/
newarray = (ArrayType *) palloc(newsize);
- newarray->size = newsize;
+ SET_VARSIZE(newarray, newsize);
newarray->ndim = ndim;
newarray->dataoffset = newhasnulls ? overheadlen : 0;
newarray->elemtype = ARR_ELEMTYPE(array);
@@ -2458,7 +2458,7 @@ array_set_slice(ArrayType *array,
newsize = overheadlen + olddatasize - olditemsize + newitemsize;
newarray = (ArrayType *) palloc(newsize);
- newarray->size = newsize;
+ SET_VARSIZE(newarray, newsize);
newarray->ndim = ndim;
newarray->dataoffset = newhasnulls ? overheadlen : 0;
newarray->elemtype = ARR_ELEMTYPE(array);
@@ -2717,7 +2717,7 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType,
nbytes += ARR_OVERHEAD_NONULLS(ndim);
}
result = (ArrayType *) palloc(nbytes);
- result->size = nbytes;
+ SET_VARSIZE(result, nbytes);
result->ndim = ndim;
result->dataoffset = dataoffset;
result->elemtype = retType;
@@ -2853,7 +2853,7 @@ construct_md_array(Datum *elems,
nbytes += ARR_OVERHEAD_NONULLS(ndims);
}
result = (ArrayType *) palloc(nbytes);
- result->size = nbytes;
+ SET_VARSIZE(result, nbytes);
result->ndim = ndims;
result->dataoffset = dataoffset;
result->elemtype = elmtype;
@@ -2877,7 +2877,7 @@ construct_empty_array(Oid elmtype)
ArrayType *result;
result = (ArrayType *) palloc(sizeof(ArrayType));
- result->size = sizeof(ArrayType);
+ SET_VARSIZE(result, sizeof(ArrayType));
result->ndim = 0;
result->dataoffset = 0;
result->elemtype = elmtype;
diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c
index 241f8e3147..f7110e477c 100644
--- a/src/backend/utils/adt/cash.c
+++ b/src/backend/utils/adt/cash.c
@@ -860,7 +860,7 @@ cash_words(PG_FUNCTION_ARGS)
/* make a text type for output */
result = (text *) palloc(strlen(buf) + VARHDRSZ);
- VARATT_SIZEP(result) = strlen(buf) + VARHDRSZ;
+ SET_VARSIZE(result, strlen(buf) + VARHDRSZ);
memcpy(VARDATA(result), buf, strlen(buf));
PG_RETURN_TEXT_P(result);
diff --git a/src/backend/utils/adt/char.c b/src/backend/utils/adt/char.c
index cab91675a6..d761bd555f 100644
--- a/src/backend/utils/adt/char.c
+++ b/src/backend/utils/adt/char.c
@@ -203,11 +203,11 @@ char_text(PG_FUNCTION_ARGS)
*/
if (arg1 != '\0')
{
- VARATT_SIZEP(result) = VARHDRSZ + 1;
+ SET_VARSIZE(result, VARHDRSZ + 1);
*(VARDATA(result)) = arg1;
}
else
- VARATT_SIZEP(result) = VARHDRSZ;
+ SET_VARSIZE(result, VARHDRSZ);
PG_RETURN_TEXT_P(result);
}
diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c
index b4e7f02bac..d367306af2 100644
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -891,8 +891,8 @@ date_text(PG_FUNCTION_ARGS)
result = palloc(len);
- VARATT_SIZEP(result) = len;
- memmove(VARDATA(result), str, (len - VARHDRSZ));
+ SET_VARSIZE(result, len);
+ memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
@@ -1634,8 +1634,8 @@ time_text(PG_FUNCTION_ARGS)
result = palloc(len);
- VARATT_SIZEP(result) = len;
- memmove(VARDATA(result), str, (len - VARHDRSZ));
+ SET_VARSIZE(result, len);
+ memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
@@ -2420,8 +2420,8 @@ timetz_text(PG_FUNCTION_ARGS)
result = palloc(len);
- VARATT_SIZEP(result) = len;
- memmove(VARDATA(result), str, (len - VARHDRSZ));
+ SET_VARSIZE(result, len);
+ memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
diff --git a/src/backend/utils/adt/datum.c b/src/backend/utils/adt/datum.c
index 79d85808e6..be8cfa18c6 100644
--- a/src/backend/utils/adt/datum.c
+++ b/src/backend/utils/adt/datum.c
@@ -79,7 +79,7 @@ datumGetSize(Datum value, bool typByVal, int typLen)
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid Datum pointer")));
- size = (Size) VARATT_SIZE(s);
+ size = (Size) VARSIZE(s);
}
else if (typLen == -2)
{
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 5945be97e0..95a368b81b 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -396,7 +396,7 @@ pg_size_pretty(PG_FUNCTION_ARGS)
}
}
- VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ;
+ SET_VARSIZE(result, strlen(VARDATA(result)) + VARHDRSZ);
PG_RETURN_TEXT_P(result);
}
diff --git a/src/backend/utils/adt/encode.c b/src/backend/utils/adt/encode.c
index 6b82a96125..8db52cd16f 100644
--- a/src/backend/utils/adt/encode.c
+++ b/src/backend/utils/adt/encode.c
@@ -63,7 +63,7 @@ binary_encode(PG_FUNCTION_ARGS)
if (res > resultlen)
elog(FATAL, "overflow - encode estimate too small");
- VARATT_SIZEP(result) = VARHDRSZ + res;
+ SET_VARSIZE(result, VARHDRSZ + res);
PG_RETURN_TEXT_P(result);
}
@@ -99,7 +99,7 @@ binary_decode(PG_FUNCTION_ARGS)
if (res > resultlen)
elog(FATAL, "overflow - decode estimate too small");
- VARATT_SIZEP(result) = VARHDRSZ + res;
+ SET_VARSIZE(result, VARHDRSZ + res);
PG_RETURN_BYTEA_P(result);
}
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index fc69f838d1..d08e5d7c09 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -1214,7 +1214,7 @@ float8_text(PG_FUNCTION_ARGS)
result = (text *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
@@ -1265,7 +1265,7 @@ float4_text(PG_FUNCTION_ARGS)
result = (text *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index d7a49d51f0..f1ee9cc95e 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -2991,7 +2991,7 @@ datetime_to_char_body(TmToChar *tmtc, text *fmt, bool is_interval)
reslen = strlen(result);
res = (text *) palloc(reslen + VARHDRSZ);
memcpy(VARDATA(res), result, reslen);
- VARATT_SIZEP(res) = reslen + VARHDRSZ;
+ SET_VARSIZE(res, reslen + VARHDRSZ);
pfree(result);
return res;
@@ -4829,10 +4829,10 @@ do { \
} \
\
result_tmp = result; \
- result = (text *) palloc( len + 1 + VARHDRSZ); \
+ result = (text *) palloc(len + VARHDRSZ); \
\
- strcpy( VARDATA(result), VARDATA(result_tmp)); \
- VARATT_SIZEP(result) = len + VARHDRSZ; \
+ memcpy(VARDATA(result), VARDATA(result_tmp), len); \
+ SET_VARSIZE(result, len + VARHDRSZ); \
pfree(result_tmp); \
} while(0)
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index 84c5f31d35..eee8bbe7a0 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -135,7 +135,7 @@ pg_read_file(PG_FUNCTION_ARGS)
(errcode_for_file_access(),
errmsg("could not read file \"%s\": %m", filename)));
- VARATT_SIZEP(buf) = nbytes + VARHDRSZ;
+ SET_VARSIZE(buf, nbytes + VARHDRSZ);
FreeFile(file);
pfree(filename);
@@ -261,7 +261,7 @@ pg_ls_dir(PG_FUNCTION_ARGS)
continue;
result = palloc(len + VARHDRSZ);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, len + VARHDRSZ);
memcpy(VARDATA(result), de->d_name, len);
SRF_RETURN_NEXT(funcctx, PointerGetDatum(result));
diff --git a/src/backend/utils/adt/geo_ops.c b/src/backend/utils/adt/geo_ops.c
index 3dbd0d66af..92be67deea 100644
--- a/src/backend/utils/adt/geo_ops.c
+++ b/src/backend/utils/adt/geo_ops.c
@@ -1415,7 +1415,7 @@ path_in(PG_FUNCTION_ARGS)
size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * npts;
path = (PATH *) palloc(size);
- path->size = size;
+ SET_VARSIZE(path, size);
path->npts = npts;
if ((!path_decode(TRUE, npts, s, &isopen, &s, &(path->p[0])))
@@ -1464,7 +1464,7 @@ path_recv(PG_FUNCTION_ARGS)
size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * npts;
path = (PATH *) palloc(size);
- path->size = size;
+ SET_VARSIZE(path, size);
path->npts = npts;
path->closed = (closed ? 1 : 0);
@@ -3440,7 +3440,7 @@ poly_in(PG_FUNCTION_ARGS)
size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts;
poly = (POLYGON *) palloc0(size); /* zero any holes */
- poly->size = size;
+ SET_VARSIZE(poly, size);
poly->npts = npts;
if ((!path_decode(FALSE, npts, str, &isopen, &s, &(poly->p[0])))
@@ -3492,7 +3492,7 @@ poly_recv(PG_FUNCTION_ARGS)
size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * npts;
poly = (POLYGON *) palloc0(size); /* zero any holes */
- poly->size = size;
+ SET_VARSIZE(poly, size);
poly->npts = npts;
for (i = 0; i < npts; i++)
@@ -4079,7 +4079,7 @@ path_add(PG_FUNCTION_ARGS)
result = (PATH *) palloc(size);
- result->size = size;
+ SET_VARSIZE(result, size);
result->npts = (p1->npts + p2->npts);
result->closed = p1->closed;
@@ -4207,7 +4207,7 @@ path_poly(PG_FUNCTION_ARGS)
size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * path->npts;
poly = (POLYGON *) palloc(size);
- poly->size = size;
+ SET_VARSIZE(poly, size);
poly->npts = path->npts;
for (i = 0; i < path->npts; i++)
@@ -4282,7 +4282,7 @@ box_poly(PG_FUNCTION_ARGS)
size = offsetof(POLYGON, p[0]) +sizeof(poly->p[0]) * 4;
poly = (POLYGON *) palloc(size);
- poly->size = size;
+ SET_VARSIZE(poly, size);
poly->npts = 4;
poly->p[0].x = box->low.x;
@@ -4312,7 +4312,7 @@ poly_path(PG_FUNCTION_ARGS)
size = offsetof(PATH, p[0]) +sizeof(path->p[0]) * poly->npts;
path = (PATH *) palloc(size);
- path->size = size;
+ SET_VARSIZE(path, size);
path->npts = poly->npts;
path->closed = TRUE;
@@ -4995,7 +4995,7 @@ circle_poly(PG_FUNCTION_ARGS)
errmsg("too many points requested")));
poly = (POLYGON *) palloc0(size); /* zero any holes */
- poly->size = size;
+ SET_VARSIZE(poly, size);
poly->npts = npts;
anglestep = (2.0 * M_PI) / npts;
diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c
index 5e995aeec9..201369c945 100644
--- a/src/backend/utils/adt/int.c
+++ b/src/backend/utils/adt/int.c
@@ -124,7 +124,7 @@ buildint2vector(const int2 *int2s, int n)
* Attach standard array header. For historical reasons, we set the index
* lower bound to 0 not 1.
*/
- result->size = Int2VectorSize(n);
+ SET_VARSIZE(result, Int2VectorSize(n));
result->ndim = 1;
result->dataoffset = 0; /* never any nulls */
result->elemtype = INT2OID;
@@ -162,7 +162,7 @@ int2vectorin(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("int2vector has too many elements")));
- result->size = Int2VectorSize(n);
+ SET_VARSIZE(result, Int2VectorSize(n));
result->ndim = 1;
result->dataoffset = 0; /* never any nulls */
result->elemtype = INT2OID;
@@ -350,7 +350,7 @@ int2_text(PG_FUNCTION_ARGS)
text *result = (text *) palloc(7 + VARHDRSZ); /* sign,5 digits, '\0' */
pg_itoa(arg1, VARDATA(result));
- VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ;
+ SET_VARSIZE(result, strlen(VARDATA(result)) + VARHDRSZ);
PG_RETURN_TEXT_P(result);
}
@@ -381,7 +381,7 @@ int4_text(PG_FUNCTION_ARGS)
text *result = (text *) palloc(12 + VARHDRSZ); /* sign,10 digits,'\0' */
pg_ltoa(arg1, VARDATA(result));
- VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ;
+ SET_VARSIZE(result, strlen(VARDATA(result)) + VARHDRSZ);
PG_RETURN_TEXT_P(result);
}
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index e831d99506..ed2c61602f 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -1171,7 +1171,7 @@ int8_text(PG_FUNCTION_ARGS)
result = (text *) palloc(VARHDRSZ + len);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, VARHDRSZ + len);
memcpy(VARDATA(result), s, len);
pfree(s);
diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c
index 92b5820dc9..f3c98610f1 100644
--- a/src/backend/utils/adt/like.c
+++ b/src/backend/utils/adt/like.c
@@ -532,7 +532,7 @@ like_escape_bytea(PG_FUNCTION_ARGS)
}
}
- VARATT_SIZEP(result) = r - ((char *) result);
+ SET_VARSIZE(result, r - ((char *) result));
PG_RETURN_BYTEA_P(result);
}
diff --git a/src/backend/utils/adt/like_match.c b/src/backend/utils/adt/like_match.c
index 4ef5a046ad..983651d22b 100644
--- a/src/backend/utils/adt/like_match.c
+++ b/src/backend/utils/adt/like_match.c
@@ -332,7 +332,7 @@ do_like_escape(text *pat, text *esc)
}
}
- VARATT_SIZEP(result) = r - ((char *) result);
+ SET_VARSIZE(result, r - ((char *) result));
return result;
}
diff --git a/src/backend/utils/adt/mac.c b/src/backend/utils/adt/mac.c
index 8b1638efab..c6a7c370f5 100644
--- a/src/backend/utils/adt/mac.c
+++ b/src/backend/utils/adt/mac.c
@@ -163,8 +163,8 @@ macaddr_text(PG_FUNCTION_ARGS)
result = palloc(len);
- VARATT_SIZEP(result) = len;
- memmove(VARDATA(result), str, (len - VARHDRSZ));
+ SET_VARSIZE(result, len);
+ memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c
index 6bad6cf635..72781eac66 100644
--- a/src/backend/utils/adt/nabstime.c
+++ b/src/backend/utils/adt/nabstime.c
@@ -1596,7 +1596,7 @@ timeofday(PG_FUNCTION_ARGS)
len = VARHDRSZ + strlen(buf);
result = (text *) palloc(len);
- VARATT_SIZEP(result) = len;
- memcpy(VARDATA(result), buf, strlen(buf));
+ SET_VARSIZE(result, len);
+ memcpy(VARDATA(result), buf, len - VARHDRSZ);
PG_RETURN_TEXT_P(result);
}
diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c
index d10902e312..a6d73bad83 100644
--- a/src/backend/utils/adt/network.c
+++ b/src/backend/utils/adt/network.c
@@ -105,9 +105,9 @@ network_in(char *src, bool is_cidr)
errdetail("Value has bits set to right of mask.")));
}
- VARATT_SIZEP(dst) = VARHDRSZ +
+ SET_VARSIZE(dst, VARHDRSZ +
((char *) ip_addr(dst) - (char *) VARDATA(dst)) +
- ip_addrsize(dst);
+ ip_addrsize(dst));
ip_bits(dst) = bits;
return dst;
@@ -220,9 +220,9 @@ network_recv(StringInfo buf, bool is_cidr)
/* translator: %s is inet or cidr */
errmsg("invalid length in external \"%s\" value",
is_cidr ? "cidr" : "inet")));
- VARATT_SIZEP(addr) = VARHDRSZ +
+ SET_VARSIZE(addr, VARHDRSZ +
((char *) ip_addr(addr) - (char *) VARDATA(addr)) +
- ip_addrsize(addr);
+ ip_addrsize(addr));
addrptr = (char *) ip_addr(addr);
for (i = 0; i < nb; i++)
@@ -638,7 +638,7 @@ network_host(PG_FUNCTION_ARGS)
/* Return string as a text datum */
len = strlen(tmp);
ret = (text *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(ret) = len + VARHDRSZ;
+ SET_VARSIZE(ret, len + VARHDRSZ);
memcpy(VARDATA(ret), tmp, len);
PG_RETURN_TEXT_P(ret);
}
@@ -667,7 +667,7 @@ network_show(PG_FUNCTION_ARGS)
/* Return string as a text datum */
len = strlen(tmp);
ret = (text *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(ret) = len + VARHDRSZ;
+ SET_VARSIZE(ret, len + VARHDRSZ);
memcpy(VARDATA(ret), tmp, len);
PG_RETURN_TEXT_P(ret);
}
@@ -692,7 +692,7 @@ inet_abbrev(PG_FUNCTION_ARGS)
/* Return string as a text datum */
len = strlen(tmp);
ret = (text *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(ret) = len + VARHDRSZ;
+ SET_VARSIZE(ret, len + VARHDRSZ);
memcpy(VARDATA(ret), tmp, len);
PG_RETURN_TEXT_P(ret);
}
@@ -717,7 +717,7 @@ cidr_abbrev(PG_FUNCTION_ARGS)
/* Return string as a text datum */
len = strlen(tmp);
ret = (text *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(ret) = len + VARHDRSZ;
+ SET_VARSIZE(ret, len + VARHDRSZ);
memcpy(VARDATA(ret), tmp, len);
PG_RETURN_TEXT_P(ret);
}
@@ -793,9 +793,9 @@ network_broadcast(PG_FUNCTION_ARGS)
ip_family(dst) = ip_family(ip);
ip_bits(dst) = ip_bits(ip);
- VARATT_SIZEP(dst) = VARHDRSZ +
+ SET_VARSIZE(dst, VARHDRSZ +
((char *) ip_addr(dst) - (char *) VARDATA(dst)) +
- ip_addrsize(dst);
+ ip_addrsize(dst));
PG_RETURN_INET_P(dst);
}
@@ -838,9 +838,9 @@ network_network(PG_FUNCTION_ARGS)
ip_family(dst) = ip_family(ip);
ip_bits(dst) = ip_bits(ip);
- VARATT_SIZEP(dst) = VARHDRSZ +
+ SET_VARSIZE(dst, VARHDRSZ +
((char *) ip_addr(dst) - (char *) VARDATA(dst)) +
- ip_addrsize(dst);
+ ip_addrsize(dst));
PG_RETURN_INET_P(dst);
}
@@ -881,9 +881,9 @@ network_netmask(PG_FUNCTION_ARGS)
ip_family(dst) = ip_family(ip);
ip_bits(dst) = ip_maxbits(ip);
- VARATT_SIZEP(dst) = VARHDRSZ +
+ SET_VARSIZE(dst, VARHDRSZ +
((char *) ip_addr(dst) - (char *) VARDATA(dst)) +
- ip_addrsize(dst);
+ ip_addrsize(dst));
PG_RETURN_INET_P(dst);
}
@@ -930,9 +930,9 @@ network_hostmask(PG_FUNCTION_ARGS)
ip_family(dst) = ip_family(ip);
ip_bits(dst) = ip_maxbits(ip);
- VARATT_SIZEP(dst) = VARHDRSZ +
+ SET_VARSIZE(dst, VARHDRSZ +
((char *) ip_addr(dst) - (char *) VARDATA(dst)) +
- ip_addrsize(dst);
+ ip_addrsize(dst));
PG_RETURN_INET_P(dst);
}
@@ -1272,9 +1272,9 @@ inetnot(PG_FUNCTION_ARGS)
ip_bits(dst) = ip_bits(ip);
ip_family(dst) = ip_family(ip);
- VARATT_SIZEP(dst) = VARHDRSZ +
+ SET_VARSIZE(dst, VARHDRSZ +
((char *) ip_addr(dst) - (char *) VARDATA(dst)) +
- ip_addrsize(dst);
+ ip_addrsize(dst));
PG_RETURN_INET_P(dst);
}
@@ -1306,9 +1306,9 @@ inetand(PG_FUNCTION_ARGS)
ip_bits(dst) = Max(ip_bits(ip), ip_bits(ip2));
ip_family(dst) = ip_family(ip);
- VARATT_SIZEP(dst) = VARHDRSZ +
+ SET_VARSIZE(dst, VARHDRSZ +
((char *) ip_addr(dst) - (char *) VARDATA(dst)) +
- ip_addrsize(dst);
+ ip_addrsize(dst));
PG_RETURN_INET_P(dst);
}
@@ -1340,9 +1340,9 @@ inetor(PG_FUNCTION_ARGS)
ip_bits(dst) = Max(ip_bits(ip), ip_bits(ip2));
ip_family(dst) = ip_family(ip);
- VARATT_SIZEP(dst) = VARHDRSZ +
+ SET_VARSIZE(dst, VARHDRSZ +
((char *) ip_addr(dst) - (char *) VARDATA(dst)) +
- ip_addrsize(dst);
+ ip_addrsize(dst));
PG_RETURN_INET_P(dst);
}
@@ -1394,9 +1394,9 @@ internal_inetpl(inet *ip, int64 addend)
ip_bits(dst) = ip_bits(ip);
ip_family(dst) = ip_family(ip);
- VARATT_SIZEP(dst) = VARHDRSZ +
+ SET_VARSIZE(dst, VARHDRSZ +
((char *) ip_addr(dst) - (char *) VARDATA(dst)) +
- ip_addrsize(dst);
+ ip_addrsize(dst));
return dst;
}
diff --git a/src/backend/utils/adt/numeric.c b/src/backend/utils/adt/numeric.c
index 1cb71deb31..f6fe9a777e 100644
--- a/src/backend/utils/adt/numeric.c
+++ b/src/backend/utils/adt/numeric.c
@@ -230,7 +230,7 @@ static void dump_var(const char *str, NumericVar *var);
#define NUMERIC_DIGITS(num) ((NumericDigit *)(num)->n_data)
#define NUMERIC_NDIGITS(num) \
- (((num)->varlen - NUMERIC_HDRSZ) / sizeof(NumericDigit))
+ ((VARSIZE(num) - NUMERIC_HDRSZ) / sizeof(NumericDigit))
static void alloc_var(NumericVar *var, int ndigits);
static void free_var(NumericVar *var);
@@ -494,8 +494,8 @@ numeric(PG_FUNCTION_ARGS)
*/
if (typmod < (int32) (VARHDRSZ))
{
- new = (Numeric) palloc(num->varlen);
- memcpy(new, num, num->varlen);
+ new = (Numeric) palloc(VARSIZE(num));
+ memcpy(new, num, VARSIZE(num));
PG_RETURN_NUMERIC(new);
}
@@ -515,8 +515,8 @@ numeric(PG_FUNCTION_ARGS)
ddigits = (num->n_weight + 1) * DEC_DIGITS;
if (ddigits <= maxdigits && scale >= NUMERIC_DSCALE(num))
{
- new = (Numeric) palloc(num->varlen);
- memcpy(new, num, num->varlen);
+ new = (Numeric) palloc(VARSIZE(num));
+ memcpy(new, num, VARSIZE(num));
new->n_sign_dscale = NUMERIC_SIGN(new) |
((uint16) scale & NUMERIC_DSCALE_MASK);
PG_RETURN_NUMERIC(new);
@@ -621,8 +621,8 @@ numeric_abs(PG_FUNCTION_ARGS)
/*
* Do it the easy way directly on the packed format
*/
- res = (Numeric) palloc(num->varlen);
- memcpy(res, num, num->varlen);
+ res = (Numeric) palloc(VARSIZE(num));
+ memcpy(res, num, VARSIZE(num));
res->n_sign_dscale = NUMERIC_POS | NUMERIC_DSCALE(num);
@@ -645,15 +645,15 @@ numeric_uminus(PG_FUNCTION_ARGS)
/*
* Do it the easy way directly on the packed format
*/
- res = (Numeric) palloc(num->varlen);
- memcpy(res, num, num->varlen);
+ res = (Numeric) palloc(VARSIZE(num));
+ memcpy(res, num, VARSIZE(num));
/*
* The packed format is known to be totally zero digit trimmed always. So
* we can identify a ZERO by the fact that there are no digits at all. Do
* nothing to a zero.
*/
- if (num->varlen != NUMERIC_HDRSZ)
+ if (VARSIZE(num) != NUMERIC_HDRSZ)
{
/* Else, flip the sign */
if (NUMERIC_SIGN(num) == NUMERIC_POS)
@@ -672,8 +672,8 @@ numeric_uplus(PG_FUNCTION_ARGS)
Numeric num = PG_GETARG_NUMERIC(0);
Numeric res;
- res = (Numeric) palloc(num->varlen);
- memcpy(res, num, num->varlen);
+ res = (Numeric) palloc(VARSIZE(num));
+ memcpy(res, num, VARSIZE(num));
PG_RETURN_NUMERIC(res);
}
@@ -703,7 +703,7 @@ numeric_sign(PG_FUNCTION_ARGS)
* The packed format is known to be totally zero digit trimmed always. So
* we can identify a ZERO by the fact that there are no digits at all.
*/
- if (num->varlen == NUMERIC_HDRSZ)
+ if (VARSIZE(num) == NUMERIC_HDRSZ)
set_var_from_var(&const_zero, &result);
else
{
@@ -2105,7 +2105,7 @@ numeric_text(PG_FUNCTION_ARGS)
result = (text *) palloc(VARHDRSZ + len);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, VARHDRSZ + len);
memcpy(VARDATA(result), s, len);
pfree(s);
@@ -2301,7 +2301,7 @@ numeric_avg(PG_FUNCTION_ARGS)
/* SQL92 defines AVG of no values to be NULL */
/* N is zero iff no digits (cf. numeric_uminus) */
- if (N->varlen == NUMERIC_HDRSZ)
+ if (VARSIZE(N) == NUMERIC_HDRSZ)
PG_RETURN_NULL();
PG_RETURN_DATUM(DirectFunctionCall2(numeric_div,
@@ -3232,7 +3232,7 @@ make_result(NumericVar *var)
{
result = (Numeric) palloc(NUMERIC_HDRSZ);
- result->varlen = NUMERIC_HDRSZ;
+ SET_VARSIZE(result, NUMERIC_HDRSZ);
result->n_weight = 0;
result->n_sign_dscale = NUMERIC_NAN;
@@ -3263,7 +3263,7 @@ make_result(NumericVar *var)
/* Build the result */
len = NUMERIC_HDRSZ + n * sizeof(NumericDigit);
result = (Numeric) palloc(len);
- result->varlen = len;
+ SET_VARSIZE(result, len);
result->n_weight = weight;
result->n_sign_dscale = sign | (var->dscale & NUMERIC_DSCALE_MASK);
diff --git a/src/backend/utils/adt/oid.c b/src/backend/utils/adt/oid.c
index bf27b4d634..a82da371f3 100644
--- a/src/backend/utils/adt/oid.c
+++ b/src/backend/utils/adt/oid.c
@@ -174,7 +174,7 @@ buildoidvector(const Oid *oids, int n)
* Attach standard array header. For historical reasons, we set the index
* lower bound to 0 not 1.
*/
- result->size = OidVectorSize(n);
+ SET_VARSIZE(result, OidVectorSize(n));
result->ndim = 1;
result->dataoffset = 0; /* never any nulls */
result->elemtype = OIDOID;
@@ -211,7 +211,7 @@ oidvectorin(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("oidvector has too many elements")));
- result->size = OidVectorSize(n);
+ SET_VARSIZE(result, OidVectorSize(n));
result->ndim = 1;
result->dataoffset = 0; /* never any nulls */
result->elemtype = OIDOID;
@@ -434,7 +434,7 @@ oid_text(PG_FUNCTION_ARGS)
result = (text *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
diff --git a/src/backend/utils/adt/oracle_compat.c b/src/backend/utils/adt/oracle_compat.c
index de01cec428..68d2c1bd98 100644
--- a/src/backend/utils/adt/oracle_compat.c
+++ b/src/backend/utils/adt/oracle_compat.c
@@ -144,7 +144,7 @@ wcstotext(const wchar_t *str, int ncodes)
Assert(nbytes <= (size_t) (ncodes * MB_CUR_MAX));
- VARATT_SIZEP(result) = nbytes + VARHDRSZ;
+ SET_VARSIZE(result, nbytes + VARHDRSZ);
return result;
}
@@ -229,7 +229,7 @@ win32_utf8_wcstotext(const wchar_t *str)
errmsg("UTF-16 to UTF-8 translation failed: %lu",
GetLastError())));
- VARATT_SIZEP(result) = nbytes + VARHDRSZ - 1; /* -1 to ignore null */
+ SET_VARSIZE(result, nbytes + VARHDRSZ - 1); /* -1 to ignore null */
return result;
}
@@ -278,7 +278,7 @@ wstring_upper(char *str)
in_text = palloc(nbytes + VARHDRSZ);
memcpy(VARDATA(in_text), str, nbytes);
- VARATT_SIZEP(in_text) = nbytes + VARHDRSZ;
+ SET_VARSIZE(in_text, nbytes + VARHDRSZ);
workspace = texttowcs(in_text);
@@ -312,7 +312,7 @@ wstring_lower(char *str)
in_text = palloc(nbytes + VARHDRSZ);
memcpy(VARDATA(in_text), str, nbytes);
- VARATT_SIZEP(in_text) = nbytes + VARHDRSZ;
+ SET_VARSIZE(in_text, nbytes + VARHDRSZ);
workspace = texttowcs(in_text);
@@ -639,7 +639,7 @@ lpad(PG_FUNCTION_ARGS)
ptr1 += mlen;
}
- VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
+ SET_VARSIZE(ret, ptr_ret - (char *) ret);
PG_RETURN_TEXT_P(ret);
}
@@ -735,7 +735,7 @@ rpad(PG_FUNCTION_ARGS)
ptr2 = VARDATA(string2);
}
- VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
+ SET_VARSIZE(ret, ptr_ret - (char *) ret);
PG_RETURN_TEXT_P(ret);
}
@@ -944,7 +944,7 @@ dotrim(const char *string, int stringlen,
/* Return selected portion of string */
result = (text *) palloc(VARHDRSZ + stringlen);
- VARATT_SIZEP(result) = VARHDRSZ + stringlen;
+ SET_VARSIZE(result, VARHDRSZ + stringlen);
memcpy(VARDATA(result), string, stringlen);
return result;
@@ -1017,7 +1017,7 @@ byteatrim(PG_FUNCTION_ARGS)
}
ret = (bytea *) palloc(VARHDRSZ + m);
- VARATT_SIZEP(ret) = VARHDRSZ + m;
+ SET_VARSIZE(ret, VARHDRSZ + m);
memcpy(VARDATA(ret), ptr, m);
PG_RETURN_BYTEA_P(ret);
@@ -1223,7 +1223,7 @@ translate(PG_FUNCTION_ARGS)
m -= source_len;
}
- VARATT_SIZEP(result) = retlen + VARHDRSZ;
+ SET_VARSIZE(result, retlen + VARHDRSZ);
/*
* There may be some wasted space in the result if deletions occurred, but
@@ -1275,13 +1275,13 @@ ascii(PG_FUNCTION_ARGS)
********************************************************************/
Datum
-chr (PG_FUNCTION_ARGS)
+chr(PG_FUNCTION_ARGS)
{
int32 cvalue = PG_GETARG_INT32(0);
text *result;
result = (text *) palloc(VARHDRSZ + 1);
- VARATT_SIZEP(result) = VARHDRSZ + 1;
+ SET_VARSIZE(result, VARHDRSZ + 1);
*VARDATA(result) = (char) cvalue;
PG_RETURN_TEXT_P(result);
@@ -1332,7 +1332,7 @@ repeat(PG_FUNCTION_ARGS)
result = (text *) palloc(tlen);
- VARATT_SIZEP(result) = tlen;
+ SET_VARSIZE(result, tlen);
cp = VARDATA(result);
for (i = 0; i < count; i++)
{
diff --git a/src/backend/utils/adt/pg_lzcompress.c b/src/backend/utils/adt/pg_lzcompress.c
index 8e859d1a0f..c0c8464e9c 100644
--- a/src/backend/utils/adt/pg_lzcompress.c
+++ b/src/backend/utils/adt/pg_lzcompress.c
@@ -45,7 +45,7 @@
* PGLZ_Header is defined as
*
* typedef struct PGLZ_Header {
- * int32 varsize;
+ * int32 vl_len_;
* int32 rawsize;
* }
*
@@ -54,7 +54,7 @@
* The data representation is easiest explained by describing
* the process of decompression.
*
- * If varsize == rawsize + sizeof(PGLZ_Header), then the data
+ * If VARSIZE(x) == rawsize + sizeof(PGLZ_Header), then the data
* is stored uncompressed as plain bytes. Thus, the decompressor
* simply copies rawsize bytes from the location after the
* header to the destination.
@@ -618,7 +618,7 @@ pglz_compress(const char *source, int32 slen, PGLZ_Header *dest,
/*
* Success - need only fill in the actual length of the compressed datum.
*/
- dest->varsize = result_size + sizeof(PGLZ_Header);
+ SET_VARSIZE(dest, result_size + sizeof(PGLZ_Header));
return true;
}
@@ -643,7 +643,7 @@ pglz_decompress(const PGLZ_Header *source, char *dest)
int32 destsize;
dp = ((const unsigned char *) source) + sizeof(PGLZ_Header);
- dend = ((const unsigned char *) source) + VARATT_SIZE(source);
+ dend = ((const unsigned char *) source) + VARSIZE(source);
bp = (unsigned char *) dest;
while (dp < dend)
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 49f891bb27..3ad44174d6 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -398,7 +398,7 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
len = strlen(activity);
result = palloc(VARHDRSZ + len);
- VARATT_SIZEP(result) = VARHDRSZ + len;
+ SET_VARSIZE(result, VARHDRSZ + len);
memcpy(VARDATA(result), activity, len);
PG_RETURN_TEXT_P(result);
diff --git a/src/backend/utils/adt/quote.c b/src/backend/utils/adt/quote.c
index 29a276eccd..000f75ad8d 100644
--- a/src/backend/utils/adt/quote.c
+++ b/src/backend/utils/adt/quote.c
@@ -39,7 +39,7 @@ quote_ident(PG_FUNCTION_ARGS)
len = strlen(qstr);
result = (text *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, len + VARHDRSZ);
memcpy(VARDATA(result), qstr, len);
PG_RETURN_TEXT_P(result);
@@ -92,7 +92,7 @@ quote_literal(PG_FUNCTION_ARGS)
}
*cp2++ = '\'';
- VARATT_SIZEP(result) = cp2 - ((char *) result);
+ SET_VARSIZE(result, cp2 - ((char *) result));
PG_RETURN_TEXT_P(result);
}
diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c
index dc944f0944..d4041aa402 100644
--- a/src/backend/utils/adt/regexp.c
+++ b/src/backend/utils/adt/regexp.c
@@ -620,7 +620,7 @@ similar_escape(PG_FUNCTION_ARGS)
*r++ = ')';
*r++ = '$';
- VARATT_SIZEP(result) = r - ((char *) result);
+ SET_VARSIZE(result, r - ((char *) result));
PG_RETURN_TEXT_P(result);
}
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index fb8909e600..aa2d5b719d 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -5298,7 +5298,7 @@ string_to_text(char *str)
tlen = slen + VARHDRSZ;
result = (text *) palloc(tlen);
- VARATT_SIZEP(result) = tlen;
+ SET_VARSIZE(result, tlen);
memcpy(VARDATA(result), str, slen);
pfree(str);
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 8b9ac190bd..aebc973b16 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -4731,7 +4731,7 @@ string_to_bytea_const(const char *str, size_t str_len)
Datum conval;
memcpy(VARDATA(bstr), str, str_len);
- VARATT_SIZEP(bstr) = VARHDRSZ + str_len;
+ SET_VARSIZE(bstr, VARHDRSZ + str_len);
conval = PointerGetDatum(bstr);
return makeConst(BYTEAOID, -1, conval, false, false);
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 05959f6101..1d1917ced4 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -3199,8 +3199,8 @@ timestamp_text(PG_FUNCTION_ARGS)
result = palloc(len);
- VARATT_SIZEP(result) = len;
- memmove(VARDATA(result), str, len - VARHDRSZ);
+ SET_VARSIZE(result, len);
+ memcpy(VARDATA(result), str, len - VARHDRSZ);
pfree(str);
@@ -3260,8 +3260,8 @@ timestamptz_text(PG_FUNCTION_ARGS)
result = palloc(len);
- VARATT_SIZEP(result) = len;
- memmove(VARDATA(result), str, len - VARHDRSZ);
+ SET_VARSIZE(result, len);
+ memcpy(VARDATA(result), str, len - VARHDRSZ);
pfree(str);
@@ -3320,8 +3320,8 @@ interval_text(PG_FUNCTION_ARGS)
result = palloc(len);
- VARATT_SIZEP(result) = len;
- memmove(VARDATA(result), str, len - VARHDRSZ);
+ SET_VARSIZE(result, len);
+ memcpy(VARDATA(result), str, len - VARHDRSZ);
pfree(str);
diff --git a/src/backend/utils/adt/varbit.c b/src/backend/utils/adt/varbit.c
index 207e4bfd62..477feaf65a 100644
--- a/src/backend/utils/adt/varbit.c
+++ b/src/backend/utils/adt/varbit.c
@@ -160,7 +160,7 @@ bit_in(PG_FUNCTION_ARGS)
len = VARBITTOTALLEN(atttypmod);
/* set to 0 so that *r is always initialised and string is zero-padded */
result = (VarBit *) palloc0(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = atttypmod;
r = VARBITS(result);
@@ -299,7 +299,7 @@ bit_recv(PG_FUNCTION_ARGS)
len = VARBITTOTALLEN(bitlen);
result = (VarBit *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = bitlen;
pq_copymsgbytes(buf, (char *) VARBITS(result), VARBITBYTES(result));
@@ -356,7 +356,7 @@ bit(PG_FUNCTION_ARGS)
rlen = VARBITTOTALLEN(len);
/* set to 0 so that string is zero-padded */
result = (VarBit *) palloc0(rlen);
- VARATT_SIZEP(result) = rlen;
+ SET_VARSIZE(result, rlen);
VARBITLEN(result) = len;
memcpy(VARBITS(result), VARBITS(arg),
@@ -458,7 +458,7 @@ varbit_in(PG_FUNCTION_ARGS)
len = VARBITTOTALLEN(bitlen);
/* set to 0 so that *r is always initialised and string is zero-padded */
result = (VarBit *) palloc0(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = Min(bitlen, atttypmod);
r = VARBITS(result);
@@ -595,7 +595,7 @@ varbit_recv(PG_FUNCTION_ARGS)
len = VARBITTOTALLEN(bitlen);
result = (VarBit *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = bitlen;
pq_copymsgbytes(buf, (char *) VARBITS(result), VARBITBYTES(result));
@@ -656,7 +656,7 @@ varbit(PG_FUNCTION_ARGS)
rlen = VARBITTOTALLEN(len);
result = (VarBit *) palloc(rlen);
- VARATT_SIZEP(result) = rlen;
+ SET_VARSIZE(result, rlen);
VARBITLEN(result) = len;
memcpy(VARBITS(result), VARBITS(arg), VARBITBYTES(result));
@@ -884,7 +884,7 @@ bitcat(PG_FUNCTION_ARGS)
bytelen = VARBITTOTALLEN(bitlen1 + bitlen2);
result = (VarBit *) palloc(bytelen);
- VARATT_SIZEP(result) = bytelen;
+ SET_VARSIZE(result, bytelen);
VARBITLEN(result) = bitlen1 + bitlen2;
/* Copy the first bitstring in */
@@ -951,7 +951,7 @@ bitsubstr(PG_FUNCTION_ARGS)
/* Need to return a zero-length bitstring */
len = VARBITTOTALLEN(0);
result = (VarBit *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = 0;
}
else
@@ -963,7 +963,7 @@ bitsubstr(PG_FUNCTION_ARGS)
rbitlen = e1 - s1;
len = VARBITTOTALLEN(rbitlen);
result = (VarBit *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = rbitlen;
len -= VARHDRSZ + VARBITHDRSZ;
/* Are we copying from a byte boundary? */
@@ -1044,7 +1044,7 @@ bitand(PG_FUNCTION_ARGS)
len = VARSIZE(arg1);
result = (VarBit *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = bitlen1;
p1 = VARBITS(arg1);
@@ -1084,7 +1084,7 @@ bitor(PG_FUNCTION_ARGS)
errmsg("cannot OR bit strings of different sizes")));
len = VARSIZE(arg1);
result = (VarBit *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = bitlen1;
p1 = VARBITS(arg1);
@@ -1131,7 +1131,7 @@ bitxor(PG_FUNCTION_ARGS)
len = VARSIZE(arg1);
result = (VarBit *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = bitlen1;
p1 = VARBITS(arg1);
@@ -1164,7 +1164,7 @@ bitnot(PG_FUNCTION_ARGS)
bits8 mask;
result = (VarBit *) palloc(VARSIZE(arg));
- VARATT_SIZEP(result) = VARSIZE(arg);
+ SET_VARSIZE(result, VARSIZE(arg));
VARBITLEN(result) = VARBITLEN(arg);
p = VARBITS(arg);
@@ -1205,7 +1205,7 @@ bitshiftleft(PG_FUNCTION_ARGS)
Int32GetDatum(-shft)));
result = (VarBit *) palloc(VARSIZE(arg));
- VARATT_SIZEP(result) = VARSIZE(arg);
+ SET_VARSIZE(result, VARSIZE(arg));
VARBITLEN(result) = VARBITLEN(arg);
r = VARBITS(result);
@@ -1264,7 +1264,7 @@ bitshiftright(PG_FUNCTION_ARGS)
Int32GetDatum(-shft)));
result = (VarBit *) palloc(VARSIZE(arg));
- VARATT_SIZEP(result) = VARSIZE(arg);
+ SET_VARSIZE(result, VARSIZE(arg));
VARBITLEN(result) = VARBITLEN(arg);
r = VARBITS(result);
@@ -1324,7 +1324,7 @@ bitfromint4(PG_FUNCTION_ARGS)
rlen = VARBITTOTALLEN(typmod);
result = (VarBit *) palloc(rlen);
- VARATT_SIZEP(result) = rlen;
+ SET_VARSIZE(result, rlen);
VARBITLEN(result) = typmod;
r = VARBITS(result);
@@ -1399,7 +1399,7 @@ bitfromint8(PG_FUNCTION_ARGS)
rlen = VARBITTOTALLEN(typmod);
result = (VarBit *) palloc(rlen);
- VARATT_SIZEP(result) = rlen;
+ SET_VARSIZE(result, rlen);
VARBITLEN(result) = typmod;
r = VARBITS(result);
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index ce0490d5f8..50c3ac479b 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -169,7 +169,7 @@ bpchar_input(const char *s, size_t len, int32 atttypmod)
}
result = (BpChar *) palloc(maxlen + VARHDRSZ);
- VARATT_SIZEP(result) = maxlen + VARHDRSZ;
+ SET_VARSIZE(result, maxlen + VARHDRSZ);
r = VARDATA(result);
memcpy(r, s, len);
@@ -328,7 +328,7 @@ bpchar(PG_FUNCTION_ARGS)
s = VARDATA(source);
result = palloc(maxlen);
- VARATT_SIZEP(result) = maxlen;
+ SET_VARSIZE(result, maxlen);
r = VARDATA(result);
memcpy(r, s, len - VARHDRSZ);
@@ -352,7 +352,7 @@ char_bpchar(PG_FUNCTION_ARGS)
result = (BpChar *) palloc(VARHDRSZ + 1);
- VARATT_SIZEP(result) = VARHDRSZ + 1;
+ SET_VARSIZE(result, VARHDRSZ + 1);
*(VARDATA(result)) = c;
PG_RETURN_BPCHAR_P(result);
@@ -409,7 +409,7 @@ name_bpchar(PG_FUNCTION_ARGS)
len = strlen(NameStr(*s));
result = (BpChar *) palloc(VARHDRSZ + len);
memcpy(VARDATA(result), NameStr(*s), len);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, VARHDRSZ + len);
PG_RETURN_BPCHAR_P(result);
}
@@ -477,7 +477,7 @@ varchar_input(const char *s, size_t len, int32 atttypmod)
}
result = (VarChar *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, len + VARHDRSZ);
memcpy(VARDATA(result), s, len);
return result;
@@ -601,7 +601,7 @@ varchar(PG_FUNCTION_ARGS)
len = maxmblen + VARHDRSZ;
result = palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), VARDATA(source), len - VARHDRSZ);
PG_RETURN_VARCHAR_P(result);
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 75632f08fd..34fbedec3d 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -124,7 +124,7 @@ byteain(PG_FUNCTION_ARGS)
byte += VARHDRSZ;
result = (bytea *) palloc(byte);
- VARATT_SIZEP(result) = byte; /* set varlena length */
+ SET_VARSIZE(result, byte);
tp = inputText;
rp = VARDATA(result);
@@ -233,7 +233,7 @@ bytearecv(PG_FUNCTION_ARGS)
nbytes = buf->len - buf->cursor;
result = (bytea *) palloc(nbytes + VARHDRSZ);
- VARATT_SIZEP(result) = nbytes + VARHDRSZ;
+ SET_VARSIZE(result, nbytes + VARHDRSZ);
pq_copymsgbytes(buf, VARDATA(result), nbytes);
PG_RETURN_BYTEA_P(result);
}
@@ -264,7 +264,7 @@ textin(PG_FUNCTION_ARGS)
len = strlen(inputText);
result = (text *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, len + VARHDRSZ);
memcpy(VARDATA(result), inputText, len);
@@ -303,7 +303,7 @@ textrecv(PG_FUNCTION_ARGS)
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
result = (text *) palloc(nbytes + VARHDRSZ);
- VARATT_SIZEP(result) = nbytes + VARHDRSZ;
+ SET_VARSIZE(result, nbytes + VARHDRSZ);
memcpy(VARDATA(result), str, nbytes);
pfree(str);
PG_RETURN_TEXT_P(result);
@@ -466,7 +466,7 @@ textcat(PG_FUNCTION_ARGS)
result = (text *) palloc(len);
/* Set size of result string... */
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
/* Fill data field of result string... */
ptr = VARDATA(result);
@@ -737,7 +737,7 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
p += pg_mblen(p);
ret = (text *) palloc(VARHDRSZ + (p - s));
- VARATT_SIZEP(ret) = VARHDRSZ + (p - s);
+ SET_VARSIZE(ret, VARHDRSZ + (p - s));
memcpy(VARDATA(ret), s, (p - s));
if (slice != (text *) DatumGetPointer(str))
@@ -1409,7 +1409,7 @@ byteacat(PG_FUNCTION_ARGS)
result = (bytea *) palloc(len);
/* Set size of result string... */
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
/* Fill data field of result string... */
ptr = VARDATA(result);
@@ -1761,7 +1761,7 @@ name_text(PG_FUNCTION_ARGS)
#endif
result = palloc(VARHDRSZ + len);
- VARATT_SIZEP(result) = VARHDRSZ + len;
+ SET_VARSIZE(result, VARHDRSZ + len);
memcpy(VARDATA(result), NameStr(*s), len);
PG_RETURN_TEXT_P(result);
@@ -2593,7 +2593,7 @@ text_to_array(PG_FUNCTION_ARGS)
/* must build a temp text datum to pass to accumArrayResult */
result_text = (text *) palloc(VARHDRSZ + chunk_len);
- VARATT_SIZEP(result_text) = VARHDRSZ + chunk_len;
+ SET_VARSIZE(result_text, VARHDRSZ + chunk_len);
memcpy(VARDATA(result_text), start_ptr, chunk_len);
/* stash away this field */
diff --git a/src/backend/utils/adt/version.c b/src/backend/utils/adt/version.c
index 889198481b..368935f5af 100644
--- a/src/backend/utils/adt/version.c
+++ b/src/backend/utils/adt/version.c
@@ -23,7 +23,7 @@ pgsql_version(PG_FUNCTION_ARGS)
int n = strlen(PG_VERSION_STR);
text *ret = (text *) palloc(n + VARHDRSZ);
- VARATT_SIZEP(ret) = n + VARHDRSZ;
+ SET_VARSIZE(ret, n + VARHDRSZ);
memcpy(VARDATA(ret), PG_VERSION_STR, n);
PG_RETURN_TEXT_P(ret);
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index a222602c42..0feaddbcaf 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -128,7 +128,7 @@ xml_in(PG_FUNCTION_ARGS)
len = strlen(s);
vardata = palloc(len + VARHDRSZ);
- VARATT_SIZEP(vardata) = len + VARHDRSZ;
+ SET_VARSIZE(vardata, len + VARHDRSZ);
memcpy(VARDATA(vardata), s, len);
/*
@@ -225,7 +225,7 @@ xml_recv(PG_FUNCTION_ARGS)
str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
result = palloc(nbytes + VARHDRSZ);
- VARATT_SIZEP(result) = nbytes + VARHDRSZ;
+ SET_VARSIZE(result, nbytes + VARHDRSZ);
memcpy(VARDATA(result), str, nbytes);
parse_xml_decl((xmlChar *) str, NULL, NULL, &encoding, NULL);
@@ -251,7 +251,7 @@ xml_recv(PG_FUNCTION_ARGS)
nbytes = strlen(newstr);
result = palloc(nbytes + VARHDRSZ);
- VARATT_SIZEP(result) = nbytes + VARHDRSZ;
+ SET_VARSIZE(result, nbytes + VARHDRSZ);
memcpy(VARDATA(result), newstr, nbytes);
}
@@ -293,7 +293,7 @@ stringinfo_to_xmltype(StringInfo buf)
len = buf->len + VARHDRSZ;
result = palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), buf->data, buf->len);
return result;
@@ -308,7 +308,7 @@ cstring_to_xmltype(const char *string)
len = strlen(string) + VARHDRSZ;
result = palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), string, len - VARHDRSZ);
return result;
@@ -324,7 +324,7 @@ xmlBuffer_to_xmltype(xmlBufferPtr buf)
len = xmlBufferLength(buf) + VARHDRSZ;
result = palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), xmlBufferContent(buf), len - VARHDRSZ);
return result;
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index c7504ba4d7..0420ef10c0 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -3244,7 +3244,7 @@ load_relcache_init_file(void)
rel->rd_options = palloc(len);
if ((nread = fread(rel->rd_options, 1, len, fp)) != len)
goto read_failed;
- if (len != VARATT_SIZE(rel->rd_options))
+ if (len != VARSIZE(rel->rd_options))
goto read_failed; /* sanity check */
}
else
@@ -3540,7 +3540,7 @@ write_relcache_init_file(void)
/* next, do the access method specific field */
write_item(rel->rd_options,
- (rel->rd_options ? VARATT_SIZE(rel->rd_options) : 0),
+ (rel->rd_options ? VARSIZE(rel->rd_options) : 0),
fp);
/* If it's an index, there's more to do */
diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c
index 1ff32c2ce5..89dc6e2f9a 100644
--- a/src/backend/utils/mb/mbutils.c
+++ b/src/backend/utils/mb/mbutils.c
@@ -339,7 +339,7 @@ pg_convert2(PG_FUNCTION_ARGS)
*/
len = strlen((char *) result) + VARHDRSZ;
retval = palloc(len);
- VARATT_SIZEP(retval) = len;
+ SET_VARSIZE(retval, len);
memcpy(VARDATA(retval), result, len - VARHDRSZ);
if (result != str)
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;
diff --git a/src/tutorial/funcs.c b/src/tutorial/funcs.c
index 9a83e6438c..28f9c5e297 100644
--- a/src/tutorial/funcs.c
+++ b/src/tutorial/funcs.c
@@ -71,7 +71,7 @@ copytext(text *t)
*/
text *new_t = (text *) palloc(VARSIZE(t));
- VARATT_SIZEP(new_t) = VARSIZE(t);
+ SET_VARSIZE(new_t, VARSIZE(t));
/*
* VARDATA is a pointer to the data region of the struct.
@@ -90,7 +90,7 @@ concat_text(text *arg1, text *arg2)
int32 new_text_size = arg1_size + arg2_size + VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
- VARATT_SIZEP(new_text) = new_text_size;
+ SET_VARSIZE(new_text, new_text_size);
memcpy(VARDATA(new_text), VARDATA(arg1), arg1_size);
memcpy(VARDATA(new_text) + arg1_size, VARDATA(arg2), arg2_size);
return new_text;
diff --git a/src/tutorial/funcs_new.c b/src/tutorial/funcs_new.c
index b76146c9d3..f67c97560d 100644
--- a/src/tutorial/funcs_new.c
+++ b/src/tutorial/funcs_new.c
@@ -83,7 +83,7 @@ copytext(PG_FUNCTION_ARGS)
*/
text *new_t = (text *) palloc(VARSIZE(t));
- VARATT_SIZEP(new_t) = VARSIZE(t);
+ SET_VARSIZE(new_t, VARSIZE(t));
/*
* VARDATA is a pointer to the data region of the struct.
@@ -106,7 +106,7 @@ concat_text(PG_FUNCTION_ARGS)
int32 new_text_size = arg1_size + arg2_size + VARHDRSZ;
text *new_text = (text *) palloc(new_text_size);
- VARATT_SIZEP(new_text) = new_text_size;
+ SET_VARSIZE(new_text, new_text_size);
memcpy(VARDATA(new_text), VARDATA(arg1), arg1_size);
memcpy(VARDATA(new_text) + arg1_size, VARDATA(arg2), arg2_size);
PG_RETURN_TEXT_P(new_text);