Skip to content

Commit ae8647d

Browse files
authored
Remove leading underscore for _zend_hash_find_known_hash (#7260)
Convert zend_hash_find_ex(..., 1) to zend_hash_find_known_hash(...) Convert zend_hash_find_ex(..., 0) to zend_hash_find(...) Also add serializable changes to UPGRADING.INTERNALS summary
1 parent 576655e commit ae8647d

21 files changed

+171
-168
lines changed

UPGRADING.INTERNALS

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP 8.1 INTERNALS UPGRADE NOTES
66
c. zend_get_opcode_id()
77
d. Removed support for "p" printf format specifier
88
e. ZEND_ATOL() changes
9+
f. Non-serializable classes should use ZEND_ACC_NOT_SERIALIZABLE
10+
g. _zend_hash_find_known_hash renamed to zend_hash_find_known_hash
911

1012
2. Build system changes
1113
a. New compiler flags
@@ -50,6 +52,7 @@ PHP 8.1 INTERNALS UPGRADE NOTES
5052
f. Non-serializable classes should be indicated using the
5153
ZEND_ACC_NOT_SERIALIZABLE (@not-serializable in stubs) rather than the
5254
zend_class_(un)serialize_deny handlers which are removed.
55+
g. _zend_hash_find_known_hash has been renamed to zend_hash_find_known_hash.
5356

5457
========================
5558
2. Build system changes

Zend/Optimizer/zend_func_info.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ static uint32_t get_internal_func_info(
811811
return 0;
812812
}
813813

814-
zval *zv = zend_hash_find_ex(&func_info, callee_func->common.function_name, 1);
814+
zval *zv = zend_hash_find_known_hash(&func_info, callee_func->common.function_name);
815815
if (!zv) {
816816
return 0;
817817
}

Zend/zend_builtin_functions.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ ZEND_FUNCTION(error_reporting)
382382
zend_ini_entry *p = EG(error_reporting_ini_entry);
383383

384384
if (!p) {
385-
zval *zv = zend_hash_find_ex(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING), 1);
385+
zval *zv = zend_hash_find_known_hash(EG(ini_directives), ZSTR_KNOWN(ZEND_STR_ERROR_REPORTING));
386386
if (!zv) {
387387
/* Ini setting does not exist -- can this happen? */
388388
RETURN_LONG(old_error_reporting);

Zend/zend_compile.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ ZEND_API void function_add_ref(zend_function *function) /* {{{ */
10591059

10601060
static zend_never_inline ZEND_COLD ZEND_NORETURN void do_bind_function_error(zend_string *lcname, zend_op_array *op_array, bool compile_time) /* {{{ */
10611061
{
1062-
zval *zv = zend_hash_find_ex(compile_time ? CG(function_table) : EG(function_table), lcname, 1);
1062+
zval *zv = zend_hash_find_known_hash(compile_time ? CG(function_table) : EG(function_table), lcname);
10631063
int error_level = compile_time ? E_COMPILE_ERROR : E_ERROR;
10641064
zend_function *old_function;
10651065

@@ -1102,7 +1102,7 @@ ZEND_API zend_result do_bind_class(zval *lcname, zend_string *lc_parent_name) /*
11021102

11031103
rtd_key = lcname + 1;
11041104

1105-
zv = zend_hash_find_ex(EG(class_table), Z_STR_P(rtd_key), 1);
1105+
zv = zend_hash_find_known_hash(EG(class_table), Z_STR_P(rtd_key));
11061106

11071107
if (UNEXPECTED(!zv)) {
11081108
ce = zend_hash_find_ptr(EG(class_table), Z_STR_P(lcname));
@@ -1114,7 +1114,7 @@ ZEND_API zend_result do_bind_class(zval *lcname, zend_string *lc_parent_name) /*
11141114
ZEND_ASSERT(EG(current_execute_data)->func->op_array.fn_flags & ZEND_ACC_PRELOADED);
11151115
if (zend_preload_autoload
11161116
&& zend_preload_autoload(EG(current_execute_data)->func->op_array.filename) == SUCCESS) {
1117-
zv = zend_hash_find_ex(EG(class_table), Z_STR_P(rtd_key), 1);
1117+
zv = zend_hash_find_known_hash(EG(class_table), Z_STR_P(rtd_key));
11181118
if (EXPECTED(zv != NULL)) {
11191119
break;
11201120
}
@@ -1383,7 +1383,7 @@ ZEND_API void zend_do_delayed_early_binding(zend_op_array *op_array, uint32_t fi
13831383
while (opline_num != (uint32_t)-1) {
13841384
const zend_op *opline = &op_array->opcodes[opline_num];
13851385
zval *lcname = RT_CONSTANT(opline, opline->op1);
1386-
zval *zv = zend_hash_find_ex(EG(class_table), Z_STR_P(lcname + 1), 1);
1386+
zval *zv = zend_hash_find_known_hash(EG(class_table), Z_STR_P(lcname + 1));
13871387

13881388
if (zv) {
13891389
zend_class_entry *ce = Z_CE_P(zv);

Zend/zend_exceptions.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,14 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /*
547547
smart_str_append_long(str, num);
548548
smart_str_appendc(str, ' ');
549549

550-
file = zend_hash_find_ex(ht, ZSTR_KNOWN(ZEND_STR_FILE), 1);
550+
file = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_FILE));
551551
if (file) {
552552
if (Z_TYPE_P(file) != IS_STRING) {
553553
zend_error(E_WARNING, "File name is not a string");
554554
smart_str_appends(str, "[unknown file]: ");
555555
} else{
556556
zend_long line = 0;
557-
tmp = zend_hash_find_ex(ht, ZSTR_KNOWN(ZEND_STR_LINE), 1);
557+
tmp = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_LINE));
558558
if (tmp) {
559559
if (Z_TYPE_P(tmp) == IS_LONG) {
560560
line = Z_LVAL_P(tmp);
@@ -574,7 +574,7 @@ static void _build_trace_string(smart_str *str, HashTable *ht, uint32_t num) /*
574574
TRACE_APPEND_KEY(ZSTR_KNOWN(ZEND_STR_TYPE));
575575
TRACE_APPEND_KEY(ZSTR_KNOWN(ZEND_STR_FUNCTION));
576576
smart_str_appendc(str, '(');
577-
tmp = zend_hash_find_ex(ht, ZSTR_KNOWN(ZEND_STR_ARGS), 1);
577+
tmp = zend_hash_find_known_hash(ht, ZSTR_KNOWN(ZEND_STR_ARGS));
578578
if (tmp) {
579579
if (Z_TYPE_P(tmp) == IS_ARRAY) {
580580
size_t last_len = ZSTR_LEN(str->s);

Zend/zend_execute.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,7 @@ static zend_never_inline zval* ZEND_FASTCALL zend_find_array_dim_slow(HashTable
25542554
return zend_hash_index_find(ht, hval);
25552555
} else if (Z_TYPE_P(offset) == IS_NULL) {
25562556
str_idx:
2557-
return zend_hash_find_ex(ht, ZSTR_EMPTY_ALLOC(), 1);
2557+
return zend_hash_find_known_hash(ht, ZSTR_EMPTY_ALLOC());
25582558
} else if (Z_TYPE_P(offset) == IS_FALSE) {
25592559
hval = 0;
25602560
goto num_idx;
@@ -2866,7 +2866,7 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
28662866
}
28672867
zobj->properties = zend_array_dup(zobj->properties);
28682868
}
2869-
ptr = zend_hash_find_ex(zobj->properties, Z_STR_P(prop_ptr), 1);
2869+
ptr = zend_hash_find_known_hash(zobj->properties, Z_STR_P(prop_ptr));
28702870
if (EXPECTED(ptr)) {
28712871
ZVAL_INDIRECT(result, ptr);
28722872
return;
@@ -4398,12 +4398,12 @@ static zend_always_inline zend_result _zend_quick_get_constant(
43984398
zend_constant *c = NULL;
43994399

44004400
/* null/true/false are resolved during compilation, so don't check for them here. */
4401-
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
4401+
zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
44024402
if (zv) {
44034403
c = (zend_constant*)Z_PTR_P(zv);
44044404
} else if (flags & IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE) {
44054405
key++;
4406-
zv = zend_hash_find_ex(EG(zend_constants), Z_STR_P(key), 1);
4406+
zv = zend_hash_find_known_hash(EG(zend_constants), Z_STR_P(key));
44074407
if (zv) {
44084408
c = (zend_constant*)Z_PTR_P(zv);
44094409
}

Zend/zend_execute_API.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ ZEND_API void zend_attach_symbol_table(zend_execute_data *execute_data) /* {{{ *
16171617
zval *var = EX_VAR_NUM(0);
16181618

16191619
do {
1620-
zval *zv = zend_hash_find_ex(ht, *str, 1);
1620+
zval *zv = zend_hash_find_known_hash(ht, *str);
16211621

16221622
if (zv) {
16231623
if (Z_TYPE_P(zv) == IS_INDIRECT) {

Zend/zend_hash.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2270,7 +2270,7 @@ ZEND_API zval* ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *ke
22702270
return p ? &p->val : NULL;
22712271
}
22722272

2273-
ZEND_API zval* ZEND_FASTCALL _zend_hash_find_known_hash(const HashTable *ht, zend_string *key)
2273+
ZEND_API zval* ZEND_FASTCALL zend_hash_find_known_hash(const HashTable *ht, zend_string *key)
22742274
{
22752275
Bucket *p;
22762276

Zend/zend_hash.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,13 @@ ZEND_API zval* ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char
177177
ZEND_API zval* ZEND_FASTCALL zend_hash_index_find(const HashTable *ht, zend_ulong h);
178178
ZEND_API zval* ZEND_FASTCALL _zend_hash_index_find(const HashTable *ht, zend_ulong h);
179179

180-
/* The same as zend_hash_find(), but hash value of the key must be already calculated */
181-
ZEND_API zval* ZEND_FASTCALL _zend_hash_find_known_hash(const HashTable *ht, zend_string *key);
180+
/* The same as zend_hash_find(), but hash value of the key must be already calculated. */
181+
ZEND_API zval* ZEND_FASTCALL zend_hash_find_known_hash(const HashTable *ht, zend_string *key);
182182

183183
static zend_always_inline zval *zend_hash_find_ex(const HashTable *ht, zend_string *key, bool known_hash)
184184
{
185185
if (known_hash) {
186-
return _zend_hash_find_known_hash(ht, key);
186+
return zend_hash_find_known_hash(ht, key);
187187
} else {
188188
return zend_hash_find(ht, key);
189189
}

Zend/zend_inheritance.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ static zend_never_inline void do_inheritance_check_on_method(
11601160

11611161
static zend_always_inline void do_inherit_method(zend_string *key, zend_function *parent, zend_class_entry *ce, bool is_interface, bool checked) /* {{{ */
11621162
{
1163-
zval *child = zend_hash_find_ex(&ce->function_table, key, 1);
1163+
zval *child = zend_hash_find_known_hash(&ce->function_table, key);
11641164

11651165
if (child) {
11661166
zend_function *func = (zend_function*)Z_PTR_P(child);
@@ -1235,7 +1235,7 @@ static void emit_incompatible_property_error(
12351235

12361236
static void do_inherit_property(zend_property_info *parent_info, zend_string *key, zend_class_entry *ce) /* {{{ */
12371237
{
1238-
zval *child = zend_hash_find_ex(&ce->properties_info, key, 1);
1238+
zval *child = zend_hash_find_known_hash(&ce->properties_info, key);
12391239
zend_property_info *child_info;
12401240

12411241
if (UNEXPECTED(child)) {
@@ -1340,7 +1340,7 @@ static void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_en
13401340

13411341
static void do_inherit_class_constant(zend_string *name, zend_class_constant *parent_const, zend_class_entry *ce) /* {{{ */
13421342
{
1343-
zval *zv = zend_hash_find_ex(&ce->constants_table, name, 1);
1343+
zval *zv = zend_hash_find_known_hash(&ce->constants_table, name);
13441344
zend_class_constant *c;
13451345

13461346
if (zv != NULL) {
@@ -1644,7 +1644,7 @@ ZEND_API void zend_do_inheritance_ex(zend_class_entry *ce, zend_class_entry *par
16441644
static bool do_inherit_constant_check(
16451645
zend_class_entry *ce, zend_class_constant *parent_constant, zend_string *name
16461646
) {
1647-
zval *zv = zend_hash_find_ex(&ce->constants_table, name, 1);
1647+
zval *zv = zend_hash_find_known_hash(&ce->constants_table, name);
16481648
if (zv == NULL) {
16491649
return true;
16501650
}
@@ -2870,7 +2870,7 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
28702870
if (traits_and_interfaces) {
28712871
free_alloca(traits_and_interfaces, use_heap);
28722872
}
2873-
zv = zend_hash_find_ex(CG(class_table), key, 1);
2873+
zv = zend_hash_find_known_hash(CG(class_table), key);
28742874
Z_CE_P(zv) = ret;
28752875
if (ZSTR_HAS_CE_CACHE(ret->name)) {
28762876
ZSTR_SET_CE_CACHE(ret->name, ret);
@@ -2888,7 +2888,7 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
28882888
}
28892889
/* Lazy class loading */
28902890
ce = zend_lazy_class_load(ce);
2891-
zv = zend_hash_find_ex(CG(class_table), key, 1);
2891+
zv = zend_hash_find_known_hash(CG(class_table), key);
28922892
Z_CE_P(zv) = ce;
28932893
if (CG(unlinked_uses)
28942894
&& zend_hash_index_del(CG(unlinked_uses), (zend_long)(zend_uintptr_t)proto) == SUCCESS) {
@@ -2898,7 +2898,7 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
28982898
/* Lazy class loading */
28992899
ce = zend_lazy_class_load(ce);
29002900
ce->ce_flags &= ~ZEND_ACC_FILE_CACHED;
2901-
zv = zend_hash_find_ex(CG(class_table), key, 1);
2901+
zv = zend_hash_find_known_hash(CG(class_table), key);
29022902
Z_CE_P(zv) = ce;
29032903
if (CG(unlinked_uses)
29042904
&& zend_hash_index_del(CG(unlinked_uses), (zend_long)(zend_uintptr_t)proto) == SUCCESS) {
@@ -2987,7 +2987,7 @@ ZEND_API zend_class_entry *zend_do_link_class(zend_class_entry *ce, zend_string
29872987
ce->inheritance_cache = NULL;
29882988
new_ce = zend_inheritance_cache_add(ce, proto, parent, traits_and_interfaces, ht);
29892989
if (new_ce) {
2990-
zv = zend_hash_find_ex(CG(class_table), key, 1);
2990+
zv = zend_hash_find_known_hash(CG(class_table), key);
29912991
ce = new_ce;
29922992
Z_CE_P(zv) = ce;
29932993
}
@@ -3019,7 +3019,7 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e
30193019
inheritance_status overall_status = INHERITANCE_SUCCESS;
30203020

30213021
ZEND_HASH_FOREACH_STR_KEY_PTR(&parent_ce->function_table, key, parent_func) {
3022-
zval *zv = zend_hash_find_ex(&ce->function_table, key, 1);
3022+
zval *zv = zend_hash_find_known_hash(&ce->function_table, key);
30233023
if (zv) {
30243024
zend_function *child_func = Z_FUNC_P(zv);
30253025
inheritance_status status =
@@ -3041,7 +3041,7 @@ static inheritance_status zend_can_early_bind(zend_class_entry *ce, zend_class_e
30413041
continue;
30423042
}
30433043

3044-
zv = zend_hash_find_ex(&ce->properties_info, key, 1);
3044+
zv = zend_hash_find_known_hash(&ce->properties_info, key);
30453045
if (zv) {
30463046
zend_property_info *child_info = Z_PTR_P(zv);
30473047
if (ZEND_TYPE_IS_SET(child_info->type)) {
@@ -3146,7 +3146,7 @@ zend_class_entry *zend_try_early_bind(zend_class_entry *ce, zend_class_entry *pa
31463146
ce->inheritance_cache = NULL;
31473147
new_ce = zend_inheritance_cache_add(ce, proto, parent_ce, NULL, ht);
31483148
if (new_ce) {
3149-
zval *zv = zend_hash_find_ex(CG(class_table), lcname, 1);
3149+
zval *zv = zend_hash_find_known_hash(CG(class_table), lcname);
31503150
ce = new_ce;
31513151
Z_CE_P(zv) = ce;
31523152
}

Zend/zend_object_handlers.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1847,10 +1847,10 @@ ZEND_API int zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj,
18471847

18481848
ZEND_API int zend_std_get_closure(zend_object *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zend_object **obj_ptr, bool check_only) /* {{{ */
18491849
{
1850-
zval *func;
18511850
zend_class_entry *ce = obj->ce;
1851+
zval *func = zend_hash_find_known_hash(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE));
18521852

1853-
if ((func = zend_hash_find_ex(&ce->function_table, ZSTR_KNOWN(ZEND_STR_MAGIC_INVOKE), 1)) == NULL) {
1853+
if (func == NULL) {
18541854
return FAILURE;
18551855
}
18561856
*fptr_ptr = Z_FUNC_P(func);

0 commit comments

Comments
 (0)