aboutsummaryrefslogtreecommitdiff
path: root/contrib/intarray
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-02-28 22:44:38 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-02-28 22:44:38 +0000
commit9f652d430fbd1e757caaec9fe64d3e94c8693158 (patch)
tree9215d2131d85e73caeb96fe23ba442c17b8d4575 /contrib/intarray
parentd1ce4f7396aac34233e075d0342ac704593799ce (diff)
downloadpostgresql-9f652d430fbd1e757caaec9fe64d3e94c8693158.tar.gz
postgresql-9f652d430fbd1e757caaec9fe64d3e94c8693158.zip
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/intarray')
-rw-r--r--contrib/intarray/_int.h8
-rw-r--r--contrib/intarray/_int_bool.c2
-rw-r--r--contrib/intarray/_intbig_gist.c18
3 files changed, 14 insertions, 14 deletions
diff --git a/contrib/intarray/_int.h b/contrib/intarray/_int.h
index cee970d1b1f..97e6fe642fc 100644
--- a/contrib/intarray/_int.h
+++ b/contrib/intarray/_int.h
@@ -85,7 +85,7 @@ typedef char *BITVECP;
*/
typedef struct
{
- int4 len;
+ int32 vl_len_; /* varlena header (do not touch directly!) */
int4 flag;
char data[1];
} GISTTYPE;
@@ -94,7 +94,7 @@ typedef struct
#define ISALLTRUE(x) ( ((GISTTYPE*)x)->flag & ALLISTRUE )
-#define GTHDRSIZE ( sizeof(int4)*2 )
+#define GTHDRSIZE (VARHDRSZ + sizeof(int4))
#define CALCGTSIZE(flag) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )
#define GETSIGN(x) ( (BITVECP)( (char*)x+GTHDRSIZE ) )
@@ -145,12 +145,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) ( HDRSIZEQT + size * sizeof(ITEM) )
#define GETQUERY(x) (ITEM*)( (char*)(x)+HDRSIZEQT )
diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c
index b6a5d1b1e89..2a9d80bfdbc 100644
--- a/contrib/intarray/_int_bool.c
+++ b/contrib/intarray/_int_bool.c
@@ -465,7 +465,7 @@ bqarr_in(PG_FUNCTION_ARGS)
commonlen = COMPUTESIZE(state.num);
query = (QUERYTYPE *) palloc(commonlen);
- query->len = commonlen;
+ SET_VARSIZE(query, commonlen);
query->size = state.num;
ptr = GETQUERY(query);
diff --git a/contrib/intarray/_intbig_gist.c b/contrib/intarray/_intbig_gist.c
index cb80d8f6f24..ffbbe71a956 100644
--- a/contrib/intarray/_intbig_gist.c
+++ b/contrib/intarray/_intbig_gist.c
@@ -147,7 +147,7 @@ g_intbig_compress(PG_FUNCTION_ARGS)
ArrayType *in = (ArrayType *) PG_DETOAST_DATUM(entry->key);
int4 *ptr;
int num;
- GISTTYPE *res = (GISTTYPE *) palloc(CALCGTSIZE(0));
+ GISTTYPE *res = (GISTTYPE *) palloc0(CALCGTSIZE(0));
CHECKARRVALID(in);
if (ARRISVOID(in))
@@ -160,8 +160,7 @@ g_intbig_compress(PG_FUNCTION_ARGS)
ptr = ARRPTR(in);
num = ARRNELEMS(in);
}
- memset(res, 0, CALCGTSIZE(0));
- res->len = CALCGTSIZE(0);
+ SET_VARSIZE(res, CALCGTSIZE(0));
while (num--)
{
@@ -192,7 +191,7 @@ g_intbig_compress(PG_FUNCTION_ARGS)
);
res = (GISTTYPE *) palloc(CALCGTSIZE(ALLISTRUE));
- res->len = CALCGTSIZE(ALLISTRUE);
+ SET_VARSIZE(res, CALCGTSIZE(ALLISTRUE));
res->flag = ALLISTRUE;
retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
@@ -292,10 +291,11 @@ g_intbig_union(PG_FUNCTION_ARGS)
len = CALCGTSIZE(flag);
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);
}
@@ -389,26 +389,26 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
if (ISALLTRUE(GETENTRY(entryvec, seed_1)))
{
datum_l = (GISTTYPE *) palloc(GTHDRSIZE);
- datum_l->len = GTHDRSIZE;
+ SET_VARSIZE(datum_l, GTHDRSIZE);
datum_l->flag = ALLISTRUE;
}
else
{
datum_l = (GISTTYPE *) palloc(GTHDRSIZE + SIGLEN);
- datum_l->len = GTHDRSIZE + SIGLEN;
+ SET_VARSIZE(datum_l, GTHDRSIZE + SIGLEN);
datum_l->flag = 0;
memcpy((void *) GETSIGN(datum_l), (void *) GETSIGN(GETENTRY(entryvec, seed_1)), sizeof(BITVEC));
}
if (ISALLTRUE(GETENTRY(entryvec, seed_2)))
{
datum_r = (GISTTYPE *) palloc(GTHDRSIZE);
- datum_r->len = GTHDRSIZE;
+ SET_VARSIZE(datum_r, GTHDRSIZE);
datum_r->flag = ALLISTRUE;
}
else
{
datum_r = (GISTTYPE *) palloc(GTHDRSIZE + SIGLEN);
- datum_r->len = GTHDRSIZE + SIGLEN;
+ SET_VARSIZE(datum_r, GTHDRSIZE + SIGLEN);
datum_r->flag = 0;
memcpy((void *) GETSIGN(datum_r), (void *) GETSIGN(GETENTRY(entryvec, seed_2)), sizeof(BITVEC));
}