Skip to content

Commit 81bdce7

Browse files
committed
Deprecate the range check macros replaced by ZEND_IN_RANGE_OF()
ZEND_LONG_INT_OVFL(), ZEND_LONG_INT_UDFL(), ZEND_LONG_EXCEEDS_INT(), ZEND_LONG_UINT_OVFL(), ZEND_SIZE_T_INT_OVFL() and ZEND_SIZE_T_UINT_OVFL() have no callers left in php-src. They stay for code outside of it, with their behaviour unchanged, but are deprecated in favour of ZEND_IN_RANGE_OF(). C has no way to deprecate a macro, so each of them calls the empty function _zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), marked ZEND_ATTRIBUTE_DEPRECATED, instead. Every use then raises -Wdeprecated-declarations naming the replacement, and the compiler points at the macro. The flags ZEND_LONG_CAN_OVFL_INT, ZEND_LONG_CAN_OVFL_UINT and ZEND_SIZE_T_CAN_OVFL_UINT only serve these macros and are deprecated as well. Being only usable in #if, they can do so in a comment only. zend_portability.h includes zend_range_check.h last now, after ZEND_ATTRIBUTE_DEPRECATED is defined.
1 parent 207f54f commit 81bdce7

3 files changed

Lines changed: 40 additions & 45 deletions

File tree

‎UPGRADING.INTERNALS‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ PHP 8.7 INTERNALS UPGRADE NOTES
5050
- Added ZEND_IN_RANGE_OF(x, T) to check whether the value of an integer x is
5151
representable in the integer type T.
5252
- Added ZEND_TYPE_MIN(T) and ZEND_TYPE_MAX(T).
53+
- Deprecated ZEND_LONG_INT_OVFL(), ZEND_LONG_INT_UDFL(),
54+
ZEND_LONG_EXCEEDS_INT(), ZEND_LONG_UINT_OVFL(), ZEND_SIZE_T_INT_OVFL(),
55+
ZEND_SIZE_T_UINT_OVFL() and the *_CAN_OVFL_* flags. Use ZEND_IN_RANGE_OF()
56+
instead.
5357

5458
========================
5559
2. Build system changes

‎Zend/zend_portability.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ using std::atomic_int;
8787
#include <intrin.h>
8888
#endif
8989

90-
#include "zend_range_check.h"
91-
9290
/* GCC x.y.z supplies __GNUC__ = x and __GNUC_MINOR__ = y */
9391
#ifdef __GNUC__
9492
# define ZEND_GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
@@ -947,4 +945,7 @@ static zend_always_inline uint64_t ZEND_BYTES_SWAP64(uint64_t u)
947945
# define ZEND_OPCACHE_SHM_REATTACHMENT 1
948946
#endif
949947

948+
/* Last, as its declarations use ZEND_ATTRIBUTE_DEPRECATED. */
949+
#include "zend_range_check.h"
950+
950951
#endif /* ZEND_PORTABILITY_H */

‎Zend/zend_range_check.h‎

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,6 @@
2121

2222
#include "zend_long.h"
2323

