diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-02-28 22:44:38 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-02-28 22:44:38 +0000 |
| commit | 9f652d430fbd1e757caaec9fe64d3e94c8693158 (patch) | |
| tree | 9215d2131d85e73caeb96fe23ba442c17b8d4575 /contrib/ltree | |
| parent | d1ce4f7396aac34233e075d0342ac704593799ce (diff) | |
| download | postgresql-9f652d430fbd1e757caaec9fe64d3e94c8693158.tar.gz | |
Fix up several contrib modules that were using varlena datatypes in not-so-obvious
ways. I'm not totally sure that I caught everything, but at least now they pass
their regression tests with VARSIZE/SET_VARSIZE defined to reverse byte order.
Diffstat (limited to 'contrib/ltree')
| -rw-r--r-- | contrib/ltree/_ltree_gist.c | 15 | ||||
| -rw-r--r-- | contrib/ltree/_ltree_op.c | 16 | ||||
| -rw-r--r-- | contrib/ltree/ltree.h | 20 | ||||
| -rw-r--r-- | contrib/ltree/ltree_gist.c | 36 | ||||
| -rw-r--r-- | contrib/ltree/ltree_io.c | 8 | ||||
| -rw-r--r-- | contrib/ltree/ltree_op.c | 19 | ||||
| -rw-r--r-- | contrib/ltree/ltxtquery_io.c | 4 |
7 files changed, 60 insertions, 58 deletions
diff --git a/contrib/ltree/_ltree_gist.c b/contrib/ltree/_ltree_gist.c index 0bac647547..4ce8864fb3 100644 --- a/contrib/ltree/_ltree_gist.c +++ b/contrib/ltree/_ltree_gist.c @@ -94,7 +94,7 @@ _ltree_compress(PG_FUNCTION_ARGS) errmsg("array must not contain nulls"))); key = (ltree_gist *) palloc(len); - key->len = len; + SET_VARSIZE(key, len); key->flag = 0; MemSet(LTG_SIGN(key), 0, ASIGLEN); @@ -124,7 +124,7 @@ _ltree_compress(PG_FUNCTION_ARGS) ); len = LTG_HDRSIZE; key = (ltree_gist *) palloc(len); - key->len = len; + SET_VARSIZE(key, len); key->flag = LTG_ALLTRUE; retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); @@ -204,10 +204,11 @@ _ltree_union(PG_FUNCTION_ARGS) len = LTG_HDRSIZE + ((flag & LTG_ALLTRUE) ? 0 : ASIGLEN); result = (ltree_gist *) palloc(len); - *size = result->len = len; + SET_VARSIZE(result, len); result->flag = flag; if (!LTG_ISALLTRUE(result)) memcpy((void *) LTG_SIGN(result), (void *) base, sizeof(ABITVEC)); + *size = len; PG_RETURN_POINTER(result); } @@ -340,26 +341,26 @@ _ltree_picksplit(PG_FUNCTION_ARGS) if (LTG_ISALLTRUE(GETENTRY(entryvec, seed_1))) { datum_l = (ltree_gist *) palloc(LTG_HDRSIZE); - datum_l->len = LTG_HDRSIZE; + SET_VARSIZE(datum_l, LTG_HDRSIZE); datum_l->flag = LTG_ALLTRUE; } else { datum_l = (ltree_gist *) palloc(LTG_HDRSIZE + ASIGLEN); - datum_l->len = LTG_HDRSIZE + ASIGLEN; + SET_VARSIZE(datum_l, LTG_HDRSIZE + ASIGLEN); datum_l->flag = 0; memcpy((void *) LTG_SIGN(datum_l), (void *) LTG_SIGN(GETENTRY(entryvec, seed_1)), sizeof(ABITVEC)); } if (LTG_ISALLTRUE(GETENTRY(entryvec, seed_2))) { datum_r = (ltree_gist *) palloc(LTG_HDRSIZE); - datum_r->len = LTG_HDRSIZE; + SET_VARSIZE(datum_r, LTG_HDRSIZE); datum_r->flag = LTG_ALLTRUE; } else { datum_r = (ltree_gist *) palloc(LTG_HDRSIZE + ASIGLEN); - datum_r->len = LTG_HDRSIZE + ASIGLEN; + SET_VARSIZE(datum_r, LTG_HDRSIZE + ASIGLEN); datum_r->flag = 0; memcpy((void *) LTG_SIGN(datum_r), (void *) LTG_SIGN(GETENTRY(entryvec, seed_2)), sizeof(ABITVEC)); } diff --git a/contrib/ltree/_ltree_op.c b/contrib/ltree/_ltree_op.c index ff8eec793a..f93d2bb888 100644 --- a/contrib/ltree/_ltree_op.c +++ b/contrib/ltree/_ltree_op.c @@ -215,8 +215,8 @@ _ltree_extract_isparent(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - item = (ltree *) palloc(found->len); - memcpy(item, found, found->len); + item = (ltree *) palloc(VARSIZE(found)); + memcpy(item, found, VARSIZE(found)); PG_FREE_IF_COPY(la, 0); PG_FREE_IF_COPY(query, 1); @@ -238,8 +238,8 @@ _ltree_extract_risparent(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - item = (ltree *) palloc(found->len); - memcpy(item, found, found->len); + item = (ltree *) palloc(VARSIZE(found)); + memcpy(item, found, VARSIZE(found)); PG_FREE_IF_COPY(la, 0); PG_FREE_IF_COPY(query, 1); @@ -261,8 +261,8 @@ _ltq_extract_regex(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - item = (ltree *) palloc(found->len); - memcpy(item, found, found->len); + item = (ltree *) palloc(VARSIZE(found)); + memcpy(item, found, VARSIZE(found)); PG_FREE_IF_COPY(la, 0); PG_FREE_IF_COPY(query, 1); @@ -284,8 +284,8 @@ _ltxtq_extract_exec(PG_FUNCTION_ARGS) PG_RETURN_NULL(); } - item = (ltree *) palloc(found->len); - memcpy(item, found, found->len); + item = (ltree *) palloc(VARSIZE(found)); + memcpy(item, found, VARSIZE(found)); PG_FREE_IF_COPY(la, 0); PG_FREE_IF_COPY(query, 1); diff --git a/contrib/ltree/ltree.h b/contrib/ltree/ltree.h index 1ff5707fb1..d627c45bd3 100644 --- a/contrib/ltree/ltree.h +++ b/contrib/ltree/ltree.h @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/contrib/ltree/ltree.h,v 1.17 2006/10/04 00:29:45 momjian Exp $ */ +/* $PostgreSQL: pgsql/contrib/ltree/ltree.h,v 1.18 2007/02/28 22:44:38 tgl Exp $ */ #ifndef __LTREE_H__ #define __LTREE_H__ @@ -18,12 +18,12 @@ typedef struct typedef struct { - int32 len; + int32 vl_len_; /* varlena header (do not touch directly!) */ uint16 numlevel; char data[1]; } ltree; -#define LTREE_HDRSIZE MAXALIGN( sizeof(int32) + sizeof(uint16) ) +#define LTREE_HDRSIZE MAXALIGN(VARHDRSZ + sizeof(uint16)) #define LTREE_FIRST(x) ( (ltree_level*)( ((char*)(x))+LTREE_HDRSIZE ) ) @@ -68,14 +68,14 @@ typedef struct typedef struct { - int32 len; + int32 vl_len_; /* varlena header (do not touch directly!) */ uint16 numlevel; uint16 firstgood; uint16 flag; char data[1]; } lquery; -#define LQUERY_HDRSIZE MAXALIGN( sizeof(int32) + 3*sizeof(uint16) ) +#define LQUERY_HDRSIZE MAXALIGN(VARHDRSZ + 3*sizeof(uint16)) #define LQUERY_FIRST(x) ( (lquery_level*)( ((char*)(x))+LQUERY_HDRSIZE ) ) #define LQUERY_HASNOT 0x01 @@ -105,12 +105,12 @@ typedef struct ITEM */ typedef struct { - int4 len; + int32 vl_len_; /* varlena header (do not touch directly!) */ int4 size; char data[1]; } ltxtquery; -#define HDRSIZEQT MAXALIGN( 2*sizeof(int4) ) +#define HDRSIZEQT MAXALIGN(VARHDRSZ + sizeof(int4)) #define COMPUTESIZE(size,lenofoperand) ( HDRSIZEQT + (size) * sizeof(ITEM) + (lenofoperand) ) #define GETQUERY(x) (ITEM*)( (char*)(x)+HDRSIZEQT ) #define GETOPERAND(x) ( (char*)GETQUERY(x) + ((ltxtquery*)x)->size * sizeof(ITEM) ) @@ -205,7 +205,7 @@ typedef unsigned char *BITVECP; typedef struct { - int4 len; + int32 vl_len_; /* varlena header (do not touch directly!) */ uint32 flag; char data[1]; } ltree_gist; @@ -214,14 +214,14 @@ typedef struct #define LTG_ALLTRUE 0x02 #define LTG_NORIGHT 0x04 -#define LTG_HDRSIZE MAXALIGN( sizeof(int4) + sizeof(uint32) ) +#define LTG_HDRSIZE MAXALIGN(VARHDRSZ + sizeof(uint32)) #define LTG_SIGN(x) ( (BITVECP)( ((char*)(x))+LTG_HDRSIZE ) ) #define LTG_NODE(x) ( (ltree*)( ((char*)(x))+LTG_HDRSIZE ) ) #define LTG_ISONENODE(x) ( ((ltree_gist*)(x))->flag & LTG_ONENODE ) #define LTG_ISALLTRUE(x) ( ((ltree_gist*)(x))->flag & LTG_ALLTRUE ) #define LTG_ISNORIGHT(x) ( ((ltree_gist*)(x))->flag & LTG_NORIGHT ) #define LTG_LNODE(x) ( (ltree*)( ( ((char*)(x))+LTG_HDRSIZE ) + ( LTG_ISALLTRUE(x) ? 0 : SIGLEN ) ) ) -#define LTG_RENODE(x) ( (ltree*)( ((char*)LTG_LNODE(x)) + LTG_LNODE(x)->len) ) +#define LTG_RENODE(x) ( (ltree*)( ((char*)LTG_LNODE(x)) + VARSIZE(LTG_LNODE(x))) ) #define LTG_RNODE(x) ( LTG_ISNORIGHT(x) ? LTG_LNODE(x) : LTG_RENODE(x) ) #define LTG_GETLNODE(x) ( LTG_ISONENODE(x) ? LTG_NODE(x) : LTG_LNODE(x) ) diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c index 0239c5fe99..b74110d8f5 100644 --- a/contrib/ltree/ltree_gist.c +++ b/contrib/ltree/ltree_gist.c @@ -1,7 +1,7 @@ /* * GiST support for ltree * Teodor Sigaev <teodor@stack.net> - * $PostgreSQL: pgsql/contrib/ltree/ltree_gist.c,v 1.19 2006/10/04 00:29:45 momjian Exp $ + * $PostgreSQL: pgsql/contrib/ltree/ltree_gist.c,v 1.20 2007/02/28 22:44:38 tgl Exp $ */ #include "ltree.h" @@ -71,12 +71,12 @@ ltree_compress(PG_FUNCTION_ARGS) { /* ltree */ ltree_gist *key; ltree *val = (ltree *) DatumGetPointer(PG_DETOAST_DATUM(entry->key)); - int4 len = LTG_HDRSIZE + val->len; + int4 len = LTG_HDRSIZE + VARSIZE(val); key = (ltree_gist *) palloc(len); - key->len = len; + SET_VARSIZE(key, len); key->flag = LTG_ONENODE; - memcpy((void *) LTG_NODE(key), (void *) val, val->len); + memcpy((void *) LTG_NODE(key), (void *) val, VARSIZE(val)); retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); gistentryinit(*retval, PointerGetDatum(key), @@ -225,10 +225,10 @@ ltree_union(PG_FUNCTION_ARGS) } isleqr = (left == right || ISEQ(left, right)) ? true : false; - *size = LTG_HDRSIZE + ((isalltrue) ? 0 : SIGLEN) + left->len + ((isleqr) ? 0 : right->len); + *size = LTG_HDRSIZE + ((isalltrue) ? 0 : SIGLEN) + VARSIZE(left) + ((isleqr) ? 0 : VARSIZE(right)); result = (ltree_gist *) palloc(*size); - result->len = *size; + SET_VARSIZE(result, *size); result->flag = 0; if (isalltrue) @@ -236,11 +236,11 @@ ltree_union(PG_FUNCTION_ARGS) else memcpy((void *) LTG_SIGN(result), base, SIGLEN); - memcpy((void *) LTG_LNODE(result), (void *) left, left->len); + memcpy((void *) LTG_LNODE(result), (void *) left, VARSIZE(left)); if (isleqr) result->flag |= LTG_NORIGHT; else - memcpy((void *) LTG_RNODE(result), (void *) right, right->len); + memcpy((void *) LTG_RNODE(result), (void *) right, VARSIZE(right)); PG_RETURN_POINTER(result); } @@ -399,36 +399,36 @@ ltree_picksplit(PG_FUNCTION_ARGS) lu_l = LTG_GETLNODE(GETENTRY(entryvec, array[FirstOffsetNumber].index)); isleqr = (lu_l == lu_r || ISEQ(lu_l, lu_r)) ? true : false; - size = LTG_HDRSIZE + ((lisat) ? 0 : SIGLEN) + lu_l->len + ((isleqr) ? 0 : lu_r->len); + size = LTG_HDRSIZE + ((lisat) ? 0 : SIGLEN) + VARSIZE(lu_l) + ((isleqr) ? 0 : VARSIZE(lu_r)); lu = (ltree_gist *) palloc(size); - lu->len = size; + SET_VARSIZE(lu, size); lu->flag = 0; if (lisat) lu->flag |= LTG_ALLTRUE; else memcpy((void *) LTG_SIGN(lu), ls, SIGLEN); - memcpy((void *) LTG_LNODE(lu), (void *) lu_l, lu_l->len); + memcpy((void *) LTG_LNODE(lu), (void *) lu_l, VARSIZE(lu_l)); if (isleqr) lu->flag |= LTG_NORIGHT; else - memcpy((void *) LTG_RNODE(lu), (void *) lu_r, lu_r->len); + memcpy((void *) LTG_RNODE(lu), (void *) lu_r, VARSIZE(lu_r)); ru_l = LTG_GETLNODE(GETENTRY(entryvec, array[1 + ((maxoff - FirstOffsetNumber + 1) / 2)].index)); isleqr = (ru_l == ru_r || ISEQ(ru_l, ru_r)) ? true : false; - size = LTG_HDRSIZE + ((risat) ? 0 : SIGLEN) + ru_l->len + ((isleqr) ? 0 : ru_r->len); + size = LTG_HDRSIZE + ((risat) ? 0 : SIGLEN) + VARSIZE(ru_l) + ((isleqr) ? 0 : VARSIZE(ru_r)); ru = (ltree_gist *) palloc(size); - ru->len = size; + SET_VARSIZE(ru, size); ru->flag = 0; if (risat) ru->flag |= LTG_ALLTRUE; else memcpy((void *) LTG_SIGN(ru), rs, SIGLEN); - memcpy((void *) LTG_LNODE(ru), (void *) ru_l, ru_l->len); + memcpy((void *) LTG_LNODE(ru), (void *) ru_l, VARSIZE(ru_l)); if (isleqr) ru->flag |= LTG_NORIGHT; else - memcpy((void *) LTG_RNODE(ru), (void *) ru_r, ru_r->len); + memcpy((void *) LTG_RNODE(ru), (void *) ru_r, VARSIZE(ru_r)); v->spl_ldatum = PointerGetDatum(lu); v->spl_rdatum = PointerGetDatum(ru); @@ -459,9 +459,9 @@ gist_isparent(ltree_gist * key, ltree * query) static ltree * copy_ltree(ltree * src) { - ltree *dst = (ltree *) palloc(src->len); + ltree *dst = (ltree *) palloc(VARSIZE(src)); - memcpy(dst, src, src->len); + memcpy(dst, src, VARSIZE(src)); return dst; } diff --git a/contrib/ltree/ltree_io.c b/contrib/ltree/ltree_io.c index eb22894079..a6cb357d27 100644 --- a/contrib/ltree/ltree_io.c +++ b/contrib/ltree/ltree_io.c @@ -1,7 +1,7 @@ /* * in/out function for ltree and lquery * Teodor Sigaev <teodor@stack.net> - * $PostgreSQL: pgsql/contrib/ltree/ltree_io.c,v 1.13 2006/09/22 21:39:57 tgl Exp $ + * $PostgreSQL: pgsql/contrib/ltree/ltree_io.c,v 1.14 2007/02/28 22:44:38 tgl Exp $ */ #include "ltree.h" @@ -119,7 +119,7 @@ ltree_in(PG_FUNCTION_ARGS) errdetail("Unexpected end of line."))); result = (ltree *) palloc(LTREE_HDRSIZE + totallen); - result->len = LTREE_HDRSIZE + totallen; + SET_VARSIZE(result, LTREE_HDRSIZE + totallen); result->numlevel = lptr - list; curlevel = LTREE_FIRST(result); lptr = list; @@ -144,7 +144,7 @@ ltree_out(PG_FUNCTION_ARGS) int i; ltree_level *curlevel; - ptr = buf = (char *) palloc(in->len); + ptr = buf = (char *) palloc(VARSIZE(in)); curlevel = LTREE_FIRST(in); for (i = 0; i < in->numlevel; i++) { @@ -449,7 +449,7 @@ lquery_in(PG_FUNCTION_ARGS) } result = (lquery *) palloc(totallen); - result->len = totallen; + SET_VARSIZE(result, totallen); result->numlevel = num; result->firstgood = 0; result->flag = 0; diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c index 5f80394a71..be2733273f 100644 --- a/contrib/ltree/ltree_op.c +++ b/contrib/ltree/ltree_op.c @@ -1,7 +1,7 @@ /* * op function for ltree * Teodor Sigaev <teodor@stack.net> - * $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.15 2007/02/27 23:48:06 tgl Exp $ + * $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.16 2007/02/28 22:44:38 tgl Exp $ */ #include "ltree.h" @@ -230,7 +230,7 @@ inner_subltree(ltree * t, int4 startpos, int4 endpos) } res = (ltree *) palloc(LTREE_HDRSIZE + (end - start)); - res->len = LTREE_HDRSIZE + (end - start); + SET_VARSIZE(res, LTREE_HDRSIZE + (end - start)); res->numlevel = endpos - startpos; memcpy(LTREE_FIRST(res), start, end - start); @@ -286,13 +286,14 @@ ltree_concat(ltree * a, ltree * b) { ltree *r; - r = (ltree *) palloc(a->len + b->len - LTREE_HDRSIZE); - r->len = a->len + b->len - LTREE_HDRSIZE; + r = (ltree *) palloc(VARSIZE(a) + VARSIZE(b) - LTREE_HDRSIZE); + SET_VARSIZE(r, VARSIZE(a) + VARSIZE(b) - LTREE_HDRSIZE); r->numlevel = a->numlevel + b->numlevel; - memcpy(LTREE_FIRST(r), LTREE_FIRST(a), a->len - LTREE_HDRSIZE); - memcpy(((char *) LTREE_FIRST(r)) + a->len - LTREE_HDRSIZE, LTREE_FIRST(b), b->len - - LTREE_HDRSIZE); + memcpy(LTREE_FIRST(r), LTREE_FIRST(a), VARSIZE(a) - LTREE_HDRSIZE); + memcpy(((char *) LTREE_FIRST(r)) + VARSIZE(a) - LTREE_HDRSIZE, + LTREE_FIRST(b), + VARSIZE(b) - LTREE_HDRSIZE); return r; } @@ -476,7 +477,7 @@ lca_inner(ltree ** a, int len) } res = (ltree *) palloc(reslen); - res->len = reslen; + SET_VARSIZE(res, reslen); res->numlevel = num; l1 = LTREE_FIRST(*a); @@ -542,7 +543,7 @@ ltree2text(PG_FUNCTION_ARGS) ltree_level *curlevel; text *out; - out = (text *) palloc(in->len + VARHDRSZ); + out = (text *) palloc(VARSIZE(in) + VARHDRSZ); ptr = VARDATA(out); curlevel = LTREE_FIRST(in); for (i = 0; i < in->numlevel; i++) diff --git a/contrib/ltree/ltxtquery_io.c b/contrib/ltree/ltxtquery_io.c index ca6325adf7..904d4490dc 100644 --- a/contrib/ltree/ltxtquery_io.c +++ b/contrib/ltree/ltxtquery_io.c @@ -1,7 +1,7 @@ /* * txtquery io * Teodor Sigaev <teodor@stack.net> - * $PostgreSQL: pgsql/contrib/ltree/ltxtquery_io.c,v 1.12 2006/09/22 21:39:57 tgl Exp $ + * $PostgreSQL: pgsql/contrib/ltree/ltxtquery_io.c,v 1.13 2007/02/28 22:44:38 tgl Exp $ */ #include "ltree.h" @@ -337,7 +337,7 @@ queryin(char *buf) /* make finish struct */ commonlen = COMPUTESIZE(state.num, state.sumlen); query = (ltxtquery *) palloc(commonlen); - query->len = commonlen; + SET_VARSIZE(query, commonlen); query->size = state.num; ptr = GETQUERY(query); |
