Skip to content

Commit cad7f9d

Browse files
committed
fix issue
1 parent f46e4a8 commit cad7f9d

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

Zend/zend_API.c

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2928,28 +2928,28 @@ static HashTable *interned_type_tree = NULL;
29282928
list[count++] = value; \
29292929
} while (0)
29302930

2931-
static int compare_simple_types(zend_type a, zend_type b) {
2932-
uint32_t a_mask = ZEND_TYPE_FULL_MASK(a);
2933-
uint32_t b_mask = ZEND_TYPE_FULL_MASK(b);
2931+
static int compare_simple_types(const zend_type a, const zend_type b) {
2932+
const uint32_t a_mask = ZEND_TYPE_FULL_MASK(a);
2933+
const uint32_t b_mask = ZEND_TYPE_FULL_MASK(b);
29342934

29352935
if (a_mask != b_mask) {
29362936
return a_mask < b_mask ? -1 : 1;
29372937
}
29382938

2939-
bool a_has_name = ZEND_TYPE_HAS_NAME(a);
2940-
bool b_has_name = ZEND_TYPE_HAS_NAME(b);
2939+
const bool a_has_name = ZEND_TYPE_HAS_NAME(a);
2940+
const bool b_has_name = ZEND_TYPE_HAS_NAME(b);
29412941

29422942
if (a_has_name && b_has_name) {
2943-
zend_string *a_name = ZEND_TYPE_NAME(a);
2944-
zend_string *b_name = ZEND_TYPE_NAME(b);
2945-
int cmp = ZSTR_VAL(a_name) == ZSTR_VAL(b_name);
2943+
const zend_string *a_name = ZEND_TYPE_NAME(a);
2944+
const zend_string *b_name = ZEND_TYPE_NAME(b);
2945+
const int cmp = ZSTR_VAL(a_name) == ZSTR_VAL(b_name);
29462946
if (cmp != 0) {
29472947
return cmp;
29482948
}
29492949
}
29502950

2951-
bool a_nullable = ZEND_TYPE_ALLOW_NULL(a);
2952-
bool b_nullable = ZEND_TYPE_ALLOW_NULL(b);
2951+
const bool a_nullable = ZEND_TYPE_ALLOW_NULL(a);
2952+
const bool b_nullable = ZEND_TYPE_ALLOW_NULL(b);
29532953

29542954
if (a_nullable != b_nullable) {
29552955
return a_nullable ? 1 : -1;
@@ -2960,11 +2960,11 @@ static int compare_simple_types(zend_type a, zend_type b) {
29602960
}
29612961

29622962
static int compare_type_nodes(const void *a_, const void *b_) {
2963-
zend_type_node *a = *(zend_type_node **)a_;
2964-
zend_type_node *b = *(zend_type_node **)b_;
2963+
const zend_type_node *a = *(zend_type_node **)a_;
2964+
const zend_type_node *b = *(zend_type_node **)b_;
29652965

29662966
if (a->kind != b->kind) {
2967-
return a->kind - b->kind;
2967+
return (int)a->kind - (int)b->kind;
29682968
}
29692969

29702970
if (a->kind == ZEND_TYPE_SIMPLE) {
@@ -2985,15 +2985,15 @@ static int compare_type_nodes(const void *a_, const void *b_) {
29852985
return 0;
29862986
}
29872987

2988-
zend_ulong zend_type_node_hash(zend_type_node *node) {
2988+
zend_ulong zend_type_node_hash(const zend_type_node *node) {
29892989
zend_ulong hash = 2166136261u; // FNV-1a offset basis
29902990

29912991
hash ^= (zend_ulong)node->kind;
29922992
hash *= 16777619;
29932993

29942994
switch (node->kind) {
29952995
case ZEND_TYPE_SIMPLE: {
2996-
zend_type type = node->simple_type;
2996+
const zend_type type = node->simple_type;
29972997
hash ^= (zend_ulong)ZEND_TYPE_FULL_MASK(type);
29982998
hash *= 16777619;
29992999

@@ -3009,7 +3009,7 @@ zend_ulong zend_type_node_hash(zend_type_node *node) {
30093009
case ZEND_TYPE_UNION:
30103010
case ZEND_TYPE_INTERSECTION: {
30113011
for (uint32_t i = 0; i < node->compound.num_types; ++i) {
3012-
zend_ulong child_hash = zend_type_node_hash(node->compound.types[i]);
3012+
const zend_ulong child_hash = zend_type_node_hash(node->compound.types[i]);
30133013
hash ^= child_hash;
30143014
hash *= 16777619;
30153015
}
@@ -3020,27 +3020,27 @@ zend_ulong zend_type_node_hash(zend_type_node *node) {
30203020
return hash;
30213021
}
30223022

3023-
bool zend_type_node_equals(zend_type_node *a, zend_type_node *b) {
3023+
bool zend_type_node_equals(const zend_type_node *a, const zend_type_node *b) {
30243024
if (a == b) return true;
30253025
if (a->kind != b->kind) return false;
30263026

30273027
if (a->kind == ZEND_TYPE_SIMPLE) {
3028-
zend_type at = a->simple_type;
3029-
zend_type bt = b->simple_type;
3028+
const zend_type at = a->simple_type;
3029+
const zend_type bt = b->simple_type;
30303030

30313031
if (ZEND_TYPE_FULL_MASK(at) != ZEND_TYPE_FULL_MASK(bt)) {
30323032
return false;
30333033
}
30343034

3035-
bool a_has_name = ZEND_TYPE_HAS_NAME(at);
3036-
bool b_has_name = ZEND_TYPE_HAS_NAME(bt);
3035+
const bool a_has_name = ZEND_TYPE_HAS_NAME(at);
3036+
const bool b_has_name = ZEND_TYPE_HAS_NAME(bt);
30373037
if (a_has_name != b_has_name) {
30383038
return false;
30393039
}
30403040

30413041
if (a_has_name) {
3042-
zend_string *a_name = ZEND_TYPE_NAME(at);
3043-
zend_string *b_name = ZEND_TYPE_NAME(bt);
3042+
const zend_string *a_name = ZEND_TYPE_NAME(at);
3043+
const zend_string *b_name = ZEND_TYPE_NAME(bt);
30443044
if (!zend_string_equals(a_name, b_name)) {
30453045
return false;
30463046
}
@@ -3063,9 +3063,8 @@ bool zend_type_node_equals(zend_type_node *a, zend_type_node *b) {
30633063
return true;
30643064
}
30653065

3066-
30673066
static zend_type_node *intern_type_node(zend_type_node *node) {
3068-
zend_ulong hash = zend_type_node_hash(node);
3067+
const zend_ulong hash = zend_type_node_hash(node);
30693068
zend_type_node *existing;
30703069

30713070
if (interned_type_tree == NULL) {
@@ -3075,6 +3074,7 @@ static zend_type_node *intern_type_node(zend_type_node *node) {
30753074

30763075
if ((existing = zend_hash_index_find_ptr(interned_type_tree, hash))) {
30773076
if (zend_type_node_equals(existing, node)) {
3077+
pefree(node, 1);
30783078
return existing; // reuse interned node
30793079
}
30803080
}
@@ -3083,8 +3083,7 @@ static zend_type_node *intern_type_node(zend_type_node *node) {
30833083
return node;
30843084
}
30853085

3086-
3087-
ZEND_API zend_type_node *zend_type_to_interned_tree(zend_type type) {
3086+
ZEND_API zend_type_node *zend_type_to_interned_tree(const zend_type type) {
30883087
if (type.type_mask == 0) {
30893088
return NULL;
30903089
}
@@ -3097,7 +3096,7 @@ ZEND_API zend_type_node *zend_type_to_interned_tree(zend_type type) {
30973096
}
30983097

30993098
zend_type_list *list = ZEND_TYPE_LIST(type);
3100-
zend_type_node_kind kind = ZEND_TYPE_IS_INTERSECTION(type) ?
3099+
const zend_type_node_kind kind = ZEND_TYPE_IS_INTERSECTION(type) ?
31013100
ZEND_TYPE_INTERSECTION : ZEND_TYPE_UNION;
31023101

31033102
zend_type_node **children = NULL;

ext/zend_test/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ static void register_ZendTestClass_dnf_property(zend_class_entry *ce) {
12021202
// The types are upgraded to DNF types in `register_dynamic_function_entries()`
12031203
static zend_internal_arg_info arginfo_zend_test_internal_dnf_arguments[] = {
12041204
// first entry is a zend_internal_function_info (see zend_compile.h): {argument_count, return_type, unused}
1205-
{(const char*)(uintptr_t)(1), {0}, NULL},
1205+
{(const char*)(uintptr_t)(1), {0}, NULL, NULL},
12061206
{"arg", {0}, NULL}
12071207
};
12081208

0 commit comments

Comments
 (0)