Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 7 additions & 32 deletions Include/pymacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,40 +107,15 @@
# endif
#endif

#if ((defined(__GNUC__) || defined(__clang__)) \
&& defined(_Py_TYPEOF) && !defined(__cplusplus))
// Implement Py_MIN(), Py_MAX() and Py_ABS() using _Py_TYPEOF() and
// statement expression to only evaluate each argument only once.
// It cannot be used in C++: ISO C++ forbids braced-groups within
// expressions. Statement expression is a GNU extension. Use __extension__
// to avoid compiler warning in pedantic mode.

/* Minimum value between x and y */
# define Py_MIN(x, y) \
__extension__ \
({ _Py_TYPEOF (x) _x = (x); \
_Py_TYPEOF (y) _y = (y); \
_x < _y ? _x : _y; })
/* Maximum value between x and y */
# define Py_MAX(x, y) \
__extension__ \
({ _Py_TYPEOF (x) _x = (x); \
_Py_TYPEOF (y) _y = (y); \
_x > _y ? _x : _y; })
/* Absolute value of the number x */
# define Py_ABS(x) \
__extension__ \
({ _Py_TYPEOF (x) _x = (x); \
_x < 0 ? -_x : _x; })
#else
/* Minimum value between x and y */
# define Py_MIN(x, y) (((x) > (y)) ? (y) : (x))
/* Maximum value between x and y */
# define Py_MAX(x, y) (((x) > (y)) ? (x) : (y))
/* Absolute value of the number x */
# define Py_ABS(x) ((x) < 0 ? -(x) : (x))
#endif
/* Minimum value between x and y */
#define Py_MIN(x, y) (((x) > (y)) ? (y) : (x))

/* Maximum value between x and y */
#define Py_MAX(x, y) (((x) > (y)) ? (x) : (y))

/* Absolute value of the number x */
#define Py_ABS(x) ((x) < 0 ? -(x) : (x))
/* Safer implementation that avoids an undefined behavior for the minimal
value of the signed integer type if its absolute value is larger than
the maximal value of the signed integer type (in the two's complement
Expand Down

This file was deleted.

11 changes: 0 additions & 11 deletions Modules/_testcapimodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2050,17 +2050,6 @@ test_macros(PyObject *self, PyObject *Py_UNUSED(args))
assert(Py_MAX(5, 11) == 11);
assert(Py_ABS(-5) == 5);

#if ((defined(__GNUC__) || defined(__clang__)) \
&& defined(_Py_TYPEOF) && !defined(__cplusplus))
// When _Py_TYPEOF() is available, arguments are only evaluated once
int x = 5, y = 11;
assert(Py_MIN(++x, ++y) == 6);
x = 5; y = 11;
assert(Py_MAX(++x, ++y) == 12);
x = -5;
assert(Py_ABS(--x) == 6);
#endif

// Py_STRINGIFY()
assert(strcmp(Py_STRINGIFY(123), "123") == 0);

Expand Down
Loading