Skip to content

Commit da6b4e1

Browse files
committed
Zend: add const qualifiers to the majority of compare functions
This sadly does not include zend_compare() and functions relying on it due to 2 reasons: - The compare object handler doesn't take const pointers - The cast object handler (used for comparisons against other types) doesn't take const pointers
1 parent 031b4c6 commit da6b4e1

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

Zend/zend_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3209,7 +3209,7 @@ static zend_always_inline int zend_hash_compare_impl(const HashTable *ht1, const
32093209
return 0;
32103210
}
32113211

3212-
ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, bool ordered)
3212+
ZEND_API int zend_hash_compare(HashTable *ht1, const HashTable *ht2, compare_func_t compar, bool ordered)
32133213
{
32143214
int result;
32153215
IS_CONSISTENT(ht1);

Zend/zend_hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ ZEND_API void zend_hash_bucket_renum_swap(Bucket *p, Bucket *q);
301301
ZEND_API void zend_hash_bucket_packed_swap(Bucket *p, Bucket *q);
302302

303303
typedef int (*bucket_compare_func_t)(Bucket *a, Bucket *b);
304-
ZEND_API int zend_hash_compare(HashTable *ht1, HashTable *ht2, compare_func_t compar, bool ordered);
304+
ZEND_API int zend_hash_compare(HashTable *ht1, const HashTable *ht2, compare_func_t compar, bool ordered);
305305
ZEND_API void ZEND_FASTCALL zend_hash_sort_ex(HashTable *ht, sort_func_t sort_func, bucket_compare_func_t compare_func, bool renumber);
306306
ZEND_API void ZEND_FASTCALL zend_array_sort_ex(HashTable *ht, sort_func_t sort_func, bucket_compare_func_t compare_func, bool renumber);
307307
ZEND_API zval* ZEND_FASTCALL zend_hash_minmax(const HashTable *ht, compare_func_t compar, uint32_t flag);

Zend/zend_operators.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ ZEND_API double ZEND_FASTCALL zval_get_double_func(const zval *op) /* {{{ */
10591059
}
10601060
/* }}} */
10611061

