[Python-checkins] cpython: Reuse Py_MIN and Py_MAX macros: remove duplicate MIN/MAX macros

victor.stinner python-checkins at python.org
Tue Jun 4 23:15:41 CEST 2013


http://hg.python.org/cpython/rev/41a2cbe23349
changeset: 84022:41a2cbe23349
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Jun 04 23:14:37 2013 +0200
summary:
 Reuse Py_MIN and Py_MAX macros: remove duplicate MIN/MAX macros
multiprocessing.h: remove unused MIN and MAX macros
files:
 Modules/_bz2module.c | 12 +++-----
 Modules/_cursesmodule.c | 14 +++------
 Modules/_multiprocessing/multiprocessing.h | 9 ------
 Modules/md5module.c | 6 +---
 Modules/sha1module.c | 6 +---
 Modules/socketmodule.c | 7 +---
 Objects/floatobject.c | 13 ++------
 Objects/frameobject.c | 11 ++-----
 Objects/longobject.c | 13 ++------
 9 files changed, 25 insertions(+), 66 deletions(-)
diff --git a/Modules/_bz2module.c b/Modules/_bz2module.c
--- a/Modules/_bz2module.c
+++ b/Modules/_bz2module.c
@@ -36,8 +36,6 @@
 #define RELEASE_LOCK(obj)
 #endif
 
-#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
-
 
 typedef struct {
 PyObject_HEAD
@@ -157,7 +155,7 @@
 /* On a 64-bit system, len might not fit in avail_in (an unsigned int).
 Do compression in chunks of no more than UINT_MAX bytes each. */
 if (c->bzs.avail_in == 0 && len > 0) {
- c->bzs.avail_in = MIN(len, UINT_MAX);
+ c->bzs.avail_in = Py_MIN(len, UINT_MAX);
 len -= c->bzs.avail_in;
 }
 
@@ -173,7 +171,7 @@
 c->bzs.next_out = PyBytes_AS_STRING(result) + data_size;
 buffer_left = PyBytes_GET_SIZE(result) - data_size;
 }
- c->bzs.avail_out = MIN(buffer_left, UINT_MAX);
+ c->bzs.avail_out = Py_MIN(buffer_left, UINT_MAX);
 }
 
 Py_BEGIN_ALLOW_THREADS
@@ -370,7 +368,7 @@
 d->bzs.next_in = data;
 /* On a 64-bit system, len might not fit in avail_in (an unsigned int).
 Do decompression in chunks of no more than UINT_MAX bytes each. */
- d->bzs.avail_in = MIN(len, UINT_MAX);
+ d->bzs.avail_in = Py_MIN(len, UINT_MAX);
 len -= d->bzs.avail_in;
 d->bzs.next_out = PyBytes_AS_STRING(result);
 d->bzs.avail_out = PyBytes_GET_SIZE(result);
@@ -399,7 +397,7 @@
 if (d->bzs.avail_in == 0) {
 if (len == 0)
 break;
- d->bzs.avail_in = MIN(len, UINT_MAX);
+ d->bzs.avail_in = Py_MIN(len, UINT_MAX);
 len -= d->bzs.avail_in;
 }
 if (d->bzs.avail_out == 0) {
@@ -410,7 +408,7 @@
 d->bzs.next_out = PyBytes_AS_STRING(result) + data_size;
 buffer_left = PyBytes_GET_SIZE(result) - data_size;
 }
- d->bzs.avail_out = MIN(buffer_left, UINT_MAX);
+ d->bzs.avail_out = Py_MIN(buffer_left, UINT_MAX);
 }
 }
 if (data_size != PyBytes_GET_SIZE(result))
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -168,10 +168,6 @@
 "must call start_color() first"); \
 return 0; }
 
