diff options
| author | Tom Lane | 2007-02-28 22:44:38 +0000 |
|---|---|---|
| committer | Tom Lane | 2007-02-28 22:44:38 +0000 |
| commit | 9f652d430fbd1e757caaec9fe64d3e94c8693158 (patch) | |
| tree | 9215d2131d85e73caeb96fe23ba442c17b8d4575 /contrib/tsearch2 | |
| parent | d1ce4f7396aac34233e075d0342ac704593799ce (diff) | |
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/tsearch2')
| -rw-r--r-- | contrib/tsearch2/gistidx.c | 23 | ||||
| -rw-r--r-- | contrib/tsearch2/gistidx.h | 8 | ||||
| -rw-r--r-- | contrib/tsearch2/query.c | 8 | ||||
| -rw-r--r-- | contrib/tsearch2/query.h | 4 | ||||
| -rw-r--r-- | contrib/tsearch2/query_rewrite.c | 16 | ||||
| -rw-r--r-- | contrib/tsearch2/query_support.c | 4 | ||||
| -rw-r--r-- | contrib/tsearch2/query_util.c | 2 |
7 files changed, 33 insertions, 32 deletions
diff --git a/contrib/tsearch2/gistidx.c b/contrib/tsearch2/gistidx.c index a4d9b2312ed..14fdecb0b8d 100644 --- a/contrib/tsearch2/gistidx.c +++ b/contrib/tsearch2/gistidx.c @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/contrib/tsearch2/gistidx.c,v 1.15 2006/10/04 00:29:46 momjian Exp $ */ +/* $PostgreSQL: pgsql/contrib/tsearch2/gistidx.c,v 1.16 2007/02/28 22:44:38 tgl Exp $ */ #include "postgres.h" @@ -163,7 +163,7 @@ gtsvector_compress(PG_FUNCTION_ARGS) len = CALCGTSIZE(ARRKEY, val->size); res = (GISTTYPE *) palloc(len); - res->len = len; + SET_VARSIZE(res, len); res->flag = ARRKEY; arr = GETARR(res); len = val->size; @@ -183,17 +183,17 @@ gtsvector_compress(PG_FUNCTION_ARGS) */ len = CALCGTSIZE(ARRKEY, len); res = (GISTTYPE *) repalloc((void *) res, len); - res->len = len; + SET_VARSIZE(res, len); } /* make signature, if array is too long */ - if (res->len > TOAST_INDEX_TARGET) + if (VARSIZE(res) > TOAST_INDEX_TARGET) { GISTTYPE *ressign; len = CALCGTSIZE(SIGNKEY, 0); ressign = (GISTTYPE *) palloc(len); - ressign->len = len; + SET_VARSIZE(ressign, len); ressign->flag = SIGNKEY; makesign(GETSIGN(ressign), res); res = ressign; @@ -219,7 +219,7 @@ gtsvector_compress(PG_FUNCTION_ARGS) len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0); res = (GISTTYPE *) palloc(len); - res->len = len; + SET_VARSIZE(res, len); res->flag = SIGNKEY | ALLISTRUE; retval = (GISTENTRY *) palloc(sizeof(GISTENTRY)); @@ -375,10 +375,11 @@ gtsvector_union(PG_FUNCTION_ARGS) flag |= SIGNKEY; len = CALCGTSIZE(flag, 0); result = (GISTTYPE *) palloc(len); - *size = result->len = len; + SET_VARSIZE(result, len); result->flag = flag; if (!ISALLTRUE(result)) memcpy((void *) GETSIGN(result), (void *) base, sizeof(BITVEC)); + *size = len; PG_RETURN_POINTER(result); } @@ -627,26 +628,26 @@ gtsvector_picksplit(PG_FUNCTION_ARGS) if (cache[seed_1].allistrue) { datum_l = (GISTTYPE *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0)); - datum_l->len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0); + SET_VARSIZE(datum_l, CALCGTSIZE(SIGNKEY | ALLISTRUE, 0)); datum_l->flag = SIGNKEY | ALLISTRUE; } else { datum_l = (GISTTYPE *) palloc(CALCGTSIZE(SIGNKEY, 0)); - datum_l->len = CALCGTSIZE(SIGNKEY, 0); + SET_VARSIZE(datum_l, CALCGTSIZE(SIGNKEY, 0)); datum_l->flag = SIGNKEY; memcpy((void *) GETSIGN(datum_l), (void *) cache[seed_1].sign, sizeof(BITVEC)); } if (cache[seed_2].allistrue) { datum_r = (GISTTYPE *) palloc(CALCGTSIZE(SIGNKEY | ALLISTRUE, 0)); - datum_r->len = CALCGTSIZE(SIGNKEY | ALLISTRUE, 0); + SET_VARSIZE(datum_r, CALCGTSIZE(SIGNKEY | ALLISTRUE, 0)); datum_r->flag = SIGNKEY | ALLISTRUE; } else { datum_r = (GISTTYPE *) palloc(CALCGTSIZE(SIGNKEY, 0)); - datum_r->len = CALCGTSIZE(SIGNKEY, 0); + SET_VARSIZE(datum_r, CALCGTSIZE(SIGNKEY, 0)); datum_r->flag = SIGNKEY; memcpy((void *) GETSIGN(datum_r), (void *) cache[seed_2].sign, sizeof(BITVEC)); } diff --git a/contrib/tsearch2/gistidx.h b/contrib/tsearch2/gistidx.h index 9545946e315..5362584b807 100644 --- a/contrib/tsearch2/gistidx.h +++ b/contrib/tsearch2/gistidx.h @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/contrib/tsearch2/gistidx.h,v 1.7 2006/03/11 04:38:30 momjian Exp $ */ +/* $PostgreSQL: pgsql/contrib/tsearch2/gistidx.h,v 1.8 2007/02/28 22:44:38 tgl Exp $ */ #ifndef __GISTIDX_H__ #define __GISTIDX_H__ @@ -39,7 +39,7 @@ typedef char *BITVECP; */ typedef struct { - int4 len; + int32 vl_len_; /* varlena header (do not touch directly!) */ int4 flag; char data[1]; } GISTTYPE; @@ -52,11 +52,11 @@ typedef struct #define ISSIGNKEY(x) ( ((GISTTYPE*)(x))->flag & SIGNKEY ) #define ISALLTRUE(x) ( ((GISTTYPE*)(x))->flag & ALLISTRUE ) -#define GTHDRSIZE ( sizeof(int4) * 2 ) +#define GTHDRSIZE ( VARHDRSZ + sizeof(int4) ) #define CALCGTSIZE(flag, len) ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int4)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) ) #define GETSIGN(x) ( (BITVECP)( (char*)(x)+GTHDRSIZE ) ) #define GETARR(x) ( (int4*)( (char*)(x)+GTHDRSIZE ) ) -#define ARRNELEM(x) ( ( ((GISTTYPE*)(x))->len - GTHDRSIZE )/sizeof(int4) ) +#define ARRNELEM(x) ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int4) ) #endif diff --git a/contrib/tsearch2/query.c b/contrib/tsearch2/query.c index eb2d30e1592..62a305ed1e8 100644 --- a/contrib/tsearch2/query.c +++ b/contrib/tsearch2/query.c @@ -658,7 +658,7 @@ static QUERYTYPE * (errmsg("tsearch query doesn't contain lexeme(s): \"%s\"", state.buffer))); query = (QUERYTYPE *) palloc(HDRSIZEQT); - query->len = HDRSIZEQT; + SET_VARSIZE(query, HDRSIZEQT); query->size = 0; return query; } @@ -666,7 +666,7 @@ static QUERYTYPE * /* make finish struct */ commonlen = COMPUTESIZE(state.num, state.sumlen); query = (QUERYTYPE *) palloc(commonlen); - query->len = commonlen; + SET_VARSIZE(query, commonlen); query->size = state.num; ptr = GETQUERY(query); @@ -961,7 +961,7 @@ to_tsquery(PG_FUNCTION_ARGS) res = clean_fakeval_v2(GETQUERY(query), &len); if (!res) { - query->len = HDRSIZEQT; + SET_VARSIZE(query, HDRSIZEQT); query->size = 0; PG_RETURN_POINTER(query); } @@ -1016,7 +1016,7 @@ plainto_tsquery(PG_FUNCTION_ARGS) res = clean_fakeval_v2(GETQUERY(query), &len); if (!res) { - query->len = HDRSIZEQT; + SET_VARSIZE(query, HDRSIZEQT); query->size = 0; PG_RETURN_POINTER(query); } diff --git a/contrib/tsearch2/query.h b/contrib/tsearch2/query.h index b4d586a684b..44f87012130 100644 --- a/contrib/tsearch2/query.h +++ b/contrib/tsearch2/query.h @@ -28,12 +28,12 @@ typedef struct ITEM */ typedef struct { - int4 len; + int32 vl_len_; /* varlena header (do not touch directly!) */ int4 size; char data[1]; } QUERYTYPE; -#define HDRSIZEQT ( 2 * sizeof(int4) ) +#define HDRSIZEQT ( 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) + ((QUERYTYPE*)(x))->size * sizeof(ITEM) ) diff --git a/contrib/tsearch2/query_rewrite.c b/contrib/tsearch2/query_rewrite.c index 63d8140a6c2..0604a49927a 100644 --- a/contrib/tsearch2/query_rewrite.c +++ b/contrib/tsearch2/query_rewrite.c @@ -250,7 +250,7 @@ rewrite_accum(PG_FUNCTION_ARGS) if (acc == NULL || PG_ARGISNULL(0)) { acc = (QUERYTYPE *) MEMALLOC(AggMemory, sizeof(QUERYTYPE)); - acc->len = HDRSIZEQT; + SET_VARSIZE(acc, HDRSIZEQT); acc->size = 0; } @@ -287,7 +287,7 @@ rewrite_accum(PG_FUNCTION_ARGS) if (!acc->size) { - if (acc->len > HDRSIZEQT) + if (VARSIZE(acc) > HDRSIZEQT) { pfree(elemsp); PG_RETURN_POINTER(acc); @@ -328,7 +328,7 @@ rewrite_accum(PG_FUNCTION_ARGS) else { acc = (QUERYTYPE *) MEMALLOC(AggMemory, HDRSIZEQT * 2); - acc->len = HDRSIZEQT * 2; + SET_VARSIZE(acc, HDRSIZEQT * 2); acc->size = 0; } } @@ -353,12 +353,12 @@ rewrite_finish(PG_FUNCTION_ARGS) if (acc == NULL || PG_ARGISNULL(0) || acc->size == 0) { acc = (QUERYTYPE *) palloc(sizeof(QUERYTYPE)); - acc->len = HDRSIZEQT; + SET_VARSIZE(acc, HDRSIZEQT); acc->size = 0; } - rewrited = (QUERYTYPE *) palloc(acc->len); - memcpy(rewrited, acc, acc->len); + rewrited = (QUERYTYPE *) palloc(VARSIZE(acc)); + memcpy(rewrited, acc, VARSIZE(acc)); pfree(acc); PG_RETURN_POINTER(rewrited); @@ -481,7 +481,7 @@ tsquery_rewrite(PG_FUNCTION_ARGS) } else { - rewrited->len = HDRSIZEQT; + SET_VARSIZE(rewrited, HDRSIZEQT); rewrited->size = 0; } @@ -529,7 +529,7 @@ tsquery_rewrite_query(PG_FUNCTION_ARGS) if (!tree) { - rewrited->len = HDRSIZEQT; + SET_VARSIZE(rewrited, HDRSIZEQT); rewrited->size = 0; PG_FREE_IF_COPY(ex, 1); PG_FREE_IF_COPY(subst, 2); diff --git a/contrib/tsearch2/query_support.c b/contrib/tsearch2/query_support.c index dfdd7140739..0fc6fe334d2 100644 --- a/contrib/tsearch2/query_support.c +++ b/contrib/tsearch2/query_support.c @@ -144,9 +144,9 @@ CompareTSQ(QUERYTYPE * a, QUERYTYPE * b) { return (a->size < b->size) ? -1 : 1; } - else if (a->len != b->len) + else if (VARSIZE(a) != VARSIZE(b)) { - return (a->len < b->len) ? -1 : 1; + return (VARSIZE(a) < VARSIZE(b)) ? -1 : 1; } else { diff --git a/contrib/tsearch2/query_util.c b/contrib/tsearch2/query_util.c index efa74fe053c..083d173d132 100644 --- a/contrib/tsearch2/query_util.c +++ b/contrib/tsearch2/query_util.c @@ -260,7 +260,7 @@ QTN2QT(QTNode * in, MemoryType memtype) len = COMPUTESIZE(nnode, sumlen); out = (QUERYTYPE *) MEMALLOC(memtype, len); - out->len = len; + SET_VARSIZE(out, len); out->size = nnode; state.curitem = GETQUERY(out); |