24-
/* Flag macros for basic range recognition. Notable is that
25-
always sizeof(signed) == sizeof(unsigned), so no need to
26-
overcomplicate things. */
27-
#if SIZEOF_INT < SIZEOF_ZEND_LONG
28-
# define ZEND_LONG_CAN_OVFL_INT 1
29-
# define ZEND_LONG_CAN_OVFL_UINT 1
30-
#endif
31-
32-
#if SIZEOF_INT < SIZEOF_SIZE_T
33-
/* size_t can always overflow signed int on the same platform.
34-
Furthermore, by the current design, size_t can always
35-
overflow zend_long. */
36-
# define ZEND_SIZE_T_CAN_OVFL_UINT 1
37-
#endif
38-
39-
40-
/* zend_long vs. (unsigned) int checks. */
41-
#ifdef ZEND_LONG_CAN_OVFL_INT
42-
# define ZEND_LONG_INT_OVFL(zlong) UNEXPECTED((zlong) > (zend_long)INT_MAX)
43-
# define ZEND_LONG_INT_UDFL(zlong) UNEXPECTED((zlong) < (zend_long)INT_MIN)
44-
# define ZEND_LONG_EXCEEDS_INT(zlong) UNEXPECTED(ZEND_LONG_INT_OVFL(zlong) || ZEND_LONG_INT_UDFL(zlong))
45-
# define ZEND_LONG_UINT_OVFL(zlong) UNEXPECTED((zlong) < 0 || (zlong) > (zend_long)UINT_MAX)
46-
#else
47-
# define ZEND_LONG_INT_OVFL(zl) (0)
48-
# define ZEND_LONG_INT_UDFL(zl) (0)
49-
# define ZEND_LONG_EXCEEDS_INT(zlong) (0)
50-
# define ZEND_LONG_UINT_OVFL(zl) (0)
51-
#endif
52-
53-
/* size_t vs (unsigned) int checks. */
54-
#define ZEND_SIZE_T_INT_OVFL(size) UNEXPECTED((size) > (size_t)INT_MAX)
55-
#ifdef ZEND_SIZE_T_CAN_OVFL_UINT
56-
# define ZEND_SIZE_T_UINT_OVFL(size) UNEXPECTED((size) > (size_t)UINT_MAX)
57-
#else
58-
# define ZEND_SIZE_T_UINT_OVFL(size) (0)
59-
#endif
60-
61-
/* Comparison zend_long vs size_t */
62-
#define ZEND_SIZE_T_GT_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) > (size_t)(zlong))
63-
#define ZEND_SIZE_T_GTE_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) >= (size_t)(zlong))
64-
#define ZEND_SIZE_T_LT_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) < (size_t)(zlong))
65-
#define ZEND_SIZE_T_LTE_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) <= (size_t)(zlong))
66-
6724
/* _ZEND_INT_TYPE_CHECK(T): the integer constant 0,
6825
* or a compile error unless T is an integer type not wider than intmax_t. */
6926
#ifndef __cplusplus
@@ -166,4 +123,37 @@ extern "C++" {
166123
# define ZEND_IN_RANGE_OF(x, T) EXPECTED(_zend_in_range_of<T>(+(x)))
167124
#endif
168125

126+
/* Comparison zend_long vs size_t */
127+
#define ZEND_SIZE_T_GT_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) > (size_t)(zlong))
128+
#define ZEND_SIZE_T_GTE_ZEND_LONG(size, zlong) ((zlong) < 0 || (size) >= (size_t)(zlong))
129+
#define ZEND_SIZE_T_LT_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) < (size_t)(zlong))
130+
#define ZEND_SIZE_T_LTE_ZEND_LONG(size, zlong) ((zlong) >= 0 && (size) <= (size_t)(zlong))
131+
132+
/* -- DEPRECATED -- */
133+
134+
/* The zend_long and size_t vs. (unsigned) int checks below are deprecated, use ZEND_IN_RANGE_OF() instead. */
135+
static inline ZEND_ATTRIBUTE_DEPRECATED void _zend_deprecated_use_ZEND_IN_RANGE_OF_instead(void) {}
136+
137+
#if SIZEOF_INT < SIZEOF_ZEND_LONG
138+
# define ZEND_LONG_CAN_OVFL_INT 1 /* Deprecated */
139+
# define ZEND_LONG_CAN_OVFL_UINT 1 /* Deprecated */
140+
# define ZEND_LONG_INT_OVFL(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((zlong) > (zend_long)INT_MAX))
141+
# define ZEND_LONG_INT_UDFL(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((zlong) < (zend_long)INT_MIN))
142+
# define ZEND_LONG_EXCEEDS_INT(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((zlong) > (zend_long)INT_MAX || (zlong) < (zend_long)INT_MIN))
143+
# define ZEND_LONG_UINT_OVFL(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((zlong) < 0 || (zlong) > (zend_long)UINT_MAX))
144+
#else
145+
# define ZEND_LONG_INT_OVFL(zl) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), 0)
146+
# define ZEND_LONG_INT_UDFL(zl) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), 0)
147+
# define ZEND_LONG_EXCEEDS_INT(zlong) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), 0)
148+
# define ZEND_LONG_UINT_OVFL(zl) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), 0)
149+
#endif
150+
151+
#define ZEND_SIZE_T_INT_OVFL(size) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((size) > (size_t)INT_MAX))
152+
#if SIZEOF_INT < SIZEOF_SIZE_T
153+
# define ZEND_SIZE_T_CAN_OVFL_UINT 1 /* Deprecated */
154+
# define ZEND_SIZE_T_UINT_OVFL(size) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), UNEXPECTED((size) > (size_t)UINT_MAX))
155+
#else
156+
# define ZEND_SIZE_T_UINT_OVFL(size) (_zend_deprecated_use_ZEND_IN_RANGE_OF_instead(), 0)
157+
#endif
158+
169159
#endif /* ZEND_RANGE_CHECK_H */

0 commit comments

Comments
 (0)