-#ifndef MIN
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#endif
-
 /* Utility Functions */
 
 /*
@@ -1212,7 +1208,7 @@
 if (!PyArg_ParseTuple(args,"i;n", &n))
 return NULL;
 Py_BEGIN_ALLOW_THREADS
- rtn2 = wgetnstr(self->win,rtn,MIN(n, 1023));
+ rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023));
 Py_END_ALLOW_THREADS
 break;
 case 2:
@@ -1232,11 +1228,11 @@
 #ifdef STRICT_SYSV_CURSES
 Py_BEGIN_ALLOW_THREADS
 rtn2 = wmove(self->win,y,x)==ERR ? ERR :
- wgetnstr(self->win, rtn, MIN(n, 1023));
+ wgetnstr(self->win, rtn, Py_MIN(n, 1023));
 Py_END_ALLOW_THREADS
 #else
 Py_BEGIN_ALLOW_THREADS
- rtn2 = mvwgetnstr(self->win, y, x, rtn, MIN(n, 1023));
+ rtn2 = mvwgetnstr(self->win, y, x, rtn, Py_MIN(n, 1023));
 Py_END_ALLOW_THREADS
 #endif
 break;
@@ -1374,7 +1370,7 @@
 case 1:
 if (!PyArg_ParseTuple(args,"i;n", &n))
 return NULL;
- rtn2 = winnstr(self->win,rtn,MIN(n,1023));
+ rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023));
 break;
 case 2:
 if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x))
@@ -1384,7 +1380,7 @@
 case 3:
 if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n))
 return NULL;
- rtn2 = mvwinnstr(self->win, y, x, rtn, MIN(n,1023));
+ rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023));
 break;
 default:
 PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments");
diff --git a/Modules/_multiprocessing/multiprocessing.h b/Modules/_multiprocessing/multiprocessing.h
--- a/Modules/_multiprocessing/multiprocessing.h
+++ b/Modules/_multiprocessing/multiprocessing.h
@@ -99,13 +99,4 @@
 
 extern PyTypeObject _PyMp_SemLockType;
 
-/*
- * Miscellaneous
- */
-
-#ifndef MIN
-# define MIN(x, y) ((x) < (y) ? x : y)
-# define MAX(x, y) ((x) > (y) ? x : y)
-#endif
-
 #endif /* MULTIPROCESSING_H */
diff --git a/Modules/md5module.c b/Modules/md5module.c
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -91,10 +91,6 @@
 (y)[3] = (unsigned char)(((x)>>24)&255); (y)[2] = (unsigned char)(((x)>>16)&255); \
 (y)[1] = (unsigned char)(((x)>>8)&255); (y)[0] = (unsigned char)((x)&255); }
 
-#ifndef MIN
- #define MIN(x, y) ( ((x)<(y))?(x):(y) )
-#endif
-
 
 /* MD5 macros */
 
@@ -244,7 +240,7 @@
 in += MD5_BLOCKSIZE;
 inlen -= MD5_BLOCKSIZE;
 } else {
- n = MIN(inlen, (Py_ssize_t)(MD5_BLOCKSIZE - md5->curlen));
+ n = Py_MIN(inlen, (Py_ssize_t)(MD5_BLOCKSIZE - md5->curlen));
 memcpy(md5->buf + md5->curlen, in, (size_t)n);
 md5->curlen += (MD5_INT32)n;
 in += n;
diff --git a/Modules/sha1module.c b/Modules/sha1module.c
--- a/Modules/sha1module.c
+++ b/Modules/sha1module.c
@@ -92,10 +92,6 @@
 (y)[4] = (unsigned char)(((x)>>24)&255); (y)[5] = (unsigned char)(((x)>>16)&255); \
 (y)[6] = (unsigned char)(((x)>>8)&255); (y)[7] = (unsigned char)((x)&255); }
 
-#ifndef MIN
- #define MIN(x, y) ( ((x)<(y))?(x):(y) )
-#endif
-
 
 /* SHA1 macros */
 
