Reuse Py_MIN and Py_MAX macros: remove duplicate MIN/MAX macros · pythoncapi/cpython@640c35c · GitHub
Skip to content

Commit 640c35c

Browse files
committed
Reuse Py_MIN and Py_MAX macros: remove duplicate MIN/MAX macros
multiprocessing.h: remove unused MIN and MAX macros
1 parent e0b99ba commit 640c35c

9 files changed

Lines changed: 25 additions & 66 deletions

File tree

Modules/_bz2module.c

Lines changed: 5 additions & 7 deletions

Modules/_cursesmodule.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ static char *screen_encoding = NULL;
168168
"must call start_color() first"); \
169169
return 0; }
170170

171-
#ifndef MIN
172-
#define MIN(x,y) ((x) < (y) ? (x) : (y))
173-
#endif
174-
175171
/* Utility Functions */
176172

177173
/*
@@ -1212,7 +1208,7 @@ PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
12121208
if (!PyArg_ParseTuple(args,"i;n", &n))
12131209
return NULL;
12141210
Py_BEGIN_ALLOW_THREADS
1215-
rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023));
1211+
rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023));
12161212
Py_END_ALLOW_THREADS
12171213
break;
12181214
case 2:
@@ -1232,11 +1228,11 @@ PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args)
12321228
#ifdef STRICT_SYSV_CURSES
12331229
Py_BEGIN_ALLOW_THREADS
12341230
rtn2 = wmove(self->win,y,x)==ERR ? ERR :
1235-
wgetnstr(self->win, rtn, MIN(n, 1023));
1231+
wgetnstr(self->win, rtn, Py_MIN(n, 1023));
12361232
Py_END_ALLOW_THREADS
12371233
#else
12381234
Py_BEGIN_ALLOW_THREADS
1239-
rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023));
1235+
rtn2 = mvwgetnstr(self->win, y, x, rtn, Py_MIN(n, 1023));
12401236
Py_END_ALLOW_THREADS
12411237
#endif
12421238
break;
@@ -1374,7 +1370,7 @@ PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
13741370
case 1:
13751371
if (!PyArg_ParseTuple(args,"i;n", &n))
13761372
return NULL;
1377-
rtn2 = winnstr(self->win,rtn,MIN(n,1023));
1373+
rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023));
13781374
break;
13791375
case 2:
13801376
if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
@@ -1384,7 +1380,7 @@ PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args)
13841380
case 3:
13851381
if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
13861382
return NULL;
1387-
rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023));
1383+
rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023));
13881384
break;
13891385
default:
13901386
PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");

Modules/_multiprocessing/multiprocessing.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,4 @@ PyObject *_PyMp_SetError(PyObject *Type, int num);
9999

100100
extern PyTypeObject _PyMp_SemLockType;
101101

102-
/*
103-
* Miscellaneous
104-
*/
105-
106-
#ifndef MIN
107-
# define MIN(x, y) ((x) < (y) ? x : y)
108-
# define MAX(x, y) ((x) > (y) ? x : y)
109-
#endif
110-
111102
#endif /* MULTIPROCESSING_H */

