Commit 380bd04c authored by Tom Lane's avatar Tom Lane

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.
parent a171fc1a
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
#include "cubedata.h" #include "cubedata.h"
#define abs(a) ((a) < (0) ? (-a) : (a))
extern int cube_yyparse(); extern int cube_yyparse();
extern void cube_yyerror(const char *message); extern void cube_yyerror(const char *message);
extern void cube_scanner_init(const char *str); extern void cube_scanner_init(const char *str);
...@@ -683,7 +681,7 @@ cube_size(NDBOX * a) ...@@ -683,7 +681,7 @@ cube_size(NDBOX * a)
*result = 1.0; *result = 1.0;
for (i = 0, j = a->dim; i < a->dim; i++, j++) 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); return (result);
} }
...@@ -700,7 +698,7 @@ rt_cube_size(NDBOX * a, double *size) ...@@ -700,7 +698,7 @@ rt_cube_size(NDBOX * a, double *size)
{ {
*size = 1.0; *size = 1.0;
for (i = 0, j = a->dim; i < a->dim; i++, j++) 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; return;
} }
......
...@@ -14,10 +14,6 @@ ...@@ -14,10 +14,6 @@
/* number ranges for compression */ /* number ranges for compression */
#define MAXNUMRANGE 100 #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 */ /* dimension of array */
#define NDIM 1 #define NDIM 1
......
...@@ -425,7 +425,7 @@ g_int_picksplit(PG_FUNCTION_ARGS) ...@@ -425,7 +425,7 @@ g_int_picksplit(PG_FUNCTION_ARGS)
union_d = inner_int_union(datum_r, datum_alpha); union_d = inner_int_union(datum_r, datum_alpha);
rt__int_size(union_d, &size_beta); rt__int_size(union_d, &size_beta);
pfree(union_d); 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); qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
......
...@@ -137,7 +137,7 @@ inner_int_inter(ArrayType *a, ArrayType *b) ...@@ -137,7 +137,7 @@ inner_int_inter(ArrayType *a, ArrayType *b)
nb = ARRNELEMS(b); nb = ARRNELEMS(b);
da = ARRPTR(a); da = ARRPTR(a);
db = ARRPTR(b); db = ARRPTR(b);
r = new_intArrayType(min(na, nb)); r = new_intArrayType(Min(na, nb));
dr = ARRPTR(r); dr = ARRPTR(r);
i = j = 0; i = j = 0;
......
...@@ -402,7 +402,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS) ...@@ -402,7 +402,7 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
_j = GETENTRY(entryvec, j); _j = GETENTRY(entryvec, j);
size_alpha = hemdist(datum_l, _j); size_alpha = hemdist(datum_l, _j);
size_beta = hemdist(datum_r, _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); qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
......
...@@ -361,7 +361,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS) ...@@ -361,7 +361,7 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
_j = GETENTRY(entryvec, j); _j = GETENTRY(entryvec, j);
size_alpha = hemdist(datum_l, _j); size_alpha = hemdist(datum_l, _j);
size_beta = hemdist(datum_r, _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); qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
......
...@@ -78,15 +78,6 @@ typedef struct ...@@ -78,15 +78,6 @@ typedef struct
#define LQUERY_HASNOT 0x01 #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) == '_' ) #define ISALNUM(x) ( isalnum((unsigned char)(x)) || (x) == '_' )
/* full text query */ /* full text query */
......
...@@ -259,7 +259,7 @@ ltree_penalty(PG_FUNCTION_ARGS) ...@@ -259,7 +259,7 @@ ltree_penalty(PG_FUNCTION_ARGS)
cmpl = ltree_compare(LTG_GETLNODE(origval), LTG_GETLNODE(newval)); cmpl = ltree_compare(LTG_GETLNODE(origval), LTG_GETLNODE(newval));
cmpr = ltree_compare(LTG_GETRNODE(newval), LTG_GETRNODE(origval)); 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); PG_RETURN_POINTER(penalty);
} }
...@@ -537,7 +537,7 @@ gist_tqcmp(ltree * t, lquery * q) ...@@ -537,7 +537,7 @@ gist_tqcmp(ltree * t, lquery * q)
while (an > 0 && bn > 0) while (an > 0 && bn > 0)
{ {
bl = LQL_FIRST(ql); 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) if (al->len != bl->len)
return al->len - bl->len; return al->len - bl->len;
......
...@@ -55,7 +55,7 @@ ltree_compare(const ltree * a, const ltree * b) ...@@ -55,7 +55,7 @@ ltree_compare(const ltree * a, const ltree * b)
while (an > 0 && bn > 0) 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) if (al->len != bl->len)
return (al->len - bl->len) * 10 * (an + 1); return (al->len - bl->len) * 10 * (an + 1);
...@@ -443,7 +443,7 @@ lca_inner(ltree ** a, int len) ...@@ -443,7 +443,7 @@ lca_inner(ltree ** a, int len)
l2 = LTREE_FIRST(*ptr); l2 = LTREE_FIRST(*ptr);
tmp = num; tmp = num;
num = 0; 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) if (l1->len == l2->len && strncmp(l1->name, l2->name, l1->len) == 0)
num = i + 1; num = i + 1;
......
...@@ -30,9 +30,6 @@ ...@@ -30,9 +30,6 @@
#include "misc_utils.h" #include "misc_utils.h"
#undef MIN
#define MIN(x,y) ((x)<=(y) ? (x) : (y))
int int
backend_pid() backend_pid()
...@@ -48,15 +45,15 @@ unlisten(char *relname) ...@@ -48,15 +45,15 @@ unlisten(char *relname)
} }
int int
max(int x, int y) int4max(int x, int y)
{ {
return ((x > y) ? x : y); return Max(x, y);
} }
int 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) ...@@ -84,7 +81,7 @@ active_listeners(text *relname)
if (relname && (VARSIZE(relname) > VARHDRSZ)) if (relname && (VARSIZE(relname) > VARHDRSZ))
{ {
MemSet(listen_name, 0, NAMEDATALEN); 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); memcpy(listen_name, VARDATA(relname), len);
ScanKeyInit(&key, ScanKeyInit(&key,
Anum_pg_listener_relname, Anum_pg_listener_relname,
......
#ifndef MISC_UTILS_H #ifndef MISC_UTILS_H
#define MISC_UTILS_H #define MISC_UTILS_H
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
int backend_pid(void); int backend_pid(void);
int unlisten(char *relname); int unlisten(char *relname);
int max(int x, int y); int int4max(int x, int y);
int min(int x, int y); int int4min(int x, int y);
int active_listeners(text *relname); int active_listeners(text *relname);
#endif #endif
...@@ -36,14 +36,14 @@ LANGUAGE 'SQL'; ...@@ -36,14 +36,14 @@ LANGUAGE 'SQL';
-- --
CREATE OR REPLACE FUNCTION min(int4,int4) CREATE OR REPLACE FUNCTION min(int4,int4)
RETURNS int4 RETURNS int4
AS 'MODULE_PATHNAME' AS 'MODULE_PATHNAME', 'int4min'
LANGUAGE 'C'; LANGUAGE 'C';
-- max(x,y) -- max(x,y)
-- --
CREATE OR REPLACE FUNCTION max(int4,int4) CREATE OR REPLACE FUNCTION max(int4,int4)
RETURNS int4 RETURNS int4
AS 'MODULE_PATHNAME' AS 'MODULE_PATHNAME', 'int4max'
LANGUAGE 'C'; LANGUAGE 'C';
-- Return the number of active listeners on a relation -- Return the number of active listeners on a relation
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "segdata.h" #include "segdata.h"
#define abs(a) ((a) < (0) ? (-a) : (a))
/* /*
#define GIST_DEBUG #define GIST_DEBUG
#define GIST_QUERY_DEBUG #define GIST_QUERY_DEBUG
...@@ -717,7 +715,7 @@ rt_seg_size(SEG * a, float *size) ...@@ -717,7 +715,7 @@ rt_seg_size(SEG * a, float *size)
if (a == (SEG *) NULL || a->upper <= a->lower) if (a == (SEG *) NULL || a->upper <= a->lower)
*size = 0.0; *size = 0.0;
else else
*size = (float) abs(a->upper - a->lower); *size = (float) Abs(a->upper - a->lower);
return; return;
} }
...@@ -729,7 +727,7 @@ seg_size(SEG * a) ...@@ -729,7 +727,7 @@ seg_size(SEG * a)
result = (float *) palloc(sizeof(float)); result = (float *) palloc(sizeof(float));
*result = (float) abs(a->upper - a->lower); *result = (float) Abs(a->upper - a->lower);
return (result); return (result);
} }
...@@ -948,7 +946,7 @@ restore(char *result, float val, int n) ...@@ -948,7 +946,7 @@ restore(char *result, float val, int n)
} }
else else
{ {
if (abs(exp) <= 4) if (Abs(exp) <= 4)
{ {
/* /*
* remove the decimal point from the mantyssa and write the * remove the decimal point from the mantyssa and write the
...@@ -1036,7 +1034,7 @@ restore(char *result, float val, int n) ...@@ -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]. */ /* just get rid of zeroes after [eE]- and +zeroes after [Ee]. */
/* ... this is not done yet. */ /* ... this is not done yet. */
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
/* define this if you want to see iso-8859 characters */ /* define this if you want to see iso-8859 characters */
#define ISO8859 #define ISO8859
#undef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define VALUE(char) ((char) - '0') #define VALUE(char) ((char) - '0')
#define DIGIT(val) ((val) + '0') #define DIGIT(val) ((val) + '0')
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7')) #define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
...@@ -229,7 +227,7 @@ string_input(unsigned char *str, int size, int hdrsize, int *rtn_size) ...@@ -229,7 +227,7 @@ string_input(unsigned char *str, int size, int hdrsize, int *rtn_size)
else else
/* result has variable length with maximum size */ /* result has variable length with maximum size */
if (size < 0) if (size < 0)
size = MIN(len, -size) + 1; size = Min(len, -size) + 1;
result = (char *) palloc(hdrsize + size); result = (char *) palloc(hdrsize + size);
memset(result, 0, hdrsize + size); memset(result, 0, hdrsize + size);
......
...@@ -700,7 +700,7 @@ gtxtidx_picksplit(PG_FUNCTION_ARGS) ...@@ -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); qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
......
...@@ -32,11 +32,6 @@ typedef char *BITVECP; ...@@ -32,11 +32,6 @@ typedef char *BITVECP;
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) ) #define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 ) #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 HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
#define HASH(sign, val) SETBIT((sign), HASHVAL(val)) #define HASH(sign, val) SETBIT((sign), HASHVAL(val))
......
...@@ -634,7 +634,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS) ...@@ -634,7 +634,7 @@ gtsvector_picksplit(PG_FUNCTION_ARGS)
costvector[j - 1].pos = j; costvector[j - 1].pos = j;
size_alpha = hemdistcache(&(cache[seed_1]), &(cache[j])); size_alpha = hemdistcache(&(cache[seed_1]), &(cache[j]));
size_beta = hemdistcache(&(cache[seed_2]), &(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); qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
......
...@@ -33,8 +33,6 @@ typedef char *BITVECP; ...@@ -33,8 +33,6 @@ typedef char *BITVECP;
#define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) ) #define SETBIT(x,i) GETBYTE(x,i) |= ( 0x01 << ( (i) % BITBYTE ) )
#define GETBIT(x,i) ( (GETBYTE(x,i) >> ( (i) % BITBYTE )) & 0x01 ) #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 HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
#define HASH(sign, val) SETBIT((sign), HASHVAL(val)) #define HASH(sign, val) SETBIT((sign), HASHVAL(val))
......
...@@ -165,7 +165,7 @@ calc_rank_and(float *w, tsvector * t, QUERYTYPE * q) ...@@ -165,7 +165,7 @@ calc_rank_and(float *w, tsvector * t, QUERYTYPE * q)
{ {
for (p = 0; p < lenct; p++) 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))) if (dist || (dist == 0 && (pos[i] == (uint16 *) POSNULL || pos[k] == (uint16 *) POSNULL)))
{ {
float curw; float curw;
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * 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 * NOTES
* *
...@@ -3702,7 +3702,7 @@ win32_waitpid(int *exitstatus) ...@@ -3702,7 +3702,7 @@ win32_waitpid(int *exitstatus)
for (offset = 0; offset < win32_numChildren; offset += MAXIMUM_WAIT_OBJECTS) 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); ret = WaitForMultipleObjects(num, &win32_childHNDArray[offset], FALSE, 0);
switch (ret) switch (ret)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * 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); ...@@ -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_DATA_BLOCKSIZE 2048
#define PGRESULT_ALIGN_BOUNDARY MAXIMUM_ALIGNOF /* from configure */ #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) #define PGRESULT_SEP_ALLOC_THRESHOLD (PGRESULT_DATA_BLOCKSIZE / 2)
......
/* /*
* $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" #include "postgres.h"
...@@ -272,8 +272,6 @@ pt_in_widget(PG_FUNCTION_ARGS) ...@@ -272,8 +272,6 @@ pt_in_widget(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius); PG_RETURN_BOOL(point_dt(point, &widget->center) < widget->radius);
} }
#define ABS(X) ((X) >= 0 ? (X) : -(X))
PG_FUNCTION_INFO_V1(boxarea); PG_FUNCTION_INFO_V1(boxarea);
Datum Datum
...@@ -283,8 +281,8 @@ boxarea(PG_FUNCTION_ARGS) ...@@ -283,8 +281,8 @@ boxarea(PG_FUNCTION_ARGS)
double width, double width,
height; height;
width = ABS(box->high.x - box->low.x); width = Abs(box->high.x - box->low.x);
height = ABS(box->high.y - box->low.y); height = Abs(box->high.y - box->low.y);
PG_RETURN_FLOAT8(width * height); PG_RETURN_FLOAT8(width * height);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment