diff options
Diffstat (limited to 'src/backend/utils')
-rw-r--r-- | src/backend/utils/adt/arrayfuncs.c | 84 | ||||
-rw-r--r-- | src/backend/utils/adt/datum.c | 6 | ||||
-rw-r--r-- | src/backend/utils/adt/network.c | 104 | ||||
-rw-r--r-- | src/backend/utils/adt/pg_lzcompress.c | 4 | ||||
-rw-r--r-- | src/backend/utils/adt/varchar.c | 160 | ||||
-rw-r--r-- | src/backend/utils/adt/varlena.c | 280 | ||||
-rw-r--r-- | src/backend/utils/adt/xml.c | 6 | ||||
-rw-r--r-- | src/backend/utils/fmgr/fmgr.c | 17 | ||||
-rw-r--r-- | src/backend/utils/init/flatfiles.c | 6 |
9 files changed, 335 insertions, 332 deletions
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 38a86452e3f..991c7a46f7c 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.138 2007/03/27 23:21:10 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.139 2007/04/06 04:21:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -805,8 +805,8 @@ ReadArrayStr(char *arrayStr, /* let's just make sure data is not toasted */ if (typlen == -1) values[i] = PointerGetDatum(PG_DETOAST_DATUM(values[i])); - totbytes = att_addlength(totbytes, typlen, values[i]); - totbytes = att_align(totbytes, typalign); + totbytes = att_addlength_datum(totbytes, typlen, values[i]); + totbytes = att_align_nominal(totbytes, typalign); /* check for overflow of total request */ if (!AllocSizeIsValid(totbytes)) ereport(ERROR, @@ -1011,8 +1011,8 @@ array_out(PG_FUNCTION_ARGS) itemvalue = fetch_att(p, typbyval, typlen); values[i] = OutputFunctionCall(&my_extra->proc, itemvalue); - p = att_addlength(p, typlen, PointerGetDatum(p)); - p = (char *) att_align(p, typalign); + p = att_addlength_pointer(p, typlen, p); + p = (char *) att_align_nominal(p, typalign); /* count data plus backslashes; detect chars needing quotes */ if (values[i][0] == '\0') @@ -1399,8 +1399,8 @@ ReadArrayBinary(StringInfo buf, /* let's just make sure data is not toasted */ if (typlen == -1) values[i] = PointerGetDatum(PG_DETOAST_DATUM(values[i])); - totbytes = att_addlength(totbytes, typlen, values[i]); - totbytes = att_align(totbytes, typalign); + totbytes = att_addlength_datum(totbytes, typlen, values[i]); + totbytes = att_align_nominal(totbytes, typalign); /* check for overflow of total request */ if (!AllocSizeIsValid(totbytes)) ereport(ERROR, @@ -1512,8 +1512,8 @@ array_send(PG_FUNCTION_ARGS) VARSIZE(outputbytes) - VARHDRSZ); pfree(outputbytes); - p = att_addlength(p, typlen, PointerGetDatum(p)); - p = (char *) att_align(p, typalign); + p = att_addlength_pointer(p, typlen, p); + p = (char *) att_align_nominal(p, typalign); } /* advance bitmap pointer if any */ @@ -2108,8 +2108,8 @@ array_set(ArrayType *array, olditemlen = 0; else { - olditemlen = att_addlength(0, elmlen, PointerGetDatum(elt_ptr)); - olditemlen = att_align(olditemlen, elmalign); + olditemlen = att_addlength_pointer(0, elmlen, elt_ptr); + olditemlen = att_align_nominal(olditemlen, elmalign); } lenafter = (int) (olddatasize - lenbefore - olditemlen); } @@ -2118,8 +2118,8 @@ array_set(ArrayType *array, newitemlen = 0; else { - newitemlen = att_addlength(0, elmlen, dataValue); - newitemlen = att_align(newitemlen, elmalign); + newitemlen = att_addlength_datum(0, elmlen, dataValue); + newitemlen = att_align_nominal(newitemlen, elmalign); } newsize = overheadlen + lenbefore + newitemlen + lenafter; @@ -2639,8 +2639,8 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType, else { elt = fetch_att(s, inp_typbyval, inp_typlen); - s = att_addlength(s, inp_typlen, elt); - s = (char *) att_align(s, inp_typalign); + s = att_addlength_datum(s, inp_typlen, elt); + s = (char *) att_align_nominal(s, inp_typalign); fcinfo->arg[0] = elt; fcinfo->argnull[0] = false; } @@ -2679,8 +2679,8 @@ array_map(FunctionCallInfo fcinfo, Oid inpType, Oid retType, if (typlen == -1) values[i] = PointerGetDatum(PG_DETOAST_DATUM(values[i])); /* Update total result size */ - nbytes = att_addlength(nbytes, typlen, values[i]); - nbytes = att_align(nbytes, typalign); + nbytes = att_addlength_datum(nbytes, typlen, values[i]); + nbytes = att_align_nominal(nbytes, typalign); /* check for overflow of total request */ if (!AllocSizeIsValid(nbytes)) ereport(ERROR, @@ -2827,8 +2827,8 @@ construct_md_array(Datum *elems, /* make sure data is not toasted */ if (elmlen == -1) elems[i] = PointerGetDatum(PG_DETOAST_DATUM(elems[i])); - nbytes = att_addlength(nbytes, elmlen, elems[i]); - nbytes = att_align(nbytes, elmalign); + nbytes = att_addlength_datum(nbytes, elmlen, elems[i]); + nbytes = att_align_nominal(nbytes, elmalign); /* check for overflow of total request */ if (!AllocSizeIsValid(nbytes)) ereport(ERROR, @@ -2947,8 +2947,8 @@ deconstruct_array(ArrayType *array, elems[i] = fetch_att(p, elmbyval, elmlen); if (nulls) nulls[i] = false; - p = att_addlength(p, elmlen, PointerGetDatum(p)); - p = (char *) att_align(p, elmalign); + p = att_addlength_pointer(p, elmlen, p); + p = (char *) att_align_nominal(p, elmalign); } /* advance bitmap pointer if any */ @@ -3064,8 +3064,8 @@ array_eq(PG_FUNCTION_ARGS) { isnull1 = false; elt1 = fetch_att(ptr1, typbyval, typlen); - ptr1 = att_addlength(ptr1, typlen, PointerGetDatum(ptr1)); - ptr1 = (char *) att_align(ptr1, typalign); + ptr1 = att_addlength_pointer(ptr1, typlen, ptr1); + ptr1 = (char *) att_align_nominal(ptr1, typalign); } if (bitmap2 && (*bitmap2 & bitmask) == 0) @@ -3077,8 +3077,8 @@ array_eq(PG_FUNCTION_ARGS) { isnull2 = false; elt2 = fetch_att(ptr2, typbyval, typlen); - ptr2 = att_addlength(ptr2, typlen, PointerGetDatum(ptr2)); - ptr2 = (char *) att_align(ptr2, typalign); + ptr2 = att_addlength_pointer(ptr2, typlen, ptr2); + ptr2 = (char *) att_align_nominal(ptr2, typalign); } /* advance bitmap pointers if any */ @@ -3265,8 +3265,8 @@ array_cmp(FunctionCallInfo fcinfo) { isnull1 = false; elt1 = fetch_att(ptr1, typbyval, typlen); - ptr1 = att_addlength(ptr1, typlen, PointerGetDatum(ptr1)); - ptr1 = (char *) att_align(ptr1, typalign); + ptr1 = att_addlength_pointer(ptr1, typlen, ptr1); + ptr1 = (char *) att_align_nominal(ptr1, typalign); } if (bitmap2 && (*bitmap2 & bitmask) == 0) @@ -3278,8 +3278,8 @@ array_cmp(FunctionCallInfo fcinfo) { isnull2 = false; elt2 = fetch_att(ptr2, typbyval, typlen); - ptr2 = att_addlength(ptr2, typlen, PointerGetDatum(ptr2)); - ptr2 = (char *) att_align(ptr2, typalign); + ptr2 = att_addlength_pointer(ptr2, typlen, ptr2); + ptr2 = (char *) att_align_nominal(ptr2, typalign); } /* advance bitmap pointers if any */ @@ -3468,8 +3468,8 @@ array_contain_compare(ArrayType *array1, ArrayType *array2, bool matchall, { isnull1 = false; elt1 = fetch_att(ptr1, typbyval, typlen); - ptr1 = att_addlength(ptr1, typlen, PointerGetDatum(ptr1)); - ptr1 = (char *) att_align(ptr1, typalign); + ptr1 = att_addlength_pointer(ptr1, typlen, ptr1); + ptr1 = (char *) att_align_nominal(ptr1, typalign); } /* advance bitmap pointer if any */ @@ -3667,14 +3667,14 @@ ArrayCastAndSet(Datum src, store_att_byval(dest, src, typlen); else memmove(dest, DatumGetPointer(src), typlen); - inc = att_align(typlen, typalign); + inc = att_align_nominal(typlen, typalign); } else { Assert(!typbyval); - inc = att_addlength(0, typlen, src); + inc = att_addlength_datum(0, typlen, src); memmove(dest, DatumGetPointer(src), inc); - inc = att_align(inc, typalign); + inc = att_align_nominal(inc, typalign); } return inc; @@ -3700,7 +3700,7 @@ array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems, /* easy if fixed-size elements and no NULLs */ if (typlen > 0 && !nullbitmap) - return ptr + nitems * ((Size) att_align(typlen, typalign)); + return ptr + nitems * ((Size) att_align_nominal(typlen, typalign)); /* seems worth having separate loops for NULL and no-NULLs cases */ if (nullbitmap) @@ -3712,8 +3712,8 @@ array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems, { if (*nullbitmap & bitmask) { - ptr = att_addlength(ptr, typlen, PointerGetDatum(ptr)); - ptr = (char *) att_align(ptr, typalign); + ptr = att_addlength_pointer(ptr, typlen, ptr); + ptr = (char *) att_align_nominal(ptr, typalign); } bitmask <<= 1; if (bitmask == 0x100) @@ -3727,8 +3727,8 @@ array_seek(char *ptr, int offset, bits8 *nullbitmap, int nitems, { for (i = 0; i < nitems; i++) { - ptr = att_addlength(ptr, typlen, PointerGetDatum(ptr)); - ptr = (char *) att_align(ptr, typalign); + ptr = att_addlength_pointer(ptr, typlen, ptr); + ptr = (char *) att_align_nominal(ptr, typalign); } } return ptr; @@ -3883,7 +3883,7 @@ array_slice_size(char *arraydataptr, bits8 *arraynullsptr, /* Pretty easy for fixed element length without nulls ... */ if (typlen > 0 && !arraynullsptr) - return ArrayGetNItems(ndim, span) * att_align(typlen, typalign); + return ArrayGetNItems(ndim, span) * att_align_nominal(typlen, typalign); /* Else gotta do it the hard way */ src_offset = ArrayGetOffset(ndim, dim, lb, st); @@ -3904,8 +3904,8 @@ array_slice_size(char *arraydataptr, bits8 *arraynullsptr, } if (!array_get_isnull(arraynullsptr, src_offset)) { - inc = att_addlength(0, typlen, PointerGetDatum(ptr)); - inc = att_align(inc, typalign); + inc = att_addlength_pointer(0, typlen, ptr); + inc = att_align_nominal(inc, typalign); ptr += inc; count += inc; } diff --git a/src/backend/utils/adt/datum.c b/src/backend/utils/adt/datum.c index 21e7cc55412..c025de61f74 100644 --- a/src/backend/utils/adt/datum.c +++ b/src/backend/utils/adt/datum.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/datum.c,v 1.34 2007/02/27 23:48:07 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/datum.c,v 1.35 2007/04/06 04:21:42 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -47,7 +47,7 @@ * Find the "real" size of a datum, given the datum value, * whether it is a "by value", and the declared type length. * - * This is essentially an out-of-line version of the att_addlength() + * This is essentially an out-of-line version of the att_addlength_datum() * macro in access/tupmacs.h. We do a tad more error checking though. *------------------------------------------------------------------------- */ @@ -79,7 +79,7 @@ datumGetSize(Datum value, bool typByVal, int typLen) (errcode(ERRCODE_DATA_EXCEPTION), errmsg("invalid Datum pointer"))); - size = (Size) VARSIZE(s); + size = (Size) VARSIZE_ANY(s); } else if (typLen == -2) { diff --git a/src/backend/utils/adt/network.c b/src/backend/utils/adt/network.c index 88fa427450f..c1dadfbcc1b 100644 --- a/src/backend/utils/adt/network.c +++ b/src/backend/utils/adt/network.c @@ -1,7 +1,7 @@ /* * PostgreSQL type definitions for the INET and CIDR types. * - * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.68 2007/02/27 23:48:08 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.69 2007/04/06 04:21:43 tgl Exp $ * * Jon Postel RIP 16 Oct 1998 */ @@ -30,23 +30,38 @@ static int ip_addrsize(inet *inetptr); static inet *internal_inetpl(inet *ip, int64 addend); /* - * Access macros. + * Access macros. We use VARDATA_ANY so that we can process short-header + * varlena values without detoasting them. This requires a trick: + * VARDATA_ANY assumes the varlena header is already filled in, which is + * not the case when constructing a new value (until SET_INET_VARSIZE is + * called, which we typically can't do till the end). Therefore, we + * always initialize the newly-allocated value to zeroes (using palloc0). + * A zero length word will look like the not-1-byte case to VARDATA_ANY, + * and so we correctly construct an uncompressed value. + * + * Note that ip_maxbits() and SET_INET_VARSIZE() require + * the family field to be set correctly. */ #define ip_family(inetptr) \ - (((inet_struct *)VARDATA(inetptr))->family) + (((inet_struct *) VARDATA_ANY(inetptr))->family) #define ip_bits(inetptr) \ - (((inet_struct *)VARDATA(inetptr))->bits) + (((inet_struct *) VARDATA_ANY(inetptr))->bits) #define ip_addr(inetptr) \ - (((inet_struct *)VARDATA(inetptr))->ipaddr) + (((inet_struct *) VARDATA_ANY(inetptr))->ipaddr) #define ip_maxbits(inetptr) \ (ip_family(inetptr) == PGSQL_AF_INET ? 32 : 128) +#define SET_INET_VARSIZE(dst) \ + SET_VARSIZE(dst, VARHDRSZ + offsetof(inet_struct, ipaddr) + \ + ip_addrsize(dst)) + + /* - * Return the number of bytes of storage needed for this data type. + * Return the number of bytes of address storage needed for this data type. */ static int ip_addrsize(inet *inetptr) @@ -71,7 +86,7 @@ network_in(char *src, bool is_cidr) int bits; inet *dst; - dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + dst = (inet *) palloc0(sizeof(inet)); /* * First, check to see if this is an IPv6 or IPv4 address. IPv6 addresses @@ -105,10 +120,8 @@ network_in(char *src, bool is_cidr) errdetail("Value has bits set to right of mask."))); } - SET_VARSIZE(dst, VARHDRSZ + - ((char *) ip_addr(dst) - (char *) VARDATA(dst)) + - ip_addrsize(dst)); ip_bits(dst) = bits; + SET_INET_VARSIZE(dst); return dst; } @@ -194,7 +207,7 @@ network_recv(StringInfo buf, bool is_cidr) i; /* make sure any unused bits in a CIDR value are zeroed */ - addr = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + addr = (inet *) palloc0(sizeof(inet)); ip_family(addr) = pq_getmsgbyte(buf); if (ip_family(addr) != PGSQL_AF_INET && @@ -220,9 +233,6 @@ network_recv(StringInfo buf, bool is_cidr) /* translator: %s is inet or cidr */ errmsg("invalid length in external \"%s\" value", is_cidr ? "cidr" : "inet"))); - SET_VARSIZE(addr, VARHDRSZ + - ((char *) ip_addr(addr) - (char *) VARDATA(addr)) + - ip_addrsize(addr)); addrptr = (char *) ip_addr(addr); for (i = 0; i < nb; i++) @@ -240,6 +250,8 @@ network_recv(StringInfo buf, bool is_cidr) errdetail("Value has bits set to right of mask."))); } + SET_INET_VARSIZE(addr); + return addr; } @@ -348,8 +360,8 @@ inet_to_cidr(PG_FUNCTION_ARGS) elog(ERROR, "invalid inet bit length: %d", bits); /* clone the original data */ - dst = (inet *) palloc(VARSIZE(src)); - memcpy(dst, src, VARSIZE(src)); + dst = (inet *) palloc(VARSIZE_ANY(src)); + memcpy(dst, src, VARSIZE_ANY(src)); /* zero out any bits to the right of the netmask */ byte = bits / 8; @@ -387,8 +399,8 @@ inet_set_masklen(PG_FUNCTION_ARGS) errmsg("invalid mask length: %d", bits))); /* clone the original data */ - dst = (inet *) palloc(VARSIZE(src)); - memcpy(dst, src, VARSIZE(src)); + dst = (inet *) palloc(VARSIZE_ANY(src)); + memcpy(dst, src, VARSIZE_ANY(src)); ip_bits(dst) = bits; @@ -414,8 +426,8 @@ cidr_set_masklen(PG_FUNCTION_ARGS) errmsg("invalid mask length: %d", bits))); /* clone the original data */ - dst = (inet *) palloc(VARSIZE(src)); - memcpy(dst, src, VARSIZE(src)); + dst = (inet *) palloc(VARSIZE_ANY(src)); + memcpy(dst, src, VARSIZE_ANY(src)); ip_bits(dst) = bits; @@ -546,7 +558,7 @@ hashinet(PG_FUNCTION_ARGS) int addrsize = ip_addrsize(addr); /* XXX this assumes there are no pad bytes in the data structure */ - return hash_any((unsigned char *) VARDATA(addr), addrsize + 2); + return hash_any((unsigned char *) VARDATA_ANY(addr), addrsize + 2); } /* @@ -762,7 +774,7 @@ network_broadcast(PG_FUNCTION_ARGS) *b; /* make sure any unused bits are zeroed */ - dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + dst = (inet *) palloc0(sizeof(inet)); if (ip_family(ip) == PGSQL_AF_INET) maxbytes = 4; @@ -793,9 +805,7 @@ network_broadcast(PG_FUNCTION_ARGS) ip_family(dst) = ip_family(ip); ip_bits(dst) = ip_bits(ip); - SET_VARSIZE(dst, VARHDRSZ + - ((char *) ip_addr(dst) - (char *) VARDATA(dst)) + - ip_addrsize(dst)); + SET_INET_VARSIZE(dst); PG_RETURN_INET_P(dst); } @@ -812,7 +822,7 @@ network_network(PG_FUNCTION_ARGS) *b; /* make sure any unused bits are zeroed */ - dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + dst = (inet *) palloc0(sizeof(inet)); bits = ip_bits(ip); a = ip_addr(ip); @@ -838,9 +848,7 @@ network_network(PG_FUNCTION_ARGS) ip_family(dst) = ip_family(ip); ip_bits(dst) = ip_bits(ip); - SET_VARSIZE(dst, VARHDRSZ + - ((char *) ip_addr(dst) - (char *) VARDATA(dst)) + - ip_addrsize(dst)); + SET_INET_VARSIZE(dst); PG_RETURN_INET_P(dst); } @@ -856,7 +864,7 @@ network_netmask(PG_FUNCTION_ARGS) unsigned char *b; /* make sure any unused bits are zeroed */ - dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + dst = (inet *) palloc0(sizeof(inet)); bits = ip_bits(ip); b = ip_addr(dst); @@ -881,9 +889,7 @@ network_netmask(PG_FUNCTION_ARGS) ip_family(dst) = ip_family(ip); ip_bits(dst) = ip_maxbits(ip); - SET_VARSIZE(dst, VARHDRSZ + - ((char *) ip_addr(dst) - (char *) VARDATA(dst)) + - ip_addrsize(dst)); + SET_INET_VARSIZE(dst); PG_RETURN_INET_P(dst); } @@ -900,7 +906,7 @@ network_hostmask(PG_FUNCTION_ARGS) unsigned char *b; /* make sure any unused bits are zeroed */ - dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + dst = (inet *) palloc0(sizeof(inet)); if (ip_family(ip) == PGSQL_AF_INET) maxbytes = 4; @@ -930,9 +936,7 @@ network_hostmask(PG_FUNCTION_ARGS) ip_family(dst) = ip_family(ip); ip_bits(dst) = ip_maxbits(ip); - SET_VARSIZE(dst, VARHDRSZ + - ((char *) ip_addr(dst) - (char *) VARDATA(dst)) + - ip_addrsize(dst)); + SET_INET_VARSIZE(dst); PG_RETURN_INET_P(dst); } @@ -1259,7 +1263,7 @@ inetnot(PG_FUNCTION_ARGS) inet *ip = PG_GETARG_INET_P(0); inet *dst; - dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + dst = (inet *) palloc0(sizeof(inet)); { int nb = ip_addrsize(ip); @@ -1272,9 +1276,7 @@ inetnot(PG_FUNCTION_ARGS) ip_bits(dst) = ip_bits(ip); ip_family(dst) = ip_family(ip); - SET_VARSIZE(dst, VARHDRSZ + - ((char *) ip_addr(dst) - (char *) VARDATA(dst)) + - ip_addrsize(dst)); + SET_INET_VARSIZE(dst); PG_RETURN_INET_P(dst); } @@ -1287,7 +1289,7 @@ inetand(PG_FUNCTION_ARGS) inet *ip2 = PG_GETARG_INET_P(1); inet *dst; - dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + dst = (inet *) palloc0(sizeof(inet)); if (ip_family(ip) != ip_family(ip2)) ereport(ERROR, @@ -1306,9 +1308,7 @@ inetand(PG_FUNCTION_ARGS) ip_bits(dst) = Max(ip_bits(ip), ip_bits(ip2)); ip_family(dst) = ip_family(ip); - SET_VARSIZE(dst, VARHDRSZ + - ((char *) ip_addr(dst) - (char *) VARDATA(dst)) + - ip_addrsize(dst)); + SET_INET_VARSIZE(dst); PG_RETURN_INET_P(dst); } @@ -1321,7 +1321,7 @@ inetor(PG_FUNCTION_ARGS) inet *ip2 = PG_GETARG_INET_P(1); inet *dst; - dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + dst = (inet *) palloc0(sizeof(inet)); if (ip_family(ip) != ip_family(ip2)) ereport(ERROR, @@ -1340,9 +1340,7 @@ inetor(PG_FUNCTION_ARGS) ip_bits(dst) = Max(ip_bits(ip), ip_bits(ip2)); ip_family(dst) = ip_family(ip); - SET_VARSIZE(dst, VARHDRSZ + - ((char *) ip_addr(dst) - (char *) VARDATA(dst)) + - ip_addrsize(dst)); + SET_INET_VARSIZE(dst); PG_RETURN_INET_P(dst); } @@ -1353,7 +1351,7 @@ internal_inetpl(inet *ip, int64 addend) { inet *dst; - dst = (inet *) palloc0(VARHDRSZ + sizeof(inet_struct)); + dst = (inet *) palloc0(sizeof(inet)); { int nb = ip_addrsize(ip); @@ -1391,12 +1389,10 @@ internal_inetpl(inet *ip, int64 addend) (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("result is out of range"))); } - ip_bits(dst) = ip_bits(ip); + ip_bits(dst) = ip_bits(ip); ip_family(dst) = ip_family(ip); - SET_VARSIZE(dst, VARHDRSZ + - ((char *) ip_addr(dst) - (char *) VARDATA(dst)) + - ip_addrsize(dst)); + SET_INET_VARSIZE(dst); return dst; } diff --git a/src/backend/utils/adt/pg_lzcompress.c b/src/backend/utils/adt/pg_lzcompress.c index c756e5707a5..085bc63e0dd 100644 --- a/src/backend/utils/adt/pg_lzcompress.c +++ b/src/backend/utils/adt/pg_lzcompress.c @@ -166,7 +166,7 @@ * * Copyright (c) 1999-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.25 2007/02/27 23:48:08 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.26 2007/04/06 04:21:43 tgl Exp $ * ---------- */ #include "postgres.h" @@ -618,7 +618,7 @@ pglz_compress(const char *source, int32 slen, PGLZ_Header *dest, /* * Success - need only fill in the actual length of the compressed datum. */ - SET_VARSIZE(dest, result_size + sizeof(PGLZ_Header)); + SET_VARSIZE_COMPRESSED(dest, result_size + sizeof(PGLZ_Header)); return true; } diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c index 371a8a605d6..77a6ab9c4fc 100644 --- a/src/backend/utils/adt/varchar.c +++ b/src/backend/utils/adt/varchar.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.122 2007/02/27 23:48:09 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/varchar.c,v 1.123 2007/04/06 04:21:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -16,6 +16,7 @@ #include "access/hash.h" +#include "access/tuptoaster.h" #include "libpq/pqformat.h" #include "utils/array.h" #include "utils/builtins.h" @@ -206,14 +207,14 @@ bpcharin(PG_FUNCTION_ARGS) Datum bpcharout(PG_FUNCTION_ARGS) { - BpChar *s = PG_GETARG_BPCHAR_P(0); + BpChar *s = PG_GETARG_BPCHAR_PP(0); char *result; int len; /* copy and add null term */ - len = VARSIZE(s) - VARHDRSZ; + len = VARSIZE_ANY_EXHDR(s); result = (char *) palloc(len + 1); - memcpy(result, VARDATA(s), len); + memcpy(result, VARDATA_ANY(s), len); result[len] = '\0'; PG_RETURN_CSTRING(result); @@ -267,7 +268,7 @@ bpcharsend(PG_FUNCTION_ARGS) Datum bpchar(PG_FUNCTION_ARGS) { - BpChar *source = PG_GETARG_BPCHAR_P(0); + BpChar *source = PG_GETARG_BPCHAR_PP(0); int32 maxlen = PG_GETARG_INT32(1); bool isExplicit = PG_GETARG_BOOL(2); BpChar *result; @@ -282,9 +283,12 @@ bpchar(PG_FUNCTION_ARGS) if (maxlen < (int32) VARHDRSZ) PG_RETURN_BPCHAR_P(source); - len = VARSIZE(source); + maxlen -= VARHDRSZ; - charlen = pg_mbstrlen_with_len(VARDATA(source), len - VARHDRSZ) + VARHDRSZ; + len = VARSIZE_ANY_EXHDR(source); + s = VARDATA_ANY(source); + + charlen = pg_mbstrlen_with_len(s, len); /* No work if supplied data matches typmod already */ if (charlen == maxlen) @@ -295,23 +299,22 @@ bpchar(PG_FUNCTION_ARGS) /* Verify that extra characters are spaces, and clip them off */ size_t maxmblen; - maxmblen = pg_mbcharcliplen(VARDATA(source), len - VARHDRSZ, - maxlen - VARHDRSZ) + VARHDRSZ; + maxmblen = pg_mbcharcliplen(s, len, maxlen); if (!isExplicit) { - for (i = maxmblen - VARHDRSZ; i < len - VARHDRSZ; i++) - if (*(VARDATA(source) + i) != ' ') + for (i = maxmblen; i < len; i++) + if (s[i] != ' ') ereport(ERROR, (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), errmsg("value too long for type character(%d)", - maxlen - VARHDRSZ))); + maxlen))); } len = maxmblen; /* - * XXX: at this point, maxlen is the necessary byte length+VARHDRSZ, + * At this point, maxlen is the necessary byte length, * not the number of CHARACTERS! */ maxlen = len; @@ -319,23 +322,23 @@ bpchar(PG_FUNCTION_ARGS) else { /* - * XXX: at this point, maxlen is the necessary byte length+VARHDRSZ, + * At this point, maxlen is the necessary byte length, * not the number of CHARACTERS! */ maxlen = len + (maxlen - charlen); } - s = VARDATA(source); + Assert(maxlen >= len); - result = palloc(maxlen); - SET_VARSIZE(result, maxlen); + result = palloc(maxlen+VARHDRSZ); + SET_VARSIZE(result, maxlen+VARHDRSZ); r = VARDATA(result); - memcpy(r, s, len - VARHDRSZ); + memcpy(r, s, len); /* blank pad the string if necessary */ if (maxlen > len) - memset(r + len - VARHDRSZ, ' ', maxlen - len); + memset(r + len, ' ', maxlen - len); PG_RETURN_BPCHAR_P(result); } @@ -365,11 +368,13 @@ char_bpchar(PG_FUNCTION_ARGS) Datum bpchar_name(PG_FUNCTION_ARGS) { - BpChar *s = PG_GETARG_BPCHAR_P(0); + BpChar *s = PG_GETARG_BPCHAR_PP(0); + char *s_data; Name result; int len; - len = VARSIZE(s) - VARHDRSZ; + len = VARSIZE_ANY_EXHDR(s); + s_data = VARDATA_ANY(s); /* Truncate to max length for a Name */ if (len >= NAMEDATALEN) @@ -378,13 +383,13 @@ bpchar_name(PG_FUNCTION_ARGS) /* Remove trailing blanks */ while (len > 0) { - if (*(VARDATA(s) + len - 1) != ' ') + if (s_data[len - 1] != ' ') break; len--; } result = (NameData *) palloc(NAMEDATALEN); - memcpy(NameStr(*result), VARDATA(s), len); + memcpy(NameStr(*result), s_data, len); /* Now null pad to full length... */ while (len < NAMEDATALEN) @@ -509,14 +514,14 @@ varcharin(PG_FUNCTION_ARGS) Datum varcharout(PG_FUNCTION_ARGS) { - VarChar *s = PG_GETARG_VARCHAR_P(0); + VarChar *s = PG_GETARG_VARCHAR_PP(0); char *result; int32 len; /* copy and add null term */ - len = VARSIZE(s) - VARHDRSZ; + len = VARSIZE_ANY_EXHDR(s); result = palloc(len + 1); - memcpy(result, VARDATA(s), len); + memcpy(result, VARDATA_ANY(s), len); result[len] = '\0'; PG_RETURN_CSTRING(result); @@ -570,39 +575,41 @@ varcharsend(PG_FUNCTION_ARGS) Datum varchar(PG_FUNCTION_ARGS) { - VarChar *source = PG_GETARG_VARCHAR_P(0); - int32 maxlen = PG_GETARG_INT32(1); + VarChar *source = PG_GETARG_VARCHAR_PP(0); + int32 typmod = PG_GETARG_INT32(1); bool isExplicit = PG_GETARG_BOOL(2); VarChar *result; - int32 len; + int32 len, maxlen; size_t maxmblen; int i; + char *s_data; + + len = VARSIZE_ANY_EXHDR(source); + s_data = VARDATA_ANY(source); + maxlen = typmod - VARHDRSZ; - len = VARSIZE(source); /* No work if typmod is invalid or supplied data fits it already */ - if (maxlen < (int32) VARHDRSZ || len <= maxlen) + if (maxlen < 0 || len <= maxlen) PG_RETURN_VARCHAR_P(source); /* only reach here if string is too long... */ /* truncate multibyte string preserving multibyte boundary */ - maxmblen = pg_mbcharcliplen(VARDATA(source), len - VARHDRSZ, - maxlen - VARHDRSZ); + maxmblen = pg_mbcharcliplen(s_data, len, maxlen); if (!isExplicit) { - for (i = maxmblen; i < len - VARHDRSZ; i++) - if (*(VARDATA(source) + i) != ' ') + for (i = maxmblen; i < len; i++) + if (s_data[i] != ' ') ereport(ERROR, (errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION), - errmsg("value too long for type character varying(%d)", - maxlen - VARHDRSZ))); + errmsg("value too long for type character varying(%d)", + maxlen))); } - len = maxmblen + VARHDRSZ; - result = palloc(len); - SET_VARSIZE(result, len); - memcpy(VARDATA(result), VARDATA(source), len - VARHDRSZ); + result = palloc(maxmblen + VARHDRSZ); + SET_VARSIZE(result, maxmblen + VARHDRSZ); + memcpy(VARDATA(result), s_data, maxmblen); PG_RETURN_VARCHAR_P(result); } @@ -632,11 +639,11 @@ varchartypmodout(PG_FUNCTION_ARGS) static int bcTruelen(BpChar *arg) { - char *s = VARDATA(arg); + char *s = VARDATA_ANY(arg); int i; int len; - len = VARSIZE(arg) - VARHDRSZ; + len = VARSIZE_ANY_EXHDR(arg); for (i = len - 1; i >= 0; i--) { if (s[i] != ' ') @@ -648,7 +655,7 @@ bcTruelen(BpChar *arg) Datum bpcharlen(PG_FUNCTION_ARGS) { - BpChar *arg = PG_GETARG_BPCHAR_P(0); + BpChar *arg = PG_GETARG_BPCHAR_PP(0); int len; /* get number of bytes, ignoring trailing spaces */ @@ -656,7 +663,7 @@ bpcharlen(PG_FUNCTION_ARGS) /* in multibyte encoding, convert to number of characters */ if (pg_database_encoding_max_length() != 1) - len = pg_mbstrlen_with_len(VARDATA(arg), len); + len = pg_mbstrlen_with_len(VARDATA_ANY(arg), len); PG_RETURN_INT32(len); } @@ -664,9 +671,10 @@ bpcharlen(PG_FUNCTION_ARGS) Datum bpcharoctetlen(PG_FUNCTION_ARGS) { - BpChar *arg = PG_GETARG_BPCHAR_P(0); + Datum arg = PG_GETARG_DATUM(0); - PG_RETURN_INT32(VARSIZE(arg) - VARHDRSZ); + /* We need not detoast the input at all */ + PG_RETURN_INT32(toast_raw_datum_size(arg) - VARHDRSZ); } @@ -681,8 +689,8 @@ bpcharoctetlen(PG_FUNCTION_ARGS) Datum bpchareq(PG_FUNCTION_ARGS) { - BpChar *arg1 = PG_GETARG_BPCHAR_P(0); - BpChar *arg2 = PG_GETARG_BPCHAR_P(1); + BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); + BpChar *arg2 = PG_GETARG_BPCHAR_PP(1); int len1, len2; bool result; @@ -697,7 +705,7 @@ bpchareq(PG_FUNCTION_ARGS) if (len1 != len2) result = false; else - result = (strncmp(VARDATA(arg1), VARDATA(arg2), len1) == 0); + result = (strncmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) == 0); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -708,8 +716,8 @@ bpchareq(PG_FUNCTION_ARGS) Datum bpcharne(PG_FUNCTION_ARGS) { - BpChar *arg1 = PG_GETARG_BPCHAR_P(0); - BpChar *arg2 = PG_GETARG_BPCHAR_P(1); + BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); + BpChar *arg2 = PG_GETARG_BPCHAR_PP(1); int len1, len2; bool result; @@ -724,7 +732,7 @@ bpcharne(PG_FUNCTION_ARGS) if (len1 != len2) result = true; else - result = (strncmp(VARDATA(arg1), VARDATA(arg2), len1) != 0); + result = (strncmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) != 0); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -735,8 +743,8 @@ bpcharne(PG_FUNCTION_ARGS) Datum bpcharlt(PG_FUNCTION_ARGS) { - BpChar *arg1 = PG_GETARG_BPCHAR_P(0); - BpChar *arg2 = PG_GETARG_BPCHAR_P(1); + BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); + BpChar *arg2 = PG_GETARG_BPCHAR_PP(1); int len1, len2; int cmp; @@ -744,7 +752,7 @@ bpcharlt(PG_FUNCTION_ARGS) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); + cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -755,8 +763,8 @@ bpcharlt(PG_FUNCTION_ARGS) Datum bpcharle(PG_FUNCTION_ARGS) { - BpChar *arg1 = PG_GETARG_BPCHAR_P(0); - BpChar *arg2 = PG_GETARG_BPCHAR_P(1); + BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); + BpChar *arg2 = PG_GETARG_BPCHAR_PP(1); int len1, len2; int cmp; @@ -764,7 +772,7 @@ bpcharle(PG_FUNCTION_ARGS) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); + cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -775,8 +783,8 @@ bpcharle(PG_FUNCTION_ARGS) Datum bpchargt(PG_FUNCTION_ARGS) { - BpChar *arg1 = PG_GETARG_BPCHAR_P(0); - BpChar *arg2 = PG_GETARG_BPCHAR_P(1); + BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); + BpChar *arg2 = PG_GETARG_BPCHAR_PP(1); int len1, len2; int cmp; @@ -784,7 +792,7 @@ bpchargt(PG_FUNCTION_ARGS) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); + cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -795,8 +803,8 @@ bpchargt(PG_FUNCTION_ARGS) Datum bpcharge(PG_FUNCTION_ARGS) { - BpChar *arg1 = PG_GETARG_BPCHAR_P(0); - BpChar *arg2 = PG_GETARG_BPCHAR_P(1); + BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); + BpChar *arg2 = PG_GETARG_BPCHAR_PP(1); int len1, len2; int cmp; @@ -804,7 +812,7 @@ bpcharge(PG_FUNCTION_ARGS) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); + cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -815,8 +823,8 @@ bpcharge(PG_FUNCTION_ARGS) Datum bpcharcmp(PG_FUNCTION_ARGS) { - BpChar *arg1 = PG_GETARG_BPCHAR_P(0); - BpChar *arg2 = PG_GETARG_BPCHAR_P(1); + BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); + BpChar *arg2 = PG_GETARG_BPCHAR_PP(1); int len1, len2; int cmp; @@ -824,7 +832,7 @@ bpcharcmp(PG_FUNCTION_ARGS) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); + cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -835,8 +843,8 @@ bpcharcmp(PG_FUNCTION_ARGS) Datum bpchar_larger(PG_FUNCTION_ARGS) { - BpChar *arg1 = PG_GETARG_BPCHAR_P(0); - BpChar *arg2 = PG_GETARG_BPCHAR_P(1); + BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); + BpChar *arg2 = PG_GETARG_BPCHAR_PP(1); int len1, len2; int cmp; @@ -844,7 +852,7 @@ bpchar_larger(PG_FUNCTION_ARGS) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); + cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2); PG_RETURN_BPCHAR_P((cmp >= 0) ? arg1 : arg2); } @@ -852,8 +860,8 @@ bpchar_larger(PG_FUNCTION_ARGS) Datum bpchar_smaller(PG_FUNCTION_ARGS) { - BpChar *arg1 = PG_GETARG_BPCHAR_P(0); - BpChar *arg2 = PG_GETARG_BPCHAR_P(1); + BpChar *arg1 = PG_GETARG_BPCHAR_PP(0); + BpChar *arg2 = PG_GETARG_BPCHAR_PP(1); int len1, len2; int cmp; @@ -861,7 +869,7 @@ bpchar_smaller(PG_FUNCTION_ARGS) len1 = bcTruelen(arg1); len2 = bcTruelen(arg2); - cmp = varstr_cmp(VARDATA(arg1), len1, VARDATA(arg2), len2); + cmp = varstr_cmp(VARDATA_ANY(arg1), len1, VARDATA_ANY(arg2), len2); PG_RETURN_BPCHAR_P((cmp <= 0) ? arg1 : arg2); } @@ -878,12 +886,12 @@ bpchar_smaller(PG_FUNCTION_ARGS) Datum hashbpchar(PG_FUNCTION_ARGS) { - BpChar *key = PG_GETARG_BPCHAR_P(0); + BpChar *key = PG_GETARG_BPCHAR_PP(0); char *keydata; int keylen; Datum result; - keydata = VARDATA(key); + keydata = VARDATA_ANY(key); keylen = bcTruelen(key); result = hash_any((unsigned char *) keydata, keylen); diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 51130efd79b..0b5b4fd16a4 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.155 2007/02/27 23:48:09 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.156 2007/04/06 04:21:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -175,7 +175,7 @@ byteain(PG_FUNCTION_ARGS) Datum byteaout(PG_FUNCTION_ARGS) { - bytea *vlena = PG_GETARG_BYTEA_P(0); + bytea *vlena = PG_GETARG_BYTEA_PP(0); char *result; char *vp; char *rp; @@ -184,8 +184,8 @@ byteaout(PG_FUNCTION_ARGS) int len; len = 1; /* empty string has 1 char */ - vp = VARDATA(vlena); - for (i = VARSIZE(vlena) - VARHDRSZ; i != 0; i--, vp++) + vp = VARDATA_ANY(vlena); + for (i = VARSIZE_ANY_EXHDR(vlena); i != 0; i--, vp++) { if (*vp == '\\') len += 2; @@ -195,8 +195,8 @@ byteaout(PG_FUNCTION_ARGS) len++; } rp = result = (char *) palloc(len); - vp = VARDATA(vlena); - for (i = VARSIZE(vlena) - VARHDRSZ; i != 0; i--, vp++) + vp = VARDATA_ANY(vlena); + for (i = VARSIZE_ANY_EXHDR(vlena); i != 0; i--, vp++) { if (*vp == '\\') { @@ -277,13 +277,13 @@ textin(PG_FUNCTION_ARGS) Datum textout(PG_FUNCTION_ARGS) { - text *t = PG_GETARG_TEXT_P(0); + text *t = PG_GETARG_TEXT_PP(0); int len; char *result; - len = VARSIZE(t) - VARHDRSZ; + len = VARSIZE_ANY_EXHDR(t); result = (char *) palloc(len + 1); - memcpy(result, VARDATA(t), len); + memcpy(result, VARDATA_ANY(t), len); result[len] = '\0'; PG_RETURN_CSTRING(result); @@ -315,11 +315,11 @@ textrecv(PG_FUNCTION_ARGS) Datum textsend(PG_FUNCTION_ARGS) { - text *t = PG_GETARG_TEXT_P(0); + text *t = PG_GETARG_TEXT_PP(0); StringInfoData buf; pq_begintypsend(&buf); - pq_sendtext(&buf, VARDATA(t), VARSIZE(t) - VARHDRSZ); + pq_sendtext(&buf, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t)); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); } @@ -412,10 +412,10 @@ text_length(Datum str) PG_RETURN_INT32(toast_raw_datum_size(str) - VARHDRSZ); else { - text *t = DatumGetTextP(str); + text *t = DatumGetTextPP(str); - PG_RETURN_INT32(pg_mbstrlen_with_len(VARDATA(t), - VARSIZE(t) - VARHDRSZ)); + PG_RETURN_INT32(pg_mbstrlen_with_len(VARDATA_ANY(t), + VARSIZE_ANY_EXHDR(t))); } } @@ -446,19 +446,19 @@ textoctetlen(PG_FUNCTION_ARGS) Datum textcat(PG_FUNCTION_ARGS) { - text *t1 = PG_GETARG_TEXT_P(0); - text *t2 = PG_GETARG_TEXT_P(1); + text *t1 = PG_GETARG_TEXT_PP(0); + text *t2 = PG_GETARG_TEXT_PP(1); int len1, len2, len; text *result; char *ptr; - len1 = VARSIZE(t1) - VARHDRSZ; + len1 = VARSIZE_ANY_EXHDR(t1); if (len1 < 0) len1 = 0; - len2 = VARSIZE(t2) - VARHDRSZ; + len2 = VARSIZE_ANY_EXHDR(t2); if (len2 < 0) len2 = 0; @@ -471,9 +471,9 @@ textcat(PG_FUNCTION_ARGS) /* Fill data field of result string... */ ptr = VARDATA(result); if (len1 > 0) - memcpy(ptr, VARDATA(t1), len1); + memcpy(ptr, VARDATA_ANY(t1), len1); if (len2 > 0) - memcpy(ptr + len1, VARDATA(t2), len2); + memcpy(ptr + len1, VARDATA_ANY(t2), len2); PG_RETURN_TEXT_P(result); } @@ -1058,12 +1058,12 @@ text_cmp(text *arg1, text *arg2) int len1, len2; - a1p = VARDATA(arg1); - a2p = VARDATA(arg2); - - len1 = VARSIZE(arg1) - VARHDRSZ; - len2 = VARSIZE(arg2) - VARHDRSZ; + a1p = VARDATA_ANY(arg1); + a2p = VARDATA_ANY(arg2); + len1 = VARSIZE_ANY_EXHDR(arg1); + len2 = VARSIZE_ANY_EXHDR(arg2); + return varstr_cmp(a1p, len1, a2p, len2); } @@ -1078,19 +1078,19 @@ text_cmp(text *arg1, text *arg2) Datum texteq(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); bool result; /* * Since we only care about equality or not-equality, we can avoid all the * expense of strcoll() here, and just do bitwise comparison. */ - if (VARSIZE(arg1) != VARSIZE(arg2)) + if (VARSIZE_ANY_EXHDR(arg1) != VARSIZE_ANY_EXHDR(arg2)) result = false; else - result = (strncmp(VARDATA(arg1), VARDATA(arg2), - VARSIZE(arg1) - VARHDRSZ) == 0); + result = (strncmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), + VARSIZE_ANY_EXHDR(arg1)) == 0); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -1101,19 +1101,19 @@ texteq(PG_FUNCTION_ARGS) Datum textne(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); bool result; /* * Since we only care about equality or not-equality, we can avoid all the * expense of strcoll() here, and just do bitwise comparison. */ - if (VARSIZE(arg1) != VARSIZE(arg2)) + if (VARSIZE_ANY_EXHDR(arg1) != VARSIZE_ANY_EXHDR(arg2)) result = true; else - result = (strncmp(VARDATA(arg1), VARDATA(arg2), - VARSIZE(arg1) - VARHDRSZ) != 0); + result = (strncmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), + VARSIZE_ANY_EXHDR(arg1)) != 0); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -1124,8 +1124,8 @@ textne(PG_FUNCTION_ARGS) Datum text_lt(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); bool result; result = (text_cmp(arg1, arg2) < 0); @@ -1139,8 +1139,8 @@ text_lt(PG_FUNCTION_ARGS) Datum text_le(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); bool result; result = (text_cmp(arg1, arg2) <= 0); @@ -1154,8 +1154,8 @@ text_le(PG_FUNCTION_ARGS) Datum text_gt(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); bool result; result = (text_cmp(arg1, arg2) > 0); @@ -1169,8 +1169,8 @@ text_gt(PG_FUNCTION_ARGS) Datum text_ge(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); bool result; result = (text_cmp(arg1, arg2) >= 0); @@ -1184,8 +1184,8 @@ text_ge(PG_FUNCTION_ARGS) Datum bttextcmp(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); int32 result; result = text_cmp(arg1, arg2); @@ -1200,8 +1200,8 @@ bttextcmp(PG_FUNCTION_ARGS) Datum text_larger(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); text *result; result = ((text_cmp(arg1, arg2) > 0) ? arg1 : arg2); @@ -1212,8 +1212,8 @@ text_larger(PG_FUNCTION_ARGS) Datum text_smaller(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); text *result; result = ((text_cmp(arg1, arg2) < 0) ? arg1 : arg2); @@ -1233,13 +1233,13 @@ internal_text_pattern_compare(text *arg1, text *arg2) { int result; - result = memcmp(VARDATA(arg1), VARDATA(arg2), - Min(VARSIZE(arg1), VARSIZE(arg2)) - VARHDRSZ); + result = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), + Min(VARSIZE_ANY_EXHDR(arg1), VARSIZE_ANY_EXHDR(arg2))); if (result != 0) return result; - else if (VARSIZE(arg1) < VARSIZE(arg2)) + else if (VARSIZE_ANY_EXHDR(arg1) < VARSIZE_ANY_EXHDR(arg2)) return -1; - else if (VARSIZE(arg1) > VARSIZE(arg2)) + else if (VARSIZE_ANY_EXHDR(arg1) > VARSIZE_ANY_EXHDR(arg2)) return 1; else return 0; @@ -1249,8 +1249,8 @@ internal_text_pattern_compare(text *arg1, text *arg2) Datum text_pattern_lt(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); int result; result = internal_text_pattern_compare(arg1, arg2); @@ -1265,8 +1265,8 @@ text_pattern_lt(PG_FUNCTION_ARGS) Datum text_pattern_le(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); int result; result = internal_text_pattern_compare(arg1, arg2); @@ -1281,11 +1281,11 @@ text_pattern_le(PG_FUNCTION_ARGS) Datum text_pattern_eq(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); int result; - if (VARSIZE(arg1) != VARSIZE(arg2)) + if (VARSIZE_ANY_EXHDR(arg1) != VARSIZE_ANY_EXHDR(arg2)) result = 1; else result = internal_text_pattern_compare(arg1, arg2); @@ -1300,8 +1300,8 @@ text_pattern_eq(PG_FUNCTION_ARGS) Datum text_pattern_ge(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); int result; result = internal_text_pattern_compare(arg1, arg2); @@ -1316,8 +1316,8 @@ text_pattern_ge(PG_FUNCTION_ARGS) Datum text_pattern_gt(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); int result; result = internal_text_pattern_compare(arg1, arg2); @@ -1332,11 +1332,11 @@ text_pattern_gt(PG_FUNCTION_ARGS) Datum text_pattern_ne(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); int result; - if (VARSIZE(arg1) != VARSIZE(arg2)) + if (VARSIZE_ANY_EXHDR(arg1) != VARSIZE_ANY_EXHDR(arg2)) result = 1; else result = internal_text_pattern_compare(arg1, arg2); @@ -1351,8 +1351,8 @@ text_pattern_ne(PG_FUNCTION_ARGS) Datum bttext_pattern_cmp(PG_FUNCTION_ARGS) { - text *arg1 = PG_GETARG_TEXT_P(0); - text *arg2 = PG_GETARG_TEXT_P(1); + text *arg1 = PG_GETARG_TEXT_PP(0); + text *arg2 = PG_GETARG_TEXT_PP(1); int result; result = internal_text_pattern_compare(arg1, arg2); @@ -1389,19 +1389,19 @@ byteaoctetlen(PG_FUNCTION_ARGS) Datum byteacat(PG_FUNCTION_ARGS) { - bytea *t1 = PG_GETARG_BYTEA_P(0); - bytea *t2 = PG_GETARG_BYTEA_P(1); + bytea *t1 = PG_GETARG_BYTEA_PP(0); + bytea *t2 = PG_GETARG_BYTEA_PP(1); int len1, len2, len; bytea *result; char *ptr; - len1 = VARSIZE(t1) - VARHDRSZ; + len1 = VARSIZE_ANY_EXHDR(t1); if (len1 < 0) len1 = 0; - len2 = VARSIZE(t2) - VARHDRSZ; + len2 = VARSIZE_ANY_EXHDR(t2); if (len2 < 0) len2 = 0; @@ -1414,9 +1414,9 @@ byteacat(PG_FUNCTION_ARGS) /* Fill data field of result string... */ ptr = VARDATA(result); if (len1 > 0) - memcpy(ptr, VARDATA(t1), len1); + memcpy(ptr, VARDATA_ANY(t1), len1); if (len2 > 0) - memcpy(ptr + len1, VARDATA(t2), len2); + memcpy(ptr + len1, VARDATA_ANY(t2), len2); PG_RETURN_BYTEA_P(result); } @@ -1509,8 +1509,8 @@ bytea_substr_no_len(PG_FUNCTION_ARGS) Datum byteapos(PG_FUNCTION_ARGS) { - bytea *t1 = PG_GETARG_BYTEA_P(0); - bytea *t2 = PG_GETARG_BYTEA_P(1); + bytea *t1 = PG_GETARG_BYTEA_PP(0); + bytea *t2 = PG_GETARG_BYTEA_PP(1); int pos; int px, p; @@ -1519,14 +1519,14 @@ byteapos(PG_FUNCTION_ARGS) char *p1, *p2; - if (VARSIZE(t2) <= VARHDRSZ) - PG_RETURN_INT32(1); /* result for empty pattern */ + len1 = VARSIZE_ANY_EXHDR(t1); + len2 = VARSIZE_ANY_EXHDR(t2); - len1 = VARSIZE(t1) - VARHDRSZ; - len2 = VARSIZE(t2) - VARHDRSZ; + if (len2 <= 0) + PG_RETURN_INT32(1); /* result for empty pattern */ - p1 = VARDATA(t1); - p2 = VARDATA(t2); + p1 = VARDATA_ANY(t1); + p2 = VARDATA_ANY(t2); pos = 0; px = (len1 - len2); @@ -1553,12 +1553,12 @@ byteapos(PG_FUNCTION_ARGS) Datum byteaGetByte(PG_FUNCTION_ARGS) { - bytea *v = PG_GETARG_BYTEA_P(0); + bytea *v = PG_GETARG_BYTEA_PP(0); int32 n = PG_GETARG_INT32(1); int len; int byte; - len = VARSIZE(v) - VARHDRSZ; + len = VARSIZE_ANY_EXHDR(v); if (n < 0 || n >= len) ereport(ERROR, @@ -1566,7 +1566,7 @@ byteaGetByte(PG_FUNCTION_ARGS) errmsg("index %d out of valid range, 0..%d", n, len - 1))); - byte = ((unsigned char *) VARDATA(v))[n]; + byte = ((unsigned char *) VARDATA_ANY(v))[n]; PG_RETURN_INT32(byte); } @@ -1582,14 +1582,14 @@ byteaGetByte(PG_FUNCTION_ARGS) Datum byteaGetBit(PG_FUNCTION_ARGS) { - bytea *v = PG_GETARG_BYTEA_P(0); + bytea *v = PG_GETARG_BYTEA_PP(0); int32 n = PG_GETARG_INT32(1); int byteNo, bitNo; int len; int byte; - len = VARSIZE(v) - VARHDRSZ; + len = VARSIZE_ANY_EXHDR(v); if (n < 0 || n >= len * 8) ereport(ERROR, @@ -1600,7 +1600,7 @@ byteaGetBit(PG_FUNCTION_ARGS) byteNo = n / 8; bitNo = n % 8; - byte = ((unsigned char *) VARDATA(v))[byteNo]; + byte = ((unsigned char *) VARDATA_ANY(v))[byteNo]; if (byte & (1 << bitNo)) PG_RETURN_INT32(1); @@ -1715,23 +1715,18 @@ byteaSetBit(PG_FUNCTION_ARGS) Datum text_name(PG_FUNCTION_ARGS) { - text *s = PG_GETARG_TEXT_P(0); + text *s = PG_GETARG_TEXT_PP(0); Name result; int len; - len = VARSIZE(s) - VARHDRSZ; + len = VARSIZE_ANY_EXHDR(s); /* Truncate oversize input */ if (len >= NAMEDATALEN) len = NAMEDATALEN - 1; -#ifdef STRINGDEBUG - printf("text- convert string length %d (%d) ->%d\n", - VARSIZE(s) - VARHDRSZ, VARSIZE(s), len); -#endif - result = (Name) palloc(NAMEDATALEN); - memcpy(NameStr(*result), VARDATA(s), len); + memcpy(NameStr(*result), VARDATA_ANY(s), len); /* now null pad to full length... */ while (len < NAMEDATALEN) @@ -1755,11 +1750,6 @@ name_text(PG_FUNCTION_ARGS) len = strlen(NameStr(*s)); -#ifdef STRINGDEBUG - printf("text- convert string length %d (%d) ->%d\n", - VARSIZE(s) - VARHDRSZ, VARSIZE(s), len); -#endif - result = palloc(VARHDRSZ + len); SET_VARSIZE(result, VARHDRSZ + len); memcpy(VARDATA(result), NameStr(*s), len); @@ -1948,20 +1938,20 @@ SplitIdentifierString(char *rawstring, char separator, Datum byteaeq(PG_FUNCTION_ARGS) { - bytea *arg1 = PG_GETARG_BYTEA_P(0); - bytea *arg2 = PG_GETARG_BYTEA_P(1); + bytea *arg1 = PG_GETARG_BYTEA_PP(0); + bytea *arg2 = PG_GETARG_BYTEA_PP(1); int len1, len2; bool result; - len1 = VARSIZE(arg1) - VARHDRSZ; - len2 = VARSIZE(arg2) - VARHDRSZ; + len1 = VARSIZE_ANY_EXHDR(arg1); + len2 = VARSIZE_ANY_EXHDR(arg2); /* fast path for different-length inputs */ if (len1 != len2) result = false; else - result = (memcmp(VARDATA(arg1), VARDATA(arg2), len1) == 0); + result = (memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) == 0); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -1972,20 +1962,20 @@ byteaeq(PG_FUNCTION_ARGS) Datum byteane(PG_FUNCTION_ARGS) { - bytea *arg1 = PG_GETARG_BYTEA_P(0); - bytea *arg2 = PG_GETARG_BYTEA_P(1); + bytea *arg1 = PG_GETARG_BYTEA_PP(0); + bytea *arg2 = PG_GETARG_BYTEA_PP(1); int len1, len2; bool result; - len1 = VARSIZE(arg1) - VARHDRSZ; - len2 = VARSIZE(arg2) - VARHDRSZ; + len1 = VARSIZE_ANY_EXHDR(arg1); + len2 = VARSIZE_ANY_EXHDR(arg2); /* fast path for different-length inputs */ if (len1 != len2) result = true; else - result = (memcmp(VARDATA(arg1), VARDATA(arg2), len1) != 0); + result = (memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), len1) != 0); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -1996,16 +1986,16 @@ byteane(PG_FUNCTION_ARGS) Datum bytealt(PG_FUNCTION_ARGS) { - bytea *arg1 = PG_GETARG_BYTEA_P(0); - bytea *arg2 = PG_GETARG_BYTEA_P(1); + bytea *arg1 = PG_GETARG_BYTEA_PP(0); + bytea *arg2 = PG_GETARG_BYTEA_PP(1); int len1, len2; int cmp; - len1 = VARSIZE(arg1) - VARHDRSZ; - len2 = VARSIZE(arg2) - VARHDRSZ; + len1 = VARSIZE_ANY_EXHDR(arg1); + len2 = VARSIZE_ANY_EXHDR(arg2); - cmp = memcmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), Min(len1, len2)); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -2016,16 +2006,16 @@ bytealt(PG_FUNCTION_ARGS) Datum byteale(PG_FUNCTION_ARGS) { - bytea *arg1 = PG_GETARG_BYTEA_P(0); - bytea *arg2 = PG_GETARG_BYTEA_P(1); + bytea *arg1 = PG_GETARG_BYTEA_PP(0); + bytea *arg2 = PG_GETARG_BYTEA_PP(1); int len1, len2; int cmp; - len1 = VARSIZE(arg1) - VARHDRSZ; - len2 = VARSIZE(arg2) - VARHDRSZ; + len1 = VARSIZE_ANY_EXHDR(arg1); + len2 = VARSIZE_ANY_EXHDR(arg2); - cmp = memcmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), Min(len1, len2)); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -2036,16 +2026,16 @@ byteale(PG_FUNCTION_ARGS) Datum byteagt(PG_FUNCTION_ARGS) { - bytea *arg1 = PG_GETARG_BYTEA_P(0); - bytea *arg2 = PG_GETARG_BYTEA_P(1); + bytea *arg1 = PG_GETARG_BYTEA_PP(0); + bytea *arg2 = PG_GETARG_BYTEA_PP(1); int len1, len2; int cmp; - len1 = VARSIZE(arg1) - VARHDRSZ; - len2 = VARSIZE(arg2) - VARHDRSZ; + len1 = VARSIZE_ANY_EXHDR(arg1); + len2 = VARSIZE_ANY_EXHDR(arg2); - cmp = memcmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), Min(len1, len2)); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -2056,16 +2046,16 @@ byteagt(PG_FUNCTION_ARGS) Datum byteage(PG_FUNCTION_ARGS) { - bytea *arg1 = PG_GETARG_BYTEA_P(0); - bytea *arg2 = PG_GETARG_BYTEA_P(1); + bytea *arg1 = PG_GETARG_BYTEA_PP(0); + bytea *arg2 = PG_GETARG_BYTEA_PP(1); int len1, len2; int cmp; - len1 = VARSIZE(arg1) - VARHDRSZ; - len2 = VARSIZE(arg2) - VARHDRSZ; + len1 = VARSIZE_ANY_EXHDR(arg1); + len2 = VARSIZE_ANY_EXHDR(arg2); - cmp = memcmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), Min(len1, len2)); PG_FREE_IF_COPY(arg1, 0); PG_FREE_IF_COPY(arg2, 1); @@ -2076,16 +2066,16 @@ byteage(PG_FUNCTION_ARGS) Datum byteacmp(PG_FUNCTION_ARGS) { - bytea *arg1 = PG_GETARG_BYTEA_P(0); - bytea *arg2 = PG_GETARG_BYTEA_P(1); + bytea *arg1 = PG_GETARG_BYTEA_PP(0); + bytea *arg2 = PG_GETARG_BYTEA_PP(1); int len1, len2; int cmp; - len1 = VARSIZE(arg1) - VARHDRSZ; - len2 = VARSIZE(arg2) - VARHDRSZ; + len1 = VARSIZE_ANY_EXHDR(arg1); + len2 = VARSIZE_ANY_EXHDR(arg2); - cmp = memcmp(VARDATA(arg1), VARDATA(arg2), Min(len1, len2)); + cmp = memcmp(VARDATA_ANY(arg1), VARDATA_ANY(arg2), Min(len1, len2)); if ((cmp == 0) && (len1 != len2)) cmp = (len1 < len2) ? -1 : 1; @@ -2713,8 +2703,8 @@ array_to_text(PG_FUNCTION_ARGS) appendStringInfoString(&buf, value); printed = true; - p = att_addlength(p, typlen, PointerGetDatum(p)); - p = (char *) att_align(p, typalign); + p = att_addlength_pointer(p, typlen, p); + p = (char *) att_align_nominal(p, typalign); } /* advance bitmap pointer if any */ @@ -2795,16 +2785,16 @@ to_hex64(PG_FUNCTION_ARGS) Datum md5_text(PG_FUNCTION_ARGS) { - text *in_text = PG_GETARG_TEXT_P(0); + text *in_text = PG_GETARG_TEXT_PP(0); size_t len; char hexsum[MD5_HASH_LEN + 1]; text *result_text; /* Calculate the length of the buffer using varlena metadata */ - len = VARSIZE(in_text) - VARHDRSZ; + len = VARSIZE_ANY_EXHDR(in_text); /* get the hash result */ - if (pg_md5_hash(VARDATA(in_text), len, hexsum) == false) + if (pg_md5_hash(VARDATA_ANY(in_text), len, hexsum) == false) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); @@ -2821,13 +2811,13 @@ md5_text(PG_FUNCTION_ARGS) Datum md5_bytea(PG_FUNCTION_ARGS) { - bytea *in = PG_GETARG_BYTEA_P(0); + bytea *in = PG_GETARG_BYTEA_PP(0); size_t len; char hexsum[MD5_HASH_LEN + 1]; text *result_text; - len = VARSIZE(in) - VARHDRSZ; - if (pg_md5_hash(VARDATA(in), len, hexsum) == false) + len = VARSIZE_ANY_EXHDR(in); + if (pg_md5_hash(VARDATA_ANY(in), len, hexsum) == false) ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index f039bba21e0..e873264e3a1 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -7,7 +7,7 @@ * 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.41 2007/04/05 13:53:23 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/xml.c,v 1.42 2007/04/06 04:21:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -3071,8 +3071,8 @@ xmlpath(PG_FUNCTION_ARGS) else ns_uris[i - ns_count] = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(ptr))); - ptr = att_addlength(ptr, typlen, PointerGetDatum(ptr)); - ptr = (char *) att_align(ptr, typalign); + ptr = att_addlength_pointer(ptr, typlen, ptr); + ptr = (char *) att_align_nominal(ptr, typalign); } /* advance bitmap pointer if any */ diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c index a28acdc2ad8..5a67a84cf88 100644 --- a/src/backend/utils/fmgr/fmgr.c +++ b/src/backend/utils/fmgr/fmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.105 2007/03/27 23:21:10 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.106 2007/04/06 04:21:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1962,7 +1962,7 @@ struct varlena * pg_detoast_datum(struct varlena * datum) { if (VARATT_IS_EXTENDED(datum)) - return (struct varlena *) heap_tuple_untoast_attr((varattrib *) datum); + return heap_tuple_untoast_attr(datum); else return datum; } @@ -1971,7 +1971,7 @@ struct varlena * pg_detoast_datum_copy(struct varlena * datum) { if (VARATT_IS_EXTENDED(datum)) - return (struct varlena *) heap_tuple_untoast_attr((varattrib *) datum); + return heap_tuple_untoast_attr(datum); else { /* Make a modifiable copy of the varlena object */ @@ -1987,7 +1987,16 @@ struct varlena * pg_detoast_datum_slice(struct varlena * datum, int32 first, int32 count) { /* Only get the specified portion from the toast rel */ - return (struct varlena *) heap_tuple_untoast_attr_slice((varattrib *) datum, first, count); + return heap_tuple_untoast_attr_slice(datum, first, count); +} + +struct varlena * +pg_detoast_datum_packed(struct varlena * datum) +{ + if (VARATT_IS_COMPRESSED(datum) || VARATT_IS_EXTERNAL(datum)) + return heap_tuple_untoast_attr(datum); + else + return datum; } /*------------------------------------------------------------------------- diff --git a/src/backend/utils/init/flatfiles.c b/src/backend/utils/init/flatfiles.c index 1699979c3d0..e388d1edfdc 100644 --- a/src/backend/utils/init/flatfiles.c +++ b/src/backend/utils/init/flatfiles.c @@ -23,7 +23,7 @@ * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.24 2007/01/05 22:19:43 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/init/flatfiles.c,v 1.25 2007/04/06 04:21:43 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -467,7 +467,7 @@ write_auth_file(Relation rel_authid, Relation rel_authmem) auth_info[curr_role].rolpassword = DatumGetCString(DirectFunctionCall1(textout, datum)); /* assume passwd has attlen -1 */ - off = att_addlength(off, -1, tp + off); + off = att_addlength_pointer(off, -1, tp + off); } if (HeapTupleHasNulls(tuple) && @@ -482,7 +482,7 @@ write_auth_file(Relation rel_authid, Relation rel_authmem) * rolvaliduntil is timestamptz, which we assume is double * alignment and pass-by-reference. */ - off = att_align(off, 'd'); + off = att_align_nominal(off, 'd'); datum = PointerGetDatum(tp + off); auth_info[curr_role].rolvaliduntil = DatumGetCString(DirectFunctionCall1(timestamptz_out, datum)); } |