Modules/md5module.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ typedef struct {
9191
(y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
9292
(y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
9393

94-
#ifndef MIN
95-
#define MIN(x, y) ( ((x)<(y))?(x):(y) )
96-
#endif
97-
9894

9995
/* MD5 macros */
10096

@@ -244,7 +240,7 @@ md5_process(struct md5_state *md5, const unsigned char *in, Py_ssize_t inlen)
244240
in += MD5_BLOCKSIZE;
245241
inlen -= MD5_BLOCKSIZE;
246242
} else {
247-
n = MIN(inlen, (Py_ssize_t)(MD5_BLOCKSIZE - md5->curlen));
243+
n = Py_MIN(inlen, (Py_ssize_t)(MD5_BLOCKSIZE - md5->curlen));
248244
memcpy(md5->buf + md5->curlen, in, (size_t)n);
249245
md5->curlen += (MD5_INT32)n;
250246
in += n;

Modules/sha1module.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ typedef struct {
9292
(y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
9393
(y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
9494

95-
#ifndef MIN
96-
#define MIN(x, y) ( ((x)<(y))?(x):(y) )
97-
#endif
98-
9995

10096
/* SHA1 macros */
10197

@@ -220,7 +216,7 @@ sha1_process(struct sha1_state *sha1,
220216
in += SHA1_BLOCKSIZE;
221217
inlen -= SHA1_BLOCKSIZE;
222218
} else {
223-
n = MIN(inlen, (Py_ssize_t)(SHA1_BLOCKSIZE - sha1->curlen));
219+
n = Py_MIN(inlen, (Py_ssize_t)(SHA1_BLOCKSIZE - sha1->curlen));
224220
memcpy(sha1->buf + sha1->curlen, in, (size_t)n);
225221
sha1->curlen += (SHA1_INT32)n;
226222
in += n;

Modules/socketmodule.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ Local naming conventions:
9595
#include "Python.h"
9696
#include "structmember.h"
9797

98-
#undef MAX
99-
#define MAX(x, y) ((x) < (y) ? (y) : (x))
100-
10198
/* Socket object documentation */
10299
PyDoc_STRVAR(sock_doc,
103100
"socket([family[, type[, proto]]]) -> socket object\n\
@@ -4819,7 +4816,7 @@ socket_inet_pton(PyObject *self, PyObject *args)
48194816
char* ip;
48204817
int retval;
48214818
#ifdef ENABLE_IPV6
4822-
char packed[MAX(sizeof(struct in_addr), sizeof(struct in6_addr))];
4819+
char packed[Py_MAX(sizeof(struct in_addr), sizeof(struct in6_addr))];
48234820
#else
48244821
char packed[sizeof(struct in_addr)];
48254822
#endif
@@ -4870,7 +4867,7 @@ socket_inet_ntop(PyObject *self, PyObject *args)
48704867
int len;
48714868
const char* retval;
48724869
#ifdef ENABLE_IPV6
4873-
char ip[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1];
4870+
char ip[Py_MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1];
48744871
#else
48754872
char ip[INET_ADDRSTRLEN + 1];
48764873
#endif

Objects/floatobject.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
#include <ctype.h>
1010
#include <float.h>
1111

12-
#undef MAX
13-
#undef MIN
14-
#define MAX(x, y) ((x) < (y) ? (y) : (x))
15-
#define MIN(x, y) ((x) < (y) ? (x) : (y))
16-
1712

1813
/* Special free list
1914
free_list is a singly-linked list of available PyFloatObjects, linked
@@ -1131,7 +1126,7 @@ float_hex(PyObject *v)
11311126
}
11321127

11331128
m = frexp(fabs(x), &e);
1134-
shift = 1 - MAX(DBL_MIN_EXP - e, 0);
1129+
shift = 1 - Py_MAX(DBL_MIN_EXP - e, 0);
11351130
m = ldexp(m, shift);
11361131
e -= shift;
11371132

@@ -1285,8 +1280,8 @@ float_fromhex(PyObject *cls, PyObject *arg)
12851280
fdigits = coeff_end - s_store;
12861281
if (ndigits == 0)
12871282
goto parse_error;
1288-
if (ndigits > MIN(DBL_MIN_EXP - DBL_MANT_DIG - LONG_MIN/2,
1289-
LONG_MAX/2 + 1 - DBL_MAX_EXP)/4)
1283+
if (ndigits > Py_MIN(DBL_MIN_EXP - DBL_MANT_DIG - LONG_MIN/2,
1284+
LONG_MAX/2 + 1 - DBL_MAX_EXP)/4)
12901285
goto insane_length_error;
12911286

12921287
/* [p <exponent>] */
@@ -1342,7 +1337,7 @@ float_fromhex(PyObject *cls, PyObject *arg)
13421337

13431338
/* lsb = exponent of least significant bit of the *rounded* value.
13441339
This is top_exp - DBL_MANT_DIG unless result is subnormal. */
1345-
lsb = MAX(top_exp, (long)DBL_MIN_EXP) - DBL_MANT_DIG;
1340+
lsb = Py_MAX(top_exp, (long)DBL_MIN_EXP) - DBL_MANT_DIG;
13461341

13471342
x = 0.0;
13481343
if (exp >= lsb) {

Objects/frameobject.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
#include "opcode.h"
88
#include "structmember.h"
99

10-
#undef MIN
11-
#undef MAX
12-
#define MIN(a, b) ((a) < (b) ? (a) : (b))
13-
#define MAX(a, b) ((a) > (b) ? (a) : (b))
14-
1510
#define OFF(x) offsetof(PyFrameObject, x)
1611

1712
static PyMemberDef frame_memberlist[] = {
@@ -160,8 +155,8 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
160155

161156
/* We're now ready to look at the bytecode. */
162157
PyBytes_AsStringAndSize(f->f_code->co_code, (char **)&code, &code_len);
163-
min_addr = MIN(new_lasti, f->f_lasti);
164-
max_addr = MAX(new_lasti, f->f_lasti);
158+
min_addr = Py_MIN(new_lasti, f->f_lasti);
159+
max_addr = Py_MAX(new_lasti, f->f_lasti);
165160

166161
/* You can't jump onto a line with an 'except' statement on it -
167162
* they expect to have an exception on the top of the stack, which
@@ -293,7 +288,7 @@ frame_setlineno(PyFrameObject *f, PyObject* p_new_lineno)
293288
break;
294289
}
295290

296-
min_delta_iblock = MIN(min_delta_iblock, delta_iblock);
291+
min_delta_iblock = Py_MIN(min_delta_iblock, delta_iblock);
297292

298293
if (op >= HAVE_ARGUMENT) {
299294
addr += 2;

Objects/longobject.c

Lines changed: 4 additions & 9 deletions

0 commit comments

Comments
 (0)