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;
}
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;
-
}
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;
}
* darcy@druid.net
* http://www.druid.net/darcy/
*
- * $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.18 2007/02/07 00:52:35 petere Exp $
+ * $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.19 2007/02/27 23:48:05 tgl Exp $
* best viewed with tabs set to 4
*/
{
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);
}
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);
}
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);
}
/******************************************************************************
- $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.30 2006/10/04 00:29:44 momjian Exp $
+ $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.31 2007/02/27 23:48:05 tgl Exp $
This file contains routines that can be bound to a Postgres backend and
called by the backend in the process of processing queries. The calling
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++)
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++)
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++)
/*
* sizep = sizeof(NDBOX); -- NDBOX has variable size
*/
- *sizep = tmp->size;
+ *sizep = VARSIZE(tmp);
for (i = 1; i < entryvec->n; i++)
{
NDBOX *retval;
retval = cube_union_v0(r1, r2);
- *sizep = retval->size;
+ *sizep = VARSIZE(retval);
return (retval);
}
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;
}
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;
}
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++)
{
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];
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);
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++)
{
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++)
{
-/* $PostgreSQL: pgsql/contrib/cube/cubedata.h,v 1.7 2006/03/11 04:38:28 momjian Exp $ */
+/* $PostgreSQL: pgsql/contrib/cube/cubedata.h,v 1.8 2007/02/27 23:48:05 tgl Exp $ */
#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;
/* NdBox = [(lowerleft),(upperright)] */
/* [(xLL(1)...xLL(N)),(xUR(1)...xUR(n))] */
-/* $PostgreSQL: pgsql/contrib/cube/cubeparse.y,v 1.16 2006/03/11 04:38:28 momjian Exp $ */
+/* $PostgreSQL: pgsql/contrib/cube/cubeparse.y,v 1.17 2007/02/27 23:48:05 tgl Exp $ */
#define YYPARSE_PARAM result /* need this to pass a pointer (void *) to yyparse */
#define YYSTYPE char *
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;
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;
/*
* This is a port of the Double Metaphone algorithm for use in PostgreSQL.
*
- * $PostgreSQL: pgsql/contrib/fuzzystrmatch/dmetaphone.c,v 1.10 2006/09/22 21:39:56 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/fuzzystrmatch/dmetaphone.c,v 1.11 2007/02/27 23:48:05 tgl Exp $
*
* Double Metaphone computes 2 "sounds like" strings - a primary and an
* alternate. In most cases they are the same, but for foreign names
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);
}
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);
}
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);
{
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++;
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++;
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++;
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++;
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);
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);
}
* DMN Digital Music Network.
* www.dmn.com
*
- * $PostgreSQL: pgsql/contrib/intagg/int_aggregate.c,v 1.25 2006/07/11 17:04:12 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/intagg/int_aggregate.c,v 1.26 2007/02/27 23:48:06 tgl Exp $
*
* Copyright (C) Digital Music Network
* December 20, 2001
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;
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;
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 */
if (len == 0)
{
res = (text *) palloc(1 + VARHDRSZ);
- VARATT_SIZEP(res) = 1 + VARHDRSZ;
+ SET_VARSIZE(res, 1 + VARHDRSZ);
*((char *) VARDATA(res)) = 'T';
}
else
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);
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;
a = (ArrayType *) repalloc(a, nbytes);
- a->size = nbytes;
+ SET_VARSIZE(a, nbytes);
*((int *) ARR_DIMS(a)) = num;
return a;
}
/*
* op function for ltree
* Teodor Sigaev <teodor@stack.net>
- * $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.14 2006/10/04 00:29:45 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.15 2007/02/27 23:48:06 tgl Exp $
*/
#include "ltree.h"
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);
{
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++;
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.25 2006/11/10 06:28:29 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.26 2007/02/27 23:48:06 tgl Exp $
*/
#include "postgres.h"
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;
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);
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);
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);
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);
errmsg("encrypt error: %s", px_strerror(err))));
}
- VARATT_SIZEP(res) = VARHDRSZ + rlen;
+ SET_VARSIZE(res, VARHDRSZ + rlen);
PG_RETURN_BYTEA_P(res);
}
(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);
(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);
(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);
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);
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.8 2006/11/10 06:28:29 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.9 2007/02/27 23:48:06 tgl Exp $
*/
#include "postgres.h"
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;
}
/* 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);
/* res_len includes VARHDRSZ */
res = (bytea *) restmp;
- VARATT_SIZEP(res) = res_len;
+ SET_VARSIZE(res, res_len);
if (need_text && got_unicode)
{
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);
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);
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);
* Written by Victor B. Wagner <vitus@cryptocom.ru>, Cryptocom LTD
* This file is distributed under BSD-style license.
*
- * $PostgreSQL: pgsql/contrib/sslinfo/sslinfo.c,v 1.5 2006/10/04 00:29:46 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/sslinfo/sslinfo.c,v 1.6 2007/02/27 23:48:06 tgl Exp $
*/
#include "postgres.h"
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);
}
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
*/
if (dp != sp)
pfree(dp);
- VARATT_SIZEP(result) = outlen + VARHDRSZ;
+
PG_RETURN_TEXT_P(result);
}
text *out = (text *) palloc(len + VARHDRSZ);
memcpy(VARDATA(out), in, len);
- VARATT_SIZEP(out) = len + VARHDRSZ;
+ SET_VARSIZE(out, len + VARHDRSZ);
return out;
}
{
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);
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);
if (query->size == 0)
{
res = (text *) palloc(VARHDRSZ);
- VARATT_SIZEP(res) = VARHDRSZ;
+ SET_VARSIZE(res, VARHDRSZ);
PG_RETURN_POINTER(res);
}
if (!q)
{
res = (text *) palloc(1 + VARHDRSZ);
- VARATT_SIZEP(res) = 1 + VARHDRSZ;
+ SET_VARSIZE(res, 1 + VARHDRSZ);
*((char *) VARDATA(res)) = 'T';
}
else
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);
}
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);
dwptr++;
}
- VARATT_SIZEP(out) = cptr - ((char *) out);
+ SET_VARSIZE(out, cptr - ((char *) out));
pfree(dw);
for (i = 0; i < rlen; i++)
wrd++;
}
- VARATT_SIZEP(out) = ptr - ((char *) out);
+ SET_VARSIZE(out, ptr - ((char *) out));
return out;
}
{
tsstat *stat = palloc(STATHDRSIZE);
- stat->len = STATHDRSIZE;
+ SET_VARSIZE(stat, STATHDRSIZE);
stat->size = 0;
stat->weight = 0;
PG_RETURN_POINTER(stat);
slen += STATSTRSIZE(stat);
totallen = CALCSTATSIZE(nentry, slen);
newstat = palloc(totallen);
- newstat->len = totallen;
+ SET_VARSIZE(newstat, totallen);
newstat->weight = stat->weight;
newstat->size = nentry;
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;
}
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");
elog(ERROR, "column isn't of tsvector type");
stat = palloc(STATHDRSIZE);
- stat->len = STATHDRSIZE;
+ SET_VARSIZE(stat, STATHDRSIZE);
stat->size = 0;
stat->weight = 0;
typedef struct
{
- int4 len;
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int4 size;
int4 weight;
char data[1];
#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
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);
}
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);
{
text *in = PG_GETARG_TEXT_P(1);
PRSTEXT prs;
- tsvector *out = NULL;
+ tsvector *out;
TSCfgInfo *cfg;
SET_FUNCOID();
{
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);
{
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);
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;
/*
* 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
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 ) )
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);
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--)
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);
}
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);
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);
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();
tres = palloc(reslen + VARHDRSZ);
memcpy(VARDATA(tres), resstr, reslen);
- VARATT_SIZEP(tres) = reslen + VARHDRSZ;
+ SET_VARSIZE(tres, reslen + VARHDRSZ);
PG_RETURN_TEXT_P(tres);
}
-<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.125 2007/02/01 19:10:24 momjian Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.126 2007/02/27 23:48:06 tgl Exp $ -->
<sect1 id="xfunc">
<title>User-Defined Functions</title>
* 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.
*/
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);
* 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.
*/
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);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.115 2007/02/09 03:35:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/heaptuple.c,v 1.116 2007/02/27 23:48:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*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)
*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)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.80 2007/01/05 22:19:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/indextuple.c,v 1.81 2007/02/27 23:48:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* 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'))
{
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.3 2007/01/05 22:19:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/common/reloptions.c,v 1.4 2007/02/27 23:48:06 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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)
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,
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 */
}
result = (StdRdOptions *) palloc(sizeof(StdRdOptions));
- VARATT_SIZEP(result) = sizeof(StdRdOptions);
+ SET_VARSIZE(result, sizeof(StdRdOptions));
result->fillfactor = fillfactor;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.70 2007/02/04 20:00:37 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/access/heap/tuptoaster.c,v 1.71 2007/02/27 23:48:07 tgl Exp $
*
*
* INTERFACE ROUTINES
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
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
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);
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);
* tuple.
*/
toast_action[i] = 'p';
- toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+ toast_sizes[i] = VARSIZE(toast_values[i]);
continue;
}
}
/*
* Remember the size of this attribute
*/
- toast_sizes[i] = VARATT_SIZE(new_value);
+ toast_sizes[i] = VARSIZE(new_value);
}
else
{
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;
}
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;
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;
}
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;
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
*/
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 =
/*
* 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
* 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");
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
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
/*
* 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++;
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! */
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
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++;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.35 2007/02/14 01:58:56 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.36 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
len = strlen(result) + VARHDRSZ;
retval = palloc(len);
- VARATT_SIZEP(retval) = len;
+ SET_VARSIZE(retval, len);
memcpy(VARDATA(retval), result, len - VARHDRSZ);
pfree(result);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.214 2007/02/27 01:11:25 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.215 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
result = (ArrayType *) palloc(nbytes);
- result->size = nbytes;
+ SET_VARSIZE(result, nbytes);
result->ndim = ndims;
result->dataoffset = dataoffset;
result->elemtype = element_type;
int len = buf.len + VARHDRSZ;
result = palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), buf.data, buf.len);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.84 2007/01/05 22:19:29 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/be-fsstubs.c,v 1.85 2007/02/27 23:48:07 tgl Exp $
*
* NOTES
* This should be moved to a more appropriate place. It is here
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);
}
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/libpq/pqformat.c,v 1.43 2007/01/05 22:19:29 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/libpq/pqformat.c,v 1.44 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* Insert correct length into bytea length word */
Assert(buf->len >= VARHDRSZ);
- VARATT_SIZEP(result) = buf->len;
+ SET_VARSIZE(result, buf->len);
return result;
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/large_object/inv_api.c,v 1.121 2007/01/05 22:19:38 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/large_object/inv_api.c,v 1.122 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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];
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
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
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.137 2007/01/05 22:19:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.138 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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;
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));
}
/*
}
/* 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;
* Copyright (c) 2003-2007, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.21 2007/01/05 22:19:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.22 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.136 2007/01/05 22:19:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.137 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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;
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;
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);
}
}
newarray = (ArrayType *) palloc(bytes);
- newarray->size = bytes;
+ SET_VARSIZE(newarray, bytes);
newarray->ndim = ndim;
newarray->dataoffset = dataoffset;
newarray->elemtype = elemtype;
* 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);
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);
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;
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;
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;
* this version handles 64 bit numbers and so can hold values up to
* $92,233,720,368,547,758.07.
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.69 2007/01/03 01:19:50 darcy Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.70 2007/02/27 23:48:07 tgl Exp $
*/
#include "postgres.h"
/* 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);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/char.c,v 1.46 2007/01/05 22:19:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/char.c,v 1.47 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
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);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.128 2007/02/16 03:39:44 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.129 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
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);
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);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/datum.c,v 1.33 2007/01/05 22:19:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/datum.c,v 1.34 2007/02/27 23:48:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
(errcode(ERRCODE_DATA_EXCEPTION),
errmsg("invalid Datum pointer")));
- size = (Size) VARATT_SIZE(s);
+ size = (Size) VARSIZE(s);
}
else if (typLen == -2)
{
* Copyright (c) 2002-2007, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.10 2007/01/05 22:19:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.11 2007/02/27 23:48:07 tgl Exp $
*
*/
}
}
- VARATT_SIZEP(result) = strlen(VARDATA(result)) + VARHDRSZ;
+ SET_VARSIZE(result, strlen(VARDATA(result)) + VARHDRSZ);
PG_RETURN_TEXT_P(result);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/encode.c,v 1.18 2007/01/05 22:19:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/encode.c,v 1.19 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
}
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);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.148 2007/01/20 21:47:10 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.149 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
result = (text *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
result = (text *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
/* -----------------------------------------------------------------------
* formatting.c
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.128 2007/02/17 03:11:32 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/formatting.c,v 1.129 2007/02/27 23:48:08 tgl Exp $
*
*
* Portions Copyright (c) 1999-2007, PostgreSQL Global Development Group
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;
} \
\
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)
* Author: Andreas Pflug <pgadmin@pse-consulting.de>
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.15 2007/02/01 19:10:28 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/genfile.c,v 1.16 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
(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);
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));
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.94 2007/01/05 22:19:40 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/geo_ops.c,v 1.95 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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])))
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);
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])))
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++)
result = (PATH *) palloc(size);
- result->size = size;
+ SET_VARSIZE(result, size);
result->npts = (p1->npts + p2->npts);
result->closed = p1->closed;
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++)
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;
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;
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;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.78 2007/02/01 19:10:28 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.79 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* 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;
(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;
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);
}
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);
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.64 2007/02/01 19:10:28 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/int8.c,v 1.65 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
result = (text *) palloc(VARHDRSZ + len);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, VARHDRSZ + len);
memcpy(VARDATA(result), s, len);
pfree(s);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/like.c,v 1.67 2007/01/05 22:19:41 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/like.c,v 1.68 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
}
- VARATT_SIZEP(result) = r - ((char *) result);
+ SET_VARSIZE(result, r - ((char *) result));
PG_RETURN_BYTEA_P(result);
}
* Copyright (c) 1996-2007, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.14 2007/01/05 22:19:41 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/like_match.c,v 1.15 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
}
- VARATT_SIZEP(result) = r - ((char *) result);
+ SET_VARSIZE(result, r - ((char *) result));
return result;
}
/*
* PostgreSQL type definitions for MAC addresses.
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/mac.c,v 1.36 2006/01/11 08:43:12 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/mac.c,v 1.37 2007/02/27 23:48:08 tgl Exp $
*/
#include "postgres.h"
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);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.149 2007/01/05 22:19:41 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.150 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
}
/*
* PostgreSQL type definitions for the INET and CIDR types.
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.67 2007/01/02 22:21:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.68 2007/02/27 23:48:08 tgl Exp $
*
* Jon Postel RIP 16 Oct 1998
*/
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;
/* 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++)
/* 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);
}
/* 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);
}
/* 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);
}
/* 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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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;
}
* Copyright (c) 1998-2007, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.100 2007/02/17 00:55:57 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.101 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#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);
*/
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);
}
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);
/*
* 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);
/*
* 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)
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);
}
* 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
{
result = (text *) palloc(VARHDRSZ + len);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, VARHDRSZ + len);
memcpy(VARDATA(result), s, len);
pfree(s);
/* 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,
{
result = (Numeric) palloc(NUMERIC_HDRSZ);
- result->varlen = NUMERIC_HDRSZ;
+ SET_VARSIZE(result, NUMERIC_HDRSZ);
result->n_weight = 0;
result->n_sign_dscale = NUMERIC_NAN;
/* 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);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.70 2007/01/05 22:19:41 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.71 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* 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;
(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;
result = (text *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), str, (len - VARHDRSZ));
pfree(str);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.69 2007/02/08 18:19:33 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/oracle_compat.c,v 1.70 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
Assert(nbytes <= (size_t) (ncodes * MB_CUR_MAX));
- VARATT_SIZEP(result) = nbytes + VARHDRSZ;
+ SET_VARSIZE(result, nbytes + VARHDRSZ);
return result;
}
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;
}
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);
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);
ptr1 += mlen;
}
- VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
+ SET_VARSIZE(ret, ptr_ret - (char *) ret);
PG_RETURN_TEXT_P(ret);
}
ptr2 = VARDATA(string2);
}
- VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
+ SET_VARSIZE(ret, ptr_ret - (char *) ret);
PG_RETURN_TEXT_P(ret);
}
/* 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;
}
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);
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
********************************************************************/
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);
result = (text *) palloc(tlen);
- VARATT_SIZEP(result) = tlen;
+ SET_VARSIZE(result, tlen);
cp = VARDATA(result);
for (i = 0; i < count; i++)
{
* PGLZ_Header is defined as
*
* typedef struct PGLZ_Header {
- * int32 varsize;
+ * int32 vl_len_;
* int32 rawsize;
* }
*
* 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.
*
* Copyright (c) 1999-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.24 2007/01/20 01:08:42 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.25 2007/02/27 23:48:08 tgl Exp $
* ----------
*/
#include "postgres.h"
/*
* 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;
}
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)
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.38 2007/02/07 23:11:29 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.39 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.21 2007/01/05 22:19:41 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/quote.c,v 1.22 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
}
*cp2++ = '\'';
- VARATT_SIZEP(result) = cp2 - ((char *) result);
+ SET_VARSIZE(result, cp2 - ((char *) result));
PG_RETURN_TEXT_P(result);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.68 2007/01/05 22:19:41 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/regexp.c,v 1.69 2007/02/27 23:48:08 tgl Exp $
*
* Alistair Crooks added the code for the regex caching
* agc - cached the regular expressions used - there's a good chance
*r++ = ')';
*r++ = '$';
- VARATT_SIZEP(result) = r - ((char *) result);
+ SET_VARSIZE(result, r - ((char *) result));
PG_RETURN_TEXT_P(result);
}
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.251 2007/02/23 21:59:44 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.252 2007/02/27 23:48:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
tlen = slen + VARHDRSZ;
result = (text *) palloc(tlen);
- VARATT_SIZEP(result) = tlen;
+ SET_VARSIZE(result, tlen);
memcpy(VARDATA(result), str, slen);
pfree(str);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.227 2007/02/22 22:00:25 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.228 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.173 2007/02/19 17:41:39 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.174 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
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);
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);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.52 2007/01/05 22:19:42 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/varbit.c,v 1.53 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
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));
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),
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);
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));
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));
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 */
/* 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
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? */
len = VARSIZE(arg1);
result = (VarBit *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = bitlen1;
p1 = VARBITS(arg1);
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);
len = VARSIZE(arg1);
result = (VarBit *) palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
VARBITLEN(result) = bitlen1;
p1 = VARBITS(arg1);
bits8 mask;
result = (VarBit *) palloc(VARSIZE(arg));
- VARATT_SIZEP(result) = VARSIZE(arg);
+ SET_VARSIZE(result, VARSIZE(arg));
VARBITLEN(result) = VARBITLEN(arg);
p = VARBITS(arg);
Int32GetDatum(-shft)));
result = (VarBit *) palloc(VARSIZE(arg));
- VARATT_SIZEP(result) = VARSIZE(arg);
+ SET_VARSIZE(result, VARSIZE(arg));
VARBITLEN(result) = VARBITLEN(arg);
r = VARBITS(result);
Int32GetDatum(-shft)));
result = (VarBit *) palloc(VARSIZE(arg));
- VARATT_SIZEP(result) = VARSIZE(arg);
+ SET_VARSIZE(result, VARSIZE(arg));
VARBITLEN(result) = VARBITLEN(arg);
r = VARBITS(result);
rlen = VARBITTOTALLEN(typmod);
result = (VarBit *) palloc(rlen);
- VARATT_SIZEP(result) = rlen;
+ SET_VARSIZE(result, rlen);
VARBITLEN(result) = typmod;
r = VARBITS(result);
rlen = VARBITTOTALLEN(typmod);
result = (VarBit *) palloc(rlen);
- VARATT_SIZEP(result) = rlen;
+ SET_VARSIZE(result, rlen);
VARBITLEN(result) = typmod;
r = VARBITS(result);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.121 2007/01/05 22:19:42 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.122 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
result = (BpChar *) palloc(maxlen + VARHDRSZ);
- VARATT_SIZEP(result) = maxlen + VARHDRSZ;
+ SET_VARSIZE(result, maxlen + VARHDRSZ);
r = VARDATA(result);
memcpy(r, s, len);
s = VARDATA(source);
result = palloc(maxlen);
- VARATT_SIZEP(result) = maxlen;
+ SET_VARSIZE(result, maxlen);
r = VARDATA(result);
memcpy(r, s, len - VARHDRSZ);
result = (BpChar *) palloc(VARHDRSZ + 1);
- VARATT_SIZEP(result) = VARHDRSZ + 1;
+ SET_VARSIZE(result, VARHDRSZ + 1);
*(VARDATA(result)) = c;
PG_RETURN_BPCHAR_P(result);
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);
}
}
result = (VarChar *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, len + VARHDRSZ);
memcpy(VARDATA(result), s, len);
return result;
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);
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.154 2007/01/05 22:19:42 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.155 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
byte += VARHDRSZ;
result = (bytea *) palloc(byte);
- VARATT_SIZEP(result) = byte; /* set varlena length */
+ SET_VARSIZE(result, byte);
tp = inputText;
rp = VARDATA(result);
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);
}
len = strlen(inputText);
result = (text *) palloc(len + VARHDRSZ);
- VARATT_SIZEP(result) = len + VARHDRSZ;
+ SET_VARSIZE(result, len + VARHDRSZ);
memcpy(VARDATA(result), inputText, len);
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);
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);
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))
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);
#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);
/* 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 */
*
* IDENTIFICATION
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/version.c,v 1.14 2007/01/20 01:08:42 neilc Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/version.c,v 1.15 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.31 2007/02/16 18:37:43 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.32 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
len = strlen(s);
vardata = palloc(len + VARHDRSZ);
- VARATT_SIZEP(vardata) = len + VARHDRSZ;
+ SET_VARSIZE(vardata, len + VARHDRSZ);
memcpy(VARDATA(vardata), s, len);
/*
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);
nbytes = strlen(newstr);
result = palloc(nbytes + VARHDRSZ);
- VARATT_SIZEP(result) = nbytes + VARHDRSZ;
+ SET_VARSIZE(result, nbytes + VARHDRSZ);
memcpy(VARDATA(result), newstr, nbytes);
}
len = buf->len + VARHDRSZ;
result = palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), buf->data, buf->len);
return result;
len = strlen(string) + VARHDRSZ;
result = palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), string, len - VARHDRSZ);
return result;
len = xmlBufferLength(buf) + VARHDRSZ;
result = palloc(len);
- VARATT_SIZEP(result) = len;
+ SET_VARSIZE(result, len);
memcpy(VARDATA(result), xmlBufferContent(buf), len - VARHDRSZ);
return result;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.255 2007/01/25 02:17:26 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.256 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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
/* 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 */
* (currently mule internal code (mic) is used)
* Tatsuo Ishii
*
- * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.61 2006/12/24 00:57:48 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/mb/mbutils.c,v 1.62 2007/02/27 23:48:09 tgl Exp $
*/
#include "postgres.h"
*/
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)
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.91 2007/02/09 03:35:34 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/access/htup.h,v 1.92 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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 */
} 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) \
( \
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/access/tupmacs.h,v 1.31 2007/01/05 22:19:51 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/access/tupmacs.h,v 1.32 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
) \
: (((attlen) == -1) ? \
( \
- (cur_offset) + VARATT_SIZE(DatumGetPointer(attval)) \
+ (cur_offset) + VARSIZE(DatumGetPointer(attval)) \
) \
: \
( \
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/c.h,v 1.218 2007/02/05 04:22:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/c.h,v 1.219 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
* 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];
};
*/
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;
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;
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1995, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/postgres.h,v 1.76 2007/01/05 22:19:50 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/postgres.h,v 1.77 2007/02/27 23:48:09 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/* ----------------
* 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
{
#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))
/* ----------------------------------------------------------------
* 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
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/array.h,v 1.62 2007/01/05 22:19:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/array.h,v 1.63 2007/02/27 23:48:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* 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 */
*
* 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)
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/geo_decls.h,v 1.52 2007/01/05 22:19:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/geo_decls.h,v 1.53 2007/02/27 23:48:10 tgl Exp $
*
* NOTE
* These routines do *not* use the float types from adt/.
*-------------------------------------------------------------------*/
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 */
*-------------------------------------------------------------------*/
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 */
*
* Copyright (c) 1998-2007, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/include/utils/numeric.h,v 1.23 2007/01/05 22:19:59 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/numeric.h,v 1.24 2007/02/27 23:48:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
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) */
typedef NumericData *Numeric;
-#define NUMERIC_HDRSZ (sizeof(int32) + sizeof(int16) + sizeof(uint16))
+#define NUMERIC_HDRSZ (VARHDRSZ + sizeof(int16) + sizeof(uint16))
/*
*
* Definitions for the builtin LZ compressor
*
- * $PostgreSQL: pgsql/src/include/utils/pg_lzcompress.h,v 1.13 2006/10/05 23:33:33 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/utils/pg_lzcompress.h,v 1.14 2007/02/27 23:48:10 tgl Exp $
* ----------
*/
* 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;
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.97 2007/02/14 01:58:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/utils/rel.h,v 1.98 2007/02/27 23:48:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
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;
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/utils/varbit.h,v 1.25 2007/01/05 22:20:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/utils/varbit.h,v 1.26 2007/02/27 23:48:10 tgl Exp $
*
*-------------------------------------------------------------------------
*/
*/
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;
-/* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.16 2006/09/27 16:19:42 tgl Exp $ */
+/* $PostgreSQL: pgsql/src/tutorial/funcs.c,v 1.17 2007/02/27 23:48:10 tgl Exp $ */
/******************************************************************************
These are user-defined functions that can be bound to a Postgres backend
*/
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.
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;
-/* $PostgreSQL: pgsql/src/tutorial/funcs_new.c,v 1.12 2006/09/27 16:19:42 tgl Exp $ */
+/* $PostgreSQL: pgsql/src/tutorial/funcs_new.c,v 1.13 2007/02/27 23:48:10 tgl Exp $ */
/******************************************************************************
These are user-defined functions that can be bound to a Postgres backend
*/
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.
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);