@@ -220,7 +216,7 @@
 in += SHA1_BLOCKSIZE;
 inlen -= SHA1_BLOCKSIZE;
 } else {
- n = MIN(inlen, (Py_ssize_t)(SHA1_BLOCKSIZE - sha1->curlen));
+ n = Py_MIN(inlen, (Py_ssize_t)(SHA1_BLOCKSIZE - sha1->curlen));
 memcpy(sha1->buf + sha1->curlen, in, (size_t)n);
 sha1->curlen += (SHA1_INT32)n;
 in += n;
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -95,9 +95,6 @@
 #include "Python.h"
 #include "structmember.h"
 
-#undef MAX
-#define MAX(x, y) ((x) < (y) ? (y) : (x))
-
 /* Socket object documentation */
 PyDoc_STRVAR(sock_doc,
 "socket([family[, type[, proto]]]) -> socket object\n\
@@ -4819,7 +4816,7 @@
 char* ip;
 int retval;
 #ifdef ENABLE_IPV6
- char packed[MAX(sizeof(struct in_addr), sizeof(struct in6_addr))];
+ char packed[Py_MAX(sizeof(struct in_addr), sizeof(struct in6_addr))];
 #else
 char packed[sizeof(struct in_addr)];
 #endif
@@ -4870,7 +4867,7 @@
 int len;
 const char* retval;
 #ifdef ENABLE_IPV6
- char ip[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1];
+ char ip[Py_MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN) + 1];
 #else
 char ip[INET_ADDRSTRLEN + 1];
 #endif
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -9,11 +9,6 @@
 #include <ctype.h>
 #include <float.h>
 
-#undef MAX
-#undef MIN
-#define MAX(x, y) ((x) < (y) ? (y) : (x))
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-
 
 /* Special free list
 free_list is a singly-linked list of available PyFloatObjects, linked
@@ -1131,7 +1126,7 @@
 }
 
 m = frexp(fabs(x), &e);
- shift = 1 - MAX(DBL_MIN_EXP - e, 0);
+ shift = 1 - Py_MAX(DBL_MIN_EXP - e, 0);
 m = ldexp(m, shift);
 e -= shift;
 
@@ -1285,8 +1280,8 @@
 fdigits = coeff_end - s_store;
 if (ndigits == 0)
 goto parse_error;
- if (ndigits > MIN(DBL_MIN_EXP - DBL_MANT_DIG - LONG_MIN/2,
- LONG_MAX/2 + 1 - DBL_MAX_EXP)/4)
+ if (ndigits > Py_MIN(DBL_MIN_EXP - DBL_MANT_DIG - LONG_MIN/2,
+ LONG_MAX/2 + 1 - DBL_MAX_EXP)/4)
 goto insane_length_error;
 
 /* [p <exponent>] */
@@ -1342,7 +1337,7 @@
 
 /* lsb = exponent of least significant bit of the *rounded* value.
 This is top_exp - DBL_MANT_DIG unless result is subnormal. */
- lsb = MAX(top_exp, (long)DBL_MIN_EXP) - DBL_MANT_DIG;
+ lsb = Py_MAX(top_exp, (long)DBL_MIN_EXP) - DBL_MANT_DIG;
 
 x = 0.0;
 if (exp >= lsb) {
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -7,11 +7,6 @@
 #include "opcode.h"
 #include "structmember.h"
 
-#undef MIN
-#undef MAX
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-
 #define OFF(x) offsetof(PyFrameObject, x)
 
 static PyMemberDef frame_memberlist[] = {
@@ -160,8 +155,8 @@
 
 /* We're now ready to look at the bytecode. */
 PyBytes_AsStringAndSize(f->f_code->co_code, (char **)&code, &code_len);
- min_addr = MIN(new_lasti, f->f_lasti);
- max_addr = MAX(new_lasti, f->f_lasti);
+ min_addr = Py_MIN(new_lasti, f->f_lasti);
+ max_addr = Py_MAX(new_lasti, f->f_lasti);
 
 /* You can't jump onto a line with an 'except' statement on it -
 * they expect to have an exception on the top of the stack, which
@@ -293,7 +288,7 @@
 break;
 }
 
- min_delta_iblock = MIN(min_delta_iblock, delta_iblock);
+ min_delta_iblock = Py_MIN(min_delta_iblock, delta_iblock);
 
 if (op >= HAVE_ARGUMENT) {
 addr += 2;
diff --git a/Objects/longobject.c b/Objects/longobject.c
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -89,11 +89,6 @@
 */
 #define FIVEARY_CUTOFF 8
 
-#undef MIN
-#undef MAX
-#define MAX(x, y) ((x) < (y) ? (y) : (x))
-#define MIN(x, y) ((x) > (y) ? (y) : (x))
-
 #define SIGCHECK(PyTryBlock) \
 do { \
 if (PyErr_CheckSignals()) PyTryBlock \
@@ -3029,7 +3024,7 @@
 Py_ssize_t size_lo, size_hi;
 const Py_ssize_t size_n = ABS(Py_SIZE(n));
 
- size_lo = MIN(size_n, size);
+ size_lo = Py_MIN(size_n, size);
 size_hi = size_n - size_lo;
 
 if ((hi = _PyLong_New(size_hi)) == NULL)
@@ -3300,7 +3295,7 @@
 nbdone = 0;
 while (bsize > 0) {
 PyLongObject *product;
- const Py_ssize_t nbtouse = MIN(bsize, asize);
+ const Py_ssize_t nbtouse = Py_MIN(bsize, asize);
 
 /* Multiply the next slice of b by a. */
 memcpy(bslice->ob_digit, b->ob_digit + nbdone,
@@ -3591,7 +3586,7 @@
 goto underflow_or_zero;
 
 /* Choose value for shift; see comments for step 1 above. */
- shift = MAX(diff, DBL_MIN_EXP) - DBL_MANT_DIG - 2;
+ shift = Py_MAX(diff, DBL_MIN_EXP) - DBL_MANT_DIG - 2;
 
 inexact = 0;
 
@@ -3662,7 +3657,7 @@
 x_bits = (x_size-1)*PyLong_SHIFT+bits_in_digit(x->ob_digit[x_size-1]);
 
 /* The number of extra bits that have to be rounded away. */
- extra_bits = MAX(x_bits, DBL_MIN_EXP - shift) - DBL_MANT_DIG;
+ extra_bits = Py_MAX(x_bits, DBL_MIN_EXP - shift) - DBL_MANT_DIG;
 assert(extra_bits == 2 || extra_bits == 3);
 
 /* Round by directly modifying the low digit of x. */
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /