mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
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.
This commit is contained in:
@ -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 )
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user