Skip to content

Commit 79fac32

Browse files
committed
Don't call zend_attach/detach_symbol_table() for op_arrays without local variables
1 parent 3a3eeb4 commit 79fac32

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

Zend/zend_execute.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3839,7 +3839,9 @@ static zend_always_inline void i_init_code_execute_data(zend_execute_data *execu
38393839
EX(call) = NULL;
38403840
EX(return_value) = return_value;
38413841

3842-
zend_attach_symbol_table(execute_data);
3842+
if (op_array->last_var) {
3843+
zend_attach_symbol_table(execute_data);
3844+
}
38433845

38443846
if (!ZEND_MAP_PTR(op_array->run_time_cache)) {
38453847
void *ptr;

Zend/zend_vm_def.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,9 @@ ZEND_VM_HOT_HELPER(zend_leave_helper, ANY, ANY)
28632863
LOAD_NEXT_OPLINE();
28642864
ZEND_VM_LEAVE();
28652865
} else if (EXPECTED((call_info & ZEND_CALL_TOP) == 0)) {
2866-
zend_detach_symbol_table(execute_data);
2866+
if (EX(func)->op_array.last_var > 0) {
2867+
zend_detach_symbol_table(execute_data);
2868+
}
28672869
zend_destroy_static_vars(&EX(func)->op_array);
28682870
destroy_op_array(&EX(func)->op_array);
28692871
efree_size(EX(func), sizeof(zend_op_array));
@@ -2874,7 +2876,9 @@ ZEND_VM_HOT_HELPER(zend_leave_helper, ANY, ANY)
28742876
execute_data = EG(current_execute_data) = EX(prev_execute_data);
28752877
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
28762878

2877-
zend_attach_symbol_table(execute_data);
2879+
if (EX(func)->op_array.last_var > 0) {
2880+
zend_attach_symbol_table(execute_data);
2881+
}
28782882
if (UNEXPECTED(EG(exception) != NULL)) {
28792883
zend_rethrow_exception(execute_data);
28802884
HANDLE_EXCEPTION_LEAVE();
@@ -2905,11 +2909,14 @@ ZEND_VM_HOT_HELPER(zend_leave_helper, ANY, ANY)
29052909
} else /* if (call_kind == ZEND_CALL_TOP_CODE) */ {
29062910
zend_array *symbol_table = EX(symbol_table);
29072911

2908-
zend_detach_symbol_table(execute_data);
2912+
if (EX(func)->op_array.last_var > 0) {
2913+
zend_detach_symbol_table(execute_data);
2914+
}
29092915
old_execute_data = EX(prev_execute_data);
29102916
while (old_execute_data) {
29112917
if (old_execute_data->func && (ZEND_CALL_INFO(old_execute_data) & ZEND_CALL_HAS_SYMBOL_TABLE)) {
2912-
if (old_execute_data->symbol_table == symbol_table) {
2918+
if (old_execute_data->symbol_table == symbol_table
2919+
&& old_execute_data->func->op_array.last_var > 0) {
29132920
zend_attach_symbol_table(old_execute_data);
29142921
}
29152922
break;

Zend/zend_vm_execute.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,9 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_leave_helper
11451145
LOAD_NEXT_OPLINE();
11461146
ZEND_VM_LEAVE();
11471147
} else if (EXPECTED((call_info & ZEND_CALL_TOP) == 0)) {
1148-
zend_detach_symbol_table(execute_data);
1148+
if (EX(func)->op_array.last_var > 0) {
1149+
zend_detach_symbol_table(execute_data);
1150+
}
11491151
zend_destroy_static_vars(&EX(func)->op_array);
11501152
destroy_op_array(&EX(func)->op_array);
11511153
efree_size(EX(func), sizeof(zend_op_array));
@@ -1156,7 +1158,9 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_leave_helper
11561158
execute_data = EG(current_execute_data) = EX(prev_execute_data);
11571159
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
11581160

1159-
zend_attach_symbol_table(execute_data);
1161+
if (EX(func)->op_array.last_var > 0) {
1162+
zend_attach_symbol_table(execute_data);
1163+
}
11601164
if (UNEXPECTED(EG(exception) != NULL)) {
11611165
zend_rethrow_exception(execute_data);
11621166
HANDLE_EXCEPTION_LEAVE();
@@ -1187,11 +1191,14 @@ static zend_never_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_leave_helper
11871191
} else /* if (call_kind == ZEND_CALL_TOP_CODE) */ {
11881192
zend_array *symbol_table = EX(symbol_table);
11891193

1190-
zend_detach_symbol_table(execute_data);
1194+
if (EX(func)->op_array.last_var > 0) {
1195+
zend_detach_symbol_table(execute_data);
1196+
}
11911197
old_execute_data = EX(prev_execute_data);
11921198
while (old_execute_data) {
11931199
if (old_execute_data->func && (ZEND_CALL_INFO(old_execute_data) & ZEND_CALL_HAS_SYMBOL_TABLE)) {
1194-
if (old_execute_data->symbol_table == symbol_table) {
1200+
if (old_execute_data->symbol_table == symbol_table
1201+
&& old_execute_data->func->op_array.last_var > 0) {
11951202
zend_attach_symbol_table(old_execute_data);
11961203
}
11971204
break;
@@ -55398,7 +55405,9 @@ ZEND_API void execute_ex(zend_execute_data *ex)
5539855405
LOAD_NEXT_OPLINE();
5539955406
ZEND_VM_LEAVE();
5540055407
} else if (EXPECTED((call_info & ZEND_CALL_TOP) == 0)) {
55401-
zend_detach_symbol_table(execute_data);
55408+
if (EX(func)->op_array.last_var > 0) {
55409+
zend_detach_symbol_table(execute_data);
55410+
}
5540255411
zend_destroy_static_vars(&EX(func)->op_array);
5540355412
destroy_op_array(&EX(func)->op_array);
5540455413
efree_size(EX(func), sizeof(zend_op_array));
@@ -55409,7 +55418,9 @@ ZEND_API void execute_ex(zend_execute_data *ex)
5540955418
execute_data = EG(current_execute_data) = EX(prev_execute_data);
5541055419
zend_vm_stack_free_call_frame_ex(call_info, old_execute_data);
5541155420

55412-
zend_attach_symbol_table(execute_data);
55421+
if (EX(func)->op_array.last_var > 0) {
55422+
zend_attach_symbol_table(execute_data);
55423+
}
5541355424
if (UNEXPECTED(EG(exception) != NULL)) {
5541455425
zend_rethrow_exception(execute_data);
5541555426
HANDLE_EXCEPTION_LEAVE();
@@ -55440,11 +55451,14 @@ ZEND_API void execute_ex(zend_execute_data *ex)
5544055451
} else /* if (call_kind == ZEND_CALL_TOP_CODE) */ {
5544155452
zend_array *symbol_table = EX(symbol_table);
5544255453

55443-
zend_detach_symbol_table(execute_data);
55454+
if (EX(func)->op_array.last_var > 0) {
55455+
zend_detach_symbol_table(execute_data);
55456+
}
5544455457
old_execute_data = EX(prev_execute_data);
5544555458
while (old_execute_data) {
5544655459
if (old_execute_data->func && (ZEND_CALL_INFO(old_execute_data) & ZEND_CALL_HAS_SYMBOL_TABLE)) {
55447-
if (old_execute_data->symbol_table == symbol_table) {
55460+
if (old_execute_data->symbol_table == symbol_table
55461+
&& old_execute_data->func->op_array.last_var > 0) {
5544855462
zend_attach_symbol_table(old_execute_data);
5544955463
}
5545055464
break;

0 commit comments

Comments
 (0)