1062-
static zend_always_inline zend_string* __zval_get_string_func(zval *op, bool try) /* {{{ */
1062+
static zend_always_inline zend_string* __zval_get_string_func(const zval *op, bool try) /* {{{ */
10631063
{
10641064
try_again:
10651065
switch (Z_TYPE_P(op)) {
@@ -1100,19 +1100,19 @@ static zend_always_inline zend_string* __zval_get_string_func(zval *op, bool try
11001100
}
11011101
/* }}} */
11021102

1103-
ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(zval *op) /* {{{ */
1103+
ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(const zval *op) /* {{{ */
11041104
{
11051105
return __zval_get_string_func(op, false);
11061106
}
11071107
/* }}} */
11081108

1109-
ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op) /* {{{ */
1109+
ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(const zval *op) /* {{{ */
11101110
{
11111111
return __zval_get_string_func(op, true);
11121112
}
11131113
/* }}} */
11141114

1115-
static ZEND_COLD zend_never_inline void ZEND_FASTCALL zend_binop_error(const char *operator, zval *op1, zval *op2) /* {{{ */ {
1115+
static ZEND_COLD zend_never_inline void ZEND_FASTCALL zend_binop_error(const char *operator, const zval *op1, const zval *op2) /* {{{ */ {
11161116
if (EG(exception)) {
11171117
return;
11181118
}
@@ -1122,7 +1122,7 @@ static ZEND_COLD zend_never_inline void ZEND_FASTCALL zend_binop_error(const cha
11221122
}
11231123
/* }}} */
11241124

1125-
static zend_never_inline void ZEND_FASTCALL add_function_array(zval *result, zval *op1, zval *op2) /* {{{ */
1125+
static zend_never_inline void ZEND_FASTCALL add_function_array(zval *result, const zval *op1, const zval *op2) /* {{{ */
11261126
{
11271127
if (result == op1 && Z_ARR_P(op1) == Z_ARR_P(op2)) {
11281128
/* $a += $a */
@@ -2159,7 +2159,7 @@ has_op2_string:;
21592159
}
21602160
/* }}} */
21612161

2162-
ZEND_API int ZEND_FASTCALL string_compare_function_ex(zval *op1, zval *op2, bool case_insensitive) /* {{{ */
2162+
ZEND_API int ZEND_FASTCALL string_compare_function_ex(const zval *op1, const zval *op2, bool case_insensitive) /* {{{ */
21632163
{
21642164
zend_string *tmp_str1, *tmp_str2;
21652165
zend_string *str1 = zval_get_tmp_string(op1, &tmp_str1);
@@ -2178,7 +2178,7 @@ ZEND_API int ZEND_FASTCALL string_compare_function_ex(zval *op1, zval *op2, bool
21782178
}
21792179
/* }}} */
21802180

2181-
ZEND_API int ZEND_FASTCALL string_compare_function(zval *op1, zval *op2) /* {{{ */
2181+
ZEND_API int ZEND_FASTCALL string_compare_function(const zval *op1, const zval *op2) /* {{{ */
21822182
{
21832183
if (EXPECTED(Z_TYPE_P(op1) == IS_STRING) &&
21842184
EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
@@ -2200,7 +2200,7 @@ ZEND_API int ZEND_FASTCALL string_compare_function(zval *op1, zval *op2) /* {{{
22002200
}
22012201
/* }}} */
22022202

2203-
ZEND_API int ZEND_FASTCALL string_case_compare_function(zval *op1, zval *op2) /* {{{ */
2203+
ZEND_API int ZEND_FASTCALL string_case_compare_function(const zval *op1, const zval *op2) /* {{{ */
22042204
{
22052205
if (EXPECTED(Z_TYPE_P(op1) == IS_STRING) &&
22062206
EXPECTED(Z_TYPE_P(op2) == IS_STRING)) {
@@ -2222,7 +2222,7 @@ ZEND_API int ZEND_FASTCALL string_case_compare_function(zval *op1, zval *op2) /*
22222222
}
22232223
/* }}} */
22242224

2225-
ZEND_API int ZEND_FASTCALL string_locale_compare_function(zval *op1, zval *op2) /* {{{ */
2225+
ZEND_API int ZEND_FASTCALL string_locale_compare_function(const zval *op1, const zval *op2) /* {{{ */
22262226
{
22272227
zend_string *tmp_str1, *tmp_str2;
22282228
zend_string *str1 = zval_get_tmp_string(op1, &tmp_str1);
@@ -2235,7 +2235,7 @@ ZEND_API int ZEND_FASTCALL string_locale_compare_function(zval *op1, zval *op2)
22352235
}
22362236
/* }}} */
22372237

2238-
ZEND_API int ZEND_FASTCALL numeric_compare_function(zval *op1, zval *op2) /* {{{ */
2238+
ZEND_API int ZEND_FASTCALL numeric_compare_function(const zval *op1, const zval *op2) /* {{{ */
22392239
{
22402240
double d1, d2;
22412241

@@ -2253,7 +2253,7 @@ ZEND_API zend_result ZEND_FASTCALL compare_function(zval *result, zval *op1, zva
22532253
}
22542254
/* }}} */
22552255

2256-
static int compare_long_to_string(zend_long lval, zend_string *str) /* {{{ */
2256+
static int compare_long_to_string(zend_long lval, const zend_string *str) /* {{{ */
22572257
{
22582258
zend_long str_lval;
22592259
double str_dval;
@@ -2275,7 +2275,7 @@ static int compare_long_to_string(zend_long lval, zend_string *str) /* {{{ */
22752275
}
22762276
/* }}} */
22772277

2278-
static int compare_double_to_string(double dval, zend_string *str) /* {{{ */
2278+
static int compare_double_to_string(double dval, const zend_string *str) /* {{{ */
22792279
{
22802280
zend_long str_lval;
22812281
double str_dval;
@@ -2459,7 +2459,7 @@ ZEND_API int ZEND_FASTCALL zend_compare(zval *op1, zval *op2) /* {{{ */
24592459
/* }}} */
24602460

24612461
/* return int to be compatible with compare_func_t */
2462-
static int hash_zval_identical_function(zval *z1, zval *z2) /* {{{ */
2462+
static int hash_zval_identical_function(const zval *z1, const zval *z2) /* {{{ */
24632463
{
24642464
/* is_identical_function() returns 1 in case of identity and 0 in case
24652465
* of a difference;
@@ -2501,14 +2501,14 @@ ZEND_API bool ZEND_FASTCALL zend_is_identical(const zval *op1, const zval *op2)
25012501
}
25022502
/* }}} */
25032503

2504-
ZEND_API zend_result ZEND_FASTCALL is_identical_function(zval *result, zval *op1, zval *op2) /* {{{ */
2504+
ZEND_API zend_result ZEND_FASTCALL is_identical_function(zval *result, const zval *op1, const zval *op2) /* {{{ */
25052505
{
25062506
ZVAL_BOOL(result, zend_is_identical(op1, op2));
25072507
return SUCCESS;
25082508
}
25092509
/* }}} */
25102510

2511-
ZEND_API zend_result ZEND_FASTCALL is_not_identical_function(zval *result, zval *op1, zval *op2) /* {{{ */
2511+
ZEND_API zend_result ZEND_FASTCALL is_not_identical_function(zval *result, const zval *op1, const zval *op2) /* {{{ */
25122512
{
25132513
ZVAL_BOOL(result, !zend_is_identical(op1, op2));
25142514
return SUCCESS;
@@ -3354,19 +3354,19 @@ ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp_l(const char *s1, size_t len1
33543354
}
33553355
/* }}} */
33563356

3357-
ZEND_API int ZEND_FASTCALL zend_binary_zval_strcmp(zval *s1, zval *s2) /* {{{ */
3357+
ZEND_API int ZEND_FASTCALL zend_binary_zval_strcmp(const zval *s1, const zval *s2) /* {{{ */
33583358
{
33593359
return zend_binary_strcmp(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2));
33603360
}
33613361
/* }}} */
33623362

3363-
ZEND_API int ZEND_FASTCALL zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3) /* {{{ */
3363+
ZEND_API int ZEND_FASTCALL zend_binary_zval_strncmp(const zval *s1, const zval *s2, const zval *s3) /* {{{ */
33643364
{
33653365
return zend_binary_strncmp(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2), Z_LVAL_P(s3));
33663366
}
33673367
/* }}} */
33683368

3369-
ZEND_API bool ZEND_FASTCALL zendi_smart_streq(zend_string *s1, zend_string *s2) /* {{{ */
3369+
ZEND_API bool ZEND_FASTCALL zendi_smart_streq(const zend_string *s1, const zend_string *s2) /* {{{ */
33703370
{
33713371
uint8_t ret1, ret2;
33723372
int oflow1, oflow2;
@@ -3414,7 +3414,7 @@ ZEND_API bool ZEND_FASTCALL zendi_smart_streq(zend_string *s1, zend_string *s2)
34143414
}
34153415
/* }}} */
34163416

3417-
ZEND_API int ZEND_FASTCALL zendi_smart_strcmp(zend_string *s1, zend_string *s2) /* {{{ */
3417+
ZEND_API int ZEND_FASTCALL zendi_smart_strcmp(const zend_string *s1, const zend_string *s2) /* {{{ */
34183418
{
34193419
uint8_t ret1, ret2;
34203420
int oflow1, oflow2;
@@ -3489,7 +3489,7 @@ ZEND_API int ZEND_FASTCALL zend_compare_symbol_tables(HashTable *ht1, HashTable
34893489
}
34903490
/* }}} */
34913491

3492-
ZEND_API int ZEND_FASTCALL zend_compare_arrays(zval *a1, zval *a2) /* {{{ */
3492+
ZEND_API int ZEND_FASTCALL zend_compare_arrays(const zval *a1, const zval *a2) /* {{{ */
34933493
{
34943494
return zend_compare_symbol_tables(Z_ARRVAL_P(a1), Z_ARRVAL_P(a2));
34953495
}

Zend/zend_operators.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ ZEND_API zend_result ZEND_FASTCALL concat_function(zval *result, zval *op1, zval
7171
ZEND_API bool ZEND_FASTCALL zend_is_identical(const zval *op1, const zval *op2);
7272

7373
ZEND_API zend_result ZEND_FASTCALL is_equal_function(zval *result, zval *op1, zval *op2);
74-
ZEND_API zend_result ZEND_FASTCALL is_identical_function(zval *result, zval *op1, zval *op2);
75-
ZEND_API zend_result ZEND_FASTCALL is_not_identical_function(zval *result, zval *op1, zval *op2);
74+
ZEND_API zend_result ZEND_FASTCALL is_identical_function(zval *result, const zval *op1, const zval *op2);
75+
ZEND_API zend_result ZEND_FASTCALL is_not_identical_function(zval *result, const zval *op1, const zval *op2);
7676
ZEND_API zend_result ZEND_FASTCALL is_not_equal_function(zval *result, zval *op1, zval *op2);
7777
ZEND_API zend_result ZEND_FASTCALL is_smaller_function(zval *result, zval *op1, zval *op2);
7878
ZEND_API zend_result ZEND_FASTCALL is_smaller_or_equal_function(zval *result, zval *op1, zval *op2);
@@ -325,8 +325,8 @@ ZEND_API void ZEND_FASTCALL convert_to_object(zval *op);
325325
ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(const zval *op, bool is_strict);
326326
ZEND_API zend_long ZEND_FASTCALL zval_try_get_long(const zval *op, bool *failed);
327327
ZEND_API double ZEND_FASTCALL zval_get_double_func(const zval *op);
328-
ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(zval *op);
329-
ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(zval *op);
328+
ZEND_API zend_string* ZEND_FASTCALL zval_get_string_func(const zval *op);
329+
ZEND_API zend_string* ZEND_FASTCALL zval_try_get_string_func(const zval *op);
330330

331331
static zend_always_inline zend_long zval_get_long(const zval *op) {
332332
return EXPECTED(Z_TYPE_P(op) == IS_LONG) ? Z_LVAL_P(op) : zval_get_long_func(op, false);
@@ -337,11 +337,11 @@ static zend_always_inline zend_long zval_get_long_ex(const zval *op, bool is_str
337337
static zend_always_inline double zval_get_double(const zval *op) {
338338
return EXPECTED(Z_TYPE_P(op) == IS_DOUBLE) ? Z_DVAL_P(op) : zval_get_double_func(op);
339339
}
340-
static zend_always_inline zend_string *zval_get_string(zval *op) {
340+
static zend_always_inline zend_string *zval_get_string(const zval *op) {
341341
return EXPECTED(Z_TYPE_P(op) == IS_STRING) ? zend_string_copy(Z_STR_P(op)) : zval_get_string_func(op);
342342
}
343343

344-
static zend_always_inline zend_string *zval_get_tmp_string(zval *op, zend_string **tmp) {
344+
static zend_always_inline zend_string *zval_get_tmp_string(const zval *op, zend_string **tmp) {
345345
if (EXPECTED(Z_TYPE_P(op) == IS_STRING)) {
346346
*tmp = NULL;
347347
return Z_STR_P(op);
@@ -356,7 +356,7 @@ static zend_always_inline void zend_tmp_string_release(zend_string *tmp) {
356356
}
357357

358358
/* Like zval_get_string, but returns NULL if the conversion fails with an exception. */
359-
static zend_always_inline zend_string *zval_try_get_string(zval *op) {
359+
static zend_always_inline zend_string *zval_try_get_string(const zval *op) {
360360
if (EXPECTED(Z_TYPE_P(op) == IS_STRING)) {
361361
zend_string *ret = zend_string_copy(Z_STR_P(op));
362362
ZEND_ASSUME(ret != NULL);
@@ -367,7 +367,7 @@ static zend_always_inline zend_string *zval_try_get_string(zval *op) {
367367
}
368368

369369
/* Like zval_get_tmp_string, but returns NULL if the conversion fails with an exception. */
370-
static zend_always_inline zend_string *zval_try_get_tmp_string(zval *op, zend_string **tmp) {
370+
static zend_always_inline zend_string *zval_try_get_tmp_string(const zval *op, zend_string **tmp) {
371371
if (EXPECTED(Z_TYPE_P(op) == IS_STRING)) {
372372
zend_string *ret = Z_STR_P(op);
373373
*tmp = NULL;
@@ -458,11 +458,11 @@ ZEND_API int ZEND_FASTCALL zend_compare(zval *op1, zval *op2);
458458

459459
ZEND_API zend_result ZEND_FASTCALL compare_function(zval *result, zval *op1, zval *op2);
460460

461-
ZEND_API int ZEND_FASTCALL numeric_compare_function(zval *op1, zval *op2);
462-
ZEND_API int ZEND_FASTCALL string_compare_function_ex(zval *op1, zval *op2, bool case_insensitive);
463-
ZEND_API int ZEND_FASTCALL string_compare_function(zval *op1, zval *op2);
464-
ZEND_API int ZEND_FASTCALL string_case_compare_function(zval *op1, zval *op2);
465-
ZEND_API int ZEND_FASTCALL string_locale_compare_function(zval *op1, zval *op2);
461+
ZEND_API int ZEND_FASTCALL numeric_compare_function(const zval *op1, const zval *op2);
462+
ZEND_API int ZEND_FASTCALL string_compare_function_ex(const zval *op1, const zval *op2, bool case_insensitive);
463+
ZEND_API int ZEND_FASTCALL string_compare_function(const zval *op1, const zval *op2);
464+
ZEND_API int ZEND_FASTCALL string_case_compare_function(const zval *op1, const zval *op2);
465+
ZEND_API int ZEND_FASTCALL string_locale_compare_function(const zval *op1, const zval *op2);
466466

467467
ZEND_API extern const unsigned char zend_tolower_map[256];
468468
ZEND_API extern const unsigned char zend_toupper_map[256];
@@ -488,19 +488,19 @@ static zend_always_inline zend_string* zend_string_toupper(zend_string *str) {
488488
return zend_string_toupper_ex(str, false);
489489
}
490490

491-
ZEND_API int ZEND_FASTCALL zend_binary_zval_strcmp(zval *s1, zval *s2);
492-
ZEND_API int ZEND_FASTCALL zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
491+
ZEND_API int ZEND_FASTCALL zend_binary_zval_strcmp(const zval *s1, const zval *s2);
492+
ZEND_API int ZEND_FASTCALL zend_binary_zval_strncmp(const zval *s1, const zval *s2, const zval *s3);
493493
ZEND_API int ZEND_FASTCALL zend_binary_strcmp(const char *s1, size_t len1, const char *s2, size_t len2);
494494
ZEND_API int ZEND_FASTCALL zend_binary_strncmp(const char *s1, size_t len1, const char *s2, size_t len2, size_t length);
495495
ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp(const char *s1, size_t len1, const char *s2, size_t len2);
496496
ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp(const char *s1, size_t len1, const char *s2, size_t len2, size_t length);
497497
ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2);
498498
ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp_l(const char *s1, size_t len1, const char *s2, size_t len2, size_t length);
499499

500-
ZEND_API bool ZEND_FASTCALL zendi_smart_streq(zend_string *s1, zend_string *s2);
501-
ZEND_API int ZEND_FASTCALL zendi_smart_strcmp(zend_string *s1, zend_string *s2);
500+
ZEND_API bool ZEND_FASTCALL zendi_smart_streq(const zend_string *s1, const zend_string *s2);
501+
ZEND_API int ZEND_FASTCALL zendi_smart_strcmp(const zend_string *s1, const zend_string *s2);
502502
ZEND_API int ZEND_FASTCALL zend_compare_symbol_tables(HashTable *ht1, HashTable *ht2);
503-
ZEND_API int ZEND_FASTCALL zend_compare_arrays(zval *a1, zval *a2);
503+
ZEND_API int ZEND_FASTCALL zend_compare_arrays(const zval *a1, const zval *a2);
504504
ZEND_API int ZEND_FASTCALL zend_compare_objects(zval *o1, zval *o2);
505505

506506
/** Deprecated in favor of ZEND_STRTOL() */
@@ -947,7 +947,7 @@ static zend_always_inline bool fast_equal_check_string(zval *op1, zval *op2)
947947
return zend_compare(op1, op2) == 0;
948948
}
949949

950-
static zend_always_inline bool fast_is_identical_function(zval *op1, zval *op2)
950+
static zend_always_inline bool fast_is_identical_function(const zval *op1, const zval *op2)
951951
{
952952
if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
953953
return 0;
@@ -957,7 +957,7 @@ static zend_always_inline bool fast_is_identical_function(zval *op1, zval *op2)
957957
return zend_is_identical(op1, op2);
958958
}
959959

960-
static zend_always_inline bool fast_is_not_identical_function(zval *op1, zval *op2)
960+
static zend_always_inline bool fast_is_not_identical_function(const zval *op1, const zval *op2)
961961
{
962962
if (Z_TYPE_P(op1) != Z_TYPE_P(op2)) {
963963
return 1;

0 commit comments

Comments
 (0)