1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Replace int2/int4 in C code with int16/int32

The latter was already the dominant use, and it's preferable because
in C the convention is that intXX means XX bits.  Therefore, allowing
mixed use of int2, int4, int8, int16, int32 is obviously confusing.

Remove the typedefs for int2 and int4 for now.  They don't seem to be
widely used outside of the PostgreSQL source tree, and the few uses
can probably be cleaned up by the time this ships.
This commit is contained in:
Peter Eisentraut
2012-06-25 01:51:46 +03:00
parent 7eb8c78514
commit b8b2e3b2de
75 changed files with 411 additions and 404 deletions

View File

@ -10,7 +10,7 @@
#define MAXNUMRANGE 100
/* useful macros for accessing int4 arrays */
#define ARRPTR(x) ( (int4 *) ARR_DATA_PTR(x) )
#define ARRPTR(x) ( (int32 *) ARR_DATA_PTR(x) )
#define ARRNELEMS(x) ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x))
/* reject arrays we can't handle; to wit, those containing nulls */
@ -71,7 +71,7 @@ typedef char *BITVECP;
typedef struct
{
int32 vl_len_; /* varlena header (do not touch directly!) */
int4 flag;
int32 flag;
char data[1];
} GISTTYPE;
@ -79,7 +79,7 @@ typedef struct
#define ISALLTRUE(x) ( ((GISTTYPE*)x)->flag & ALLISTRUE )
#define GTHDRSIZE (VARHDRSZ + sizeof(int4))
#define GTHDRSIZE (VARHDRSZ + sizeof(int32))
#define CALCGTSIZE(flag) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )
#define GETSIGN(x) ( (BITVECP)( (char*)x+GTHDRSIZE ) )
@ -93,7 +93,7 @@ typedef void (*formfloat) (ArrayType *, float *);
/*
* useful functions
*/
bool isort(int4 *a, int len);
bool isort(int32 *a, int len);
ArrayType *new_intArrayType(int num);
ArrayType *copy_intArrayType(ArrayType *a);
ArrayType *resize_intArrayType(ArrayType *a, int num);
@ -123,15 +123,15 @@ void gensign(BITVEC sign, int *a, int len);
*/
typedef struct ITEM
{
int2 type;
int2 left;
int4 val;
int16 type;
int16 left;
int32 val;
} ITEM;
typedef struct QUERYTYPE
{
int32 vl_len_; /* varlena header (do not touch directly!) */
int4 size; /* number of ITEMs */
int32 size; /* number of ITEMs */
ITEM items[1]; /* variable length array */
} QUERYTYPE;
@ -167,7 +167,7 @@ int compDESC(const void *a, const void *b);
do { \
int _nelems_ = ARRNELEMS(a); \
if (_nelems_ > 1) \
qsort((void*) ARRPTR(a), _nelems_, sizeof(int4), \
qsort((void*) ARRPTR(a), _nelems_, sizeof(int32), \
(direction) ? compASC : compDESC ); \
} while(0)

View File

@ -34,27 +34,27 @@ Datum querytree(PG_FUNCTION_ARGS);
*/
typedef struct NODE
{
int4 type;
int4 val;
int32 type;
int32 val;
struct NODE *next;
} NODE;
typedef struct
{
char *buf;
int4 state;
int4 count;
int32 state;
int32 count;
/* reverse polish notation in list (for temporary usage) */
NODE *str;
/* number in str */
int4 num;
int32 num;
} WORKSTATE;
/*
* get token from query string
*/
static int4
gettoken(WORKSTATE *state, int4 *val)
static int32
gettoken(WORKSTATE *state, int32 *val)
{
char nnn[16];
int innn;
@ -79,7 +79,7 @@ gettoken(WORKSTATE *state, int4 *val)
else if (*(state->buf) == '!')
{
(state->buf)++;
*val = (int4) '!';
*val = (int32) '!';
return OPR;
}
else if (*(state->buf) == '(')
@ -103,7 +103,7 @@ gettoken(WORKSTATE *state, int4 *val)
nnn[innn] = '\0';
errno = 0;
lval = strtol(nnn, NULL, 0);
*val = (int4) lval;
*val = (int32) lval;
if (errno != 0 || (long) *val != lval)
return ERR;
state->state = WAITOPERATOR;
@ -115,7 +115,7 @@ gettoken(WORKSTATE *state, int4 *val)
if (*(state->buf) == '&' || *(state->buf) == '|')
{
state->state = WAITOPERAND;
*val = (int4) *(state->buf);
*val = (int32) *(state->buf);
(state->buf)++;
return OPR;
}
@ -143,7 +143,7 @@ gettoken(WORKSTATE *state, int4 *val)
* push new one in polish notation reverse view
*/
static void
pushquery(WORKSTATE *state, int4 type, int4 val)
pushquery(WORKSTATE *state, int32 type, int32 val)
{
NODE *tmp = (NODE *) palloc(sizeof(NODE));
@ -159,13 +159,13 @@ pushquery(WORKSTATE *state, int4 type, int4 val)
/*
* make polish notation of query
*/
static int4
static int32
makepol(WORKSTATE *state)
{
int4 val,
int32 val,
type;
int4 stack[STACKDEPTH];
int4 lenstack = 0;
int32 stack[STACKDEPTH];
int32 lenstack = 0;
/* since this function recurses, it could be driven to stack overflow */
check_stack_depth();
@ -176,15 +176,15 @@ makepol(WORKSTATE *state)
{
case VAL:
pushquery(state, type, val);
while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
stack[lenstack - 1] == (int4) '!'))
while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
stack[lenstack - 1] == (int32) '!'))
{
lenstack--;
pushquery(state, OPR, stack[lenstack]);
}
break;
case OPR:
if (lenstack && val == (int4) '|')
if (lenstack && val == (int32) '|')
pushquery(state, OPR, val);
else
{
@ -199,8 +199,8 @@ makepol(WORKSTATE *state)
case OPEN:
if (makepol(state) == ERR)
return ERR;
while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
stack[lenstack - 1] == (int4) '!'))
while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
stack[lenstack - 1] == (int32) '!'))
{
lenstack--;
pushquery(state, OPR, stack[lenstack]);
@ -234,8 +234,8 @@ makepol(WORKSTATE *state)
typedef struct
{
int4 *arrb;
int4 *arre;
int32 *arrb;
int32 *arre;
} CHKVAL;
/*
@ -244,9 +244,9 @@ typedef struct
static bool
checkcondition_arr(void *checkval, ITEM *item)
{
int4 *StopLow = ((CHKVAL *) checkval)->arrb;
int4 *StopHigh = ((CHKVAL *) checkval)->arre;
int4 *StopMiddle;
int32 *StopLow = ((CHKVAL *) checkval)->arrb;
int32 *StopHigh = ((CHKVAL *) checkval)->arre;
int32 *StopMiddle;
/* Loop invariant: StopLow <= val < StopHigh */
@ -281,13 +281,13 @@ execute(ITEM *curitem, void *checkval, bool calcnot,
if (curitem->type == VAL)
return (*chkcond) (checkval, curitem);
else if (curitem->val == (int4) '!')
else if (curitem->val == (int32) '!')
{
return (calcnot) ?
((execute(curitem - 1, checkval, calcnot, chkcond)) ? false : true)
: true;
}
else if (curitem->val == (int4) '&')
else if (curitem->val == (int32) '&')
{
if (execute(curitem + curitem->left, checkval, calcnot, chkcond))
return execute(curitem - 1, checkval, calcnot, chkcond);
@ -379,7 +379,7 @@ contains_required_value(ITEM *curitem)
if (curitem->type == VAL)
return true;
else if (curitem->val == (int4) '!')
else if (curitem->val == (int32) '!')
{
/*
* Assume anything under a NOT is non-required. For some cases with
@ -388,7 +388,7 @@ contains_required_value(ITEM *curitem)
*/
return false;
}
else if (curitem->val == (int4) '&')
else if (curitem->val == (int32) '&')
{
/* If either side has a required value, we're good */
if (contains_required_value(curitem + curitem->left))
@ -449,7 +449,7 @@ boolop(PG_FUNCTION_ARGS)
}
static void
findoprnd(ITEM *ptr, int4 *pos)
findoprnd(ITEM *ptr, int32 *pos)
{
#ifdef BS_DEBUG
elog(DEBUG3, (ptr[*pos].type == OPR) ?
@ -460,7 +460,7 @@ findoprnd(ITEM *ptr, int4 *pos)
ptr[*pos].left = 0;
(*pos)--;
}
else if (ptr[*pos].val == (int4) '!')
else if (ptr[*pos].val == (int32) '!')
{
ptr[*pos].left = -1;
(*pos)--;
@ -469,7 +469,7 @@ findoprnd(ITEM *ptr, int4 *pos)
else
{
ITEM *curitem = &ptr[*pos];
int4 tmp = *pos;
int32 tmp = *pos;
(*pos)--;
findoprnd(ptr, pos);
@ -487,12 +487,12 @@ bqarr_in(PG_FUNCTION_ARGS)
{
char *buf = (char *) PG_GETARG_POINTER(0);
WORKSTATE state;
int4 i;
int32 i;
QUERYTYPE *query;
int4 commonlen;
int32 commonlen;
ITEM *ptr;
NODE *tmp;
int4 pos = 0;
int32 pos = 0;
#ifdef BS_DEBUG
StringInfoData pbuf;
@ -553,11 +553,11 @@ typedef struct
ITEM *curpol;
char *buf;
char *cur;
int4 buflen;
int32 buflen;
} INFIX;
#define RESIZEBUF(inf,addsize) while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) { \
int4 len = inf->cur - inf->buf; \
int32 len = inf->cur - inf->buf; \
inf->buflen *= 2; \
inf->buf = (char*) repalloc( (void*)inf->buf, inf->buflen ); \
inf->cur = inf->buf + len; \
@ -573,7 +573,7 @@ infix(INFIX *in, bool first)
in->cur = strchr(in->cur, '\0');
in->curpol--;
}
else if (in->curpol->val == (int4) '!')
else if (in->curpol->val == (int32) '!')
{
bool isopr = false;
@ -599,11 +599,11 @@ infix(INFIX *in, bool first)
}
else
{
int4 op = in->curpol->val;
int32 op = in->curpol->val;
INFIX nrm;
in->curpol--;
if (op == (int4) '|' && !first)
if (op == (int32) '|' && !first)
{
RESIZEBUF(in, 2);
sprintf(in->cur, "( ");
@ -627,7 +627,7 @@ infix(INFIX *in, bool first)
in->cur = strchr(in->cur, '\0');
pfree(nrm.buf);
if (op == (int4) '|' && !first)
if (op == (int32) '|' && !first)
{
RESIZEBUF(in, 2);
sprintf(in->cur, " )");

View File

@ -65,7 +65,7 @@ ginint4_queryextract(PG_FUNCTION_ARGS)
*nentries = ARRNELEMS(query);
if (*nentries > 0)
{
int4 *arr;
int32 *arr;
int32 i;
res = (Datum *) palloc(sizeof(Datum) * (*nentries));

View File

@ -106,7 +106,7 @@ g_int_union(PG_FUNCTION_ARGS)
{
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *size = (int *) PG_GETARG_POINTER(1);
int4 i,
int32 i,
*ptr;
ArrayType *res;
int totlen = 0;
@ -128,7 +128,7 @@ g_int_union(PG_FUNCTION_ARGS)
int nel;
nel = ARRNELEMS(ent);
memcpy(ptr, ARRPTR(ent), nel * sizeof(int4));
memcpy(ptr, ARRPTR(ent), nel * sizeof(int32));
ptr += nel;
}
@ -317,8 +317,8 @@ g_int_same(PG_FUNCTION_ARGS)
ArrayType *a = PG_GETARG_ARRAYTYPE_P(0);
ArrayType *b = PG_GETARG_ARRAYTYPE_P(1);
bool *result = (bool *) PG_GETARG_POINTER(2);
int4 n = ARRNELEMS(a);
int4 *da,
int32 n = ARRNELEMS(a);
int32 *da,
*db;
CHECKARRVALID(a);

View File

@ -186,11 +186,11 @@ rt__int_size(ArrayType *a, float *size)
/* Sort the given data (len >= 2). Return true if any duplicates found */
bool
isort(int4 *a, int len)
isort(int32 *a, int len)
{
int4 cur,
int32 cur,
prev;
int4 *pcur,
int32 *pcur,
*pprev,
*end;
bool r = FALSE;
@ -268,7 +268,7 @@ copy_intArrayType(ArrayType *a)
int n = ARRNELEMS(a);
r = new_intArrayType(n);
memcpy(ARRPTR(r), ARRPTR(a), n * sizeof(int4));
memcpy(ARRPTR(r), ARRPTR(a), n * sizeof(int32));
return r;
}
@ -389,15 +389,15 @@ int_to_intset(int32 n)
int
compASC(const void *a, const void *b)
{
if (*(const int4 *) a == *(const int4 *) b)
if (*(const int32 *) a == *(const int32 *) b)
return 0;
return (*(const int4 *) a > *(const int4 *) b) ? 1 : -1;
return (*(const int32 *) a > *(const int32 *) b) ? 1 : -1;
}
int
compDESC(const void *a, const void *b)
{
if (*(const int4 *) a == *(const int4 *) b)
if (*(const int32 *) a == *(const int32 *) b)
return 0;
return (*(const int4 *) a < *(const int4 *) b) ? 1 : -1;
return (*(const int32 *) a < *(const int32 *) b) ? 1 : -1;
}

View File

@ -81,7 +81,7 @@ static bool
_intbig_overlap(GISTTYPE *a, ArrayType *b)
{
int num = ARRNELEMS(b);
int4 *ptr = ARRPTR(b);
int32 *ptr = ARRPTR(b);
CHECKARRVALID(b);
@ -99,7 +99,7 @@ static bool
_intbig_contains(GISTTYPE *a, ArrayType *b)
{
int num = ARRNELEMS(b);
int4 *ptr = ARRPTR(b);
int32 *ptr = ARRPTR(b);
CHECKARRVALID(b);
@ -128,7 +128,7 @@ g_intbig_same(PG_FUNCTION_ARGS)
*result = false;
else
{
int4 i;
int32 i;
BITVECP sa = GETSIGN(a),
sb = GETSIGN(b);
@ -154,7 +154,7 @@ g_intbig_compress(PG_FUNCTION_ARGS)
{
GISTENTRY *retval;
ArrayType *in = DatumGetArrayTypeP(entry->key);
int4 *ptr;
int32 *ptr;
int num;
GISTTYPE *res = (GISTTYPE *) palloc0(CALCGTSIZE(0));
@ -216,10 +216,10 @@ g_intbig_compress(PG_FUNCTION_ARGS)
}
static int4
static int32
sizebitvec(BITVECP sign)
{
int4 size = 0,
int32 size = 0,
i;
LOOPBYTE
@ -264,10 +264,10 @@ g_intbig_decompress(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(PG_GETARG_DATUM(0));
}
static int4
static int32
unionkey(BITVECP sbase, GISTTYPE *add)
{
int4 i;
int32 i;
BITVECP sadd = GETSIGN(add);
if (ISALLTRUE(add))
@ -283,9 +283,9 @@ g_intbig_union(PG_FUNCTION_ARGS)
GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
int *size = (int *) PG_GETARG_POINTER(1);
BITVEC base;
int4 i,
int32 i,
len;
int4 flag = 0;
int32 flag = 0;
GISTTYPE *result;
MemSet((void *) base, 0, sizeof(BITVEC));
@ -326,7 +326,7 @@ g_intbig_penalty(PG_FUNCTION_ARGS)
typedef struct
{
OffsetNumber pos;
int4 cost;
int32 cost;
} SPLITCOST;
static int
@ -347,11 +347,11 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
*datum_r;
BITVECP union_l,
union_r;
int4 size_alpha,
int32 size_alpha,
size_beta;
int4 size_waste,
int32 size_waste,
waste = -1;
int4 nbytes;
int32 nbytes;
OffsetNumber seed_1 = 0,
seed_2 = 0;
OffsetNumber *left,
@ -538,7 +538,7 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
{
int i,
num = ARRNELEMS(query);
int4 *ptr = ARRPTR(query);
int32 *ptr = ARRPTR(query);
BITVEC qp;
BITVECP dq,
de;
@ -577,7 +577,7 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
{
int i,
num = ARRNELEMS(query);
int4 *ptr = ARRPTR(query);
int32 *ptr = ARRPTR(query);
BITVEC qp;
BITVECP dq,
de;