mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-02-17 19:30:00 +08:00
Standardize on using the Min, Max, and Abs macros that are in our c.h file,
getting rid of numerous ad-hoc versions that have popped up in various places. Shortens code and avoids conflict with Windows min() and max() macros.
This commit is contained in:
parent
a171fc1a4f
commit
380bd04c16
@ -15,8 +15,6 @@
|
||||
|
||||
#include "cubedata.h"
|
||||
|
||||
#define abs(a) ((a) < (0) ? (-a) : (a))
|
||||
|
||||
extern int cube_yyparse();
|
||||
extern void cube_yyerror(const char *message);
|
||||
extern void cube_scanner_init(const char *str);
|
||||
@ -683,7 +681,7 @@ cube_size(NDBOX * a)
|
||||
|
||||
*result = 1.0;
|
||||
for (i = 0, j = a->dim; i < a->dim; i++, j++)
|
||||
*result = (*result) * abs((a->x[j] - a->x[i]));
|
||||
*result = (*result) * Abs((a->x[j] - a->x[i]));
|
||||
|
||||
return (result);
|
||||
}
|
||||
@ -700,7 +698,7 @@ rt_cube_size(NDBOX * a, double *size)
|
||||
{
|
||||
*size = 1.0;
|
||||
for (i = 0, j = a->dim; i < a->dim; i++, j++)
|
||||
*size = (*size) * abs((a->x[j] - a->x[i]));
|
||||
*size = (*size) * Abs((a->x[j] - a->x[i]));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -14,10 +14,6 @@
|
||||
/* number ranges for compression */
|
||||
#define MAXNUMRANGE 100
|
||||
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define min(a,b) ((a) <= (b) ? (a) : (b))
|
||||
#define abs(a) ((a) < (0) ? -(a) : (a))
|
||||
|
||||
/* dimension of array */
|
||||
#define NDIM 1
|
||||
|
||||
|
@ -425,7 +425,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
|
||||
union_d = inner_int_union(datum_r, datum_alpha);
|
||||
rt__int_size(union_d, &size_beta);
|
||||
pfree(union_d);
|
||||
costvector[i - 1].cost = abs((size_alpha - size_l) - (size_beta - size_r));
|
||||
costvector[i - 1].cost = Abs((size_alpha - size_l) - (size_beta - size_r));
|
||||
}
|
||||
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
|
||||
|
||||
|
@ -137,7 +137,7 @@ inner_int_inter(ArrayType *a, ArrayType *b)
|
||||
nb = ARRNELEMS(b);
|
||||
da = ARRPTR(a);
|
||||
db = ARRPTR(b);
|
||||
r = new_intArrayType(min(na, nb));
|
||||
r = new_intArrayType(Min(na, nb));
|
||||
dr = ARRPTR(r);
|
||||
|
||||
i = j = 0;
|
||||
|
@ -402,7 +402,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
|
||||
_j = GETENTRY(entryvec, j);
|
||||
size_alpha = hemdist(datum_l, _j);
|
||||
size_beta = hemdist(datum_r, _j);
|
||||
costvector[j - 1].cost = abs(size_alpha - size_beta);
|
||||
costvector[j - 1].cost = Abs(size_alpha - size_beta);
|
||||
}
|
||||
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
|
||||
|
||||
|
@ -361,7 +361,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
|
||||
_j = GETENTRY(entryvec, j);
|
||||
size_alpha = hemdist(datum_l, _j);
|
||||
size_beta = hemdist(datum_r, _j);
|
||||
costvector[j - 1].cost = abs(size_alpha - size_beta);
|
||||
costvector[j - 1].cost = Abs(size_alpha - size_beta);
|
||||
}
|
||||
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
|
||||
|
||||
|
@ -78,15 +78,6 @@ typedef struct
|
||||
|
||||
#define LQUERY_HASNOT 0x01
|
||||
|
||||
#ifndef max
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef min
|
||||
#define min(a,b) ((a) <= (b) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef abs
|
||||
#define abs(a) ((a) < (0) ? -(a) : (a))
|
||||
#endif
|
||||
#define ISALNUM(x) ( isalnum((unsigned char)(x)) || (x) == '_' )
|
||||
|
||||
/* full text query */
|
||||
|
@ -259,7 +259,7 @@ ltree_penalty(PG_FUNCTION_ARGS)
|
||||
cmpl = ltree_compare(LTG_GETLNODE(origval), LTG_GETLNODE(newval));
|
||||
cmpr = ltree_compare(LTG_GETRNODE(newval), LTG_GETRNODE(origval));
|
||||
|
||||
*penalty = max(cmpl, 0) + max(cmpr, 0);
|
||||
*penalty = Max(cmpl, 0) + Max(cmpr, 0);
|
||||
|
||||
PG_RETURN_POINTER(penalty);
|
||||
}
|
||||
@ -537,7 +537,7 @@ gist_tqcmp(ltree * t, lquery * q)
|
||||
while (an > 0 && bn > 0)
|
||||
{
|
||||
bl = LQL_FIRST(ql);
|
||||
if ((res = strncmp(al->name, bl->name, min(al->len, bl->len))) == 0)
|
||||
if ((res = strncmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
|
||||
{
|
||||
if (al->len != bl->len)
|
||||
return al->len - bl->len;
|
||||
|
@ -55,7 +55,7 @@ ltree_compare(const ltree * a, const ltree * b)
|
||||
|
||||
while (an > 0 && bn > 0)
|
||||
{
|
||||
if ((res = strncmp(al->name, bl->name, min(al->len, bl->len))) == 0)
|
||||
if ((res = strncmp(al->name, bl->name, Min(al->len, bl->len))) == 0)
|
||||
{
|
||||
if (al->len != bl->len)
|
||||
return (al->len - bl->len) * 10 * (an + 1);
|
||||
@ -443,7 +443,7 @@ lca_inner(ltree ** a, int len)
|
||||
l2 = LTREE_FIRST(*ptr);
|
||||
tmp = num;
|
||||
num = 0;
|
||||
for (i = 0; i < min(tmp, (*ptr)->numlevel - 1); i++)
|
||||
for (i = 0; i < Min(tmp, (*ptr)->numlevel - 1); i++)
|
||||
{
|
||||
if (l1->len == l2->len && strncmp(l1->name, l2->name, l1->len) == 0)
|
||||
num = i + 1;
|
||||
|
@ -30,9 +30,6 @@
|
||||
|
||||
#include "misc_utils.h"
|
||||
|
||||
#undef MIN
|
||||
#define MIN(x,y) ((x)<=(y) ? (x) : (y))
|
||||
|
||||
|
||||
int
|
||||
backend_pid()
|
||||
@ -48,15 +45,15 @@ unlisten(char *relname)
|
||||
}
|
||||
|
||||
int
|
||||
max(int x, int y)
|
||||
int4max(int x, int y)
|
||||
{
|
||||
return ((x > y) ? x : y);
|
||||
return Max(x, y);
|
||||
}
|
||||
|
||||
int
|
||||
min(int x, int y)
|
||||
int4min(int x, int y)
|
||||
{
|
||||
return ((x < y) ? x : y);
|
||||
return Min(x, y);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -84,7 +81,7 @@ active_listeners(text *relname)
|
||||
if (relname && (VARSIZE(relname) > VARHDRSZ))
|
||||
{
|
||||
MemSet(listen_name, 0, NAMEDATALEN);
|
||||
len = MIN(VARSIZE(relname) - VARHDRSZ, NAMEDATALEN - 1);
|
||||
len = Min(VARSIZE(relname) - VARHDRSZ, NAMEDATALEN - 1);
|
||||
memcpy(listen_name, VARDATA(relname), len);
|
||||
ScanKeyInit(&key,
|
||||
Anum_pg_listener_relname,
|
||||
|
@ -1,17 +1,10 @@
|
||||
#ifndef MISC_UTILS_H
|
||||
#define MISC_UTILS_H
|
||||
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
|
||||
int backend_pid(void);
|
||||
int unlisten(char *relname);
|
||||
int max(int x, int y);
|
||||
int min(int x, int y);
|
||||
int int4max(int x, int y);
|
||||
int int4min(int x, int y);
|
||||
int active_listeners(text *relname);
|
||||
|
||||
#endif
|
||||
|
@ -36,14 +36,14 @@ LANGUAGE 'SQL';
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION min(int4,int4)
|
||||
RETURNS int4
|
||||
AS 'MODULE_PATHNAME'
|
||||
AS 'MODULE_PATHNAME', 'int4min'
|
||||
LANGUAGE 'C';
|
||||
|
||||
-- max(x,y)
|
||||
--
|
||||
CREATE OR REPLACE FUNCTION max(int4,int4)
|
||||
RETURNS int4
|
||||
AS 'MODULE_PATHNAME'
|
||||
AS 'MODULE_PATHNAME', 'int4max'
|
||||
LANGUAGE 'C';
|
||||
|
||||
-- Return the number of active listeners on a relation
|
||||
|
@ -14,8 +14,6 @@
|
||||
|
||||
#include "segdata.h"
|
||||
|
||||
#define abs(a) ((a) < (0) ? (-a) : (a))
|
||||
|
||||
/*
|
||||
#define GIST_DEBUG
|
||||
#define GIST_QUERY_DEBUG
|
||||
@ -717,7 +715,7 @@ rt_seg_size(SEG * a, float *size)
|
||||
if (a == (SEG *) NULL || a->upper <= a->lower)
|
||||
*size = 0.0;
|
||||
else
|
||||
*size = (float) abs(a->upper - a->lower);
|
||||
*size = (float) Abs(a->upper - a->lower);
|
||||
|
||||
return;
|
||||
}
|
||||
@ -729,7 +727,7 @@ seg_size(SEG * a)
|
||||
|
||||
result = (float *) palloc(sizeof(float));
|
||||
|
||||
*result = (float) abs(a->upper - a->lower);
|
||||
*result = (float) Abs(a->upper - a->lower);
|
||||
|
||||
return (result);
|
||||
}
|
||||
@ -948,7 +946,7 @@ restore(char *result, float val, int n)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (abs(exp) <= 4)
|
||||
if (Abs(exp) <= 4)
|
||||
{
|
||||
/*
|
||||
* remove the decimal point from the mantyssa and write the
|
||||
@ -1036,7 +1034,7 @@ restore(char *result, float val, int n)
|
||||
}
|
||||
}
|
||||
|
||||
/* do nothing for abs(exp) > 4; %e must be OK */
|
||||
/* do nothing for Abs(exp) > 4; %e must be OK */
|
||||
/* just get rid of zeroes after [eE]- and +zeroes after [Ee]. */
|
||||
|
||||
/* ... this is not done yet. */
|
||||
|
@ -20,8 +20,6 @@
|
||||
/* define this if you want to see iso-8859 characters */
|
||||
#define ISO8859
|
||||
|
||||
#undef MIN
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
#define VALUE(char) ((char) - '0')
|
||||
#define DIGIT(val) ((val) + '0')
|
||||
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
|
||||
@ -229,7 +227,7 @@ string_input(unsigned char *str, int size, int hdrsize, int *rtn_size)
|
||||
else
|
||||
/* result has variable length with maximum size */
|
||||
if (size < 0)
|
||||
size = MIN(len, -size) + 1;
|
||||
size = Min(len, -size) + 1;
|
||||
|
||||
result = (char *) palloc(hdrsize + size);
|
||||
memset(result, 0, hdrsize + size);
|
||||
|
@ -700,7 +700,7 @@ gtxtidx_picksplit(PG_FUNCTION_ARGS)
|
||||
}
|
||||
|
||||
}
|
||||
costvector[j - 1].cost = abs(size_alpha - size_beta);
|
||||
costvector[j - 1].cost = Abs(size_alpha - size_beta);
|
||||
}
|
||||
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
|
||||
|
||||
|
@ -32,11 +32,6 @@ typedef char *BITVECP;
|
||||
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
|
||||
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
|
||||
|
||||
#define abs(a) ((a) < (0) ? -(a) : (a))
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
|
||||
#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
|
||||
|
||||
|
@ -634,7 +634,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS)
|
||||
costvector[j - 1].pos = j;
|
||||
size_alpha = hemdistcache(&(cache[seed_1]), &(cache[j]));
|
||||
size_beta = hemdistcache(&(cache[seed_2]), &(cache[j]));
|
||||
costvector[j - 1].cost = abs(size_alpha - size_beta);
|
||||
costvector[j - 1].cost = Abs(size_alpha - size_beta);
|
||||
}
|
||||
qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
|
||||
|
||||
|
@ -33,8 +33,6 @@ typedef char *BITVECP;
|
||||
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
|
||||
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 )
|
||||
|
||||
#define abs(a) ((a) < (0) ? -(a) : (a))
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
|
||||
#define HASH(sign, val) SETBIT((sign), HASHVAL(val))
|
||||
|
||||
|
@ -165,7 +165,7 @@ calc_rank_and(float *w, tsvector * t, QUERYTYPE * q)
|
||||
{
|
||||
for (p = 0; p < lenct; p++)
|
||||
{
|
||||
dist = abs(post[l].pos - ct[p].pos);
|
||||
dist = Abs(post[l].pos - ct[p].pos);
|
||||
if (dist || (dist == 0 && (pos[i] == (uint16 *) POSNULL || pos[k] == (uint16 *) POSNULL)))
|
||||
{
|
||||
float curw;
|
||||
|
@ -37,7 +37,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.434 2004/10/15 04:54:31 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.435 2004/10/21 19:28:35 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@ -3702,7 +3702,7 @@ win32_waitpid(int *exitstatus)
|
||||
|
||||
for (offset = 0; offset < win32_numChildren; offset += MAXIMUM_WAIT_OBJECTS)
|
||||
{
|
||||
unsigned long num = min(MAXIMUM_WAIT_OBJECTS, win32_numChildren - offset);
|
||||
unsigned long num = Min(MAXIMUM_WAIT_OBJECTS, win32_numChildren - offset);
|
||||
|
||||
ret = WaitForMultipleObjects(num, &win32_childHNDArray[offset], FALSE, 0);
|
||||
switch (ret)
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.164 2004/10/18 22:00:42 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-exec.c,v 1.165 2004/10/21 19:28:36 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -111,14 +111,9 @@ static PGresult *PQexecFinish(PGconn *conn);
|
||||
* ----------------
|
||||
*/
|
||||
|
||||
#ifdef MAX
|
||||
#undef MAX
|
||||
#endif
|
||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
#define PGRESULT_DATA_BLOCKSIZE 2048
|
||||
#define PGRESULT_ALIGN_BOUNDARY MAXIMUM_ALIGNOF /* from configure */
|
||||
#define PGRESULT_BLOCK_OVERHEAD MAX(sizeof(PGresult_data), PGRESULT_ALIGN_BOUNDARY)
|
||||
#define PGRESULT_BLOCK_OVERHEAD Max(sizeof(PGresult_data), PGRESULT_ALIGN_BOUNDARY)
|
||||
#define PGRESULT_SEP_ALLOC_THRESHOLD (PGRESULT_DATA_BLOCKSIZE / 2)
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $PostgreSQL: pgsql/src/test/regress/regress.c,v 1.61 2004/10/07 15:21:58 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/test/regress/regress.c,v 1.62 2004/10/21 19:28:36 tgl Exp $
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
@ -272,8 +272,6 @@ pt_in_widget(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius);
|
||||
}
|
||||
|
||||
#define ABS(X) ((X) >= 0 ? (X) : -(X))
|
||||
|
||||
PG_FUNCTION_INFO_V1(boxarea);
|
||||
|
||||
Datum
|
||||
@ -283,8 +281,8 @@ boxarea(PG_FUNCTION_ARGS)
|
||||
double width,
|
||||
height;
|
||||
|
||||
width = ABS(box->high.x - box->low.x);
|
||||
height = ABS(box->high.y - box->low.y);
|
||||
width = Abs(box->high.x - box->low.x);
|
||||
height = Abs(box->high.y - box->low.y);
|
||||
PG_RETURN_FLOAT8(width * height);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user